Fix alphanumeric comparisons for openstack and ubuntu releases

- fix up code where the alpha comparisons are done
- refactor the code so that it uses, rather than fights,
  charms.openstack features.

Change-Id: Ie3b7fdd53ee73c700b8515dce4bd114cab72269d
Related-Bug: #1659575
This commit is contained in:
Alex Kavanagh 2017-03-29 21:23:27 +01:00
parent 809093bed3
commit 86e6ca60ab
2 changed files with 42 additions and 36 deletions

View File

@ -34,36 +34,26 @@ def overlay_net_types(config):
return ','.join(overlay_networks)
class NeutronAPIODLCharm(charms_openstack.charm.OpenStackCharm):
@charms_openstack.charm.register_os_release_selector
def choose_charm_class():
"""Choose the charm class based on the neutron-common package installed"""
return ch_utils.os_release('neutron-common')
class IcehouseNeutronAPIODLCharm(charms_openstack.charm.OpenStackCharm):
name = 'neutron-api-odl'
release = 'icehouse'
packages = ['neutron-common', 'neutron-plugin-ml2']
required_relations = ['neutron-plugin-api-subordinate', 'odl-controller']
restart_map = {ML2_CONF: []}
release = 'icehouse'
adapters_class = charms_openstack.adapters.OpenStackRelationAdapters
def __init__(self, release=None, **kwargs):
"""Custom initialiser for class
If no release is passed, then the charm determines the release from the
ch_utils.os_release() function.
"""
if release is None:
release = ch_utils.os_release('neutron-common')
super(NeutronAPIODLCharm, self).__init__(release=release, **kwargs)
@property
def all_packages(self):
"""List of packages to be installed
@return ['pkg1', 'pkg2', ...]
"""
_packages = self.packages[:]
if self.release >= 'kilo':
_packages.extend(['python-networking-odl'])
return _packages
# Custom configure for the class
service_plugins = 'router,firewall,lbaas,vpnaas,metering'
def configure_plugin(self, api_principle):
"""Add sections and tuples to insert values into neutron-server's
@ -79,19 +69,35 @@ class NeutronAPIODLCharm(charms_openstack.charm.OpenStackCharm):
}
}
}
if self.release >= 'newton':
# NOTE: LBaaS v2 for >= newton
service_plugins = (
'router,firewall,vpnaas,metering,'
'neutron_lbaas.services.loadbalancer.'
'plugin.LoadBalancerPluginv2'
)
else:
service_plugins = 'router,firewall,lbaas,vpnaas,metering'
api_principle.configure_plugin(
neutron_plugin='odl',
core_plugin='neutron.plugins.ml2.plugin.Ml2Plugin',
neutron_plugin_config='/etc/neutron/plugins/ml2/ml2_conf.ini',
service_plugins=service_plugins,
service_plugins=self.service_plugins,
subordinate_configuration=inject_config)
class KiloNeutronAPIODLCharm(IcehouseNeutronAPIODLCharm):
"""For the kilo release we have an additional package to install:
'python-networking-odl'
"""
release = 'kilo'
packages = ['neutron-common',
'neutron-plugin-ml2',
'python-networking-odl',
]
class NewtonNeutronAPIODLCharm(KiloNeutronAPIODLCharm):
"""For Newton, the service_plugins on the configuration is different.
"""
release = 'newton'
# NOTE: LBaaS v2 for >= newton
service_plugins = ('router,firewall,vpnaas,metering,'
'neutron_lbaas.services.loadbalancer.'
'plugin.LoadBalancerPluginv2')

View File

@ -25,7 +25,7 @@ class Helper(test_utils.PatchHelper):
def setUp(self):
super().setUp()
self.patch_release(neutron_api_odl.NeutronAPIODLCharm.release)
self.patch_release(neutron_api_odl.IcehouseNeutronAPIODLCharm.release)
class TestCustomProperties(Helper):
@ -46,7 +46,7 @@ class TestNeutronAPIODLCharm(Helper):
def test_all_packages(self):
self.patch_object(neutron_api_odl.ch_utils, 'os_release')
self.os_release.return_value = 'kilo'
c = neutron_api_odl.NeutronAPIODLCharm()
c = neutron_api_odl.KiloNeutronAPIODLCharm()
self.assertEqual(
c.all_packages,
['neutron-common', 'neutron-plugin-ml2', 'python-networking-odl'])
@ -54,8 +54,8 @@ class TestNeutronAPIODLCharm(Helper):
def test_configure_plugin(self):
principle_interface = mock.MagicMock()
self.patch_object(neutron_api_odl.ch_utils, 'os_release')
self.os_release.return_value = 'kilo'
c = neutron_api_odl.NeutronAPIODLCharm()
self.os_release.return_value = 'icehouse'
c = neutron_api_odl.IcehouseNeutronAPIODLCharm()
c.configure_plugin(principle_interface)
config_dict = {
'neutron-api': {
@ -71,7 +71,7 @@ class TestNeutronAPIODLCharm(Helper):
principle_interface = mock.MagicMock()
self.patch_object(neutron_api_odl.ch_utils, 'os_release')
self.os_release.return_value = 'newton'
c = neutron_api_odl.NeutronAPIODLCharm()
c = neutron_api_odl.NewtonNeutronAPIODLCharm()
c.configure_plugin(principle_interface)
config_dict = {
'neutron-api': {