Add os-start/stop functional negative tests

The negative tests of os-start/stop API are not covered enough
in functional tests. We want to add the conflict tests of when
this API runs in the unexpected state of server.
* Case of os-start API, the server status must be SHUTOFF.
* Case of os-stop API, the server status must be ACTIVE or ERROR.

Change-Id: I1c44ae737ad39bc58dd3ebfd554176d6400fd9fd
This commit is contained in:
Maho Koshiya
2016-10-13 17:23:24 +09:00
parent bc1b11fdc2
commit 8b8a29c8b5

View File

@@ -506,6 +506,48 @@ class ServersTest(ServersTestBase):
# Cleanup
self._delete_server(created_server_id)
def test_stop_start_servers_negative_invalid_state(self):
# Create server
server = self._build_minimal_create_server_request()
created_server = self.api.post_server({"server": server})
created_server_id = created_server['id']
found_server = self._wait_for_state_change(created_server, 'BUILD')
self.assertEqual('ACTIVE', found_server['status'])
# Start server in ACTIVE
# NOTE(mkoshiya): When os-start API runs, the server status
# must be SHUTOFF.
# By returning 409, I want to confirm that the ACTIVE server does not
# cause unexpected behavior.
post = {'os-start': {}}
ex = self.assertRaises(client.OpenStackApiException,
self.api.post_server_action,
created_server_id, post)
self.assertEqual(409, ex.response.status_code)
self.assertEqual('ACTIVE', found_server['status'])
# Stop server
post = {'os-stop': {}}
self.api.post_server_action(created_server_id, post)
found_server = self._wait_for_state_change(found_server, 'ACTIVE')
self.assertEqual('SHUTOFF', found_server['status'])
# Stop server in SHUTOFF
# NOTE(mkoshiya): When os-stop API runs, the server status
# must be ACTIVE or ERROR.
# By returning 409, I want to confirm that the SHUTOFF server does not
# cause unexpected behavior.
post = {'os-stop': {}}
ex = self.assertRaises(client.OpenStackApiException,
self.api.post_server_action,
created_server_id, post)
self.assertEqual(409, ex.response.status_code)
self.assertEqual('SHUTOFF', found_server['status'])
# Cleanup
self._delete_server(created_server_id)
class ServersTestV21(ServersTest):
api_major_version = 'v2.1'