Fix tests and pep8

The project was initially imported in a broken state.

Change-Id: I2aa61e71dc8fc97636ec02a293c1cec609126c8b
This commit is contained in:
Mathieu Mitchell 2018-01-29 22:59:22 -05:00
parent 07c16aa8a9
commit b71f738d45
9 changed files with 74 additions and 153 deletions

5
.gitreview Normal file
View File

@ -0,0 +1,5 @@
[gerrit]
host=review.openstack.org
port=29418
project=openstack/charm-neutron-api-genericswitch.git
defaultbranch=master

View File

@ -1,3 +1,7 @@
# Restrictions
# charm-neutron-api-genericswitch
This charm supports deployment with OpenStack Icehouse or better.
This charm adds subordinate support for [Networking Generic Switch](https://docs.openstack.org/networking-generic-switch/latest/)
to [charm-neutron-api](https://git.openstack.org/cgit/openstack/charm-neutron-api/).
## Restrictions
This charm currently only supports deployment with OpenStack Newton.

View File

@ -1,17 +0,0 @@
Todo:
* Figure out how to do new world v oldworld rendering
* Just about everything.
* I: No icon.svg file.
* W: no copyright file
* W: no README file
* I: missing recommended hook start
* Confd ssh keys installed from /cisco/etc/confd/ssh
* Interfaces allocated to VPP should be configured within the /cisco/etc/qn.conf file via a Cisco provided script
Done-ish
* QEMU 2.2 and libvirt 1.2.8 or greater.
Done
* 1GB of hugepages allocated upon system boot. Adjusting vm.nr_hugepages within the /etc/sysctl.conf.
* vm.max_map_count should be adjusted in line with hugepages (The default of 65536 equals 1GB of hugepages)
* For debugging purposes, apport needs to be uninstalled and corekeeper installed in its place on compute hosts.

View File

@ -1,5 +1 @@
options:
pip-requirement-line:
type: string
default: "networking-generic-switch==0.4.0"
description: Pip requirement line. This configuration option is only read on initial installation.

View File

@ -19,20 +19,6 @@ import charms_openstack.charm
from charmhelpers.core import hookenv
ML2_CONF = '/etc/neutron/plugins/ml2/ml2_conf.ini'
VLAN = 'vlan'
VXLAN = 'vxlan'
GRE = 'gre'
OVERLAY_NET_TYPES = [VXLAN, GRE]
@charms_openstack.adapters.config_property
def overlay_net_types(config):
overlay_networks = config.overlay_network_type.split()
for overlay_net in overlay_networks:
if overlay_net not in OVERLAY_NET_TYPES:
raise ValueError(
'Unsupported overlay-network-type {}'.format(overlay_net))
return ','.join(overlay_networks)
@charms_openstack.charm.register_os_release_selector
@ -41,7 +27,8 @@ def choose_charm_class():
return ch_utils.os_release('neutron-common')
class NewtonNeutronAPIGenericSwitchCharm(charms_openstack.charm.OpenStackCharm):
class NewtonNeutronAPIGenericSwitchCharm(
charms_openstack.charm.OpenStackCharm):
name = 'neutron-api-genericswitch'
release = 'newton'
@ -53,7 +40,8 @@ class NewtonNeutronAPIGenericSwitchCharm(charms_openstack.charm.OpenStackCharm):
restart_map = {ML2_CONF: []}
adapters_class = charms_openstack.adapters.OpenStackRelationAdapters
genericswitch_config = '/etc/neutron/plugins/ml2/ml2_conf_genericswitch.ini'
genericswitch_config = \
'/etc/neutron/plugins/ml2/ml2_conf_genericswitch.ini'
service_plugins = ('router,firewall,vpnaas,metering,'
'neutron_lbaas.services.loadbalancer.'
@ -66,7 +54,6 @@ class NewtonNeutronAPIGenericSwitchCharm(charms_openstack.charm.OpenStackCharm):
config_path = hookenv.resource_get('genericswitch-ml2-config')
shutil.copy(config_path, self.genericswitch_config)
# NOTE(mmitchell): This puts the full package path as a package to install.
self.packages.append(package_path)
super().install()
@ -79,9 +66,7 @@ class NewtonNeutronAPIGenericSwitchCharm(charms_openstack.charm.OpenStackCharm):
"neutron-api": {
"/etc/neutron/neutron.conf": {
"sections": {
'DEFAULT': [
('hello', 'world')
],
'DEFAULT': [],
}
}
}
@ -93,4 +78,3 @@ class NewtonNeutronAPIGenericSwitchCharm(charms_openstack.charm.OpenStackCharm):
neutron_plugin_config='/etc/neutron/plugins/ml2/ml2_conf.ini',
service_plugins=self.service_plugins,
subordinate_configuration=inject_config)

View File

@ -2,8 +2,8 @@
# This file is managed centrally by release-tools and should not be modified
# within individual charm repos.
[tox]
envlist = pep8,py27,py35
skipsdist = True
envlist = pep8,py34,py35
skip_missing_interpreters = True
[testenv]
@ -51,5 +51,5 @@ commands = flake8 {posargs} src unit_tests
commands = {posargs}
[flake8]
# E402 ignore necessary for path append before sys module import in actions
ignore = E402
ignore = E402,E226
exclude = */charmhelpers

View File

@ -0,0 +1,49 @@
# 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.
from __future__ import absolute_import
from __future__ import print_function
import mock
import charms_openstack.test_utils as test_utils
import charm.openstack.neutron_api_genericswitch as neutron_api_genericswitch
class TestNeutronAPIGenericSwitchCharm(test_utils.PatchHelper):
def test_all_packages(self):
self.patch_object(neutron_api_genericswitch.ch_utils, 'os_release')
self.os_release.return_value = 'newton'
c = neutron_api_genericswitch.NewtonNeutronAPIGenericSwitchCharm()
self.assertEqual(
c.all_packages,
['neutron-common', 'neutron-plugin-ml2'])
def test_configure_plugin(self):
principle_interface = mock.MagicMock()
self.patch_object(neutron_api_genericswitch.ch_utils, 'os_release')
self.os_release.return_value = 'newton'
c = neutron_api_genericswitch.NewtonNeutronAPIGenericSwitchCharm()
c.configure_plugin(principle_interface)
config_dict = {
'neutron-api': {
'/etc/neutron/neutron.conf': {'sections': {'DEFAULT': []}}}}
principle_interface.configure_plugin.assert_called_once_with(
neutron_plugin='genericswitch',
core_plugin='neutron.plugins.ml2.plugin.Ml2Plugin',
neutron_plugin_config='/etc/neutron/plugins/ml2/ml2_conf.ini',
service_plugins=('router,firewall,vpnaas,metering,'
'neutron_lbaas.services.loadbalancer.'
'plugin.LoadBalancerPluginv2'),
subordinate_configuration=config_dict)

View File

@ -1,86 +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.
from __future__ import absolute_import
from __future__ import print_function
import mock
import charms_openstack.test_utils as test_utils
import charm.openstack.neutron_api_odl as neutron_api_odl
class Helper(test_utils.PatchHelper):
def setUp(self):
super().setUp()
self.patch_release(neutron_api_odl.IcehouseNeutronAPIODLCharm.release)
class TestCustomProperties(Helper):
def test_overlay_net_types(self):
config = mock.MagicMock()
for v in ['gre', 'gre vxlan', 'vxlan']:
config.overlay_network_type = v
neutron_api_odl.overlay_net_types(config)
# ensure that it fails
with self.assertRaises(ValueError):
config.overlay_network_type = 'fail-me'
neutron_api_odl.overlay_net_types(config)
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.KiloNeutronAPIODLCharm()
self.assertEqual(
c.all_packages,
['neutron-common', 'neutron-plugin-ml2', 'python-networking-odl'])
def test_configure_plugin(self):
principle_interface = mock.MagicMock()
self.patch_object(neutron_api_odl.ch_utils, 'os_release')
self.os_release.return_value = 'icehouse'
c = neutron_api_odl.IcehouseNeutronAPIODLCharm()
c.configure_plugin(principle_interface)
config_dict = {
'neutron-api': {
'/etc/neutron/neutron.conf': {'sections': {'DEFAULT': []}}}}
principle_interface.configure_plugin.assert_called_once_with(
neutron_plugin='odl',
core_plugin='neutron.plugins.ml2.plugin.Ml2Plugin',
neutron_plugin_config='/etc/neutron/plugins/ml2/ml2_conf.ini',
service_plugins='router,firewall,lbaas,vpnaas,metering',
subordinate_configuration=config_dict)
def test_configure_plugin_newton(self):
principle_interface = mock.MagicMock()
self.patch_object(neutron_api_odl.ch_utils, 'os_release')
self.os_release.return_value = 'newton'
c = neutron_api_odl.NewtonNeutronAPIODLCharm()
c.configure_plugin(principle_interface)
config_dict = {
'neutron-api': {
'/etc/neutron/neutron.conf': {'sections': {'DEFAULT': []}}}}
principle_interface.configure_plugin.assert_called_once_with(
neutron_plugin='odl',
core_plugin='neutron.plugins.ml2.plugin.Ml2Plugin',
neutron_plugin_config='/etc/neutron/plugins/ml2/ml2_conf.ini',
service_plugins=('router,firewall,vpnaas,metering,'
'neutron_lbaas.services.loadbalancer.'
'plugin.LoadBalancerPluginv2'),
subordinate_configuration=config_dict)

View File

@ -17,13 +17,13 @@ from __future__ import print_function
import mock
import reactive.neutron_api_odl_handlers as handlers
import reactive.neutron_api_genericswitch_handlers as handlers
import charm.openstack.neutron_api_genericswitch as neutron_api_genericswitch
import charms_openstack.test_utils as test_utils
class TestRegisteredHooks(test_utils.TestRegisteredHooks):
def test_hooks(self):
defaults = [
'charm.installed',
@ -31,8 +31,6 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks):
'update-status']
hook_set = {
'when': {
'render_config': (
'odl-controller.available',),
'configure_plugin': (
'neutron-plugin-api-subordinate.connected',),
'remote_restart': (
@ -40,7 +38,7 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks):
},
'when_file_changed': {
'remote_restart': (
'/etc/neutron/plugins/ml2/ml2_conf.ini',),
neutron_api_genericswitch.ML2_CONF,),
},
}
# test that the hooks were registered via the
@ -49,26 +47,14 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks):
class TestHandlers(test_utils.PatchHelper):
def test_render_config(self):
napi_odl_charm = mock.MagicMock()
self.patch_object(handlers.charm, 'provide_charm_instance',
new=mock.MagicMock())
self.provide_charm_instance().__enter__.return_value = napi_odl_charm
handlers.render_config('arg1')
napi_odl_charm.render_with_interfaces.assert_called_once_with(
('arg1',))
napi_odl_charm.assess_status.assert_called_once_with()
def test_configure_plugin(self):
napi_odl_charm = mock.MagicMock()
napi_gs_charm = mock.MagicMock()
self.patch_object(handlers.charm, 'provide_charm_instance',
new=mock.MagicMock())
self.provide_charm_instance().__enter__.return_value = napi_odl_charm
self.provide_charm_instance().__enter__.return_value = napi_gs_charm
handlers.configure_plugin('arg1')
napi_odl_charm.configure_plugin.assert_called_once_with('arg1')
napi_gs_charm.configure_plugin.assert_called_once_with('arg1')
def test_remote_restart(self):
principle_interface = mock.MagicMock()