diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bd9a4d714377ea51d2cd14419ae059cc9307b5d5..13dbdf1997b4d7115d467b019b31712b08540e26 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ hooks: - id: ansible-syntax-check - repo: https://github.com/willthames/ansible-lint - sha: v3.4.12 + sha: v3.4.13 hooks: - id: ansible-lint files: tests/playbook.yml diff --git a/.travis.yml b/.travis.yml index 988ef0eb14b66b07b454302d6b5d141df9907171..d32f5f72996cea77d0ad2a2585fe8463fc0c3b94 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,17 +7,14 @@ group: beta env: global: - VBOX_MEMORY=2048 + - VBOX_HWVIRTEX=off matrix: - - TOXENV=pre-commit - TOXENV=openbsd60 - TOXENV=trusty - TOXENV=precise - &jessie TOXENV=jessie - TOXENV=wheezy -matrix: - fast_finish: True - allow_failures: - - env: *jessie + cache: - pip - directories: @@ -28,7 +25,7 @@ install: - sudo apt-get install -y linux-headers-$(uname -r) virtualbox - wget https://releases.hashicorp.com/vagrant/1.9.1/vagrant_1.9.1_x86_64.deb - sudo dpkg -i vagrant_1.9.1_x86_64.deb - - pip install tox-travis | cat + - &pip_install pip install tox-travis | cat script: - travis_wait 45 tox @@ -37,3 +34,12 @@ notifications: webhooks: https://galaxy.ansible.com/api/v1/notifications/ email: false on_failure: never + +matrix: + fast_finish: True + include: + - env: + TOXENV: pre-commit + install: + - *pip_install + sudo: False diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000000000000000000000000000000000000..57e457ec22c6c18aac27a138882f83e8c5022012 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,38 @@ +/* +Jenkins pipeline for testing an Ansible role. +Required software on the agent: +- Python 2.7. +- Tox. +- Vagrant. +- Virtualbox. +*/ +pipeline { + agent any + environment { + VBOX_HWVIRTEX = off + } + stages { + stage('install') { + steps { + sh 'git submodule update --init --recursive' + } + } + stage('test') { + steps { + parallel ( + 'pre-commit': { + sh 'tox -e pre-commit' + } + 'molecule': { + sh 'tox' + } + ) + } + } + } + post { + success { + sh 'tox -e import' + } + } +} diff --git a/molecule.yml b/molecule.yml index 203d4af883219f5088c18fc66e69e25186e112aa..4e74eae221ebf137d5124a060e90cf24001101d1 100644 --- a/molecule.yml +++ b/molecule.yml @@ -46,6 +46,6 @@ vagrant: - 'landrush_ip.override = false if Vagrant.has_plugin?("landrush")' - | vm.provider "virtualbox" do |v| - v.customize "pre-boot", ["modifyvm", :id, "--hwvirtex", "off"] + v.customize "pre-boot", ["modifyvm", :id, "--hwvirtex", ENV['VBOX_HWVIRTEX']] if ENV.has_key?('VBOX_HWVIRTEX') v.memory = ENV['VBOX_MEMORY'].to_i if ENV.has_key?('VBOX_MEMORY') end diff --git a/tests/requirements.txt b/tests/requirements.txt index 1186c3351818f7fb407e6f449cebeea81093c7a9..de96393e4dd6e08964711cf0eca985e348e4ce5f 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,8 +1,8 @@ ansible==2.3.0.0 -testinfra==1.5.5 +testinfra==1.6.0 molecule==1.24.0 -ansible-lint==3.4.12 -python-vagrant==0.5.14 +ansible-lint==3.4.13 +python-vagrant==0.5.15 netaddr==0.7.19 passlib==1.7.1 bcrypt==3.1.3 diff --git a/tests/test_example.py b/tests/test_example.py index aaea50030b9784f0528df9b936cf1903d3af5994..3c308b7bc441b051237f60b2a935f56ce357557d 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -3,10 +3,10 @@ from testinfra.utils.ansible_runner import AnsibleRunner testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all') -def test_example(Command): - assert Command('uname').rc == 0 +def test_example(host): + assert host.run('uname').rc == 0 -def test_root(Command, Sudo): - with Sudo(): - assert Command('whoami').stdout.strip() == 'root' +def test_root(host): + with host.sudo(): + assert host.run('whoami').stdout.strip() == 'root' diff --git a/tox.ini b/tox.ini index 37440746fd830d4822b069e05ea6866dde1a765c..09d79c0d9c01f698cb463205bc878777af955951 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ skipsdist = True envlist = openbsd60,trusty,precise,jessie,wheezy [testenv] -envdir = {toxinidir}/.tox +envdir = {toxinidir}/.tox/molecule deps = -rtests/requirements.txt passenv = HOME VBOX* ANSIBLE_* whitelist_externals = @@ -14,7 +14,6 @@ commands = molecule test --platform {envname} [testenv:pre-commit] -envdir = {toxinidir}/.tox deps = -rtests/requirements.txt pre-commit @@ -25,3 +24,8 @@ commands = sh -c "ansible-galaxy install git+file://$(pwd),$(git rev-parse --abbrev-ref HEAD) -p .molecule/roles" molecule dependency pre-commit run --all-files + +[testenv:import] +envdir = {toxinidir}/.tox/molecule +deps = -rtests/requirements.txt +commands = ansible-galaxy import -v