From e3011f7a8914a10cbe02a61bf5fe30f5bdbf1082 Mon Sep 17 00:00:00 2001 From: Linda Wang Date: Tue, 26 Dec 2017 02:49:05 +0000 Subject: [PATCH] Configure physical_network when creating network When the network_type is vlan, configuring physical_network and segmentation_id should be supported by snaps. Here only testcase test_check_vm_ip_dhcp is changed, which is consumed by functest. JIRA: SNAPS-252 Change-Id: I12ae12f62f73f2ae66fe7ee12a49abf0394669cd Signed-off-by: Linda Wang --- snaps/openstack/tests/create_instance_tests.py | 4 ++- snaps/openstack/tests/openstack_tests.py | 35 ++++++++++++++++++++------ snaps/openstack/tests/os_source_file_test.py | 11 +++++--- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/snaps/openstack/tests/create_instance_tests.py b/snaps/openstack/tests/create_instance_tests.py index 486018d..055a5d8 100644 --- a/snaps/openstack/tests/create_instance_tests.py +++ b/snaps/openstack/tests/create_instance_tests.py @@ -306,7 +306,9 @@ class SimpleHealthCheck(OSIntegrationTestCase): self.inst_creator = None self.priv_net_config = openstack_tests.get_priv_net_config( - net_name=guid + '-priv-net', subnet_name=guid + '-priv-subnet') + net_name=guid + '-priv-net', + subnet_name=guid + '-priv-subnet', + netconf_override=self.netconf_override) self.port_settings = PortConfig( name=self.port_1_name, network_name=self.priv_net_config.network_settings.name) diff --git a/snaps/openstack/tests/openstack_tests.py b/snaps/openstack/tests/openstack_tests.py index 4b00922..3bd94c1 100644 --- a/snaps/openstack/tests/openstack_tests.py +++ b/snaps/openstack/tests/openstack_tests.py @@ -316,31 +316,50 @@ def ubuntu_image_settings(name, url=None, image_metadata=None, def get_priv_net_config(net_name, subnet_name, router_name=None, - cidr='10.55.0.0/24', external_net=None): + cidr='10.55.0.0/24', external_net=None, + netconf_override=None): return OSNetworkConfig(net_name, subnet_name, cidr, router_name, - external_gateway=external_net) + external_gateway=external_net, + netconf_override=netconf_override) def get_pub_net_config(net_name, subnet_name=None, router_name=None, - cidr='10.55.1.0/24', external_net=None): + cidr='10.55.1.0/24', external_net=None, + netconf_override=None): return OSNetworkConfig(net_name, subnet_name, cidr, router_name, - external_gateway=external_net) + external_gateway=external_net, + netconf_override=netconf_override) class OSNetworkConfig: """ Represents the settings required for the creation of a network in OpenStack + where netconf_override is used to reconfigure the network_type, + physical_network and segmentation_id """ def __init__(self, net_name, subnet_name=None, subnet_cidr=None, - router_name=None, external_gateway=None): - + router_name=None, external_gateway=None, + netconf_override=None): + """ + :param netconf_override: dict() containing the reconfigured network_type, + physical_network and segmentation_id + """ + + network_conf = None if subnet_name and subnet_cidr: - self.network_settings = NetworkConfig( + network_conf = NetworkConfig( name=net_name, subnet_settings=[ SubnetConfig(cidr=subnet_cidr, name=subnet_name)]) else: - self.network_settings = NetworkConfig(name=net_name) + network_conf = NetworkConfig(name=net_name) + if netconf_override: + network_conf.network_type = netconf_override.get('network_type') + network_conf.physical_network = netconf_override.get( + 'physical_network') + network_conf.segmentation_id = netconf_override.get( + 'segmentation_id') + self.network_settings = network_conf if router_name: if subnet_name: diff --git a/snaps/openstack/tests/os_source_file_test.py b/snaps/openstack/tests/os_source_file_test.py index ef4fcfa..7e910a4 100644 --- a/snaps/openstack/tests/os_source_file_test.py +++ b/snaps/openstack/tests/os_source_file_test.py @@ -80,7 +80,7 @@ class OSIntegrationTestCase(OSComponentTestCase): def __init__(self, method_name='runTest', os_creds=None, ext_net_name=None, use_keystone=True, flavor_metadata=None, image_metadata=None, - log_level=logging.DEBUG): + netconf_override=None, log_level=logging.DEBUG): """ Super for integration tests requiring a connection to OpenStack :param method_name: default 'runTest' @@ -98,12 +98,15 @@ class OSIntegrationTestCase(OSComponentTestCase): 'ramdisk_url': '{URI}/cirros-0.3.4-x86_64-initramfs'}) :param flavor_metadata: dict() to be sent directly into the Nova client generally used for page sizes + :param netconf_override: dict() containing the configured network_type, + physical_network and segmentation_id :param log_level: the logging level of your test run (default DEBUG) """ super(OSIntegrationTestCase, self).__init__( method_name=method_name, os_creds=os_creds, ext_net_name=ext_net_name, image_metadata=image_metadata, log_level=log_level) + self.netconf_override = netconf_override self.use_keystone = use_keystone self.keystone = None self.flavor_metadata = flavor_metadata @@ -111,7 +114,8 @@ class OSIntegrationTestCase(OSComponentTestCase): @staticmethod def parameterize(testcase_klass, os_creds, ext_net_name, use_keystone=False, flavor_metadata=None, - image_metadata=None, log_level=logging.DEBUG): + image_metadata=None, netconf_override=None, + log_level=logging.DEBUG): """ Create a suite containing all tests taken from the given subclass, passing them the parameter 'param'. @@ -122,7 +126,8 @@ class OSIntegrationTestCase(OSComponentTestCase): for name in test_names: suite.addTest(testcase_klass(name, os_creds, ext_net_name, use_keystone, flavor_metadata, - image_metadata, log_level)) + image_metadata, netconf_override, + log_level)) return suite """ -- 2.16.6