From c01f24904616215036acc82d823e58afd4c422c5 Mon Sep 17 00:00:00 2001 From: Andy McCrae Date: Thu, 25 Aug 2016 13:29:49 +0100 Subject: [PATCH] Add convergence test for test repo. For test repo we should build out keystone + infra services, as they are the most commonly used roles/tasks. We still need to add some funcitonal tests but this should give a good base. The test repo will consume it's own test plays in the same way as other repositories would. We use a "git clone ." to avoid a situation where we clone the old repo containing the errors we are trying to fix. Additional fix, we don't need a "when" clause on the rabbit/db creation tasks - since these are already delegated and a "run_once" will suffice. This fix is required for the tests to pass. Change-Id: I482500872f9e29a71e1576f67a0ad390be2a3ece --- create-grant-db.yml | 4 +-- ensure-rabbitmq.yml | 5 ++- inventory | 1 - run_tests.sh | 0 tests/ansible-role-requirements.yml | 40 +++++++++++++++++++++++ tests/group_vars/all_containers.yml | 26 +++++++++++++++ test.yml => tests/host_vars/localhost.yml | 12 ++----- tests/inventory | 30 +++++++++++++++++ tests/test.yml | 29 ++++++++++++++++ tests/tests-network-interfaces.cfg.j2 | 10 ++++++ tox.ini | 19 ++++++----- 11 files changed, 152 insertions(+), 24 deletions(-) delete mode 100644 inventory mode change 100644 => 100755 run_tests.sh create mode 100644 tests/ansible-role-requirements.yml create mode 100644 tests/group_vars/all_containers.yml rename test.yml => tests/host_vars/localhost.yml (68%) create mode 100644 tests/inventory create mode 100644 tests/test.yml create mode 100644 tests/tests-network-interfaces.cfg.j2 diff --git a/create-grant-db.yml b/create-grant-db.yml index 377e9126..ac940b2c 100644 --- a/create-grant-db.yml +++ b/create-grant-db.yml @@ -20,7 +20,7 @@ name: "{{ db_name }}" state: "present" delegate_to: "{{ groups['galera_all'][0] }}" - when: inventory_hostname == "{{ host_name }}" + run_once: True - name: Grant access to the DB for the service mysql_user: login_user: "root" @@ -35,4 +35,4 @@ - "localhost" - "%" delegate_to: "{{ groups['galera_all'][0] }}" - when: inventory_hostname == "{{ host_name }}" + run_once: True diff --git a/ensure-rabbitmq.yml b/ensure-rabbitmq.yml index 1feef0aa..0866e1f3 100644 --- a/ensure-rabbitmq.yml +++ b/ensure-rabbitmq.yml @@ -17,7 +17,7 @@ name: "{{ vhost_name }}" state: "present" delegate_to: "{{ groups['rabbitmq_all'][0] }}" - when: inventory_hostname == "{{ host_name }}" + run_once: True - name: Ensure rabbitmq user rabbitmq_user: user: "{{ user_name }}" @@ -28,5 +28,4 @@ write_priv: ".*" state: "present" delegate_to: "{{ groups['rabbitmq_all'][0] }}" - when: inventory_hostname == "{{ host_name }}" - + run_once: True diff --git a/inventory b/inventory deleted file mode 100644 index d18580b3..00000000 --- a/inventory +++ /dev/null @@ -1 +0,0 @@ -localhost \ No newline at end of file diff --git a/run_tests.sh b/run_tests.sh old mode 100644 new mode 100755 diff --git a/tests/ansible-role-requirements.yml b/tests/ansible-role-requirements.yml new file mode 100644 index 00000000..803b10d4 --- /dev/null +++ b/tests/ansible-role-requirements.yml @@ -0,0 +1,40 @@ +- name: apt_package_pinning + src: https://git.openstack.org/openstack/openstack-ansible-apt_package_pinning + scm: git + version: master +- name: pip_install + src: https://git.openstack.org/openstack/openstack-ansible-pip_install + scm: git + version: master +- name: memcached_server + src: https://git.openstack.org/openstack/openstack-ansible-memcached_server + scm: git + version: master +- name: lxc_hosts + src: https://git.openstack.org/openstack/openstack-ansible-lxc_hosts + scm: git + version: master +- name: lxc_container_create + src: https://git.openstack.org/openstack/openstack-ansible-lxc_container_create + scm: git + version: master +- name: galera_client + src: https://git.openstack.org/openstack/openstack-ansible-galera_client + scm: git + version: master +- name: galera_server + src: https://git.openstack.org/openstack/openstack-ansible-galera_server + scm: git + version: master +- name: rabbitmq_server + src: https://git.openstack.org/openstack/openstack-ansible-rabbitmq_server + scm: git + version: master +- name: memcached_server + src: https://git.openstack.org/openstack/openstack-ansible-memcached_server + scm: git + version: master +- name: os_keystone + src: https://git.openstack.org/openstack/openstack-ansible-os_keystone + scm: git + version: master diff --git a/tests/group_vars/all_containers.yml b/tests/group_vars/all_containers.yml new file mode 100644 index 00000000..f37df47c --- /dev/null +++ b/tests/group_vars/all_containers.yml @@ -0,0 +1,26 @@ +--- +# Copyright 2016, Rackspace US, 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. + +container_name: "{{ inventory_hostname }}" +container_networks: + management_address: + address: "{{ ansible_host }}" + bridge: "br-mgmt" + interface: "eth1" + netmask: "255.255.255.0" + type: "veth" +physical_host: localhost +properties: + service_name: "{{ inventory_hostname }}" diff --git a/test.yml b/tests/host_vars/localhost.yml similarity index 68% rename from test.yml rename to tests/host_vars/localhost.yml index df0ae88b..6c26f31a 100644 --- a/test.yml +++ b/tests/host_vars/localhost.yml @@ -1,5 +1,5 @@ --- -# Copyright 2015, Rackspace US, Inc. +# Copyright 2016, Rackspace US, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,11 +13,5 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Include here all the functional tests for the test repo. -- name: Playbook for deploying nova - hosts: localhost - user: root - gather_facts: true - tasks: - - debug: - msg: "Functional tests to be included here" +bridges: + - "br-mgmt" diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 00000000..8127e392 --- /dev/null +++ b/tests/inventory @@ -0,0 +1,30 @@ +[all] +localhost ansible_connection=local ansible_become=True +infra1 ansible_ssh_host=10.100.101.2 ansible_host=10.100.101.2 ansible_become=True ansible_user=root +keystone1 ansible_ssh_host=10.100.101.3 ansible_host=10.100.101.3 ansible_become=True ansible_user=root +keystone2 ansible_ssh_host=10.100.101.4 ansible_host=10.100.101.4 ansible_become=True ansible_user=root + +[all_containers] +infra1 +keystone1 +keystone2 + +[rabbitmq_all] +infra1 + +[galera_all] +infra1 + +[memcached_all] +infra1 + +[service_all:children] +rabbitmq_all +galera_all +memcached_all + +[keystone_all] +keystone1 +keystone2 + +[utility_all] diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 00000000..ae5020f3 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,29 @@ +--- +# Copyright 2015, Rackspace US, 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. + +# Prepare the user ssh keys +- include: playbooks/test-prepare-keys.yml + +# Prepare the host +- include: playbooks/test-prepare-host.yml + +# Prepare the containers +- include: playbooks/test-prepare-containers.yml + +# Install RabbitMQ/MariaDB/Memcached +- include: playbooks/test-install-infra.yml + +# Install Keystone +- include: playbooks/test-install-keystone.yml diff --git a/tests/tests-network-interfaces.cfg.j2 b/tests/tests-network-interfaces.cfg.j2 new file mode 100644 index 00000000..ed31fcff --- /dev/null +++ b/tests/tests-network-interfaces.cfg.j2 @@ -0,0 +1,10 @@ +auto br-mgmt +iface br-mgmt inet static + bridge_stp off + bridge_waitport 0 + bridge_fd 0 + # Notice the bridge port is the vlan tagged interface + bridge_ports none + address 10.100.101.1 + netmask 255.255.255.0 + offload-sg off diff --git a/tox.ini b/tox.ini index 41be8f67..183d40dd 100644 --- a/tox.ini +++ b/tox.ini @@ -117,9 +117,11 @@ commands = git clone https://git.openstack.org/openstack/openstack-ansible-plugins \ {homedir}/.ansible/plugins rm -rf {homedir}/.ansible/roles - #ansible-galaxy install \ - # --role-file={toxinidir}/tests/ansible-role-requirements.yml \ - # --force + ansible-galaxy install \ + --role-file={toxinidir}/tests/ansible-role-requirements.yml \ + --force + rm -rf {toxinidir}/tests/playbooks + git clone . {toxinidir}/tests/playbooks [testenv:ansible-syntax] @@ -129,10 +131,10 @@ setenv = {[testenv:ansible]setenv} commands = {[testenv:ansible]commands} - ansible-playbook -i {toxinidir}/inventory \ + ansible-playbook -i {toxinidir}/tests/inventory \ --syntax-check \ --list-tasks \ - {toxinidir}/test.yml + {toxinidir}/tests/test.yml [testenv:ansible-lint] @@ -155,10 +157,9 @@ setenv = {[testenv:ansible]setenv} commands = {[testenv:ansible]commands} - #NOTE(evrardjp): currently there is no functional test of the - #test repository. Only syntax checks are done. - #ansible-playbook -i {toxinidir}/inventory \ - # {toxinidir}/test.yml -vvvv + ansible-playbook -i {toxinidir}/tests/inventory \ + -e "network_conf_filename=tests/tests-network-interfaces.cfg.j2" \ + {toxinidir}/tests/test.yml -vvvv [testenv:linters]