Skip to content

Commit

Permalink
Add "pause and unpause" scenario for Nova
Browse files Browse the repository at this point in the history
This scenario covers Create server, pause, unpause
and then delete it

Change-Id: Ide46efeb37fa24b734a76036d6857f15670135ad
  • Loading branch information
pradeepkumars committed Apr 6, 2015
1 parent 6a8c59e commit 2f0c079
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 0 deletions.
20 changes: 20 additions & 0 deletions etc/rally/rally.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,26 @@
# Server resume poll interval (floating point value)
#nova_server_resume_poll_interval = 2.0

# Time to sleep after pause before polling for status (floating
# point value)
#nova_server_pause_prepoll_delay = 2.0

# Server pause timeout (floating point value)
#nova_server_pause_timeout = 300.0

# Server pause poll interval (floating point value)
#nova_server_pause_poll_interval = 2.0

# Time to sleep after unpause before polling for status (floating
# point value)
#nova_server_unpause_prepoll_delay = 2.0

# Server unpause timeout (floating point value)
#nova_server_unpause_timeout = 300.0

# Server unpause poll interval (floating point value)
#nova_server_unpause_poll_interval = 2.0

# Time to sleep after image_create before polling for status (floating
# point value)
#nova_server_image_create_prepoll_delay = 0.0
Expand Down
19 changes: 19 additions & 0 deletions rally-jobs/rally.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,25 @@
failure_rate:
max: 0

NovaServers.pause_and_unpause_server:
-
args:
flavor:
name: "m1.tiny"
image:
name: {{image_name}}
runner:
type: "constant"
times: 3
concurrency: 3
context:
users:
tenants: 3
users_per_tenant: 1
sla:
failure_rate:
max: 0

NovaServers.list_servers:
-
args:
Expand Down
20 changes: 20 additions & 0 deletions rally/benchmark/scenarios/nova/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,26 @@ def suspend_and_resume_server(self, image, flavor,
self._resume_server(server)
self._delete_server(server, force=force_delete)

@types.set(image=types.ImageResourceType,
flavor=types.FlavorResourceType)
@validation.image_valid_on_flavor("flavor", "image")
@validation.required_services(consts.Service.NOVA)
@validation.required_openstack(users=True)
@base.scenario(context={"cleanup": ["nova"]})
def pause_and_unpause_server(self, image, flavor,
force_delete=False, **kwargs):
"""Create a server, pause, unpause and then delete it
:param image: image to be used to boot an instance
:param flavor: flavor to be used to boot an instance
:param force_delete: True if force_delete should be used
:param kwargs: Optional additional arguments for server creation
"""
server = self._boot_server(image, flavor, **kwargs)
self._pause_server(server)
self._unpause_server(server)
self._delete_server(server, force=force_delete)

@types.set(image=types.ImageResourceType,
flavor=types.FlavorResourceType)
@validation.image_valid_on_flavor("flavor", "image")
Expand Down
38 changes: 38 additions & 0 deletions rally/benchmark/scenarios/nova/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
("unrescue", 2, 300, 2),
("suspend", 2, 300, 2),
("resume", 2, 300, 2),
("pause", 2, 300, 2),
("unpause", 2, 300, 2),
("image_create", 0, 300, 2),
("image_delete", 0, 300, 2),
("resize", 2, 400, 5),
Expand Down Expand Up @@ -266,6 +268,42 @@ def _resume_server(self, server):
check_interval=CONF.benchmark.nova_server_resume_poll_interval
)

@base.atomic_action_timer("nova.pause_server")
def _pause_server(self, server):
"""Pause the live server.
Returns when the server is actually paused and is in the "PAUSED"
state.
:param server: Server object
"""
server.pause()
time.sleep(CONF.benchmark.nova_server_pause_prepoll_delay)
bench_utils.wait_for(
server, is_ready=bench_utils.resource_is("PAUSED"),
update_resource=bench_utils.get_from_manager(),
timeout=CONF.benchmark.nova_server_pause_timeout,
check_interval=CONF.benchmark.nova_server_pause_poll_interval
)

@base.atomic_action_timer("nova.unpause_server")
def _unpause_server(self, server):
"""Unpause the paused server.
Returns when the server is actually unpaused and is in the "ACTIVE"
state.
:param server: Server object
"""
server.unpause()
time.sleep(CONF.benchmark.nova_server_unpause_prepoll_delay)
bench_utils.wait_for(
server, is_ready=bench_utils.resource_is("ACTIVE"),
update_resource=bench_utils.get_from_manager(),
timeout=CONF.benchmark.nova_server_unpause_timeout,
check_interval=CONF.benchmark.nova_server_unpause_poll_interval
)

def _delete_server(self, server, force=False):
"""Delete the given server.
Expand Down
26 changes: 26 additions & 0 deletions samples/tasks/scenarios/nova/pause-and-unpause.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"NovaServers.pause_and_unpause_server": [
{
"args": {
"flavor": {
"name": "m1.nano"
},
"image": {
"name": "^cirros.*uec$"
},
"force_delete": false
},
"runner": {
"type": "constant",
"times": 10,
"concurrency": 2
},
"context": {
"users": {
"tenants": 3,
"users_per_tenant": 2
}
}
}
]
}
17 changes: 17 additions & 0 deletions samples/tasks/scenarios/nova/pause-and-unpause.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
NovaServers.pause_and_unpause_server:
-
args:
flavor:
name: "m1.nano"
image:
name: "^cirros.*uec$"
force_delete: false
runner:
type: "constant"
times: 10
concurrency: 2
context:
users:
tenants: 3
users_per_tenant: 2
20 changes: 20 additions & 0 deletions tests/unit/benchmark/scenarios/nova/test_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,26 @@ def test_suspend_and_resume_server(self):
scenario._delete_server.assert_called_once_with(fake_server,
force=False)

def test_pause_and_unpause_server(self):
fake_server = object()

scenario = servers.NovaServers()
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario._boot_server = mock.MagicMock(return_value=fake_server)
scenario._pause_server = mock.MagicMock()
scenario._unpause_server = mock.MagicMock()
scenario._delete_server = mock.MagicMock()

scenario.pause_and_unpause_server("img", 0, fakearg="fakearg")

scenario._boot_server.assert_called_once_with("img", 0,
fakearg="fakearg")

scenario._pause_server.assert_called_once_with(fake_server)
scenario._unpause_server.assert_called_once_with(fake_server)
scenario._delete_server.assert_called_once_with(fake_server,
force=False)

def test_list_servers(self):
scenario = servers.NovaServers()
scenario._list_servers = mock.MagicMock()
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/benchmark/scenarios/nova/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,30 @@ def test__resume_server(self):
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
"nova.resume_server")

def test__pause_server(self):
nova_scenario = utils.NovaScenario()
nova_scenario._pause_server(self.server)
self.server.pause.assert_called_once_with()
self._test_assert_called_once_with(
self.wait_for.mock, self.server,
CONF.benchmark.nova_server_pause_poll_interval,
CONF.benchmark.nova_server_pause_timeout)
self.res_is.mock.assert_has_calls([mock.call("PAUSED")])
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
"nova.pause_server")

def test__unpause_server(self):
nova_scenario = utils.NovaScenario()
nova_scenario._unpause_server(self.server)
self.server.unpause.assert_called_once_with()
self._test_assert_called_once_with(
self.wait_for.mock, self.server,
CONF.benchmark.nova_server_unpause_poll_interval,
CONF.benchmark.nova_server_unpause_timeout)
self.res_is.mock.assert_has_calls([mock.call("ACTIVE")])
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
"nova.unpause_server")

@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__create_image(self, mock_clients):
mock_clients("nova").images.get.return_value = self.image
Expand Down

0 comments on commit 2f0c079

Please sign in to comment.