From 125f8812dcf6b2b2344e6c126fddf84b895ca23b Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Thu, 5 May 2016 11:12:43 +0200 Subject: [PATCH] Add tox.ini and tests playbooks Change-Id: If8896976ad9330cd71044fcfbf8ce893639e1324 --- tests/ansible.cfg | 3 +++ tests/inventory | 2 ++ tests/resources.yml | 41 +++++++++++++++++++++++++++++ tests/test.yaml | 64 +++++++++++++++++++++++++++++++++++++++++++++ tox.ini | 47 +++++++++++++++++++++++++++++++++ 5 files changed, 157 insertions(+) create mode 100644 tests/ansible.cfg create mode 100644 tests/inventory create mode 100644 tests/resources.yml create mode 100644 tests/test.yaml create mode 100644 tox.ini diff --git a/tests/ansible.cfg b/tests/ansible.cfg new file mode 100644 index 0000000..1ba76a9 --- /dev/null +++ b/tests/ansible.cfg @@ -0,0 +1,3 @@ +[defaults] +host_key_checking = False +roles_path = .. diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..8bc8296 --- /dev/null +++ b/tests/inventory @@ -0,0 +1,2 @@ +[test] +test01 ansible_host=localhost ansible_connection=local diff --git a/tests/resources.yml b/tests/resources.yml new file mode 100644 index 0000000..c16f659 --- /dev/null +++ b/tests/resources.yml @@ -0,0 +1,41 @@ +profiles: + - name: test_profile_a + domains: + - name: test_domain + description: test description + projects: + - name: test_project + domain: test_domain + description: test project + - name: test_profile_b + users: + - name: test_user + password: changeme + email: test@test.net + domain: test_domain + default_project: test_project +clouds: + - name: devstack-admin + profiles: + - test_profile_a + - test_profile_b + servers: + - name: test_server_a + image: cirros-0.3.4-x86_64-uec + flavor: c1 + - name: devstack + servers: + - name: test_server_b + image: cirros-0.3.4-x86_64-uec + flavor: c1 + network: test_network + networks: + - name: test_network + subnets: + - name: test_subnet + network_name: test_network + cidr: 10.0.0.1/24 + routers: + - name: test_router + network: public + interfaces: test_subnet diff --git a/tests/test.yaml b/tests/test.yaml new file mode 100644 index 0000000..edc0f75 --- /dev/null +++ b/tests/test.yaml @@ -0,0 +1,64 @@ +# Copyright 2016 Hewlett-Packard Enterprise, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +--- +- hosts: test + become: yes + vars: + rolename: "{{ lookup('pipe', 'pwd') | dirname | basename }}" + + roles: + - "{{ rolename }}" + + post_tasks: + - name: Querying for test_domain domain + shell: openstack --os-cloud devstack-admin domain show test_domain + register: result + + - name: Assert test_domain domain has been created + assert: { that: result.rc == 0 } + + - name: Querying for test_project project + shell: openstack --os-cloud devstack-admin project show test_project --domain test_domain + register: result + + - name: Assert test_project project has been created + assert: { that: result.rc == 0 } + + - name: Querying for test_user user + shell: openstack --os-cloud devstack-admin user show test_user --domain test_domain + register: result + + - name: Assert test_user user has been created + assert: { that: result.rc == 0 } + + - name: Querying for test_server_a server + shell: openstack --os-cloud devstack-admin server show test_server_a + register: result + + - name: Assert test-server-a server has been created + assert: { that: result.rc == 0 } + + - name: Querying for test_server_b server + shell: openstack --os-cloud devstack server show test_server_b + register: result + + - name: Assert test_server_a server has been created + assert: { that: result.rc == 0 } + + - name: Querying for test_network network + shell: openstack --os-cloud devstack network show test_network + register: result + + - name: Assert test-network network has been created + assert: { that: result.rc == 0 } diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..58b83e9 --- /dev/null +++ b/tox.ini @@ -0,0 +1,47 @@ +[tox] +minversion = 1.4.2 +envlist = docs,linters +skipsdist = True + +[testenv] +deps = -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt + +[testenv:functional] +commands = + ansible-playbook -i tests/inventory tests/test.yaml \ + -e "@tests/resources.yml" +passenv = HOME +setenv = + ANSIBLE_CONFIG = {toxinidir}/tests/ansible.cfg + PYTHONUNBUFFERED = 1 + +[testenv:docs] +commands = python setup.py build_sphinx + +[testenv:venv] +commands = {posargs} + +[flake8] +# E123, E125 skipped as they are invalid PEP-8. + +show-source = True +ignore = E123,E125 +builtins = _ +exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build + +[testenv:linters] +setenv = + ANSIBLE_CONFIG = tests/ansible.cfg +whitelist_externals = bash +commands = + # PEP8 Lint Check + flake8 + # Ansible Lint Check + bash -c "find . -type f -regex '.*.y[a]?ml' -print0 | xargs -t -n1 -0 \ + ansible-lint" + # Ansible Syntax Check + bash -c "find tests -type f -regex '.*.y[a]?ml' ! -name 'resources.yml' \ + -print | xargs -t -n1 \ + ansible-playbook --syntax-check -i tests/inventory \ + -e rolename=$(basename $(pwd)) > /dev/null"