From 6e589d17937d33b422dec81ccb4ee7ece5aeba40 Mon Sep 17 00:00:00 2001 From: Alex Kavanagh Date: Wed, 5 Apr 2017 15:20:50 +0100 Subject: [PATCH] Use charmhelpers OPENSTACK_RELEASES instead of internal KNOWN_RELEASES As part of the fix-alpha-comparisons-1659575 topic, OpenStack reactive charms that use charms.openstack don't generally need an update. However, it was noticed that charms.openstack used its own list, as it predated the charm-helpers version. In order to only have to maintain the list in one place (contrib.openstack.utils.OPENSTACK_RELEASES) this changeset removes the internal list and uses the external list. The py27 test has been disabled as the charms.reactive library has become py3.5+ only. However, the gate retains the test (policy) so we need to just disable the py27 here in the tox.ini. Change-Id: Iaa08252e5093f69a201af2a61cbe952d3ab3b171 Related-Bug: #1659575 --- charms_openstack/adapters.py | 7 +++--- charms_openstack/charm.py | 17 +++++++-------- charms_openstack/os_release_data.py | 33 ----------------------------- tox.ini | 3 +++ unit_tests/__init__.py | 19 +++++++++++++++++ 5 files changed, 33 insertions(+), 46 deletions(-) delete mode 100644 charms_openstack/os_release_data.py diff --git a/charms_openstack/adapters.py b/charms_openstack/adapters.py index 12e1629..6164cfc 100644 --- a/charms_openstack/adapters.py +++ b/charms_openstack/adapters.py @@ -29,7 +29,6 @@ import charmhelpers.contrib.openstack.utils as ch_utils import charmhelpers.core.hookenv as hookenv import charmhelpers.core.host as ch_host import charms_openstack.ip as os_ip -import charms_openstack.os_release_data as os_release_data ADDRESS_TYPES = os_ip.ADDRESS_MAP.keys() @@ -807,10 +806,10 @@ class APIConfigurationAdapter(ConfigurationAdapter): def use_memcache(self): release = ch_utils.get_os_codename_install_source( self.openstack_origin) - if release not in os_release_data.KNOWN_RELEASES: + if release not in ch_utils.OPENSTACK_RELEASES: return ValueError("Unkown release {}".format(release)) - return (os_release_data.KNOWN_RELEASES.index(release) >= - os_release_data.KNOWN_RELEASES.index('mitaka')) + return (ch_utils.OPENSTACK_RELEASES.index(release) >= + ch_utils.OPENSTACK_RELEASES.index('mitaka')) @property def memcache_server(self): diff --git a/charms_openstack/charm.py b/charms_openstack/charm.py index 365e8f1..8509d98 100644 --- a/charms_openstack/charm.py +++ b/charms_openstack/charm.py @@ -44,7 +44,6 @@ import charms.reactive as reactive import charms_openstack.adapters as os_adapters import charms_openstack.ip as os_ip -import charms_openstack.os_release_data as os_release_data # _releases{} is a dictionary of release -> class that is instantiated @@ -362,12 +361,12 @@ def get_charm_instance(release=None, *args, **kwargs): cls = _releases[known_releases[-1]] else: # check that the release is a valid release - if release not in os_release_data.KNOWN_RELEASES: + if release not in os_utils.OPENSTACK_RELEASES: raise RuntimeError( "Release {} is not a known OpenStack release?".format(release)) - release_index = os_release_data.KNOWN_RELEASES.index(release) + release_index = os_utils.OPENSTACK_RELEASES.index(release) if (release_index < - os_release_data.KNOWN_RELEASES.index(known_releases[0])): + os_utils.OPENSTACK_RELEASES.index(known_releases[0])): raise RuntimeError( "Release {} is not supported by this charm. Earliest support " "is {} release".format(release, known_releases[0])) @@ -375,7 +374,7 @@ def get_charm_instance(release=None, *args, **kwargs): # try to find the release that is supported. for known_release in reversed(known_releases): if (release_index >= - os_release_data.KNOWN_RELEASES.index(known_release)): + os_utils.OPENSTACK_RELEASES.index(known_release)): cls = _releases[known_release] break if cls is None: @@ -445,7 +444,7 @@ class OpenStackCharmMeta(type): return if 'release' in members.keys(): release = members['release'] - if release not in os_release_data.KNOWN_RELEASES: + if release not in os_utils.OPENSTACK_RELEASES: raise RuntimeError( "Release {} is not a known OpenStack release" .format(release)) @@ -1260,10 +1259,10 @@ class OpenStackAPICharm(OpenStackCharm): if not release: release = os_utils.get_os_codename_install_source( self.config['openstack-origin']) - if release not in os_release_data.KNOWN_RELEASES: + if release not in os_utils.OPENSTACK_RELEASES: return ValueError("Unkown release {}".format(release)) - return (os_release_data.KNOWN_RELEASES.index(release) >= - os_release_data.KNOWN_RELEASES.index('mitaka')) + return (os_utils.OPENSTACK_RELEASES.index(release) >= + os_utils.OPENSTACK_RELEASES.index('mitaka')) def token_cache_pkgs(self, release=None): """Determine additional packages needed for token caching diff --git a/charms_openstack/os_release_data.py b/charms_openstack/os_release_data.py deleted file mode 100644 index 09c27f4..0000000 --- a/charms_openstack/os_release_data.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2016 Canonical Ltd -# -# 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. - -# OpenStackCharm() - base class for build OpenStack charms from for the -# reactive framework. - -# need/want absolute imports for the package imports to work properly - -KNOWN_RELEASES = [ - 'diablo', - 'essex', - 'folsom', - 'grizzly', - 'havana', - 'icehouse', - 'juno', - 'kilo', - 'liberty', - 'mitaka', - 'newton', - 'ocata', -] diff --git a/tox.ini b/tox.ini index 7c03dd2..c7367e5 100644 --- a/tox.ini +++ b/tox.ini @@ -13,6 +13,9 @@ commands = ostestr {posargs} [testenv:py27] basepython = python2.7 deps = -r{toxinidir}/test-requirements.txt +# Py27 needs to be disabled as upstream charms.reactive is not Py3.5+ only +# However, we can't yet remove the actually py27 test from the gate. +commands = python -c "print('Py27 testing disabled.')" && /bin/true [testenv:py34] basepython = python3.4 diff --git a/unit_tests/__init__.py b/unit_tests/__init__.py index bb7dd6a..f7dba04 100644 --- a/unit_tests/__init__.py +++ b/unit_tests/__init__.py @@ -41,6 +41,25 @@ sys.modules['charmhelpers.contrib.hahelpers'] = charmhelpers.contrib.hahelpers sys.modules['charmhelpers.contrib.hahelpers.cluster'] = ( charmhelpers.contrib.hahelpers.cluster) +# mock in the openstack releases so that the tests can run +# Note that these don't need to be maintained UNLESS new functionality is for +# later OpenStack releases. +charmhelpers.contrib.openstack.utils.OPENSTACK_RELEASES = ( + 'diablo', + 'essex', + 'folsom', + 'grizzly', + 'havana', + 'icehouse', + 'juno', + 'kilo', + 'liberty', + 'mitaka', + 'newton', + 'ocata', + 'pike', +) + def _fake_retry(num_retries, base_delay=0, exc_type=Exception): def _retry_on_exception_inner_1(f):