Add neutron.CreateAndShowSecurityGroupRule scenario

Create and show Neutron security-group-rule.

Measure the "neutron security-group-rule-create" and "neutron
security-group-rule-show" command performance.

Change-Id: I0a2dc19e46253d855bc41236b1246b0112940e84
This commit is contained in:
zhangzhang 2017-06-20 12:21:29 -04:00
parent 96eabea39b
commit c91f5f0c26
7 changed files with 207 additions and 0 deletions

View File

@ -231,6 +231,26 @@
failure_rate:
max: 20
NeutronSecurityGroup.create_and_show_security_group_rule:
-
args:
security_group_args: {}
security_group_rule_args: {}
runner:
type: "constant"
times: 20
concurrency: 10
context:
users:
tenants: 3
users_per_tenant: 3
quotas:
neutron:
security_group: -1
sla:
failure_rate:
max: 0
NeutronNetworks.create_and_list_floating_ips:
-
args:

View File

@ -154,3 +154,39 @@ class CreateAndListSecurityGroupRules(utils.NeutronScenario):
self.assertIn(security_group_rule["security_group_rule"]["id"],
[sgr["id"] for sgr
in security_group_rules["security_group_rules"]])
@validation.add("required_services",
services=[consts.Service.NEUTRON])
@validation.add("required_platform", platform="openstack", users=True)
@scenario.configure(context={"cleanup": ["neutron"]},
name=("NeutronSecurityGroup"
".create_and_show_security_group_rule"))
class CreateAndShowSecurityGroupRule(utils.NeutronScenario):
def run(self, security_group_args=None,
security_group_rule_args=None):
"""Create and show Neutron security-group-rule.
Measure the "neutron security-group-rule-create" and "neutron
security-group-rule-show" command performance.
:param security_group_args: dict, POST /v2.0/security-groups
request options
:param security_group_rule_args: dict,
POST /v2.0/security-group-rules request options
"""
security_group_args = security_group_args or {}
security_group_rule_args = security_group_rule_args or {}
security_group = self._create_security_group(**security_group_args)
msg = "security_group isn't created"
self.assertTrue(security_group, err_msg=msg)
security_group_rule = self._create_security_group_rule(
security_group["security_group"]["id"], **security_group_rule_args)
msg = "security_group_rule isn't created"
self.assertTrue(security_group_rule, err_msg=msg)
self._show_security_group_rule(
security_group_rule["security_group_rule"]["id"])

View File

@ -810,3 +810,14 @@ class NeutronScenario(scenario.OpenStackScenario):
:return: list of security group rules
"""
return self.clients("neutron").list_security_group_rules(**kwargs)
@atomic.action_timer("neutron.show_security_group_rule")
def _show_security_group_rule(self, security_group_rule, **kwargs):
"""Show information of a given security group rule.
:param security_group_rule: id of security group rule
:param kwargs: Optional additional arguments for roles list
:return: details of security group rule
"""
return self.clients("neutron").show_security_group_rule(
security_group_rule, **kwargs)

View File

@ -0,0 +1,31 @@
{
"NeutronSecurityGroup.create_and_show_security_group_rule": [
{
"args": {
"security_group_args": {},
"security_group_rule_args":{}
},
"runner": {
"type": "constant",
"times": 20,
"concurrency": 10
},
"context": {
"users": {
"tenants": 3,
"users_per_tenant": 3
},
"quotas": {
"neutron": {
"security_group": -1
}
}
},
"sla": {
"failure_rate": {
"max": 0
}
}
}
]
}

View File

@ -0,0 +1,20 @@
---
NeutronSecurityGroup.create_and_show_security_group_rule:
-
args:
security_group_args: {}
security_group_rule_args: {}
runner:
type: "constant"
times: 20
concurrency: 10
context:
users:
tenants: 3
users_per_tenant: 3
quotas:
neutron:
security_group: -1
sla:
failure_rate:
max: 0

View File

@ -225,3 +225,83 @@ class NeutronSecurityGroup(test.TestCase):
security_group["security_group"]["id"],
**security_group_rule_data)
scenario._list_security_group_rules.assert_called_with()
@ddt.data(
{},
{"security_group_args": {}},
{"security_group_args": {"description": "fake-description"}},
{"security_group_rule_args": {}},
{"security_group_rule_args": {"description": "fake-rule-descr"}}
)
@ddt.unpack
def test_create_and_show_security_group_rule(
self, security_group_args=None,
security_group_rule_args=None):
scenario = security_groups.CreateAndShowSecurityGroupRule()
security_group_data = security_group_args or {}
security_group_rule_data = security_group_rule_args or {}
security_group = mock.MagicMock()
security_group_rule = {"security_group_rule": {"id": 1, "name": "f1"}}
scenario._create_security_group = mock.MagicMock()
scenario._create_security_group_rule = mock.MagicMock()
scenario._show_security_group_rule = mock.MagicMock()
# Positive case
scenario._create_security_group.return_value = security_group
scenario._create_security_group_rule.return_value = security_group_rule
scenario.run(security_group_args=security_group_data,
security_group_rule_args=security_group_rule_data)
scenario._create_security_group.assert_called_once_with(
**security_group_data)
scenario._create_security_group_rule.assert_called_once_with(
security_group["security_group"]["id"],
**security_group_rule_data)
scenario._show_security_group_rule.assert_called_once_with(
security_group_rule["security_group_rule"]["id"])
@ddt.data(
{},
{"security_group_args": {}},
{"security_group_args": {"description": "fake-description"}},
{"security_group_rule_args": {}},
{"security_group_rule_args": {"description": "fake-rule-descr"}},
)
@ddt.unpack
def test_create_and_show_security_group_rule_with_fails(
self, security_group_args=None,
security_group_rule_args=None):
scenario = security_groups.CreateAndShowSecurityGroupRule()
security_group_data = security_group_args or {}
security_group_rule_data = security_group_rule_args or {}
security_group = mock.MagicMock()
security_group_rule = {"security_group_rule": {"id": 1, "name": "f1"}}
scenario._create_security_group = mock.MagicMock()
scenario._create_security_group_rule = mock.MagicMock()
scenario._show_security_group_rule = mock.MagicMock()
scenario._create_security_group_rule.return_value = security_group_rule
# Negative case1: security_group isn't created
scenario._create_security_group.return_value = None
self.assertRaises(rally_exceptions.RallyAssertionError,
scenario.run,
security_group_data,
security_group_rule_data)
scenario._create_security_group.assert_called_with(
**security_group_data)
# Negative case2: security_group_rule isn't created
scenario._create_security_group.return_value = security_group
scenario._create_security_group_rule.return_value = None
self.assertRaises(rally_exceptions.RallyAssertionError,
scenario.run,
security_group_data,
security_group_rule_data)
scenario._create_security_group.assert_called_with(
**security_group_data)
scenario._create_security_group_rule.assert_called_with(
security_group["security_group"]["id"],
**security_group_rule_data)

View File

@ -830,6 +830,15 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(self.scenario.atomic_actions(),
"neutron.list_security_group_rules")
def test_show_security_group_rule(self):
return_rule = self.scenario._show_security_group_rule(1)
self.assertEqual(
self.clients("neutron").show_security_group_rule.return_value,
return_rule)
self._test_atomic_action_timer(self.scenario.atomic_actions(),
"neutron.show_security_group_rule")
@ddt.data(
{"networks": [{"subnets": "subnet-id"}]},
{"pool_create_args": None, "networks": [{"subnets": ["subnet-id"]}]},