In order to use the 3.0.0 release of the fixtures library some tests needed to be updated in order to be compatible with 1.4 and 3.0. Most failures with 3.0 were due to using bound methods of a class to patch another class. This requires a different signature on the method used for patching between the fixtures versions. Moving the methods to be functions addresses this for the cases where the test method does not need to access the class it was defined on. For test_networks a different tact was needed. Because the methods used for patching require accessing state on their defined class a proxy method is introduced. This proxy method captures and discards the 'self' parameter from the call point of the patched method. By doing so the patching methods can have the same signature for multiple fixtures versions. Change-Id: I9c5635d0930b091e1ae0a1439d687dd20a0ff939
107 lines
4.3 KiB
Python
107 lines
4.3 KiB
Python
# Copyright 2012 Nebula, Inc.
|
|
# Copyright 2013 IBM Corp.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import copy
|
|
|
|
import six
|
|
|
|
import nova.conf
|
|
from nova.tests.functional.api_sample_tests import api_sample_base
|
|
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 = nova.conf.CONF
|
|
|
|
|
|
class ServerActionsSampleJsonTest(api_sample_base.ApiSampleTestBaseV21):
|
|
microversion = None
|
|
ADMIN_API = True
|
|
extension_name = 'os-instance-actions'
|
|
|
|
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()
|
|
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)
|
|
|
|
def _fake_get(stub_self, context, instance_uuid, expected_attrs=None,
|
|
want_objects=True):
|
|
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):
|
|
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 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 = {}
|
|
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._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 = {}
|
|
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 ServerActionsV221SampleJsonTest(ServerActionsSampleJsonTest):
|
|
microversion = '2.21'
|
|
scenarios = [('v2_21', {'api_major_version': 'v2.1'})]
|