Merging instance_actions tests between V2 and V2.1
Currently v2 and v2.1 have separate functional tests and their corresponding sample files. As v2 and v2.1 are supposed to be identical, there is overhead to maintain two set of functional tests and sample files. We can have one set of tests which can run for both v2 and v2.1. This commit merges instance_actions functional tests. Change-Id: I0773458cdeeca2f1eeac19d579cb8228769e1e18
This commit is contained in:
parent
e69a74f365
commit
ed91ab06af
doc/api_samples/os-instance-actions
nova/tests/functional
@ -1,27 +0,0 @@
|
||||
{
|
||||
"instanceAction": {
|
||||
"action": "reboot",
|
||||
"events": [
|
||||
{
|
||||
"event": "schedule",
|
||||
"finish_time": "2012-12-05T01:02:00.000000",
|
||||
"result": "Success",
|
||||
"start_time": "2012-12-05T01:00:02.000000",
|
||||
"traceback": ""
|
||||
},
|
||||
{
|
||||
"event": "compute_create",
|
||||
"finish_time": "2012-12-05T01:04:00.000000",
|
||||
"result": "Success",
|
||||
"start_time": "2012-12-05T01:03:00.000000",
|
||||
"traceback": ""
|
||||
}
|
||||
],
|
||||
"instance_uuid": "b48316c5-71e8-45e4-9884-6c78055b9b13",
|
||||
"message": "",
|
||||
"project_id": "147",
|
||||
"request_id": "req-3293a3f1-b44c-4609-b8d2-d81b105636b8",
|
||||
"start_time": "2012-12-05T00:00:00.000000",
|
||||
"user_id": "789"
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
{
|
||||
"instanceActions": [
|
||||
{
|
||||
"action": "resize",
|
||||
"instance_uuid": "b48316c5-71e8-45e4-9884-6c78055b9b13",
|
||||
"message": "",
|
||||
"project_id": "842",
|
||||
"request_id": "req-25517360-b757-47d3-be45-0e8d2a01b36a",
|
||||
"start_time": "2012-12-05T01:00:00.000000",
|
||||
"user_id": "789"
|
||||
},
|
||||
{
|
||||
"action": "reboot",
|
||||
"instance_uuid": "b48316c5-71e8-45e4-9884-6c78055b9b13",
|
||||
"message": "",
|
||||
"project_id": "147",
|
||||
"request_id": "req-3293a3f1-b44c-4609-b8d2-d81b105636b8",
|
||||
"start_time": "2012-12-05T00:00:00.000000",
|
||||
"user_id": "789"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
{
|
||||
"instanceAction": {
|
||||
"action": "%(action)s",
|
||||
"instance_uuid": "%(instance_uuid)s",
|
||||
"request_id": "%(request_id)s",
|
||||
"user_id": "%(integer_id)s",
|
||||
"project_id": "%(integer_id)s",
|
||||
"start_time": "%(strtime)s",
|
||||
"message": "",
|
||||
"events": [
|
||||
{
|
||||
"event": "%(event)s",
|
||||
"start_time": "%(strtime)s",
|
||||
"finish_time": "%(strtime)s",
|
||||
"result": "%(result)s",
|
||||
"traceback": ""
|
||||
},
|
||||
{
|
||||
"event": "%(event)s",
|
||||
"start_time": "%(strtime)s",
|
||||
"finish_time": "%(strtime)s",
|
||||
"result": "%(result)s",
|
||||
"traceback": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
{
|
||||
"instanceActions": [
|
||||
{
|
||||
"action": "%(action)s",
|
||||
"instance_uuid": "%(uuid)s",
|
||||
"request_id": "%(request_id)s",
|
||||
"user_id": "%(integer_id)s",
|
||||
"project_id": "%(integer_id)s",
|
||||
"start_time": "%(strtime)s",
|
||||
"message": ""
|
||||
},
|
||||
{
|
||||
"action": "%(action)s",
|
||||
"instance_uuid": "%(uuid)s",
|
||||
"request_id": "%(request_id)s",
|
||||
"user_id": "%(integer_id)s",
|
||||
"project_id": "%(integer_id)s",
|
||||
"start_time": "%(strtime)s",
|
||||
"message": ""
|
||||
}
|
||||
]
|
||||
}
|
@ -14,7 +14,6 @@
|
||||
# under the License.
|
||||
|
||||
import base64
|
||||
import copy
|
||||
import datetime
|
||||
import inspect
|
||||
import os
|
||||
@ -62,7 +61,6 @@ from nova.tests.unit import fake_block_device
|
||||
from nova.tests.unit import fake_instance
|
||||
from nova.tests.unit import fake_network
|
||||
from nova.tests.unit import fake_network_cache_model
|
||||
from nova.tests.unit import fake_server_actions
|
||||
from nova.tests.unit import fake_utils
|
||||
from nova.tests.unit.image import fake
|
||||
from nova.tests.unit.objects import test_network
|
||||
@ -2566,72 +2564,6 @@ class EvacuateFindHostSampleJsonTest(ServersSampleBase):
|
||||
host=None)
|
||||
|
||||
|
||||
class InstanceActionsSampleJsonTest(ApiSampleTestBaseV2):
|
||||
ADMIN_API = True
|
||||
extension_name = ('nova.api.openstack.compute.contrib.instance_actions.'
|
||||
'Instance_actions')
|
||||
|
||||
def setUp(self):
|
||||
super(InstanceActionsSampleJsonTest, self).setUp()
|
||||
self.actions = fake_server_actions.FAKE_ACTIONS
|
||||
self.events = fake_server_actions.FAKE_EVENTS
|
||||
self.instance = test_utils.get_test_instance(obj=True)
|
||||
|
||||
def fake_server_action_get_by_request_id(context, uuid, request_id):
|
||||
return copy.deepcopy(self.actions[uuid][request_id])
|
||||
|
||||
def fake_server_actions_get(context, uuid):
|
||||
return [copy.deepcopy(value) for value in
|
||||
self.actions[uuid].itervalues()]
|
||||
|
||||
def fake_server_action_events_get(context, action_id):
|
||||
return copy.deepcopy(self.events[action_id])
|
||||
|
||||
def fake_instance_get_by_uuid(context, instance_id):
|
||||
return self.instance
|
||||
|
||||
def fake_get(self, context, instance_uuid, expected_attrs=None,
|
||||
want_objects=True):
|
||||
return fake_instance.fake_instance_obj(
|
||||
None, **{'uuid': instance_uuid})
|
||||
|
||||
self.stubs.Set(db, 'action_get_by_request_id',
|
||||
fake_server_action_get_by_request_id)
|
||||
self.stubs.Set(db, 'actions_get', fake_server_actions_get)
|
||||
self.stubs.Set(db, 'action_events_get',
|
||||
fake_server_action_events_get)
|
||||
self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get_by_uuid)
|
||||
self.stubs.Set(compute_api.API, 'get', fake_get)
|
||||
|
||||
def test_instance_action_get(self):
|
||||
fake_uuid = fake_server_actions.FAKE_UUID
|
||||
fake_request_id = fake_server_actions.FAKE_REQUEST_ID1
|
||||
fake_action = self.actions[fake_uuid][fake_request_id]
|
||||
|
||||
response = self._do_get('servers/%s/os-instance-actions/%s' %
|
||||
(fake_uuid, fake_request_id))
|
||||
subs = self._get_regexes()
|
||||
subs['action'] = '(reboot)|(resize)'
|
||||
subs['instance_uuid'] = fake_uuid
|
||||
subs['integer_id'] = '[0-9]+'
|
||||
subs['request_id'] = fake_action['request_id']
|
||||
subs['start_time'] = fake_action['start_time']
|
||||
subs['result'] = '(Success)|(Error)'
|
||||
subs['event'] = '(schedule)|(compute_create)'
|
||||
self._verify_response('instance-action-get-resp', subs, response, 200)
|
||||
|
||||
def test_instance_actions_list(self):
|
||||
fake_uuid = fake_server_actions.FAKE_UUID
|
||||
response = self._do_get('servers/%s/os-instance-actions' % (fake_uuid))
|
||||
subs = self._get_regexes()
|
||||
subs['action'] = '(reboot)|(resize)'
|
||||
subs['integer_id'] = '[0-9]+'
|
||||
subs['request_id'] = ('req-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}'
|
||||
'-[0-9a-f]{4}-[0-9a-f]{12}')
|
||||
self._verify_response('instance-actions-list-resp', subs,
|
||||
response, 200)
|
||||
|
||||
|
||||
class ImageSizeSampleJsonTests(ApiSampleTestBaseV2):
|
||||
extension_name = ("nova.api.openstack.compute.contrib"
|
||||
".image_size.Image_size")
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
import copy
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from nova.compute import api as compute_api
|
||||
from nova import db
|
||||
from nova.tests.functional.v3 import api_sample_base
|
||||
@ -22,10 +24,25 @@ from nova.tests.unit import fake_instance
|
||||
from nova.tests.unit import fake_server_actions
|
||||
from nova.tests.unit import utils as test_utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.import_opt('osapi_compute_extension',
|
||||
'nova.api.openstack.compute.extensions')
|
||||
|
||||
|
||||
class ServerActionsSampleJsonTest(api_sample_base.ApiSampleTestBaseV3):
|
||||
ADMIN_API = True
|
||||
extension_name = 'os-instance-actions'
|
||||
# TODO(gmann): Overriding '_api_version' till all functional tests
|
||||
# are merged between v2 and v2.1. After that base class variable
|
||||
# itself can be changed to 'v2'
|
||||
_api_version = 'v2'
|
||||
|
||||
def _get_flags(self):
|
||||
f = super(ServerActionsSampleJsonTest, self)._get_flags()
|
||||
f['osapi_compute_extension'] = CONF.osapi_compute_extension[:]
|
||||
f['osapi_compute_extension'].append('nova.api.openstack.compute.'
|
||||
'contrib.instance_actions.Instance_actions')
|
||||
return f
|
||||
|
||||
def setUp(self):
|
||||
super(ServerActionsSampleJsonTest, self).setUp()
|
||||
|
Loading…
x
Reference in New Issue
Block a user