From bd0880b0e440a00919173c7a6ae413caa4d7a95f Mon Sep 17 00:00:00 2001 From: zhangzhang Date: Wed, 4 Jan 2017 05:40:02 -0500 Subject: [PATCH] Add neutron.CreateAndShowSubnet scenario The scenario creates a network, a given number of subnets and show the subnet details. This scenario measures the "neutron subnet-show" command performance. Change-Id: I339adadd218ba51bc8ef5e8d0f577879684c3fb9 --- rally-jobs/rally-neutron.yaml | 24 +++++++++++++ .../openstack/scenarios/neutron/network.py | 32 +++++++++++++++++ .../openstack/scenarios/neutron/utils.py | 11 ++++++ .../neutron/create-and-show-subnets.json | 35 +++++++++++++++++++ .../neutron/create-and-show-subnets.yaml | 24 +++++++++++++ .../scenarios/neutron/test_network.py | 25 +++++++++++++ .../openstack/scenarios/neutron/test_utils.py | 9 +++++ 7 files changed, 160 insertions(+) create mode 100644 samples/tasks/scenarios/neutron/create-and-show-subnets.json create mode 100644 samples/tasks/scenarios/neutron/create-and-show-subnets.yaml diff --git a/rally-jobs/rally-neutron.yaml b/rally-jobs/rally-neutron.yaml index 1de3bbec..5243af98 100644 --- a/rally-jobs/rally-neutron.yaml +++ b/rally-jobs/rally-neutron.yaml @@ -85,6 +85,30 @@ failure_rate: max: 20 + NeutronNetworks.create_and_show_subnets: + - + args: + network_create_args: + subnet_create_args: + subnet_cidr_start: "1.1.0.0/30" + subnets_per_network: 2 + runner: + type: "constant" + times: {{smoke or 20 }} + concurrency: {{smoke or 10}} + context: + network: {} + users: + tenants: {{smoke or 3}} + users_per_tenant: {{smoke or 2}} + quotas: + neutron: + network: -1 + subnet: -1 + sla: + failure_rate: + max: 20 + NeutronSecurityGroup.create_and_list_security_groups: - args: diff --git a/rally/plugins/openstack/scenarios/neutron/network.py b/rally/plugins/openstack/scenarios/neutron/network.py index 49126308..6c30b656 100644 --- a/rally/plugins/openstack/scenarios/neutron/network.py +++ b/rally/plugins/openstack/scenarios/neutron/network.py @@ -154,6 +154,38 @@ class CreateAndUpdateSubnets(utils.NeutronScenario): self._update_subnet(subnet, subnet_update_args) +@validation.number("subnets_per_network", minval=1, integer_only=True) +@validation.required_services(consts.Service.NEUTRON) +@validation.required_openstack(users=True) +@scenario.configure(context={"cleanup": ["neutron"]}, + name="NeutronNetworks.create_and_show_subnets") +class CreateAndShowSubnets(utils.NeutronScenario): + + def run(self, network_create_args=None, + subnet_create_args=None, subnet_cidr_start=None, + subnets_per_network=1): + """Create and show a subnet details. + + The scenario creates a network, a given number of subnets + and show the subnet details. This scenario measures the + "neutron subnet-show" command performance. + + :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 one network + """ + network = self._get_or_create_network(network_create_args) + subnets = self._create_subnets(network, subnet_create_args, + subnet_cidr_start, subnets_per_network) + + with atomic.ActionTimer(self, + "neutron.show_%s_subnets" % len(subnets)): + for subnet in subnets: + self._show_subnet(subnet, atomic_action=False) + + @validation.required_parameters("subnets_per_network") @validation.required_services(consts.Service.NEUTRON) @scenario.configure(context={"cleanup": ["neutron"]}, diff --git a/rally/plugins/openstack/scenarios/neutron/utils.py b/rally/plugins/openstack/scenarios/neutron/utils.py index a65f5185..c3f1d8df 100755 --- a/rally/plugins/openstack/scenarios/neutron/utils.py +++ b/rally/plugins/openstack/scenarios/neutron/utils.py @@ -164,6 +164,17 @@ class NeutronScenario(scenario.OpenStackScenario): """Returns user subnetworks list.""" return self.clients("neutron").list_subnets()["subnets"] + @atomic.optional_action_timer("neutron.show_subnet") + def _show_subnet(self, subnet, **kwargs): + """show subnet details. + + :param: subnet: Subnet object + :param: kwargs: Optional additional arguments for subnet show + :returns: details of the subnet + """ + return self.clients("neutron").show_subnet(subnet["subnet"]["id"], + **kwargs) + @atomic.action_timer("neutron.update_subnet") def _update_subnet(self, subnet, subnet_update_args): """Update the neutron subnet. diff --git a/samples/tasks/scenarios/neutron/create-and-show-subnets.json b/samples/tasks/scenarios/neutron/create-and-show-subnets.json new file mode 100644 index 00000000..d944b153 --- /dev/null +++ b/samples/tasks/scenarios/neutron/create-and-show-subnets.json @@ -0,0 +1,35 @@ +{ + "NeutronNetworks.create_and_show_subnets": [ + { + "args": { + "network_create_args": {}, + "subnet_create_args": {}, + "subnet_cidr_start": "1.1.0.0/30", + "subnets_per_network": 2 + }, + "runner": { + "type": "constant", + "times": 10, + "concurrency": 5 + }, + "context": { + "network": {}, + "users": { + "tenants": 2, + "users_per_tenant": 3 + }, + "quotas": { + "neutron": { + "network": -1, + "subnet": -1 + } + } + }, + "sla": { + "failure_rate": { + "max": 0 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/neutron/create-and-show-subnets.yaml b/samples/tasks/scenarios/neutron/create-and-show-subnets.yaml new file mode 100644 index 00000000..f1432ef1 --- /dev/null +++ b/samples/tasks/scenarios/neutron/create-and-show-subnets.yaml @@ -0,0 +1,24 @@ +--- + NeutronNetworks.create_and_show_subnets: + - + args: + network_create_args: {} + subnet_create_args: {} + subnet_cidr_start: "1.1.0.0/30" + subnets_per_network: 2 + runner: + type: "constant" + times: 10 + concurrency: 5 + context: + network: {} + users: + tenants: 2 + users_per_tenant: 3 + quotas: + neutron: + network: -1 + subnet: -1 + sla: + failure_rate: + max: 0 diff --git a/tests/unit/plugins/openstack/scenarios/neutron/test_network.py b/tests/unit/plugins/openstack/scenarios/neutron/test_network.py index 2d7e42a5..bc13bd55 100644 --- a/tests/unit/plugins/openstack/scenarios/neutron/test_network.py +++ b/tests/unit/plugins/openstack/scenarios/neutron/test_network.py @@ -158,6 +158,31 @@ class NeutronNetworksTestCase(test.ScenarioTestCase): scenario._list_subnets.assert_called_once_with() + def test_create_and_show_subnets(self): + network_create_args = {"router:external": True} + subnet_create_args = {"allocation_pools": []} + subnet_cidr_start = "1.1.0.0/30" + subnets_per_network = 5 + net = mock.MagicMock() + + scenario = network.CreateAndShowSubnets(self.context) + scenario._get_or_create_network = mock.Mock(return_value=net) + scenario._create_subnets = mock.MagicMock() + scenario._show_subnet = 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) + + scenario._get_or_create_network.assert_called_once_with( + network_create_args) + scenario._create_subnets.assert_called_once_with( + net, subnet_create_args, subnet_cidr_start, subnets_per_network) + for subnet in scenario._create_subnets.return_value: + scenario._show_subnet.assert_called_with(subnet, + atomic_action=False) + def test_create_and_update_subnets(self): network_create_args = {"router:external": True} subnet_create_args = {"allocation_pools": []} diff --git a/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py b/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py index a9fea7c7..4e3fd740 100755 --- a/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py @@ -183,6 +183,15 @@ class NeutronScenarioTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(self.scenario.atomic_actions(), "neutron.list_subnets") + def test_show_subnet(self): + subnet = {"subnet": {"name": "fake-name", "id": "fake-id"}} + + result_subnet = self.scenario._show_subnet(subnet) + self.assertEqual(self.clients("neutron").show_subnet.return_value, + result_subnet) + self._test_atomic_action_timer(self.scenario.atomic_actions(), + "neutron.show_subnet") + def test_update_subnet(self): expected_subnet = { "subnet": {