diff options
author | fmenguy <francoisregis.menguy@orange.com> | 2021-02-16 15:32:11 +0100 |
---|---|---|
committer | Fran�ois-R�gis Menguy <francoisregis.menguy@orange.com> | 2021-03-04 15:38:58 +0000 |
commit | 8eb504093d45737a4411f997022b7e67f217aefd (patch) | |
tree | b6b54d645330bdb2ac7636619b17e8055afb00f4 | |
parent | 1c686977d9146f1b2dbbf0085c98897311c46789 (diff) |
NFVBENCH-201 Fix port creation with accurate subnet_id
Change-Id: I419cfeb82d16ff1ac1145df5d52fe6f88d890a49
Signed-off-by: fmenguy <francoisregis.menguy@orange.com>
-rw-r--r-- | nfvbench/chaining.py | 18 | ||||
-rw-r--r-- | test/test_chains.py | 8 |
2 files changed, 26 insertions, 0 deletions
diff --git a/nfvbench/chaining.py b/nfvbench/chaining.py index ed2f309..fea1c12 100644 --- a/nfvbench/chaining.py +++ b/nfvbench/chaining.py @@ -158,6 +158,10 @@ class ChainVnfPort(object): 'binding:vnic_type': vnic_type } } + subnet_id = chain_network.get_subnet_uuid() + if subnet_id: + body['port']['fixed_ips'] = [{'subnet_id': subnet_id}] + port = self.manager.neutron_client.create_port(body) self.port = port['port'] LOG.info('Created port %s', name) @@ -240,6 +244,7 @@ class ChainNetwork(object): self.name = self.name + suffix self.segmentation_id = self._get_item(network_config.segmentation_id, chain_id, auto_index=True) + self.subnet_name = self._get_item(network_config.subnet, chain_id) self.physical_network = self._get_item(network_config.physical_network, chain_id) self.reuse = False @@ -352,6 +357,18 @@ class ChainNetwork(object): """ return self.network['id'] + def get_subnet_uuid(self): + """ + Extract UUID of this subnet network. + + :return: UUID of this subnet network + """ + for subnet in self.network['subnets']: + if self.subnet_name == self.manager.neutron_client \ + .show_subnet(subnet)['subnet']['name']: + return subnet + return None + def get_vlan(self): """ Extract vlan for this network. @@ -1322,6 +1339,7 @@ class ChainManager(object): lookup_only = True ext_net = self.config.external_networks net_cfg = [AttrDict({'name': name, + 'subnet': None, 'segmentation_id': None, 'physical_network': None}) for name in [ext_net.left, ext_net.right]] diff --git a/test/test_chains.py b/test/test_chains.py index a9df54f..d6f32c7 100644 --- a/test/test_chains.py +++ b/test/test_chains.py @@ -39,6 +39,7 @@ from nfvbench.summarizer import _annotate_chain_stats from nfvbench.traffic_client import TrafficClient from nfvbench.traffic_gen.traffic_base import Latency from nfvbench.traffic_gen.trex_gen import TRex +from nfvbench import utils # just to get rid of the unused function warning no_op() @@ -108,7 +109,11 @@ def test_chain_runner_ext_no_openstack(): def _mock_find_image(self, image_name): return MagicMock() +def _mock_waiting_servers_deletion(nova_client, servers): + return MagicMock() + @patch.object(Compute, 'find_image', _mock_find_image) +@patch.object(utils, 'waiting_servers_deletion', _mock_waiting_servers_deletion) @patch('nfvbench.chaining.Client') @patch('nfvbench.chaining.neutronclient') @patch('nfvbench.chaining.glanceclient') @@ -140,6 +145,7 @@ def test_pvp_chain_runner(): # Test not admin exception with empty value is raised @patch.object(Compute, 'find_image', _mock_find_image) +@patch.object(utils, 'waiting_servers_deletion', _mock_waiting_servers_deletion) @patch('nfvbench.chaining.Client') @patch('nfvbench.chaining.neutronclient') @patch('nfvbench.chaining.glanceclient') @@ -169,6 +175,7 @@ def test_pvp_chain_runner_no_admin_no_config_values(): # Test not admin with mandatory parameters values in config file @patch.object(Compute, 'find_image', _mock_find_image) +@patch.object(utils, 'waiting_servers_deletion', _mock_waiting_servers_deletion) @patch('nfvbench.chaining.Client') @patch('nfvbench.chaining.neutronclient') @patch('nfvbench.chaining.glanceclient') @@ -275,6 +282,7 @@ def _mock_get_mac(dummy): @patch.object(TrafficClient, 'skip_sleep', lambda x: True) @patch.object(ChainVnfPort, 'get_mac', _mock_get_mac) @patch.object(TrafficClient, 'is_udp', lambda x, y: True) +@patch.object(utils, 'waiting_servers_deletion', _mock_waiting_servers_deletion) @patch('nfvbench.chaining.Client') @patch('nfvbench.chaining.neutronclient') @patch('nfvbench.chaining.glanceclient') |