def test_finish_migrate_no_local_storage(self): tiny_type_id = \ instance_types.get_instance_type_by_name('m1.tiny')['id'] self.instance_values.update({'instance_type_id': tiny_type_id, 'local_gb': 0}) instance = db.instance_create(self.context, self.instance_values) def fake_vdi_resize(*args, **kwargs): raise Exception("This shouldn't be called") self.stubs.Set(stubs.FakeSessionForMigrationTests, "VDI_resize_online", fake_vdi_resize) stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) stubs.stubout_loopingcall_start(self.stubs) conn = xenapi_conn.get_connection(False) network_info = [({'bridge': 'fa0', 'id': 0, 'injected': False}, {'broadcast': '192.168.0.255', 'dns': ['192.168.0.1'], 'gateway': '192.168.0.1', 'gateway_v6': 'dead:beef::1', 'ip6s': [{'enabled': '1', 'ip': 'dead:beef::dcad:beff:feef:0', 'netmask': '64'}], 'ips': [{'enabled': '1', 'ip': '192.168.0.100', 'netmask': '255.255.255.0'}], 'label': 'fake', 'mac': 'DE:AD:BE:EF:00:00', 'rxtx_cap': 3})] image_meta = {'id': instance.image_ref, 'disk_format': 'vhd'} conn.finish_migration(self.context, self.migration, instance, dict(base_copy='hurr', cow='durr'), network_info, image_meta, resize_instance=True)
def test_notify_usage_exists(self): """Ensure 'exists' notification generates apropriate usage data.""" instance_id = self._create_instance() instance = db.instance_get(self.context, instance_id) compute_utils.notify_usage_exists(instance) self.assertEquals(len(test_notifier.NOTIFICATIONS), 1) msg = test_notifier.NOTIFICATIONS[0] self.assertEquals(msg['priority'], 'INFO') self.assertEquals(msg['event_type'], 'compute.instance.exists') payload = msg['payload'] self.assertEquals(payload['tenant_id'], self.project_id) self.assertEquals(payload['user_id'], self.user_id) self.assertEquals(payload['instance_id'], instance.uuid) self.assertEquals(payload['instance_type'], 'm1.tiny') type_id = instance_types.get_instance_type_by_name('m1.tiny')['id'] self.assertEquals(str(payload['instance_type_id']), str(type_id)) for attr in ('display_name', 'created_at', 'launched_at', 'state', 'state_description', 'fixed_ips', 'bandwidth', 'audit_period_beginning', 'audit_period_ending'): self.assertTrue(attr in payload, msg="Key %s not in payload" % attr) image_ref_url = "%s/images/1" % utils.generate_tank_url() self.assertEquals(payload['image_ref_url'], image_ref_url) self.compute.terminate_instance(self.context, instance['uuid'])
def create(self, req, body): """Create a new VSA.""" context = req.environ['engine.context'] if not body or 'vsa' not in body: LOG.debug(_("No body provided"), context=context) raise exc.HTTPUnprocessableEntity() vsa = body['vsa'] display_name = vsa.get('displayName') vc_type = vsa.get('vcType', FLAGS.default_vsa_instance_type) try: instance_type = instance_types.get_instance_type_by_name(vc_type) except exception.NotFound: raise exc.HTTPNotFound() LOG.audit(_("Create VSA %(display_name)s of type %(vc_type)s"), locals(), context=context) args = dict(display_name=display_name, display_description=vsa.get('displayDescription'), instance_type=instance_type, storage=vsa.get('storage'), shared=vsa.get('shared'), availability_zone=vsa.get('placement', {}).\ get('AvailabilityZone')) vsa = self.vsa_api.create(context, **args) instances = self._get_instances_by_vsa_id(context, vsa.get('id')) return {'vsa': _vsa_view(context, vsa, True, instances)}
def test_no_injected_files(self): self.flags(image_service='engine.image.fake.FakeImageService') api = compute.API(image_service=self.StubImageService()) inst_type = instance_types.get_instance_type_by_name('m1.small') image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175' api.create(self.context, instance_type=inst_type, image_href=image_uuid)
def _create_instance(self, params={}): """Create a test instance""" inst = {} inst['image_ref'] = 1 inst['reservation_id'] = 'r-fakeres' inst['launch_time'] = '10' inst['user_id'] = self.user_id inst['project_id'] = self.project_id type_id = instance_types.get_instance_type_by_name('m1.tiny')['id'] inst['instance_type_id'] = type_id inst['ami_launch_index'] = 0 inst.update(params) return db.instance_create(self.context, inst)['id']
def test_too_many_metadata_items(self): metadata = {} for i in range(FLAGS.quota_metadata_items + 1): metadata['key%s' % i] = 'value%s' % i inst_type = instance_types.get_instance_type_by_name('m1.small') image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175' self.assertRaises(exception.QuotaError, compute.API().create, self.context, min_count=1, max_count=1, instance_type=inst_type, image_href=image_uuid, metadata=metadata)
def test_too_many_cores(self): instance_ids = [] instance_id = self._create_instance(cores=4) instance_ids.append(instance_id) inst_type = instance_types.get_instance_type_by_name('m1.small') image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175' self.assertRaises(exception.QuotaError, compute.API().create, self.context, min_count=1, max_count=1, instance_type=inst_type, image_href=image_uuid) for instance_id in instance_ids: db.instance_destroy(self.context, instance_id)
def test_instance_type_get_by_None_name_returns_default(self): """Ensure get by name returns default flavor with no name""" default = instance_types.get_default_instance_type() actual = instance_types.get_instance_type_by_name(None) self.assertEqual(default, actual)
def _get_default_vsa_instance_type(self): return instance_types.get_instance_type_by_name( FLAGS.default_vsa_instance_type)