Skip to content

Instantly share code, notes, and snippets.

@syndicut
Last active August 22, 2016 07:01
Show Gist options
  • Save syndicut/c64bcf410fabfe0f50d435c6a52abd92 to your computer and use it in GitHub Desktop.
Save syndicut/c64bcf410fabfe0f50d435c6a52abd92 to your computer and use it in GitHub Desktop.
Testing salt formulas with Test Kitchen and Testinfra
---
driver:
name: vagrant
platforms:
- name: ubuntu-12.04
- name: ubuntu-14.04
provisioner:
name: salt_solo
formula: mongodb
pillars-from-files:
mongodb.sls: pillar.example
pillars:
top.sls:
base:
'*':
- mongodb
suites:
- name: server
provisioner:
state_top:
base:
'*':
- mongodb
verifier:
name: shell
command: testinfra -vvv --junit-xml junit-$KITCHEN_INSTANCE.xml test/integration/$KITCHEN_SUITE
import pytest
import testinfra
import os
SSH_CONFIG = '.ssh-config'
@pytest.fixture
def TestinfraBackend(request, tmpdir):
# Override the TestinfraBackend fixture,
# all testinfra fixtures (i.e. modules) depend on it.
ssh_config_file = tmpdir.join(SSH_CONFIG)
ssh_config_file.write('Host {0}\nUser {1}\nPort {2}\nIdentityFile {3}\n'.format(
os.environ['KITCHEN_HOSTNAME'],
os.environ['KITCHEN_USERNAME'],
os.environ['KITCHEN_PORT'],
os.environ['KITCHEN_SSH_KEY'],
))
# Return a dynamic created backend
return testinfra.backend.paramiko.ParamikoBackend(os.environ['KITCHEN_HOSTNAME'], str(ssh_config_file), sudo=True)
source "https://rubygems.org"
gem "test-kitchen"
gem "kitchen-vagrant"
gem "kitchen-salt"
testinfra
pytest-logging
paramiko
def test_port_27017_is_listening(Socket):
socket = Socket("tcp://0.0.0.0:27017")
assert socket.is_listening
def test_mongodb_server_is_running(Service):
service = Service("mongod")
assert service.is_running
assert service.is_enabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment