Merged next in
This commit is contained in:
commit
ada6593a09
@ -1,4 +1,5 @@
|
||||
branch: lp:charm-helpers
|
||||
branch: lp:~gnuoy/charm-helpers/neutron-shuffle
|
||||
#branch: lp:charm-helpers
|
||||
destination: hooks/charmhelpers
|
||||
include:
|
||||
- core
|
||||
|
@ -43,10 +43,10 @@ import charmhelpers.contrib.openstack.context as context
|
||||
from charmhelpers.contrib.openstack.context import (
|
||||
SyslogContext,
|
||||
NeutronAPIContext,
|
||||
NetworkServiceContext,
|
||||
ExternalPortContext,
|
||||
PhyNICMTUContext,
|
||||
DataPortContext,
|
||||
NetworkServiceContext,
|
||||
)
|
||||
import charmhelpers.contrib.openstack.templating as templating
|
||||
from charmhelpers.contrib.openstack.neutron import headers_package
|
||||
|
@ -11,6 +11,8 @@ core_plugin = {{ core_plugin }}
|
||||
control_exchange = neutron
|
||||
notification_driver = neutron.openstack.common.notifier.list_notifier
|
||||
list_notifier_drivers = neutron.openstack.common.notifier.rabbit_notifier
|
||||
{% if network_device_mtu -%}
|
||||
network_device_mtu = {{ network_device_mtu }}
|
||||
{% endif -%}
|
||||
[agent]
|
||||
root_helper = sudo /usr/bin/neutron-rootwrap /etc/neutron/rootwrap.conf
|
||||
root_helper = sudo /usr/bin/neutron-rootwrap /etc/neutron/rootwrap.conf
|
||||
|
@ -14,12 +14,8 @@ from test_utils import (
|
||||
TO_PATCH = [
|
||||
'apt_install',
|
||||
'config',
|
||||
'context_complete',
|
||||
'eligible_leader',
|
||||
'get_os_codename_install_source',
|
||||
'relation_get',
|
||||
'relation_ids',
|
||||
'related_units',
|
||||
'unit_get',
|
||||
]
|
||||
|
||||
@ -42,182 +38,6 @@ def patch_open():
|
||||
yield mock_open, mock_file
|
||||
|
||||
|
||||
class TestNetworkServiceContext(CharmTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestNetworkServiceContext, self).setUp(quantum_contexts,
|
||||
TO_PATCH)
|
||||
self.config.side_effect = self.test_config.get
|
||||
self.context = quantum_contexts.NetworkServiceContext()
|
||||
self.test_relation.set(
|
||||
{'keystone_host': '10.5.0.1',
|
||||
'service_port': '5000',
|
||||
'auth_port': '20000',
|
||||
'service_tenant': 'tenant',
|
||||
'service_username': 'username',
|
||||
'service_password': 'password',
|
||||
'quantum_host': '10.5.0.2',
|
||||
'quantum_port': '9696',
|
||||
'quantum_url': 'http://10.5.0.2:9696/v2',
|
||||
'region': 'aregion'}
|
||||
)
|
||||
self.data_result = {
|
||||
'keystone_host': '10.5.0.1',
|
||||
'service_port': '5000',
|
||||
'auth_port': '20000',
|
||||
'service_tenant': 'tenant',
|
||||
'service_username': 'username',
|
||||
'service_password': 'password',
|
||||
'quantum_host': '10.5.0.2',
|
||||
'quantum_port': '9696',
|
||||
'quantum_url': 'http://10.5.0.2:9696/v2',
|
||||
'region': 'aregion',
|
||||
'service_protocol': 'http',
|
||||
'auth_protocol': 'http',
|
||||
}
|
||||
|
||||
def test_not_related(self):
|
||||
self.relation_ids.return_value = []
|
||||
self.assertEquals(self.context(), {})
|
||||
|
||||
def test_no_units(self):
|
||||
self.relation_ids.return_value = []
|
||||
self.relation_ids.return_value = ['foo']
|
||||
self.related_units.return_value = []
|
||||
self.assertEquals(self.context(), {})
|
||||
|
||||
def test_no_data(self):
|
||||
self.relation_ids.return_value = ['foo']
|
||||
self.related_units.return_value = ['bar']
|
||||
self.relation_get.side_effect = self.test_relation.get
|
||||
self.context_complete.return_value = False
|
||||
self.assertEquals(self.context(), {})
|
||||
|
||||
def test_data_multi_unit(self):
|
||||
self.relation_ids.return_value = ['foo']
|
||||
self.related_units.return_value = ['bar', 'baz']
|
||||
self.context_complete.return_value = True
|
||||
self.relation_get.side_effect = self.test_relation.get
|
||||
self.assertEquals(self.context(), self.data_result)
|
||||
|
||||
def test_data_single_unit(self):
|
||||
self.relation_ids.return_value = ['foo']
|
||||
self.related_units.return_value = ['bar']
|
||||
self.context_complete.return_value = True
|
||||
self.relation_get.side_effect = self.test_relation.get
|
||||
self.assertEquals(self.context(), self.data_result)
|
||||
|
||||
|
||||
class TestNeutronPortContext(CharmTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestNeutronPortContext, self).setUp(quantum_contexts,
|
||||
TO_PATCH)
|
||||
self.machine_macs = {
|
||||
'eth0': 'fe:c5:ce:8e:2b:00',
|
||||
'eth1': 'fe:c5:ce:8e:2b:01',
|
||||
'eth2': 'fe:c5:ce:8e:2b:02',
|
||||
'eth3': 'fe:c5:ce:8e:2b:03',
|
||||
}
|
||||
self.machine_nics = {
|
||||
'eth0': ['192.168.0.1'],
|
||||
'eth1': ['192.168.0.2'],
|
||||
'eth2': [],
|
||||
'eth3': [],
|
||||
}
|
||||
self.absent_macs = "aa:a5:ae:ae:ab:a4 "
|
||||
|
||||
def fake_config(self, cfgdict):
|
||||
|
||||
def _fake_config(key):
|
||||
return cfgdict.get(key)
|
||||
|
||||
return _fake_config
|
||||
|
||||
def _fake_get_hwaddr(self, arg):
|
||||
return self.machine_macs[arg]
|
||||
|
||||
def _fake_get_ipv4(self, arg, fatal=False):
|
||||
return self.machine_nics[arg]
|
||||
|
||||
@patch('charmhelpers.contrib.openstack.context.config')
|
||||
def test_no_ext_port(self, mock_config):
|
||||
self.config.side_effect = config = self.fake_config({})
|
||||
mock_config.side_effect = config
|
||||
self.assertEquals(quantum_contexts.ExternalPortContext()(), {})
|
||||
|
||||
@patch('charmhelpers.contrib.openstack.context.config')
|
||||
def test_ext_port_eth(self, mock_config):
|
||||
config = self.fake_config({'ext-port': 'eth1010'})
|
||||
self.config.side_effect = config
|
||||
mock_config.side_effect = config
|
||||
self.assertEquals(quantum_contexts.ExternalPortContext()(),
|
||||
{'ext_port': 'eth1010'})
|
||||
|
||||
@patch('charmhelpers.contrib.openstack.context.get_nic_hwaddr')
|
||||
@patch('charmhelpers.contrib.openstack.context.list_nics')
|
||||
@patch('charmhelpers.contrib.openstack.context.get_ipv6_addr')
|
||||
@patch('charmhelpers.contrib.openstack.context.get_ipv4_addr')
|
||||
@patch('charmhelpers.contrib.openstack.context.config')
|
||||
def test_ext_port_mac(self, mock_config, mock_get_ipv4_addr,
|
||||
mock_get_ipv6_addr, mock_list_nics,
|
||||
mock_get_nic_hwaddr):
|
||||
config_macs = self.absent_macs + " " + self.machine_macs['eth2']
|
||||
config = self.fake_config({'ext-port': config_macs})
|
||||
self.config.side_effect = config
|
||||
mock_config.side_effect = config
|
||||
|
||||
mock_get_ipv4_addr.side_effect = self._fake_get_ipv4
|
||||
mock_get_ipv6_addr.return_value = []
|
||||
mock_list_nics.return_value = self.machine_macs.keys()
|
||||
mock_get_nic_hwaddr.side_effect = self._fake_get_hwaddr
|
||||
|
||||
self.assertEquals(quantum_contexts.ExternalPortContext()(),
|
||||
{'ext_port': 'eth2'})
|
||||
|
||||
config = self.fake_config({'ext-port': self.absent_macs})
|
||||
self.config.side_effect = config
|
||||
mock_config.side_effect = config
|
||||
|
||||
self.assertEquals(quantum_contexts.ExternalPortContext()(), {})
|
||||
|
||||
@patch.object(quantum_contexts, 'neutron_api_settings')
|
||||
@patch('charmhelpers.contrib.openstack.context.get_nic_hwaddr')
|
||||
@patch('charmhelpers.contrib.openstack.context.list_nics')
|
||||
@patch('charmhelpers.contrib.openstack.context.get_ipv6_addr')
|
||||
@patch('charmhelpers.contrib.openstack.context.get_ipv4_addr')
|
||||
@patch('charmhelpers.contrib.openstack.context.config')
|
||||
def test_ext_port_mac_one_used_nic(self, mock_config,
|
||||
mock_get_ipv4_addr,
|
||||
mock_get_ipv6_addr, mock_list_nics,
|
||||
mock_get_nic_hwaddr,
|
||||
mock_neutron_api_settings):
|
||||
|
||||
mock_neutron_api_settings.return_value = {'network_device_mtu': 1234}
|
||||
config_macs = "%s %s" % (self.machine_macs['eth1'],
|
||||
self.machine_macs['eth2'])
|
||||
|
||||
mock_get_ipv4_addr.side_effect = self._fake_get_ipv4
|
||||
mock_get_ipv6_addr.return_value = []
|
||||
mock_list_nics.return_value = self.machine_macs.keys()
|
||||
mock_get_nic_hwaddr.side_effect = self._fake_get_hwaddr
|
||||
|
||||
config = self.fake_config({'ext-port': config_macs})
|
||||
self.config.side_effect = config
|
||||
mock_config.side_effect = config
|
||||
self.assertEquals(quantum_contexts.ExternalPortContext()(),
|
||||
{'ext_port': 'eth2', 'ext_port_mtu': 1234})
|
||||
|
||||
@patch('charmhelpers.contrib.openstack.context.NeutronPortContext.'
|
||||
'resolve_ports')
|
||||
def test_data_port_eth(self, mock_resolve):
|
||||
self.config.side_effect = self.fake_config({'data-port':
|
||||
'phybr1:eth1010'})
|
||||
mock_resolve.side_effect = lambda ports: ports
|
||||
self.assertEquals(quantum_contexts.DataPortContext()(),
|
||||
{'phybr1': 'eth1010'})
|
||||
|
||||
|
||||
class TestL3AgentContext(CharmTestCase):
|
||||
|
||||
def setUp(self):
|
||||
@ -269,9 +89,12 @@ class TestQuantumGatewayContext(CharmTestCase):
|
||||
self.config.side_effect = self.test_config.get
|
||||
self.maxDiff = None
|
||||
|
||||
@patch('charmhelpers.contrib.openstack.context.relation_get')
|
||||
@patch('charmhelpers.contrib.openstack.context.related_units')
|
||||
@patch('charmhelpers.contrib.openstack.context.relation_ids')
|
||||
@patch.object(quantum_contexts, 'get_shared_secret')
|
||||
@patch.object(quantum_contexts, 'get_host_ip')
|
||||
def test_all(self, _host_ip, _secret):
|
||||
def test_all(self, _host_ip, _secret, _rids, _runits, _rget):
|
||||
rdata = {'l2-population': 'True',
|
||||
'enable-dvr': 'True',
|
||||
'overlay-network-type': 'gre',
|
||||
@ -284,9 +107,9 @@ class TestQuantumGatewayContext(CharmTestCase):
|
||||
self.test_config.set('vlan-ranges',
|
||||
'physnet1:1000:2000 physnet2:2001:3000')
|
||||
# Provided by neutron-api relation
|
||||
self.relation_ids.return_value = ['neutron-plugin-api:0']
|
||||
self.related_units.return_value = ['neutron-api/0']
|
||||
self.relation_get.side_effect = lambda *args, **kwargs: rdata
|
||||
_rids.return_value = ['neutron-plugin-api:0']
|
||||
_runits.return_value = ['neutron-api/0']
|
||||
_rget.side_effect = lambda *args, **kwargs: rdata
|
||||
self.get_os_codename_install_source.return_value = 'folsom'
|
||||
_host_ip.return_value = '10.5.0.1'
|
||||
_secret.return_value = 'testsecret'
|
||||
@ -429,60 +252,3 @@ class TestMisc(CharmTestCase):
|
||||
self.config.return_value = 'ovs'
|
||||
self.assertEquals(quantum_contexts.core_plugin(),
|
||||
quantum_contexts.NEUTRON_ML2_PLUGIN)
|
||||
|
||||
def test_neutron_api_settings(self):
|
||||
self.relation_ids.return_value = ['foo']
|
||||
self.related_units.return_value = ['bar']
|
||||
self.test_relation.set({'l2-population': 'True',
|
||||
'overlay-network-type': 'gre', })
|
||||
self.relation_get.side_effect = self.test_relation.get
|
||||
self.assertEquals(quantum_contexts.neutron_api_settings(),
|
||||
{'enable_dvr': False,
|
||||
'enable_l3ha': False,
|
||||
'l2_population': True,
|
||||
'overlay_network_type': 'gre'})
|
||||
|
||||
def test_neutron_api_settings2(self):
|
||||
self.relation_ids.return_value = ['foo']
|
||||
self.related_units.return_value = ['bar']
|
||||
self.test_relation.set({'l2-population': 'True',
|
||||
'overlay-network-type': 'gre', })
|
||||
self.relation_get.side_effect = self.test_relation.get
|
||||
self.assertEquals(quantum_contexts.neutron_api_settings(),
|
||||
{'enable_dvr': False,
|
||||
'enable_l3ha': False,
|
||||
'l2_population': True,
|
||||
'overlay_network_type': 'gre'})
|
||||
|
||||
def test_neutron_api_settings_no_apiplugin(self):
|
||||
self.config.return_value = 1500
|
||||
self.relation_ids.return_value = []
|
||||
self.assertEquals(quantum_contexts.neutron_api_settings(),
|
||||
{'enable_dvr': False,
|
||||
'enable_l3ha': False,
|
||||
'l2_population': False,
|
||||
'overlay_network_type': 'gre', })
|
||||
|
||||
def test_neutron_api_dvr(self):
|
||||
self.relation_ids.return_value = ['foo']
|
||||
self.related_units.return_value = ['bar']
|
||||
self.test_relation.set({'l2-population': 'True',
|
||||
'enable-dvr': 'True'})
|
||||
self.relation_get.side_effect = self.test_relation.get
|
||||
self.assertEquals(quantum_contexts.neutron_api_settings(),
|
||||
{'enable_dvr': True,
|
||||
'enable_l3ha': False,
|
||||
'l2_population': True,
|
||||
'overlay_network_type': 'gre'})
|
||||
|
||||
def test_neutron_api_l3ha(self):
|
||||
self.relation_ids.return_value = ['foo']
|
||||
self.related_units.return_value = ['bar']
|
||||
self.test_relation.set({'l2-population': 'False',
|
||||
'enable-l3ha': 'True'})
|
||||
self.relation_get.side_effect = self.test_relation.get
|
||||
self.assertEquals(quantum_contexts.neutron_api_settings(),
|
||||
{'enable_dvr': False,
|
||||
'enable_l3ha': True,
|
||||
'l2_population': False,
|
||||
'overlay_network_type': 'gre'})
|
||||
|
Loading…
Reference in New Issue
Block a user