Refactor test cases related to instance object
After the blueprint unified-object-model, all of the instances should be represented by an instance object but not a db instance dict. In some test cases, they are still using db instance dict, we should change those test cases to use instance object. The fix include three parts: 1) Add a new stub method fake_fault_obj in nova/tests/fake_instance.py to help convert a dict fault to an object fault. 2) Add a new stub method fake_instance_obj in nova/tests/fake_instance.py to help convert a dict instance to an object instance. 3) Make sure all test cases related to "fault" and "instance" passed. Closes-Bug 1230125 Partial-Bug 1212915 Change-Id: Ie54fface139e4ad042b9a748c7409c3698875413
This commit is contained in:
parent
84e3b60617
commit
5aeab05277
|
@ -20,11 +20,13 @@ from nova.api.openstack.compute.contrib import extended_availability_zone
|
|||
from nova import availability_zones
|
||||
from nova import compute
|
||||
from nova.compute import vm_states
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova.tests import fake_instance
|
||||
|
||||
UUID1 = '00000000-0000-0000-0000-000000000001'
|
||||
UUID2 = '00000000-0000-0000-0000-000000000002'
|
||||
|
@ -35,20 +37,20 @@ def fake_compute_get_az(*args, **kwargs):
|
|||
inst = fakes.stub_instance(1, uuid=UUID3, host="get-host",
|
||||
vm_state=vm_states.ACTIVE,
|
||||
availability_zone='fakeaz')
|
||||
return inst
|
||||
return fake_instance.fake_instance_obj(args[1], **inst)
|
||||
|
||||
|
||||
def fake_compute_get_empty(*args, **kwargs):
|
||||
inst = fakes.stub_instance(1, uuid=UUID3, host="",
|
||||
vm_state=vm_states.ACTIVE,
|
||||
availability_zone='fakeaz')
|
||||
return inst
|
||||
return fake_instance.fake_instance_obj(args[1], **inst)
|
||||
|
||||
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
inst = fakes.stub_instance(1, uuid=UUID3, host="get-host",
|
||||
vm_state=vm_states.ACTIVE)
|
||||
return inst
|
||||
return fake_instance.fake_instance_obj(args[1], **inst)
|
||||
|
||||
|
||||
def fake_compute_get_all(*args, **kwargs):
|
||||
|
@ -83,6 +85,8 @@ class ExtendedServerAttributesTest(test.TestCase):
|
|||
self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
|
||||
self.stubs.Set(availability_zones, 'get_host_availability_zone',
|
||||
fake_get_host_availability_zone)
|
||||
return_server = fakes.fake_instance_get()
|
||||
self.stubs.Set(db, 'instance_get_by_uuid', return_server)
|
||||
|
||||
self.flags(
|
||||
osapi_compute_extension=[
|
||||
|
|
|
@ -23,6 +23,7 @@ from nova.objects import instance as instance_obj
|
|||
from nova.openstack.common import jsonutils
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova.tests import fake_instance
|
||||
|
||||
UUID1 = '00000000-0000-0000-0000-000000000001'
|
||||
UUID2 = '00000000-0000-0000-0000-000000000002'
|
||||
|
@ -88,7 +89,9 @@ ALL_IPS.sort()
|
|||
|
||||
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
return fakes.stub_instance(1, uuid=UUID3, nw_cache=NW_CACHE)
|
||||
inst = fakes.stub_instance(1, uuid=UUID3, nw_cache=NW_CACHE)
|
||||
return fake_instance.fake_instance_obj(args[1],
|
||||
expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS, **inst)
|
||||
|
||||
|
||||
def fake_compute_get_all(*args, **kwargs):
|
||||
|
|
|
@ -25,6 +25,7 @@ from nova.objects import instance as instance_obj
|
|||
from nova.openstack.common import jsonutils
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova.tests import fake_instance
|
||||
|
||||
UUID1 = '00000000-0000-0000-0000-000000000001'
|
||||
UUID2 = '00000000-0000-0000-0000-000000000002'
|
||||
|
@ -95,7 +96,9 @@ ALL_IPS.sort()
|
|||
|
||||
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
return fakes.stub_instance(1, uuid=UUID3, nw_cache=NW_CACHE)
|
||||
inst = fakes.stub_instance(1, uuid=UUID3, nw_cache=NW_CACHE)
|
||||
return fake_instance.fake_instance_obj(args[1],
|
||||
expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS, **inst)
|
||||
|
||||
|
||||
def fake_compute_get_all(*args, **kwargs):
|
||||
|
|
|
@ -18,11 +18,13 @@ import webob
|
|||
|
||||
from nova.api.openstack.compute.contrib import extended_status
|
||||
from nova import compute
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova.tests import fake_instance
|
||||
|
||||
UUID1 = '00000000-0000-0000-0000-000000000001'
|
||||
UUID2 = '00000000-0000-0000-0000-000000000002'
|
||||
|
@ -30,8 +32,9 @@ UUID3 = '00000000-0000-0000-0000-000000000003'
|
|||
|
||||
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
return fakes.stub_instance(1, uuid=UUID3, task_state="kayaking",
|
||||
inst = fakes.stub_instance(1, uuid=UUID3, task_state="kayaking",
|
||||
vm_state="slightly crunchy", power_state=1)
|
||||
return fake_instance.fake_instance_obj(args[1], **inst)
|
||||
|
||||
|
||||
def fake_compute_get_all(*args, **kwargs):
|
||||
|
@ -61,6 +64,8 @@ class ExtendedStatusTest(test.TestCase):
|
|||
osapi_compute_extension=[
|
||||
'nova.api.openstack.compute.contrib.select_extensions'],
|
||||
osapi_compute_ext_list=['Extended_status'])
|
||||
return_server = fakes.fake_instance_get()
|
||||
self.stubs.Set(db, 'instance_get_by_uuid', return_server)
|
||||
|
||||
def _make_request(self, url):
|
||||
req = webob.Request.blank(url)
|
||||
|
|
|
@ -18,10 +18,12 @@ import webob
|
|||
|
||||
from nova.api.openstack.compute.contrib import extended_volumes
|
||||
from nova import compute
|
||||
from nova import db
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova.tests import fake_instance
|
||||
|
||||
UUID1 = '00000000-0000-0000-0000-000000000001'
|
||||
UUID2 = '00000000-0000-0000-0000-000000000002'
|
||||
|
@ -29,7 +31,8 @@ UUID3 = '00000000-0000-0000-0000-000000000003'
|
|||
|
||||
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
return fakes.stub_instance(1, uuid=UUID1)
|
||||
inst = fakes.stub_instance(1, uuid=UUID1)
|
||||
return fake_instance.fake_instance_obj(args[1], **inst)
|
||||
|
||||
|
||||
def fake_compute_get_all(*args, **kwargs):
|
||||
|
@ -59,6 +62,8 @@ class ExtendedVolumesTest(test.TestCase):
|
|||
osapi_compute_extension=[
|
||||
'nova.api.openstack.compute.contrib.select_extensions'],
|
||||
osapi_compute_ext_list=['Extended_volumes'])
|
||||
return_server = fakes.fake_instance_get()
|
||||
self.stubs.Set(db, 'instance_get_by_uuid', return_server)
|
||||
|
||||
def _make_request(self, url):
|
||||
req = webob.Request.blank(url)
|
||||
|
|
|
@ -21,11 +21,13 @@ import webob
|
|||
from nova.api.openstack import wsgi
|
||||
from nova import compute
|
||||
from nova.compute import vm_states
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova.tests import fake_instance
|
||||
|
||||
|
||||
SENTINEL = object()
|
||||
|
@ -33,7 +35,8 @@ SENTINEL = object()
|
|||
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
def _return_server(*_args, **_kwargs):
|
||||
return fakes.stub_instance(*args, **kwargs)
|
||||
inst = fakes.stub_instance(*args, **kwargs)
|
||||
return fake_instance.fake_instance_obj(_args[1], **inst)
|
||||
return _return_server
|
||||
|
||||
|
||||
|
@ -47,6 +50,8 @@ class HideServerAddressesTest(test.TestCase):
|
|||
osapi_compute_extension=[
|
||||
'nova.api.openstack.compute.contrib.select_extensions'],
|
||||
osapi_compute_ext_list=['Hide_server_addresses'])
|
||||
return_server = fakes.fake_instance_get()
|
||||
self.stubs.Set(db, 'instance_get_by_uuid', return_server)
|
||||
|
||||
def _make_request(self, url):
|
||||
req = webob.Request.blank(url)
|
||||
|
|
|
@ -1498,13 +1498,15 @@ def fake_compute_get_all(*args, **kwargs):
|
|||
|
||||
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
return fakes.stub_instance(1, uuid=UUID3,
|
||||
inst = fakes.stub_instance(1, uuid=UUID3,
|
||||
security_groups=[{'name': 'fake-2-0'},
|
||||
{'name': 'fake-2-1'}])
|
||||
return fake_instance.fake_instance_obj(args[1],
|
||||
expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS, **inst)
|
||||
|
||||
|
||||
def fake_compute_create(*args, **kwargs):
|
||||
return ([fake_compute_get()], '')
|
||||
return ([fake_compute_get(*args, **kwargs)], '')
|
||||
|
||||
|
||||
def fake_get_instances_security_groups_bindings(inst, context):
|
||||
|
|
|
@ -19,12 +19,14 @@ from lxml import etree
|
|||
|
||||
from nova.api.openstack.compute.contrib import server_usage
|
||||
from nova import compute
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova.openstack.common import timeutils
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova.tests import fake_instance
|
||||
|
||||
UUID1 = '00000000-0000-0000-0000-000000000001'
|
||||
UUID2 = '00000000-0000-0000-0000-000000000002'
|
||||
|
@ -36,8 +38,9 @@ DATE3 = datetime.datetime(year=2013, month=4, day=5, hour=14)
|
|||
|
||||
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
return fakes.stub_instance(1, uuid=UUID3, launched_at=DATE1,
|
||||
inst = fakes.stub_instance(1, uuid=UUID3, launched_at=DATE1,
|
||||
terminated_at=DATE2)
|
||||
return fake_instance.fake_instance_obj(args[1], **inst)
|
||||
|
||||
|
||||
def fake_compute_get_all(*args, **kwargs):
|
||||
|
@ -66,6 +69,8 @@ class ServerUsageTest(test.TestCase):
|
|||
osapi_compute_extension=[
|
||||
'nova.api.openstack.compute.contrib.select_extensions'],
|
||||
osapi_compute_ext_list=['Server_usage'])
|
||||
return_server = fakes.fake_instance_get()
|
||||
self.stubs.Set(db, 'instance_get_by_uuid', return_server)
|
||||
|
||||
def _make_request(self, url):
|
||||
req = fakes.HTTPRequest.blank(url)
|
||||
|
|
|
@ -20,11 +20,13 @@ from nova.api.openstack.compute.plugins.v3 import extended_availability_zone
|
|||
from nova import availability_zones
|
||||
from nova import compute
|
||||
from nova.compute import vm_states
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova.tests import fake_instance
|
||||
|
||||
UUID1 = '00000000-0000-0000-0000-000000000001'
|
||||
UUID2 = '00000000-0000-0000-0000-000000000002'
|
||||
|
@ -35,20 +37,20 @@ def fake_compute_get_az(*args, **kwargs):
|
|||
inst = fakes.stub_instance(1, uuid=UUID3, host="get-host",
|
||||
vm_state=vm_states.ACTIVE,
|
||||
availability_zone='fakeaz')
|
||||
return inst
|
||||
return fake_instance.fake_instance_obj(args[1], **inst)
|
||||
|
||||
|
||||
def fake_compute_get_empty(*args, **kwargs):
|
||||
inst = fakes.stub_instance(1, uuid=UUID3, host="",
|
||||
vm_state=vm_states.ACTIVE,
|
||||
availability_zone='fakeaz')
|
||||
return inst
|
||||
return fake_instance.fake_instance_obj(args[1], **inst)
|
||||
|
||||
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
inst = fakes.stub_instance(1, uuid=UUID3, host="get-host",
|
||||
vm_state=vm_states.ACTIVE)
|
||||
return inst
|
||||
return fake_instance.fake_instance_obj(args[1], **inst)
|
||||
|
||||
|
||||
def fake_compute_get_all(*args, **kwargs):
|
||||
|
@ -83,6 +85,8 @@ class ExtendedServerAttributesTest(test.TestCase):
|
|||
self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
|
||||
self.stubs.Set(availability_zones, 'get_host_availability_zone',
|
||||
fake_get_host_availability_zone)
|
||||
return_server = fakes.fake_instance_get()
|
||||
self.stubs.Set(db, 'instance_get_by_uuid', return_server)
|
||||
|
||||
def _make_request(self, url):
|
||||
req = webob.Request.blank(url)
|
||||
|
|
|
@ -24,6 +24,7 @@ from nova.objects import instance as instance_obj
|
|||
from nova.openstack.common import jsonutils
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova.tests import fake_instance
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
|
@ -35,8 +36,10 @@ UUID3 = '00000000-0000-0000-0000-000000000003'
|
|||
|
||||
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
return fakes.stub_instance(1, uuid=UUID3, host="host-fake",
|
||||
inst = fakes.stub_instance(1, uuid=UUID3, host="host-fake",
|
||||
node="node-fake")
|
||||
return fake_instance.fake_instance_obj(args[1],
|
||||
expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS, **inst)
|
||||
|
||||
|
||||
def fake_compute_get_all(*args, **kwargs):
|
||||
|
@ -90,7 +93,7 @@ class ExtendedServerAttributesTest(test.TestCase):
|
|||
self.assertServerAttributes(self._get_server(res.body),
|
||||
host='host-fake',
|
||||
node='node-fake',
|
||||
instance_name='instance-1')
|
||||
instance_name=NAME_FMT % (1))
|
||||
|
||||
def test_detail(self):
|
||||
url = '/v3/servers/detail'
|
||||
|
|
|
@ -24,6 +24,7 @@ from nova.objects import instance as instance_obj
|
|||
from nova.openstack.common import jsonutils
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova.tests import fake_instance
|
||||
|
||||
UUID1 = '00000000-0000-0000-0000-000000000001'
|
||||
UUID2 = '00000000-0000-0000-0000-000000000002'
|
||||
|
@ -31,8 +32,9 @@ UUID3 = '00000000-0000-0000-0000-000000000003'
|
|||
|
||||
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
return fakes.stub_instance(1, uuid=UUID3, task_state="kayaking",
|
||||
inst = fakes.stub_instance(1, uuid=UUID3, task_state="kayaking",
|
||||
vm_state="slightly crunchy", power_state=1, locked_by='owner')
|
||||
return fake_instance.fake_instance_obj(args[1], **inst)
|
||||
|
||||
|
||||
def fake_compute_get_all(*args, **kwargs):
|
||||
|
@ -57,7 +59,8 @@ class ExtendedStatusTest(test.TestCase):
|
|||
fakes.stub_out_nw_api(self.stubs)
|
||||
self.stubs.Set(compute.api.API, 'get', fake_compute_get)
|
||||
self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
|
||||
self.stubs.Set(db, 'instance_get_by_uuid', fake_compute_get)
|
||||
return_server = fakes.fake_instance_get()
|
||||
self.stubs.Set(db, 'instance_get_by_uuid', return_server)
|
||||
|
||||
def _make_request(self, url):
|
||||
req = webob.Request.blank(url)
|
||||
|
|
|
@ -21,11 +21,13 @@ import webob
|
|||
from nova.api.openstack.compute.plugins.v3 import extended_volumes
|
||||
from nova import compute
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova.tests import fake_instance
|
||||
from nova import volume
|
||||
|
||||
UUID1 = '00000000-0000-0000-0000-000000000001'
|
||||
|
@ -34,7 +36,8 @@ UUID3 = '00000000-0000-0000-0000-000000000003'
|
|||
|
||||
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
return fakes.stub_instance(1, uuid=UUID1)
|
||||
inst = fakes.stub_instance(1, uuid=UUID1)
|
||||
return fake_instance.fake_instance_obj(args[1], **inst)
|
||||
|
||||
|
||||
def fake_compute_get_not_found(*args, **kwargs):
|
||||
|
@ -126,6 +129,8 @@ class ExtendedVolumesTest(test.TestCase):
|
|||
self.stubs.Set(compute.api.API, 'attach_volume', fake_attach_volume)
|
||||
self.app = fakes.wsgi_app_v3(init_only=('os-extended-volumes',
|
||||
'servers'))
|
||||
return_server = fakes.fake_instance_get()
|
||||
self.stubs.Set(db, 'instance_get_by_uuid', return_server)
|
||||
|
||||
def _make_request(self, url, body=None):
|
||||
req = webob.Request.blank(url)
|
||||
|
|
|
@ -21,11 +21,13 @@ import webob
|
|||
from nova.api.openstack import wsgi
|
||||
from nova import compute
|
||||
from nova.compute import vm_states
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova.tests import fake_instance
|
||||
|
||||
|
||||
SENTINEL = object()
|
||||
|
@ -33,7 +35,8 @@ SENTINEL = object()
|
|||
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
def _return_server(*_args, **_kwargs):
|
||||
return fakes.stub_instance(*args, **kwargs)
|
||||
inst = fakes.stub_instance(*args, **kwargs)
|
||||
return fake_instance.fake_instance_obj(_args[1], **inst)
|
||||
return _return_server
|
||||
|
||||
|
||||
|
@ -43,6 +46,8 @@ class HideServerAddressesTest(test.TestCase):
|
|||
def setUp(self):
|
||||
super(HideServerAddressesTest, self).setUp()
|
||||
fakes.stub_out_nw_api(self.stubs)
|
||||
return_server = fakes.fake_instance_get()
|
||||
self.stubs.Set(db, 'instance_get_by_uuid', return_server)
|
||||
|
||||
def _make_request(self, url):
|
||||
req = webob.Request.blank(url)
|
||||
|
|
|
@ -81,13 +81,15 @@ def fake_compute_get_all(*args, **kwargs):
|
|||
|
||||
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
return fakes.stub_instance(1, uuid=UUID3,
|
||||
inst = fakes.stub_instance(1, uuid=UUID3,
|
||||
security_groups=[{'name': 'fake-2-0'},
|
||||
{'name': 'fake-2-1'}])
|
||||
return fake_instance.fake_instance_obj(args[1],
|
||||
expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS, **inst)
|
||||
|
||||
|
||||
def fake_compute_create(*args, **kwargs):
|
||||
return ([fake_compute_get()], '')
|
||||
return ([fake_compute_get(*args, **kwargs)], '')
|
||||
|
||||
|
||||
def fake_get_instance_security_groups(*args, **kwargs):
|
||||
|
|
|
@ -19,12 +19,14 @@ from lxml import etree
|
|||
|
||||
from nova.api.openstack.compute.plugins.v3 import server_usage
|
||||
from nova import compute
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova.openstack.common import timeutils
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova.tests import fake_instance
|
||||
|
||||
UUID1 = '00000000-0000-0000-0000-000000000001'
|
||||
UUID2 = '00000000-0000-0000-0000-000000000002'
|
||||
|
@ -36,8 +38,9 @@ DATE3 = datetime.datetime(year=2013, month=4, day=5, hour=14)
|
|||
|
||||
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
return fakes.stub_instance(1, uuid=UUID3, launched_at=DATE1,
|
||||
inst = fakes.stub_instance(1, uuid=UUID3, launched_at=DATE1,
|
||||
terminated_at=DATE2)
|
||||
return fake_instance.fake_instance_obj(args[1], **inst)
|
||||
|
||||
|
||||
def fake_compute_get_all(*args, **kwargs):
|
||||
|
@ -62,6 +65,8 @@ class ServerUsageTest(test.TestCase):
|
|||
fakes.stub_out_nw_api(self.stubs)
|
||||
self.stubs.Set(compute.api.API, 'get', fake_compute_get)
|
||||
self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
|
||||
return_server = fakes.fake_instance_get()
|
||||
self.stubs.Set(db, 'instance_get_by_uuid', return_server)
|
||||
|
||||
def _make_request(self, url):
|
||||
req = fakes.HTTPRequest.blank(url)
|
||||
|
|
|
@ -2758,7 +2758,7 @@ class ServersViewBuilderTest(test.TestCase):
|
|||
super(ServersViewBuilderTest, self).setUp()
|
||||
CONF.set_override('glance_host', 'localhost')
|
||||
self.flags(use_ipv6=True)
|
||||
self.instance = fakes.stub_instance(
|
||||
db_inst = fakes.stub_instance(
|
||||
id=1,
|
||||
image_ref="5",
|
||||
uuid="deadbeef-feed-edee-beef-d0ea7beefedd",
|
||||
|
@ -2783,9 +2783,14 @@ class ServersViewBuilderTest(test.TestCase):
|
|||
fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs,
|
||||
floaters)
|
||||
|
||||
self.uuid = self.instance['uuid']
|
||||
self.uuid = db_inst['uuid']
|
||||
self.view_builder = views.servers.ViewBuilderV3()
|
||||
self.request = fakes.HTTPRequestV3.blank("")
|
||||
self.request.context = context.RequestContext('fake', 'fake')
|
||||
self.instance = fake_instance.fake_instance_obj(
|
||||
self.request.context,
|
||||
expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS,
|
||||
**db_inst)
|
||||
|
||||
def test_get_flavor_valid_instance_type(self):
|
||||
flavor_bookmark = "http://localhost/flavors/1"
|
||||
|
@ -2908,13 +2913,7 @@ class ServersViewBuilderTest(test.TestCase):
|
|||
|
||||
def test_build_server_detail_with_fault(self):
|
||||
self.instance['vm_state'] = vm_states.ERROR
|
||||
self.instance['fault'] = {
|
||||
'code': 404,
|
||||
'instance_uuid': self.uuid,
|
||||
'message': "HTTPNotFound",
|
||||
'details': "Stock details for test",
|
||||
'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
|
||||
}
|
||||
self.instance['fault'] = fake_instance.fake_fault_obj(self.uuid)
|
||||
|
||||
image_bookmark = "http://localhost:9292/images/5"
|
||||
flavor_bookmark = "http://localhost/flavors/1"
|
||||
|
@ -2984,13 +2983,10 @@ class ServersViewBuilderTest(test.TestCase):
|
|||
|
||||
def test_build_server_detail_with_fault_no_details_not_admin(self):
|
||||
self.instance['vm_state'] = vm_states.ERROR
|
||||
self.instance['fault'] = {
|
||||
'code': 500,
|
||||
'instance_uuid': self.uuid,
|
||||
'message': "Error",
|
||||
'details': 'Stock details for test',
|
||||
'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
|
||||
}
|
||||
self.instance['fault'] = fake_instance.fake_fault_obj(
|
||||
self.uuid,
|
||||
code=500,
|
||||
message='Error')
|
||||
|
||||
expected_fault = {"code": 500,
|
||||
"created": "2010-10-10T12:00:00Z",
|
||||
|
@ -3003,13 +2999,10 @@ class ServersViewBuilderTest(test.TestCase):
|
|||
|
||||
def test_build_server_detail_with_fault_admin(self):
|
||||
self.instance['vm_state'] = vm_states.ERROR
|
||||
self.instance['fault'] = {
|
||||
'code': 500,
|
||||
'instance_uuid': self.uuid,
|
||||
'message': "Error",
|
||||
'details': 'Stock details for test',
|
||||
'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
|
||||
}
|
||||
self.instance['fault'] = fake_instance.fake_fault_obj(
|
||||
self.uuid,
|
||||
code=500,
|
||||
message='Error')
|
||||
|
||||
expected_fault = {"code": 500,
|
||||
"created": "2010-10-10T12:00:00Z",
|
||||
|
@ -3023,13 +3016,11 @@ class ServersViewBuilderTest(test.TestCase):
|
|||
|
||||
def test_build_server_detail_with_fault_no_details_admin(self):
|
||||
self.instance['vm_state'] = vm_states.ERROR
|
||||
self.instance['fault'] = {
|
||||
'code': 500,
|
||||
'instance_uuid': self.uuid,
|
||||
'message': "Error",
|
||||
'details': '',
|
||||
'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
|
||||
}
|
||||
self.instance['fault'] = fake_instance.fake_fault_obj(
|
||||
self.uuid,
|
||||
code=500,
|
||||
message='Error',
|
||||
details='')
|
||||
|
||||
expected_fault = {"code": 500,
|
||||
"created": "2010-10-10T12:00:00Z",
|
||||
|
@ -3043,13 +3034,7 @@ class ServersViewBuilderTest(test.TestCase):
|
|||
def test_build_server_detail_with_fault_but_active(self):
|
||||
self.instance['vm_state'] = vm_states.ACTIVE
|
||||
self.instance['progress'] = 100
|
||||
self.instance['fault'] = {
|
||||
'code': 404,
|
||||
'instance_uuid': self.uuid,
|
||||
'message': "HTTPNotFound",
|
||||
'details': "Stock details for test",
|
||||
'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
|
||||
}
|
||||
self.instance['fault'] = fake_instance.fake_fault_obj(self.uuid)
|
||||
|
||||
image_bookmark = "http://localhost:9292/images/5"
|
||||
flavor_bookmark = "http://localhost/flavors/1"
|
||||
|
@ -3255,6 +3240,7 @@ class ServersViewBuilderTest(test.TestCase):
|
|||
|
||||
metadata = []
|
||||
metadata.append(models.InstanceMetadata(key="Open", value="Stack"))
|
||||
metadata = nova_utils.metadata_to_dict(metadata)
|
||||
self.instance['metadata'] = metadata
|
||||
|
||||
image_bookmark = "http://localhost:9292/images/5"
|
||||
|
|
|
@ -3713,7 +3713,7 @@ class ServersViewBuilderTest(test.TestCase):
|
|||
def setUp(self):
|
||||
super(ServersViewBuilderTest, self).setUp()
|
||||
self.flags(use_ipv6=True)
|
||||
self.instance = fakes.stub_instance(
|
||||
db_inst = fakes.stub_instance(
|
||||
id=1,
|
||||
image_ref="5",
|
||||
uuid="deadbeef-feed-edee-beef-d0ea7beefedd",
|
||||
|
@ -3738,9 +3738,14 @@ class ServersViewBuilderTest(test.TestCase):
|
|||
fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs,
|
||||
floaters)
|
||||
|
||||
self.uuid = self.instance['uuid']
|
||||
self.uuid = db_inst['uuid']
|
||||
self.view_builder = views.servers.ViewBuilder()
|
||||
self.request = fakes.HTTPRequest.blank("/v2/fake")
|
||||
self.request.context = context.RequestContext('fake', 'fake')
|
||||
self.instance = fake_instance.fake_instance_obj(
|
||||
self.request.context,
|
||||
expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS,
|
||||
**db_inst)
|
||||
self.self_link = "http://localhost/v2/fake/servers/%s" % self.uuid
|
||||
self.bookmark_link = "http://localhost/fake/servers/%s" % self.uuid
|
||||
self.expected_detailed_server = {
|
||||
|
@ -3842,13 +3847,7 @@ class ServersViewBuilderTest(test.TestCase):
|
|||
|
||||
def test_build_server_detail_with_fault(self):
|
||||
self.instance['vm_state'] = vm_states.ERROR
|
||||
self.instance['fault'] = {
|
||||
'code': 404,
|
||||
'instance_uuid': self.uuid,
|
||||
'message': "HTTPNotFound",
|
||||
'details': "Stock details for test",
|
||||
'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
|
||||
}
|
||||
self.instance['fault'] = fake_instance.fake_fault_obj(self.uuid)
|
||||
|
||||
self.expected_detailed_server["server"]["status"] = "ERROR"
|
||||
self.expected_detailed_server["server"]["fault"] = {
|
||||
|
@ -3866,13 +3865,10 @@ class ServersViewBuilderTest(test.TestCase):
|
|||
|
||||
def test_build_server_detail_with_fault_no_details_not_admin(self):
|
||||
self.instance['vm_state'] = vm_states.ERROR
|
||||
self.instance['fault'] = {
|
||||
'code': 500,
|
||||
'instance_uuid': self.uuid,
|
||||
'message': "Error",
|
||||
'details': 'Stock details for test',
|
||||
'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
|
||||
}
|
||||
self.instance['fault'] = fake_instance.fake_fault_obj(
|
||||
self.uuid,
|
||||
code=500,
|
||||
message='Error')
|
||||
|
||||
expected_fault = {"code": 500,
|
||||
"created": "2010-10-10T12:00:00Z",
|
||||
|
@ -3885,13 +3881,10 @@ class ServersViewBuilderTest(test.TestCase):
|
|||
|
||||
def test_build_server_detail_with_fault_admin(self):
|
||||
self.instance['vm_state'] = vm_states.ERROR
|
||||
self.instance['fault'] = {
|
||||
'code': 500,
|
||||
'instance_uuid': self.uuid,
|
||||
'message': "Error",
|
||||
'details': 'Stock details for test',
|
||||
'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
|
||||
}
|
||||
self.instance['fault'] = fake_instance.fake_fault_obj(
|
||||
self.uuid,
|
||||
code=500,
|
||||
message='Error')
|
||||
|
||||
expected_fault = {"code": 500,
|
||||
"created": "2010-10-10T12:00:00Z",
|
||||
|
@ -3905,13 +3898,11 @@ class ServersViewBuilderTest(test.TestCase):
|
|||
|
||||
def test_build_server_detail_with_fault_no_details_admin(self):
|
||||
self.instance['vm_state'] = vm_states.ERROR
|
||||
self.instance['fault'] = {
|
||||
'code': 500,
|
||||
'instance_uuid': self.uuid,
|
||||
'message': "Error",
|
||||
'details': '',
|
||||
'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
|
||||
}
|
||||
self.instance['fault'] = fake_instance.fake_fault_obj(
|
||||
self.uuid,
|
||||
code=500,
|
||||
message='Error',
|
||||
details='')
|
||||
|
||||
expected_fault = {"code": 500,
|
||||
"created": "2010-10-10T12:00:00Z",
|
||||
|
@ -3925,13 +3916,7 @@ class ServersViewBuilderTest(test.TestCase):
|
|||
def test_build_server_detail_with_fault_but_active(self):
|
||||
self.instance['vm_state'] = vm_states.ACTIVE
|
||||
self.instance['progress'] = 100
|
||||
self.instance['fault'] = {
|
||||
'code': 404,
|
||||
'instance_uuid': self.uuid,
|
||||
'message': "HTTPNotFound",
|
||||
'details': "Stock details for test",
|
||||
'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
|
||||
}
|
||||
self.instance['fault'] = fake_instance.fake_fault_obj(self.uuid)
|
||||
|
||||
output = self.view_builder.show(self.request, self.instance)
|
||||
self.assertFalse('fault' in output['server'])
|
||||
|
@ -3973,6 +3958,7 @@ class ServersViewBuilderTest(test.TestCase):
|
|||
|
||||
metadata = []
|
||||
metadata.append(models.InstanceMetadata(key="Open", value="Stack"))
|
||||
metadata = nova_utils.metadata_to_dict(metadata)
|
||||
self.instance['metadata'] = metadata
|
||||
|
||||
self.expected_detailed_server["server"]["metadata"] = {"Open": "Stack"}
|
||||
|
|
|
@ -16,15 +16,19 @@ import datetime
|
|||
import uuid
|
||||
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova.objects import instance_fault as inst_fault_obj
|
||||
|
||||
|
||||
def fake_db_secgroups(instance, names):
|
||||
secgroups = []
|
||||
for i, name in enumerate(names):
|
||||
group_name = 'secgroup-%i' % i
|
||||
if isinstance(name, dict) and name.get('name'):
|
||||
group_name = name.get('name')
|
||||
secgroups.append(
|
||||
{'id': i,
|
||||
'instance_uuid': instance['uuid'],
|
||||
'name': 'secgroup-%i' % i,
|
||||
'name': group_name,
|
||||
'description': 'Fake secgroup',
|
||||
'user_id': instance['user_id'],
|
||||
'project_id': instance['project_id'],
|
||||
|
@ -65,3 +69,33 @@ def fake_db_instance(**updates):
|
|||
db_instance, db_instance['security_groups'])
|
||||
|
||||
return db_instance
|
||||
|
||||
|
||||
def fake_instance_obj(context, **updates):
|
||||
expected_attrs = updates.pop('expected_attrs', None)
|
||||
return instance_obj.Instance._from_db_object(context,
|
||||
instance_obj.Instance(), fake_db_instance(**updates),
|
||||
expected_attrs=expected_attrs)
|
||||
|
||||
|
||||
def fake_fault_obj(instance_uuid, code=404,
|
||||
message='HTTPNotFound',
|
||||
details='Stock details for test',
|
||||
**updates):
|
||||
fault = {
|
||||
'id': 1,
|
||||
'instance_uuid': instance_uuid,
|
||||
'code': code,
|
||||
'message': message,
|
||||
'details': details,
|
||||
'host': 'fake_host',
|
||||
'deleted': False,
|
||||
'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
|
||||
'updated_at': None,
|
||||
'deleted_at': None
|
||||
}
|
||||
if updates:
|
||||
fault.update(updates)
|
||||
return inst_fault_obj.InstanceFault._from_db_object(
|
||||
inst_fault_obj.InstanceFault(),
|
||||
fault)
|
||||
|
|
Loading…
Reference in New Issue