From 4c63cd909ddbb34f9e1dfc43d59b73b8aaa18944 Mon Sep 17 00:00:00 2001 From: Andrey Kurilin Date: Fri, 21 Nov 2014 12:20:06 +0200 Subject: [PATCH] Add scenarios for security group New scenarios: - create and delete security groups - create_and_list_secgroups Co-Authored-By: Ilya Shakhat Change-Id: If9b25260c8d57dc52d7fb64abbaac0601a0eb4ed --- .../nova/create-and-delete-secgroups.json | 21 ++++++ .../nova/create-and-delete-secgroups.yaml | 14 ++++ .../nova/create-and-list-secgroups.json | 21 ++++++ .../nova/create-and-list-secgroups.yaml | 14 ++++ rally-jobs/rally-neutron.yaml | 42 +++++++++++ rally-jobs/rally.yaml | 40 ++++++++++ .../scenarios/nova/security_group.py | 75 +++++++++++++++++++ rally/benchmark/scenarios/nova/utils.py | 39 ++++++++++ .../scenarios/nova/test_security_group.py | 66 ++++++++++++++++ .../benchmark/scenarios/nova/test_utils.py | 74 ++++++++++++++++++ tests/unit/fakes.py | 4 +- 11 files changed, 408 insertions(+), 2 deletions(-) create mode 100644 doc/samples/tasks/scenarios/nova/create-and-delete-secgroups.json create mode 100644 doc/samples/tasks/scenarios/nova/create-and-delete-secgroups.yaml create mode 100644 doc/samples/tasks/scenarios/nova/create-and-list-secgroups.json create mode 100644 doc/samples/tasks/scenarios/nova/create-and-list-secgroups.yaml create mode 100644 rally/benchmark/scenarios/nova/security_group.py create mode 100644 tests/unit/benchmark/scenarios/nova/test_security_group.py diff --git a/doc/samples/tasks/scenarios/nova/create-and-delete-secgroups.json b/doc/samples/tasks/scenarios/nova/create-and-delete-secgroups.json new file mode 100644 index 0000000000..e8d2cbb042 --- /dev/null +++ b/doc/samples/tasks/scenarios/nova/create-and-delete-secgroups.json @@ -0,0 +1,21 @@ +{ + "NovaSecGroup.create_and_delete_secgroups": [ + { + "args": { + "security_group_count": 10, + "rules_per_security_group": 10 + }, + "runner": { + "type": "constant", + "times": 10, + "concurrency": 2 + }, + "context": { + "users": { + "tenants": 3, + "users_per_tenant": 2 + } + } + } + ] +} diff --git a/doc/samples/tasks/scenarios/nova/create-and-delete-secgroups.yaml b/doc/samples/tasks/scenarios/nova/create-and-delete-secgroups.yaml new file mode 100644 index 0000000000..b7399c4fbb --- /dev/null +++ b/doc/samples/tasks/scenarios/nova/create-and-delete-secgroups.yaml @@ -0,0 +1,14 @@ +--- + NovaSecGroup.create_and_delete_secgroups: + - + args: + security_group_count: 10 + rules_per_security_group: 10 + runner: + type: "constant" + times: 10 + concurrency: 2 + context: + users: + tenants: 3 + users_per_tenant: 2 diff --git a/doc/samples/tasks/scenarios/nova/create-and-list-secgroups.json b/doc/samples/tasks/scenarios/nova/create-and-list-secgroups.json new file mode 100644 index 0000000000..66af710f2e --- /dev/null +++ b/doc/samples/tasks/scenarios/nova/create-and-list-secgroups.json @@ -0,0 +1,21 @@ +{ + "NovaSecGroup.create_and_list_secgroups": [ + { + "args": { + "security_group_count": 10, + "rules_per_security_group": 10 + }, + "runner": { + "type": "constant", + "times": 10, + "concurrency": 2 + }, + "context": { + "users": { + "tenants": 3, + "users_per_tenant": 2 + } + } + } + ] +} diff --git a/doc/samples/tasks/scenarios/nova/create-and-list-secgroups.yaml b/doc/samples/tasks/scenarios/nova/create-and-list-secgroups.yaml new file mode 100644 index 0000000000..440f3c94c2 --- /dev/null +++ b/doc/samples/tasks/scenarios/nova/create-and-list-secgroups.yaml @@ -0,0 +1,14 @@ +--- + NovaSecGroup.create_and_list_secgroups: + - + args: + security_group_count: 10 + rules_per_security_group: 10 + runner: + type: "constant" + times: 10 + concurrency: 2 + context: + users: + tenants: 3 + users_per_tenant: 2 diff --git a/rally-jobs/rally-neutron.yaml b/rally-jobs/rally-neutron.yaml index 205e668388..9c3f41c488 100644 --- a/rally-jobs/rally-neutron.yaml +++ b/rally-jobs/rally-neutron.yaml @@ -478,3 +478,45 @@ sla: failure_rate: max: 0 + + NovaSecGroup.create_and_delete_secgroups: + - + args: + security_group_count: 5 + rules_per_security_group: 5 + runner: + type: "constant" + times: 4 + concurrency: 4 + context: + users: + tenants: 3 + users_per_tenant: 2 + quotas: + neutron: + security_group: -1 + security_group_rule: -1 + sla: + failure_rate: + max: 0 + + NovaSecGroup.create_and_list_secgroups: + - + args: + security_group_count: 5 + rules_per_security_group: 5 + runner: + type: "constant" + times: 4 + concurrency: 4 + context: + users: + tenants: 3 + users_per_tenant: 2 + quotas: + neutron: + security_group: -1 + security_group_rule: -1 + sla: + failure_rate: + max: 0 \ No newline at end of file diff --git a/rally-jobs/rally.yaml b/rally-jobs/rally.yaml index 4c758b09ba..00d52d9daa 100755 --- a/rally-jobs/rally.yaml +++ b/rally-jobs/rally.yaml @@ -1160,3 +1160,43 @@ type: "constant" times: 10 concurrency: 5 + + NovaSecGroup.create_and_delete_secgroups: + - + args: + security_group_count: 5 + rules_per_security_group: 5 + runner: + type: "constant" + times: 4 + concurrency: 4 + context: + users: + tenants: 3 + users_per_tenant: 2 + quotas: + nova: + security_groups: -1 + security_group_rules: -1 + sla: + max_failure_percent: 0 + + NovaSecGroup.create_and_list_secgroups: + - + args: + security_group_count: 5 + rules_per_security_group: 5 + runner: + type: "constant" + times: 4 + concurrency: 4 + context: + users: + tenants: 3 + users_per_tenant: 2 + quotas: + nova: + security_groups: -1 + security_group_rules: -1 + sla: + max_failure_percent: 0 diff --git a/rally/benchmark/scenarios/nova/security_group.py b/rally/benchmark/scenarios/nova/security_group.py new file mode 100644 index 0000000000..07593c57b9 --- /dev/null +++ b/rally/benchmark/scenarios/nova/security_group.py @@ -0,0 +1,75 @@ +# Copyright 2014: Mirantis Inc. +# All Rights Reserved. +# +# 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.benchmark.scenarios import base +from rally.benchmark.scenarios.nova import utils +from rally.benchmark import validation +from rally import consts +from rally import log as logging + + +LOG = logging.getLogger() + + +class NovaSecGroup(utils.NovaScenario): + + RESOURCE_NAME_PREFIX = "rally_novasecgrp_" + + @validation.required_parameters("security_group_count", + "rules_per_security_group") + @validation.required_services(consts.Service.NOVA) + @validation.required_openstack(users=True) + @base.scenario(context={"cleanup": ["nova"]}) + def create_and_delete_secgroups(self, security_group_count, + rules_per_security_group): + """Tests creating and deleting security groups. + + This scenario creates N security groups with M rules per group and then + deletes them. + + :param security_group_count: Number of security groups + :param rules_per_security_group: Number of rules per security group + """ + + security_groups = self._create_security_groups( + security_group_count) + + self._create_rules_for_security_group(security_groups, + rules_per_security_group) + + self._delete_security_groups(security_groups) + + @validation.required_parameters("security_group_count", + "rules_per_security_group") + @validation.required_services(consts.Service.NOVA) + @validation.required_openstack(users=True) + @base.scenario(context={"cleanup": ["nova"]}) + def create_and_list_secgroups(self, security_group_count, + rules_per_security_group): + """Tests creating and listing security groups. + + This scenario creates N security groups with M rules per group and then + lists them. + + :param security_group_count: Number of security groups + :param rules_per_security_group: Number of rules per security group + """ + + security_groups = self._create_security_groups( + security_group_count) + + self._create_rules_for_security_group(security_groups, + rules_per_security_group) + self._list_security_groups() diff --git a/rally/benchmark/scenarios/nova/utils.py b/rally/benchmark/scenarios/nova/utils.py index f88f18b899..06fdd1f7c5 100644 --- a/rally/benchmark/scenarios/nova/utils.py +++ b/rally/benchmark/scenarios/nova/utils.py @@ -566,3 +566,42 @@ class NovaScenario(base.Scenario): except IndexError: raise exceptions.InvalidHostException( "No valid host found to migrate") + + def _create_security_groups(self, security_group_count): + security_groups = [] + with base.AtomicAction(self, "nova.create_%s_security_groups" % + security_group_count): + for i in range(security_group_count): + sg_name = self._generate_random_name() + sg = self.clients("nova").security_groups.create(sg_name, + sg_name) + security_groups.append(sg) + + return security_groups + + def _create_rules_for_security_group(self, security_groups, + rules_per_security_group, + ip_protocol='tcp', cidr="0.0.0.0/0"): + action_name = ("nova.create_%s_rules_in_every_of_%s_security_group" % + (rules_per_security_group, len(security_groups))) + with base.AtomicAction(self, action_name): + for i in range(len(security_groups)): + for j in range(rules_per_security_group): + self.clients("nova").security_group_rules.create( + security_groups[i].id, + from_port=(i * rules_per_security_group + j + 1), + to_port=(i * rules_per_security_group + j + 1), + ip_protocol=ip_protocol, + cidr=cidr) + + def _delete_security_groups(self, security_group): + with base.AtomicAction(self, "nova.delete_%s_security_groups" % + len(security_group)): + for sg in security_group: + self.clients("nova").security_groups.delete(sg.id) + + def _list_security_groups(self): + """Returns security groups list.""" + + with base.AtomicAction(self, "nova.list_security_groups"): + return self.clients("nova").security_groups.list() diff --git a/tests/unit/benchmark/scenarios/nova/test_security_group.py b/tests/unit/benchmark/scenarios/nova/test_security_group.py new file mode 100644 index 0000000000..46d9efa676 --- /dev/null +++ b/tests/unit/benchmark/scenarios/nova/test_security_group.py @@ -0,0 +1,66 @@ +# Copyright 2014: Mirantis Inc. +# All Rights Reserved. +# +# 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 mock + +from rally.benchmark.scenarios.nova import security_group +from tests.unit import fakes +from tests.unit import test + + +class NovaSecurityGroupTestCase(test.TestCase): + + def test_create_and_delete_security_groups(self): + fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"), + fakes.FakeSecurityGroup(None, None, 2, "uuid2")] + + nova_scenario = security_group.NovaSecGroup() + nova_scenario._create_security_groups = mock.MagicMock( + return_value=fake_secgroups) + nova_scenario._create_rules_for_security_group = mock.MagicMock() + nova_scenario._delete_security_groups = mock.MagicMock() + + security_group_count = 2 + rules_per_security_group = 10 + nova_scenario.create_and_delete_secgroups( + security_group_count, rules_per_security_group) + + nova_scenario._create_security_groups.assert_called_once_with( + security_group_count) + nova_scenario._create_rules_for_security_group.assert_called_once_with( + fake_secgroups, rules_per_security_group) + nova_scenario._delete_security_groups.assert_called_once_with( + fake_secgroups) + + def test_create_and_list_secgroups(self): + fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"), + fakes.FakeSecurityGroup(None, None, 2, "uuid2")] + + nova_scenario = security_group.NovaSecGroup() + nova_scenario._create_security_groups = mock.MagicMock( + return_value=fake_secgroups) + nova_scenario._create_rules_for_security_group = mock.MagicMock() + nova_scenario._list_security_groups = mock.MagicMock() + + security_group_count = 2 + rules_per_security_group = 10 + nova_scenario.create_and_list_secgroups( + security_group_count, rules_per_security_group) + + nova_scenario._create_security_groups.assert_called_once_with( + security_group_count) + nova_scenario._create_rules_for_security_group.assert_called_once_with( + fake_secgroups, rules_per_security_group) + nova_scenario._list_security_groups.assert_called_once_with() \ No newline at end of file diff --git a/tests/unit/benchmark/scenarios/nova/test_utils.py b/tests/unit/benchmark/scenarios/nova/test_utils.py index 56be98084d..c48d01cfaf 100644 --- a/tests/unit/benchmark/scenarios/nova/test_utils.py +++ b/tests/unit/benchmark/scenarios/nova/test_utils.py @@ -570,3 +570,77 @@ class NovaScenarioTestCase(test.TestCase): self.assertIn( nova_scenario._find_host_to_migrate(fake_server), ["b1", "b3"]) + + def test__create_security_groups(self): + clients = mock.MagicMock() + nova_scenario = utils.NovaScenario() + nova_scenario.clients = clients + nova_scenario._generate_random_name = mock.MagicMock() + + security_group_count = 5 + + sec_groups = nova_scenario._create_security_groups( + security_group_count) + + self.assertEqual(security_group_count, clients.call_count) + self.assertEqual(security_group_count, len(sec_groups)) + self.assertEqual(security_group_count, + nova_scenario._generate_random_name.call_count) + self.assertEqual(security_group_count, + clients().security_groups.create.call_count) + self._test_atomic_action_timer( + nova_scenario.atomic_actions(), + 'nova.create_%s_security_groups' % security_group_count) + + def test__create_rules_for_security_group(self): + clients = mock.MagicMock() + nova_scenario = utils.NovaScenario() + nova_scenario.clients = clients + + fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"), + fakes.FakeSecurityGroup(None, None, 2, "uuid2")] + rules_per_security_group = 10 + + nova_scenario._create_rules_for_security_group( + fake_secgroups, rules_per_security_group) + + self.assertEqual(len(fake_secgroups) * rules_per_security_group, + clients.call_count) + self.assertEqual(len(fake_secgroups) * rules_per_security_group, + clients().security_group_rules.create.call_count) + self._test_atomic_action_timer( + nova_scenario.atomic_actions(), + "nova.create_%s_rules_in_every_of_%s_security_group" % + (rules_per_security_group, len(fake_secgroups))) + + def test__delete_security_groups(self): + clients = mock.MagicMock() + nova_scenario = utils.NovaScenario() + nova_scenario.clients = clients + + fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"), + fakes.FakeSecurityGroup(None, None, 2, "uuid2")] + + nova_scenario._delete_security_groups(fake_secgroups) + + self.assertEqual(len(fake_secgroups), clients.call_count) + + self.assertEqual( + map(lambda x: mock.call(x.id), fake_secgroups), + clients().security_groups.delete.call_args_list) + self._test_atomic_action_timer( + nova_scenario.atomic_actions(), + 'nova.delete_%s_security_groups' % len(fake_secgroups)) + + def test__list_security_groups(self): + clients = mock.MagicMock() + nova_scenario = utils.NovaScenario() + nova_scenario.clients = clients + + nova_scenario._list_security_groups() + + clients.assert_called_once_with("nova") + clients().security_groups.list.assert_called_once_with() + + self._test_atomic_action_timer(nova_scenario.atomic_actions(), + "nova.list_security_groups") diff --git a/tests/unit/fakes.py b/tests/unit/fakes.py index f008157335..6d621ba351 100644 --- a/tests/unit/fakes.py +++ b/tests/unit/fakes.py @@ -178,8 +178,8 @@ class FakeQuotas(FakeResource): class FakeSecurityGroup(FakeResource): - def __init__(self, manager=None, rule_manager=None): - super(FakeSecurityGroup, self).__init__(manager) + def __init__(self, manager=None, rule_manager=None, id=None, name=None): + super(FakeSecurityGroup, self).__init__(manager, id=id, name=name) self.rule_manager = rule_manager @property