diff --git a/.gitignore b/.gitignore index e1cf205905d93c46016f27f9e4df6a1da11cfd86..966ef052e8cb1dfe9ab17eff54ee874231f5dbb0 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ __pycache__ .vagrant/ *.log *.retry +.tox diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 233bc80d8f4b0a2ed98f97e33a6269dd6ef0d882..13dbdf1997b4d7115d467b019b31712b08540e26 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,27 +9,15 @@ - id: flake8 - id: check-symlinks - repo: https://github.com/adarnimrod/ansible-pre-commit.git - sha: 0fadd691465b97db8992cfc66650f630e433324b + sha: v0.6.0 hooks: - id: ansible-syntax-check - always_run: true - files: tests/playbook.yml - args: - - tests/playbook.yml - 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 --quiet --outdated tests/requirements.txt - files: requirements.txt - always_run: true diff --git a/.travis.yml b/.travis.yml index 17e77d2cb0d93e734ee561f45b448d4c31ed65dc..4fe1440ca59681ea63e3e0e5b240794217285a57 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,32 +1,26 @@ --- language: python -python: ["2.7", "3.5"] +python: "2.7" dist: trusty sudo: True group: beta -services: [docker] env: - - platform: openbsd60 - driver: vagrant - - platform: openbsd59 - driver: vagrant - - platform: xenial - driver: vagrant - - platform: trusty - driver: vagrant - - platform: jessie - driver: vagrant - - platform: wheezy - driver: vagrant - - driver: docker - platform: all + global: + - VBOX_MEMORY=2048 + - VBOX_HWVIRTEX=off + matrix: + - TOXENV=pre-commit + - TOXENV=openbsd60 + - TOXENV=xenial + - TOXENV=trusty + - TOXENV=precise + - &stretch TOXENV=stretch + - &jessie TOXENV=jessie + - TOXENV=wheezy matrix: fast_finish: True allow_failures: - - python: "3.5" - - env: platform=openbsd59 driver=vagrant - - env: platform=jessie driver=vagrant - - env: platform=wheezy driver=vagrant + - env: *stretch cache: - pip - directories: @@ -37,14 +31,12 @@ 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 tox-travis | cat script: - - pre-commit run --all-files - - molecule test --driver $driver --platform $platform + - travis_wait 45 tox notifications: webhooks: https://galaxy.ansible.com/api/v1/notifications/ email: false + on_failure: never diff --git a/README.rst b/README.rst index edf5c4706215f0f88a982206ca521fc462fd3882..d50fb09c8eb2981fc3817e27116a87b161505707 100644 --- a/README.rst +++ b/README.rst @@ -31,22 +31,9 @@ See :code:`tests/playbook.yml`. Testing ------- -Testing requires Python 2.7 and either Docker or 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 2dea7f403f2774209b2935d8aecfe4e81d2379a8..d768011e6d12fce30f080f03ab7b77ba904b9936 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -3,7 +3,7 @@ galaxy_info: description: An example Ansible role company: Shore technologies license: MIT - min_ansible_version: 2.0 + min_ansible_version: 2.3 platforms: - name: OpenBSD versions: @@ -11,5 +11,12 @@ galaxy_info: - name: Ubuntu versions: - xenial + - trusty + - precise + - name: Debian + versions: + - stretch + - jessie + - wheezy galaxy_tags: [ ansible ] dependencies: [] diff --git a/molecule.yml b/molecule.yml index 76623fbf0525766456018a351b90a1f0c96eeaeb..3456b7af84c8aaf756cec8c6739a22a759fe4d2f 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,40 +22,30 @@ 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 box: ubuntu/trusty32 + - name: precise + box: hashicorp/precise32 + - name: stretch + box: remram/debian-9-i386 - name: jessie - box: debian/jessie32 + box: deb/jessie-i386 - name: wheezy - box: debian/wheezy32 + box: bmorg/debian-wheezy-i386 instances: - name: example 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 - -docker: - containers: - - name: example-xenial - image: ubuntu - image_version: xenial - command: /sbin/init - privileged: True - volume_mounts: - - /sys/fs/cgroup:/sys/fs/cgroup - - /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket - environment: - DEBIAN_FRONTEND: noninteractive - container: docker diff --git a/tasks/main.yml b/tasks/main.yml index 811069eb5756ec0c7b051652b35347bd1ecc804a..0ab13c50f3aa88dc431f5b1d4f26744bb1db3bf9 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -5,4 +5,4 @@ assert: that: - ansible_os_family in ['OpenBSD', 'Debian'] - - ansible_distribution_release in ['6.0', '5.9', 'xenial', 'trusty', 'jessie', 'wheezy'] + - ansible_distribution_release in ['xenial', 'trusty', 'precise', 'stretch', 'jessie', 'wheezy'] or ansible_distribution_version in ['6.0'] diff --git a/tests/playbook.yml b/tests/playbook.yml index 10beeb2eec9f631d1daabcb1aa0e1dd0121821cc..55444f3e9d597410c72104be8cd4b99151243a5a 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -1,11 +1,21 @@ --- - hosts: example-openbsd* gather_facts: false - roles: [openbsd-bootstrap] + roles: + - openbsd-bootstrap + - role: users + users: [] + users_use_sudo: True + users_lock_root_ssh: False -- hosts: example-xenial +- hosts: [example-xenial, example-wheezy] gather_facts: false - roles: [debian-bootstrap] + roles: + - debian-bootstrap + - role: users + users: [] + users_use_sudo: True + users_lock_root_ssh: False - hosts: all roles: diff --git a/tests/requirements.txt b/tests/requirements.txt index 1c8ea361c0af0ec637c22c71f1acdb9cd22295a0..de96393e4dd6e08964711cf0eca985e348e4ce5f 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,11 +1,8 @@ -ansible==2.2.0.0 -testinfra==1.5.1 -molecule==1.17.3 -ansible-lint==3.4.9 -pre-commit==0.10.1 -piprot==0.9.7 -python-vagrant==0.5.14 -docker-py==1.10.6 -netaddr==0.7.18 -passlib==1.7.0 -bcrypt==3.1.2 +ansible==2.3.0.0 +testinfra==1.6.0 +molecule==1.24.0 +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/requirements.yml b/tests/requirements.yml index 70716f60b9e624bc5a09442517a08667363949f4..fccce7574df98d466c55a309273c4060174e8cb0 100644 --- a/tests/requirements.yml +++ b/tests/requirements.yml @@ -3,3 +3,5 @@ name: openbsd-bootstrap - src: adarnimrod.debian-bootstrap name: debian-bootstrap +- src: adarnimrod.users + name: users 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..fca46228eacd9240de0cdf608077968eb1271893 --- /dev/null +++ b/tox.ini @@ -0,0 +1,26 @@ +[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