diff --git a/rally-jobs/rally-neutron.yaml b/rally-jobs/rally-neutron.yaml index 60309ce8..c5cc14f7 100644 --- a/rally-jobs/rally-neutron.yaml +++ b/rally-jobs/rally-neutron.yaml @@ -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: diff --git a/rally/plugins/openstack/scenarios/neutron/security_groups.py b/rally/plugins/openstack/scenarios/neutron/security_groups.py index dd3bb693..a3bd8ef1 100644 --- a/rally/plugins/openstack/scenarios/neutron/security_groups.py +++ b/rally/plugins/openstack/scenarios/neutron/security_groups.py @@ -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"]) diff --git a/rally/plugins/openstack/scenarios/neutron/utils.py b/rally/plugins/openstack/scenarios/neutron/utils.py index e9d8ccd0..970156be 100644 --- a/rally/plugins/openstack/scenarios/neutron/utils.py +++ b/rally/plugins/openstack/scenarios/neutron/utils.py @@ -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) diff --git a/samples/tasks/scenarios/neutron/create-and-show-security-group-rule.json b/samples/tasks/scenarios/neutron/create-and-show-security-group-rule.json new file mode 100644 index 00000000..6816e0c8 --- /dev/null +++ b/samples/tasks/scenarios/neutron/create-and-show-security-group-rule.json @@ -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 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/neutron/create-and-show-security-group-rule.yaml b/samples/tasks/scenarios/neutron/create-and-show-security-group-rule.yaml new file mode 100644 index 00000000..759ff95d --- /dev/null +++ b/samples/tasks/scenarios/neutron/create-and-show-security-group-rule.yaml @@ -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 diff --git a/tests/unit/plugins/openstack/scenarios/neutron/test_security_groups.py b/tests/unit/plugins/openstack/scenarios/neutron/test_security_groups.py index 9e7a6012..fea5ce3e 100644 --- a/tests/unit/plugins/openstack/scenarios/neutron/test_security_groups.py +++ b/tests/unit/plugins/openstack/scenarios/neutron/test_security_groups.py @@ -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) diff --git a/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py b/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py index 94dd6423..d7bb0ed5 100644 --- a/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py @@ -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"]}]},