def test_multi_choice_server(self): uuid = str(utils.gen_uuid()) req = webob.Request.blank('/servers/' + uuid) req.accept = "application/json" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 300) self.assertEqual(res.content_type, "application/json") expected = { "choices": [ { "id": "v2.0", "status": "CURRENT", "links": [ { "href": "http://localhost/v2/servers/" + uuid, "rel": "self", }, ], "media-types": [ { "base": "application/xml", "type": "application/vnd.x7.compute+xml" ";version=2" }, { "base": "application/json", "type": "application/vnd.x7.compute+json" ";version=2" }, ], }, ], } self.assertDictMatch(expected, json.loads(res.body))
def fake_instance_get(context, instance_id): return { "id": 1, "uuid": utils.gen_uuid(), "name": 'fake', "user_id": 'fakeuser', "project_id": '123'}
def create_network(self, tenant_id, network_name, **kwargs): uuid = str(utils.gen_uuid()) self.nets[uuid] = {'net-name': network_name, 'tenant-id': tenant_id, 'ports': {}} return uuid
def fake_instance_create(context, values): """Stubs out the db.instance_create method.""" type_data = INSTANCE_TYPES[values['instance_type']] base_options = { 'name': values['name'], 'id': values['id'], 'uuid': utils.gen_uuid(), 'reservation_id': utils.generate_uid('r'), 'image_ref': values['image_ref'], 'kernel_id': values['kernel_id'], 'ramdisk_id': values['ramdisk_id'], 'vm_state': vm_states.BUILDING, 'task_state': task_states.SCHEDULING, 'user_id': values['user_id'], 'project_id': values['project_id'], 'launch_time': time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()), 'instance_type': values['instance_type'], 'memory_mb': type_data['memory_mb'], 'vcpus': type_data['vcpus'], 'mac_addresses': [{'address': values['mac_address']}], 'local_gb': type_data['local_gb'], } return FakeModel(base_options)
def setUp(self): super(AdminActionsTest, self).setUp() self.stubs.Set(compute.API, 'get', fake_compute_api_get) self.UUID = utils.gen_uuid() self.flags(allow_admin_api=True) for _method in self._methods: self.stubs.Set(compute.API, _method, fake_compute_api)
def fake_instance_get(context, instance_id): return { "id": 1, "uuid": utils.gen_uuid(), "name": 'fake', "user_id": 'fakeuser', "project_id": '123' }
def test_reboot_not_found(self): self.stubs.Set(engine.db, 'instance_get_by_uuid', return_server_by_uuid_not_found) body = dict(reboot=dict(type="HARD")) req = fakes.HTTPRequest.blank(self.url) self.assertRaises(webob.exc.HTTPNotFound, self.controller.action, req, str(utils.gen_uuid()), body)
def upgrade(migrate_engine): meta.bind = migrate_engine instances.create_column(uuid_column) rows = migrate_engine.execute(instances.select()) for row in rows: instance_uuid = str(utils.gen_uuid()) migrate_engine.execute(instances.update()\ .where(instances.c.id == row[0])\ .values(uuid=instance_uuid))
def upgrade(migrate_engine): meta.bind = migrate_engine virtual_interfaces.create_column(uuid_column) rows = migrate_engine.execute(virtual_interfaces.select()) for row in rows: vif_uuid = str(utils.gen_uuid()) migrate_engine.execute(virtual_interfaces.update()\ .where(virtual_interfaces.c.id == row[0])\ .values(uuid=vif_uuid))
def _add_server(self, id=None, uuid=None): if id is None: id = self.max_id + 1 if uuid is None: uuid = str(utils.gen_uuid()) instance = stub_instance(id, uuid=uuid) self.instances_by_id[id] = instance self.ids_by_uuid[uuid] = id if id > self.max_id: self.max_id = id
def setUp(self): super(ServerMetaDataTest, self).setUp() fakes.stub_out_key_pair_funcs(self.stubs) self.stubs.Set(engine.db, "instance_get", return_server) self.stubs.Set(engine.db, "instance_get_by_uuid", return_server_by_uuid) self.stubs.Set(engine.db, "instance_metadata_get", return_server_metadata) self.controller = server_metadata.Controller() self.uuid = str(utils.gen_uuid()) self.url = "/v1.1/fake/servers/%s/metadata" % self.uuid
def setUp(self): super(ConsolesControllerTest, self).setUp() self.flags(verbose=True) self.instance_db = FakeInstanceDB() self.stubs.Set(db, 'instance_get', self.instance_db.return_server_by_id) self.stubs.Set(db, 'instance_get_by_uuid', self.instance_db.return_server_by_uuid) self.uuid = str(utils.gen_uuid()) self.url = '/v2/fake/servers/%s/consoles' % self.uuid self.controller = consoles.Controller()
def setUp(self): super(CreateBackupTests, self).setUp() self.stubs.Set(compute.API, 'get', fake_compute_api_get) self.backup_stubs = fakes.stub_out_compute_api_backup(self.stubs) self.flags(allow_admin_api=True) router = v2.APIRouter() ext_middleware = extensions.ExtensionMiddleware(router) self.app = wsgi.LazySerializationMiddleware(ext_middleware) self.uuid = utils.gen_uuid()
def create_and_attach_port(self, tenant_id, net_id, interface_id, **kwargs): if not self.network_exists(tenant_id, net_id): raise Exception( _("network %(net_id)s does not exist for tenant %(tenant_id)" % locals())) self._confirm_not_attached(interface_id) uuid = str(utils.gen_uuid()) self.nets[net_id]['ports'][uuid] = \ {"port-state": "ACTIVE", "attachment-id": interface_id}
def setUp(self): super(ServerMetaDataTest, self).setUp() fakes.stub_out_key_pair_funcs(self.stubs) self.stubs.Set(engine.db, 'instance_get', return_server) self.stubs.Set(engine.db, 'instance_get_by_uuid', return_server_by_uuid) self.stubs.Set(engine.db, 'instance_metadata_get', return_server_metadata) self.controller = server_metadata.Controller() self.uuid = str(utils.gen_uuid()) self.url = '/v1.1/fake/servers/%s/metadata' % self.uuid
def create(self, context, metadata, data=None): """Store the image data and return the new image id. :raises: Duplicate if the image already exist. """ image_id = str(metadata.get('id', utils.gen_uuid())) metadata['id'] = image_id if image_id in self.images: raise exception.Duplicate() self.images[image_id] = copy.deepcopy(metadata) if data: self._imagedata[image_id] = data.read() return self.images[image_id]
def _add_virtual_interface(self, context, instance_id, network_id): vif = {'instance_id': instance_id, 'network_id': network_id, 'uuid': str(utils.gen_uuid())} # TODO(Vek): Ideally, we would have a VirtualInterface class # that would take care of delegating to whoever it # needs to get information from. We'll look at # this after Trey's refactorings... m_ipam = melange_ipam_lib.get_ipam_lib(self) vif['address'] = m_ipam.create_vif(vif['uuid'], vif['instance_id'], context.project_id) return self.db.virtual_interface_create(context, vif)
def test_instance_fault_create(self): """Ensure we can create an instance fault""" ctxt = context.get_admin_context() uuid = str(utils.gen_uuid()) # Create a fault fault_values = { 'message': 'message', 'details': 'detail', 'instance_uuid': uuid, 'code': 404, } db.instance_fault_create(ctxt, fault_values) # Retrieve the fault to ensure it was successfully added faults = db.instance_fault_get_by_instance_uuids(ctxt, [uuid]) self.assertEqual(404, faults[uuid][0]['code'])
def test_gen_valid_uuid(self): self.assertUUIDLike(str(utils.gen_uuid()), True)
def get_invalid_image(self): return str(utils.gen_uuid())
def instance_get_id_to_uuid_mapping(self, context, ids): # NOTE(jkoelker): This is just here until we can rely on UUIDs mapping = {} for id in ids: mapping[id] = str(utils.gen_uuid()) return mapping