---
# 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: Setup hosts for rpc-pre-upgrades
  hosts: localhost
  roles:
    - role: "rpc_pre_upgrade"
  tags:
    - rpc-pre-upgrades

---
# 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: Setup hosts for rpc-pre-upgrades
  hosts: localhost
  roles:
    - role: "rpc_pre_upgrade"
  tags:
    - rpc-pre-upgrades

- name: Run nova DB hygiene on shadow_instance tables
  hosts: galera_all[0]
  gather_facts: false
  user: root
  tasks:
    - name: Prune the shadow instance tables
      shell: |
        mysql -sNL \
              --unbuffered \
              -e "delete from {{ item }} where deleted>0;" {{ nova_galera_database | default('nova') }}
      with_items:
        - shadow_instance_actions
        - shadow_instance_actions_events
        - shadow_instance_extra
        - shadow_instance_faults
        - shadow_instance_group_member
        - shadow_instance_group_policy
        - shadow_instance_groups
        - shadow_instance_id_mappings
        - shadow_instance_info_caches
        - shadow_instance_metadata
        - shadow_instance_system_metadata
        - shadow_instance_type_extra_specs
        - shadow_instance_type_projects
        - shadow_instance_types
        - shadow_instances

- name: Run nova DB hygiene on instance tables
  hosts: nova_api_os_compute[0]
  gather_facts: false
  user: root
  tasks:
    - name: Archive all nova deleted instances
      command: "{{ nova_bin }}/nova-manage db archive_deleted_rows --until-complete"
  vars:
    nova_venv_tag: "{{ venv_tag }}"
    nova_bin: "/openstack/venvs/nova-{{ nova_venv_tag }}/bin"

Add pre-upgrade nova db Hygiene tasks
Add pre-upgrade nova db Hygiene tasks

This change adds two tasks to run a Database deleted instances archive
and then to prune the shadow tables in preparation for upgrade. This
change will ensure that all deleted instances are cleanup which speeds
up nova migrations as well as ensures migrations are not impeded due
to legacy data being stuck in a deleted VM record.

Closes-Bug: #1608
Signed-off-by: Kevin Carter <ffb54fded2f22052678e45d78b58d223654eb6fa@rackspace.com>
