From b44c93b7f6a4f24307e15578655e3faf9e8800b9 Mon Sep 17 00:00:00 2001 From: maxinjian Date: Wed, 15 Feb 2017 12:22:31 -0500 Subject: [PATCH] Add NeutronNetworks.create_and_show_routers Create a network, a given number of subnets and routers and then show all routers. Change-Id: I976875f585eaaf4b150eb9d9f942595badaeda77 --- rally-jobs/rally-neutron.yaml | 20 +++++++++++ .../openstack/scenarios/neutron/network.py | 34 +++++++++++++++++-- .../openstack/scenarios/neutron/utils.py | 11 ++++++ .../neutron/create-and-show-routers.json | 29 ++++++++++++++++ .../neutron/create-and-show-routers.yaml | 20 +++++++++++ .../scenarios/neutron/test_network.py | 28 +++++++++++++++ .../openstack/scenarios/neutron/test_utils.py | 15 ++++++++ 7 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 samples/tasks/scenarios/neutron/create-and-show-routers.json create mode 100644 samples/tasks/scenarios/neutron/create-and-show-routers.yaml diff --git a/rally-jobs/rally-neutron.yaml b/rally-jobs/rally-neutron.yaml index 62cbb681..51f0ddb8 100644 --- a/rally-jobs/rally-neutron.yaml +++ b/rally-jobs/rally-neutron.yaml @@ -257,6 +257,26 @@ failure_rate: max: 20 + NeutronNetworks.create_and_show_routers: + - + args: + subnet_cidr_start: "1.1.0.0/30" + subnets_per_network: 2 + runner: + type: "constant" + times: 4 + concurrency: 2 + context: + network: {} + users: + tenants: 2 + users_per_tenant: 2 + quotas: + neutron: + network: -1 + subnet: -1 + router: -1 + NeutronNetworks.create_and_list_ports: - args: diff --git a/rally/plugins/openstack/scenarios/neutron/network.py b/rally/plugins/openstack/scenarios/neutron/network.py index 68f1c594..eaa896f4 100644 --- a/rally/plugins/openstack/scenarios/neutron/network.py +++ b/rally/plugins/openstack/scenarios/neutron/network.py @@ -156,7 +156,7 @@ class CreateAndUpdateSubnets(utils.NeutronScenario): @validation.number("subnets_per_network", minval=1, integer_only=True) @validation.required_services(consts.Service.NEUTRON) -@validation.required_openstack(users=True) +@validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["neutron"]}, name="NeutronNetworks.create_and_show_subnets") class CreateAndShowSubnets(utils.NeutronScenario): @@ -241,6 +241,36 @@ class CreateAndListRouters(utils.NeutronScenario): self._list_routers() +@validation.number("subnets_per_network", minval=1, integer_only=True) +@validation.required_services(consts.Service.NEUTRON) +@validation.add("required_platform", platform="openstack", users=True) +@scenario.configure(context={"cleanup": ["neutron"]}, + name="NeutronNetworks.create_and_show_routers") +class CreateAndShowRouters(utils.NeutronScenario): + + def run(self, network_create_args=None, subnet_create_args=None, + subnet_cidr_start=None, subnets_per_network=1, + router_create_args=None): + """Create and show a given number of routers. + + Create a network, a given number of subnets and routers + and then show all routers. + + :param network_create_args: dict, POST /v2.0/networks request + options + :param subnet_create_args: dict, POST /v2.0/subnets request options + :param subnet_cidr_start: str, start value for subnets CIDR + :param subnets_per_network: int, number of subnets for each network + :param router_create_args: dict, POST /v2.0/routers request options + """ + network, subnets, routers = self._create_network_structure( + network_create_args, subnet_create_args, subnet_cidr_start, + subnets_per_network, router_create_args) + + for router in routers: + self._show_router(router) + + @validation.number("subnets_per_network", minval=1, integer_only=True) @validation.required_services(consts.Service.NEUTRON) @scenario.configure(context={"cleanup": ["neutron"]}, @@ -304,7 +334,7 @@ class CreateAndDeleteRouters(utils.NeutronScenario): @validation.required_services(consts.Service.NEUTRON) -@validation.required_openstack(users=True) +@validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["neutron"]}, name="NeutronNetworks.set_and_clear_router_gateway") class SetAndClearRouterGateway(utils.NeutronScenario): diff --git a/rally/plugins/openstack/scenarios/neutron/utils.py b/rally/plugins/openstack/scenarios/neutron/utils.py index cbe8bdda..c0507fb1 100755 --- a/rally/plugins/openstack/scenarios/neutron/utils.py +++ b/rally/plugins/openstack/scenarios/neutron/utils.py @@ -211,6 +211,17 @@ class NeutronScenario(scenario.OpenStackScenario): """Returns user routers list.""" return self.clients("neutron").list_routers()["routers"] + @atomic.action_timer("neutron.show_router") + def _show_router(self, router, **kwargs): + """Show information of a given router. + + :param router: ID or name of router to look up + :kwargs: dict, POST /v2.0/routers show options + :return: details of the router + """ + return self.clients("neutron").show_router( + router["router"]["id"], **kwargs) + @atomic.action_timer("neutron.delete_router") def _delete_router(self, router): """Delete neutron router diff --git a/samples/tasks/scenarios/neutron/create-and-show-routers.json b/samples/tasks/scenarios/neutron/create-and-show-routers.json new file mode 100644 index 00000000..16cea002 --- /dev/null +++ b/samples/tasks/scenarios/neutron/create-and-show-routers.json @@ -0,0 +1,29 @@ +{ + "NeutronNetworks.create_and_show_routers": [ + { + "args": { + "subnet_cidr_start": "1.1.0.0/30", + "subnets_per_network": 2 + }, + "runner": { + "type": "constant", + "times": 4, + "concurrency": 2 + }, + "context": { + "network": {}, + "users": { + "tenants": 2, + "users_per_tenant": 2 + }, + "quotas": { + "neutron": { + "network": -1, + "subnet": -1, + "router": -1 + } + } + } + } + ] +} diff --git a/samples/tasks/scenarios/neutron/create-and-show-routers.yaml b/samples/tasks/scenarios/neutron/create-and-show-routers.yaml new file mode 100644 index 00000000..0b7a43ab --- /dev/null +++ b/samples/tasks/scenarios/neutron/create-and-show-routers.yaml @@ -0,0 +1,20 @@ +--- + NeutronNetworks.create_and_show_routers: + - + args: + subnet_cidr_start: "1.1.0.0/30" + subnets_per_network: 2 + runner: + type: "constant" + times: 4 + concurrency: 2 + context: + network: {} + users: + tenants: 2 + users_per_tenant: 2 + quotas: + neutron: + network: -1 + subnet: -1 + router: -1 diff --git a/tests/unit/plugins/openstack/scenarios/neutron/test_network.py b/tests/unit/plugins/openstack/scenarios/neutron/test_network.py index ebf8ef3a..fa265d9e 100644 --- a/tests/unit/plugins/openstack/scenarios/neutron/test_network.py +++ b/tests/unit/plugins/openstack/scenarios/neutron/test_network.py @@ -352,6 +352,34 @@ class NeutronNetworksTestCase(test.ScenarioTestCase): scenario._delete_router.assert_has_calls( [mock.call(router) for router in routers]) + def test_create_and_show_routers(self): + network_create_args = {"router:external": True} + subnet_create_args = {"allocation_pools": []} + subnet_cidr_start = "default_cidr" + subnets_per_network = 5 + router_create_args = {"admin_state_up": True} + net = mock.MagicMock() + subnets = [mock.MagicMock() for i in range(subnets_per_network)] + routers = [mock.MagicMock() for i in range(subnets_per_network)] + + scenario = network.CreateAndShowRouters(self.context) + scenario._create_network_structure = mock.Mock( + return_value=(net, subnets, routers)) + scenario._show_router = mock.Mock() + + scenario.run(network_create_args=network_create_args, + subnet_create_args=subnet_create_args, + subnet_cidr_start=subnet_cidr_start, + subnets_per_network=subnets_per_network, + router_create_args=router_create_args) + + scenario._create_network_structure.assert_called_once_with( + network_create_args, subnet_create_args, subnet_cidr_start, + subnets_per_network, router_create_args) + + scenario._show_router.assert_has_calls( + [mock.call(router) for router in routers]) + def test_create_and_list_ports(self): port_create_args = {"allocation_pools": []} ports_per_network = 10 diff --git a/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py b/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py index ef83b0ba..60013b3b 100755 --- a/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py @@ -108,6 +108,21 @@ class NeutronScenarioTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(self.scenario.atomic_actions(), "neutron.show_network") + def test_show_router(self): + router = { + "router": { + "id": "fake-id", + "name": "fake-name", + "admin_state_up": False + } + } + + return_router = self.scenario._show_router(router) + self.assertEqual(self.clients("neutron").show_router.return_value, + return_router) + self._test_atomic_action_timer(self.scenario.atomic_actions(), + "neutron.show_router") + def test_update_network(self): expected_network = { "network": {