From 2ed4290addc2a2bdfdcbb7b9c7f017ecd5dff1e8 Mon Sep 17 00:00:00 2001 From: Borne Mace Date: Mon, 14 Mar 2016 13:13:24 -0700 Subject: [PATCH] Changed way we handle global properties (from /etc/kolla/globals.yml to /usr/share/kolla/ansible/group_vars/__GLOBAL). Jira-Issue: OPENSTACK-742 --- kollacli/common/inventory.py | 17 ++++++++--------- kollacli/common/properties.py | 22 ++++++++++++---------- kollacli/common/support.py | 3 --- kollacli/common/utils.py | 2 +- tests/property.py | 8 ++++---- tests/support.py | 1 - 6 files changed, 25 insertions(+), 28 deletions(-) diff --git a/kollacli/common/inventory.py b/kollacli/common/inventory.py index 3fc4911..9365568 100644 --- a/kollacli/common/inventory.py +++ b/kollacli/common/inventory.py @@ -106,10 +106,11 @@ DEFAULT_OVERRIDES = { # these groups cannot be deleted, they are required by kolla PROTECTED_GROUPS = [COMPUTE_GRP_NAME] +LOG = logging.getLogger(__name__) + class Host(object): class_version = 1 - log = logging.getLogger(__name__) def __init__(self, hostname): self.name = hostname @@ -257,8 +258,6 @@ class SubService(object): class Inventory(object): class_version = 2 - log = logging.getLogger(__name__) - """class version history 1: initial release @@ -482,11 +481,11 @@ class Inventory(object): u._('Not all hosts were set up. : {reasons}') .format(reasons=summary)) else: - self.log.info(u._LI('All hosts were successfully set up.')) + LOG.info(u._LI('All hosts were successfully set up.')) def setup_host(self, hostname, password, uname=None): try: - self.log.info( + LOG.info( u._LI('Starting setup of host ({host}).') .format(host=hostname)) ssh_setup_host(hostname, password, uname) @@ -494,8 +493,8 @@ class Inventory(object): if not check_ok: raise Exception(u._('Post-setup ssh check failed. {err}') .format(err=msg)) - self.log.info(u._LI('Host ({host}) setup succeeded.') - .format(host=hostname)) + LOG.info(u._LI('Host ({host}) setup succeeded.') + .format(host=hostname)) except Exception as e: raise CommandError( u._('Host ({host}) setup failed : {error}') @@ -576,7 +575,7 @@ class Inventory(object): subservice.remove_groupname(groupname) group_vars = os.path.join(get_group_vars_dir(), groupname) - if os.path.exists(group_vars) and groupname != '__RESERVED__': + if os.path.exists(group_vars) and groupname != '__GLOBAL__': os.remove(group_vars) if groupname in self._groups: @@ -822,7 +821,7 @@ class Inventory(object): # temporarily create group containing all hosts. this is needed for # ansible commands that are performed on hosts not yet in groups. - group = self.add_group('__RESERVED__') + group = self.add_group('__GLOBAL__') jdict[group.name] = {} jdict[group.name]['hosts'] = deploy_hostnames jdict[group.name]['vars'] = group.get_vars() diff --git a/kollacli/common/properties.py b/kollacli/common/properties.py index 03888d8..b8ce43a 100644 --- a/kollacli/common/properties.py +++ b/kollacli/common/properties.py @@ -22,7 +22,6 @@ from kollacli.common.inventory import Inventory from kollacli.common.utils import change_property from kollacli.common.utils import get_group_vars_dir from kollacli.common.utils import get_host_vars_dir -from kollacli.common.utils import get_kolla_etc from kollacli.common.utils import get_kolla_home from kollacli.common.utils import sync_read_file from kollacli.exceptions import CommandError @@ -30,7 +29,7 @@ from kollacli.exceptions import CommandError LOG = logging.getLogger(__name__) ALLVARS_PATH = 'ansible/group_vars/all.yml' -GLOBALS_FILENAME = 'globals.yml' +GLOBALS_PATH = 'ansible/group_vars/__GLOBAL__' ANSIBLE_ROLES_PATH = 'ansible/roles' ANSIBLE_DEFAULTS_PATH = 'defaults/main.yml' @@ -41,11 +40,14 @@ class AnsibleProperties(object): load_hosts=True): """initialize ansible property information - property information is pulled from the following files: - KOLLA_ETC/globals.yml - KOLLA_ETC/passwords.yml - KOLLA_HOME/group_vars/all.yml + property information is pulled from the following files + (from lowest to highest priority): KOLLA_HOME/ansible/roles//default/main.yml + KOLLA_HOME/ansible/group_vars/all.yml + KOLLA_HOME/ansible/group_vars/__GLOBAL__ + KOLLA_HOME/ansible/group_vars/* + KOLLA_HOME/ansible/host_vars/* + KOLLA_ETC/passwords.yml """ self.globals_path = '' self.global_props = [] @@ -93,7 +95,7 @@ class AnsibleProperties(object): self.unique_global_props[key] = ansible_prop def _load_properties_global(self): - self.globals_path = os.path.join(get_kolla_etc(), GLOBALS_FILENAME) + self.globals_path = os.path.join(get_kolla_home(), GLOBALS_PATH) globals_data = sync_read_file(self.globals_path) globals_contents = yaml.safe_load(globals_data) for key, value in globals_contents.items(): @@ -105,7 +107,7 @@ class AnsibleProperties(object): override_flags.ovr_global = True orig_value = self.unique_global_props[key].value ansible_prop = AnsibleProperty(key, value, - GLOBALS_FILENAME, + 'group_vars/__GLOBAL', overrides, orig_value) ansible_prop.override_flags = override_flags self.global_props.append(ansible_prop) @@ -145,8 +147,8 @@ class AnsibleProperties(object): if (groupfile == 'all.yml'): continue self.group_props[groupfile] = [] - # don't load __RESERVED__ as a group property list as it is globals - if groupfile == '__RESERVED__': + # don't load __GLOBAL__ as a group property list as it is globals + if groupfile == '__GLOBAL__': continue with open(os.path.join(group_dir, groupfile)) as group_data: group_contents = yaml.safe_load(group_data) diff --git a/kollacli/common/support.py b/kollacli/common/support.py index a5c1149..c92a884 100644 --- a/kollacli/common/support.py +++ b/kollacli/common/support.py @@ -47,7 +47,6 @@ def dump(): kolla_docs = os.path.join(kolla_home, 'docs') kolla_etc = get_kolla_etc() kolla_config = os.path.join(kolla_etc, 'config') - kolla_globals = os.path.join(kolla_etc, 'globals.yml') kollacli_etc = get_kollacli_etc().rstrip('/') ketc = 'kolla/etc/' kshare = 'kolla/share/' @@ -66,8 +65,6 @@ def dump(): # file is accessible by the kolla user only (not kolla group) tar.add(kolla_config, arcname=ketc + os.path.basename(kolla_config)) - tar.add(kolla_globals, - arcname=ketc + os.path.basename(kolla_globals)) tar.add(kollacli_etc, arcname=ketc + os.path.basename(kollacli_etc)) diff --git a/kollacli/common/utils.py b/kollacli/common/utils.py index f47d475..0134427 100644 --- a/kollacli/common/utils.py +++ b/kollacli/common/utils.py @@ -269,7 +269,7 @@ def safe_decode(text): """Convert bytes or string to unicode string""" try: text = text.decode('utf-8') - except AttributeError: + except AttributeError: # nosec # py3 will raise if text is already a string pass return text diff --git a/tests/property.py b/tests/property.py index 54046d3..acc06d8 100644 --- a/tests/property.py +++ b/tests/property.py @@ -20,7 +20,6 @@ import unittest from kollacli.common.utils import get_group_vars_dir from kollacli.common.utils import get_host_vars_dir -from kollacli.common.utils import get_kolla_etc from kollacli.common.utils import get_kolla_home from kollacli.common.inventory import Inventory @@ -29,7 +28,7 @@ from kollacli.common.inventory import Inventory class TestFunctional(KollaCliTest): def test_properties(self): - # test globals.yml properties + # test global properties self._properties_test() # test single group vars @@ -146,7 +145,8 @@ class TestFunctional(KollaCliTest): sizes[path] = [os.path.getsize(path)] if not switch: self.run_cli_cmd('property clear %s' % key) - path = os.path.join(get_kolla_etc(), 'globals.yml') + path = os.path.join(get_kolla_home(), + 'ansible/group_vars/__GLOBAL__') sizes[path] = [os.path.getsize(path)] # test append @@ -211,7 +211,7 @@ class TestFunctional(KollaCliTest): prop['Property Value'] == value): ok = True if not ok: - error_msg = '%s:%s is missing in globals.yml' + error_msg = '%s:%s is missing in __GLOBAL__' else: target_map = {} for target in targets: diff --git a/tests/support.py b/tests/support.py index a1849bb..022b20e 100644 --- a/tests/support.py +++ b/tests/support.py @@ -46,7 +46,6 @@ class TestFunctional(KollaCliTest): def test_dump(self): check_files = [ 'var/log/kolla/kolla.log', - 'kolla/etc/globals.yml', 'kolla/etc/config/nova/nova-api.conf', 'kolla/etc/kollacli/ansible/inventory.json', 'kolla/share/ansible/site.yml',