diff --git a/.gitignore b/.gitignore index 78a7d185ba9c5bba0caac2042728722c01ce32dd..25aaab8248f046fc9eb1a4862f39057b268417e4 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,6 @@ __pycache__ .vagrant/ *.log *.retry +.tox tests/files/id_rsa tests/files/id_rsa.pub diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1c367af8565706e3bae4c4b6b210c98468e1084d..0bc91cb7d598474dd9caf2752c493894b0ee6aeb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ - repo: https://github.com/pre-commit/pre-commit-hooks - sha: 7539d8bd1a00a3c1bfd34cdb606d3a6372e83469 + sha: v0.7.1 hooks: - id: check-added-large-files - id: check-json @@ -9,31 +9,19 @@ - id: flake8 - id: check-symlinks - repo: https://github.com/adarnimrod/ansible-pre-commit.git - sha: v0.5.0 + sha: v0.6.0 hooks: - id: ansible-syntax-check - always_run: true - files: tests/playbook.yml - args: - - tests/playbook.yml -- repo: https://github.com/adarnimrod/shell-pre-commit - sha: v0.1.0 - hooks: - - id: shell-lint - repo: https://github.com/willthames/ansible-lint - sha: 959ab0f525e9abb19cf75f34381015cf33695f61 + sha: v3.4.13 hooks: - id: ansible-lint - always_run: true files: tests/playbook.yml - args: - - tests/playbook.yml -- repo: local +- repo: https://github.com/adarnimrod/python-pre-commit.git + sha: v0.2.0 hooks: - id: piprot - name: piprot - description: Check up-to-date Python requirements - language: system - entry: piprot --outdated tests/requirements.txt - files: requirements.txt - always_run: true +- repo: https://github.com/adarnimrod/shell-pre-commit + sha: v0.1.0 + hooks: + - id: shell-lint diff --git a/.travis.yml b/.travis.yml index 9762643b5f37a33c6f602b4d31c5225dc07af751..fba962b950a578374c37104635dd048299887420 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,22 @@ --- language: python -python: ["2.7", "3.5"] +python: "2.7" dist: trusty sudo: True group: beta env: - - platform: openbsd60 - - &openbsd59 platform=openbsd59 - - platform: xenial - - platform: trusty - - platform: precise - - &stretch platform=stretch - - platform: jessie - - platform: wheezy -matrix: - fast_finish: True - allow_failures: - - python: "3.5" - - env: *openbsd59 - - env: *stretch + global: + - VBOX_MEMORY=2048 + - VBOX_HWVIRTEX=off + matrix: + - TOXENV=openbsd60 + - TOXENV=xenial + - TOXENV=trusty + - TOXENV=precise + - &stretch TOXENV=stretch + - &jessie TOXENV=jessie + - TOXENV=wheezy + cache: - pip - directories: @@ -29,14 +27,23 @@ 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 -r tests/requirements.txt | cat - - ansible-galaxy install git+file://$(pwd),$(git rev-parse --abbrev-ref HEAD) -p .molecule/roles - - molecule dependency + - &pip_install pip install tox-travis | cat script: - - pre-commit run --all-files - - travis_wait 45 molecule test --platform $platform + - travis_wait 45 tox notifications: webhooks: https://galaxy.ansible.com/api/v1/notifications/ email: false + on_failure: never + +matrix: + fast_finish: True + allow_failures: + - env: *stretch + 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/README.rst b/README.rst index 5b6a09c93374448d86a226edf69471913ae6734c..84cff1858b8545fc4236c21fdad258d108bad961 100644 --- a/README.rst +++ b/README.rst @@ -30,21 +30,9 @@ See :code:`tests/playbook.yml`. Testing ------- -Testing requires Python 2.7, Vagrant and Virtualbox. Install the Python -dependencies, dependent roles and roles required for testing: - -.. code:: shell - - pip install -r tests/requirements.txt - ansible-galaxy install git+file://$(pwd),$(git rev-parse --abbrev-ref HEAD) -p .molecule/roles - molecule dependency - -To run the full test suite: - -.. code:: shell - - pre-commit run --all-files - molecule test --platform all +Testing requires Python 2.7, Tox, Vagrant and Virtualbox. To test simply run +:code:`tox`. `Pre-commit <http://pre-commit.com/>`_ is also setup for this +project. License ------- diff --git a/meta/main.yml b/meta/main.yml index 400e6912cf45dca9c1a0915a4cd8c1ac328fe3f6..59a8652945bfb49c08e173690ec1b8952e19a463 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -3,18 +3,20 @@ galaxy_info: description: Provision gitreceive company: Shore technologies license: MIT - min_ansible_version: 2.0 + min_ansible_version: 2.3 platforms: - name: OpenBSD versions: - - 5.9 - 6.0 - - name: Debian - versions: - - jessie - name: Ubuntu versions: - - trusty - xenial + - trusty + - precise + - name: Debian + versions: + - stretch + - jessie + - wheezy galaxy_tags: [ ci, git ] dependencies: [] diff --git a/molecule.yml b/molecule.yml index d1906924e949537f8ecbcaefaa98a3d145f926d8..2c53e86c198fa582f9391656dcb2e19abc680405 100644 --- a/molecule.yml +++ b/molecule.yml @@ -5,6 +5,10 @@ ansible: diff: True config_file: ../ansible.cfg +molecule: + ignore_paths: + - .tox + dependency: name: galaxy requirements_file: tests/requirements.yml @@ -18,8 +22,6 @@ vagrant: platforms: - name: openbsd60 box: fnichol/openbsd-6.0-i386 - - name: openbsd59 - box: fnichol/openbsd-5.9-i386 - name: xenial box: ubuntu/xenial32 - name: trusty @@ -37,11 +39,13 @@ vagrant: options: append_platform_to_hostname: yes raw_config_args: + - 'vm.boot_timeout = 600' - 'vm.synced_folder ".", "/vagrant", disabled: true' - 'vbguest.auto_update = false if Vagrant.has_plugin?("vbguest")' - 'landrush.enabled = false if Vagrant.has_plugin?("landrush")' - '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 fc43b9a640a4f4c4c75292e61185d25556ae45e7..ec406ec475e9be833c88d7a988b2ea0221180b2d 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,10 +1,8 @@ -ansible==2.2.1.0 -testinfra==1.5.3 -molecule==1.19.1 -ansible-lint==3.4.10 -pre-commit==0.12.2 -piprot==0.9.7 -python-vagrant==0.5.14 +ansible==2.3.0.0 +testinfra==1.6.3 +molecule==1.24.0 +ansible-lint==3.4.13 +python-vagrant==0.5.15 netaddr==0.7.19 -passlib==1.7.0 -bcrypt==3.1.2 +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 new file mode 100644 index 0000000000000000000000000000000000000000..c80d480b6f557c37a14f6ec977a2900494e95d51 --- /dev/null +++ b/tox.ini @@ -0,0 +1,31 @@ +[tox] +skip_install = True +skipsdist = True +envlist = openbsd60,xenial,trusty,precise,stretch,jessie,wheezy + +[testenv] +envdir = {toxinidir}/.tox/molecule +deps = -rtests/requirements.txt +passenv = HOME VBOX* ANSIBLE_* +whitelist_externals = + sh +commands = + sh -c "ansible-galaxy install git+file://$(pwd),$(git rev-parse --abbrev-ref HEAD) -p .molecule/roles" + molecule test --platform {envname} + +[testenv:pre-commit] +deps = + -rtests/requirements.txt + pre-commit +passenv = HOME VBOX* ANSIBLE_* +whitelist_externals = + sh +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