Add NovaAggregates.create_and_list_aggregates

This scenario creates a aggregate and then lists all aggregates.

Change-Id: If0a9aa864d5e912d72e197f5042b9c050768ddfe
This commit is contained in:
maxinjian 2016-09-13 22:55:41 -04:00
parent 4d2cd8d22c
commit 9c165148fd
9 changed files with 131 additions and 0 deletions

View File

@ -1136,3 +1136,19 @@
sla:
failure_rate:
max: 0
NovaAggregates.create_and_list_aggregates:
-
args:
availability_zone: "nova"
runner:
type: "constant"
times: 10
concurrency: 2
context:
users:
tenants: 2
users_per_tenant: 2
sla:
failure_rate:
max: 0

View File

@ -262,6 +262,14 @@ class NovaNetworks(SynchronizedDeletion, base.ResourceManager):
if utils.name_matches_object(net.label, *classes)]
@base.resource("nova", "aggregates", order=next(_nova_order),
admin_required=True, perform_for_admin_only=True)
class NovaAggregate(SynchronizedDeletion, base.ResourceManager):
def list(self):
return [r for r in self._manager().list()
if utils.name_matches_object(r.name, nova_utils.NovaScenario)]
# EC2
_ec2_order = get_order(250)

View File

@ -31,3 +31,20 @@ class NovaAggregates(utils.NovaScenario):
Measure the "nova aggregate-list" command performance.
"""
self._list_aggregates()
@validation.required_services(consts.Service.NOVA)
@validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["nova"]},
name="NovaAggregates.create_and_list_aggregates")
class CreateAndListAggregates(utils.NovaScenario):
"""scenario for create and list aggregate."""
def run(self, availability_zone):
"""Create a aggregate and then list all aggregates.
This scenario creates a aggregate and then lists all aggregates.
:param availability_zone: The availability zone of the aggregate
"""
self._create_aggregate(availability_zone)
self._list_aggregates()

View File

@ -995,3 +995,14 @@ class NovaScenario(scenario.OpenStackScenario):
:param flavor_id: The flavor ID to get
"""
return self.admin_clients("nova").flavors.get(flavor_id)
@atomic.action_timer("nova.create_aggregate")
def _create_aggregate(self, availability_zone):
"""Create a new aggregate.
:param availability_zone: The availability zone of the aggregate
:returns: The created aggregate
"""
aggregate_name = self.generate_random_name()
return self.admin_clients("nova").aggregates.create(aggregate_name,
availability_zone)

View File

@ -0,0 +1,25 @@
{
"NovaAggregates.create_and_list_aggregates": [
{
"args": {
"availability_zone": "nova"
},
"runner": {
"type": "constant",
"times": 10,
"concurrency": 2
},
"context": {
"users": {
"tenants": 3,
"users_per_tenant": 2
}
},
"sla": {
"failure_rate": {
"max": 0
}
}
}
]
}

View File

@ -0,0 +1,16 @@
---
NovaAggregates.create_and_list_aggregates:
-
args:
availability_zone: "nova"
runner:
type: "constant"
times: 10
concurrency: 2
context:
users:
tenants: 3
users_per_tenant: 2
sla:
failure_rate:
max: 0

View File

@ -173,6 +173,22 @@ class NovaFlavorsTestCase(test.TestCase):
self.assertRaises(TypeError, flavor.is_deleted)
class NovaAggregatesTestCase(test.TestCase):
@mock.patch("%s.base.ResourceManager._manager" % BASE)
@mock.patch("rally.common.utils.name_matches_object")
def test_list(self, mock_name_matches_object,
mock_resource_manager__manager):
aggregates = [mock.MagicMock(name="rally_foo1"),
mock.MagicMock(name="rally_foo2"),
mock.MagicMock(name="foo3")]
mock_name_matches_object.side_effect = [False, True, True]
mock_resource_manager__manager().list.return_value = aggregates
self.assertEqual(aggregates[1:], resources.NovaAggregate().list())
mock_name_matches_object.assert_has_calls(
[mock.call(r.name, nutils.NovaScenario) for r in aggregates])
class NovaSecurityGroupTestCase(test.TestCase):
@mock.patch("%s.base.ResourceManager._manager" % BASE)

View File

@ -26,3 +26,11 @@ class NovaAggregatesTestCase(test.TestCase):
scenario._list_aggregates = mock.Mock()
scenario.list_aggregates()
scenario._list_aggregates.assert_called_once_with()
def test_create_and_list_aggregates(self):
scenario = aggregates.CreateAndListAggregates()
scenario._create_aggregate = mock.Mock()
scenario._list_aggregates = mock.Mock()
scenario.run(availability_zone="nova")
scenario._create_aggregate.assert_called_once_with("nova")
scenario._list_aggregates.assert_called_once_with()

View File

@ -1030,3 +1030,17 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
"nova.update_server")
def test_create_aggregate(self):
nova_scenario = utils.NovaScenario(context=self.context)
random_name = "random_name"
nova_scenario.generate_random_name = mock.Mock(
return_value=random_name)
result = nova_scenario._create_aggregate("nova")
self.assertEqual(
self.admin_clients("nova").aggregates.create.return_value,
result)
self.admin_clients("nova").aggregates.create.assert_called_once_with(
random_name, "nova")
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
"nova.create_aggregate")