From afe63f6f1972f6747134544d8b2edea608da4f37 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Thu, 22 Jun 2017 19:00:33 +0100 Subject: [PATCH] Resolve migration issues A run_once task decides on a host without the context of conditionals related to the task. The filter is done prior to evaluating any conditionals. Also, only the neutron-server neutron.conf has the database connection credentials as a security measure, so it is not able to execute the database migrations. This patch ensures that the database migrations are only run once, but are also executed wherever neutron-server is. It also adds multiple instances of neutron-server and neutron-agents to better test against problems of this nature happening again. Additionally, the patch uses the handlers for the offline migrations to ensure that neutron-server is only restarted once when a new tag is deployed. Change-Id: I672ceb0848415c8f2653ebc8f7556db77f7f001c --- handlers/main.yml | 10 ++++ tasks/main.yml | 5 +- tasks/neutron_db_setup.yml | 47 +++++++------------ tests/ansible-role-requirements.yml | 4 ++ tests/host_vars/agents1.yml | 18 +++++++ tests/host_vars/agents2.yml | 18 +++++++ .../host_vars/{openstack1.yml => server1.yml} | 0 tests/host_vars/server2.yml | 18 +++++++ tests/lxb_inventory | 44 ++++++++++++----- tests/os_neutron-overrides.yml | 16 +++++++ tests/ovs_inventory | 38 ++++++++++----- tests/test-neutron-resources-upgrade.yml | 2 - tests/test-upgrade.yml | 3 ++ tests/test.yml | 3 ++ 14 files changed, 166 insertions(+), 60 deletions(-) create mode 100644 tests/host_vars/agents1.yml create mode 100644 tests/host_vars/agents2.yml rename tests/host_vars/{openstack1.yml => server1.yml} (100%) create mode 100644 tests/host_vars/server2.yml diff --git a/handlers/main.yml b/handlers/main.yml index 1001b17b..f34edf73 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -63,6 +63,16 @@ remote_src: yes listen: "Restart neutron services" +- name: Perform a DB contract + command: "{{ neutron_bin }}/neutron-db-manage upgrade --contract" + become: yes + become_user: "{{ neutron_system_user_name }}" + delegate_to: "{{ groups[neutron_services['neutron-server']['group']][0] }}" + when: + - "ansible_local['openstack_ansible']['neutron']['need_db_contract'] | bool" + run_once: yes + listen: "Restart neutron services" + - name: Start services service: name: "{{ item.service_name }}" diff --git a/tasks/main.yml b/tasks/main.yml index 80029944..0f5a430c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -86,14 +86,11 @@ - neutron-config - include: neutron_db_setup.yml - when: - - "neutron_services['neutron-server']['group'] in group_names" tags: - neutron-config - include: neutron_service_setup.yml - when: - - "neutron_services['neutron-server']['group'] in group_names" + run_once: yes tags: - neutron-config diff --git a/tasks/neutron_db_setup.yml b/tasks/neutron_db_setup.yml index 05c67230..8c87dc4c 100644 --- a/tasks/neutron_db_setup.yml +++ b/tasks/neutron_db_setup.yml @@ -17,14 +17,25 @@ command: "{{ neutron_bin }}/neutron-db-manage upgrade --expand" become: yes become_user: "{{ neutron_system_user_name }}" + delegate_to: "{{ groups[neutron_services['neutron-server']['group']][0] }}" when: - "ansible_local['openstack_ansible']['neutron']['need_db_expand'] | bool" run_once: yes +- name: Disable the db expand fact + ini_file: + dest: "/etc/ansible/facts.d/openstack_ansible.fact" + section: neutron + option: "need_db_expand" + value: "False" + - name: Check for available offline migrations command: "{{ neutron_bin }}/neutron-db-manage has_offline_migrations" - register: _offline_migrations_check + become: yes + become_user: "{{ neutron_system_user_name }}" + delegate_to: "{{ groups[neutron_services['neutron-server']['group']][0] }}" changed_when: false + register: _offline_migrations_check failed_when: - "_offline_migrations_check.rc == 1" - "'Need to apply migrations from neutron contract branch' not in _offline_migrations_check.stdout" @@ -35,37 +46,13 @@ dest: "/etc/ansible/facts.d/openstack_ansible.fact" section: neutron option: "need_db_contract" - value: "{{ ('Need to apply migrations from neutron contract branch' in _offline_migrations_check.stdout) | bool }}" + value: "True" + when: + - "'stdout' in _offline_migrations_check" + - "'Need to apply migrations from neutron contract branch' in _offline_migrations_check.stdout" + notify: Restart neutron services - name: Refresh local facts setup: filter: ansible_local gather_subset: "!all" - -- name: Stop Neutron server - service: - name: "neutron-server" - state: stopped - when: - - "ansible_local['openstack_ansible']['neutron']['need_db_contract'] | bool" - -- name: Perform a DB contract - command: "{{ neutron_bin }}/neutron-db-manage upgrade --contract" - become: yes - become_user: "{{ neutron_system_user_name }}" - when: - - "ansible_local['openstack_ansible']['neutron']['need_db_contract'] | bool" - run_once: yes - notify: Restart neutron services - -- name: Disable the db sync local facts - ini_file: - dest: "/etc/ansible/facts.d/openstack_ansible.fact" - section: neutron - option: "{{ item.name }}" - value: "{{ item.state }}" - with_items: - - name: "need_db_expand" - state: "False" - - name: "need_db_contract" - state: "False" diff --git a/tests/ansible-role-requirements.yml b/tests/ansible-role-requirements.yml index 5f0b28b3..3c5d6116 100644 --- a/tests/ansible-role-requirements.yml +++ b/tests/ansible-role-requirements.yml @@ -14,6 +14,10 @@ src: https://git.openstack.org/openstack/openstack-ansible-galera_server scm: git version: master +- name: haproxy_server + src: https://git.openstack.org/openstack/openstack-ansible-haproxy_server + scm: git + version: master - name: lxc_container_create src: https://git.openstack.org/openstack/openstack-ansible-lxc_container_create scm: git diff --git a/tests/host_vars/agents1.yml b/tests/host_vars/agents1.yml new file mode 100644 index 00000000..9878fcc2 --- /dev/null +++ b/tests/host_vars/agents1.yml @@ -0,0 +1,18 @@ +--- +# 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. + +ansible_host: 10.1.0.5 +ansible_become: True +ansible_user: root diff --git a/tests/host_vars/agents2.yml b/tests/host_vars/agents2.yml new file mode 100644 index 00000000..b78a2ea8 --- /dev/null +++ b/tests/host_vars/agents2.yml @@ -0,0 +1,18 @@ +--- +# 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. + +ansible_host: 10.1.0.6 +ansible_become: True +ansible_user: root diff --git a/tests/host_vars/openstack1.yml b/tests/host_vars/server1.yml similarity index 100% rename from tests/host_vars/openstack1.yml rename to tests/host_vars/server1.yml diff --git a/tests/host_vars/server2.yml b/tests/host_vars/server2.yml new file mode 100644 index 00000000..0e876f60 --- /dev/null +++ b/tests/host_vars/server2.yml @@ -0,0 +1,18 @@ +--- +# 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. + +ansible_host: 10.1.0.4 +ansible_become: True +ansible_user: root diff --git a/tests/lxb_inventory b/tests/lxb_inventory index c07fc244..b10413e1 100644 --- a/tests/lxb_inventory +++ b/tests/lxb_inventory @@ -1,14 +1,20 @@ [all] localhost infra1 -openstack1 +server1 +server2 +agents1 +agents2 [physical_host] localhost [all_containers] infra1 -openstack1 +server1 +server2 +agents1 +agents2 [rabbitmq_all] infra1 @@ -25,33 +31,41 @@ galera_all memcached_all [keystone_all] -openstack1 +infra1 [neutron_agent] -openstack1 +agents1 +agents2 [neutron_dhcp_agent] -openstack1 +agents1 +agents2 [neutron_linuxbridge_agent] -openstack1 +agents1 +agents2 [neutron_openvswitch_agent] [neutron_metering_agent] -openstack1 +agents1 +agents2 [neutron_l3_agent] -openstack1 +agents1 +agents2 [neutron_lbaas_agent] -openstack1 +agents1 +agents2 [neutron_metadata_agent] -openstack1 +agents1 +agents2 [neutron_server] -openstack1 +server1 +server2 [neutron_calico_dhcp_agent] @@ -67,4 +81,10 @@ neutron_metadata_agent neutron_server [utility_all] -openstack1 +infra1 + +[haproxy_all:children] +haproxy + +[haproxy] +localhost diff --git a/tests/os_neutron-overrides.yml b/tests/os_neutron-overrides.yml index 1363fd34..dff38b42 100644 --- a/tests/os_neutron-overrides.yml +++ b/tests/os_neutron-overrides.yml @@ -22,3 +22,19 @@ tempest_plugins: tempest_test_whitelist: - neutron.tests.tempest.api.test_networks* + +haproxy_ssl: false +external_lb_vip_address: 10.1.0.1 +internal_lb_vip_address: 10.1.0.1 + +test_neutron_server_host: "{{ external_lb_vip_address }}" + +haproxy_default_services: + - service: + haproxy_service_name: neutron_server + haproxy_backend_nodes: "{{ groups['neutron_server'] | default([]) }}" + haproxy_port: 9696 + haproxy_ssl: "{{ haproxy_ssl }}" + haproxy_balance_type: http + haproxy_backend_options: + - "httpchk GET /" diff --git a/tests/ovs_inventory b/tests/ovs_inventory index 035b21f4..d15f929f 100644 --- a/tests/ovs_inventory +++ b/tests/ovs_inventory @@ -1,14 +1,20 @@ [all] localhost infra1 -openstack1 +server1 +server2 +agents1 +agents2 [physical_host] localhost [all_containers] infra1 -openstack1 +server1 +server2 +agents1 +agents2 [rabbitmq_all] infra1 @@ -25,33 +31,41 @@ galera_all memcached_all [keystone_all] -openstack1 +infra1 [neutron_agent] -openstack1 +agents1 +agents2 [neutron_dhcp_agent] -openstack1 +agents1 +agents2 [neutron_linuxbridge_agent] [neutron_openvswitch_agent] -openstack1 +agents1 +agents2 [neutron_metering_agent] -openstack1 +agents1 +agents2 [neutron_l3_agent] -openstack1 +agents1 +agents2 [neutron_lbaas_agent] -openstack1 +agents1 +agents2 [neutron_metadata_agent] -openstack1 +agents1 +agents2 [neutron_server] -openstack1 +server1 +server2 [neutron_calico_dhcp_agent] @@ -67,4 +81,4 @@ neutron_metadata_agent neutron_server [utility_all] -openstack1 +infra1 diff --git a/tests/test-neutron-resources-upgrade.yml b/tests/test-neutron-resources-upgrade.yml index 5b52966d..14d53a86 100644 --- a/tests/test-neutron-resources-upgrade.yml +++ b/tests/test-neutron-resources-upgrade.yml @@ -17,9 +17,7 @@ hosts: localhost user: root become: true - # TODO: remove the static reference to openstack1 vars: - test_keystone_host: openstack1 working_dir: "{{ lookup('env', 'WORKING_DIR') }}" tasks: - name: Install openstack sdk diff --git a/tests/test-upgrade.yml b/tests/test-upgrade.yml index 2aa64e07..b3201ff6 100644 --- a/tests/test-upgrade.yml +++ b/tests/test-upgrade.yml @@ -16,6 +16,9 @@ # Setup the user ssh keys, host and containers - include: common/test-setup-host.yml +# Install haproxy +- include: common/test-install-haproxy.yml + # Install RabbitMQ/MariaDB - include: common/test-install-infra.yml diff --git a/tests/test.yml b/tests/test.yml index 354b523f..1b1220bf 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -16,6 +16,9 @@ # Setup the user ssh keys, host and containers - include: common/test-setup-host.yml +# Install haproxy +- include: common/test-install-haproxy.yml + # Install RabbitMQ/MariaDB - include: common/test-install-infra.yml