Merge "Add tox.ini and tests playbooks"

This commit is contained in:
Jenkins 2016-05-27 10:57:00 +00:00 committed by Gerrit Code Review
commit 437bbac039
5 changed files with 157 additions and 0 deletions

3
tests/ansible.cfg Normal file
View File

@ -0,0 +1,3 @@
[defaults]
host_key_checking = False
roles_path = ..

2
tests/inventory Normal file
View File

@ -0,0 +1,2 @@
[test]
test01 ansible_host=localhost ansible_connection=local

41
tests/resources.yml Normal file
View File

@ -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

64
tests/test.yaml Normal file
View File

@ -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 }

47
tox.ini Normal file
View File

@ -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"