Last active
August 22, 2016 07:01
-
-
Save syndicut/c64bcf410fabfe0f50d435c6a52abd92 to your computer and use it in GitHub Desktop.
Testing salt formulas with Test Kitchen and Testinfra
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem "test-kitchen" | |
gem "kitchen-vagrant" | |
gem "kitchen-salt" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testinfra | |
pytest-logging | |
paramiko |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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