
This commit conditionally allows the os_neutron role to install build and deploy within a venv. This is the new default behavior of the role however the functionality can be disabled. In this PR, like all of the other venv related PRs, the `is_metal` flag was removed from the role however unlike some of the other PRs this removal required moving some of the `is_metal` logic out of the role and into the play. This was done for consistency as well as making the role more standalone. The only thing that the role should care about, in terms of installation, is whether or not to install in a venv. Implements: blueprint enable-venv-support-within-the-roles Change-Id: I85aadc43e1c21f296b2fb5932a17eddce57b9ece Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
155 lines
4.4 KiB
Python
155 lines
4.4 KiB
Python
#!/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
|
|
library_path:
|
|
description:
|
|
- Local path to the location where the neutron python package
|
|
is installed.
|
|
default: /usr/local/lib/python2.7/dist-packages/neutron
|
|
bin_path:
|
|
description:
|
|
- Local path to the where the neutron binaries are.
|
|
default: /usr/local/bin
|
|
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, library_path):
|
|
migrations_dir = (
|
|
'%s/db/migration/alembic_migrations/versions/%s/' % (
|
|
library_path,
|
|
release,
|
|
)
|
|
)
|
|
for branch in MIGRATIONS.keys():
|
|
migration_dir = os.path.join(get_abs_path(migrations_dir), branch)
|
|
for file in os.listdir(migration_dir):
|
|
if file.endswith('.py') and file.split('_')[0] == revision:
|
|
return branch
|
|
|
|
|
|
def get_abs_path(path):
|
|
return os.path.abspath(
|
|
os.path.expanduser(
|
|
path
|
|
)
|
|
)
|
|
|
|
|
|
def main():
|
|
module = AnsibleModule(
|
|
argument_spec=dict(
|
|
release=dict(
|
|
type='str',
|
|
default='liberty'
|
|
),
|
|
library_path=dict(
|
|
type='str',
|
|
default='/usr/local/lib/python2.7/dist-packages/neutron'
|
|
),
|
|
bin_path=dict(
|
|
type='str',
|
|
default='/usr/local/bin'
|
|
)
|
|
),
|
|
supports_check_mode=False
|
|
)
|
|
state_change = False
|
|
|
|
command = [
|
|
'%s/neutron-db-manage' % get_abs_path(module.params['bin_path']),
|
|
'current'
|
|
]
|
|
|
|
try:
|
|
current = subprocess.check_output(command)
|
|
except subprocess.CalledProcessError as e:
|
|
module.fail_json(msg='neutron fact collection failed: "%s".' % e)
|
|
|
|
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(
|
|
release=module.params['release'],
|
|
revision=revision,
|
|
library_path=get_abs_path(module.params['library_path'])
|
|
)
|
|
if branch is None:
|
|
module.fail_json(
|
|
msg='neutron fact collection failed: unable to find'
|
|
' migration with revision %s' % revision
|
|
)
|
|
|
|
MIGRATIONS[branch]['revision'] = revision
|
|
MIGRATIONS[branch]['head'] = head
|
|
|
|
module.exit_json(
|
|
changed=state_change,
|
|
ansible_facts={'neutron_migrations': MIGRATIONS}
|
|
)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|