synced ch and fixed tests
This commit is contained in:
parent
4387974a3a
commit
717248440c
@ -158,5 +158,6 @@ options:
|
||||
type: int
|
||||
default: 1500
|
||||
description: |
|
||||
To improve network performance of VM, sometimes we should keep VM MTU as 1500
|
||||
and use charm to modify MTU of tunnel nic more than 1500 (e.g. 1546 for GRE)
|
||||
To improve network performance of VM, sometimes we should keep VM MTU as
|
||||
1500 and use charm to modify MTU of tunnel nic more than 1500 (e.g. 1546
|
||||
for GRE).
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
from base64 import b64decode
|
||||
from subprocess import check_call
|
||||
@ -47,6 +48,8 @@ from charmhelpers.core.hookenv import (
|
||||
from charmhelpers.core.sysctl import create as sysctl_create
|
||||
|
||||
from charmhelpers.core.host import (
|
||||
list_nics,
|
||||
get_nic_hwaddr,
|
||||
mkdir,
|
||||
write_file,
|
||||
)
|
||||
@ -66,10 +69,12 @@ from charmhelpers.contrib.openstack.neutron import (
|
||||
)
|
||||
from charmhelpers.contrib.network.ip import (
|
||||
get_address_in_network,
|
||||
get_ipv4_addr,
|
||||
get_ipv6_addr,
|
||||
get_netmask_for_address,
|
||||
format_ipv6_addr,
|
||||
is_address_in_network,
|
||||
is_bridge_member,
|
||||
)
|
||||
from charmhelpers.contrib.openstack.utils import get_host_ip
|
||||
|
||||
@ -833,6 +838,40 @@ class NeutronContext(OSContextGenerator):
|
||||
return ctxt
|
||||
|
||||
|
||||
class NeutronPortContext(OSContextGenerator):
|
||||
def resolve_port(self, config_key):
|
||||
if not config(config_key):
|
||||
return None
|
||||
|
||||
hwaddr_to_nic = {}
|
||||
hwaddr_to_ip = {}
|
||||
for nic in list_nics(['eth', 'bond']):
|
||||
hwaddr = get_nic_hwaddr(nic)
|
||||
hwaddr_to_nic[hwaddr] = nic
|
||||
addresses = get_ipv4_addr(nic, fatal=False) + \
|
||||
get_ipv6_addr(iface=nic, fatal=False)
|
||||
hwaddr_to_ip[hwaddr] = addresses
|
||||
|
||||
mac_regex = re.compile(r'([0-9A-F]{2}[:-]){5}([0-9A-F]{2})', re.I)
|
||||
for entry in config(config_key).split():
|
||||
entry = entry.strip()
|
||||
if re.match(mac_regex, entry):
|
||||
if entry in hwaddr_to_nic and len(hwaddr_to_ip[entry]) == 0:
|
||||
# If the nic is part of a bridge then don't use it
|
||||
if is_bridge_member(hwaddr_to_nic[entry]):
|
||||
continue
|
||||
# Entry is a MAC address for a valid interface that doesn't
|
||||
# have an IP address assigned yet.
|
||||
return hwaddr_to_nic[entry]
|
||||
else:
|
||||
# If the passed entry is not a MAC address, assume it's a valid
|
||||
# interface, and that the user put it there on purpose (we can
|
||||
# trust it to be the real external network).
|
||||
return entry
|
||||
|
||||
return None
|
||||
|
||||
|
||||
class OSConfigFlagContext(OSContextGenerator):
|
||||
"""Provides support for user-defined config flags.
|
||||
|
||||
|
@ -2,10 +2,6 @@
|
||||
import os
|
||||
import uuid
|
||||
import socket
|
||||
from charmhelpers.core.host import (
|
||||
list_nics,
|
||||
get_nic_hwaddr
|
||||
)
|
||||
from charmhelpers.core.hookenv import (
|
||||
config,
|
||||
relation_ids,
|
||||
@ -20,6 +16,7 @@ from charmhelpers.fetch import (
|
||||
from charmhelpers.contrib.openstack.context import (
|
||||
OSContextGenerator,
|
||||
context_complete,
|
||||
NeutronPortContext,
|
||||
)
|
||||
from charmhelpers.contrib.openstack.utils import (
|
||||
get_os_codename_install_source
|
||||
@ -27,12 +24,8 @@ from charmhelpers.contrib.openstack.utils import (
|
||||
from charmhelpers.contrib.hahelpers.cluster import(
|
||||
eligible_leader
|
||||
)
|
||||
import re
|
||||
from charmhelpers.contrib.network.ip import (
|
||||
get_address_in_network,
|
||||
get_ipv4_addr,
|
||||
get_ipv6_addr,
|
||||
is_bridge_member,
|
||||
)
|
||||
|
||||
DB_USER = "quantum"
|
||||
@ -111,8 +104,8 @@ def _neutron_api_settings():
|
||||
'''
|
||||
neutron_settings = {
|
||||
'l2_population': False,
|
||||
'network_device_mtu': 1500,
|
||||
'overlay_network_type': 'gre',
|
||||
'network_device_mtu': 1500,
|
||||
}
|
||||
for rid in relation_ids('neutron-plugin-api'):
|
||||
for unit in related_units(rid):
|
||||
@ -122,8 +115,7 @@ def _neutron_api_settings():
|
||||
neutron_settings = {
|
||||
'l2_population': rdata['l2-population'],
|
||||
'overlay_network_type': rdata['overlay-network-type'],
|
||||
'network_device_mtu': rdata['network-device-mtu']
|
||||
if 'network-device-mtu' in rdata else 1500,
|
||||
'network_device_mtu': rdata.get('network-device-mtu', 1500)
|
||||
}
|
||||
return neutron_settings
|
||||
return neutron_settings
|
||||
@ -178,44 +170,13 @@ class L3AgentContext(OSContextGenerator):
|
||||
return ctxt
|
||||
|
||||
|
||||
class NeutronPortContext(OSContextGenerator):
|
||||
|
||||
def _resolve_port(self, config_key):
|
||||
if not config(config_key):
|
||||
return None
|
||||
hwaddr_to_nic = {}
|
||||
hwaddr_to_ip = {}
|
||||
for nic in list_nics(['eth', 'bond']):
|
||||
hwaddr = get_nic_hwaddr(nic)
|
||||
hwaddr_to_nic[hwaddr] = nic
|
||||
addresses = get_ipv4_addr(nic, fatal=False) + \
|
||||
get_ipv6_addr(iface=nic, fatal=False)
|
||||
hwaddr_to_ip[hwaddr] = addresses
|
||||
mac_regex = re.compile(r'([0-9A-F]{2}[:-]){5}([0-9A-F]{2})', re.I)
|
||||
for entry in config(config_key).split():
|
||||
entry = entry.strip()
|
||||
if re.match(mac_regex, entry):
|
||||
if entry in hwaddr_to_nic and len(hwaddr_to_ip[entry]) == 0:
|
||||
# If the nic is part of a bridge then don't use it
|
||||
if is_bridge_member(hwaddr_to_nic[entry]):
|
||||
continue
|
||||
# Entry is a MAC address for a valid interface that doesn't
|
||||
# have an IP address assigned yet.
|
||||
return hwaddr_to_nic[entry]
|
||||
else:
|
||||
# If the passed entry is not a MAC address, assume it's a valid
|
||||
# interface, and that the user put it there on purpose (we can
|
||||
# trust it to be the real external network).
|
||||
return entry
|
||||
return None
|
||||
|
||||
|
||||
class ExternalPortContext(NeutronPortContext):
|
||||
|
||||
def __call__(self):
|
||||
port = self._resolve_port('ext-port')
|
||||
port = self.resolve_port('ext-port')
|
||||
if port:
|
||||
return {"ext_port": port}
|
||||
return {"ext_port": port,
|
||||
"mtu": config('phy-nic-mtu')}
|
||||
else:
|
||||
return None
|
||||
|
||||
@ -223,7 +184,7 @@ class ExternalPortContext(NeutronPortContext):
|
||||
class DataPortContext(NeutronPortContext):
|
||||
|
||||
def __call__(self):
|
||||
port = self._resolve_port('data-port')
|
||||
port = self.resolve_port('data-port')
|
||||
if port:
|
||||
return {"data_port": port}
|
||||
else:
|
||||
|
@ -22,9 +22,6 @@ from charmhelpers.core.host import (
|
||||
restart_on_change,
|
||||
lsb_release,
|
||||
)
|
||||
from charmhelpers.contrib.network.ip import (
|
||||
configure_phy_nic_mtu
|
||||
)
|
||||
from charmhelpers.contrib.hahelpers.cluster import(
|
||||
get_hacluster_config,
|
||||
eligible_leader
|
||||
@ -81,7 +78,6 @@ def install():
|
||||
fatal=True)
|
||||
apt_install(filter_installed_packages(get_packages()),
|
||||
fatal=True)
|
||||
configure_phy_nic_mtu()
|
||||
else:
|
||||
log('Please provide a valid plugin config', level=ERROR)
|
||||
sys.exit(1)
|
||||
@ -114,7 +110,6 @@ def config_changed():
|
||||
if valid_plugin():
|
||||
CONFIGS.write_all()
|
||||
configure_ovs()
|
||||
configure_phy_nic_mtu()
|
||||
else:
|
||||
log('Please provide a valid plugin config', level=ERROR)
|
||||
sys.exit(1)
|
||||
|
@ -6,4 +6,5 @@ task
|
||||
|
||||
script
|
||||
ip link set {{ ext_port }} up
|
||||
ip link set {{ ext_port }} mtu {{ mtu }}
|
||||
end script
|
@ -16,11 +16,7 @@ TO_PATCH = [
|
||||
'config',
|
||||
'context_complete',
|
||||
'eligible_leader',
|
||||
'get_ipv4_addr',
|
||||
'get_ipv6_addr',
|
||||
'get_nic_hwaddr',
|
||||
'get_os_codename_install_source',
|
||||
'list_nics',
|
||||
'relation_get',
|
||||
'relation_ids',
|
||||
'related_units',
|
||||
@ -131,14 +127,12 @@ class TestNeutronPortContext(CharmTestCase):
|
||||
}
|
||||
self.absent_macs = "aa:a5:ae:ae:ab:a4 "
|
||||
|
||||
def test_no_ext_port(self):
|
||||
self.config.return_value = None
|
||||
self.assertIsNone(quantum_contexts.ExternalPortContext()())
|
||||
def fake_config(self, cfgdict):
|
||||
|
||||
def test_ext_port_eth(self):
|
||||
self.config.return_value = 'eth1010'
|
||||
self.assertEquals(quantum_contexts.ExternalPortContext()(),
|
||||
{'ext_port': 'eth1010'})
|
||||
def _fake_config(key):
|
||||
return cfgdict.get(key)
|
||||
|
||||
return _fake_config
|
||||
|
||||
def _fake_get_hwaddr(self, arg):
|
||||
return self.machine_macs[arg]
|
||||
@ -146,31 +140,77 @@ class TestNeutronPortContext(CharmTestCase):
|
||||
def _fake_get_ipv4(self, arg, fatal=False):
|
||||
return self.machine_nics[arg]
|
||||
|
||||
def test_ext_port_mac(self):
|
||||
config_macs = self.absent_macs + " " + self.machine_macs['eth2']
|
||||
self.get_ipv4_addr.side_effect = self._fake_get_ipv4
|
||||
self.get_ipv6_addr.return_value = []
|
||||
self.config.return_value = config_macs
|
||||
self.list_nics.return_value = self.machine_macs.keys()
|
||||
self.get_nic_hwaddr.side_effect = self._fake_get_hwaddr
|
||||
self.assertEquals(quantum_contexts.ExternalPortContext()(),
|
||||
{'ext_port': 'eth2'})
|
||||
self.config.return_value = self.absent_macs
|
||||
@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.assertIsNone(quantum_contexts.ExternalPortContext()())
|
||||
|
||||
def test_ext_port_mac_one_used_nic(self):
|
||||
config_macs = self.machine_macs['eth1'] + " " + \
|
||||
self.machine_macs['eth2']
|
||||
self.get_ipv4_addr.side_effect = self._fake_get_ipv4
|
||||
self.get_ipv6_addr.return_value = []
|
||||
self.config.return_value = config_macs
|
||||
self.list_nics.return_value = self.machine_macs.keys()
|
||||
self.get_nic_hwaddr.side_effect = self._fake_get_hwaddr
|
||||
@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': 'eth2'})
|
||||
{'ext_port': 'eth1010', 'mtu': None})
|
||||
|
||||
def test_data_port_eth(self):
|
||||
self.config.return_value = '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', 'mtu': None})
|
||||
|
||||
config = self.fake_config({'ext-port': self.absent_macs})
|
||||
self.config.side_effect = config
|
||||
mock_config.side_effect = config
|
||||
|
||||
self.assertIsNone(quantum_contexts.ExternalPortContext()())
|
||||
self.assertTrue(mock_config.called)
|
||||
|
||||
@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):
|
||||
|
||||
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,
|
||||
'phy-nic-mtu': 1234})
|
||||
self.config.side_effect = config
|
||||
mock_config.side_effect = config
|
||||
self.assertEquals(quantum_contexts.ExternalPortContext()(),
|
||||
{'ext_port': 'eth2', 'mtu': 1234})
|
||||
|
||||
@patch('charmhelpers.contrib.openstack.context.config')
|
||||
def test_data_port_eth(self, mock_config):
|
||||
config = self.fake_config({'data-port': 'eth1010'})
|
||||
mock_config.side_effect = config
|
||||
self.assertEquals(quantum_contexts.DataPortContext()(),
|
||||
{'data_port': 'eth1010'})
|
||||
|
||||
|
@ -48,7 +48,6 @@ TO_PATCH = [
|
||||
'remove_legacy_ha_files',
|
||||
'cleanup_ovs_netns',
|
||||
'stop_neutron_ha_monitor_daemon',
|
||||
'configure_phy_nic_mtu'
|
||||
]
|
||||
|
||||
|
||||
@ -88,7 +87,6 @@ class TestQuantumHooks(CharmTestCase):
|
||||
self.assertTrue(self.get_early_packages.called)
|
||||
self.assertTrue(self.get_packages.called)
|
||||
self.assertTrue(self.execd_preinstall.called)
|
||||
self.assertTrue(self.configure_phy_nic_mtu.called)
|
||||
|
||||
def test_install_hook_precise_nocloudarchive(self):
|
||||
self.test_config.set('openstack-origin', 'distro')
|
||||
@ -123,7 +121,6 @@ class TestQuantumHooks(CharmTestCase):
|
||||
self.assertTrue(_amqp_joined.called)
|
||||
self.assertTrue(_amqp_nova_joined.called)
|
||||
self.create_sysctl.assert_called()
|
||||
self.assertTrue(self.configure_phy_nic_mtu.called)
|
||||
|
||||
def test_config_changed_upgrade(self):
|
||||
self.openstack_upgrade_available.return_value = True
|
||||
@ -131,7 +128,6 @@ class TestQuantumHooks(CharmTestCase):
|
||||
self._call_hook('config-changed')
|
||||
self.assertTrue(self.do_openstack_upgrade.called)
|
||||
self.assertTrue(self.configure_ovs.called)
|
||||
self.assertTrue(self.configure_phy_nic_mtu.called)
|
||||
|
||||
def test_config_changed_n1kv(self):
|
||||
self.openstack_upgrade_available.return_value = False
|
||||
|
Loading…
x
Reference in New Issue
Block a user