diff --git a/tests/ansible-role-requirements.yml b/tests/ansible-role-requirements.yml index b955e767..25355041 100644 --- a/tests/ansible-role-requirements.yml +++ b/tests/ansible-role-requirements.yml @@ -14,10 +14,6 @@ src: https://git.openstack.org/openstack/openstack-ansible-lxc_container_create scm: git version: origin/stable/mitaka -- name: openstack_hosts - src: https://git.openstack.org/openstack/openstack-ansible-openstack_hosts - scm: git - version: origin/stable/mitaka - name: galera_client src: https://git.openstack.org/openstack/openstack-ansible-galera_client scm: git diff --git a/tests/group_vars/all_containers.yml b/tests/group_vars/all_containers.yml new file mode 100644 index 00000000..83ce0212 --- /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: "lxcbr0" + interface: "eth1" + netmask: "255.255.252.0" + type: "veth" +physical_host: localhost +properties: + service_name: "{{ inventory_hostname }}" diff --git a/tests/inventory b/tests/inventory index fb48aff3..fdb3b9ae 100644 --- a/tests/inventory +++ b/tests/inventory @@ -1,6 +1,13 @@ [all] localhost ansible_connection=local ansible_become=True +container1 ansible_ssh_host=10.100.100.101 ansible_host=10.100.100.101 ansible_become=True ansible_user=root +container2 ansible_ssh_host=10.100.100.102 ansible_host=10.100.100.102 ansible_become=True ansible_user=root +container3 ansible_ssh_host=10.100.100.103 ansible_host=10.100.100.103 ansible_become=True ansible_user=root -[hosts] -localhost ansible_ssh_host=127.0.0.1 +[galera_test_hosts] +container1 +container2 +container3 +[all_containers:children] +galera_test_hosts diff --git a/tests/test-functional.yml b/tests/test-galera-server-functional.yml similarity index 87% rename from tests/test-functional.yml rename to tests/test-galera-server-functional.yml index 890287af..2889bdc5 100644 --- a/tests/test-functional.yml +++ b/tests/test-galera-server-functional.yml @@ -13,44 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Playbook for testing +- name: Run functional tests hosts: galera_test_hosts user: root gather_facts: true - vars: - galera_root_password: secrete - galera_root_user: root - pre_tasks: - - debug: - msg: "===== Running Function Tests =====" tasks: - - name: Create DB for service on 10.100.100.101 - mysql_db: - login_user: "{{ galera_root_user }}" - login_password: "{{ galera_root_password }}" - login_host: "10.100.100.101" - name: "OSA-test" - state: "present" - tags: - - neutron-db-setup - when: ansible_ssh_host == '10.100.100.101' - - name: Grant access to the DB on 10.100.100.102 - mysql_user: - login_user: "{{ galera_root_user }}" - login_password: "{{ galera_root_password }}" - login_host: "10.100.100.102" - name: "osa-tester" - password: "tester-secrete" - host: "{{ item }}" - state: "present" - priv: "OSA-test.*:ALL" - with_items: - - "localhost" - - "%" - tags: - - neutron-db-setup - when: ansible_ssh_host == '10.100.100.102' - - name: check cluster state incoming addresses + - name: Check cluster incoming addresses command: | mysql -h {{ ansible_ssh_host }} \ -p"{{ galera_root_password }}" \ @@ -58,7 +26,7 @@ --silent \ --skip-column-names register: wsrep_incoming_addresses - - name: check cluster state + - name: Check cluster local state command: | mysql -h {{ ansible_ssh_host }} \ -p"{{ galera_root_password }}" \ @@ -66,7 +34,7 @@ --silent \ --skip-column-names register: wsrep_local_state_comment - - name: check cluster state + - name: Check cluster evs state command: | mysql -h {{ ansible_ssh_host }} \ -p"{{ galera_root_password }}" \ @@ -82,3 +50,27 @@ - "'10.100.100.101' in wsrep_incoming_addresses.stdout" - "'10.100.100.102' in wsrep_incoming_addresses.stdout" - "'10.100.100.103' in wsrep_incoming_addresses.stdout" + - name: Create DB for service on 10.100.100.101 + mysql_db: + login_user: "{{ galera_root_user }}" + login_password: "{{ galera_root_password }}" + login_host: "10.100.100.101" + name: "OSA-test" + state: "present" + when: ansible_ssh_host == '10.100.100.101' + - name: Grant access to the DB on 10.100.100.102 + mysql_user: + login_user: "{{ galera_root_user }}" + login_password: "{{ galera_root_password }}" + login_host: "10.100.100.102" + name: "osa-tester" + password: "tester-secrete" + host: "{{ item }}" + state: "present" + priv: "OSA-test.*:ALL" + with_items: + - "localhost" + - "%" + when: ansible_ssh_host == '10.100.100.102' + vars_files: + - test-vars.yml diff --git a/tests/test-install-galera-server.yml b/tests/test-install-galera-server.yml new file mode 100644 index 00000000..b87eb299 --- /dev/null +++ b/tests/test-install-galera-server.yml @@ -0,0 +1,27 @@ +--- +# 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. + +- name: Install galera server + hosts: galera_test_hosts + serial: 1 + user: root + gather_facts: true + pre_tasks: + - debug: + msg: "{{ message }}" + roles: + - role: "{{ rolename | basename }}" + vars_files: + - test-vars.yml diff --git a/tests/test-container-create.yml b/tests/test-prepare-containers.yml similarity index 96% rename from tests/test-container-create.yml rename to tests/test-prepare-containers.yml index 966dc7b4..d2bcdf58 100644 --- a/tests/test-container-create.yml +++ b/tests/test-prepare-containers.yml @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Playbook for pre-role upgrade testing +- name: Create test containers hosts: all_containers connection: local gather_facts: false @@ -51,4 +51,4 @@ port: "{{ ansible_ssh_port | default('22') }}" host: "{{ ansible_ssh_host | default(inventory_hostname) }}" search_regex: OpenSSH - delay: 1 \ No newline at end of file + delay: 1 diff --git a/tests/test-prep.yml b/tests/test-prepare-host.yml similarity index 55% rename from tests/test-prep.yml rename to tests/test-prepare-host.yml index 516b44fd..65f08a31 100644 --- a/tests/test-prep.yml +++ b/tests/test-prepare-host.yml @@ -13,37 +13,19 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Playbook for pre-role testing 1of3 - hosts: 127.0.0.1 - connection: local - become: false - pre_tasks: - - name: Create ssh key pair for root - user: - name: "{{ ansible_ssh_user }}" - generate_ssh_key: "yes" - ssh_key_bits: 2048 - ssh_key_file: ".ssh/id_rsa" - - name: get the calling users key - command: cat ~/.ssh/id_rsa.pub - register: key_get - - set_fact: - lxc_container_ssh_key: "{{ key_get.stdout }}" - -- name: Playbook for pre-role testing 2of3 +- name: Perform basic LXC host setup hosts: localhost - connection: local pre_tasks: - - name: First ensure apt cache is always refreshed + - name: Ensure apt cache is always refreshed apt: update_cache: yes - name: Ensure root's new public ssh key is in authorized_keys authorized_key: user: root - key: "{{ hostvars['127.0.0.1']['lxc_container_ssh_key'] }}" + key: "{{ hostvars['localhost']['lxc_container_ssh_key'] }}" manage_dir: no - set_fact: - lxc_container_ssh_key: "{{ hostvars['127.0.0.1']['lxc_container_ssh_key'] }}" + lxc_container_ssh_key: "{{ hostvars['localhost']['lxc_container_ssh_key'] }}" - name: Check if this is an OpenStack-CI nodepool instance stat: path: /etc/nodepool/provider @@ -74,29 +56,3 @@ name: "trusty.tgz" sha256sum: "56c6a6e132ea7d10be2f3e8104f47136ccf408b30e362133f0dc4a0a9adb4d0c" chroot_path: trusty/rootfs-amd64 - post_tasks: - # Inventory is being pre-loaded using a post tasks instead of through a dynamic - # inventory system. While this is not a usual method for deployment it's being - # done for functional testing. - - name: Create container hosts - add_host: - groups: "all,all_containers,galera_test_hosts" - hostname: "{{ item.name }}" - inventory_hostname: "{{ item.name }}" - ansible_ssh_host: "{{ item.address }}" - ansible_become: true - properties: - service_name: "{{ item.service }}" - container_networks: - management_address: - address: "{{ item.address }}" - bridge: "lxcbr0" - interface: "eth1" - netmask: "255.255.255.0" - type: "veth" - physical_host: localhost - container_name: "{{ item.name }}" - with_items: - - { name: "container1", service: "service1", address: "10.100.100.101" } - - { name: "container2", service: "service2", address: "10.100.100.102" } - - { name: "container3", service: "service3", address: "10.100.100.103" } diff --git a/tests/test-prepare-keys.yml b/tests/test-prepare-keys.yml new file mode 100644 index 00000000..f4df126d --- /dev/null +++ b/tests/test-prepare-keys.yml @@ -0,0 +1,33 @@ +--- +# 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. + +# NOTE: we use become_user because setting become: no or become: false +# doesn't seem to override the ansible_become=true in the +# inventory +- name: Create ssh key pairs for use with containers + hosts: localhost + become_user: "{{ ansible_ssh_user }}" + tasks: + - name: Create ssh key pair for root + user: + name: "{{ ansible_ssh_user }}" + generate_ssh_key: "yes" + ssh_key_bits: 2048 + ssh_key_file: ".ssh/id_rsa" + - name: get the calling users key + command: cat ~/.ssh/id_rsa.pub + register: key_get + - set_fact: + lxc_container_ssh_key: "{{ key_get.stdout }}" diff --git a/tests/test-vars.yml b/tests/test-vars.yml new file mode 100644 index 00000000..1437bf9e --- /dev/null +++ b/tests/test-vars.yml @@ -0,0 +1,10 @@ +galera_cluster_members: "{{ groups['galera_test_hosts'] }}" +galera_root_password: secrete +galera_root_user: root +galera_innodb_buffer_pool_size: 512M +galera_innodb_log_buffer_size: 32M +galera_server_id: "{{ inventory_hostname | string_2_int }}" +galera_wsrep_node_name: "{{ inventory_hostname }}" +galera_wsrep_provider_options: + - { option: "gcache.size", value: "32M" } +galera_server_id: "{{ inventory_hostname | string_2_int }}" diff --git a/tests/test.yml b/tests/test.yml index 6a6b68b4..aa5a0aba 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -13,92 +13,44 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Run basic prep -- include: test-prep.yml +# Prepare the user ssh keys +- include: test-prepare-keys.yml + +# Prepare the host +- include: test-prepare-host.yml # Run container clean up and build -- include: test-container-create.yml +- include: test-prepare-containers.yml -# Deploy the environment -- name: Playbook for role testing - hosts: galera_test_hosts - serial: 1 - user: root - gather_facts: true +# Install Galera server +- include: test-install-galera-server.yml vars: - galera_cluster_members: "{{ groups['galera_test_hosts'] }}" - galera_root_password: secrete - galera_root_user: root - galera_innodb_buffer_pool_size: 512M - galera_innodb_log_buffer_size: 32M - galera_server_id: "{{ inventory_hostname | string_2_int }}" - galera_wsrep_node_name: "{{ inventory_hostname }}" - galera_wsrep_provider_options: - - { option: "gcache.size", value: "32M" } - roles: - - role: "{{ rolename | basename }}" - galera_server_id: "{{ inventory_hostname | string_2_int }}" + message: "===== Running Current MariaDB Deployment =====" -# Run playbook test -- include: test-functional.yml +# Run functional tests +- include: test-galera-server-functional.yml ############################# UPGRADE TESTING ############################# # Run container clean up and build -- include: test-container-create.yml +- include: test-prepare-containers.yml -# Deploy the environment running a 5.5 to 10.0 upgrade -- name: Playbook for role upgrade testing - hosts: galera_test_hosts - serial: 1 - user: root - gather_facts: true +# Install previous version of Galera server +- include: test-install-galera-server.yml vars: - galera_cluster_members: "{{ groups['galera_test_hosts'] }}" - galera_root_password: secrete - galera_root_user: root - galera_innodb_buffer_pool_size: 512M - galera_innodb_log_buffer_size: 32M - galera_server_id: "{{ inventory_hostname | string_2_int }}" - galera_wsrep_node_name: "{{ inventory_hostname }}" - galera_wsrep_provider_options: - - { option: "gcache.size", value: "32M" } - pre_tasks: - - debug: - msg: "===== Running MariaDB 5.5 Deployment for Upgrade =====" - roles: - - role: "{{ rolename | basename }}" - galera_mariadb_server_package: "mariadb-galera-server-5.5" - galera_apt_repo_url: "https://mirror.rackspace.com/mariadb/repo/5.5/ubuntu" - galera_server_id: "{{ inventory_hostname | string_2_int }}" + message: "===== Running MariaDB 5.5 Deployment for Upgrade =====" + galera_mariadb_server_package: "mariadb-galera-server-5.5" + galera_apt_repo_url: "https://mirror.rackspace.com/mariadb/repo/5.5/ubuntu" -# Run initial playbook test -- include: test-functional.yml +# Run initial functional tests +- include: test-galera-server-functional.yml -# Deploy the environment running a 5.5 to 10.0 upgrade -- name: Playbook for role upgrade testing - hosts: galera_test_hosts - serial: 1 - user: root - gather_facts: true +# Perform upgrade of Galera server +- include: test-install-galera-server.yml vars: - galera_cluster_members: "{{ groups['galera_test_hosts'] }}" - galera_root_password: secrete - galera_root_user: root - galera_innodb_buffer_pool_size: 512M - galera_innodb_log_buffer_size: 32M - galera_server_id: "{{ inventory_hostname | string_2_int }}" - galera_wsrep_node_name: "{{ inventory_hostname }}" - galera_wsrep_provider_options: - - { option: "gcache.size", value: "32M" } - pre_tasks: - - debug: - msg: "===== Running MariaDB 5.5 to current Upgrade =====" - roles: - - role: "{{ rolename | basename }}" - galera_server_id: "{{ inventory_hostname | string_2_int }}" - galera_ignore_cluster_state: true - galera_upgrade: true + message: "===== Running MariaDB 5.5 to Current Upgrade =====" + galera_ignore_cluster_state: true + galera_upgrade: true -# Run final playbook test -- include: test-functional.yml +# Run final functional tests +- include: test-galera-server-functional.yml diff --git a/tox.ini b/tox.ini index 34ce164e..0671385a 100644 --- a/tox.ini +++ b/tox.ini @@ -15,6 +15,7 @@ whitelist_externals = bash git rm + wget setenv = VIRTUAL_ENV={envdir} ANSIBLE_HOST_KEY_CHECKING = False @@ -108,12 +109,16 @@ commands = rm -rf {homedir}/.ansible git clone https://git.openstack.org/openstack/openstack-ansible-plugins \ {homedir}/.ansible/plugins + # This plugin makes the ansible-playbook output easier to read + wget -O {homedir}/.ansible/plugins/callback/human_log.py \ + https://gist.githubusercontent.com/cliffano/9868180/raw/f360f306b3c6d689734a6aa8773a00edf16a0054/human_log.py ansible-galaxy install \ --role-file={toxinidir}/tests/ansible-role-requirements.yml \ --ignore-errors \ --force ansible-playbook -i {toxinidir}/tests/inventory \ -e "rolename={toxinidir}" \ + -vv \ {toxinidir}/tests/test.yml