Merge "Add scenarios for security group"
This commit is contained in:
commit
20314afe2f
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -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
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -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
|
@ -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
|
||||
|
@ -1158,3 +1158,43 @@
|
||||
type: "constant"
|
||||
times: 5
|
||||
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
|
||||
|
75
rally/benchmark/scenarios/nova/security_group.py
Normal file
75
rally/benchmark/scenarios/nova/security_group.py
Normal file
@ -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()
|
@ -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()
|
||||
|
66
tests/unit/benchmark/scenarios/nova/test_security_group.py
Normal file
66
tests/unit/benchmark/scenarios/nova/test_security_group.py
Normal file
@ -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()
|
@ -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")
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user