Enhance Trunk port scenarios to create multiple trunks

Earlier it was only possible to create one trunk port with multiple
subports. This commits adds capability to specify number of trunks each
with some subports.

Change-Id: Icc23fd28dab617d841f2b1aff6cc813e4c869290
This commit is contained in:
Sai Sindhur Malleni 2018-12-14 11:25:28 -05:00
parent 140d017877
commit baf4b91a71
9 changed files with 37 additions and 9 deletions

View File

@ -35,6 +35,7 @@ Added
* [scenario plugin] Octavia.create_and_show_pools * [scenario plugin] Octavia.create_and_show_pools
* Support for osprofiler config in Devstack plugin. * Support for osprofiler config in Devstack plugin.
* Added property 'floating_ip_enabled' in magnum cluster_templates context. * Added property 'floating_ip_enabled' in magnum cluster_templates context.
* Enhanced neutron trunk port scenario to create multiple trunks
Changed Changed
~~~~~~~ ~~~~~~~

View File

@ -621,6 +621,7 @@
- -
args: args:
network_create_args: {} network_create_args: {}
trunk_count: 1
subport_count: 10 subport_count: 10
runner: runner:
type: "constant" type: "constant"

View File

@ -608,14 +608,16 @@ class DeleteSubnets(utils.NeutronScenario):
@validation.add("number", param_name="subport_count", minval=1, @validation.add("number", param_name="subport_count", minval=1,
integer_only=True) integer_only=True)
@validation.add("number", param_name="trunk_count", minval=1,
integer_only=True)
@validation.add("required_services", services=[consts.Service.NEUTRON]) @validation.add("required_services", services=[consts.Service.NEUTRON])
@validation.add("required_platform", platform="openstack", users=True) @validation.add("required_platform", platform="openstack", users=True)
@scenario.configure(context={"cleanup@openstack": ["neutron"]}, @scenario.configure(context={"cleanup@openstack": ["neutron"]},
name="NeutronTrunks.create_and_list_trunks") name="NeutronTrunks.create_and_list_trunks")
class CreateAndListTrunks(utils.NeutronScenario): class CreateAndListTrunks(utils.NeutronScenario):
def run(self, network_create_args=None, subport_count=10): def run(self, network_create_args=None, trunk_count=1, subport_count=10):
"""Create and a given number of trunks with subports and list all trunks """Create given number of trunks with subports and list all trunks.
:param network_create_args: dict, POST /v2.0/networks request :param network_create_args: dict, POST /v2.0/networks request
options. Deprecated. options. Deprecated.
@ -623,15 +625,23 @@ class CreateAndListTrunks(utils.NeutronScenario):
:param subport_count: int, number of subports per trunk :param subport_count: int, number of subports per trunk
""" """
net = self._create_network(network_create_args or {}) net = self._create_network(network_create_args or {})
ports = [self._create_port(net, {}) for _ in range(subport_count)] ports = [self._create_port(net, {}) for _ in range(
parent, subports = ports[0], ports[1:] (trunk_count + trunk_count * subport_count))]
parents, subports = ports[0:trunk_count], ports[trunk_count:]
subport_payload = [{"port_id": p["port"]["id"], subport_payload = [{"port_id": p["port"]["id"],
"segmentation_type": "vlan", "segmentation_type": "vlan",
"segmentation_id": seg_id} "segmentation_id": seg_id}
for seg_id, p in enumerate(subports, start=1)] for seg_id, p in enumerate(subports, start=1)]
trunk_payload = {"port_id": parent["port"]["id"], subport_index = 0
"sub_ports": subport_payload} for p in parents:
self._create_trunk(trunk_payload) trunk_payload = {
self._update_port(parent, {"device_id": "sometrunk"}) "port_id": p["port"]["id"],
"sub_ports": subport_payload[slice(
subport_index, subport_index + subport_count)]
}
trunk = self._create_trunk(trunk_payload)
self._update_port(p, {"device_id": "sometrunk"})
self._list_subports_by_trunk(trunk["trunk"]["id"])
subport_index += subport_count
self._list_trunks() self._list_trunks()
self._list_ports_by_device_id("sometrunk") self._list_ports_by_device_id("sometrunk")

View File

@ -894,3 +894,7 @@ class NeutronScenario(scenario.OpenStackScenario):
@atomic.optional_action_timer("neutron.list_ports_by_device_id") @atomic.optional_action_timer("neutron.list_ports_by_device_id")
def _list_ports_by_device_id(self, device_id): def _list_ports_by_device_id(self, device_id):
return self.clients("neutron").list_ports(device_id=device_id) return self.clients("neutron").list_ports(device_id=device_id)
@atomic.optional_action_timer("neutron.list_subports_by_trunk")
def _list_subports_by_trunk(self, trunk_id):
return self.clients("neutron").trunk_get_subports(trunk_id)

View File

@ -3,6 +3,7 @@
{ {
"args": { "args": {
"network_create_args": {}, "network_create_args": {},
"trunk_count": 1,
"subport_count": 10 "subport_count": 10
}, },
"runner": { "runner": {

View File

@ -4,6 +4,7 @@
- -
args: args:
network_create_args: {} network_create_args: {}
trunk_count: 1
subport_count: 10 subport_count: 10
runner: runner:
type: "constant" type: "constant"

View File

@ -265,6 +265,7 @@
- -
args: args:
network_create_args: {} network_create_args: {}
trunk_count: 1
subport_count: 10 subport_count: 10
context: context:
{% call user_context(tenants_amount, users_amount, use_existing_users) %} {% call user_context(tenants_amount, users_amount, use_existing_users) %}

View File

@ -598,6 +598,7 @@ class NeutronNetworksTestCase(test.ScenarioTestCase):
mock__delete_subnet.call_args_list) mock__delete_subnet.call_args_list)
def test_create_and_list_trunks(self): def test_create_and_list_trunks(self):
trunk_count = 1
subport_count = 10 subport_count = 10
network_create_args = {} network_create_args = {}
net = mock.MagicMock() net = mock.MagicMock()
@ -613,7 +614,7 @@ class NeutronNetworksTestCase(test.ScenarioTestCase):
network_create_args) network_create_args)
scenario._create_port.assert_has_calls( scenario._create_port.assert_has_calls(
[mock.call(net, {}) [mock.call(net, {})
for _ in range(subport_count)]) for _ in range(trunk_count + (trunk_count * subport_count))])
self.assertEqual(1, scenario._create_trunk.call_count) self.assertEqual(1, scenario._create_trunk.call_count)
self.assertEqual(1, scenario._update_port.call_count) self.assertEqual(1, scenario._update_port.call_count)
self.assertEqual(1, scenario._list_ports_by_device_id.call_count) self.assertEqual(1, scenario._list_ports_by_device_id.call_count)

View File

@ -1331,6 +1331,14 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
self.clients("neutron").list_ports.assert_called_once_with( self.clients("neutron").list_ports.assert_called_once_with(
device_id=device_id) device_id=device_id)
def test__list_subports_by_trunk(self):
trunk_id = "trunk-id"
self.scenario._list_subports_by_trunk(trunk_id)
self.clients("neutron").trunk_get_subports.assert_called_once_with(
trunk_id)
self._test_atomic_action_timer(self.scenario.atomic_actions(),
"neutron.list_subports_by_trunk")
class NeutronScenarioFunctionalTestCase(test.FakeClientsScenarioTestCase): class NeutronScenarioFunctionalTestCase(test.FakeClientsScenarioTestCase):