Refactor so that instances.instance_type is now instances.instance_type_id.
Update the Openstack API to return the correct flavor_id.
This commit is contained in:
		| @@ -878,7 +878,7 @@ class InstanceTypeCommands(object): | |||||||
|             elif name == "--all": |             elif name == "--all": | ||||||
|                 inst_types = instance_types.get_all_types(True) |                 inst_types = instance_types.get_all_types(True) | ||||||
|             else: |             else: | ||||||
|                 inst_types = instance_types.get_instance_type(name) |                 inst_types = instance_types.get_instance_type_by_name(name) | ||||||
|         except exception.DBError, e: |         except exception.DBError, e: | ||||||
|             _db_error(e) |             _db_error(e) | ||||||
|         if isinstance(inst_types.values()[0], dict): |         if isinstance(inst_types.values()[0], dict): | ||||||
|   | |||||||
| @@ -84,7 +84,8 @@ class ComputeTestCase(test.TestCase): | |||||||
|         inst['launch_time'] = '10' |         inst['launch_time'] = '10' | ||||||
|         inst['user_id'] = self.user.id |         inst['user_id'] = self.user.id | ||||||
|         inst['project_id'] = self.project.id |         inst['project_id'] = self.project.id | ||||||
|         inst['instance_type'] = 'm1.tiny' |         type_id = instance_types.get_instance_type_by_name('m1.tiny')['id'] | ||||||
|  |         inst['instance_type_id'] = type_id | ||||||
|         inst['mac_address'] = utils.generate_mac() |         inst['mac_address'] = utils.generate_mac() | ||||||
|         inst['ami_launch_index'] = 0 |         inst['ami_launch_index'] = 0 | ||||||
|         inst.update(params) |         inst.update(params) | ||||||
| @@ -132,7 +133,7 @@ class ComputeTestCase(test.TestCase): | |||||||
|         cases = [dict(), dict(display_name=None)] |         cases = [dict(), dict(display_name=None)] | ||||||
|         for instance in cases: |         for instance in cases: | ||||||
|             ref = self.compute_api.create(self.context, |             ref = self.compute_api.create(self.context, | ||||||
|                 FLAGS.default_instance_type, None, **instance) |                 instance_types.get_default_instance_type(), None, **instance) | ||||||
|             try: |             try: | ||||||
|                 self.assertNotEqual(ref[0]['display_name'], None) |                 self.assertNotEqual(ref[0]['display_name'], None) | ||||||
|             finally: |             finally: | ||||||
| @@ -143,7 +144,7 @@ class ComputeTestCase(test.TestCase): | |||||||
|         group = self._create_group() |         group = self._create_group() | ||||||
|         ref = self.compute_api.create( |         ref = self.compute_api.create( | ||||||
|                 self.context, |                 self.context, | ||||||
|                 instance_type=FLAGS.default_instance_type, |                 instance_type=instance_types.get_default_instance_type(), | ||||||
|                 image_id=None, |                 image_id=None, | ||||||
|                 security_group=['testgroup']) |                 security_group=['testgroup']) | ||||||
|         try: |         try: | ||||||
| @@ -161,7 +162,7 @@ class ComputeTestCase(test.TestCase): | |||||||
|  |  | ||||||
|         ref = self.compute_api.create( |         ref = self.compute_api.create( | ||||||
|                 self.context, |                 self.context, | ||||||
|                 instance_type=FLAGS.default_instance_type, |                 instance_type=instance_types.get_default_instance_type(), | ||||||
|                 image_id=None, |                 image_id=None, | ||||||
|                 security_group=['testgroup']) |                 security_group=['testgroup']) | ||||||
|         try: |         try: | ||||||
| @@ -177,7 +178,7 @@ class ComputeTestCase(test.TestCase): | |||||||
|  |  | ||||||
|         ref = self.compute_api.create( |         ref = self.compute_api.create( | ||||||
|                 self.context, |                 self.context, | ||||||
|                 instance_type=FLAGS.default_instance_type, |                 instance_type=instance_types.get_default_instance_type(), | ||||||
|                 image_id=None, |                 image_id=None, | ||||||
|                 security_group=['testgroup']) |                 security_group=['testgroup']) | ||||||
|  |  | ||||||
| @@ -359,8 +360,9 @@ class ComputeTestCase(test.TestCase): | |||||||
|         instance_id = self._create_instance() |         instance_id = self._create_instance() | ||||||
|  |  | ||||||
|         self.compute.run_instance(self.context, instance_id) |         self.compute.run_instance(self.context, instance_id) | ||||||
|  |         inst_type = instance_types.get_instance_type_by_name('m1.xlarge') | ||||||
|         db.instance_update(self.context, instance_id, |         db.instance_update(self.context, instance_id, | ||||||
|                 {'instance_type': 'm1.xlarge'}) |                 {'instance_type_id': inst_type['id']}) | ||||||
|  |  | ||||||
|         self.assertRaises(exception.ApiError, self.compute_api.resize, |         self.assertRaises(exception.ApiError, self.compute_api.resize, | ||||||
|                 context, instance_id, 1) |                 context, instance_id, 1) | ||||||
| @@ -380,8 +382,8 @@ class ComputeTestCase(test.TestCase): | |||||||
|         self.compute.terminate_instance(context, instance_id) |         self.compute.terminate_instance(context, instance_id) | ||||||
|  |  | ||||||
|     def test_get_by_flavor_id(self): |     def test_get_by_flavor_id(self): | ||||||
|         type = instance_types.get_by_flavor_id(1) |         type = instance_types.get_instance_type_by_flavor_id(1) | ||||||
|         self.assertEqual(type, 'm1.tiny') |         self.assertEqual(type['name'], 'm1.tiny') | ||||||
|  |  | ||||||
|     def test_resize_same_source_fails(self): |     def test_resize_same_source_fails(self): | ||||||
|         """Ensure instance fails to migrate when source and destination are |         """Ensure instance fails to migrate when source and destination are | ||||||
|   | |||||||
| @@ -62,7 +62,7 @@ class ConsoleTestCase(test.TestCase): | |||||||
|         inst['launch_time'] = '10' |         inst['launch_time'] = '10' | ||||||
|         inst['user_id'] = self.user.id |         inst['user_id'] = self.user.id | ||||||
|         inst['project_id'] = self.project.id |         inst['project_id'] = self.project.id | ||||||
|         inst['instance_type'] = 'm1.tiny' |         inst['instance_type_id'] = 1 | ||||||
|         inst['mac_address'] = utils.generate_mac() |         inst['mac_address'] = utils.generate_mac() | ||||||
|         inst['ami_launch_index'] = 0 |         inst['ami_launch_index'] = 0 | ||||||
|         return db.instance_create(self.context, inst)['id'] |         return db.instance_create(self.context, inst)['id'] | ||||||
|   | |||||||
| @@ -40,7 +40,11 @@ class InstanceTypeTestCase(test.TestCase): | |||||||
|         max_flavorid = session.query(models.InstanceTypes).\ |         max_flavorid = session.query(models.InstanceTypes).\ | ||||||
|                                      order_by("flavorid desc").\ |                                      order_by("flavorid desc").\ | ||||||
|                                      first() |                                      first() | ||||||
|  |         max_id = session.query(models.InstanceTypes).\ | ||||||
|  |                                      order_by("id desc").\ | ||||||
|  |                                      first() | ||||||
|         self.flavorid = max_flavorid["flavorid"] + 1 |         self.flavorid = max_flavorid["flavorid"] + 1 | ||||||
|  |         self.id = max_id["id"] + 1 | ||||||
|         self.name = str(int(time.time())) |         self.name = str(int(time.time())) | ||||||
|  |  | ||||||
|     def test_instance_type_create_then_delete(self): |     def test_instance_type_create_then_delete(self): | ||||||
| @@ -53,7 +57,7 @@ class InstanceTypeTestCase(test.TestCase): | |||||||
|                             'instance type was not created') |                             'instance type was not created') | ||||||
|         instance_types.destroy(self.name) |         instance_types.destroy(self.name) | ||||||
|         self.assertEqual(1, |         self.assertEqual(1, | ||||||
|                     instance_types.get_instance_type(self.name)["deleted"]) |                     instance_types.get_instance_type(self.id)["deleted"]) | ||||||
|         self.assertEqual(starting_inst_list, instance_types.get_all_types()) |         self.assertEqual(starting_inst_list, instance_types.get_all_types()) | ||||||
|         instance_types.purge(self.name) |         instance_types.purge(self.name) | ||||||
|         self.assertEqual(len(starting_inst_list), |         self.assertEqual(len(starting_inst_list), | ||||||
|   | |||||||
| @@ -263,7 +263,7 @@ class SimpleDriverTestCase(test.TestCase): | |||||||
|         inst['reservation_id'] = 'r-fakeres' |         inst['reservation_id'] = 'r-fakeres' | ||||||
|         inst['user_id'] = self.user.id |         inst['user_id'] = self.user.id | ||||||
|         inst['project_id'] = self.project.id |         inst['project_id'] = self.project.id | ||||||
|         inst['instance_type'] = 'm1.tiny' |         inst['instance_type_id'] = '1' | ||||||
|         inst['mac_address'] = utils.generate_mac() |         inst['mac_address'] = utils.generate_mac() | ||||||
|         inst['vcpus'] = kwargs.get('vcpus', 1) |         inst['vcpus'] = kwargs.get('vcpus', 1) | ||||||
|         inst['ami_launch_index'] = 0 |         inst['ami_launch_index'] = 0 | ||||||
|   | |||||||
| @@ -140,7 +140,7 @@ class LibvirtConnTestCase(test.TestCase): | |||||||
|                      'vcpus':         2, |                      'vcpus':         2, | ||||||
|                      'project_id':    'fake', |                      'project_id':    'fake', | ||||||
|                      'bridge':        'br101', |                      'bridge':        'br101', | ||||||
|                      'instance_type': 'm1.small'} |                      'instance_type_id': '5'}  # m1.small | ||||||
|  |  | ||||||
|     def lazy_load_library_exists(self): |     def lazy_load_library_exists(self): | ||||||
|         """check if libvirt is available.""" |         """check if libvirt is available.""" | ||||||
|   | |||||||
| @@ -106,7 +106,7 @@ class VolumeTestCase(test.TestCase): | |||||||
|         inst['launch_time'] = '10' |         inst['launch_time'] = '10' | ||||||
|         inst['user_id'] = 'fake' |         inst['user_id'] = 'fake' | ||||||
|         inst['project_id'] = 'fake' |         inst['project_id'] = 'fake' | ||||||
|         inst['instance_type'] = 'm1.tiny' |         inst['instance_type_id'] = '2'  # m1.tiny | ||||||
|         inst['mac_address'] = utils.generate_mac() |         inst['mac_address'] = utils.generate_mac() | ||||||
|         inst['ami_launch_index'] = 0 |         inst['ami_launch_index'] = 0 | ||||||
|         instance_id = db.instance_create(self.context, inst)['id'] |         instance_id = db.instance_create(self.context, inst)['id'] | ||||||
|   | |||||||
| @@ -80,7 +80,7 @@ class XenAPIVolumeTestCase(test.TestCase): | |||||||
|                   'image_id': 1, |                   'image_id': 1, | ||||||
|                   'kernel_id': 2, |                   'kernel_id': 2, | ||||||
|                   'ramdisk_id': 3, |                   'ramdisk_id': 3, | ||||||
|                   'instance_type': 'm1.large', |                   'instance_type_id': '3',  # m1.large | ||||||
|                   'mac_address': 'aa:bb:cc:dd:ee:ff', |                   'mac_address': 'aa:bb:cc:dd:ee:ff', | ||||||
|                   'os_type': 'linux'} |                   'os_type': 'linux'} | ||||||
|  |  | ||||||
| @@ -328,7 +328,7 @@ class XenAPIVMTestCase(test.TestCase): | |||||||
|         self.assertEquals(self.vm['HVM_boot_policy'], '') |         self.assertEquals(self.vm['HVM_boot_policy'], '') | ||||||
|  |  | ||||||
|     def _test_spawn(self, image_id, kernel_id, ramdisk_id, |     def _test_spawn(self, image_id, kernel_id, ramdisk_id, | ||||||
|                     instance_type="m1.large", os_type="linux", |                     instance_type_id="3", os_type="linux", | ||||||
|                     instance_id=1, check_injection=False): |                     instance_id=1, check_injection=False): | ||||||
|         stubs.stubout_loopingcall_start(self.stubs) |         stubs.stubout_loopingcall_start(self.stubs) | ||||||
|         values = {'id': instance_id, |         values = {'id': instance_id, | ||||||
| @@ -337,7 +337,7 @@ class XenAPIVMTestCase(test.TestCase): | |||||||
|                   'image_id': image_id, |                   'image_id': image_id, | ||||||
|                   'kernel_id': kernel_id, |                   'kernel_id': kernel_id, | ||||||
|                   'ramdisk_id': ramdisk_id, |                   'ramdisk_id': ramdisk_id, | ||||||
|                   'instance_type': instance_type, |                   'instance_type_id': instance_type_id, | ||||||
|                   'mac_address': 'aa:bb:cc:dd:ee:ff', |                   'mac_address': 'aa:bb:cc:dd:ee:ff', | ||||||
|                   'os_type': os_type} |                   'os_type': os_type} | ||||||
|         instance = db.instance_create(self.context, values) |         instance = db.instance_create(self.context, values) | ||||||
| @@ -349,7 +349,7 @@ class XenAPIVMTestCase(test.TestCase): | |||||||
|         FLAGS.xenapi_image_service = 'glance' |         FLAGS.xenapi_image_service = 'glance' | ||||||
|         self.assertRaises(Exception, |         self.assertRaises(Exception, | ||||||
|                           self._test_spawn, |                           self._test_spawn, | ||||||
|                           1, 2, 3, "m1.xlarge") |                           1, 2, 3, "4")  # m1.xlarge | ||||||
|  |  | ||||||
|     def test_spawn_raw_objectstore(self): |     def test_spawn_raw_objectstore(self): | ||||||
|         FLAGS.xenapi_image_service = 'objectstore' |         FLAGS.xenapi_image_service = 'objectstore' | ||||||
| @@ -523,7 +523,7 @@ class XenAPIVMTestCase(test.TestCase): | |||||||
|             'image_id': 1, |             'image_id': 1, | ||||||
|             'kernel_id': 2, |             'kernel_id': 2, | ||||||
|             'ramdisk_id': 3, |             'ramdisk_id': 3, | ||||||
|             'instance_type': 'm1.large', |             'instance_type_id': '3',  # m1.large | ||||||
|             'mac_address': 'aa:bb:cc:dd:ee:ff', |             'mac_address': 'aa:bb:cc:dd:ee:ff', | ||||||
|             'os_type': 'linux'} |             'os_type': 'linux'} | ||||||
|         instance = db.instance_create(self.context, values) |         instance = db.instance_create(self.context, values) | ||||||
| @@ -580,7 +580,7 @@ class XenAPIMigrateInstance(test.TestCase): | |||||||
|                   'kernel_id': None, |                   'kernel_id': None, | ||||||
|                   'ramdisk_id': None, |                   'ramdisk_id': None, | ||||||
|                   'local_gb': 5, |                   'local_gb': 5, | ||||||
|                   'instance_type': 'm1.large', |                   'instance_type_id': '3',  # m1.large | ||||||
|                   'mac_address': 'aa:bb:cc:dd:ee:ff', |                   'mac_address': 'aa:bb:cc:dd:ee:ff', | ||||||
|                   'os_type': 'linux'} |                   'os_type': 'linux'} | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Dan Prince
					Dan Prince