From 27f4060e79970c1c19f689f96b86dd464b88b065 Mon Sep 17 00:00:00 2001 From: David Della Vecchia Date: Mon, 28 Sep 2015 21:24:44 +0000 Subject: [PATCH 1/8] Implementing new charmhelpers-based upgrade action --- actions.yaml | 2 + actions/openstack-upgrade | 29 +++++++++ actions/openstack_upgrade.py | 29 +++++++++ charm-helpers-hooks.yaml | 2 +- config.yaml | 10 +++ hooks/charmhelpers/contrib/network/ip.py | 8 ++- .../contrib/openstack/amulet/utils.py | 2 +- .../charmhelpers/contrib/openstack/context.py | 13 +++- .../contrib/openstack/templating.py | 3 +- hooks/charmhelpers/contrib/openstack/utils.py | 56 ++++++++++++++++- hooks/charmhelpers/core/hookenv.py | 32 ++++++++++ hooks/nova_compute_hooks.py | 2 +- tests/charmhelpers/contrib/amulet/utils.py | 63 ++++++++++++++----- .../contrib/openstack/amulet/utils.py | 2 +- unit_tests/test_actions_openstack_upgrade.py | 62 ++++++++++++++++++ unit_tests/test_nova_compute_hooks.py | 9 +++ 16 files changed, 298 insertions(+), 26 deletions(-) create mode 100755 actions/openstack-upgrade create mode 100755 actions/openstack_upgrade.py create mode 100644 unit_tests/test_actions_openstack_upgrade.py diff --git a/actions.yaml b/actions.yaml index f5b64c38..92f46a1b 100644 --- a/actions.yaml +++ b/actions.yaml @@ -1,2 +1,4 @@ git-reinstall: description: Reinstall nova-compute from the openstack-origin-git repositories. +openstack-upgrade: + description: Perform openstack upgrades. Config option action-managed-upgrade must be set to True. diff --git a/actions/openstack-upgrade b/actions/openstack-upgrade new file mode 100755 index 00000000..dfdadbf9 --- /dev/null +++ b/actions/openstack-upgrade @@ -0,0 +1,29 @@ +#!/usr/bin/python + +from nova_compute_hooks import ( + config_changed, + CONFIGS +) + +from charmhelpers.contrib.openstack.utils import ( + do_action_openstack_upgrade, +) + +from nova_compute_utils import do_openstack_upgrade + + +def openstack_upgrade(): + """Upgrade packages to config-set Openstack version. + + If the charm was installed from source we cannot upgrade it. + For backwards compatibility a config flag must be set for this + code to run, otherwise a full service level upgrade will fire + on config-changed.""" + + if (do_action_openstack_upgrade('nova_compute-common', + do_openstack_upgrade, + CONFIGS)): + config_changed() + +if __name__ == '__main__': + openstack_upgrade() diff --git a/actions/openstack_upgrade.py b/actions/openstack_upgrade.py new file mode 100755 index 00000000..dfdadbf9 --- /dev/null +++ b/actions/openstack_upgrade.py @@ -0,0 +1,29 @@ +#!/usr/bin/python + +from nova_compute_hooks import ( + config_changed, + CONFIGS +) + +from charmhelpers.contrib.openstack.utils import ( + do_action_openstack_upgrade, +) + +from nova_compute_utils import do_openstack_upgrade + + +def openstack_upgrade(): + """Upgrade packages to config-set Openstack version. + + If the charm was installed from source we cannot upgrade it. + For backwards compatibility a config flag must be set for this + code to run, otherwise a full service level upgrade will fire + on config-changed.""" + + if (do_action_openstack_upgrade('nova_compute-common', + do_openstack_upgrade, + CONFIGS)): + config_changed() + +if __name__ == '__main__': + openstack_upgrade() diff --git a/charm-helpers-hooks.yaml b/charm-helpers-hooks.yaml index 5fb8d7b3..45b58b42 100644 --- a/charm-helpers-hooks.yaml +++ b/charm-helpers-hooks.yaml @@ -1,4 +1,4 @@ -branch: lp:~hopem/charm-helpers/add-rbd-cache-config-support +branch: lp:charm-helpers destination: hooks/charmhelpers include: - core diff --git a/config.yaml b/config.yaml index 38594672..e7e846c9 100644 --- a/config.yaml +++ b/config.yaml @@ -265,3 +265,13 @@ options: description: | The pecentage of system memory to use for hugepages eg '10%' or the total number of 2M hugepages - eg "1024". + action-managed-upgrade: + type: boolean + default: False + description: | + If True enables openstack upgrades for this charm via juju actions. + You will still need to set openstack-origin to the new repository but + instead of an upgrade running automatically across all units, it will + wait for you to execute the openstack-upgrade action for this charm on + each unit. If False it will revert to existing behavior of upgrading + all units on config change. diff --git a/hooks/charmhelpers/contrib/network/ip.py b/hooks/charmhelpers/contrib/network/ip.py index 67b4dccc..7f3b66b1 100644 --- a/hooks/charmhelpers/contrib/network/ip.py +++ b/hooks/charmhelpers/contrib/network/ip.py @@ -23,7 +23,7 @@ import socket from functools import partial from charmhelpers.core.hookenv import unit_get -from charmhelpers.fetch import apt_install +from charmhelpers.fetch import apt_install, apt_update from charmhelpers.core.hookenv import ( log, WARNING, @@ -32,13 +32,15 @@ from charmhelpers.core.hookenv import ( try: import netifaces except ImportError: - apt_install('python-netifaces') + apt_update(fatal=True) + apt_install('python-netifaces', fatal=True) import netifaces try: import netaddr except ImportError: - apt_install('python-netaddr') + apt_update(fatal=True) + apt_install('python-netaddr', fatal=True) import netaddr diff --git a/hooks/charmhelpers/contrib/openstack/amulet/utils.py b/hooks/charmhelpers/contrib/openstack/amulet/utils.py index b1397419..2b3087ea 100644 --- a/hooks/charmhelpers/contrib/openstack/amulet/utils.py +++ b/hooks/charmhelpers/contrib/openstack/amulet/utils.py @@ -752,7 +752,7 @@ class OpenStackAmuletUtils(AmuletUtils): self.log.debug('SSL is enabled @{}:{} ' '({})'.format(host, port, unit_name)) return True - elif not port and not conf_ssl: + elif not conf_ssl: self.log.debug('SSL not enabled @{}:{} ' '({})'.format(host, port, unit_name)) return False diff --git a/hooks/charmhelpers/contrib/openstack/context.py b/hooks/charmhelpers/contrib/openstack/context.py index 1248d49f..34c26fa9 100644 --- a/hooks/charmhelpers/contrib/openstack/context.py +++ b/hooks/charmhelpers/contrib/openstack/context.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with charm-helpers. If not, see . +import glob import json import os import re @@ -1378,8 +1379,18 @@ class PhyNICMTUContext(DataPortContext): ports = mappings.values() napi_settings = NeutronAPIContext()() mtu = napi_settings.get('network_device_mtu') + all_ports = set() + # If any of ports is a vlan device, its underlying device must have + # mtu applied first. + for port in ports: + for lport in glob.glob("/sys/class/net/%s/lower_*" % port): + lport = os.path.basename(lport) + all_ports.add(lport.split('_')[1]) + + all_ports = list(all_ports) + all_ports.extend(ports) if mtu: - ctxt["devs"] = '\\n'.join(ports) + ctxt["devs"] = '\\n'.join(all_ports) ctxt['mtu'] = mtu return ctxt diff --git a/hooks/charmhelpers/contrib/openstack/templating.py b/hooks/charmhelpers/contrib/openstack/templating.py index 0813719a..e5e3cb1b 100644 --- a/hooks/charmhelpers/contrib/openstack/templating.py +++ b/hooks/charmhelpers/contrib/openstack/templating.py @@ -18,7 +18,7 @@ import os import six -from charmhelpers.fetch import apt_install +from charmhelpers.fetch import apt_install, apt_update from charmhelpers.core.hookenv import ( log, ERROR, @@ -29,6 +29,7 @@ from charmhelpers.contrib.openstack.utils import OPENSTACK_CODENAMES try: from jinja2 import FileSystemLoader, ChoiceLoader, Environment, exceptions except ImportError: + apt_update(fatal=True) apt_install('python-jinja2', fatal=True) from jinja2 import FileSystemLoader, ChoiceLoader, Environment, exceptions diff --git a/hooks/charmhelpers/contrib/openstack/utils.py b/hooks/charmhelpers/contrib/openstack/utils.py index 47a4c22f..eefcf08b 100644 --- a/hooks/charmhelpers/contrib/openstack/utils.py +++ b/hooks/charmhelpers/contrib/openstack/utils.py @@ -25,6 +25,7 @@ import sys import re import six +import traceback import yaml from charmhelpers.contrib.network import ip @@ -34,6 +35,8 @@ from charmhelpers.core import ( ) from charmhelpers.core.hookenv import ( + action_fail, + action_set, config, log as juju_log, charm_dir, @@ -51,7 +54,8 @@ from charmhelpers.contrib.storage.linux.lvm import ( ) from charmhelpers.contrib.network.ip import ( - get_ipv6_addr + get_ipv6_addr, + is_ipv6, ) from charmhelpers.contrib.python.packages import ( @@ -516,6 +520,12 @@ def sync_db_with_multi_ipv6_addresses(database, database_user, relation_prefix=None): hosts = get_ipv6_addr(dynamic_only=False) + if config('vip'): + vips = config('vip').split() + for vip in vips: + if vip and is_ipv6(vip): + hosts.append(vip) + kwargs = {'database': database, 'username': database_user, 'hostname': json.dumps(hosts)} @@ -921,3 +931,47 @@ def incomplete_relation_data(configs, required_interfaces): for i in incomplete_relations: incomplete_context_data[i] = configs.get_incomplete_context_data(required_interfaces[i]) return incomplete_context_data + + +def do_action_openstack_upgrade(package, upgrade_callback, configs): + """Perform action-managed OpenStack upgrade. + + Upgrades packages to the configured openstack-origin version and sets + the corresponding action status as a result. + + If the charm was installed from source we cannot upgrade it. + For backwards compatibility a config flag (action-managed-upgrade) must + be set for this code to run, otherwise a full service level upgrade will + fire on config-changed. + + @param package: package name for determining if upgrade available + @param upgrade_callback: function callback to charm's upgrade function + @param configs: templating object derived from OSConfigRenderer class + + @return: True if upgrade successful; False if upgrade failed or skipped + """ + ret = False + + if git_install_requested(): + action_set({'outcome': 'installed from source, skipped upgrade.'}) + else: + if openstack_upgrade_available(package): + if config('action-managed-upgrade'): + juju_log('Upgrading OpenStack release') + + try: + upgrade_callback(configs=configs) + action_set({'outcome': 'success, upgrade completed.'}) + ret = True + except: + action_set({'outcome': 'upgrade failed, see traceback.'}) + action_set({'traceback': traceback.format_exc()}) + action_fail('do_openstack_upgrade resulted in an ' + 'unexpected error') + else: + action_set({'outcome': 'action-managed-upgrade config is ' + 'False, skipped upgrade.'}) + else: + action_set({'outcome': 'no upgrade available.'}) + + return ret diff --git a/hooks/charmhelpers/core/hookenv.py b/hooks/charmhelpers/core/hookenv.py index ab53a780..c2bee134 100644 --- a/hooks/charmhelpers/core/hookenv.py +++ b/hooks/charmhelpers/core/hookenv.py @@ -623,6 +623,38 @@ def unit_private_ip(): return unit_get('private-address') +@cached +def storage_get(attribute="", storage_id=""): + """Get storage attributes""" + _args = ['storage-get', '--format=json'] + if storage_id: + _args.extend(('-s', storage_id)) + if attribute: + _args.append(attribute) + try: + return json.loads(subprocess.check_output(_args).decode('UTF-8')) + except ValueError: + return None + + +@cached +def storage_list(storage_name=""): + """List the storage IDs for the unit""" + _args = ['storage-list', '--format=json'] + if storage_name: + _args.append(storage_name) + try: + return json.loads(subprocess.check_output(_args).decode('UTF-8')) + except ValueError: + return None + except OSError as e: + import errno + if e.errno == errno.ENOENT: + # storage-list does not exist + return [] + raise + + class UnregisteredHookError(Exception): """Raised when an undefined hook is called""" pass diff --git a/hooks/nova_compute_hooks.py b/hooks/nova_compute_hooks.py index df58bb10..f184c704 100755 --- a/hooks/nova_compute_hooks.py +++ b/hooks/nova_compute_hooks.py @@ -106,7 +106,7 @@ def config_changed(): if git_install_requested(): if config_value_changed('openstack-origin-git'): git_install(config('openstack-origin-git')) - else: + elif not config('action-managed-upgrade'): if openstack_upgrade_available('nova-common'): CONFIGS = do_openstack_upgrade() diff --git a/tests/charmhelpers/contrib/amulet/utils.py b/tests/charmhelpers/contrib/amulet/utils.py index 55c86347..2591a9b1 100644 --- a/tests/charmhelpers/contrib/amulet/utils.py +++ b/tests/charmhelpers/contrib/amulet/utils.py @@ -326,7 +326,7 @@ class AmuletUtils(object): def service_restarted_since(self, sentry_unit, mtime, service, pgrep_full=None, sleep_time=20, - retry_count=2, retry_sleep_time=30): + retry_count=30, retry_sleep_time=10): """Check if service was been started after a given time. Args: @@ -334,8 +334,9 @@ class AmuletUtils(object): mtime (float): The epoch time to check against service (string): service name to look for in process table pgrep_full: [Deprecated] Use full command line search mode with pgrep - sleep_time (int): Seconds to sleep before looking for process - retry_count (int): If service is not found, how many times to retry + sleep_time (int): Initial sleep time (s) before looking for file + retry_sleep_time (int): Time (s) to sleep between retries + retry_count (int): If file is not found, how many times to retry Returns: bool: True if service found and its start time it newer than mtime, @@ -359,11 +360,12 @@ class AmuletUtils(object): pgrep_full) self.log.debug('Attempt {} to get {} proc start time on {} ' 'OK'.format(tries, service, unit_name)) - except IOError: + except IOError as e: # NOTE(beisner) - race avoidance, proc may not exist yet. # https://bugs.launchpad.net/charm-helpers/+bug/1474030 self.log.debug('Attempt {} to get {} proc start time on {} ' - 'failed'.format(tries, service, unit_name)) + 'failed\n{}'.format(tries, service, + unit_name, e)) time.sleep(retry_sleep_time) tries += 1 @@ -383,35 +385,62 @@ class AmuletUtils(object): return False def config_updated_since(self, sentry_unit, filename, mtime, - sleep_time=20): + sleep_time=20, retry_count=30, + retry_sleep_time=10): """Check if file was modified after a given time. Args: sentry_unit (sentry): The sentry unit to check the file mtime on filename (string): The file to check mtime of mtime (float): The epoch time to check against - sleep_time (int): Seconds to sleep before looking for process + sleep_time (int): Initial sleep time (s) before looking for file + retry_sleep_time (int): Time (s) to sleep between retries + retry_count (int): If file is not found, how many times to retry Returns: bool: True if file was modified more recently than mtime, False if - file was modified before mtime, + file was modified before mtime, or if file not found. """ - self.log.debug('Checking %s updated since %s' % (filename, mtime)) + unit_name = sentry_unit.info['unit_name'] + self.log.debug('Checking that %s updated since %s on ' + '%s' % (filename, mtime, unit_name)) time.sleep(sleep_time) - file_mtime = self._get_file_mtime(sentry_unit, filename) + file_mtime = None + tries = 0 + while tries <= retry_count and not file_mtime: + try: + file_mtime = self._get_file_mtime(sentry_unit, filename) + self.log.debug('Attempt {} to get {} file mtime on {} ' + 'OK'.format(tries, filename, unit_name)) + except IOError as e: + # NOTE(beisner) - race avoidance, file may not exist yet. + # https://bugs.launchpad.net/charm-helpers/+bug/1474030 + self.log.debug('Attempt {} to get {} file mtime on {} ' + 'failed\n{}'.format(tries, filename, + unit_name, e)) + time.sleep(retry_sleep_time) + tries += 1 + + if not file_mtime: + self.log.warn('Could not determine file mtime, assuming ' + 'file does not exist') + return False + if file_mtime >= mtime: self.log.debug('File mtime is newer than provided mtime ' - '(%s >= %s)' % (file_mtime, mtime)) + '(%s >= %s) on %s (OK)' % (file_mtime, + mtime, unit_name)) return True else: - self.log.warn('File mtime %s is older than provided mtime %s' - % (file_mtime, mtime)) + self.log.warn('File mtime is older than provided mtime' + '(%s < on %s) on %s' % (file_mtime, + mtime, unit_name)) return False def validate_service_config_changed(self, sentry_unit, mtime, service, filename, pgrep_full=None, - sleep_time=20, retry_count=2, - retry_sleep_time=30): + sleep_time=20, retry_count=30, + retry_sleep_time=10): """Check service and file were updated after mtime Args: @@ -456,7 +485,9 @@ class AmuletUtils(object): sentry_unit, filename, mtime, - sleep_time=0) + sleep_time=sleep_time, + retry_count=retry_count, + retry_sleep_time=retry_sleep_time) return service_restart and config_update diff --git a/tests/charmhelpers/contrib/openstack/amulet/utils.py b/tests/charmhelpers/contrib/openstack/amulet/utils.py index b1397419..2b3087ea 100644 --- a/tests/charmhelpers/contrib/openstack/amulet/utils.py +++ b/tests/charmhelpers/contrib/openstack/amulet/utils.py @@ -752,7 +752,7 @@ class OpenStackAmuletUtils(AmuletUtils): self.log.debug('SSL is enabled @{}:{} ' '({})'.format(host, port, unit_name)) return True - elif not port and not conf_ssl: + elif not conf_ssl: self.log.debug('SSL not enabled @{}:{} ' '({})'.format(host, port, unit_name)) return False diff --git a/unit_tests/test_actions_openstack_upgrade.py b/unit_tests/test_actions_openstack_upgrade.py new file mode 100644 index 00000000..5c295b0a --- /dev/null +++ b/unit_tests/test_actions_openstack_upgrade.py @@ -0,0 +1,62 @@ +from mock import patch +import os + +os.environ['JUJU_UNIT_NAME'] = 'nova_compute' + +with patch('charmhelpers.core.hookenv.config') as config: + config.return_value = 'nova' + import nova_compute_utils as utils # noqa + +with patch('nova_compute_utils.restart_map'): + with patch('nova_compute_utils.register_configs'): + import openstack_upgrade + +from test_utils import ( + CharmTestCase +) + +TO_PATCH = [ + 'config_changed', + 'do_openstack_upgrade' +] + + +class TestNovaComputeUpgradeActions(CharmTestCase): + + def setUp(self): + super(TestNovaComputeUpgradeActions, self).setUp(openstack_upgrade, + TO_PATCH) + + @patch('charmhelpers.contrib.openstack.utils.config') + @patch('charmhelpers.contrib.openstack.utils.action_set') + @patch('charmhelpers.contrib.openstack.utils.git_install_requested') + @patch('charmhelpers.contrib.openstack.utils.openstack_upgrade_available') + @patch('charmhelpers.contrib.openstack.utils.juju_log') + def test_openstack_upgrade_true(self, log, upgrade_avail, git_requested, + action_set, config): + + git_requested.return_value = False + upgrade_avail.return_value = True + config.return_value = True + + openstack_upgrade.openstack_upgrade() + + self.assertTrue(self.do_openstack_upgrade.called) + self.assertTrue(self.config_changed.called) + + @patch('charmhelpers.contrib.openstack.utils.config') + @patch('charmhelpers.contrib.openstack.utils.action_set') + @patch('charmhelpers.contrib.openstack.utils.git_install_requested') # noqa + @patch('charmhelpers.contrib.openstack.utils.openstack_upgrade_available') # noqa + @patch('charmhelpers.contrib.openstack.utils.juju_log') + def test_openstack_upgrade_false(self, log, upgrade_avail, git_requested, + action_set, config): + + git_requested.return_value = False + upgrade_avail.return_value = True + config.return_value = False + + openstack_upgrade.openstack_upgrade() + + self.assertFalse(self.do_openstack_upgrade.called) + self.assertFalse(self.config_changed.called) diff --git a/unit_tests/test_nova_compute_hooks.py b/unit_tests/test_nova_compute_hooks.py index 70440773..aca839a4 100644 --- a/unit_tests/test_nova_compute_hooks.py +++ b/unit_tests/test_nova_compute_hooks.py @@ -115,6 +115,15 @@ class NovaComputeRelationsTests(CharmTestCase): hooks.config_changed() self.assertTrue(self.do_openstack_upgrade.called) + @patch.object(hooks, 'git_install_requested') + def test_config_changed_with_openstack_upgrade_action(self, git_requested): + git_requested.return_value = False + self.openstack_upgrade_available.return_value = True + self.test_config.set('action-managed-upgrade', True) + + hooks.config_changed() + self.assertFalse(self.do_openstack_upgrade.called) + @patch.object(hooks, 'compute_joined') def test_config_changed_with_migration(self, compute_joined): self.git_install_requested.return_value = False From 2a88553fe228057f0dc44caf14e2149f70611fdc Mon Sep 17 00:00:00 2001 From: David Della Vecchia Date: Mon, 5 Oct 2015 14:55:59 +0000 Subject: [PATCH 2/8] adding proper path --- actions/openstack_upgrade.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/actions/openstack_upgrade.py b/actions/openstack_upgrade.py index dfdadbf9..76a5bf43 100755 --- a/actions/openstack_upgrade.py +++ b/actions/openstack_upgrade.py @@ -1,4 +1,7 @@ #!/usr/bin/python +import sys + +sys.path.append('hooks/') from nova_compute_hooks import ( config_changed, From f63e4eda4fbeaf01c14ff5d0aba0c3300700d3c0 Mon Sep 17 00:00:00 2001 From: David Della Vecchia Date: Mon, 5 Oct 2015 16:25:44 +0000 Subject: [PATCH 3/8] re-ordering imports for debugging --- actions/openstack_upgrade.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/actions/openstack_upgrade.py b/actions/openstack_upgrade.py index 76a5bf43..dfb80682 100755 --- a/actions/openstack_upgrade.py +++ b/actions/openstack_upgrade.py @@ -3,17 +3,17 @@ import sys sys.path.append('hooks/') -from nova_compute_hooks import ( - config_changed, - CONFIGS -) - from charmhelpers.contrib.openstack.utils import ( do_action_openstack_upgrade, ) from nova_compute_utils import do_openstack_upgrade +from nova_compute_hooks import ( + config_changed, + CONFIGS +) + def openstack_upgrade(): """Upgrade packages to config-set Openstack version. From 4aa1db01c60d936522a0a7404ad10aad990850c5 Mon Sep 17 00:00:00 2001 From: David Della Vecchia Date: Mon, 5 Oct 2015 22:56:56 +0000 Subject: [PATCH 4/8] removing openstack-upgrade file that should be a symlink --- actions/openstack-upgrade | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) mode change 100755 => 120000 actions/openstack-upgrade diff --git a/actions/openstack-upgrade b/actions/openstack-upgrade deleted file mode 100755 index dfdadbf9..00000000 --- a/actions/openstack-upgrade +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/python - -from nova_compute_hooks import ( - config_changed, - CONFIGS -) - -from charmhelpers.contrib.openstack.utils import ( - do_action_openstack_upgrade, -) - -from nova_compute_utils import do_openstack_upgrade - - -def openstack_upgrade(): - """Upgrade packages to config-set Openstack version. - - If the charm was installed from source we cannot upgrade it. - For backwards compatibility a config flag must be set for this - code to run, otherwise a full service level upgrade will fire - on config-changed.""" - - if (do_action_openstack_upgrade('nova_compute-common', - do_openstack_upgrade, - CONFIGS)): - config_changed() - -if __name__ == '__main__': - openstack_upgrade() diff --git a/actions/openstack-upgrade b/actions/openstack-upgrade new file mode 120000 index 00000000..61793013 --- /dev/null +++ b/actions/openstack-upgrade @@ -0,0 +1 @@ +openstack_upgrade.py \ No newline at end of file From acdee0ad323685eed1a756d1b492ea9b19f4afb3 Mon Sep 17 00:00:00 2001 From: David Della Vecchia Date: Tue, 6 Oct 2015 15:14:02 +0000 Subject: [PATCH 5/8] updating charmhelpers --- hooks/charmhelpers/contrib/openstack/context.py | 6 +++--- hooks/charmhelpers/contrib/openstack/neutron.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/hooks/charmhelpers/contrib/openstack/context.py b/hooks/charmhelpers/contrib/openstack/context.py index 34c26fa9..49c04de0 100644 --- a/hooks/charmhelpers/contrib/openstack/context.py +++ b/hooks/charmhelpers/contrib/openstack/context.py @@ -1364,7 +1364,7 @@ class DataPortContext(NeutronPortContext): normalized.update({port: port for port in resolved if port in ports}) if resolved: - return {bridge: normalized[port] for port, bridge in + return {normalized[port]: bridge for port, bridge in six.iteritems(portmap) if port in normalized.keys()} return None @@ -1375,8 +1375,8 @@ class PhyNICMTUContext(DataPortContext): def __call__(self): ctxt = {} mappings = super(PhyNICMTUContext, self).__call__() - if mappings and mappings.values(): - ports = mappings.values() + if mappings and mappings.keys(): + ports = sorted(mappings.keys()) napi_settings = NeutronAPIContext()() mtu = napi_settings.get('network_device_mtu') all_ports = set() diff --git a/hooks/charmhelpers/contrib/openstack/neutron.py b/hooks/charmhelpers/contrib/openstack/neutron.py index 55b2037f..2a59d86b 100644 --- a/hooks/charmhelpers/contrib/openstack/neutron.py +++ b/hooks/charmhelpers/contrib/openstack/neutron.py @@ -310,10 +310,10 @@ def parse_bridge_mappings(mappings): def parse_data_port_mappings(mappings, default_bridge='br-data'): """Parse data port mappings. - Mappings must be a space-delimited list of port:bridge mappings. + Mappings must be a space-delimited list of bridge:port. - Returns dict of the form {port:bridge} where port may be an mac address or - interface name. + Returns dict of the form {port:bridge} where ports may be mac addresses or + interface names. """ # NOTE(dosaboy): we use rvalue for key to allow multiple values to be From 79a7e294bd082601dba7b3c46bb74863548cc6c2 Mon Sep 17 00:00:00 2001 From: David Della Vecchia Date: Tue, 6 Oct 2015 15:38:12 +0000 Subject: [PATCH 6/8] refactoring do_openstack_upgrade to accept configs argument, bringing it in line with the other openstack charms --- actions/openstack_upgrade.py | 2 +- hooks/nova_compute_hooks.py | 2 +- hooks/nova_compute_utils.py | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/actions/openstack_upgrade.py b/actions/openstack_upgrade.py index dfb80682..d9dc9e3d 100755 --- a/actions/openstack_upgrade.py +++ b/actions/openstack_upgrade.py @@ -23,7 +23,7 @@ def openstack_upgrade(): code to run, otherwise a full service level upgrade will fire on config-changed.""" - if (do_action_openstack_upgrade('nova_compute-common', + if (do_action_openstack_upgrade('nova-common', do_openstack_upgrade, CONFIGS)): config_changed() diff --git a/hooks/nova_compute_hooks.py b/hooks/nova_compute_hooks.py index f184c704..889a0df5 100755 --- a/hooks/nova_compute_hooks.py +++ b/hooks/nova_compute_hooks.py @@ -108,7 +108,7 @@ def config_changed(): git_install(config('openstack-origin-git')) elif not config('action-managed-upgrade'): if openstack_upgrade_available('nova-common'): - CONFIGS = do_openstack_upgrade() + do_openstack_upgrade(CONFIGS) sysctl_dict = config('sysctl') if sysctl_dict: diff --git a/hooks/nova_compute_utils.py b/hooks/nova_compute_utils.py index 15e7a535..e0a35998 100644 --- a/hooks/nova_compute_utils.py +++ b/hooks/nova_compute_utils.py @@ -523,7 +523,7 @@ def import_authorized_keys(user='root', prefix=None): _keys.write('{}\n'.format(authorized_keys[index])) -def do_openstack_upgrade(): +def do_openstack_upgrade(configs): # NOTE(jamespage) horrible hack to make utils forget a cached value import charmhelpers.contrib.openstack.utils as utils utils.os_rel = None @@ -543,10 +543,8 @@ def do_openstack_upgrade(): apt_install(determine_packages(), fatal=True) # Regenerate configs in full for new release - configs = register_configs() configs.write_all() [service_restart(s) for s in services()] - return configs def import_keystone_ca_cert():