All Projects β†’ ottomatica β†’ Opunit

ottomatica / Opunit

Licence: apache-2.0
πŸ•΅οΈβ€β™‚οΈ Sanity checking containers, vms, and servers

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Opunit

Ansible For Kubernetes
Ansible and Kubernetes examples from Ansible for Kubernetes Book
Stars: ✭ 389 (+121.02%)
Mutual labels:  devops, infrastructure
Sceptre
Build better AWS infrastructure
Stars: ✭ 1,160 (+559.09%)
Mutual labels:  devops, infrastructure
Howtheysre
A curated collection of publicly available resources on how technology and tech-savvy organizations around the world practice Site Reliability Engineering (SRE)
Stars: ✭ 6,962 (+3855.68%)
Mutual labels:  devops, infrastructure
Minicron
πŸ•°οΈ Monitor your cron jobs
Stars: ✭ 2,351 (+1235.8%)
Mutual labels:  devops, infrastructure
Toc
A Table of Contents of all Gruntwork Code
Stars: ✭ 111 (-36.93%)
Mutual labels:  devops, infrastructure
Awesome Learning
A curated list for DevOps learning resources. Join the slack channel to discuss more.
Stars: ✭ 327 (+85.8%)
Mutual labels:  devops, infrastructure
Chef
Chef Infra, a powerful automation platform that transforms infrastructure into code automating how infrastructure is configured, deployed and managed across any environment, at any scale
Stars: ✭ 6,766 (+3744.32%)
Mutual labels:  devops, infrastructure
Around Dataengineering
A Data Engineering & Machine Learning Knowledge Hub
Stars: ✭ 257 (+46.02%)
Mutual labels:  devops, infrastructure
Terraform Multienv
A template for maintaining a multiple environments infrastructure with Terraform. This template includes a CI/CD process, that applies the infrastructure in an AWS account.
Stars: ✭ 107 (-39.2%)
Mutual labels:  devops, infrastructure
Defcon24 Infra Monitoring Workshop
Defcon24 Workshop Contents : Ninja Level Infrastructure Monitoring
Stars: ✭ 104 (-40.91%)
Mutual labels:  devops, infrastructure
Awesome Devops
A curated list of resources for Devops
Stars: ✭ 697 (+296.02%)
Mutual labels:  devops, infrastructure
Mitogen
Distributed self-replicating programs in Python
Stars: ✭ 1,779 (+910.8%)
Mutual labels:  devops, infrastructure
Cintodeutilidadesdocker
My Docker templates repository 🐳 ☁️ 🐳
Stars: ✭ 74 (-57.95%)
Mutual labels:  devops, infrastructure
Terrascan
Detect compliance and security violations across Infrastructure as Code to mitigate risk before provisioning cloud native infrastructure.
Stars: ✭ 2,687 (+1426.7%)
Mutual labels:  devops, infrastructure
Terrahub
Terraform Automation and Orchestration Tool (Open Source)
Stars: ✭ 148 (-15.91%)
Mutual labels:  devops, infrastructure
Devspace
DevSpace - The Fastest Developer Tool for Kubernetes ⚑ Automate your deployment workflow with DevSpace and develop software directly inside Kubernetes.
Stars: ✭ 2,559 (+1353.98%)
Mutual labels:  devops
Docker Security Images
πŸ” Docker Container for Penetration Testing & Security
Stars: ✭ 172 (-2.27%)
Mutual labels:  devops
Devsecops
πŸ”± Collection and Roadmap for everyone who wants DevSecOps.
Stars: ✭ 171 (-2.84%)
Mutual labels:  devops
Dellemc Openmanage Ansible Modules
Dell EMC OpenManage Ansible Modules
Stars: ✭ 169 (-3.98%)
Mutual labels:  devops
Pypyr
pypyr task-runner cli & api for automation pipelines. Automate anything by combining commands, different scripts in different languages & applications into one pipeline process.
Stars: ✭ 173 (-1.7%)
Mutual labels:  devops

OpunitπŸ•΅οΈβ€ | CI dependencies Status

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

screen shot 2018-10-23 at 10 55 00

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

contains check also supports checking value of a property in a JSON file. This check is useful for making sure a configuration file is using correct values. For example, given the JSON file below, the following check verifies DriveName property is set to mysql:

{
  "SqlSettings": {
    "DriveName":"mysql"
  }
}
- contains: 
    file: /path/config.json
    query: .SqlSettings.DriverName
    string: mysql
    expect: 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

reachable check also supports checking permission, group and user of a given file or directory.

# check if file permission is set to 660
- path: /path/file
  permission: 660

# check if group `foo` has write permission to this file
- path: /path/file
  permission: w
  group: foo

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 (optional), to then send a http request and check if it receives the expected status code. or, ||, and, && can be used to check more than one port.

- availability:
    port: 3000 || 5000 || 8080
    status: 200
    url: /
    timeout: 10000                        # <--- optional
    setup:                                # <--- optional
        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

valid check verifies the given file's format is valid. Current supported file formats are json, yaml/yml.

- valid:
    - json: /path/config.json
    - yaml: /path/playbook.yml

env check verifies value of an environment variable.

- env:
  - APP_PORT=3002
  - MONGO_PORT=27017

jenkins_job check can verify status of a jenkins build job.

- jenkins_job:
    name: myjenkinsjob
    host: 123.123.123.123    # <--- optional, will use host from connector if not provided
    port: 1234               # <--- optional, will use 8080 if not provided
    status: success
    user: admin
    pass: admin

status = success | failure

Note: jenkins_job uses Jenkins api to get the job status.


command check can run any arbitrary command in the target environment and test it's stdout, stderr, and/or exit code against the provided values (string or regex).

- command: 
    exec: echo 'FOO'
    stdout: F.*O              # <--- regex or string
    stderr: ''
    exitCode: 0               # <--- alias for exitCode: code

- command: 
    exec: echo 'FOO'
    stdout: FOO

Note: We recommend you use this generic command check only if there are no other opunit checks for your needs. Feel free to request addition of other opunit checks by opening an issue.


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 to opunit.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 [email protected]: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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].