diff --git a/rally-jobs/rally-neutron.yaml b/rally-jobs/rally-neutron.yaml index e12594f1..ae4b72b8 100644 --- a/rally-jobs/rally-neutron.yaml +++ b/rally-jobs/rally-neutron.yaml @@ -44,6 +44,64 @@ failure_rate: max: 20 + NeutronSecurityGroup.create_and_list_security_groups: + - + args: + security_group_create_args: {} + runner: + type: "constant" + times: {{smoke or 20 }} + concurrency: {{smoke or 10}} + context: + users: + tenants: {{smoke or 3}} + users_per_tenant: {{smoke or 2}} + quotas: + neutron: + security_group: -1 + sla: + failure_rate: + max: 20 + + NeutronSecurityGroup.create_and_delete_security_groups: + - + args: + security_group_create_args: {} + runner: + type: "constant" + times: {{smoke or 20 }} + concurrency: {{smoke or 10}} + context: + users: + tenants: {{smoke or 3}} + users_per_tenant: {{smoke or 2}} + quotas: + neutron: + security_group: -1 + sla: + failure_rate: + max: 20 + + NeutronSecurityGroup.create_and_update_security_groups: + - + args: + security_group_create_args: {} + security_group_update_args: {} + runner: + type: "constant" + times: {{smoke or 20 }} + concurrency: {{smoke or 10}} + context: + users: + tenants: {{smoke or 3}} + users_per_tenant: {{smoke or 2}} + quotas: + neutron: + security_group: -1 + sla: + failure_rate: + max: 20 + NeutronNetworks.create_and_list_floating_ips: - args: diff --git a/rally/plugins/openstack/scenarios/neutron/security_groups.py b/rally/plugins/openstack/scenarios/neutron/security_groups.py new file mode 100644 index 00000000..328e8485 --- /dev/null +++ b/rally/plugins/openstack/scenarios/neutron/security_groups.py @@ -0,0 +1,77 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from rally import consts +from rally.plugins.openstack import scenario +from rally.plugins.openstack.scenarios.neutron import utils +from rally.task import validation + + +class NeutronSecurityGroup(utils.NeutronScenario): + """Benchmark scenarios for Neutron Security Groups.""" + + @validation.required_services(consts.Service.NEUTRON) + @validation.required_openstack(users=True) + @scenario.configure(context={"cleanup": ["neutron"]}) + def create_and_list_security_groups(self, security_group_create_args=None): + """Create and list Neutron security-groups. + + Measure the "neutron security-group-create" and "neutron + security-group-list" command performance. + + :param security_group_create_args: dict, POST /v2.0/security-groups + request options + """ + security_group_create_args = security_group_create_args or {} + self._create_security_group(**security_group_create_args) + self._list_security_groups() + + @validation.required_services(consts.Service.NEUTRON) + @validation.required_openstack(users=True) + @scenario.configure() + def create_and_delete_security_groups(self, + security_group_create_args=None): + """Create and delete Neutron security-groups. + + Measure the "neutron security-group-create" and "neutron + security-group-delete" command performance. + + :param security_group_create_args: dict, POST /v2.0/security-groups + request options + """ + security_group_create_args = security_group_create_args or {} + security_group = self._create_security_group( + **security_group_create_args) + self._delete_security_group(security_group) + + @validation.required_services(consts.Service.NEUTRON) + @validation.required_openstack(users=True) + @scenario.configure(context={"cleanup": ["neutron"]}) + def create_and_update_security_groups(self, + security_group_create_args=None, + security_group_update_args=None): + """Create and update Neutron security-groups. + + Measure the "neutron security-group-create" and "neutron + security-group-update" command performance. + + :param security_group_create_args: dict, POST /v2.0/security-groups + request options + :param security_group_update_args: dict, POST /v2.0/security-groups + update options + """ + security_group_create_args = security_group_create_args or {} + security_group_update_args = security_group_update_args or {} + security_group = self._create_security_group( + **security_group_create_args) + self._update_security_group(security_group, + **security_group_update_args) diff --git a/rally/plugins/openstack/scenarios/neutron/utils.py b/rally/plugins/openstack/scenarios/neutron/utils.py index 80fb5e96..36f2b8ee 100644 --- a/rally/plugins/openstack/scenarios/neutron/utils.py +++ b/rally/plugins/openstack/scenarios/neutron/utils.py @@ -490,3 +490,45 @@ class NeutronScenario(scenario.OpenStackScenario): body = {"health_monitor": healthmonitor_update_args} return self.clients("neutron").update_health_monitor( healthmonitor["health_monitor"]["id"], body) + + @atomic.action_timer("neutron.create_security_group") + def _create_security_group(self, **security_group_create_args): + """Create Neutron security-group. + + param: security_group_create_args: dict, POST /v2.0/security-groups + request options + return: dict, neutron security-group + """ + security_group_create_args["name"] = self.generate_random_name() + return self.clients("neutron").create_security_group( + {"security_group": security_group_create_args}) + + @atomic.action_timer("neutron.delete_security_group") + def _delete_security_group(self, security_group): + """Delete Neutron security group. + + param: security_group: dict, neutron security_group + """ + return self.clients("neutron").delete_security_group( + security_group["security_group"]["id"]) + + @atomic.action_timer("neutron.list_security_groups") + def _list_security_groups(self, **kwargs): + """Return list of Neutron security groups.""" + return self.clients("neutron").list_security_groups(**kwargs) + + @atomic.action_timer("neutron.update_security_group") + def _update_security_group(self, security_group, + **security_group_update_args): + """Update Neutron security-group. + + param: security_group: dict, neutron security_group + param: security_group_update_args: dict, POST /v2.0/security-groups + update options + return: dict, updated neutron security-group + """ + self._warn_about_deprecated_name_kwarg(security_group, + security_group_update_args) + body = {"security_group": security_group_update_args} + return self.clients("neutron").update_security_group( + security_group["security_group"]["id"], body) diff --git a/tests/unit/plugins/openstack/scenarios/neutron/test_security_groups.py b/tests/unit/plugins/openstack/scenarios/neutron/test_security_groups.py new file mode 100644 index 00000000..dfbc4b39 --- /dev/null +++ b/tests/unit/plugins/openstack/scenarios/neutron/test_security_groups.py @@ -0,0 +1,83 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import ddt +import mock + +from rally.plugins.openstack.scenarios.neutron import security_groups +from tests.unit import test + + +@ddt.ddt +class NeutronSecurityGroup(test.TestCase): + + @ddt.data( + {}, + {"security_group_create_args": {}}, + {"security_group_create_args": {"description": "fake-description"}}, + ) + @ddt.unpack + def test_create_and_list_security_groups( + self, security_group_create_args=None): + neutron_scenario = security_groups.NeutronSecurityGroup() + security_group_data = security_group_create_args or {} + neutron_scenario._create_security_group = mock.Mock() + neutron_scenario._list_security_groups = mock.Mock() + neutron_scenario.create_and_list_security_groups( + security_group_create_args=security_group_create_args) + neutron_scenario._create_security_group.assert_called_once_with( + **security_group_data) + neutron_scenario._list_security_groups.assert_called_once_with() + + @ddt.data( + {}, + {"security_group_create_args": {}}, + {"security_group_create_args": {"description": "fake-description"}}, + ) + @ddt.unpack + def test_create_and_delete_security_groups( + self, security_group_create_args=None): + neutron_scenario = security_groups.NeutronSecurityGroup() + security_group_data = security_group_create_args or {} + neutron_scenario._create_security_group = mock.Mock() + neutron_scenario._delete_security_group = mock.Mock() + neutron_scenario.create_and_delete_security_groups( + security_group_create_args=security_group_create_args) + neutron_scenario._create_security_group.assert_called_once_with( + **security_group_data) + neutron_scenario._delete_security_group.assert_called_once_with( + neutron_scenario._create_security_group.return_value) + + @ddt.data( + {}, + {"security_group_create_args": {}}, + {"security_group_create_args": {"description": "fake-description"}}, + {"security_group_update_args": {}}, + {"security_group_update_args": {"description": "fake-updated-descr"}}, + ) + @ddt.unpack + def test_create_and_update_security_groups( + self, security_group_create_args=None, + security_group_update_args=None): + neutron_scenario = security_groups.NeutronSecurityGroup() + security_group_data = security_group_create_args or {} + security_group_update_data = security_group_update_args or {} + neutron_scenario._create_security_group = mock.Mock() + neutron_scenario._update_security_group = mock.Mock() + neutron_scenario.create_and_update_security_groups( + security_group_create_args=security_group_create_args, + security_group_update_args=security_group_update_args) + neutron_scenario._create_security_group.assert_called_once_with( + **security_group_data) + neutron_scenario._update_security_group.assert_called_once_with( + neutron_scenario._create_security_group.return_value, + **security_group_update_data) diff --git a/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py b/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py index 20ec47ca..048f1039 100644 --- a/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py @@ -575,6 +575,77 @@ class NeutronScenarioTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(scenario.atomic_actions(), "neutron.update_vip") + @mock.patch(NEUTRON_UTILS + "NeutronScenario.generate_random_name") + def test_create_security_group(self, mock_generate_random_name): + neutron_scenario = utils.NeutronScenario(self.context) + random_name = "random_name" + security_group_create_args = {"description": "Fake security group"} + expected_security_group = { + "security_group": {"id": "fake-id", + "name": random_name, + "description": "Fake security group"} + } + mock_generate_random_name.return_value = random_name + self.clients("neutron").create_security_group = mock.Mock( + return_value=expected_security_group) + + security_group_data = { + "security_group": + {"name": "random_name", + "description": "Fake security group"} + } + resultant_security_group = neutron_scenario._create_security_group( + **security_group_create_args) + self.assertEqual(expected_security_group, resultant_security_group) + self.clients("neutron").create_security_group.assert_called_once_with( + security_group_data) + self._test_atomic_action_timer(neutron_scenario.atomic_actions(), + "neutron.create_security_group") + + def test_list_security_groups(self): + scenario = utils.NeutronScenario() + security_groups_list = [{"id": "security-group-id"}] + security_groups_dict = {"security_groups": security_groups_list} + self.clients("neutron").list_security_groups = mock.Mock( + return_value=security_groups_dict) + self.assertEqual( + scenario._list_security_groups(), + self.clients("neutron").list_security_groups.return_value) + self._test_atomic_action_timer(scenario.atomic_actions(), + "neutron.list_security_groups") + + def test_delete_security_group(self): + scenario = utils.NeutronScenario() + + security_group = {"security_group": {"id": "fake-id"}} + scenario._delete_security_group(security_group) + self.clients("neutron").delete_security_group.assert_called_once_with( + security_group["security_group"]["id"]) + self._test_atomic_action_timer(scenario.atomic_actions(), + "neutron.delete_security_group") + + def test_update_security_group(self): + scenario = utils.NeutronScenario() + + security_group = {"security_group": {"id": "security-group-id", + "description": "Not updated"}} + expected_security_group = { + "security_group": {"id": "security-group-id", + "description": "Updated"} + } + security_group_update_args = {"description": "Updated"} + security_group_update_data = { + "security_group": security_group_update_args} + self.clients("neutron").update_security_group = mock.Mock( + return_value=expected_security_group) + result_security_group = scenario._update_security_group( + security_group, **security_group_update_args) + self.clients("neutron").update_security_group.assert_called_once_with( + security_group["security_group"]["id"], security_group_update_data) + self.assertEqual(result_security_group, expected_security_group) + self._test_atomic_action_timer(scenario.atomic_actions(), + "neutron.update_security_group") + class NeutronScenarioFunctionalTestCase(test.FakeClientsScenarioTestCase):