diff options
64 files changed, 469 insertions, 467 deletions
diff --git a/doc/source/devref/compute.rst b/doc/source/devref/compute.rst index 50397cbec..00da777e8 100644 --- a/doc/source/devref/compute.rst +++ b/doc/source/devref/compute.rst @@ -64,10 +64,10 @@ The :mod:`nova.virt.images` Module :show-inheritance: -The :mod:`nova.compute.instance_types` Module +The :mod:`nova.compute.flavors` Module ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: nova.compute.instance_types +.. automodule:: nova.compute.flavors :noindex: :members: :undoc-members: diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 8f4e20798..537f74efa 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -1092,7 +1092,7 @@ class CloudController(object): @staticmethod def _format_instance_type(instance, result): - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) result['instanceType'] = instance_type['name'] @staticmethod @@ -1326,7 +1326,7 @@ class CloudController(object): raise exception.EC2APIError(_('Image must be available')) (instances, resv_id) = self.compute_api.create(context, - instance_type=flavors.get_instance_type_by_name( + instance_type=flavors.get_flavor_by_name( kwargs.get('instance_type', None)), image_href=image_uuid, max_count=int(kwargs.get('max_count', min_count)), diff --git a/nova/api/metadata/base.py b/nova/api/metadata/base.py index d53241308..425e5bf53 100644 --- a/nova/api/metadata/base.py +++ b/nova/api/metadata/base.py @@ -209,7 +209,7 @@ class InstanceMetadata(): meta_data['product-codes'] = [] if self._check_version('2007-08-29', version): - instance_type = flavors.extract_instance_type(self.instance) + instance_type = flavors.extract_flavor(self.instance) meta_data['instance-type'] = instance_type['name'] if False and self._check_version('2007-10-10', version): diff --git a/nova/api/openstack/compute/contrib/flavor_access.py b/nova/api/openstack/compute/contrib/flavor_access.py index 47d7e07e2..bea92d883 100644 --- a/nova/api/openstack/compute/contrib/flavor_access.py +++ b/nova/api/openstack/compute/contrib/flavor_access.py @@ -71,7 +71,7 @@ def _marshall_flavor_access(flavor_id): rval = [] try: access_list = flavors.\ - get_instance_type_access_by_flavor_id(flavor_id) + get_flavor_access_by_flavor_id(flavor_id) except exception.FlavorNotFound: explanation = _("Flavor not found.") raise webob.exc.HTTPNotFound(explanation=explanation) @@ -95,7 +95,7 @@ class FlavorAccessController(object): authorize(context) try: - flavor = flavors.get_instance_type_by_flavor_id(flavor_id) + flavor = flavors.get_flavor_by_flavor_id(flavor_id) except exception.FlavorNotFound: explanation = _("Flavor not found.") raise webob.exc.HTTPNotFound(explanation=explanation) @@ -119,7 +119,7 @@ class FlavorActionController(wsgi.Controller): def _get_flavor_refs(self, context): """Return a dictionary mapping flavorid to flavor_ref.""" - flavor_refs = flavors.get_all_types(context) + flavor_refs = flavors.get_all_flavors(context) rval = {} for name, obj in flavor_refs.iteritems(): rval[obj['flavorid']] = obj @@ -173,7 +173,7 @@ class FlavorActionController(wsgi.Controller): tenant = vals['tenant'] try: - flavors.add_instance_type_access(id, tenant, context) + flavors.add_flavor_access(id, tenant, context) except exception.FlavorAccessExists as err: raise webob.exc.HTTPConflict(explanation=err.format_message()) @@ -190,7 +190,7 @@ class FlavorActionController(wsgi.Controller): tenant = vals['tenant'] try: - flavors.remove_instance_type_access(id, tenant, context) + flavors.remove_flavor_access(id, tenant, context) except exception.FlavorAccessNotFound as e: raise webob.exc.HTTPNotFound(explanation=e.format_message()) diff --git a/nova/api/openstack/compute/contrib/flavormanage.py b/nova/api/openstack/compute/contrib/flavormanage.py index 8dc942f18..43d5d2110 100644 --- a/nova/api/openstack/compute/contrib/flavormanage.py +++ b/nova/api/openstack/compute/contrib/flavormanage.py @@ -40,7 +40,7 @@ class FlavorManageController(wsgi.Controller): authorize(context) try: - flavor = flavors.get_instance_type_by_flavor_id( + flavor = flavors.get_flavor_by_flavor_id( id, read_deleted="no") except exception.NotFound as e: raise webob.exc.HTTPNotFound(explanation=e.format_message()) diff --git a/nova/api/openstack/compute/contrib/simple_tenant_usage.py b/nova/api/openstack/compute/contrib/simple_tenant_usage.py index e5f9b44b7..cee1f6d85 100644 --- a/nova/api/openstack/compute/contrib/simple_tenant_usage.py +++ b/nova/api/openstack/compute/contrib/simple_tenant_usage.py @@ -108,7 +108,7 @@ class SimpleTenantUsageController(object): """Get flavor information from the instance's system_metadata, allowing a fallback to lookup by-id for deleted instances only.""" try: - return flavors.extract_instance_type(instance) + return flavors.extract_flavor(instance) except KeyError: if not instance['deleted']: # Only support the fallback mechanism for deleted instances diff --git a/nova/api/openstack/compute/flavors.py b/nova/api/openstack/compute/flavors.py index 744fe5e93..4da130e9b 100644 --- a/nova/api/openstack/compute/flavors.py +++ b/nova/api/openstack/compute/flavors.py @@ -85,7 +85,7 @@ class Controller(wsgi.Controller): def show(self, req, id): """Return data about the given flavor id.""" try: - flavor = flavors.get_instance_type_by_flavor_id(id) + flavor = flavors.get_flavor_by_flavor_id(id) req.cache_db_flavor(flavor) except exception.NotFound: raise webob.exc.HTTPNotFound() @@ -134,7 +134,7 @@ class Controller(wsgi.Controller): msg = _('Invalid minDisk filter [%s]') % req.params['minDisk'] raise webob.exc.HTTPBadRequest(explanation=msg) - limited_flavors = flavors.get_all_types(context, filters=filters) + limited_flavors = flavors.get_all_flavors(context, filters=filters) flavors_list = limited_flavors.values() sorted_flavors = sorted(flavors_list, key=lambda item: item['flavorid']) diff --git a/nova/api/openstack/compute/plugins/v3/servers.py b/nova/api/openstack/compute/plugins/v3/servers.py index e4dc5db92..b12988010 100644 --- a/nova/api/openstack/compute/plugins/v3/servers.py +++ b/nova/api/openstack/compute/plugins/v3/servers.py @@ -955,8 +955,8 @@ class ServersController(wsgi.Controller): # scheduler_hints = server_dict.get('scheduler_hints', {}) try: - _get_inst_type = flavors.get_instance_type_by_flavor_id - inst_type = _get_inst_type(flavor_id, read_deleted="no") + inst_type = flavors.get_flavor_by_flavor_id( + flavor_id, read_deleted="no") (instances, resv_id) = self.compute_api.create(context, inst_type, diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index a996a843b..67d64127a 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -877,7 +877,7 @@ class Controller(wsgi.Controller): scheduler_hints = server_dict.get('scheduler_hints', {}) try: - _get_inst_type = flavors.get_instance_type_by_flavor_id + _get_inst_type = flavors.get_flavor_by_flavor_id inst_type = _get_inst_type(flavor_id, read_deleted="no") (instances, resv_id) = self.compute_api.create(context, diff --git a/nova/api/openstack/compute/views/servers.py b/nova/api/openstack/compute/views/servers.py index 0cd6afaa1..bf7123ba7 100644 --- a/nova/api/openstack/compute/views/servers.py +++ b/nova/api/openstack/compute/views/servers.py @@ -181,7 +181,7 @@ class ViewBuilder(common.ViewBuilder): return "" def _get_flavor(self, request, instance): - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) if not instance_type: LOG.warn(_("Instance has had its instance_type removed " "from the DB"), instance=instance) diff --git a/nova/cloudpipe/pipelib.py b/nova/cloudpipe/pipelib.py index 0727528c2..db79d4d42 100644 --- a/nova/cloudpipe/pipelib.py +++ b/nova/cloudpipe/pipelib.py @@ -43,9 +43,11 @@ cloudpipe_opts = [ cfg.StrOpt('vpn_image_id', default='0', help='image id used when starting up a cloudpipe vpn server'), - cfg.StrOpt('vpn_instance_type', + cfg.StrOpt('vpn_flavor', + # Deprecated in Havana + deprecated_name='vpn_instance_type', default='m1.tiny', - help=_('Instance type for vpn instances')), + help=_('Flavor for vpn instances')), cfg.StrOpt('boot_script_template', default=paths.basedir_def('nova/cloudpipe/bootscript.template'), help=_('Template for cloudpipe instance boot script')), @@ -126,8 +128,8 @@ class CloudPipe(object): LOG.debug(_("Launching VPN for %s") % (context.project_id)) key_name = self.setup_key_pair(context) group_name = self.setup_security_group(context) - instance_type = flavors.get_instance_type_by_name( - CONF.vpn_instance_type) + instance_type = flavors.get_flavor_by_name( + CONF.vpn_flavor) instance_name = '%s%s' % (context.project_id, CONF.vpn_key_suffix) user_data = self.get_encoded_zip(context.project_id) return self.compute_api.create(context, diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index 599b9a299..1dc57aea0 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -617,7 +617,7 @@ class VmCommands(object): context.get_admin_context(), host) for instance in instances: - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) print ("%-10s %-15s %-10s %-10s %-26s %-9s %-9s %-9s" " %-10s %-10s %-10s %-5d" % (instance['display_name'], instance['host'], @@ -928,9 +928,9 @@ class InstanceTypeCommands(object): """Lists all active or specific instance types / flavors.""" try: if name is None: - inst_types = flavors.get_all_types() + inst_types = flavors.get_all_flavors() else: - inst_types = flavors.get_instance_type_by_name(name) + inst_types = flavors.get_flavor_by_name(name) except db_exc.DBError as e: _db_error(e) if isinstance(inst_types.values()[0], dict): @@ -946,7 +946,7 @@ class InstanceTypeCommands(object): """Add key/value pair to specified instance type's extra_specs.""" try: try: - inst_type = flavors.get_instance_type_by_name(name) + inst_type = flavors.get_flavor_by_name(name) except exception.InstanceTypeNotFoundByName as e: print e return(2) @@ -968,7 +968,7 @@ class InstanceTypeCommands(object): """Delete the specified extra spec for instance type.""" try: try: - inst_type = flavors.get_instance_type_by_name(name) + inst_type = flavors.get_flavor_by_name(name) except exception.InstanceTypeNotFoundByName as e: print e return(2) diff --git a/nova/compute/api.py b/nova/compute/api.py index 65142aef0..145a0ee27 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -599,7 +599,7 @@ class API(base.Base): root_device_name = block_device.properties_root_device_name( image.get('properties', {})) - system_metadata = flavors.save_instance_type_info( + system_metadata = flavors.save_flavor_info( dict(), instance_type) base_options = { @@ -731,7 +731,7 @@ class API(base.Base): max_count = max_count or min_count block_device_mapping = block_device_mapping or [] if not instance_type: - instance_type = flavors.get_default_instance_type() + instance_type = flavors.get_default_flavor() if image_href: image_id, image = self._get_image(context, image_href) @@ -1244,9 +1244,8 @@ class API(base.Base): new_instance['instance_type_id'] == migration_ref['new_instance_type_id']): old_inst_type_id = migration_ref['old_instance_type_id'] - get_inst_type_by_id = flavors.get_instance_type try: - old_inst_type = get_inst_type_by_id(old_inst_type_id) + old_inst_type = flavors.get_flavor(old_inst_type_id) except exception.InstanceTypeNotFound: LOG.warning(_("instance type %(old_inst_type_id)d " "not found") % locals()) @@ -1340,7 +1339,7 @@ class API(base.Base): def restore(self, context, instance): """Restore a previously deleted (but not reclaimed) instance.""" # Reserve quotas - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) num_instances, quota_reservations = self._check_num_instances_quota( context, instance_type, 1, 1) @@ -1420,7 +1419,7 @@ class API(base.Base): #NOTE(bcwaldon): this doesn't really belong in this class def get_instance_type(self, context, instance_type_id): """Get an instance type by instance type id.""" - return flavors.get_instance_type(instance_type_id) + return flavors.get_flavor(instance_type_id) def get(self, context, instance_id): """Get a single instance with the given instance_id.""" @@ -1477,7 +1476,7 @@ class API(base.Base): filters = {} def _remap_flavor_filter(flavor_id): - instance_type = flavors.get_instance_type_by_flavor_id( + instance_type = flavors.get_flavor_by_flavor_id( flavor_id) filters['instance_type_id'] = instance_type['id'] @@ -1756,7 +1755,7 @@ class API(base.Base): #disk format of vhd is non-shrinkable if orig_image.get('disk_format') == 'vhd': - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) min_disk = instance_type['root_gb'] else: #set new image values to the original image values @@ -1834,7 +1833,7 @@ class API(base.Base): orig_image_ref = instance['image_ref'] or '' files_to_inject = kwargs.pop('files_to_inject', []) metadata = kwargs.get('metadata', {}) - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) image_id, image = self._get_image(context, image_href) @@ -2003,9 +2002,9 @@ class API(base.Base): Calculate deltas required to reverse a prior upsizing quota adjustment. """ - old_instance_type = flavors.get_instance_type( + old_instance_type = flavors.get_flavor( migration_ref['old_instance_type_id']) - new_instance_type = flavors.get_instance_type( + new_instance_type = flavors.get_flavor( migration_ref['new_instance_type_id']) return API._resize_quota_delta(context, new_instance_type, @@ -2016,9 +2015,9 @@ class API(base.Base): """ Calculate deltas required to adjust quota for an instance downsize. """ - old_instance_type = flavors.extract_instance_type(instance, + old_instance_type = flavors.extract_flavor(instance, 'old_') - new_instance_type = flavors.extract_instance_type(instance, + new_instance_type = flavors.extract_flavor(instance, 'new_') return API._resize_quota_delta(context, new_instance_type, old_instance_type, 1, -1) @@ -2038,7 +2037,7 @@ class API(base.Base): the original flavor_id. If flavor_id is not None, the instance should be migrated to a new host and resized to the new flavor_id. """ - current_instance_type = flavors.extract_instance_type(instance) + current_instance_type = flavors.extract_flavor(instance) # If flavor_id is not provided, only migrate the instance. if not flavor_id: @@ -2046,7 +2045,7 @@ class API(base.Base): instance=instance) new_instance_type = current_instance_type else: - new_instance_type = flavors.get_instance_type_by_flavor_id( + new_instance_type = flavors.get_flavor_by_flavor_id( flavor_id, read_deleted="no") current_instance_type_name = current_instance_type['name'] diff --git a/nova/compute/cells_api.py b/nova/compute/cells_api.py index 5ac5dd475..6f1e12480 100644 --- a/nova/compute/cells_api.py +++ b/nova/compute/cells_api.py @@ -350,12 +350,12 @@ class ComputeCellsAPI(compute_api.API): # specified flavor_id is valid and exists. We'll need to load # it again, but that should be safe. - old_instance_type = flavors.extract_instance_type(instance) + old_instance_type = flavors.extract_flavor(instance) if not flavor_id: new_instance_type = old_instance_type else: - new_instance_type = flavors.get_instance_type_by_flavor_id( + new_instance_type = flavors.get_flavor_by_flavor_id( flavor_id, read_deleted="no") # NOTE(johannes): Later, when the resize is confirmed or reverted, diff --git a/nova/compute/flavors.py b/nova/compute/flavors.py index 7177f26bd..b58f1f05d 100644 --- a/nova/compute/flavors.py +++ b/nova/compute/flavors.py @@ -33,14 +33,16 @@ from nova.openstack.common import log as logging from nova.openstack.common import strutils from nova import utils -instance_type_opts = [ - cfg.StrOpt('default_instance_type', +flavor_opts = [ + cfg.StrOpt('default_flavor', + # Deprecated in Havana + deprecated_name='default_instance_type', default='m1.small', - help='default instance type to use, testing only'), + help='default flavor to use, testing only'), ] CONF = cfg.CONF -CONF.register_opts(instance_type_opts) +CONF.register_opts(flavor_opts) LOG = logging.getLogger(__name__) @@ -52,7 +54,7 @@ def _int_or_none(val): return int(val) -system_metadata_instance_type_props = { +system_metadata_flavor_props = { 'id': int, 'name': str, 'memory_mb': int, @@ -68,7 +70,7 @@ system_metadata_instance_type_props = { def create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None, swap=0, rxtx_factor=1.0, is_public=True): - """Creates instance types.""" + """Creates flavors.""" if not flavorid: flavorid = uuid.uuid4() @@ -137,7 +139,7 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None, def destroy(name): - """Marks instance types as deleted.""" + """Marks flavor as deleted.""" try: assert name is not None db.instance_type_destroy(context.get_admin_context(), name) @@ -146,10 +148,10 @@ def destroy(name): raise exception.InstanceTypeNotFoundByName(instance_type_name=name) -def get_all_types(ctxt=None, inactive=False, filters=None): +def get_all_flavors(ctxt=None, inactive=False, filters=None): """Get all non-deleted flavors. - Pass true as argument if you want deleted instance types returned also. + Pass true as argument if you want deleted flavors returned also. """ if ctxt is None: ctxt = context.get_admin_context() @@ -162,19 +164,17 @@ def get_all_types(ctxt=None, inactive=False, filters=None): inst_type_dict[inst_type['name']] = inst_type return inst_type_dict -get_all_flavors = get_all_types +def get_default_flavor(): + """Get the default flavor.""" + name = CONF.default_flavor + return get_flavor_by_name(name) -def get_default_instance_type(): - """Get the default instance type.""" - name = CONF.default_instance_type - return get_instance_type_by_name(name) - -def get_instance_type(instance_type_id, ctxt=None, inactive=False): - """Retrieves single instance type by id.""" +def get_flavor(instance_type_id, ctxt=None, inactive=False): + """Retrieves single flavor by id.""" if instance_type_id is None: - return get_default_instance_type() + return get_default_flavor() if ctxt is None: ctxt = context.get_admin_context() @@ -185,10 +185,10 @@ def get_instance_type(instance_type_id, ctxt=None, inactive=False): return db.instance_type_get(ctxt, instance_type_id) -def get_instance_type_by_name(name, ctxt=None): - """Retrieves single instance type by name.""" +def get_flavor_by_name(name, ctxt=None): + """Retrieves single flavor by name.""" if name is None: - return get_default_instance_type() + return get_default_flavor() if ctxt is None: ctxt = context.get_admin_context() @@ -198,8 +198,8 @@ def get_instance_type_by_name(name, ctxt=None): # TODO(termie): flavor-specific code should probably be in the API that uses # flavors. -def get_instance_type_by_flavor_id(flavorid, ctxt=None, read_deleted="yes"): - """Retrieve instance type by flavorid. +def get_flavor_by_flavor_id(flavorid, ctxt=None, read_deleted="yes"): + """Retrieve flavor by flavorid. :raises: FlavorNotFound """ @@ -209,43 +209,43 @@ def get_instance_type_by_flavor_id(flavorid, ctxt=None, read_deleted="yes"): return db.instance_type_get_by_flavor_id(ctxt, flavorid) -def get_instance_type_access_by_flavor_id(flavorid, ctxt=None): - """Retrieve instance type access list by flavor id.""" +def get_flavor_access_by_flavor_id(flavorid, ctxt=None): + """Retrieve flavor access list by flavor id.""" if ctxt is None: ctxt = context.get_admin_context() return db.instance_type_access_get_by_flavor_id(ctxt, flavorid) -def add_instance_type_access(flavorid, projectid, ctxt=None): - """Add instance type access for project.""" +def add_flavor_access(flavorid, projectid, ctxt=None): + """Add flavor access for project.""" if ctxt is None: ctxt = context.get_admin_context() return db.instance_type_access_add(ctxt, flavorid, projectid) -def remove_instance_type_access(flavorid, projectid, ctxt=None): - """Remove instance type access for project.""" +def remove_flavor_access(flavorid, projectid, ctxt=None): + """Remove flavor access for project.""" if ctxt is None: ctxt = context.get_admin_context() return db.instance_type_access_remove(ctxt, flavorid, projectid) -def extract_instance_type(instance, prefix=''): +def extract_flavor(instance, prefix=''): """Create an InstanceType-like object from instance's system_metadata information.""" instance_type = {} sys_meta = utils.instance_sys_meta(instance) - for key, type_fn in system_metadata_instance_type_props.items(): + for key, type_fn in system_metadata_flavor_props.items(): type_key = '%sinstance_type_%s' % (prefix, key) instance_type[key] = type_fn(sys_meta[type_key]) return instance_type -def save_instance_type_info(metadata, instance_type, prefix=''): +def save_flavor_info(metadata, instance_type, prefix=''): """Save properties from instance_type into instance's system_metadata, in the format of: @@ -255,17 +255,17 @@ def save_instance_type_info(metadata, instance_type, prefix=''): as stash information about another instance_type for later use (such as during resize).""" - for key in system_metadata_instance_type_props.keys(): + for key in system_metadata_flavor_props.keys(): to_key = '%sinstance_type_%s' % (prefix, key) metadata[to_key] = instance_type[key] return metadata -def delete_instance_type_info(metadata, *prefixes): - """Delete instance_type information from instance's system_metadata +def delete_flavor_info(metadata, *prefixes): + """Delete flavor instance_type information from instance's system_metadata by prefix.""" - for key in system_metadata_instance_type_props.keys(): + for key in system_metadata_flavor_props.keys(): for prefix in prefixes: to_key = '%sinstance_type_%s' % (prefix, key) del metadata[to_key] diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 42f8029a5..5c697993b 100755 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -2130,15 +2130,15 @@ class ComputeManager(manager.SchedulerDependentManager): """ sys_meta = utils.metadata_to_dict(instance['system_metadata']) if restore_old: - instance_type = flavors.extract_instance_type(instance, + instance_type = flavors.extract_flavor(instance, 'old_') - sys_meta = flavors.save_instance_type_info(sys_meta, + sys_meta = flavors.save_flavor_info(sys_meta, instance_type) else: - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) - flavors.delete_instance_type_info(sys_meta, 'old_') - flavors.delete_instance_type_info(sys_meta, 'new_') + flavors.delete_flavor_info(sys_meta, 'old_') + flavors.delete_flavor_info(sys_meta, 'new_') return sys_meta, instance_type @@ -2384,7 +2384,7 @@ class ComputeManager(manager.SchedulerDependentManager): # NOTE(danms): Stash the new instance_type to avoid having to # look it up in the database later sys_meta = utils.metadata_to_dict(instance['system_metadata']) - flavors.save_instance_type_info(sys_meta, instance_type, + flavors.save_flavor_info(sys_meta, instance_type, prefix='new_') # NOTE(mriedem): Stash the old vm_state so we can set the # resized/reverted instance back to the same state later. @@ -2555,19 +2555,19 @@ class ComputeManager(manager.SchedulerDependentManager): resize_instance = False old_instance_type_id = migration['old_instance_type_id'] new_instance_type_id = migration['new_instance_type_id'] - old_instance_type = flavors.extract_instance_type(instance) + old_instance_type = flavors.extract_flavor(instance) sys_meta = utils.metadata_to_dict(instance['system_metadata']) # NOTE(mriedem): Get the old_vm_state so we know if we should # power on the instance. If old_vm_sate is not set we need to default # to ACTIVE for backwards compatibility old_vm_state = sys_meta.get('old_vm_state', vm_states.ACTIVE) - flavors.save_instance_type_info(sys_meta, - old_instance_type, - prefix='old_') + flavors.save_flavor_info(sys_meta, + old_instance_type, + prefix='old_') if old_instance_type_id != new_instance_type_id: - instance_type = flavors.extract_instance_type(instance, + instance_type = flavors.extract_flavor(instance, prefix='new_') - flavors.save_instance_type_info(sys_meta, instance_type) + flavors.save_flavor_info(sys_meta, instance_type) instance = self._instance_update( context, diff --git a/nova/compute/resource_tracker.py b/nova/compute/resource_tracker.py index ef91063b4..43fd80c43 100644 --- a/nova/compute/resource_tracker.py +++ b/nova/compute/resource_tracker.py @@ -160,7 +160,7 @@ class ResourceTracker(object): be done while the COMPUTE_RESOURCES_SEMAPHORE is held so the resource claim will not be lost if the audit process starts. """ - old_instance_type = flavors.extract_instance_type(instance) + old_instance_type = flavors.extract_flavor(instance) return self.conductor_api.migration_create(context, instance, {'dest_compute': self.host, @@ -580,7 +580,7 @@ class ResourceTracker(object): instance_type_id = instance['instance_type_id'] try: - return flavors.extract_instance_type(instance, prefix) + return flavors.extract_flavor(instance, prefix) except KeyError: return self.conductor_api.instance_type_get(context, instance_type_id) diff --git a/nova/compute/utils.py b/nova/compute/utils.py index 1ce115b20..561c3308a 100644 --- a/nova/compute/utils.py +++ b/nova/compute/utils.py @@ -151,7 +151,7 @@ def get_device_name_for_instance(context, instance, bdms, device): # NOTE(vish): remove this when xenapi is properly setting # default_ephemeral_device and default_swap_device if driver.compute_driver_matches('xenapi.XenAPIDriver'): - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) if instance_type['ephemeral_gb']: used_letters.add('b') diff --git a/nova/network/api.py b/nova/network/api.py index 1654bb32c..d482c51ab 100644 --- a/nova/network/api.py +++ b/nova/network/api.py @@ -279,7 +279,7 @@ class API(base.Base): # this is called from compute.manager which shouldn't # have db access so we do it on the other side of the # rpc. - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) args = {} args['vpn'] = vpn args['requested_networks'] = requested_networks @@ -329,7 +329,7 @@ class API(base.Base): def add_fixed_ip_to_instance(self, context, instance, network_id, conductor_api=None): """Adds a fixed ip to instance from specified network.""" - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) args = {'instance_id': instance['uuid'], 'rxtx_factor': instance_type['rxtx_factor'], 'host': instance['host'], @@ -342,7 +342,7 @@ class API(base.Base): conductor_api=None): """Removes a fixed ip from instance from specified network.""" - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) args = {'instance_id': instance['uuid'], 'rxtx_factor': instance_type['rxtx_factor'], 'host': instance['host'], @@ -390,7 +390,7 @@ class API(base.Base): def _get_instance_nw_info(self, context, instance): """Returns all network info related to an instance.""" - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) args = {'instance_id': instance['uuid'], 'rxtx_factor': instance_type['rxtx_factor'], 'host': instance['host'], @@ -507,7 +507,7 @@ class API(base.Base): @wrap_check_policy def migrate_instance_start(self, context, instance, migration): """Start to migrate the network of an instance.""" - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) args = dict( instance_uuid=instance['uuid'], rxtx_factor=instance_type['rxtx_factor'], @@ -527,7 +527,7 @@ class API(base.Base): @wrap_check_policy def migrate_instance_finish(self, context, instance, migration): """Finish migrating the network of an instance.""" - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) args = dict( instance_uuid=instance['uuid'], rxtx_factor=instance_type['rxtx_factor'], diff --git a/nova/network/quantumv2/api.py b/nova/network/quantumv2/api.py index c577ebce8..3721d53b1 100644 --- a/nova/network/quantumv2/api.py +++ b/nova/network/quantumv2/api.py @@ -311,7 +311,7 @@ class API(base.Base): """ self._refresh_quantum_extensions_cache() if 'nvp-qos' in self.extensions: - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) rxtx_factor = instance_type.get('rxtx_factor') port_req_body['port']['rxtx_factor'] = rxtx_factor diff --git a/nova/notifications.py b/nova/notifications.py index 3800632c5..d000c4083 100644 --- a/nova/notifications.py +++ b/nova/notifications.py @@ -284,7 +284,7 @@ def info_from_instance(context, instance_ref, network_info, image_ref_url = glance.generate_image_url(instance_ref['image_ref']) - instance_type = flavors.extract_instance_type(instance_ref) + instance_type = flavors.extract_flavor(instance_ref) instance_type_name = instance_type.get('name', '') if system_metadata is None: diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py index 4ad6b8513..5fed1e397 100644 --- a/nova/scheduler/driver.py +++ b/nova/scheduler/driver.py @@ -257,7 +257,7 @@ class Scheduler(object): # If dest is not specified, have scheduler pick one. if dest is None: - instance_type = flavors.extract_instance_type(instance_ref) + instance_type = flavors.extract_flavor(instance_ref) if not instance_ref['image_ref']: image = None else: diff --git a/nova/scheduler/filter_scheduler.py b/nova/scheduler/filter_scheduler.py index 186cecc14..08cb6a20e 100644 --- a/nova/scheduler/filter_scheduler.py +++ b/nova/scheduler/filter_scheduler.py @@ -392,7 +392,7 @@ class FilterScheduler(driver.Scheduler): host_state = self.host_manager.host_state_cls(dest, node) host_state.update_from_compute_node(compute) - instance_type = flavors.extract_instance_type(instance_ref) + instance_type = flavors.extract_flavor(instance_ref) filter_properties = {'instance_type': instance_type} hosts = self.host_manager.get_filtered_hosts([host_state], diff --git a/nova/scheduler/utils.py b/nova/scheduler/utils.py index 315f9df2b..d17ab89b2 100644 --- a/nova/scheduler/utils.py +++ b/nova/scheduler/utils.py @@ -28,6 +28,6 @@ def build_request_spec(image, instances): request_spec = { 'image': image, 'instance_properties': instance, - 'instance_type': flavors.extract_instance_type(instance), + 'instance_type': flavors.extract_flavor(instance), 'instance_uuids': [inst['uuid'] for inst in instances]} return request_spec diff --git a/nova/tests/api/ec2/test_cinder_cloud.py b/nova/tests/api/ec2/test_cinder_cloud.py index a307eaa2f..4b578a787 100644 --- a/nova/tests/api/ec2/test_cinder_cloud.py +++ b/nova/tests/api/ec2/test_cinder_cloud.py @@ -41,7 +41,7 @@ from nova import volume CONF = cfg.CONF CONF.import_opt('compute_driver', 'nova.virt.driver') -CONF.import_opt('default_instance_type', 'nova.compute.flavors') +CONF.import_opt('default_flavor', 'nova.compute.flavors') CONF.import_opt('use_ipv6', 'nova.netconf') @@ -415,8 +415,8 @@ class CinderCloudTestCase(test.TestCase): def _setUpBlockDeviceMapping(self): image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175' - sys_meta = flavors.save_instance_type_info( - {}, flavors.get_instance_type(1)) + sys_meta = flavors.save_flavor_info( + {}, flavors.get_flavor(1)) inst1 = db.instance_create(self.context, {'image_ref': image_uuid, 'instance_type_id': 1, @@ -758,7 +758,7 @@ class CinderCloudTestCase(test.TestCase): self._restart_compute_service(periodic_interval_max=0.3) kwargs = {'image_id': 'ami-1', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1, 'block_device_mapping': [{'device_name': '/dev/sdb', 'volume_id': vol1_uuid, @@ -840,7 +840,7 @@ class CinderCloudTestCase(test.TestCase): # enforce periodic tasks run in short time to avoid wait for 60s. self._restart_compute_service(periodic_interval_max=0.3) kwargs = {'image_id': 'ami-1', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1, 'block_device_mapping': [{'device_name': '/dev/sdb', 'volume_id': vol1_uuid, @@ -921,7 +921,7 @@ class CinderCloudTestCase(test.TestCase): snap2_uuid = ec2utils.ec2_snap_id_to_uuid(snap2['snapshotId']) kwargs = {'image_id': 'ami-1', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1, 'block_device_mapping': [{'device_name': '/dev/vdb', 'snapshot_id': snap1_uuid, @@ -981,7 +981,7 @@ class CinderCloudTestCase(test.TestCase): create_volumes_and_snapshots=True) kwargs = {'image_id': 'ami-1', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1} ec2_instance_id = self._run_instance(**kwargs) diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py index 8a10712cb..b4cb24404 100644 --- a/nova/tests/api/ec2/test_cloud.py +++ b/nova/tests/api/ec2/test_cloud.py @@ -59,7 +59,7 @@ from nova import volume CONF = cfg.CONF CONF.import_opt('compute_driver', 'nova.virt.driver') -CONF.import_opt('default_instance_type', 'nova.compute.flavors') +CONF.import_opt('default_flavor', 'nova.compute.flavors') CONF.import_opt('use_ipv6', 'nova.netconf') LOG = logging.getLogger(__name__) @@ -765,8 +765,8 @@ class CloudTestCase(test.TestCase): self._stub_instance_get_with_fixed_ips('get') image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175' - sys_meta = flavors.save_instance_type_info( - {}, flavors.get_instance_type(1)) + sys_meta = flavors.save_flavor_info( + {}, flavors.get_flavor(1)) inst1 = db.instance_create(self.context, {'reservation_id': 'a', 'image_ref': image_uuid, 'instance_type_id': 1, @@ -871,8 +871,8 @@ class CloudTestCase(test.TestCase): fake_change_instance_metadata) # Create some test images - sys_meta = flavors.save_instance_type_info( - {}, flavors.get_instance_type(1)) + sys_meta = flavors.save_flavor_info( + {}, flavors.get_flavor(1)) image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175' inst1_kwargs = { 'reservation_id': 'a', @@ -1043,8 +1043,8 @@ class CloudTestCase(test.TestCase): self._stub_instance_get_with_fixed_ips('get') image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175' - sys_meta = flavors.save_instance_type_info( - {}, flavors.get_instance_type(1)) + sys_meta = flavors.save_flavor_info( + {}, flavors.get_flavor(1)) inst_base = { 'reservation_id': 'a', 'image_ref': image_uuid, @@ -1098,8 +1098,8 @@ class CloudTestCase(test.TestCase): def test_instance_state(expected_code, expected_name, power_state_, vm_state_, values=None): image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175' - sys_meta = flavors.save_instance_type_info( - {}, flavors.get_instance_type(1)) + sys_meta = flavors.save_flavor_info( + {}, flavors.get_flavor(1)) values = values or {} values.update({'image_ref': image_uuid, 'instance_type_id': 1, 'power_state': power_state_, 'vm_state': vm_state_, @@ -1133,8 +1133,8 @@ class CloudTestCase(test.TestCase): self._stub_instance_get_with_fixed_ips('get') image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175' - sys_meta = flavors.save_instance_type_info( - {}, flavors.get_instance_type(1)) + sys_meta = flavors.save_flavor_info( + {}, flavors.get_flavor(1)) inst1 = db.instance_create(self.context, {'reservation_id': 'a', 'image_ref': image_uuid, 'instance_type_id': 1, @@ -1160,8 +1160,8 @@ class CloudTestCase(test.TestCase): def test_describe_instances_deleted(self): image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175' - sys_meta = flavors.save_instance_type_info( - {}, flavors.get_instance_type(1)) + sys_meta = flavors.save_flavor_info( + {}, flavors.get_flavor(1)) args1 = {'reservation_id': 'a', 'image_ref': image_uuid, 'instance_type_id': 1, @@ -1185,8 +1185,8 @@ class CloudTestCase(test.TestCase): def test_describe_instances_with_image_deleted(self): image_uuid = 'aebef54a-ed67-4d10-912f-14455edce176' - sys_meta = flavors.save_instance_type_info( - {}, flavors.get_instance_type(1)) + sys_meta = flavors.save_flavor_info( + {}, flavors.get_flavor(1)) args1 = {'reservation_id': 'a', 'image_ref': image_uuid, 'instance_type_id': 1, @@ -1619,7 +1619,7 @@ class CloudTestCase(test.TestCase): def test_get_password_data(self): instance_id = self._run_instance( image_id='ami-1', - instance_type=CONF.default_instance_type, + instance_type=CONF.default_flavor, max_count=1) self.stubs.Set(password, 'extract_password', lambda i: 'fakepass') output = self.cloud.get_password_data(context=self.context, @@ -1630,7 +1630,7 @@ class CloudTestCase(test.TestCase): def test_console_output(self): instance_id = self._run_instance( image_id='ami-1', - instance_type=CONF.default_instance_type, + instance_type=CONF.default_flavor, max_count=1) output = self.cloud.get_console_output(context=self.context, instance_id=[instance_id]) @@ -1743,7 +1743,7 @@ class CloudTestCase(test.TestCase): def test_run_instances(self): kwargs = {'image_id': 'ami-00000001', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1} run_instances = self.cloud.run_instances @@ -1775,7 +1775,7 @@ class CloudTestCase(test.TestCase): def test_run_instances_availability_zone(self): kwargs = {'image_id': 'ami-00000001', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1, 'placement': {'availability_zone': 'fake'}, } @@ -1811,7 +1811,7 @@ class CloudTestCase(test.TestCase): def test_run_instances_image_state_none(self): kwargs = {'image_id': 'ami-00000001', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1} run_instances = self.cloud.run_instances @@ -1830,7 +1830,7 @@ class CloudTestCase(test.TestCase): def test_run_instances_image_state_invalid(self): kwargs = {'image_id': 'ami-00000001', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1} run_instances = self.cloud.run_instances @@ -1851,7 +1851,7 @@ class CloudTestCase(test.TestCase): def test_run_instances_image_status_active(self): kwargs = {'image_id': 'ami-00000001', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1} run_instances = self.cloud.run_instances @@ -1890,7 +1890,7 @@ class CloudTestCase(test.TestCase): self._restart_compute_service(periodic_interval_max=0.3) kwargs = {'image_id': 'ami-1', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1, } instance_id = self._run_instance(**kwargs) @@ -1919,7 +1919,7 @@ class CloudTestCase(test.TestCase): def test_start_instances(self): kwargs = {'image_id': 'ami-1', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1, } instance_id = self._run_instance(**kwargs) @@ -1941,7 +1941,7 @@ class CloudTestCase(test.TestCase): def test_stop_instances(self): kwargs = {'image_id': 'ami-1', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1, } instance_id = self._run_instance(**kwargs) @@ -1960,7 +1960,7 @@ class CloudTestCase(test.TestCase): def test_terminate_instances(self): kwargs = {'image_id': 'ami-1', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1, } instance_id = self._run_instance(**kwargs) @@ -1981,7 +1981,7 @@ class CloudTestCase(test.TestCase): def test_terminate_instances_invalid_instance_id(self): kwargs = {'image_id': 'ami-1', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1, } instance_id = self._run_instance(**kwargs) @@ -1992,7 +1992,7 @@ class CloudTestCase(test.TestCase): def test_terminate_instances_disable_terminate(self): kwargs = {'image_id': 'ami-1', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1, } instance_id = self._run_instance(**kwargs) @@ -2025,7 +2025,7 @@ class CloudTestCase(test.TestCase): def test_terminate_instances_two_instances(self): kwargs = {'image_id': 'ami-1', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1, } inst1 = self._run_instance(**kwargs) inst2 = self._run_instance(**kwargs) @@ -2050,7 +2050,7 @@ class CloudTestCase(test.TestCase): def test_reboot_instances(self): kwargs = {'image_id': 'ami-1', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1, } instance_id = self._run_instance(**kwargs) @@ -2096,7 +2096,7 @@ class CloudTestCase(test.TestCase): create_volumes_and_snapshots=True) kwargs = {'image_id': 'ami-1', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1} ec2_instance_id = self._run_instance(**kwargs) @@ -2186,7 +2186,7 @@ class CloudTestCase(test.TestCase): create_volumes_and_snapshots=True) kwargs = {'image_id': 'ami-1', - 'instance_type': CONF.default_instance_type, + 'instance_type': CONF.default_flavor, 'max_count': 1} ec2_instance_id = self._run_instance(**kwargs) @@ -2269,9 +2269,9 @@ class CloudTestCase(test.TestCase): self._fake_bdm_get) def fake_get(ctxt, instance_id): - inst_type = flavors.get_default_instance_type() + inst_type = flavors.get_default_flavor() inst_type['name'] = 'fake_type' - sys_meta = flavors.save_instance_type_info({}, inst_type) + sys_meta = flavors.save_flavor_info({}, inst_type) sys_meta = utils.dict_to_metadata(sys_meta) return { 'id': 0, @@ -2347,7 +2347,7 @@ class CloudTestCase(test.TestCase): def test_dia_iisb(expected_result, **kwargs): """test describe_instance_attribute attribute instance_initiated_shutdown_behavior""" - kwargs.update({'instance_type': CONF.default_instance_type, + kwargs.update({'instance_type': CONF.default_flavor, 'max_count': 1}) instance_id = self._run_instance(**kwargs) diff --git a/nova/tests/api/openstack/compute/contrib/test_flavor_access.py b/nova/tests/api/openstack/compute/contrib/test_flavor_access.py index 6bae7882f..d072e0784 100644 --- a/nova/tests/api/openstack/compute/contrib/test_flavor_access.py +++ b/nova/tests/api/openstack/compute/contrib/test_flavor_access.py @@ -27,7 +27,7 @@ from nova import test from nova.tests.api.openstack import fakes -def generate_instance_type(flavorid, ispublic): +def generate_flavor(flavorid, ispublic): return { 'id': flavorid, 'flavorid': str(flavorid), @@ -49,10 +49,10 @@ def generate_instance_type(flavorid, ispublic): INSTANCE_TYPES = { - '0': generate_instance_type(0, True), - '1': generate_instance_type(1, True), - '2': generate_instance_type(2, False), - '3': generate_instance_type(3, False)} + '0': generate_flavor(0, True), + '1': generate_flavor(1, True), + '2': generate_flavor(2, False), + '3': generate_flavor(3, False)} ACCESS_LIST = [{'flavor_id': '2', 'project_id': 'proj2'}, @@ -60,7 +60,7 @@ ACCESS_LIST = [{'flavor_id': '2', 'project_id': 'proj2'}, {'flavor_id': '3', 'project_id': 'proj3'}] -def fake_get_instance_type_access_by_flavor_id(flavorid): +def fake_get_flavor_access_by_flavor_id(flavorid): res = [] for access in ACCESS_LIST: if access['flavor_id'] == flavorid: @@ -68,7 +68,7 @@ def fake_get_instance_type_access_by_flavor_id(flavorid): return res -def fake_get_instance_type_by_flavor_id(flavorid): +def fake_get_flavor_by_flavor_id(flavorid): return INSTANCE_TYPES[flavorid] @@ -80,7 +80,7 @@ def _has_flavor_access(flavorid, projectid): return False -def fake_get_all_types(context, inactive=0, filters=None): +def fake_get_all_flavors(context, inactive=0, filters=None): if filters == None or filters['is_public'] == None: return INSTANCE_TYPES @@ -121,11 +121,11 @@ class FlavorAccessTest(test.TestCase): self.flavor_action_controller = flavor_access.FlavorActionController() self.req = FakeRequest() self.context = self.req.environ['nova.context'] - self.stubs.Set(flavors, 'get_instance_type_by_flavor_id', - fake_get_instance_type_by_flavor_id) - self.stubs.Set(flavors, 'get_all_types', fake_get_all_types) - self.stubs.Set(flavors, 'get_instance_type_access_by_flavor_id', - fake_get_instance_type_access_by_flavor_id) + self.stubs.Set(flavors, 'get_flavor_by_flavor_id', + fake_get_flavor_by_flavor_id) + self.stubs.Set(flavors, 'get_all_flavors', fake_get_all_flavors) + self.stubs.Set(flavors, 'get_flavor_access_by_flavor_id', + fake_get_flavor_access_by_flavor_id) def _verify_flavor_list(self, result, expected): # result already sorted by flavor_id @@ -246,11 +246,11 @@ class FlavorAccessTest(test.TestCase): resp.obj['flavor']) def test_add_tenant_access(self): - def stub_add_instance_type_access(flavorid, projectid, ctxt=None): + def stub_add_flavor_access(flavorid, projectid, ctxt=None): self.assertEqual('3', flavorid, "flavorid") self.assertEqual("proj2", projectid, "projectid") - self.stubs.Set(flavors, 'add_instance_type_access', - stub_add_instance_type_access) + self.stubs.Set(flavors, 'add_flavor_access', + stub_add_flavor_access) expected = {'flavor_access': [{'flavor_id': '3', 'tenant_id': 'proj3'}]} body = {'addTenantAccess': {'tenant': 'proj2'}} @@ -261,11 +261,11 @@ class FlavorAccessTest(test.TestCase): self.assertEqual(result, expected) def test_add_tenant_access_with_already_added_access(self): - def stub_add_instance_type_access(flavorid, projectid, ctxt=None): + def stub_add_flavor_access(flavorid, projectid, ctxt=None): raise exception.FlavorAccessExists(flavor_id=flavorid, project_id=projectid) - self.stubs.Set(flavors, 'add_instance_type_access', - stub_add_instance_type_access) + self.stubs.Set(flavors, 'add_flavor_access', + stub_add_flavor_access) body = {'addTenantAccess': {'tenant': 'proj2'}} req = fakes.HTTPRequest.blank('/v2/fake/flavors/2/action', use_admin_context=True) @@ -274,11 +274,11 @@ class FlavorAccessTest(test.TestCase): self.req, '3', body) def test_remove_tenant_access_with_bad_access(self): - def stub_remove_instance_type_access(flavorid, projectid, ctxt=None): + def stub_remove_flavor_access(flavorid, projectid, ctxt=None): raise exception.FlavorAccessNotFound(flavor_id=flavorid, project_id=projectid) - self.stubs.Set(flavors, 'remove_instance_type_access', - stub_remove_instance_type_access) + self.stubs.Set(flavors, 'remove_flavor_access', + stub_remove_flavor_access) body = {'removeTenantAccess': {'tenant': 'proj2'}} req = fakes.HTTPRequest.blank('/v2/fake/flavors/2/action', use_admin_context=True) diff --git a/nova/tests/api/openstack/compute/contrib/test_flavor_disabled.py b/nova/tests/api/openstack/compute/contrib/test_flavor_disabled.py index 8a8660a67..e46e02a44 100644 --- a/nova/tests/api/openstack/compute/contrib/test_flavor_disabled.py +++ b/nova/tests/api/openstack/compute/contrib/test_flavor_disabled.py @@ -39,11 +39,11 @@ FAKE_FLAVORS = { } -def fake_instance_type_get_by_flavor_id(flavorid): +def fake_flavor_get_by_flavor_id(flavorid): return FAKE_FLAVORS['flavor %s' % flavorid] -def fake_instance_type_get_all(*args, **kwargs): +def fake_flavor_get_all(*args, **kwargs): return FAKE_FLAVORS @@ -57,11 +57,11 @@ class FlavorDisabledTest(test.TestCase): '.flavor_disabled.Flavor_disabled') self.flags(osapi_compute_extension=[ext]) fakes.stub_out_nw_api(self.stubs) - self.stubs.Set(flavors, "get_all_types", - fake_instance_type_get_all) + self.stubs.Set(flavors, "get_all_flavors", + fake_flavor_get_all) self.stubs.Set(flavors, - "get_instance_type_by_flavor_id", - fake_instance_type_get_by_flavor_id) + "get_flavor_by_flavor_id", + fake_flavor_get_by_flavor_id) def _make_request(self, url): req = webob.Request.blank(url) diff --git a/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py b/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py index 2ca02cafa..df2c3d392 100644 --- a/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py +++ b/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py @@ -25,7 +25,7 @@ from nova import test from nova.tests.api.openstack import fakes -def fake_get_instance_type_by_flavor_id(flavorid, read_deleted='yes'): +def fake_get_flavor_by_flavor_id(flavorid, read_deleted='yes'): if flavorid == 'failtest': raise exception.NotFound("Not found sucka!") elif not str(flavorid) == '1234': @@ -62,7 +62,7 @@ def fake_create(name, memory_mb, vcpus, root_gb, ephemeral_gb, flavorid, swap, rxtx_factor, is_public): if flavorid is None: flavorid = 1234 - newflavor = fake_get_instance_type_by_flavor_id(flavorid, + newflavor = fake_get_flavor_by_flavor_id(flavorid, read_deleted="no") newflavor["name"] = name @@ -81,8 +81,8 @@ class FlavorManageTest(test.TestCase): def setUp(self): super(FlavorManageTest, self).setUp() self.stubs.Set(flavors, - "get_instance_type_by_flavor_id", - fake_get_instance_type_by_flavor_id) + "get_flavor_by_flavor_id", + fake_get_flavor_by_flavor_id) self.stubs.Set(flavors, "destroy", fake_destroy) self.stubs.Set(flavors, "create", fake_create) self.flags( @@ -191,7 +191,7 @@ class FlavorManageTest(test.TestCase): for key in expected["flavor"]: self.assertEquals(body["flavor"][key], expected["flavor"][key]) - def test_instance_type_exists_exception_returns_409(self): + def test_flavor_exists_exception_returns_409(self): expected = { "flavor": { "name": "test", diff --git a/nova/tests/api/openstack/compute/contrib/test_flavor_rxtx.py b/nova/tests/api/openstack/compute/contrib/test_flavor_rxtx.py index 965d0e1bb..5843a60a1 100644 --- a/nova/tests/api/openstack/compute/contrib/test_flavor_rxtx.py +++ b/nova/tests/api/openstack/compute/contrib/test_flavor_rxtx.py @@ -38,11 +38,11 @@ FAKE_FLAVORS = { } -def fake_instance_type_get_by_flavor_id(flavorid): +def fake_flavor_get_by_flavor_id(flavorid): return FAKE_FLAVORS['flavor %s' % flavorid] -def fake_instance_type_get_all(*args, **kwargs): +def fake_flavor_get_all(*args, **kwargs): return FAKE_FLAVORS @@ -56,11 +56,11 @@ class FlavorRxtxTest(test.TestCase): '.flavor_rxtx.Flavor_rxtx') self.flags(osapi_compute_extension=[ext]) fakes.stub_out_nw_api(self.stubs) - self.stubs.Set(flavors, "get_all_types", - fake_instance_type_get_all) + self.stubs.Set(flavors, "get_all_flavors", + fake_flavor_get_all) self.stubs.Set(flavors, - "get_instance_type_by_flavor_id", - fake_instance_type_get_by_flavor_id) + "get_flavor_by_flavor_id", + fake_flavor_get_by_flavor_id) def _make_request(self, url): req = webob.Request.blank(url) diff --git a/nova/tests/api/openstack/compute/contrib/test_flavor_swap.py b/nova/tests/api/openstack/compute/contrib/test_flavor_swap.py index ea3ab6e34..fd154479d 100644 --- a/nova/tests/api/openstack/compute/contrib/test_flavor_swap.py +++ b/nova/tests/api/openstack/compute/contrib/test_flavor_swap.py @@ -38,11 +38,12 @@ FAKE_FLAVORS = { } -def fake_instance_type_get_by_flavor_id(flavorid): +#TOD(jogo) dedup these accross nova.api.openstack.contrib.test_flavor* +def fake_flavor_get_by_flavor_id(flavorid): return FAKE_FLAVORS['flavor %s' % flavorid] -def fake_instance_type_get_all(*args, **kwargs): +def fake_flavor_get_all(*args, **kwargs): return FAKE_FLAVORS @@ -56,11 +57,11 @@ class FlavorSwapTest(test.TestCase): '.flavor_swap.Flavor_swap') self.flags(osapi_compute_extension=[ext]) fakes.stub_out_nw_api(self.stubs) - self.stubs.Set(flavors, "get_all_types", - fake_instance_type_get_all) + self.stubs.Set(flavors, "get_all_flavors", + fake_flavor_get_all) self.stubs.Set(flavors, - "get_instance_type_by_flavor_id", - fake_instance_type_get_by_flavor_id) + "get_flavor_by_flavor_id", + fake_flavor_get_by_flavor_id) def _make_request(self, url): req = webob.Request.blank(url) diff --git a/nova/tests/api/openstack/compute/contrib/test_flavorextradata.py b/nova/tests/api/openstack/compute/contrib/test_flavorextradata.py index f45f98bbc..ec0d68b04 100644 --- a/nova/tests/api/openstack/compute/contrib/test_flavorextradata.py +++ b/nova/tests/api/openstack/compute/contrib/test_flavorextradata.py @@ -23,7 +23,7 @@ from nova import test from nova.tests.api.openstack import fakes -def fake_get_instance_type_by_flavor_id(flavorid): +def fake_get_flavor_by_flavor_id(flavorid): return { 'id': flavorid, 'flavorid': str(flavorid), @@ -41,10 +41,10 @@ def fake_get_instance_type_by_flavor_id(flavorid): } -def fake_get_all_types(inactive=0, filters=None): +def fake_get_all_flavors(inactive=0, filters=None): return { - 'fake1': fake_get_instance_type_by_flavor_id(1), - 'fake2': fake_get_instance_type_by_flavor_id(2) + 'fake1': fake_get_flavor_by_flavor_id(1), + 'fake2': fake_get_flavor_by_flavor_id(2) } @@ -54,9 +54,9 @@ class FlavorextradataTest(test.TestCase): ext = ('nova.api.openstack.compute.contrib' '.flavorextradata.Flavorextradata') self.flags(osapi_compute_extension=[ext]) - self.stubs.Set(flavors, 'get_instance_type_by_flavor_id', - fake_get_instance_type_by_flavor_id) - self.stubs.Set(flavors, 'get_all_types', fake_get_all_types) + self.stubs.Set(flavors, 'get_flavor_by_flavor_id', + fake_get_flavor_by_flavor_id) + self.stubs.Set(flavors, 'get_all_flavors', fake_get_all_flavors) def _verify_flavor_response(self, flavor, expected): for key in expected: diff --git a/nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py b/nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py index 004a6716e..8c8242505 100644 --- a/nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py +++ b/nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py @@ -59,7 +59,7 @@ FAKE_INST_TYPE = {'id': 1, def get_fake_db_instance(start, end, instance_id, tenant_id): sys_meta = utils.dict_to_metadata( - flavors.save_instance_type_info({}, FAKE_INST_TYPE)) + flavors.save_flavor_info({}, FAKE_INST_TYPE)) return {'id': instance_id, 'uuid': '00000000-0000-0000-0000-00000000000000%02d' % instance_id, 'image_ref': '1', @@ -415,7 +415,7 @@ class SimpleTenantUsageControllerTest(test.TestCase): class FakeComputeAPI: def get_instance_type(self, context, flavor_type): if flavor_type == 1: - return flavors.get_default_instance_type() + return flavors.get_default_flavor() else: raise exception.InstanceTypeNotFound(flavor_type) @@ -429,11 +429,11 @@ class SimpleTenantUsageControllerTest(test.TestCase): instance_type_id=1, vm_state='deleted', deleted=0) - basetype = flavors.get_default_instance_type() + basetype = flavors.get_default_flavor() sys_meta = utils.dict_to_metadata( - flavors.save_instance_type_info({}, basetype)) + flavors.save_flavor_info({}, basetype)) self.baseinst['system_metadata'] = sys_meta - self.basetype = flavors.extract_instance_type(self.baseinst) + self.basetype = flavors.extract_flavor(self.baseinst) def test_get_flavor_from_sys_meta(self): # Non-deleted instances get their type information from their @@ -458,7 +458,7 @@ class SimpleTenantUsageControllerTest(test.TestCase): deleted=1) flavor = self.controller._get_flavor(self.context, self.compute_api, inst_without_sys_meta, {}) - self.assertEqual(flavor, flavors.get_default_instance_type()) + self.assertEqual(flavor, flavors.get_default_flavor()) def test_get_flavor_from_deleted_with_id_of_deleted(self): # Verify the legacy behavior of instance_type_id pointing to a diff --git a/nova/tests/api/openstack/compute/contrib/test_volumes.py b/nova/tests/api/openstack/compute/contrib/test_volumes.py index 5e331f4f4..bdca7fdef 100644 --- a/nova/tests/api/openstack/compute/contrib/test_volumes.py +++ b/nova/tests/api/openstack/compute/contrib/test_volumes.py @@ -47,7 +47,7 @@ def fake_compute_api_create(cls, context, instance_type, image_href, **kwargs): global _block_device_mapping_seen _block_device_mapping_seen = kwargs.get('block_device_mapping') - inst_type = flavors.get_instance_type_by_flavor_id(2) + inst_type = flavors.get_flavor_by_flavor_id(2) resv_id = None return ([{'id': 1, 'display_name': 'test_server', diff --git a/nova/tests/api/openstack/compute/plugins/v3/test_servers.py b/nova/tests/api/openstack/compute/plugins/v3/test_servers.py index 6c75ef5fe..da17d8fd5 100644 --- a/nova/tests/api/openstack/compute/plugins/v3/test_servers.py +++ b/nova/tests/api/openstack/compute/plugins/v3/test_servers.py @@ -1779,7 +1779,7 @@ class ServersControllerCreateTest(test.TestCase): self.controller = servers.ServersController(extension_info=ext_info) def instance_create(context, inst): - inst_type = flavors.get_instance_type_by_flavor_id(3) + inst_type = flavors.get_flavor_by_flavor_id(3) image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6' def_image_ref = 'http://localhost/images/%s' % image_uuid self.instance_cache_num += 1 diff --git a/nova/tests/api/openstack/compute/test_flavors.py b/nova/tests/api/openstack/compute/test_flavors.py index 13206b6f8..77e637044 100644 --- a/nova/tests/api/openstack/compute/test_flavors.py +++ b/nova/tests/api/openstack/compute/test_flavors.py @@ -50,11 +50,11 @@ FAKE_FLAVORS = { } -def fake_instance_type_get_by_flavor_id(flavorid): +def fake_flavor_get_by_flavor_id(flavorid): return FAKE_FLAVORS['flavor %s' % flavorid] -def fake_instance_type_get_all(inactive=False, filters=None): +def fake_flavor_get_all(inactive=False, filters=None): def reject_min(db_attr, filter_attr): return (filter_attr in filters and int(flavor[db_attr]) < int(filters[filter_attr])) @@ -72,11 +72,11 @@ def fake_instance_type_get_all(inactive=False, filters=None): return output -def empty_instance_type_get_all(inactive=False, filters=None): +def empty_flavor_get_all(inactive=False, filters=None): return {} -def return_instance_type_not_found(flavor_id): +def return_flavor_not_found(flavor_id): raise exception.InstanceTypeNotFound(instance_type_id=flavor_id) @@ -86,18 +86,18 @@ class FlavorsTest(test.TestCase): self.flags(osapi_compute_extension=[]) fakes.stub_out_networking(self.stubs) fakes.stub_out_rate_limiting(self.stubs) - self.stubs.Set(nova.compute.flavors, "get_all_types", - fake_instance_type_get_all) + self.stubs.Set(nova.compute.flavors, "get_all_flavors", + fake_flavor_get_all) self.stubs.Set(nova.compute.flavors, - "get_instance_type_by_flavor_id", - fake_instance_type_get_by_flavor_id) + "get_flavor_by_flavor_id", + fake_flavor_get_by_flavor_id) self.controller = flavors.Controller() def test_get_flavor_by_invalid_id(self): self.stubs.Set(nova.compute.flavors, - "get_instance_type_by_flavor_id", - return_instance_type_not_found) + "get_flavor_by_flavor_id", + return_flavor_not_found) req = fakes.HTTPRequest.blank('/v2/fake/flavors/asdf') self.assertRaises(webob.exc.HTTPNotFound, self.controller.show, req, 'asdf') @@ -341,8 +341,8 @@ class FlavorsTest(test.TestCase): self.assertEqual(flavor, expected) def test_get_empty_flavor_list(self): - self.stubs.Set(nova.compute.flavors, "get_all_types", - empty_instance_type_get_all) + self.stubs.Set(nova.compute.flavors, "get_all_flavors", + empty_flavor_get_all) req = fakes.HTTPRequest.blank('/v2/fake/flavors') flavors = self.controller.index(req) diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index 97a1a5826..6a8c3702f 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -1785,7 +1785,7 @@ class ServersControllerCreateTest(test.TestCase): self.volume_id = 'fake' def instance_create(context, inst): - inst_type = flavors.get_instance_type_by_flavor_id(3) + inst_type = flavors.get_flavor_by_flavor_id(3) image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6' def_image_ref = 'http://localhost/images/%s' % image_uuid self.instance_cache_num += 1 @@ -4244,7 +4244,7 @@ class ServersViewBuilderTest(test.TestCase): self.view_builder = views.servers.ViewBuilder() self.request = fakes.HTTPRequest.blank("/v2") - def test_get_flavor_valid_instance_type(self): + def test_get_flavor_valid_flavor(self): flavor_bookmark = "http://localhost/fake/flavors/1" expected = {"id": "1", "links": [{"rel": "bookmark", diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py index 04857b59c..f05561ff2 100644 --- a/nova/tests/api/openstack/fakes.py +++ b/nova/tests/api/openstack/fakes.py @@ -476,8 +476,8 @@ def stub_instance(id, user_id=None, project_id=None, host=None, else: metadata = [] - inst_type = flavors.get_instance_type_by_flavor_id(int(flavor_id)) - sys_meta = flavors.save_instance_type_info({}, inst_type) + inst_type = flavors.get_flavor_by_flavor_id(int(flavor_id)) + sys_meta = flavors.save_flavor_info({}, inst_type) if host is not None: host = str(host) diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 4dea52dfb..b1f046c52 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -230,8 +230,8 @@ class BaseTestCase(test.TestCase): def make_fake_sys_meta(): sys_meta = {} - inst_type = flavors.get_instance_type_by_name(type_name) - for key in flavors.system_metadata_instance_type_props: + inst_type = flavors.get_flavor_by_name(type_name) + for key in flavors.system_metadata_flavor_props: sys_meta['instance_type_%s' % key] = inst_type[key] return sys_meta @@ -243,7 +243,7 @@ class BaseTestCase(test.TestCase): inst['project_id'] = self.project_id inst['host'] = 'fake_host' inst['node'] = NODENAME - type_id = flavors.get_instance_type_by_name(type_name)['id'] + type_id = flavors.get_flavor_by_name(type_name)['id'] inst['instance_type_id'] = type_id inst['ami_launch_index'] = 0 inst['memory_mb'] = 0 @@ -2160,7 +2160,7 @@ class ComputeTestCase(BaseTestCase): self.assertEquals(payload['user_id'], self.user_id) self.assertEquals(payload['instance_id'], inst_ref['uuid']) self.assertEquals(payload['instance_type'], 'm1.tiny') - type_id = flavors.get_instance_type_by_name('m1.tiny')['id'] + type_id = flavors.get_flavor_by_name('m1.tiny')['id'] self.assertEquals(str(payload['instance_type_id']), str(type_id)) self.assertEquals(payload['state'], 'active') self.assertTrue('display_name' in payload) @@ -2273,7 +2273,7 @@ class ComputeTestCase(BaseTestCase): self.assertEquals(payload['user_id'], self.user_id) self.assertEquals(payload['instance_id'], instance['uuid']) self.assertEquals(payload['instance_type'], 'm1.tiny') - type_id = flavors.get_instance_type_by_name('m1.tiny')['id'] + type_id = flavors.get_flavor_by_name('m1.tiny')['id'] self.assertEquals(str(payload['instance_type_id']), str(type_id)) self.assertTrue('display_name' in payload) self.assertTrue('created_at' in payload) @@ -2696,7 +2696,7 @@ class ComputeTestCase(BaseTestCase): vm_state = vm_states.STOPPED params = {'vm_state': vm_state} instance = jsonutils.to_primitive(self._create_fake_instance(params)) - instance_type = flavors.get_default_instance_type() + instance_type = flavors.get_default_flavor() db.instance_update(self.context, instance["uuid"], {"task_state": task_states.RESIZE_PREP}) self.compute.prep_resize(self.context, instance=instance, @@ -2791,7 +2791,7 @@ class ComputeTestCase(BaseTestCase): jsonutils.dumps(connection_info)) # begin resize - instance_type = flavors.get_default_instance_type() + instance_type = flavors.get_default_flavor() db.instance_update(self.context, instance["uuid"], {"task_state": task_states.RESIZE_PREP}) self.compute.prep_resize(self.context, instance=instance, @@ -2885,7 +2885,7 @@ class ComputeTestCase(BaseTestCase): reservations = self._ensure_quota_reservations_rolledback() instance = jsonutils.to_primitive(self._create_fake_instance()) - instance_type = flavors.get_default_instance_type() + instance_type = flavors.get_default_flavor() self.compute.prep_resize(self.context, instance=instance, instance_type=instance_type, image={}, reservations=reservations) @@ -2963,7 +2963,7 @@ class ComputeTestCase(BaseTestCase): self.assertEquals(payload['user_id'], self.user_id) self.assertEquals(payload['instance_id'], inst_ref['uuid']) self.assertEquals(payload['instance_type'], 'm1.tiny') - type_id = flavors.get_instance_type_by_name('m1.tiny')['id'] + type_id = flavors.get_flavor_by_name('m1.tiny')['id'] self.assertEquals(str(payload['instance_type_id']), str(type_id)) self.assertTrue('display_name' in payload) self.assertTrue('created_at' in payload) @@ -2979,7 +2979,7 @@ class ComputeTestCase(BaseTestCase): cur_time = datetime.datetime(2012, 12, 21, 12, 21) timeutils.set_time_override(old_time) instance = jsonutils.to_primitive(self._create_fake_instance()) - new_type = flavors.get_instance_type_by_name('m1.small') + new_type = flavors.get_flavor_by_name('m1.small') new_type = jsonutils.to_primitive(new_type) new_type_id = new_type['id'] self.compute.run_instance(self.context, instance=instance) @@ -3041,7 +3041,7 @@ class ComputeTestCase(BaseTestCase): new_instance = db.instance_update(self.context, instance['uuid'], {'host': 'foo'}) new_instance = jsonutils.to_primitive(new_instance) - instance_type = flavors.get_default_instance_type() + instance_type = flavors.get_default_flavor() self.compute.prep_resize(self.context, instance=new_instance, instance_type=instance_type, image={}) db.migration_get_by_instance_and_status(self.context.elevated(), @@ -3064,7 +3064,7 @@ class ComputeTestCase(BaseTestCase): self.assertEquals(payload['user_id'], self.user_id) self.assertEquals(payload['instance_id'], new_instance['uuid']) self.assertEquals(payload['instance_type'], 'm1.tiny') - type_id = flavors.get_instance_type_by_name('m1.tiny')['id'] + type_id = flavors.get_flavor_by_name('m1.tiny')['id'] self.assertEquals(str(payload['instance_type_id']), str(type_id)) self.assertTrue('display_name' in payload) self.assertTrue('created_at' in payload) @@ -3087,7 +3087,7 @@ class ComputeTestCase(BaseTestCase): new_instance = db.instance_update(self.context, instance['uuid'], {'host': self.compute.host}) new_instance = jsonutils.to_primitive(new_instance) - instance_type = flavors.get_default_instance_type() + instance_type = flavors.get_default_flavor() self.assertRaises(exception.MigrationError, self.compute.prep_resize, self.context, instance=new_instance, @@ -3107,7 +3107,7 @@ class ComputeTestCase(BaseTestCase): new_instance = db.instance_update(self.context, instance['uuid'], {'host': None}) new_instance = jsonutils.to_primitive(new_instance) - instance_type = flavors.get_default_instance_type() + instance_type = flavors.get_default_flavor() self.assertRaises(exception.MigrationError, self.compute.prep_resize, self.context, instance=new_instance, @@ -3125,7 +3125,7 @@ class ComputeTestCase(BaseTestCase): throw_up) instance = jsonutils.to_primitive(self._create_fake_instance()) - instance_type = flavors.get_default_instance_type() + instance_type = flavors.get_default_flavor() reservations = self._ensure_quota_reservations_rolledback() @@ -3163,7 +3163,7 @@ class ComputeTestCase(BaseTestCase): throw_up) instance = jsonutils.to_primitive(self._create_fake_instance()) - instance_type = flavors.get_default_instance_type() + instance_type = flavors.get_default_flavor() reservations = self._ensure_quota_reservations_rolledback() self.compute.run_instance(self.context, instance=instance) new_instance = db.instance_update(self.context, instance['uuid'], @@ -3193,7 +3193,7 @@ class ComputeTestCase(BaseTestCase): def test_resize_instance(self): # Ensure instance can be migrated/resized. instance = jsonutils.to_primitive(self._create_fake_instance()) - instance_type = flavors.get_default_instance_type() + instance_type = flavors.get_default_flavor() self.compute.run_instance(self.context, instance=instance) new_instance = db.instance_update(self.context, instance['uuid'], @@ -3481,20 +3481,20 @@ class ComputeTestCase(BaseTestCase): instance['system_metadata'].append(dict(key='instance_type_id', value=old)) sys_meta = dict(instance_type_id=old) - self.mox.StubOutWithMock(flavors, 'extract_instance_type') - self.mox.StubOutWithMock(flavors, 'delete_instance_type_info') - self.mox.StubOutWithMock(flavors, 'save_instance_type_info') + self.mox.StubOutWithMock(flavors, 'extract_flavor') + self.mox.StubOutWithMock(flavors, 'delete_flavor_info') + self.mox.StubOutWithMock(flavors, 'save_flavor_info') if revert: - flavors.extract_instance_type(instance, 'old_').AndReturn( + flavors.extract_flavor(instance, 'old_').AndReturn( {'instance_type_id': old}) - flavors.save_instance_type_info( + flavors.save_flavor_info( sys_meta, {'instance_type_id': old}).AndReturn(sys_meta) else: - flavors.extract_instance_type(instance).AndReturn( + flavors.extract_flavor(instance).AndReturn( {'instance_type_id': new}) - flavors.delete_instance_type_info( + flavors.delete_flavor_info( sys_meta, 'old_').AndReturn(sys_meta) - flavors.delete_instance_type_info( + flavors.delete_flavor_info( sys_meta, 'new_').AndReturn(sys_meta) self.mox.ReplayAll() @@ -3517,7 +3517,7 @@ class ComputeTestCase(BaseTestCase): self._test_cleanup_stored_instance_types('1', '1', True) def test_get_by_flavor_id(self): - type = flavors.get_instance_type_by_flavor_id(1) + type = flavors.get_flavor_by_flavor_id(1) self.assertEqual(type['name'], 'm1.tiny') def test_resize_same_source_fails(self): @@ -3527,7 +3527,7 @@ class ComputeTestCase(BaseTestCase): instance = jsonutils.to_primitive(self._create_fake_instance()) self.compute.run_instance(self.context, instance=instance) instance = db.instance_get_by_uuid(self.context, instance['uuid']) - instance_type = flavors.get_default_instance_type() + instance_type = flavors.get_default_flavor() self.assertRaises(exception.MigrationError, self.compute.prep_resize, self.context, instance=instance, instance_type=instance_type, image={}, @@ -3546,7 +3546,7 @@ class ComputeTestCase(BaseTestCase): reservations = self._ensure_quota_reservations_rolledback() inst_ref = jsonutils.to_primitive(self._create_fake_instance()) - instance_type = flavors.get_default_instance_type() + instance_type = flavors.get_default_flavor() self.compute.run_instance(self.context, instance=inst_ref) inst_ref = db.instance_update(self.context, inst_ref['uuid'], @@ -5101,7 +5101,7 @@ class ComputeAPITestCase(BaseTestCase): def test_create_with_too_little_ram(self): # Test an instance type with too little memory. - inst_type = flavors.get_default_instance_type() + inst_type = flavors.get_default_flavor() inst_type['memory_mb'] = 1 self.fake_image['min_ram'] = 2 @@ -5120,7 +5120,7 @@ class ComputeAPITestCase(BaseTestCase): def test_create_with_too_little_disk(self): # Test an instance type with too little disk space. - inst_type = flavors.get_default_instance_type() + inst_type = flavors.get_default_flavor() inst_type['root_gb'] = 1 self.fake_image['min_disk'] = 2 @@ -5139,7 +5139,7 @@ class ComputeAPITestCase(BaseTestCase): def test_create_with_too_large_image(self): # Test an instance type with too little disk space. - inst_type = flavors.get_default_instance_type() + inst_type = flavors.get_default_flavor() inst_type['root_gb'] = 1 self.fake_image['size'] = '1073741825' @@ -5159,7 +5159,7 @@ class ComputeAPITestCase(BaseTestCase): def test_create_just_enough_ram_and_disk(self): # Test an instance type with just enough ram and disk space. - inst_type = flavors.get_default_instance_type() + inst_type = flavors.get_default_flavor() inst_type['root_gb'] = 2 inst_type['memory_mb'] = 2 @@ -5175,7 +5175,7 @@ class ComputeAPITestCase(BaseTestCase): def test_create_with_no_ram_and_disk_reqs(self): # Test an instance type with no min_ram or min_disk. - inst_type = flavors.get_default_instance_type() + inst_type = flavors.get_default_flavor() inst_type['root_gb'] = 1 inst_type['memory_mb'] = 1 @@ -5188,7 +5188,7 @@ class ComputeAPITestCase(BaseTestCase): def test_create_with_deleted_image(self): # If we're given a deleted image by glance, we should not be able to # build from it - inst_type = flavors.get_default_instance_type() + inst_type = flavors.get_default_flavor() self.fake_image['name'] = 'fake_name' self.fake_image['status'] = 'DELETED' @@ -5207,7 +5207,7 @@ class ComputeAPITestCase(BaseTestCase): cases = [dict(), dict(display_name=None)] for instance in cases: (ref, resv_id) = self.compute_api.create(self.context, - flavors.get_default_instance_type(), + flavors.get_default_flavor(), 'fake-image-uuid', **instance) try: self.assertNotEqual(ref[0]['display_name'], None) @@ -5218,7 +5218,7 @@ class ComputeAPITestCase(BaseTestCase): # Make sure image properties are copied into system metadata. (ref, resv_id) = self.compute_api.create( self.context, - instance_type=flavors.get_default_instance_type(), + instance_type=flavors.get_default_flavor(), image_href='fake-image-uuid') try: sys_metadata = db.instance_system_metadata_get(self.context, @@ -5235,7 +5235,7 @@ class ComputeAPITestCase(BaseTestCase): db.instance_destroy(self.context, ref[0]['uuid']) def test_create_saves_type_in_system_metadata(self): - instance_type = flavors.get_default_instance_type() + instance_type = flavors.get_default_flavor() (ref, resv_id) = self.compute_api.create( self.context, instance_type=instance_type, @@ -5261,7 +5261,7 @@ class ComputeAPITestCase(BaseTestCase): group = self._create_group() (ref, resv_id) = self.compute_api.create( self.context, - instance_type=flavors.get_default_instance_type(), + instance_type=flavors.get_default_flavor(), image_href=None, security_group=['testgroup']) try: @@ -5274,7 +5274,7 @@ class ComputeAPITestCase(BaseTestCase): db.instance_destroy(self.context, ref[0]['uuid']) def test_create_instance_with_invalid_security_group_raises(self): - instance_type = flavors.get_default_instance_type() + instance_type = flavors.get_default_flavor() pre_build_len = len(db.instance_get_all(self.context)) self.assertRaises(exception.SecurityGroupNotFoundForProject, @@ -5289,7 +5289,7 @@ class ComputeAPITestCase(BaseTestCase): def test_create_with_large_user_data(self): # Test an instance type with too much user data. - inst_type = flavors.get_default_instance_type() + inst_type = flavors.get_default_flavor() self.fake_image['min_ram'] = 2 self.stubs.Set(fake_image._FakeImageService, 'show', self.fake_show) @@ -5301,7 +5301,7 @@ class ComputeAPITestCase(BaseTestCase): def test_create_with_malformed_user_data(self): # Test an instance type with malformed user data. - inst_type = flavors.get_default_instance_type() + inst_type = flavors.get_default_flavor() self.fake_image['min_ram'] = 2 self.stubs.Set(fake_image._FakeImageService, 'show', self.fake_show) @@ -5313,7 +5313,7 @@ class ComputeAPITestCase(BaseTestCase): def test_create_with_base64_user_data(self): # Test an instance type with ok much user data. - inst_type = flavors.get_default_instance_type() + inst_type = flavors.get_default_flavor() self.fake_image['min_ram'] = 2 self.stubs.Set(fake_image._FakeImageService, 'show', self.fake_show) @@ -5344,7 +5344,7 @@ class ComputeAPITestCase(BaseTestCase): ('hello_server', 'hello-server')] for display_name, hostname in cases: (ref, resv_id) = self.compute_api.create(self.context, - flavors.get_default_instance_type(), None, + flavors.get_default_flavor(), None, display_name=display_name) try: self.assertEqual(ref[0]['hostname'], hostname) @@ -5357,7 +5357,7 @@ class ComputeAPITestCase(BaseTestCase): (ref, resv_id) = self.compute_api.create( self.context, - instance_type=flavors.get_default_instance_type(), + instance_type=flavors.get_default_flavor(), image_href=None, security_group=['testgroup']) try: @@ -5373,7 +5373,7 @@ class ComputeAPITestCase(BaseTestCase): (ref, resv_id) = self.compute_api.create( self.context, - instance_type=flavors.get_default_instance_type(), + instance_type=flavors.get_default_flavor(), image_href=None, security_group=['testgroup']) @@ -5494,7 +5494,7 @@ class ComputeAPITestCase(BaseTestCase): def test_delete_in_resizing(self): def fake_quotas_reserve(context, expire=None, project_id=None, **deltas): - old_type = flavors.get_instance_type_by_name('m1.tiny') + old_type = flavors.get_flavor_by_name('m1.tiny') # ensure using old instance type to create reservations self.assertEqual(deltas['cores'], -old_type['vcpus']) self.assertEqual(deltas['ram'], -old_type['memory_mb']) @@ -5505,7 +5505,7 @@ class ComputeAPITestCase(BaseTestCase): 'host': CONF.host}) # create a fake migration record (manager does this) - new_inst_type = flavors.get_instance_type_by_name('m1.small') + new_inst_type = flavors.get_flavor_by_name('m1.small') db.migration_create(self.context.elevated(), {'instance_uuid': instance['uuid'], 'old_instance_type_id': instance['instance_type_id'], @@ -5843,11 +5843,11 @@ class ComputeAPITestCase(BaseTestCase): instance = jsonutils.to_primitive( self._create_fake_instance(params={'image_ref': '1'})) - def fake_extract_instance_type(_inst): + def fake_extract_flavor(_inst): return dict(memory_mb=64, root_gb=1) - self.stubs.Set(flavors, 'extract_instance_type', - fake_extract_instance_type) + self.stubs.Set(flavors, 'extract_flavor', + fake_extract_flavor) self.fake_image['min_ram'] = 128 self.stubs.Set(fake_image._FakeImageService, 'show', self.fake_show) @@ -5867,11 +5867,11 @@ class ComputeAPITestCase(BaseTestCase): instance = jsonutils.to_primitive( self._create_fake_instance(params={'image_ref': '1'})) - def fake_extract_instance_type(_inst): + def fake_extract_flavor(_inst): return dict(memory_mb=64, root_gb=1) - self.stubs.Set(flavors, 'extract_instance_type', - fake_extract_instance_type) + self.stubs.Set(flavors, 'extract_flavor', + fake_extract_flavor) self.fake_image['min_disk'] = 2 self.stubs.Set(fake_image._FakeImageService, 'show', self.fake_show) @@ -5891,11 +5891,11 @@ class ComputeAPITestCase(BaseTestCase): instance = jsonutils.to_primitive( self._create_fake_instance(params={'image_ref': '1'})) - def fake_extract_instance_type(_inst): + def fake_extract_flavor(_inst): return dict(memory_mb=64, root_gb=1) - self.stubs.Set(flavors, 'extract_instance_type', - fake_extract_instance_type) + self.stubs.Set(flavors, 'extract_flavor', + fake_extract_flavor) self.fake_image['min_ram'] = 64 self.fake_image['min_disk'] = 1 @@ -5909,11 +5909,11 @@ class ComputeAPITestCase(BaseTestCase): instance = jsonutils.to_primitive( self._create_fake_instance(params={'image_ref': '1'})) - def fake_extract_instance_type(_inst): + def fake_extract_flavor(_inst): return dict(memory_mb=64, root_gb=1) - self.stubs.Set(flavors, 'extract_instance_type', - fake_extract_instance_type) + self.stubs.Set(flavors, 'extract_flavor', + fake_extract_flavor) self.stubs.Set(fake_image._FakeImageService, 'show', self.fake_show) self.compute_api.rebuild(self.context, @@ -5924,11 +5924,11 @@ class ComputeAPITestCase(BaseTestCase): instance = jsonutils.to_primitive( self._create_fake_instance(params={'image_ref': '1'})) - def fake_extract_instance_type(_inst): + def fake_extract_flavor(_inst): return dict(memory_mb=64, root_gb=1) - self.stubs.Set(flavors, 'extract_instance_type', - fake_extract_instance_type) + self.stubs.Set(flavors, 'extract_flavor', + fake_extract_flavor) self.fake_image['size'] = '1073741825' self.stubs.Set(fake_image._FakeImageService, 'show', self.fake_show) @@ -6070,7 +6070,7 @@ class ComputeAPITestCase(BaseTestCase): def test_hostname_create(self): # Ensure instance hostname is set during creation. - inst_type = flavors.get_instance_type_by_name('m1.tiny') + inst_type = flavors.get_flavor_by_name('m1.tiny') (instances, _) = self.compute_api.create(self.context, inst_type, None, @@ -6233,7 +6233,7 @@ class ComputeAPITestCase(BaseTestCase): {'extra_param': 'value1'}) self.assertEqual(image['name'], 'snap1') - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) self.assertEqual(image['min_ram'], self.fake_image['min_ram']) self.assertEqual(image['min_disk'], instance_type['root_gb']) properties = image['properties'] @@ -6461,15 +6461,15 @@ class ComputeAPITestCase(BaseTestCase): self.compute_api.resize(self.context, instance, '4') # Do the prep/finish_resize steps (manager does this) - old_type = flavors.extract_instance_type(instance) - new_type = flavors.get_instance_type_by_flavor_id('4') + old_type = flavors.extract_flavor(instance) + new_type = flavors.get_flavor_by_flavor_id('4') sys_meta = utils.metadata_to_dict(instance['system_metadata']) - sys_meta = flavors.save_instance_type_info(sys_meta, - old_type, 'old_') - sys_meta = flavors.save_instance_type_info(sys_meta, - new_type, 'new_') - sys_meta = flavors.save_instance_type_info(sys_meta, - new_type) + sys_meta = flavors.save_flavor_info(sys_meta, + old_type, 'old_') + sys_meta = flavors.save_flavor_info(sys_meta, + new_type, 'new_') + sys_meta = flavors.save_flavor_info(sys_meta, + new_type) # create a fake migration record (manager does this) db.migration_create(self.context.elevated(), @@ -6580,7 +6580,7 @@ class ComputeAPITestCase(BaseTestCase): self.compute.run_instance(self.context, instance=instance) old_instance_type_id = instance['instance_type_id'] - new_flavor = flavors.get_instance_type_by_name('m1.tiny') + new_flavor = flavors.get_flavor_by_name('m1.tiny') new_flavorid = new_flavor['flavorid'] new_instance_type_id = new_flavor['id'] self.compute_api.resize(self.context, instance, new_flavorid) @@ -6657,7 +6657,7 @@ class ComputeAPITestCase(BaseTestCase): instance = self._create_fake_instance(dict(host='host2')) instance = db.instance_get_by_uuid(self.context, instance['uuid']) instance = jsonutils.to_primitive(instance) - orig_instance_type = flavors.extract_instance_type(instance) + orig_instance_type = flavors.extract_flavor(instance) self.compute.run_instance(self.context, instance=instance) # We need to set the host to something 'known'. Unfortunately, # the compute manager is using a cached copy of CONF.host, @@ -7220,7 +7220,7 @@ class ComputeAPITestCase(BaseTestCase): self.assertThat(bdms, matchers.DictListMatches(expected_result)) self.compute_api._update_block_device_mapping( - self.context, flavors.get_default_instance_type(), + self.context, flavors.get_default_flavor(), instance['uuid'], block_device_mapping) bdms = [self._parse_db_block_device_mapping(bdm_ref) for bdm_ref in block_device.legacy_mapping( @@ -7331,7 +7331,7 @@ class ComputeAPITestCase(BaseTestCase): """Verify building an instance has a reservation_id that matches return value from create""" (refs, resv_id) = self.compute_api.create(self.context, - flavors.get_default_instance_type(), None) + flavors.get_default_flavor(), None) try: self.assertEqual(len(refs), 1) self.assertEqual(refs[0]['reservation_id'], resv_id) @@ -7344,7 +7344,7 @@ class ComputeAPITestCase(BaseTestCase): in both instances """ (refs, resv_id) = self.compute_api.create(self.context, - flavors.get_default_instance_type(), None, + flavors.get_default_flavor(), None, min_count=2, max_count=2) try: self.assertEqual(len(refs), 2) @@ -7358,7 +7358,7 @@ class ComputeAPITestCase(BaseTestCase): def test_multi_instance_display_name_template(self): self.flags(multi_instance_display_name_template='%(name)s') (refs, resv_id) = self.compute_api.create(self.context, - flavors.get_default_instance_type(), None, + flavors.get_default_flavor(), None, min_count=2, max_count=2, display_name='x') self.assertEqual(refs[0]['display_name'], 'x') self.assertEqual(refs[0]['hostname'], 'x') @@ -7367,7 +7367,7 @@ class ComputeAPITestCase(BaseTestCase): self.flags(multi_instance_display_name_template='%(name)s-%(count)s') (refs, resv_id) = self.compute_api.create(self.context, - flavors.get_default_instance_type(), None, + flavors.get_default_flavor(), None, min_count=2, max_count=2, display_name='x') self.assertEqual(refs[0]['display_name'], 'x-1') self.assertEqual(refs[0]['hostname'], 'x-1') @@ -7376,7 +7376,7 @@ class ComputeAPITestCase(BaseTestCase): self.flags(multi_instance_display_name_template='%(name)s-%(uuid)s') (refs, resv_id) = self.compute_api.create(self.context, - flavors.get_default_instance_type(), None, + flavors.get_default_flavor(), None, min_count=2, max_count=2, display_name='x') self.assertEqual(refs[0]['display_name'], 'x-%s' % refs[0]['uuid']) self.assertEqual(refs[0]['hostname'], 'x-%s' % refs[0]['uuid']) @@ -8074,7 +8074,7 @@ class ComputeAPITestCase(BaseTestCase): inst['project_id'] = self.project_id inst['host'] = 'fake_host' inst['node'] = NODENAME - type_id = flavors.get_instance_type_by_name('m1.tiny')['id'] + type_id = flavors.get_flavor_by_name('m1.tiny')['id'] inst['instance_type_id'] = type_id inst['ami_launch_index'] = 0 inst['memory_mb'] = 0 @@ -8465,7 +8465,7 @@ class DisabledInstanceTypesTestCase(BaseTestCase): def setUp(self): super(DisabledInstanceTypesTestCase, self).setUp() self.compute_api = compute.API() - self.inst_type = flavors.get_default_instance_type() + self.inst_type = flavors.get_default_flavor() def test_can_build_instance_from_visible_instance_type(self): self.inst_type['disabled'] = False @@ -8479,19 +8479,19 @@ class DisabledInstanceTypesTestCase(BaseTestCase): def test_can_resize_to_visible_instance_type(self): instance = self._create_fake_instance() - orig_get_instance_type_by_flavor_id =\ - flavors.get_instance_type_by_flavor_id + orig_get_flavor_by_flavor_id =\ + flavors.get_flavor_by_flavor_id - def fake_get_instance_type_by_flavor_id(flavor_id, ctxt=None, + def fake_get_flavor_by_flavor_id(flavor_id, ctxt=None, read_deleted="yes"): - instance_type = orig_get_instance_type_by_flavor_id(flavor_id, + instance_type = orig_get_flavor_by_flavor_id(flavor_id, ctxt, read_deleted) instance_type['disabled'] = False return instance_type - self.stubs.Set(flavors, 'get_instance_type_by_flavor_id', - fake_get_instance_type_by_flavor_id) + self.stubs.Set(flavors, 'get_flavor_by_flavor_id', + fake_get_flavor_by_flavor_id) # FIXME(sirp): for legacy this raises FlavorNotFound instead of # InstanceTypeNotFound; we should eventually make it raise @@ -8500,19 +8500,19 @@ class DisabledInstanceTypesTestCase(BaseTestCase): def test_cannot_resize_to_disabled_instance_type(self): instance = self._create_fake_instance() - orig_get_instance_type_by_flavor_id = \ - flavors.get_instance_type_by_flavor_id + orig_get_flavor_by_flavor_id = \ + flavors.get_flavor_by_flavor_id - def fake_get_instance_type_by_flavor_id(flavor_id, ctxt=None, + def fake_get_flavor_by_flavor_id(flavor_id, ctxt=None, read_deleted="yes"): - instance_type = orig_get_instance_type_by_flavor_id(flavor_id, + instance_type = orig_get_flavor_by_flavor_id(flavor_id, ctxt, read_deleted) instance_type['disabled'] = True return instance_type - self.stubs.Set(flavors, 'get_instance_type_by_flavor_id', - fake_get_instance_type_by_flavor_id) + self.stubs.Set(flavors, 'get_flavor_by_flavor_id', + fake_get_flavor_by_flavor_id) # FIXME(sirp): for legacy this raises FlavorNotFound instead of # InstanceTypeNot; we should eventually make it raise @@ -8805,7 +8805,7 @@ class ComputeRescheduleResizeOrReraiseTestCase(BaseTestCase): super(ComputeRescheduleResizeOrReraiseTestCase, self).setUp() self.instance = self._create_fake_instance() self.instance_uuid = self.instance['uuid'] - self.instance_type = flavors.get_instance_type_by_name( + self.instance_type = flavors.get_flavor_by_name( "m1.tiny") def test_reschedule_resize_or_reraise_called(self): @@ -8912,7 +8912,7 @@ class ComputeInactiveImageTestCase(BaseTestCase): def test_create_instance_with_deleted_image(self): # Make sure we can't start an instance with a deleted image. - inst_type = flavors.get_instance_type_by_name('m1.tiny') + inst_type = flavors.get_flavor_by_name('m1.tiny') self.assertRaises(exception.ImageNotActive, self.compute_api.create, self.context, inst_type, 'fake-image-uuid') @@ -9202,7 +9202,7 @@ class CheckRequestedImageTestCase(test.TestCase): self.context = context.RequestContext( 'fake_user_id', 'fake_project_id') - self.instance_type = flavors.get_default_instance_type() + self.instance_type = flavors.get_default_flavor() self.instance_type['memory_mb'] = 64 self.instance_type['root_gb'] = 1 diff --git a/nova/tests/compute/test_compute_utils.py b/nova/tests/compute/test_compute_utils.py index 84dd67eb5..12c007963 100644 --- a/nova/tests/compute/test_compute_utils.py +++ b/nova/tests/compute/test_compute_utils.py @@ -185,7 +185,7 @@ class ComputeValidateDeviceTestCase(test.TestCase): 'ephemeral_gb': 10, 'swap': 0, }) - self.stubs.Set(flavors, 'get_instance_type', + self.stubs.Set(flavors, 'get_flavor', lambda instance_type_id, ctxt=None: self.instance_type) device = self._validate_device() self.assertEqual(device, '/dev/xvdc') @@ -195,7 +195,7 @@ class ComputeValidateDeviceTestCase(test.TestCase): 'ephemeral_gb': 0, 'swap': 10, }) - self.stubs.Set(flavors, 'get_instance_type', + self.stubs.Set(flavors, 'get_flavor', lambda instance_type_id, ctxt=None: self.instance_type) device = self._validate_device() self.assertEqual(device, '/dev/xvdb') @@ -205,7 +205,7 @@ class ComputeValidateDeviceTestCase(test.TestCase): 'ephemeral_gb': 10, 'swap': 10, }) - self.stubs.Set(flavors, 'get_instance_type', + self.stubs.Set(flavors, 'get_flavor', lambda instance_type_id, ctxt=None: self.instance_type) device = self._validate_device() self.assertEqual(device, '/dev/xvdd') @@ -215,7 +215,7 @@ class ComputeValidateDeviceTestCase(test.TestCase): 'ephemeral_gb': 0, 'swap': 10, }) - self.stubs.Set(flavors, 'get_instance_type', + self.stubs.Set(flavors, 'get_flavor', lambda instance_type_id, ctxt=None: self.instance_type) device = self._validate_device() self.assertEqual(device, '/dev/xvdb') @@ -258,8 +258,8 @@ class UsageInfoTestCase(test.TestCase): def _create_instance(self, params={}): """Create a test instance.""" - instance_type = flavors.get_instance_type_by_name('m1.tiny') - sys_meta = flavors.save_instance_type_info({}, instance_type) + instance_type = flavors.get_flavor_by_name('m1.tiny') + sys_meta = flavors.save_flavor_info({}, instance_type) inst = {} inst['image_ref'] = 1 inst['reservation_id'] = 'r-fakeres' @@ -294,7 +294,7 @@ class UsageInfoTestCase(test.TestCase): self.assertEquals(payload['user_id'], self.user_id) self.assertEquals(payload['instance_id'], instance['uuid']) self.assertEquals(payload['instance_type'], 'm1.tiny') - type_id = flavors.get_instance_type_by_name('m1.tiny')['id'] + type_id = flavors.get_flavor_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', @@ -330,7 +330,7 @@ class UsageInfoTestCase(test.TestCase): self.assertEquals(payload['user_id'], self.user_id) self.assertEquals(payload['instance_id'], instance['uuid']) self.assertEquals(payload['instance_type'], 'm1.tiny') - type_id = flavors.get_instance_type_by_name('m1.tiny')['id'] + type_id = flavors.get_flavor_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', @@ -357,7 +357,7 @@ class UsageInfoTestCase(test.TestCase): self.assertEquals(payload['user_id'], self.user_id) self.assertEquals(payload['instance_id'], instance['uuid']) self.assertEquals(payload['instance_type'], 'm1.tiny') - type_id = flavors.get_instance_type_by_name('m1.tiny')['id'] + type_id = flavors.get_flavor_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', @@ -393,7 +393,7 @@ class UsageInfoTestCase(test.TestCase): self.assertEquals(payload['user_id'], self.user_id) self.assertEquals(payload['instance_id'], instance['uuid']) self.assertEquals(payload['instance_type'], 'm1.tiny') - type_id = flavors.get_instance_type_by_name('m1.tiny')['id'] + type_id = flavors.get_flavor_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', 'image_meta'): diff --git a/nova/tests/compute/test_resource_tracker.py b/nova/tests/compute/test_resource_tracker.py index 43bed38ba..e8514cc8e 100644 --- a/nova/tests/compute/test_resource_tracker.py +++ b/nova/tests/compute/test_resource_tracker.py @@ -112,7 +112,7 @@ class BaseTestCase(test.TestCase): 'instance_update_and_get_original', self._fake_instance_update_and_get_original) self.stubs.Set(self.conductor.db, - 'instance_type_get', self._fake_instance_type_get) + 'instance_type_get', self._fake_flavor_get) self.host = 'fakehost' @@ -153,7 +153,7 @@ class BaseTestCase(test.TestCase): def _fake_instance_system_metadata(self, instance_type, prefix=''): sys_meta = [] - for key in flavors.system_metadata_instance_type_props.keys(): + for key in flavors.system_metadata_flavor_props.keys(): sys_meta.append({'key': '%sinstance_type_%s' % (prefix, key), 'value': instance_type[key]}) return sys_meta @@ -162,7 +162,7 @@ class BaseTestCase(test.TestCase): # Default to an instance ready to resize to or from the same # instance_type - itype = self._fake_instance_type_create() + itype = self._fake_flavor_create() sys_meta = self._fake_instance_system_metadata(itype) if stash: @@ -193,7 +193,7 @@ class BaseTestCase(test.TestCase): self._instances[instance_uuid] = instance return instance - def _fake_instance_type_create(self, **kwargs): + def _fake_flavor_create(self, **kwargs): instance_type = { 'id': 1, 'name': 'fakeitype', @@ -215,7 +215,7 @@ class BaseTestCase(test.TestCase): def _fake_instance_get_all_by_host_and_node(self, context, host, nodename): return [i for i in self._instances.values() if i['host'] == host] - def _fake_instance_type_get(self, ctxt, id_): + def _fake_flavor_get(self, ctxt, id_): return self._instance_types[id_] def _fake_instance_update_and_get_original(self, context, instance_uuid, @@ -286,7 +286,7 @@ class UnsupportedDriverTestCase(BaseTestCase): def test_disabled_resize_claim(self): instance = self._fake_instance() - instance_type = self._fake_instance_type_create() + instance_type = self._fake_flavor_create() claim = self.tracker.resize_claim(self.context, instance, instance_type) self.assertEqual(0, claim.memory_mb) @@ -296,7 +296,7 @@ class UnsupportedDriverTestCase(BaseTestCase): def test_disabled_resize_context_claim(self): instance = self._fake_instance() - instance_type = self._fake_instance_type_create() + instance_type = self._fake_flavor_create() with self.tracker.resize_claim(self.context, instance, instance_type) \ as claim: self.assertEqual(0, claim.memory_mb) @@ -666,7 +666,7 @@ class ResizeClaimTestCase(BaseTrackerTestCase): 'migration_create', self._fake_migration_create) self.instance = self._fake_instance() - self.instance_type = self._fake_instance_type_create() + self.instance_type = self._fake_flavor_create() def _fake_migration_create(self, context, values=None): instance_uuid = str(uuid.uuid1()) @@ -737,9 +737,9 @@ class ResizeClaimTestCase(BaseTrackerTestCase): def test_same_host(self): self.limits['vcpu'] = 3 - src_type = self._fake_instance_type_create(id=2, memory_mb=1, + src_type = self._fake_flavor_create(id=2, memory_mb=1, root_gb=1, ephemeral_gb=0, vcpus=1) - dest_type = self._fake_instance_type_create(id=2, memory_mb=2, + dest_type = self._fake_flavor_create(id=2, memory_mb=2, root_gb=2, ephemeral_gb=1, vcpus=2) # make an instance of src_type: @@ -848,7 +848,7 @@ class ResizeClaimTestCase(BaseTrackerTestCase): self.assertTrue(self.tracker._instance_in_resize_state(instance)) def test_dupe_filter(self): - self._fake_instance_type_create(id=2, memory_mb=1, root_gb=1, + self._fake_flavor_create(id=2, memory_mb=1, root_gb=1, ephemeral_gb=1, vcpus=1) instance = self._fake_instance(host=self.host) diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py index e5abd1182..03896ee3a 100644 --- a/nova/tests/conductor/test_conductor.py +++ b/nova/tests/conductor/test_conductor.py @@ -79,7 +79,7 @@ class _BaseTestCase(object): inst['user_id'] = self.user_id inst['project_id'] = self.project_id inst['host'] = 'fake_host' - type_id = flavors.get_instance_type_by_name(type_name)['id'] + type_id = flavors.get_flavor_by_name(type_name)['id'] inst['instance_type_id'] = type_id inst['ami_launch_index'] = 0 inst['memory_mb'] = 0 @@ -357,7 +357,7 @@ class _BaseTestCase(object): fake_instance, fake_values) - def test_instance_type_get(self): + def test_flavor_get(self): self.mox.StubOutWithMock(db, 'instance_type_get') db.instance_type_get(self.context, 'fake-id').AndReturn('fake-type') self.mox.ReplayAll() @@ -1197,11 +1197,11 @@ class _BaseTaskTestCase(object): self.context, None, None, True, False, "dummy", None, None) def test_build_instances(self): - instance_type = flavors.get_default_instance_type() - system_metadata = flavors.save_instance_type_info({}, instance_type) + instance_type = flavors.get_default_flavor() + system_metadata = flavors.save_flavor_info({}, instance_type) # NOTE(alaski): instance_type -> system_metadata -> instance_type loses # some data (extra_specs) so we need both for testing. - instance_type_extract = flavors.extract_instance_type( + instance_type_extract = flavors.extract_flavor( {'system_metadata': system_metadata}) self.mox.StubOutWithMock(self.conductor_manager.scheduler_rpcapi, 'run_instance') diff --git a/nova/tests/network/test_api.py b/nova/tests/network/test_api.py index 871d26616..13bc3ce67 100644 --- a/nova/tests/network/test_api.py +++ b/nova/tests/network/test_api.py @@ -81,9 +81,9 @@ class ApiTestCase(test.TestCase): self.network_api.network_rpcapi.allocate_for_instance( mox.IgnoreArg(), **kwargs).AndReturn([]) self.mox.ReplayAll() - inst_type = flavors.get_default_instance_type() + inst_type = flavors.get_default_flavor() inst_type['rxtx_factor'] = 0 - sys_meta = flavors.save_instance_type_info({}, inst_type) + sys_meta = flavors.save_flavor_info({}, inst_type) instance = dict(id='id', uuid='uuid', project_id='project_id', host='host', system_metadata=utils.dict_to_metadata(sys_meta)) self.network_api.allocate_for_instance( @@ -140,10 +140,10 @@ class ApiTestCase(test.TestCase): self._do_test_associate_floating_ip(None) def _stub_migrate_instance_calls(self, method, multi_host, info): - fake_instance_type = flavors.get_default_instance_type() + fake_instance_type = flavors.get_default_flavor() fake_instance_type['rxtx_factor'] = 1.21 sys_meta = utils.dict_to_metadata( - flavors.save_instance_type_info({}, fake_instance_type)) + flavors.save_flavor_info({}, fake_instance_type)) fake_instance = {'uuid': 'fake_uuid', 'instance_type_id': fake_instance_type['id'], 'project_id': 'fake_project_id', diff --git a/nova/tests/network/test_quantumv2.py b/nova/tests/network/test_quantumv2.py index 3a2b8a7c4..0b6f184ae 100644 --- a/nova/tests/network/test_quantumv2.py +++ b/nova/tests/network/test_quantumv2.py @@ -402,10 +402,10 @@ class TestQuantumv2(test.TestCase): self.moxed_client.list_extensions().AndReturn( {'extensions': [{'name': 'nvp-qos'}]}) self.mox.ReplayAll() - instance_type = flavors.get_default_instance_type() + instance_type = flavors.get_default_flavor() instance_type['rxtx_factor'] = 1 sys_meta = utils.dict_to_metadata( - flavors.save_instance_type_info({}, instance_type)) + flavors.save_flavor_info({}, instance_type)) instance = {'system_metadata': sys_meta} port_req_body = {'port': {}} api._populate_quantum_extension_values(instance, port_req_body) diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py index 44ddcc7a6..5663f1378 100644 --- a/nova/tests/scheduler/test_scheduler.py +++ b/nova/tests/scheduler/test_scheduler.py @@ -443,7 +443,7 @@ class SchedulerTestCase(test.NoDBTestCase): 'vcpu_weight': None, 'id': 1} sys_meta = utils.dict_to_metadata( - flavors.save_instance_type_info({}, inst_type)) + flavors.save_flavor_info({}, inst_type)) return {'id': 31337, 'uuid': 'fake_uuid', 'name': 'fake-instance', @@ -792,7 +792,7 @@ class SchedulerTestCase(test.NoDBTestCase): # Confirm dest is picked by scheduler if not set. self.mox.StubOutWithMock(self.driver, 'select_hosts') - self.mox.StubOutWithMock(flavors, 'extract_instance_type') + self.mox.StubOutWithMock(flavors, 'extract_flavor') request_spec = {'instance_properties': instance, 'instance_type': {}, @@ -803,7 +803,7 @@ class SchedulerTestCase(test.NoDBTestCase): ignore_hosts = [instance['host']] filter_properties = {'ignore_hosts': ignore_hosts} - flavors.extract_instance_type(instance).AndReturn({}) + flavors.extract_flavor(instance).AndReturn({}) self.driver.select_hosts(self.context, request_spec, filter_properties).AndReturn(['fake_host2']) @@ -818,7 +818,7 @@ class SchedulerTestCase(test.NoDBTestCase): # Confirm dest is picked by scheduler if not set. self.mox.StubOutWithMock(self.driver, 'select_hosts') - self.mox.StubOutWithMock(flavors, 'extract_instance_type') + self.mox.StubOutWithMock(flavors, 'extract_flavor') request_spec = {'instance_properties': instance, 'instance_type': {}, @@ -828,7 +828,7 @@ class SchedulerTestCase(test.NoDBTestCase): ignore_hosts = [instance['host']] filter_properties = {'ignore_hosts': ignore_hosts} - flavors.extract_instance_type(instance).AndReturn({}) + flavors.extract_flavor(instance).AndReturn({}) self.driver.select_hosts(self.context, request_spec, filter_properties).AndReturn(['fake_host2']) @@ -841,7 +841,7 @@ class SchedulerTestCase(test.NoDBTestCase): instance = self._live_migration_instance() # Confirm scheduler picks target host if none given. - self.mox.StubOutWithMock(flavors, 'extract_instance_type') + self.mox.StubOutWithMock(flavors, 'extract_flavor') self.mox.StubOutWithMock(self.driver, '_live_migration_src_check') self.mox.StubOutWithMock(self.driver, 'select_hosts') self.mox.StubOutWithMock(self.driver, '_live_migration_common_check') @@ -860,7 +860,7 @@ class SchedulerTestCase(test.NoDBTestCase): self.driver._live_migration_src_check(self.context, instance) - flavors.extract_instance_type( + flavors.extract_flavor( instance).MultipleTimes().AndReturn({}) # First selected host raises exception.InvalidHypervisorType diff --git a/nova/tests/test_instance_types.py b/nova/tests/test_flavors.py index d8a915730..bd3f805cd 100644 --- a/nova/tests/test_instance_types.py +++ b/nova/tests/test_flavors.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. """ -Unit Tests for instance types code +Unit Tests for flavors code """ import time @@ -27,11 +27,11 @@ from nova import test class InstanceTypeTestCase(test.TestCase): - """Test cases for instance type code.""" + """Test cases for flavor code.""" def _generate_name(self): """return a name not in the DB.""" nonexistent_flavor = str(int(time.time())) - all_flavors = flavors.get_all_types() + all_flavors = flavors.get_all_flavors() while nonexistent_flavor in all_flavors: nonexistent_flavor += "z" else: @@ -41,15 +41,15 @@ class InstanceTypeTestCase(test.TestCase): """return a flavorid not in the DB.""" nonexistent_flavor = 2700 flavor_ids = [value["id"] for key, value in - flavors.get_all_types().iteritems()] + flavors.get_all_flavors().iteritems()] while nonexistent_flavor in flavor_ids: nonexistent_flavor += 1 else: return nonexistent_flavor def _existing_flavor(self): - """return first instance type name.""" - return flavors.get_all_types().keys()[0] + """return first flavor name.""" + return flavors.get_all_flavors().keys()[0] def test_add_instance_type_access(self): user_id = 'fake' @@ -58,51 +58,51 @@ class InstanceTypeTestCase(test.TestCase): flavor_id = 'flavor1' type_ref = flavors.create('some flavor', 256, 1, 120, 100, flavorid=flavor_id) - access_ref = flavors.add_instance_type_access(flavor_id, + access_ref = flavors.add_flavor_access(flavor_id, project_id, ctxt=ctxt) self.assertEqual(access_ref["project_id"], project_id) self.assertEqual(access_ref["instance_type_id"], type_ref["id"]) - def test_add_instance_type_access_already_exists(self): + def test_add_flavor_access_already_exists(self): user_id = 'fake' project_id = 'fake' ctxt = context.RequestContext(user_id, project_id, is_admin=True) flavor_id = 'flavor1' type_ref = flavors.create('some flavor', 256, 1, 120, 100, flavorid=flavor_id) - access_ref = flavors.add_instance_type_access(flavor_id, + access_ref = flavors.add_flavor_access(flavor_id, project_id, ctxt=ctxt) self.assertRaises(exception.FlavorAccessExists, - flavors.add_instance_type_access, + flavors.add_flavor_access, flavor_id, project_id, ctxt) - def test_add_instance_type_access_invalid_flavor(self): + def test_add_flavor_access_invalid_flavor(self): user_id = 'fake' project_id = 'fake' ctxt = context.RequestContext(user_id, project_id, is_admin=True) flavor_id = 'no_such_flavor' self.assertRaises(exception.FlavorNotFound, - flavors.add_instance_type_access, + flavors.add_flavor_access, flavor_id, project_id, ctxt) - def test_remove_instance_type_access(self): + def test_remove_flavor_access(self): user_id = 'fake' project_id = 'fake' ctxt = context.RequestContext(user_id, project_id, is_admin=True) flavor_id = 'flavor1' type_ref = flavors.create('some flavor', 256, 1, 120, 100, flavorid=flavor_id) - access_ref = flavors.add_instance_type_access(flavor_id, project_id, + access_ref = flavors.add_flavor_access(flavor_id, project_id, ctxt) - flavors.remove_instance_type_access(flavor_id, project_id, ctxt) + flavors.remove_flavor_access(flavor_id, project_id, ctxt) - projects = flavors.get_instance_type_access_by_flavor_id(flavor_id, + projects = flavors.get_flavor_access_by_flavor_id(flavor_id, ctxt) self.assertEqual([], projects) - def test_remove_instance_type_access_doesnt_exists(self): + def test_remove_flavor_access_doesnt_exists(self): user_id = 'fake' project_id = 'fake' ctxt = context.RequestContext(user_id, project_id, is_admin=True) @@ -110,18 +110,18 @@ class InstanceTypeTestCase(test.TestCase): type_ref = flavors.create('some flavor', 256, 1, 120, 100, flavorid=flavor_id) self.assertRaises(exception.FlavorAccessNotFound, - flavors.remove_instance_type_access, + flavors.remove_flavor_access, flavor_id, project_id, ctxt=ctxt) def test_get_all_instance_types(self): - # Ensures that all instance types can be retrieved. + # Ensures that all flavors can be retrieved. session = sql_session.get_session() total_instance_types = session.query(models.InstanceTypes).count() - inst_types = flavors.get_all_types() + inst_types = flavors.get_all_flavors() self.assertEqual(total_instance_types, len(inst_types)) def test_non_existent_inst_type_shouldnt_delete(self): - # Ensures that instance type creation fails with invalid args. + # Ensures that flavor creation fails with invalid args. self.assertRaises(exception.InstanceTypeNotFoundByName, flavors.destroy, 'unknown_flavor') @@ -132,52 +132,52 @@ class InstanceTypeTestCase(test.TestCase): flavors.destroy, None) def test_will_not_get_bad_default_instance_type(self): - # ensures error raised on bad default instance type. - self.flags(default_instance_type='unknown_flavor') + # ensures error raised on bad default flavor. + self.flags(default_flavor='unknown_flavor') self.assertRaises(exception.InstanceTypeNotFound, - flavors.get_default_instance_type) + flavors.get_default_flavor) - def test_will_get_instance_type_by_id(self): - default_instance_type = flavors.get_default_instance_type() + def test_will_get_flavor_by_id(self): + default_instance_type = flavors.get_default_flavor() instance_type_id = default_instance_type['id'] - fetched = flavors.get_instance_type(instance_type_id) + fetched = flavors.get_flavor(instance_type_id) self.assertEqual(default_instance_type, fetched) - def test_will_not_get_instance_type_by_unknown_id(self): + def test_will_not_get_flavor_by_unknown_id(self): # Ensure get by name returns default flavor with no name. self.assertRaises(exception.InstanceTypeNotFound, - flavors.get_instance_type, 10000) + flavors.get_flavor, 10000) - def test_will_not_get_instance_type_with_bad_id(self): + def test_will_not_get_flavor_with_bad_id(self): # Ensure get by name returns default flavor with bad name. self.assertRaises(exception.InstanceTypeNotFound, - flavors.get_instance_type, 'asdf') + flavors.get_flavor, 'asdf') - def test_instance_type_get_by_None_name_returns_default(self): + def test_flavor_get_by_None_name_returns_default(self): # Ensure get by name returns default flavor with no name. - default = flavors.get_default_instance_type() - actual = flavors.get_instance_type_by_name(None) + default = flavors.get_default_flavor() + actual = flavors.get_flavor_by_name(None) self.assertEqual(default, actual) - def test_will_not_get_instance_type_with_bad_name(self): + def test_will_not_get_flavor_with_bad_name(self): # Ensure get by name returns default flavor with bad name. self.assertRaises(exception.InstanceTypeNotFound, - flavors.get_instance_type_by_name, 10000) + flavors.get_flavor_by_name, 10000) def test_will_not_get_instance_by_unknown_flavor_id(self): # Ensure get by flavor raises error with wrong flavorid. self.assertRaises(exception.FlavorNotFound, - flavors.get_instance_type_by_flavor_id, + flavors.get_flavor_by_flavor_id, 'unknown_flavor') def test_will_get_instance_by_flavor_id(self): - default_instance_type = flavors.get_default_instance_type() + default_instance_type = flavors.get_default_flavor() flavorid = default_instance_type['flavorid'] - fetched = flavors.get_instance_type_by_flavor_id(flavorid) + fetched = flavors.get_flavor_by_flavor_id(flavorid) self.assertEqual(default_instance_type, fetched) def test_can_read_deleted_types_using_flavor_id(self): - # Ensure deleted instance types can be read when querying flavor_id. + # Ensure deleted flavors can be read when querying flavor_id. inst_type_name = "test" inst_type_flavor_id = "test1" @@ -186,16 +186,16 @@ class InstanceTypeTestCase(test.TestCase): self.assertEqual(inst_type_name, inst_type["name"]) # NOTE(jk0): The deleted flavor will show up here because the context - # in get_instance_type_by_flavor_id() is set to use read_deleted by + # in get_flavor_by_flavor_id() is set to use read_deleted by # default. flavors.destroy(inst_type["name"]) - deleted_inst_type = flavors.get_instance_type_by_flavor_id( + deleted_inst_type = flavors.get_flavor_by_flavor_id( inst_type_flavor_id) self.assertEqual(inst_type_name, deleted_inst_type["name"]) def test_read_deleted_false_converting_flavorid(self): """ - Ensure deleted instance types are not returned when not needed (for + Ensure deleted flavors are not returned when not needed (for example when creating a server and attempting to translate from flavorid to instance_type_id. """ @@ -203,7 +203,7 @@ class InstanceTypeTestCase(test.TestCase): flavors.destroy("instance_type1") flavors.create("instance_type1_redo", 256, 1, 120, 100, "test1") - instance_type = flavors.get_instance_type_by_flavor_id( + instance_type = flavors.get_flavor_by_flavor_id( "test1", read_deleted="no") self.assertEqual("instance_type1_redo", instance_type["name"]) @@ -212,52 +212,52 @@ class InstanceTypeToolsTest(test.TestCase): def _dict_to_metadata(self, data): return [{'key': key, 'value': value} for key, value in data.items()] - def _test_extract_instance_type(self, prefix): - instance_type = flavors.get_default_instance_type() + def _test_extract_flavor(self, prefix): + instance_type = flavors.get_default_flavor() metadata = {} - flavors.save_instance_type_info(metadata, instance_type, + flavors.save_flavor_info(metadata, instance_type, prefix) instance = {'system_metadata': self._dict_to_metadata(metadata)} - _instance_type = flavors.extract_instance_type(instance, prefix) + _instance_type = flavors.extract_flavor(instance, prefix) - props = flavors.system_metadata_instance_type_props.keys() + props = flavors.system_metadata_flavor_props.keys() for key in instance_type.keys(): if key not in props: del instance_type[key] self.assertEqual(instance_type, _instance_type) - def test_extract_instance_type(self): - self._test_extract_instance_type('') + def test_extract_flavor(self): + self._test_extract_flavor('') - def test_extract_instance_type_prefix(self): - self._test_extract_instance_type('foo_') + def test_extract_flavor_prefix(self): + self._test_extract_flavor('foo_') - def test_save_instance_type_info(self): - instance_type = flavors.get_default_instance_type() + def test_save_flavor_info(self): + instance_type = flavors.get_default_flavor() example = {} example_prefix = {} - for key in flavors.system_metadata_instance_type_props.keys(): + for key in flavors.system_metadata_flavor_props.keys(): example['instance_type_%s' % key] = instance_type[key] example_prefix['fooinstance_type_%s' % key] = instance_type[key] metadata = {} - flavors.save_instance_type_info(metadata, instance_type) + flavors.save_flavor_info(metadata, instance_type) self.assertEqual(example, metadata) metadata = {} - flavors.save_instance_type_info(metadata, instance_type, 'foo') + flavors.save_flavor_info(metadata, instance_type, 'foo') self.assertEqual(example_prefix, metadata) - def test_delete_instance_type_info(self): - instance_type = flavors.get_default_instance_type() + def test_delete_flavor_info(self): + instance_type = flavors.get_default_flavor() metadata = {} - flavors.save_instance_type_info(metadata, instance_type) - flavors.save_instance_type_info(metadata, instance_type, '_') - flavors.delete_instance_type_info(metadata, '', '_') + flavors.save_flavor_info(metadata, instance_type) + flavors.save_flavor_info(metadata, instance_type, '_') + flavors.delete_flavor_info(metadata, '', '_') self.assertEqual(metadata, {}) @@ -391,7 +391,7 @@ class CreateInstanceTypeTest(test.TestCase): def test_basic_create(self): # Ensure instance types can be created. - original_list = flavors.get_all_types() + original_list = flavors.get_all_flavors() # Create new type and make sure values stick flavor = flavors.create('flavor', 64, 1, 120) @@ -401,26 +401,26 @@ class CreateInstanceTypeTest(test.TestCase): self.assertEqual(flavor['root_gb'], 120) # Ensure new type shows up in list - new_list = flavors.get_all_types() + new_list = flavors.get_all_flavors() self.assertNotEqual(len(original_list), len(new_list), 'flavor was not created') def test_create_then_delete(self): - original_list = flavors.get_all_types() + original_list = flavors.get_all_flavors() flavor = flavors.create('flavor', 64, 1, 120) # Ensure new type shows up in list - new_list = flavors.get_all_types() + new_list = flavors.get_all_flavors() self.assertNotEqual(len(original_list), len(new_list), 'instance type was not created') flavors.destroy('flavor') self.assertRaises(exception.InstanceTypeNotFound, - flavors.get_instance_type, flavor['id']) + flavors.get_flavor, flavor['id']) # Deleted instance should not be in list anymore - new_list = flavors.get_all_types() + new_list = flavors.get_all_flavors() self.assertEqual(original_list, new_list) def test_duplicate_names_fail(self): diff --git a/nova/tests/test_metadata.py b/nova/tests/test_metadata.py index 6b84121c4..8cdc3e7af 100644 --- a/nova/tests/test_metadata.py +++ b/nova/tests/test_metadata.py @@ -77,8 +77,8 @@ INSTANCES = ( def get_default_sys_meta(): return utils.dict_to_metadata( - flavors.save_instance_type_info( - {}, flavors.get_default_instance_type())) + flavors.save_flavor_info( + {}, flavors.get_default_flavor())) def return_non_existing_address(*args, **kwarg): diff --git a/nova/tests/test_notifications.py b/nova/tests/test_notifications.py index 988ce983d..23fe4c82b 100644 --- a/nova/tests/test_notifications.py +++ b/nova/tests/test_notifications.py @@ -69,8 +69,8 @@ class NotificationsTestCase(test.TestCase): self.instance = self._wrapped_create() def _wrapped_create(self, params=None): - instance_type = flavors.get_instance_type_by_name('m1.tiny') - sys_meta = flavors.save_instance_type_info({}, instance_type) + instance_type = flavors.get_flavor_by_name('m1.tiny') + sys_meta = flavors.save_flavor_info({}, instance_type) inst = {} inst['image_ref'] = 1 inst['user_id'] = self.user_id diff --git a/nova/tests/test_quota.py b/nova/tests/test_quota.py index 30f823ace..c4c6b93ca 100644 --- a/nova/tests/test_quota.py +++ b/nova/tests/test_quota.py @@ -95,7 +95,7 @@ class QuotaIntegrationTestCase(test.TestCase): for i in range(CONF.quota_instances): instance = self._create_instance() instance_uuids.append(instance['uuid']) - inst_type = flavors.get_instance_type_by_name('m1.small') + inst_type = flavors.get_flavor_by_name('m1.small') image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175' self.assertRaises(exception.QuotaError, compute.API().create, self.context, @@ -108,7 +108,7 @@ class QuotaIntegrationTestCase(test.TestCase): def test_too_many_cores(self): instance = self._create_instance(cores=4) - inst_type = flavors.get_instance_type_by_name('m1.small') + inst_type = flavors.get_flavor_by_name('m1.small') image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175' self.assertRaises(exception.QuotaError, compute.API().create, self.context, @@ -146,7 +146,7 @@ class QuotaIntegrationTestCase(test.TestCase): metadata = {} for i in range(CONF.quota_metadata_items + 1): metadata['key%s' % i] = 'value%s' % i - inst_type = flavors.get_instance_type_by_name('m1.small') + inst_type = flavors.get_flavor_by_name('m1.small') image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175' self.assertRaises(exception.QuotaError, compute.API().create, self.context, @@ -158,7 +158,7 @@ class QuotaIntegrationTestCase(test.TestCase): def _create_with_injected_files(self, files): api = compute.API() - inst_type = flavors.get_instance_type_by_name('m1.small') + inst_type = flavors.get_flavor_by_name('m1.small') image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175' api.create(self.context, min_count=1, max_count=1, instance_type=inst_type, image_href=image_uuid, @@ -166,7 +166,7 @@ class QuotaIntegrationTestCase(test.TestCase): def test_no_injected_files(self): api = compute.API() - inst_type = flavors.get_instance_type_by_name('m1.small') + inst_type = flavors.get_flavor_by_name('m1.small') image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175' api.create(self.context, instance_type=inst_type, diff --git a/nova/tests/utils.py b/nova/tests/utils.py index 5545b789f..75b4eab73 100644 --- a/nova/tests/utils.py +++ b/nova/tests/utils.py @@ -72,7 +72,7 @@ def get_test_instance(context=None, instance_type=None): instance_type = get_test_instance_type(context) metadata = {} - flavors.save_instance_type_info(metadata, instance_type, '') + flavors.save_flavor_info(metadata, instance_type, '') test_instance = {'memory_kb': '2048000', 'basepath': '/some/path', diff --git a/nova/tests/virt/libvirt/test_libvirt.py b/nova/tests/virt/libvirt/test_libvirt.py index 2f5f9c857..d46b08946 100644 --- a/nova/tests/virt/libvirt/test_libvirt.py +++ b/nova/tests/virt/libvirt/test_libvirt.py @@ -321,7 +321,7 @@ class LibvirtConnTestCase(test.TestCase): lambda *a, **k: self.conn) instance_type = db.instance_type_get(self.context, 5) - sys_meta = flavors.save_instance_type_info({}, instance_type) + sys_meta = flavors.save_flavor_info({}, instance_type) nova.tests.image.fake.stub_out_image_service(self.stubs) self.test_instance = { @@ -2613,7 +2613,7 @@ class LibvirtConnTestCase(test.TestCase): instance_ref['image_ref'] = 123456 # we send an int to test sha1 call instance_type = db.instance_type_get(self.context, instance_ref['instance_type_id']) - sys_meta = flavors.save_instance_type_info({}, instance_type) + sys_meta = flavors.save_flavor_info({}, instance_type) instance_ref['system_metadata'] = sys_meta instance = db.instance_create(self.context, instance_ref) @@ -4815,15 +4815,15 @@ class LibvirtDriverTestCase(test.TestCase): if not params: params = {} - sys_meta = flavors.save_instance_type_info( - {}, flavors.get_instance_type_by_name('m1.tiny')) + sys_meta = flavors.save_flavor_info( + {}, flavors.get_flavor_by_name('m1.tiny')) inst = {} inst['image_ref'] = '1' inst['reservation_id'] = 'r-fakeres' inst['user_id'] = 'fake' inst['project_id'] = 'fake' - type_id = flavors.get_instance_type_by_name('m1.tiny')['id'] + type_id = flavors.get_flavor_by_name('m1.tiny')['id'] inst['instance_type_id'] = type_id inst['ami_launch_index'] = 0 inst['host'] = 'host1' diff --git a/nova/tests/virt/libvirt/test_libvirt_blockinfo.py b/nova/tests/virt/libvirt/test_libvirt_blockinfo.py index aae5bec58..a43d0d5e0 100644 --- a/nova/tests/virt/libvirt/test_libvirt_blockinfo.py +++ b/nova/tests/virt/libvirt/test_libvirt_blockinfo.py @@ -34,7 +34,7 @@ class LibvirtBlockInfoTest(test.TestCase): self.project_id = 'fake' self.context = context.get_admin_context() instance_type = db.instance_type_get(self.context, 2) - sys_meta = flavors.save_instance_type_info({}, instance_type) + sys_meta = flavors.save_flavor_info({}, instance_type) nova.tests.image.fake.stub_out_image_service(self.stubs) self.test_instance = { 'uuid': '32dfcb37-5af1-552b-357c-be8c3aa38310', diff --git a/nova/tests/virt/powervm/test_powervm.py b/nova/tests/virt/powervm/test_powervm.py index 3781c6738..8fe08bdb8 100644 --- a/nova/tests/virt/powervm/test_powervm.py +++ b/nova/tests/virt/powervm/test_powervm.py @@ -180,7 +180,7 @@ def create_instance(testcase): fake.stub_out_image_service(testcase.stubs) ctxt = context.get_admin_context() instance_type = db.instance_type_get(ctxt, 1) - sys_meta = flavors.save_instance_type_info({}, instance_type) + sys_meta = flavors.save_flavor_info({}, instance_type) return db.instance_create(ctxt, {'user_id': 'fake', 'project_id': 'fake', diff --git a/nova/tests/virt/xenapi/test_vm_utils.py b/nova/tests/virt/xenapi/test_vm_utils.py index f2a75d899..68caab651 100644 --- a/nova/tests/virt/xenapi/test_vm_utils.py +++ b/nova/tests/virt/xenapi/test_vm_utils.py @@ -427,8 +427,8 @@ class CheckVDISizeTestCase(test.TestCase): self.vdi_uuid = 'fakeuuid' def test_not_too_large(self): - self.mox.StubOutWithMock(flavors, 'extract_instance_type') - flavors.extract_instance_type(self.instance).AndReturn( + self.mox.StubOutWithMock(flavors, 'extract_flavor') + flavors.extract_flavor(self.instance).AndReturn( dict(root_gb=1)) self.mox.StubOutWithMock(vm_utils, '_get_vdi_chain_size') @@ -441,8 +441,8 @@ class CheckVDISizeTestCase(test.TestCase): self.vdi_uuid) def test_too_large(self): - self.mox.StubOutWithMock(flavors, 'extract_instance_type') - flavors.extract_instance_type(self.instance).AndReturn( + self.mox.StubOutWithMock(flavors, 'extract_flavor') + flavors.extract_flavor(self.instance).AndReturn( dict(root_gb=1)) self.mox.StubOutWithMock(vm_utils, '_get_vdi_chain_size') @@ -456,8 +456,8 @@ class CheckVDISizeTestCase(test.TestCase): self.instance, self.vdi_uuid) def test_zero_root_gb_disables_check(self): - self.mox.StubOutWithMock(flavors, 'extract_instance_type') - flavors.extract_instance_type(self.instance).AndReturn( + self.mox.StubOutWithMock(flavors, 'extract_flavor') + flavors.extract_flavor(self.instance).AndReturn( dict(root_gb=0)) self.mox.ReplayAll() diff --git a/nova/tests/virt/xenapi/test_xenapi.py b/nova/tests/virt/xenapi/test_xenapi.py index bc166655d..7dcb1cec8 100644 --- a/nova/tests/virt/xenapi/test_xenapi.py +++ b/nova/tests/virt/xenapi/test_xenapi.py @@ -179,7 +179,7 @@ def stub_vm_utils_with_vdi_attached_here(function, should_return=True): def create_instance_with_system_metadata(context, instance_values): instance_type = db.instance_type_get(context, instance_values['instance_type_id']) - sys_meta = flavors.save_instance_type_info({}, + sys_meta = flavors.save_flavor_info({}, instance_type) instance_values['system_metadata'] = sys_meta return db.instance_create(context, instance_values) @@ -1192,7 +1192,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): def test_per_instance_usage_running(self): instance = self._create_instance(spawn=True) - instance_type = flavors.get_instance_type(3) + instance_type = flavors.get_flavor(3) expected = {instance['uuid']: {'memory_mb': instance_type['memory_mb'], 'uuid': instance['uuid']}} @@ -1479,7 +1479,7 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase): self._test_finish_migrate(False) def test_finish_migrate_no_local_storage(self): - tiny_type = flavors.get_instance_type_by_name('m1.tiny') + tiny_type = flavors.get_flavor_by_name('m1.tiny') tiny_type_id = tiny_type['id'] self.instance_values.update({'instance_type_id': tiny_type_id, 'root_gb': 0}) diff --git a/nova/virt/baremetal/pxe.py b/nova/virt/baremetal/pxe.py index 4c63f2b07..6a5a5ece5 100644 --- a/nova/virt/baremetal/pxe.py +++ b/nova/virt/baremetal/pxe.py @@ -174,7 +174,7 @@ def get_pxe_config_file_path(instance): def get_partition_sizes(instance): - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) root_mb = instance_type['root_gb'] * 1024 swap_mb = instance_type['swap'] diff --git a/nova/virt/baremetal/tilera.py b/nova/virt/baremetal/tilera.py index 7906fdddd..64335298c 100755 --- a/nova/virt/baremetal/tilera.py +++ b/nova/virt/baremetal/tilera.py @@ -108,7 +108,7 @@ def get_tilera_nfs_path(node_id): def get_partition_sizes(instance): - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) root_mb = instance_type['root_gb'] * 1024 swap_mb = instance_type['swap'] diff --git a/nova/virt/hyperv/imagecache.py b/nova/virt/hyperv/imagecache.py index 85588a769..8f29a62dc 100644 --- a/nova/virt/hyperv/imagecache.py +++ b/nova/virt/hyperv/imagecache.py @@ -52,7 +52,7 @@ class ImageCache(object): def _get_root_vhd_size_gb(self, instance): try: # In case of resizes we need the old root disk size - old_instance_type = flavors.extract_instance_type( + old_instance_type = flavors.extract_flavor( instance, prefix='old_') return old_instance_type['root_gb'] except KeyError: diff --git a/nova/virt/libvirt/blockinfo.py b/nova/virt/libvirt/blockinfo.py index 39b6292b1..3e9e359e6 100644 --- a/nova/virt/libvirt/blockinfo.py +++ b/nova/virt/libvirt/blockinfo.py @@ -300,7 +300,7 @@ def get_disk_mapping(virt_type, instance, Returns the guest disk mapping for the devices.""" - inst_type = flavors.extract_instance_type(instance) + inst_type = flavors.extract_flavor(instance) mapping = {} diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index c0cec7a43..91d5b1a50 100755 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -1798,7 +1798,7 @@ class LibvirtDriver(driver.ComputeDriver): user_id=instance['user_id'], project_id=instance['project_id']) - inst_type = flavors.extract_instance_type(instance) + inst_type = flavors.extract_flavor(instance) # NOTE(ndipanov): Even if disk_mapping was passed in, which # currently happens only on rescue - we still don't want to diff --git a/nova/virt/powervm/blockdev.py b/nova/virt/powervm/blockdev.py index 73099b148..9f567b746 100644 --- a/nova/virt/powervm/blockdev.py +++ b/nova/virt/powervm/blockdev.py @@ -177,7 +177,7 @@ class PowerVMLocalVolumeAdapter(PowerVMDiskAdapter): # calculate root device size in bytes # we respect the minimum root device size in constants - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) size_gb = max(instance_type['root_gb'], constants.POWERVM_MIN_ROOT_GB) size = size_gb * 1024 * 1024 * 1024 diff --git a/nova/virt/powervm/driver.py b/nova/virt/powervm/driver.py index 5117bdf72..58c0d5f09 100755 --- a/nova/virt/powervm/driver.py +++ b/nova/virt/powervm/driver.py @@ -290,7 +290,7 @@ class PowerVMDriver(driver.ComputeDriver): """ lpar_obj = self._powervm._create_lpar_instance(instance, network_info) - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) new_lv_size = instance_type['root_gb'] old_lv_size = disk_info['old_lv_size'] if 'root_disk_file' in disk_info: diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 0c54dc1dd..9c8c73ba9 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -213,7 +213,7 @@ def create_vm(session, instance, name_label, kernel, ramdisk, 3. Using hardware virtualization """ - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) mem = str(long(instance_type['memory_mb']) * 1024 * 1024) vcpus = str(instance_type['vcpus']) @@ -326,7 +326,7 @@ def is_vm_shutdown(session, vm_ref): def ensure_free_mem(session, instance): - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) mem = long(instance_type['memory_mb']) * 1024 * 1024 host = session.get_xenapi_host() host_free_mem = long(session.call_xenapi("host.compute_free_memory", @@ -1194,7 +1194,7 @@ def _get_vdi_chain_size(session, vdi_uuid): def _check_vdi_size(context, session, instance, vdi_uuid): - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) allowed_size = instance_type['root_gb'] * (1024 ** 3) if not allowed_size: diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index e178d08fd..90ca3cbed 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -577,7 +577,7 @@ class VMOps(object): def _attach_disks(self, instance, vm_ref, name_label, vdis, disk_image_type, admin_password=None, files=None): ctx = nova_context.get_admin_context() - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) # Attach (required) root disk if disk_image_type == vm_utils.ImageType.DISK_ISO: @@ -702,7 +702,7 @@ class VMOps(object): agent.resetnetwork() # Set VCPU weight - instance_type = flavors.extract_instance_type(instance) + instance_type = flavors.extract_flavor(instance) vcpu_weight = instance_type['vcpu_weight'] if vcpu_weight is not None: LOG.debug(_("Setting VCPU weight"), instance=instance) |