Merge "Add neutron_migrations_facts module"
This commit is contained in:
commit
4e85ba4e53
@ -32,7 +32,6 @@ neutron_system_home_folder: "/var/lib/{{ neutron_system_user_name }}"
|
|||||||
neutron_galera_user: neutron
|
neutron_galera_user: neutron
|
||||||
neutron_galera_password: "{{ neutron_container_mysql_password }}"
|
neutron_galera_password: "{{ neutron_container_mysql_password }}"
|
||||||
neutron_galera_database: neutron
|
neutron_galera_database: neutron
|
||||||
neutron_db_revision: heads
|
|
||||||
neutron_db_config: /etc/neutron/neutron.conf
|
neutron_db_config: /etc/neutron/neutron.conf
|
||||||
neutron_db_plugin: /etc/neutron/plugins/ml2/ml2_conf.ini
|
neutron_db_plugin: /etc/neutron/plugins/ml2/ml2_conf.ini
|
||||||
neutron_db_max_overflow: 20
|
neutron_db_max_overflow: 20
|
||||||
|
101
playbooks/roles/os_neutron/library/neutron_migrations_facts
Normal file
101
playbooks/roles/os_neutron/library/neutron_migrations_facts
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
from ansible.module_utils.basic import *
|
||||||
|
|
||||||
|
DOCUMENTATION = """
|
||||||
|
---
|
||||||
|
module: neutron_migrations_facts
|
||||||
|
short_description:
|
||||||
|
- A module for gathering neutron migrations facts.
|
||||||
|
description:
|
||||||
|
- This module creates a fact called 'neutron_migrations', which is a dict
|
||||||
|
containing keys that represent each alembic migration branch. The value
|
||||||
|
for each key is another dict, containing a key value for the current
|
||||||
|
neutron revision for that branch (revision), and whether or not the
|
||||||
|
branch is currently at the latest revision (head). The
|
||||||
|
'neutron_migrations' fact can then be used to determine if migrations
|
||||||
|
for either branch are required, and allows us to only apply migrations
|
||||||
|
if necessary.
|
||||||
|
options:
|
||||||
|
release:
|
||||||
|
description:
|
||||||
|
- This is the OpenStack release you're running, used when
|
||||||
|
searching for migration revisions in the neutron code.
|
||||||
|
default: liberty
|
||||||
|
author: Rcbops
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = """
|
||||||
|
- name: Gather neutron migration facts
|
||||||
|
neutron_migrations_facts:
|
||||||
|
release: mitaka
|
||||||
|
"""
|
||||||
|
|
||||||
|
MIGRATIONS = {'expand': {'revision': None, 'head': None},
|
||||||
|
'contract': {'revision': None, 'head': None}}
|
||||||
|
|
||||||
|
|
||||||
|
def get_branch(release, revision):
|
||||||
|
migrations_dir = '/usr/local/lib/python2.7/dist-packages/neutron/db/' \
|
||||||
|
'migration/alembic_migrations/versions/%s/' % release
|
||||||
|
for branch in MIGRATIONS.keys():
|
||||||
|
for file in os.listdir('%s/%s' % (migrations_dir, branch)):
|
||||||
|
if file.endswith('.py') and file.split('_')[0] == revision:
|
||||||
|
return branch
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
module = AnsibleModule(
|
||||||
|
argument_spec=dict(
|
||||||
|
release=dict(
|
||||||
|
type='str',
|
||||||
|
default='liberty'
|
||||||
|
)
|
||||||
|
),
|
||||||
|
supports_check_mode=False
|
||||||
|
)
|
||||||
|
state_change = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
current = subprocess.check_output(['neutron-db-manage', 'current'])
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
message = 'neutron fact collection failed: "%s".' % e
|
||||||
|
module.fail_json(msg=message)
|
||||||
|
|
||||||
|
for line in current.splitlines():
|
||||||
|
head = False
|
||||||
|
match = re.search("^([0-9a-z]{4,12})(\s\(head\))?$", line)
|
||||||
|
if match:
|
||||||
|
revision = match.group(1)
|
||||||
|
if match.group(2):
|
||||||
|
head = True
|
||||||
|
branch = get_branch(module.params['release'], revision)
|
||||||
|
if branch is None:
|
||||||
|
message = 'neutron fact collection failed: unable to find ' \
|
||||||
|
'migration with revision %s' % revision
|
||||||
|
module.fail_json(msg=message)
|
||||||
|
|
||||||
|
MIGRATIONS[branch]['revision'] = revision
|
||||||
|
MIGRATIONS[branch]['head'] = head
|
||||||
|
|
||||||
|
module.exit_json(changed=state_change,
|
||||||
|
ansible_facts={'neutron_migrations': MIGRATIONS})
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@ -16,6 +16,7 @@
|
|||||||
- include: neutron_pre_install.yml
|
- include: neutron_pre_install.yml
|
||||||
- include: neutron_install.yml
|
- include: neutron_install.yml
|
||||||
- include: neutron_post_install.yml
|
- include: neutron_post_install.yml
|
||||||
|
- include: neutron_upstart_init.yml
|
||||||
|
|
||||||
- include: neutron_db_setup.yml
|
- include: neutron_db_setup.yml
|
||||||
when: >
|
when: >
|
||||||
@ -29,7 +30,5 @@
|
|||||||
when: >
|
when: >
|
||||||
inventory_hostname in groups['neutron_agent']
|
inventory_hostname in groups['neutron_agent']
|
||||||
|
|
||||||
- include: neutron_upstart_init.yml
|
|
||||||
|
|
||||||
- name: Flush handlers
|
- name: Flush handlers
|
||||||
meta: flush_handlers
|
meta: flush_handlers
|
||||||
|
@ -39,25 +39,15 @@
|
|||||||
tags:
|
tags:
|
||||||
- neutron-db-setup
|
- neutron-db-setup
|
||||||
|
|
||||||
- name: Check for existing migrations
|
- name: Get neutron migrations facts
|
||||||
shell: |
|
neutron_migrations_facts:
|
||||||
neutron-db-manage --config-file {{ neutron_db_config }} --config-file {{ neutron_db_plugin }} current | egrep "^[0-9a-z]{12}"
|
release: liberty
|
||||||
sudo: yes
|
|
||||||
sudo_user: "{{ neutron_system_user_name }}"
|
|
||||||
failed_when: false
|
|
||||||
register: neutron_migrations_previously_run
|
|
||||||
tags:
|
tags:
|
||||||
- neutron-db-setup
|
- neutron-db-setup
|
||||||
- neutron-upgrade
|
- neutron-upgrade
|
||||||
|
|
||||||
- name: Perform an initial Neutron DB sync
|
- name: Print neutron migrations facts
|
||||||
command: |
|
debug: var=neutron_migrations
|
||||||
neutron-db-manage --config-file {{ neutron_db_config }}
|
|
||||||
--config-file {{ neutron_db_plugin }}
|
|
||||||
upgrade {{ neutron_db_revision }}
|
|
||||||
sudo: yes
|
|
||||||
sudo_user: "{{ neutron_system_user_name }}"
|
|
||||||
when: neutron_migrations_previously_run.rc == 1
|
|
||||||
tags:
|
tags:
|
||||||
- neutron-db-setup
|
- neutron-db-setup
|
||||||
- neutron-upgrade
|
- neutron-upgrade
|
||||||
@ -69,7 +59,7 @@
|
|||||||
upgrade --expand
|
upgrade --expand
|
||||||
sudo: yes
|
sudo: yes
|
||||||
sudo_user: "{{ neutron_system_user_name }}"
|
sudo_user: "{{ neutron_system_user_name }}"
|
||||||
when: neutron_migrations_previously_run.rc == 0
|
when: not neutron_migrations['expand']['head']|bool
|
||||||
tags:
|
tags:
|
||||||
- neutron-db-setup
|
- neutron-db-setup
|
||||||
- neutron-upgrade
|
- neutron-upgrade
|
||||||
@ -81,7 +71,7 @@
|
|||||||
pattern: "neutron-server"
|
pattern: "neutron-server"
|
||||||
delegate_to: "{{ item }}"
|
delegate_to: "{{ item }}"
|
||||||
with_items: groups['neutron_server']
|
with_items: groups['neutron_server']
|
||||||
when: neutron_migrations_previously_run.rc == 0
|
when: not neutron_migrations['contract']['head']|bool
|
||||||
tags:
|
tags:
|
||||||
- neutron-db-setup
|
- neutron-db-setup
|
||||||
- neutron-upgrade
|
- neutron-upgrade
|
||||||
@ -93,7 +83,7 @@
|
|||||||
upgrade --contract
|
upgrade --contract
|
||||||
sudo: yes
|
sudo: yes
|
||||||
sudo_user: "{{ neutron_system_user_name }}"
|
sudo_user: "{{ neutron_system_user_name }}"
|
||||||
when: neutron_migrations_previously_run.rc == 0
|
when: not neutron_migrations['contract']['head']|bool
|
||||||
tags:
|
tags:
|
||||||
- neutron-db-setup
|
- neutron-db-setup
|
||||||
- neutron-upgrade
|
- neutron-upgrade
|
||||||
@ -105,7 +95,7 @@
|
|||||||
pattern: "neutron-server"
|
pattern: "neutron-server"
|
||||||
delegate_to: "{{ item }}"
|
delegate_to: "{{ item }}"
|
||||||
with_items: groups['neutron_server']
|
with_items: groups['neutron_server']
|
||||||
when: neutron_migrations_previously_run.rc == 0
|
when: not neutron_migrations['contract']['head']|bool
|
||||||
tags:
|
tags:
|
||||||
- neutron-db-setup
|
- neutron-db-setup
|
||||||
- neutron-upgrade
|
- neutron-upgrade
|
||||||
|
Loading…
x
Reference in New Issue
Block a user