Add nova.CreateAndGetKeypair scenario

Create a keypair and get the keypair details

Change-Id: I32c05a6d9fc4857106c808a5497c4a6d6e919374
This commit is contained in:
zhangzhang 2016-11-01 02:06:37 -04:00
parent e094b882ad
commit 323549e62e
7 changed files with 100 additions and 0 deletions

View File

@ -976,6 +976,21 @@
failure_rate:
max: 0
NovaKeypair.create_and_get_keypair:
-
args: {}
runner:
type: "constant"
times: 10
concurrency: 2
context:
users:
tenants: 3
users_per_tenant: 2
sla:
failure_rate:
max: 0
NovaKeypair.boot_and_delete_server_with_keypair:
-
args:

View File

@ -101,3 +101,20 @@ class BootAndDeleteServerWithKeypair(utils.NovaScenario):
**boot_server_kwargs)
self._delete_server(server)
self._delete_keypair(keypair)
@validation.required_services(consts.Service.NOVA)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["nova"]},
name="NovaKeypair.create_and_get_keypair")
class CreateAndGetKeypair(utils.NovaScenario):
def run(self, **kwargs):
"""Create a keypair and get the keypair details.
:param kwargs: Optional additional arguments for keypair creation
"""
keypair = self._create_keypair(**kwargs)
self._get_keypair(keypair)

View File

@ -536,6 +536,15 @@ class NovaScenario(scenario.OpenStackScenario):
"""
return self.clients("nova").images.list(detailed, **kwargs)
@atomic.action_timer("nova.get_keypair")
def _get_keypair(self, keypair):
"""Get a keypair.
:param keypair: The ID of the keypair to get.
:rtype: :class:`Keypair`
"""
return self.clients("nova").keypairs.get(keypair)
@atomic.action_timer("nova.create_keypair")
def _create_keypair(self, **kwargs):
"""Create a keypair

View File

@ -0,0 +1,24 @@
{
"NovaKeypair.create_and_get_keypair": [
{
"args": {},
"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,15 @@
---
NovaKeypair.create_and_get_keypair:
-
args: {}
runner:
type: "constant"
times: 10
concurrency: 2
context:
users:
tenants: 3
users_per_tenant: 2
sla:
failure_rate:
max: 0

View File

@ -54,6 +54,18 @@ class NovaKeypairTestCase(test.ScenarioTestCase):
scenario._create_keypair.assert_called_with(fakearg="fakearg")
scenario._list_keypairs.assert_called_with()
def test_create_and_get_keypair(self):
scenario = keypairs.CreateAndGetKeypair(self.context)
fake_keypair = mock.MagicMock()
scenario._create_keypair = mock.MagicMock()
scenario._get_keypair = mock.MagicMock()
scenario._create_keypair.return_value = fake_keypair
scenario.run(fakearg="fakearg")
scenario._create_keypair.assert_called_once_with(fakearg="fakearg")
scenario._get_keypair.assert_called_once_with(fake_keypair)
def test_create_and_delete_keypair(self):
scenario = keypairs.CreateAndDeleteKeypair(self.context)
scenario.generate_random_name = mock.MagicMock(return_value="name")

View File

@ -840,6 +840,14 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
"nova.delete_keypair")
def test__get_keypair(self):
nova_scenario = utils.NovaScenario()
nova_scenario._get_keypair("fake_keypair")
self.clients("nova").keypairs.get.assert_called_once_with(
"fake_keypair")
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
"nova.get_keypair")
def test__list_floating_ips_bulk(self):
floating_ips_bulk_list = ["foo_floating_ips_bulk"]
self.admin_clients("nova").floating_ips_bulk.list.return_value = (