def fake_compute_get_all(*args, **kwargs): inst_list = [ fakes.stub_instance_obj(None, 1, uuid=UUID1, host="host-1", node="node-1", reservation_id="r-1", launch_index=0, kernel_id=UUID4, ramdisk_id=UUID5, display_name="hostname-1", root_device_name="/dev/vda", user_data="userdata", services=fake_services("host-1")), fakes.stub_instance_obj(None, 2, uuid=UUID2, host="host-2", node="node-2", reservation_id="r-2", launch_index=1, kernel_id=UUID4, ramdisk_id=UUID5, display_name="hostname-2", root_device_name="/dev/vda", user_data="userdata", services=fake_services("host-2")), ] return objects.InstanceList(objects=inst_list)
def setUp(self): super(DiskConfigTestCaseV21, self).setUp() fakes.stub_out_nw_api(self) fakes.stub_out_secgroup_api(self) self._set_up_app() self._setup_fake_image_service() ctxt = nova_context.RequestContext( # These values match what is used in fakes.HTTPRequest.blank. user_id='fake_user', project_id=self.project_id) FAKE_INSTANCES = [ fakes.stub_instance_obj(ctxt, uuid=MANUAL_INSTANCE_UUID, auto_disk_config=False), fakes.stub_instance_obj(ctxt, uuid=AUTO_INSTANCE_UUID, auto_disk_config=True) ] def fake_instance_get(_self, context, server_id, *args, **kwargs): for instance in FAKE_INSTANCES: if server_id == instance.uuid: return instance raise exception.InstanceNotFound(instance_id=server_id) self.stub_out('nova.compute.api.API.get', fake_instance_get) self.stub_out('nova.objects.Instance.save', lambda *args, **kwargs: None) def fake_rebuild(*args, **kwargs): pass self.stub_out('nova.compute.api.API.rebuild', fake_rebuild) def fake_instance_create(context, inst_, session=None): inst = fake_instance.fake_db_instance( **{ 'id': 1, 'uuid': AUTO_INSTANCE_UUID, 'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0), 'updated_at': datetime.datetime(2010, 10, 10, 12, 0, 0), 'progress': 0, 'name': 'instance-1', # this is a property 'task_state': '', 'vm_state': '', 'auto_disk_config': inst_['auto_disk_config'], 'security_groups': inst_['security_groups'], 'flavor': objects.Flavor.get_by_name(context, 'm1.small'), }) return inst self.stub_out('nova.db.api.instance_create', fake_instance_create)
def setUp(self): super(DiskConfigTestCaseV21, self).setUp() fakes.stub_out_nw_api(self) fakes.stub_out_secgroup_api(self) self._set_up_app() self._setup_fake_image_service() ctxt = nova_context.RequestContext( # These values match what is used in fakes.HTTPRequest.blank. user_id='fake_user', project_id='fake') FAKE_INSTANCES = [ fakes.stub_instance_obj(ctxt, uuid=MANUAL_INSTANCE_UUID, auto_disk_config=False), fakes.stub_instance_obj(ctxt, uuid=AUTO_INSTANCE_UUID, auto_disk_config=True) ] def fake_instance_get(_self, context, server_id, *args, **kwargs): for instance in FAKE_INSTANCES: if server_id == instance.uuid: return instance raise exception.InstanceNotFound(instance_id=server_id) self.stub_out('nova.compute.api.API.get', fake_instance_get) self.stub_out('nova.objects.Instance.save', lambda *args, **kwargs: None) def fake_rebuild(*args, **kwargs): pass self.stub_out('nova.compute.api.API.rebuild', fake_rebuild) def fake_instance_create(context, inst_, session=None): inst = fake_instance.fake_db_instance(**{ 'id': 1, 'uuid': AUTO_INSTANCE_UUID, 'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0), 'updated_at': datetime.datetime(2010, 10, 10, 12, 0, 0), 'progress': 0, 'name': 'instance-1', # this is a property 'task_state': '', 'vm_state': '', 'auto_disk_config': inst_['auto_disk_config'], 'security_groups': inst_['security_groups'], 'instance_type': objects.Flavor.get_by_name(context, 'm1.small'), }) return inst self.stub_out('nova.db.api.instance_create', fake_instance_create)
def test_detail_servers(self, mock_get_all): # NOTE(danms): Orphan these fakes (no context) so that we # are sure that the API is requesting what it needs without # having to lazy-load. mock_get_all.return_value = objects.InstanceList( objects=[fakes.stub_instance_obj(ctxt=None, id=1), fakes.stub_instance_obj(ctxt=None, id=2)]) req = fakes.HTTPRequest.blank(self.base_url + 'detail') res = req.get_response(self.app) server_dicts = jsonutils.loads(res.body)['servers'] self.assertNotEqual(len(server_dicts), 0) for server_dict in server_dicts: self.assertIn('config_drive', server_dict)
def test_rebuild_server_with_auto_disk_config(self, get_instance_mock): req = fakes.HTTPRequest.blank( '/fake/servers/%s/action' % AUTO_INSTANCE_UUID) req.method = 'POST' req.content_type = 'application/json' instance = fakes.stub_instance_obj( req.environ['nova.context'], project_id=req.environ['nova.context'].project_id, user_id=req.environ['nova.context'].user_id, auto_disk_config=True) get_instance_mock.return_value = instance body = {"rebuild": { 'imageRef': 'cedef40a-ed67-4d10-800e-17455edce175', API_DISK_CONFIG: 'AUTO' }} def rebuild(*args, **kwargs): self.assertIn('auto_disk_config', kwargs) self.assertTrue(kwargs['auto_disk_config']) self.stub_out('nova.compute.api.API.rebuild', rebuild) req.body = jsonutils.dump_as_bytes(body) res = req.get_response(self.app) server_dict = jsonutils.loads(res.body)['server'] self.assertDiskConfig(server_dict, 'AUTO')
def test_rebuild_server_with_auto_disk_config(self, get_instance_mock): req = fakes.HTTPRequest.blank('/%s/servers/%s/action' % (self.project_id, AUTO_INSTANCE_UUID)) req.method = 'POST' req.content_type = 'application/json' instance = fakes.stub_instance_obj( req.environ['nova.context'], project_id=req.environ['nova.context'].project_id, user_id=req.environ['nova.context'].user_id, auto_disk_config=True) get_instance_mock.return_value = instance body = { "rebuild": { 'imageRef': 'cedef40a-ed67-4d10-800e-17455edce175', API_DISK_CONFIG: 'AUTO' } } def rebuild(*args, **kwargs): self.assertIn('auto_disk_config', kwargs) self.assertTrue(kwargs['auto_disk_config']) self.stub_out('nova.compute.api.API.rebuild', rebuild) req.body = jsonutils.dump_as_bytes(body) res = req.get_response(self.app) server_dict = jsonutils.loads(res.body)['server'] self.assertDiskConfig(server_dict, 'AUTO')
def test_detail_servers(self, mock_get_all): # NOTE(danms): Orphan these fakes (no context) so that we # are sure that the API is requesting what it needs without # having to lazy-load. meta = {"preemptible": True} mock_get_all.return_value = objects.InstanceList( objects=[os_api_fakes.stub_instance_obj(ctxt=None, id=1, system_metadata=meta), os_api_fakes.stub_instance_obj(ctxt=None, id=2, system_metadata=meta)]) req = os_api_fakes.HTTPRequest.blank(self.base_url + 'servers/detail') res = req.get_response(self.app) server_dicts = jsonutils.loads(res.body)['servers'] self.assertNotEqual(len(server_dicts), 0) for server_dict in server_dicts: self.assertIn('preemptible', server_dict)
def test_detail_servers(self, mock_get_all): # NOTE(danms): Orphan these fakes (no context) so that we # are sure that the API is requesting what it needs without # having to lazy-load. meta = {"preemptible": True} mock_get_all.return_value = objects.InstanceList(objects=[ os_api_fakes.stub_instance_obj( ctxt=None, id=1, system_metadata=meta), os_api_fakes.stub_instance_obj( ctxt=None, id=2, system_metadata=meta) ]) req = os_api_fakes.HTTPRequest.blank(self.base_url + 'servers/detail') res = req.get_response(self.app) server_dicts = jsonutils.loads(res.body)['servers'] self.assertNotEqual(len(server_dicts), 0) for server_dict in server_dicts: self.assertIn('preemptible', server_dict)
def fake_compute_get_all(*args, **kwargs): inst_list = [ fakes.stub_instance_obj( None, 1, uuid=UUID1, host="host-1", node="node-1", reservation_id="r-1", launch_index=0, kernel_id=UUID4, ramdisk_id=UUID5, display_name="hostname-1", root_device_name="/dev/vda", user_data="userdata"), fakes.stub_instance_obj( None, 2, uuid=UUID2, host="host-2", node="node-2", reservation_id="r-2", launch_index=1, kernel_id=UUID4, ramdisk_id=UUID5, display_name="hostname-2", root_device_name="/dev/vda", user_data="userdata"), ] return objects.InstanceList(objects=inst_list)
def fake_compute_get(*args, **kwargs): return fakes.stub_instance_obj( None, 1, uuid=UUID3, host="host-fake", node="node-fake", reservation_id="r-1", launch_index=0, kernel_id=UUID4, ramdisk_id=UUID5, display_name="hostname-1", root_device_name="/dev/vda", user_data="userdata")
def fake_compute_get(*args, **kwargs): return fakes.stub_instance_obj( None, 1, uuid=UUID3, host="host-fake", node="node-fake", reservation_id="r-1", launch_index=0, kernel_id=UUID4, ramdisk_id=UUID5, display_name="hostname-1", root_device_name="/dev/vda", user_data="userdata", services=fake_services("host-fake"))
def test_create_server_keypair_name_with_leading_trailing_compat_mode( self, mock_create): mock_create.return_value = ( objects.InstanceList(objects=[ fakes.stub_instance_obj(ctxt=None, id=1)]), None) req = fakes.HTTPRequest.blank(self.base_url + '/servers') req.method = 'POST' req.headers["content-type"] = "application/json" req.body = jsonutils.dump_as_bytes({'server': {'name': 'test', 'flavorRef': 1, 'keypair_name': ' abc ', 'imageRef': FAKE_UUID}}) res = req.get_response(self.app_server) self.assertEqual(202, res.status_code)
def _test_update_server_disk_config(self, uuid, disk_config, get_instance_mock): req = fakes.HTTPRequest.blank('/fake/servers/%s' % uuid) req.method = 'PUT' req.content_type = 'application/json' body = {'server': {API_DISK_CONFIG: disk_config}} req.body = jsonutils.dump_as_bytes(body) auto_disk_config = (disk_config == 'AUTO') instance = fakes.stub_instance_obj( req.environ['nova.context'], project_id=req.environ['nova.context'].project_id, user_id=req.environ['nova.context'].user_id, auto_disk_config=auto_disk_config) get_instance_mock.return_value = instance res = req.get_response(self.app) server_dict = jsonutils.loads(res.body)['server'] self.assertDiskConfig(server_dict, disk_config)
def _test_update_server_disk_config(self, uuid, disk_config, get_instance_mock): req = fakes.HTTPRequest.blank( '/fake/servers/%s' % uuid) req.method = 'PUT' req.content_type = 'application/json' body = {'server': {API_DISK_CONFIG: disk_config}} req.body = jsonutils.dump_as_bytes(body) auto_disk_config = (disk_config == 'AUTO') instance = fakes.stub_instance_obj( req.environ['nova.context'], project_id=req.environ['nova.context'].project_id, user_id=req.environ['nova.context'].user_id, auto_disk_config=auto_disk_config) get_instance_mock.return_value = instance res = req.get_response(self.app) server_dict = jsonutils.loads(res.body)['server'] self.assertDiskConfig(server_dict, disk_config)
def _test_rebuild_server_disk_config(self, uuid, disk_config, get_instance_mock): req = fakes.HTTPRequest.blank( '/fake/servers/%s/action' % uuid) req.method = 'POST' req.content_type = 'application/json' auto_disk_config = (disk_config == 'AUTO') instance = fakes.stub_instance_obj( req.environ['nova.context'], project_id=req.environ['nova.context'].project_id, user_id=req.environ['nova.context'].user_id, auto_disk_config=auto_disk_config) get_instance_mock.return_value = instance body = {"rebuild": { 'imageRef': 'cedef40a-ed67-4d10-800e-17455edce175', API_DISK_CONFIG: disk_config }} req.body = jsonutils.dump_as_bytes(body) res = req.get_response(self.app) server_dict = jsonutils.loads(res.body)['server'] self.assertDiskConfig(server_dict, disk_config)
def setUp(self): super(SchedulerHintsTestCaseV21, self).setUp() self.fake_instance = fakes.stub_instance_obj(None, id=1, uuid=UUID) self._set_up_router()
def create(context, *args, **kwargs): self.assertIsNone(kwargs['user_data']) return ([fakes.stub_instance_obj(context)], None)
def fake_compute_get_all(*args, **kwargs): inst_list = [ fakes.stub_instance_obj(None, 1, uuid=UUID1, nw_cache=NW_CACHE), fakes.stub_instance_obj(None, 2, uuid=UUID2, nw_cache=NW_CACHE), ] return objects.InstanceList(objects=inst_list)
def fake_compute_get(*args, **kwargs): inst = fakes.stub_instance_obj(None, 1, uuid=UUID3, nw_cache=NW_CACHE) return inst