ServerActionsSampleJsonTest refactor
Change the instance action sample to a real world action. In Setup, we create an instance and then stop it. That would be 2 actions(create and stop), and the stop action should have a "compute_stop_instance" event. And then we do 2.1/2.21/2.51 test case based on these actions, like we have done in 2.58. Change-Id: Iac23a574a05e62a99aab20ffce4265f4fb5a44d9
This commit is contained in:
@@ -13,90 +13,50 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
|
||||
import six
|
||||
|
||||
from nova.tests.functional.api_sample_tests import api_sample_base
|
||||
from nova.tests.functional.api_sample_tests import test_servers
|
||||
from nova.tests.functional import api_samples_test_base
|
||||
from nova.tests.functional import integrated_helpers
|
||||
from nova.tests.unit import fake_instance
|
||||
from nova.tests.unit import fake_server_actions
|
||||
from nova.tests.unit import utils as test_utils
|
||||
|
||||
|
||||
class ServerActionsSampleJsonTest(api_sample_base.ApiSampleTestBaseV21):
|
||||
class ServerActionsSampleJsonTest(test_servers.ServersSampleBase,
|
||||
integrated_helpers.InstanceHelperMixin):
|
||||
microversion = None
|
||||
ADMIN_API = True
|
||||
sample_dir = 'os-instance-actions'
|
||||
|
||||
def setUp(self):
|
||||
super(ServerActionsSampleJsonTest, self).setUp()
|
||||
self.api.microversion = self.microversion
|
||||
self.actions = fake_server_actions.FAKE_ACTIONS
|
||||
self.events = fake_server_actions.FAKE_EVENTS
|
||||
self.instance = test_utils.get_test_instance(obj=True)
|
||||
# Create and stop a server
|
||||
self.uuid = self._post_server()
|
||||
self._get_response('servers/%s/action' % self.uuid, 'POST',
|
||||
'{"os-stop": null}')
|
||||
response = self._do_get('servers/%s/os-instance-actions' % self.uuid)
|
||||
response_data = api_samples_test_base.pretty_data(response.content)
|
||||
actions = api_samples_test_base.objectify(response_data)
|
||||
self.action_stop = actions['instanceActions'][0]
|
||||
self._wait_for_state_change(self.api, {'id': self.uuid}, 'SHUTOFF')
|
||||
|
||||
def _fake_get(stub_self, context, instance_uuid, expected_attrs=None):
|
||||
return fake_instance.fake_instance_obj(
|
||||
None, **{'uuid': instance_uuid})
|
||||
|
||||
def fake_instance_action_get_by_request_id(context, uuid, request_id):
|
||||
return copy.deepcopy(self.actions[uuid][request_id])
|
||||
|
||||
def fake_server_actions_get(context, uuid, limit=None, marker=None,
|
||||
filters=None):
|
||||
return [copy.deepcopy(value) for value in
|
||||
six.itervalues(self.actions[uuid])]
|
||||
|
||||
def fake_instance_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
|
||||
|
||||
self.stub_out('nova.db.action_get_by_request_id',
|
||||
fake_instance_action_get_by_request_id)
|
||||
self.stub_out('nova.db.actions_get', fake_server_actions_get)
|
||||
self.stub_out('nova.db.action_events_get',
|
||||
fake_instance_action_events_get)
|
||||
self.stub_out('nova.db.instance_get_by_uuid',
|
||||
fake_instance_get_by_uuid)
|
||||
self.stub_out('nova.compute.api.API.get', _fake_get)
|
||||
def _get_subs(self):
|
||||
return {
|
||||
'uuid': self.uuid,
|
||||
'project_id': self.action_stop['project_id']
|
||||
}
|
||||
|
||||
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]
|
||||
|
||||
req_id = self.action_stop['request_id']
|
||||
response = self._do_get('servers/%s/os-instance-actions/%s' %
|
||||
(fake_uuid, fake_request_id))
|
||||
subs = {}
|
||||
subs['action'] = '(reboot)|(resize)'
|
||||
subs['instance_uuid'] = str(fake_uuid)
|
||||
subs['integer_id'] = '[0-9]+'
|
||||
subs['request_id'] = str(fake_action['request_id'])
|
||||
subs['start_time'] = str(fake_action['start_time'])
|
||||
subs['result'] = '(Success)|(Error)'
|
||||
subs['event'] = '(schedule)|(compute_create)'
|
||||
(self.uuid, req_id))
|
||||
# Non-admins can see event details except for the "traceback" field
|
||||
# starting in the 2.51 microversion.
|
||||
if self.ADMIN_API:
|
||||
name = 'instance-action-get-resp'
|
||||
else:
|
||||
name = 'instance-action-get-non-admin-resp'
|
||||
self._verify_response(name, subs, response, 200)
|
||||
self._verify_response(name, self._get_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 = {}
|
||||
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 = self._do_get('servers/%s/os-instance-actions' % self.uuid)
|
||||
self._verify_response('instance-actions-list-resp', self._get_subs(),
|
||||
response, 200)
|
||||
|
||||
|
||||
@@ -132,47 +92,9 @@ class ServerActionsV251NonAdminSampleJsonTest(ServerActionsSampleJsonTest):
|
||||
scenarios = [('v2_51', {'api_major_version': 'v2.1'})]
|
||||
|
||||
|
||||
class ServerActionsV258SampleJsonTest(test_servers.ServersSampleBase,
|
||||
integrated_helpers.InstanceHelperMixin):
|
||||
class ServerActionsV258SampleJsonTest(ServerActionsV251AdminSampleJsonTest):
|
||||
microversion = '2.58'
|
||||
scenarios = [('v2_58', {'api_major_version': 'v2.1'})]
|
||||
sample_dir = 'os-instance-actions'
|
||||
ADMIN_API = True
|
||||
|
||||
def setUp(self):
|
||||
super(ServerActionsV258SampleJsonTest, self).setUp()
|
||||
# Create and stop a server
|
||||
self.uuid = self._post_server()
|
||||
self._get_response('servers/%s/action' % self.uuid, 'POST',
|
||||
'{"os-stop": null}')
|
||||
response = self._do_get('servers/%s/os-instance-actions' % self.uuid)
|
||||
response_data = api_samples_test_base.pretty_data(response.content)
|
||||
actions = api_samples_test_base.objectify(response_data)
|
||||
self.action_stop = actions['instanceActions'][0]
|
||||
self._wait_for_state_change(self.api, {'id': self.uuid}, 'SHUTOFF')
|
||||
|
||||
def _get_subs(self):
|
||||
return {
|
||||
'uuid': self.uuid,
|
||||
'project_id': self.action_stop['project_id']
|
||||
}
|
||||
|
||||
def test_instance_action_get(self):
|
||||
req_id = self.action_stop['request_id']
|
||||
response = self._do_get('servers/%s/os-instance-actions/%s' %
|
||||
(self.uuid, req_id))
|
||||
# Non-admins can see event details except for the "traceback" field
|
||||
# starting in the 2.51 microversion.
|
||||
if self.ADMIN_API:
|
||||
name = 'instance-action-get-resp'
|
||||
else:
|
||||
name = 'instance-action-get-non-admin-resp'
|
||||
self._verify_response(name, self._get_subs(), response, 200)
|
||||
|
||||
def test_instance_actions_list(self):
|
||||
response = self._do_get('servers/%s/os-instance-actions' % self.uuid)
|
||||
self._verify_response('instance-actions-list-resp', self._get_subs(),
|
||||
response, 200)
|
||||
|
||||
def test_instance_actions_list_with_limit(self):
|
||||
response = self._do_get('servers/%s/os-instance-actions'
|
||||
|
||||
Reference in New Issue
Block a user