Ensure mgmt network mtu
This will ensure that mtu is set whenever setup_hm_port() is called regardless of if the port has just been created or not. Also checks mtu in update-status hook. Change-Id: I80b5cea812becd1724fcfe2a8a232253eac76735 Closes-Bug: #2018998 (cherry picked from commitf326ef267a
) (cherry picked from commit3ebb523f89
) (cherry picked from commit1fa839826f
) (cherry picked from commit5747bcad93
)
This commit is contained in:
parent
aab20025c9
commit
31cb8fe1eb
|
@ -455,6 +455,35 @@ def wait_for_hm_port_bound(identity_service, local_unit_name):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_hm_port_mtu(identity_service):
|
||||||
|
"""
|
||||||
|
Ensure the Octavia health manager port has the same mtu as the network it
|
||||||
|
is attached to. This is to ensure that of the mtu changes in Neutron it is
|
||||||
|
reflected here as well.
|
||||||
|
"""
|
||||||
|
session = session_from_identity_service(identity_service)
|
||||||
|
nc = init_neutron_client(session)
|
||||||
|
resp = nc.list_networks(tags='charm-octavia')
|
||||||
|
if len(resp['networks']) > 0:
|
||||||
|
network = resp['networks'][0]
|
||||||
|
ch_core.hookenv.log('ensuring mgmt network {} mtu={}'.
|
||||||
|
format(network['id'], network['mtu']),
|
||||||
|
level=ch_core.hookenv.DEBUG)
|
||||||
|
try:
|
||||||
|
subprocess.check_call(
|
||||||
|
['ovs-vsctl', 'set', 'Interface', octavia.OCTAVIA_MGMT_INTF,
|
||||||
|
'mtu={}'.format(network['mtu'])])
|
||||||
|
subprocess.check_call(
|
||||||
|
['ip', 'link', 'set', octavia.OCTAVIA_MGMT_INTF, 'mtu',
|
||||||
|
str(network['mtu'])])
|
||||||
|
except subprocess.CalledProcessError as exc:
|
||||||
|
ch_core.hookenv.log("failed to apply mtu to interface '{}': {}".
|
||||||
|
format(octavia.OCTAVIA_MGMT_INTF, exc),
|
||||||
|
level=ch_core.hookenv.DEBUG)
|
||||||
|
else:
|
||||||
|
ch_core.hookenv.log('mgmt network not found - cannot set mtu')
|
||||||
|
|
||||||
|
|
||||||
def setup_hm_port(identity_service, octavia_charm, host_id=None):
|
def setup_hm_port(identity_service, octavia_charm, host_id=None):
|
||||||
"""Create a per unit Neutron and OVS port for Octavia Health Manager.
|
"""Create a per unit Neutron and OVS port for Octavia Health Manager.
|
||||||
|
|
||||||
|
@ -523,6 +552,10 @@ def setup_hm_port(identity_service, octavia_charm, host_id=None):
|
||||||
else:
|
else:
|
||||||
# unknown error, raise
|
# unknown error, raise
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
# NOTE: apply this always to ensure consistency
|
||||||
|
ensure_hm_port_mtu(identity_service)
|
||||||
|
|
||||||
if (not hm_port['admin_state_up'] or
|
if (not hm_port['admin_state_up'] or
|
||||||
not is_hm_port_bound(identity_service,
|
not is_hm_port_bound(identity_service,
|
||||||
octavia_charm.local_unit_name) or
|
octavia_charm.local_unit_name) or
|
||||||
|
|
|
@ -124,6 +124,17 @@ def setup_neutron_lbaas_proxy():
|
||||||
neutron.publish_load_balancer_info('octavia', octavia_url)
|
neutron.publish_load_balancer_info('octavia', octavia_url)
|
||||||
|
|
||||||
|
|
||||||
|
@reactive.when('is-update-status-hook', 'octavia.hm-port.available')
|
||||||
|
def ensure_hm_port_mtu():
|
||||||
|
try:
|
||||||
|
identity_service = reactive.endpoint_from_flag(
|
||||||
|
'identity-service.available')
|
||||||
|
api_crud.ensure_hm_port_mtu(identity_service)
|
||||||
|
except Exception:
|
||||||
|
ch_core.hookenv.log('failed to ensure health manager port mtu',
|
||||||
|
level=ch_core.hookenv.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
@reactive.when('config.default.enable-amphora',
|
@reactive.when('config.default.enable-amphora',
|
||||||
'charm.octavia.action_setup_hm_port')
|
'charm.octavia.action_setup_hm_port')
|
||||||
def action_setup_hm_port():
|
def action_setup_hm_port():
|
||||||
|
|
|
@ -282,6 +282,14 @@ class TestAPICrud(test_utils.PatchHelper):
|
||||||
'ids', 'fake-unit-name'))
|
'ids', 'fake-unit-name'))
|
||||||
|
|
||||||
def test_setup_hm_port(self):
|
def test_setup_hm_port(self):
|
||||||
|
self.patch_object(api_crud, 'session_from_identity_service')
|
||||||
|
self.patch_object(api_crud, 'init_neutron_client')
|
||||||
|
nc = mock.MagicMock()
|
||||||
|
self.init_neutron_client.return_value = nc
|
||||||
|
network_uuid = 'fake-network-uuid'
|
||||||
|
nc.list_networks.return_value = {'networks': [{'id': network_uuid,
|
||||||
|
'mtu': 9000}]}
|
||||||
|
|
||||||
self.patch('subprocess.check_output', 'check_output')
|
self.patch('subprocess.check_output', 'check_output')
|
||||||
self.patch('subprocess.check_call', 'check_call')
|
self.patch('subprocess.check_call', 'check_call')
|
||||||
self.patch_object(api_crud, 'get_hm_port')
|
self.patch_object(api_crud, 'get_hm_port')
|
||||||
|
@ -328,10 +336,21 @@ class TestAPICrud(test_utils.PatchHelper):
|
||||||
mock.call(['ip', 'link', 'set', 'o-hm0', 'up', 'address',
|
mock.call(['ip', 'link', 'set', 'o-hm0', 'up', 'address',
|
||||||
'fake-mac-address']),
|
'fake-mac-address']),
|
||||||
])
|
])
|
||||||
self.check_call.assert_called_with(
|
self.check_call.assert_has_calls([
|
||||||
['ip', 'link', 'set', api_crud.octavia.OCTAVIA_MGMT_INTF,
|
mock.call(['ovs-vsctl', '--', 'add-port', 'br-int', 'o-hm0', '--',
|
||||||
'up', 'address', port_mac_address])
|
'set', 'Interface', 'o-hm0', 'type=internal', '--',
|
||||||
self.toggle_hm_port.assert_called
|
'set', 'Interface', 'o-hm0',
|
||||||
|
'external-ids:iface-status=active',
|
||||||
|
'--', 'set', 'Interface', 'o-hm0',
|
||||||
|
'external-ids:attached-mac=fake-mac-address', '--',
|
||||||
|
'set', 'Interface', 'o-hm0',
|
||||||
|
'external-ids:iface-id=fake-port-uuid',
|
||||||
|
'--', 'set', 'Interface', 'o-hm0',
|
||||||
|
'external-ids:skip_cleanup=true']),
|
||||||
|
mock.call(['ip', 'link', 'set', 'o-hm0', 'up', 'address',
|
||||||
|
'fake-mac-address']),
|
||||||
|
mock.call(['ovs-vsctl', 'set', 'Interface', 'o-hm0', 'mtu=9000']),
|
||||||
|
mock.call(['ip', 'link', 'set', 'o-hm0', 'mtu', '9000'])])
|
||||||
|
|
||||||
def test_get_port_ips(self):
|
def test_get_port_ips(self):
|
||||||
self.patch_object(api_crud, 'session_from_identity_service')
|
self.patch_object(api_crud, 'session_from_identity_service')
|
||||||
|
|
|
@ -36,6 +36,8 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks):
|
||||||
]
|
]
|
||||||
hook_set = {
|
hook_set = {
|
||||||
'when': {
|
'when': {
|
||||||
|
'ensure_hm_port_mtu': ('is-update-status-hook',
|
||||||
|
'octavia.hm-port.available'),
|
||||||
'render': ('shared-db.available',
|
'render': ('shared-db.available',
|
||||||
'identity-service.available',
|
'identity-service.available',
|
||||||
'amqp.available',
|
'amqp.available',
|
||||||
|
|
Loading…
Reference in New Issue