From 1f27258a8dd0622b630252faf57a9aa92f76d929 Mon Sep 17 00:00:00 2001 From: zhangzhang Date: Tue, 3 Jan 2017 11:03:48 -0500 Subject: [PATCH] Add neutron.CreateAndShowNetwork scenario Create a network, then show details of the network. Change-Id: I4d9f89e16b15d879db5941205dba4bc74e95979b --- rally-jobs/rally-neutron.yaml | 19 ++++++++++++ .../openstack/scenarios/neutron/network.py | 17 +++++++++++ .../openstack/scenarios/neutron/utils.py | 11 +++++++ .../neutron/create-and-show-network.json | 30 +++++++++++++++++++ .../neutron/create-and-show-network.yaml | 19 ++++++++++++ .../scenarios/neutron/test_network.py | 23 ++++++++++++++ .../openstack/scenarios/neutron/test_utils.py | 15 ++++++++++ 7 files changed, 134 insertions(+) create mode 100644 samples/tasks/scenarios/neutron/create-and-show-network.json create mode 100644 samples/tasks/scenarios/neutron/create-and-show-network.yaml diff --git a/rally-jobs/rally-neutron.yaml b/rally-jobs/rally-neutron.yaml index 6e8d25b6..c340ecf6 100644 --- a/rally-jobs/rally-neutron.yaml +++ b/rally-jobs/rally-neutron.yaml @@ -42,6 +42,25 @@ failure_rate: max: 20 + NeutronNetworks.create_and_show_network: + - + args: + network_create_args: {} + runner: + type: "constant" + times: {{smoke or 10}} + concurrency: {{smoke or 2}} + context: + users: + tenants: {{smoke or 3}} + users_per_tenant: {{smoke or 2}} + quotas: + neutron: + network: -1 + sla: + failure_rate: + max: 0 + NeutronNetworks.create_and_list_subnets: - args: diff --git a/rally/plugins/openstack/scenarios/neutron/network.py b/rally/plugins/openstack/scenarios/neutron/network.py index 1ea2d5cb..59bec825 100644 --- a/rally/plugins/openstack/scenarios/neutron/network.py +++ b/rally/plugins/openstack/scenarios/neutron/network.py @@ -45,6 +45,23 @@ class CreateAndListNetworks(utils.NeutronScenario): self._list_networks() +@validation.required_services(consts.Service.NEUTRON) +@validation.required_openstack(users=True) +@scenario.configure(context={"cleanup": ["neutron"]}, + name="NeutronNetworks.create_and_show_network") +class CreateAndShowNetwork(utils.NeutronScenario): + + def run(self, network_create_args=None): + """Create a network and show network details. + + Measure the "neutron net-show" command performance. + + :param network_create_args: dict, POST /v2.0/networks request options + """ + network = self._create_network(network_create_args or {}) + self._show_network(network) + + @validation.required_services(consts.Service.NEUTRON) @validation.required_openstack(users=True) @scenario.configure(context={"cleanup": ["neutron"]}, diff --git a/rally/plugins/openstack/scenarios/neutron/utils.py b/rally/plugins/openstack/scenarios/neutron/utils.py index 8321f79e..ca1d2662 100644 --- a/rally/plugins/openstack/scenarios/neutron/utils.py +++ b/rally/plugins/openstack/scenarios/neutron/utils.py @@ -98,6 +98,17 @@ class NeutronScenario(scenario.OpenStackScenario): return self.clients("neutron").update_network( network["network"]["id"], body) + @atomic.action_timer("neutron.show_network") + def _show_network(self, network, **kwargs): + """show network details. + + :param network: Network object + :param kwargs: dict, POST /v2.0/networks show options + :returns: details of the network + """ + return self.clients("neutron").show_network( + network["network"]["id"], **kwargs) + @atomic.action_timer("neutron.delete_network") def _delete_network(self, network): """Delete neutron network. diff --git a/samples/tasks/scenarios/neutron/create-and-show-network.json b/samples/tasks/scenarios/neutron/create-and-show-network.json new file mode 100644 index 00000000..559fbbcc --- /dev/null +++ b/samples/tasks/scenarios/neutron/create-and-show-network.json @@ -0,0 +1,30 @@ +{ + "NeutronNetworks.create_and_show_network": [ + { + "args": { + "network_create_args": {} + }, + "runner": { + "type": "constant", + "times": 10, + "concurrency": 2 + }, + "context": { + "users": { + "tenants": 3, + "users_per_tenant": 3 + }, + "quotas": { + "neutron": { + "network": -1 + } + } + }, + "sla": { + "failure_rate": { + "max": 0 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/neutron/create-and-show-network.yaml b/samples/tasks/scenarios/neutron/create-and-show-network.yaml new file mode 100644 index 00000000..11090023 --- /dev/null +++ b/samples/tasks/scenarios/neutron/create-and-show-network.yaml @@ -0,0 +1,19 @@ +--- + NeutronNetworks.create_and_show_network: + - + args: + network_create_args: {} + runner: + type: "constant" + times: 10 + concurrency: 2 + context: + users: + tenants: 3 + users_per_tenant: 3 + quotas: + neutron: + network: -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 1efad093..925a7d27 100644 --- a/tests/unit/plugins/openstack/scenarios/neutron/test_network.py +++ b/tests/unit/plugins/openstack/scenarios/neutron/test_network.py @@ -46,6 +46,29 @@ class NeutronNetworksTestCase(test.ScenarioTestCase): mock__create_network.reset_mock() mock__list_networks.reset_mock() + @ddt.data( + {"network_create_args": {}}, + {"network_create_args": {"name": "given-name"}}, + ) + @ddt.unpack + @mock.patch("%s.CreateAndShowNetwork._show_network" % BASE) + @mock.patch("%s.CreateAndShowNetwork._create_network" % BASE) + def test_create_and_show_network(self, + mock__create_network, + mock__show_network, + network_create_args): + scenario = network.CreateAndShowNetwork(self.context) + mock_net = mock.Mock() + + mock__create_network.return_value = mock_net + scenario.run(network_create_args=network_create_args) + + mock__create_network.assert_called_once_with(network_create_args) + mock__show_network.assert_called_once_with(mock_net) + + mock__create_network.reset_mock() + mock__show_network.reset_mock() + @mock.patch("%s.CreateAndUpdateNetworks._update_network" % BASE) @mock.patch("%s.CreateAndUpdateNetworks._create_network" % BASE, return_value={ diff --git a/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py b/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py index d66fe872..05f238f0 100644 --- a/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py @@ -94,6 +94,21 @@ class NeutronScenarioTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(self.scenario.atomic_actions(), "neutron.list_networks") + def test_show_network(self): + network = { + "network": { + "id": "fake-id", + "name": "fake-name", + "admin_state_up": False + } + } + + return_network = self.scenario._show_network(network) + self.assertEqual(self.clients("neutron").show_network.return_value, + return_network) + self._test_atomic_action_timer(self.scenario.atomic_actions(), + "neutron.show_network") + def test_update_network(self): expected_network = { "network": {