Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
348 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# Copyright 2020 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. | ||
|
||
"""Code for configuring OVN tests.""" | ||
|
||
import logging | ||
|
||
import zaza | ||
|
||
import zaza.openstack.charm_tests.test_utils as test_utils | ||
|
||
|
||
class _OVNSetupHelper(test_utils.BaseCharmTest): | ||
"""Helper class to get at the common `config_change` helper.""" | ||
|
||
@staticmethod | ||
def _get_instance_mtu_from_global_physnet_mtu(): | ||
"""Calculate instance mtu from Neutron API global-physnet-mtu. | ||
:returns: Value for instance mtu after migration. | ||
:rtype: int | ||
""" | ||
n_api_config = zaza.model.get_application_config('neutron-api') | ||
|
||
# NOTE: we would have to adjust this calculation if we use IPv6 tunnel | ||
# endpoints | ||
GENEVE_ENCAP_OVERHEAD = 38 | ||
IP4_HEADER_SIZE = 20 | ||
return int(n_api_config['global-physnet-mtu']['value']) - ( | ||
GENEVE_ENCAP_OVERHEAD + IP4_HEADER_SIZE) | ||
|
||
def configure_ngw_novs(self): | ||
"""Configure n-ovs and n-gw units.""" | ||
cfg = { | ||
# To be able to successfully clean up after the Neutron agents we | ||
# need to use the 'openvswitch' `firewall-driver`. | ||
'firewall-driver': 'openvswitch', | ||
# To be able to have instances successfully survive the migration | ||
# without communication issues we need to lower the MTU announced | ||
# to instances prior to migration. | ||
# | ||
# NOTE: In a real world scenario the end user would configure the | ||
# MTU at least 24 hrs prior to doing the migration to allow | ||
# instances to reconfigure as they renew the DHCP lease. | ||
# | ||
# NOTE: For classic n-gw topologies the `instance-mtu` config | ||
# is a NOOP on neutron-openvswitch units, but that is ok. | ||
'instance-mtu': self._get_instance_mtu_from_global_physnet_mtu() | ||
} | ||
apps = ('neutron-gateway', 'neutron-openvswitch') | ||
for app in apps: | ||
try: | ||
zaza.model.get_application(app) | ||
for k, v in cfg.items(): | ||
logging.info('Setting `{}` to "{}" on "{}"...' | ||
.format(k, v, app)) | ||
with self.config_change(cfg, cfg, app): | ||
continue | ||
except KeyError: | ||
pass | ||
|
||
def configure_ovn_mappings(self): | ||
"""Copy mappings from n-gw or n-ovs application.""" | ||
dst_apps = ('ovn-dedicated-chassis', 'ovn-chassis') | ||
src_apps = ('neutron-gateway', 'neutron-openvswitch') | ||
ovn_cfg = {} | ||
for app in src_apps: | ||
try: | ||
app_cfg = zaza.model.get_application_config(app) | ||
ovn_cfg['bridge-interface-mappings'] = app_cfg[ | ||
'data-port']['value'] | ||
ovn_cfg['ovn-bridge-mappings'] = app_cfg[ | ||
'bridge-mappings']['value'] | ||
# Use values from neutron-gateway when present, otherwise use | ||
# values from neutron-openvswitch | ||
break | ||
except KeyError: | ||
pass | ||
else: | ||
raise RuntimeError( | ||
'None of the expected apps ({}) are present in the model.' | ||
.format(src_apps) | ||
) | ||
|
||
for app in dst_apps: | ||
try: | ||
zaza.model.get_application(app) | ||
for k, v in ovn_cfg.items(): | ||
logging.info('Setting `{}` to "{}" on "{}"...' | ||
.format(k, v, app)) | ||
with self.config_change(ovn_cfg, ovn_cfg, app): | ||
# Set values only on ovn-dedicated-chassis when present, | ||
# otherwise we set them on ovn-chassis. | ||
break | ||
except KeyError: | ||
pass | ||
else: | ||
raise RuntimeError( | ||
'None of the expected apps ({}) are present in the model.' | ||
.format(dst_apps) | ||
) | ||
|
||
|
||
def pre_migration_configuration(): | ||
"""Perform pre-migration configuration steps. | ||
NOTE: Doing the configuration post-deploy and after doing initial network | ||
configuration is an important part of the test as we need to prove that our | ||
end users would be successful in doing this in the wild. | ||
""" | ||
# we use a helper class to leverage common setup code and the | ||
# `config_change` helper | ||
helper = _OVNSetupHelper() | ||
helper.setUpClass() | ||
# Configure `firewall-driver` and `instance-mtu` on n-gw and n-ovs units. | ||
helper.configure_ngw_novs() | ||
# Copy mappings from n-gw or n-ovs application to ovn-dedicated-chassis or | ||
# ovn-chassis. | ||
helper.configure_ovn_mappings() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters