

GitHub - ottomatica/opunit: ?️♂️? Sanity checking containers, vms, and servers
source link: https://github.com/ottomatica/opunit
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md
Opunit?️ | 
Simple tool for doing sanity checks on vms, and containers and remote servers. Written in pure node.js
Install with npm
npm install -g opunit
Using Opunit
Opunit uses a configuration file (opunit.yml) in the /test
directory of you project. This is an example opunit.yml file. By running opunit verify
in the root directory of your project, opunit runs the checks defined in the configuration file on the environment of your project; this can be a VM, container or even a remote server.
- group: description: "Basic checks for startup" checks: - availability: port: 8080 status: 200 url: / setup: cmd: node app.js wait_for: Started Application - version: cmd: mysql --version range: ^8.x.x - version: cmd: node --version range: ^10.x.x
In this example opunit will run 3 checks. First one runs the command node app.js
and waits for "Started Application", then checks the reponse status for a request to http://{IP}/
.
The next two checks run --version
commands for MySQL and Java inside the environment and compare the actual version with the provided semver range.
If all the checks pass, the output of opunit will look like this:
Checks
availability check
Setup: node index.js
Resolved wait_for condition: Stdout matches "Started Application"
Tearing down
✔ [node-app] http://192.168.8.8:8080// expected: 200 actual: 200
version check
✔ mysql --version: 8.0.12 > ^8.x.x => true
version check
✔ node --version: 10.12.0 > ^10.x.x => true
Summary
100.0% of all checks passed.
3 passed · 0 failed
More examples of using Opunit can be found in Baker environments of baker-examples repository.
Checks
Opunit has many checks available for common verification tasks. See the documentation below.
contains
supports checking contents of the file. This can be useful when there is a template file and you want to check and make sure it is updated with the correct values in the file.
- contains: file: /home/jenkins/settings/login.properties string: 'username: root'
status
= true
| false
Expected output format:
contains check
✔ [/home/jenkins/settings/login.properties] contains [username: root] status: true
service
supports checking the status of a system service (e.g. systemd).
- service: name: mysql status: active - service: name: shouldntexist status: none
status
= active
| inactive
| none
Expected output:
service check
✔ [mysql] expected: active actual: active
service check
✔ [shouldntexist] expected: none actual: none
reachable
determines whether a resource, such as a url, domain, or path is accessible from the instance. This check is good for determining whether dns or firewalls are configured appropriately.
- reachable: - google.com - nope.com/404.html - reallyImportantFile.txt
capability
supports checking the environment satisfies that minimum size of memory, CPU cores, and free disk space.
- capability: memory: 2000 cores: 1 disks: - location: / size: 10
availability
supports running the specified command and waiting for an output, to then send a http request and check if it receives the expected status code.
- availability: port: 3000 status: 200 url: / setup: cmd: baker run serve wait_for: Started Application
version
supports running the provided "--version"
command for an application on the environment, and checking if the installed version is in the range of specified semver range.
- version: cmd: mysql --version range: ^5.x.x
timezone
supports checking the timezone settings on the environment.
- timezone: EST
Connectors
Opunit has different connectors to be able to run checks on different kinds of environments. See below for description of each one and how they can be used.
In general, opunit verify command looks like
$ opunit verify [env_address] -c {criteria_path}
env_address
is used to automatically determine the type of connector for you (this is explains in more details below).criteria_path
is path toopunit.yml
file. Opunit automatically finds this file if it is in{current working directory}/test/opunit.yml
and in this case you don't have to provide-c
.
ssh Connector
If env_address
matches username@host:port
format (ex. [email protected]:2222
), then opunit will use this connector. When using this connector, you must also provide path to the ssh key:
$ opunit verify [email protected]:2222 --ssh_key ~/.ssh/id_rsa
By default, if port
is not provided, opunit assumes the default ssh port (22).
Baker Connector
If you don't specify a env_address
, Opunit will try to use Baker connector by default; for example if opunit is run as below and there is a baker.yml
file in the directory:
$ opunit verify
Vagrant Connector
If you don't specify a env_address
, Opunit will try to use Vagrant connector by default (if it fails to find a Baker env); for example if opunit is run as below and there is a Vagrantfile
file in the directory:
$ opunit verify
Also if env_address
is provided and there is a running Vagrant VM with name == env_address
, Vagrant connector will be used:
$ opunit verify opunit_vagrant
Docker Connector
If there is a running Docker container with the name or id equal to env_address
, opunit will try to use this connector.
$ opunit verify opunit_container
Local Connector
If env_address
is "local" or "localhost", opunit will use local connector to run the checks on localhost.
$ opunit verify local
Inventory
Opunit also supports using an inventory file to run checks on multiple (types of) environments. Inventory file is a Yaml file which lists environments that you want to check:
--- - docker: - name: opunit_container1 - name: opunit_container2 - vagrant: - name: opunit_vagrant - ssh: - target: [email protected] private_key: ~/.ssh/id_rsa - target: [email protected] private_key: ~/.ssh/id_rsa - baker: - name: hibernate-spring target: ~/projects/hibernate-spring criteria_path: ~/projects/opunit.yml
Note: If for an environment a criteria_path
is specified, that will be the criteria used for that environment, regardless of what is specified in -c
or {current working directory}/test/opunit.yml
.
You can run Opunit with an inventory file by running:
$ opunit verify -i {path to inventory.yml}
What about inspec?
Inspec is a great tool! However, it requires much more verbose and manual specifications of tests. For example, in inspec, a test is for checking the timezone requires writing something like this:
# timezone should be est describe command('date +%Z') do its(:stdout) { should match(/(EST)/) } end
In opunit, this is simply expressed as:
- timezone: EST
Installing from Source
If you want to play with opunit's source code, we suggesting installing and running things like this:
git clone https://github.com/ottomatica/opunit
cd opunit
npm install
npm link
Recommend
-
62
In a rush? Skip to We’ve spent the last few months building the new version of our shopping cart. When we started working on it, we knew this would...
-
61
We recently migrated the @sanity-packages written with Flow to TypeScript . It was an intere...
-
8
Here are some of our best tips & tricks for using SSH more effectively. This post will cover how to: Add a second factor to your SSH login Use agent forwarding safely Exit from...
-
3
Tools for Sanity in Isolation This is what sanity looks like, I swearI live alone at the moment, and the start of quarantine, was… roc...
-
5
Closed Bug 1514392 Opened 2 years ago Closed 2 years ago...
-
10
Introduction In this article, you will learn how to build a simple web application with Vue.js, query your data from Sanity, and make it a Progressive Web Application (PWA) by installing the PWA plugin. In making it a PWA, th...
-
8
Post-Its, how it saved the sanity of a UX Designer in Pandemic life — 3MLife is complex and hence our decision-making. Multitasking, need to hyper-focus, distracted genre, Post-Its are a powerful tool in UX...
-
5
July 16th, 2021 · ~5 minutes In this article, we’ll go through creating a pair of utility functions wrapping the Sanity JavaScript client to query data without losing your sani...
-
4
How to Check DAG Health Status for All Exchange Servers A...
-
3
Backup your Sanity dataset with GitHub Actions Skip to main content August 9th, 2022 · ~2 min...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK