Merge "Remove flavors.get_flavor() only used in tests"
This commit is contained in:
@@ -206,20 +206,6 @@ def get_default_flavor():
|
|||||||
return get_flavor_by_name(name)
|
return get_flavor_by_name(name)
|
||||||
|
|
||||||
|
|
||||||
def get_flavor(instance_type_id, ctxt=None, inactive=False):
|
|
||||||
"""Retrieves single flavor by id."""
|
|
||||||
if instance_type_id is None:
|
|
||||||
return get_default_flavor()
|
|
||||||
|
|
||||||
if ctxt is None:
|
|
||||||
ctxt = context.get_admin_context()
|
|
||||||
|
|
||||||
if inactive:
|
|
||||||
ctxt = ctxt.elevated(read_deleted="yes")
|
|
||||||
|
|
||||||
return objects.Flavor.get_by_id(ctxt, instance_type_id)
|
|
||||||
|
|
||||||
|
|
||||||
def get_flavor_by_name(name, ctxt=None):
|
def get_flavor_by_name(name, ctxt=None):
|
||||||
"""Retrieves single flavor by name."""
|
"""Retrieves single flavor by name."""
|
||||||
if name is None:
|
if name is None:
|
||||||
|
@@ -26,7 +26,6 @@ from oslo_serialization import jsonutils
|
|||||||
from nova.api.ec2 import cloud
|
from nova.api.ec2 import cloud
|
||||||
from nova.api.ec2 import ec2utils
|
from nova.api.ec2 import ec2utils
|
||||||
from nova.compute import api as compute_api
|
from nova.compute import api as compute_api
|
||||||
from nova.compute import flavors
|
|
||||||
from nova.compute import manager as compute_manager
|
from nova.compute import manager as compute_manager
|
||||||
from nova.compute import utils as compute_utils
|
from nova.compute import utils as compute_utils
|
||||||
from nova import context
|
from nova import context
|
||||||
@@ -498,8 +497,9 @@ class CinderCloudTestCase(test.TestCase):
|
|||||||
|
|
||||||
def _setUpBlockDeviceMapping(self):
|
def _setUpBlockDeviceMapping(self):
|
||||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||||
|
flavor = objects.Flavor.get_by_id(self.context, 1)
|
||||||
flavorinfo = jsonutils.dumps({
|
flavorinfo = jsonutils.dumps({
|
||||||
'cur': flavors.get_flavor(1).obj_to_primitive(),
|
'cur': flavor.obj_to_primitive(),
|
||||||
'old': None,
|
'old': None,
|
||||||
'new': None,
|
'new': None,
|
||||||
})
|
})
|
||||||
|
@@ -908,6 +908,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
self._stub_instance_get_with_fixed_ips('get')
|
self._stub_instance_get_with_fixed_ips('get')
|
||||||
|
|
||||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||||
|
flavor = objects.Flavor.get_by_id(self.context, 1)
|
||||||
inst1 = objects.Instance(context=self.context,
|
inst1 = objects.Instance(context=self.context,
|
||||||
reservation_id='a',
|
reservation_id='a',
|
||||||
image_ref=image_uuid,
|
image_ref=image_uuid,
|
||||||
@@ -918,7 +919,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
system_metadata={
|
system_metadata={
|
||||||
'EC2_client_token': 'client-token-1',
|
'EC2_client_token': 'client-token-1',
|
||||||
},
|
},
|
||||||
flavor=flavors.get_flavor(1))
|
flavor=flavor)
|
||||||
inst1.create()
|
inst1.create()
|
||||||
inst2 = objects.Instance(context=self.context,
|
inst2 = objects.Instance(context=self.context,
|
||||||
reservation_id='a',
|
reservation_id='a',
|
||||||
@@ -930,7 +931,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
system_metadata={
|
system_metadata={
|
||||||
'EC2_client_token': 'client-token-2',
|
'EC2_client_token': 'client-token-2',
|
||||||
},
|
},
|
||||||
flavor=flavors.get_flavor(1))
|
flavor=flavor)
|
||||||
inst2.create()
|
inst2.create()
|
||||||
comp1 = db.service_create(self.context, {'host': 'host1',
|
comp1 = db.service_create(self.context, {'host': 'host1',
|
||||||
'topic': "compute"})
|
'topic': "compute"})
|
||||||
@@ -1021,7 +1022,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
fake_change_instance_metadata)
|
fake_change_instance_metadata)
|
||||||
|
|
||||||
utc = iso8601.iso8601.Utc()
|
utc = iso8601.iso8601.Utc()
|
||||||
flavor = flavors.get_flavor(1)
|
flavor = objects.Flavor.get_by_id(self.context, 1)
|
||||||
# Create some test images
|
# Create some test images
|
||||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||||
inst1 = objects.Instance(context=self.context,
|
inst1 = objects.Instance(context=self.context,
|
||||||
@@ -1243,13 +1244,14 @@ class CloudTestCase(test.TestCase):
|
|||||||
self._stub_instance_get_with_fixed_ips('get')
|
self._stub_instance_get_with_fixed_ips('get')
|
||||||
|
|
||||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||||
|
flavor = objects.Flavor.get_by_id(self.context, 1)
|
||||||
inst_base = objects.Instance(context=self.context,
|
inst_base = objects.Instance(context=self.context,
|
||||||
reservation_id='a',
|
reservation_id='a',
|
||||||
image_ref=image_uuid,
|
image_ref=image_uuid,
|
||||||
instance_type_id=1,
|
instance_type_id=1,
|
||||||
vm_state='active',
|
vm_state='active',
|
||||||
system_metadata={},
|
system_metadata={},
|
||||||
flavor=flavors.get_flavor(1))
|
flavor=flavor)
|
||||||
|
|
||||||
utc = iso8601.iso8601.Utc()
|
utc = iso8601.iso8601.Utc()
|
||||||
|
|
||||||
@@ -1298,8 +1300,9 @@ class CloudTestCase(test.TestCase):
|
|||||||
def test_instance_state(expected_code, expected_name,
|
def test_instance_state(expected_code, expected_name,
|
||||||
power_state_, vm_state_, values=None):
|
power_state_, vm_state_, values=None):
|
||||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||||
|
flavor = objects.Flavor.get_by_id(self.context, 1)
|
||||||
inst = objects.Instance(context=self.context,
|
inst = objects.Instance(context=self.context,
|
||||||
flavor=flavors.get_flavor(1),
|
flavor=flavor,
|
||||||
image_ref=image_uuid,
|
image_ref=image_uuid,
|
||||||
instance_type_id=1,
|
instance_type_id=1,
|
||||||
power_state=power_state_,
|
power_state=power_state_,
|
||||||
@@ -1334,6 +1337,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
self._stub_instance_get_with_fixed_ips('get')
|
self._stub_instance_get_with_fixed_ips('get')
|
||||||
|
|
||||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||||
|
flavor = objects.Flavor.get_by_id(self.context, 1)
|
||||||
inst = objects.Instance(context=self.context,
|
inst = objects.Instance(context=self.context,
|
||||||
reservation_id='a',
|
reservation_id='a',
|
||||||
image_ref=image_uuid,
|
image_ref=image_uuid,
|
||||||
@@ -1341,7 +1345,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
hostname='server-1234',
|
hostname='server-1234',
|
||||||
vm_state='active',
|
vm_state='active',
|
||||||
system_metadata={},
|
system_metadata={},
|
||||||
flavor=flavors.get_flavor(1))
|
flavor=flavor)
|
||||||
inst.create()
|
inst.create()
|
||||||
comp1 = db.service_create(self.context, {'host': 'host1',
|
comp1 = db.service_create(self.context, {'host': 'host1',
|
||||||
'topic': "compute"})
|
'topic': "compute"})
|
||||||
@@ -1361,6 +1365,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
|
|
||||||
def test_describe_instances_deleted(self):
|
def test_describe_instances_deleted(self):
|
||||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||||
|
flavor = objects.Flavor.get_by_id(self.context, 1)
|
||||||
inst1 = objects.Instance(context=self.context,
|
inst1 = objects.Instance(context=self.context,
|
||||||
reservation_id='a',
|
reservation_id='a',
|
||||||
image_ref=image_uuid,
|
image_ref=image_uuid,
|
||||||
@@ -1368,7 +1373,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
host='host1',
|
host='host1',
|
||||||
vm_state='active',
|
vm_state='active',
|
||||||
system_metadata={},
|
system_metadata={},
|
||||||
flavor=flavors.get_flavor(1))
|
flavor=flavor)
|
||||||
inst1.create()
|
inst1.create()
|
||||||
inst2 = objects.Instance(context=self.context,
|
inst2 = objects.Instance(context=self.context,
|
||||||
reservation_id='b',
|
reservation_id='b',
|
||||||
@@ -1377,7 +1382,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
host='host2',
|
host='host2',
|
||||||
vm_state='active',
|
vm_state='active',
|
||||||
system_metadata={},
|
system_metadata={},
|
||||||
flavor=flavors.get_flavor(1))
|
flavor=flavor)
|
||||||
inst2.create()
|
inst2.create()
|
||||||
db.instance_destroy(self.context, inst1.uuid)
|
db.instance_destroy(self.context, inst1.uuid)
|
||||||
result = self.cloud.describe_instances(self.context)
|
result = self.cloud.describe_instances(self.context)
|
||||||
@@ -1388,6 +1393,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
|
|
||||||
def test_describe_instances_with_image_deleted(self):
|
def test_describe_instances_with_image_deleted(self):
|
||||||
image_uuid = 'aebef54a-ed67-4d10-912f-14455edce176'
|
image_uuid = 'aebef54a-ed67-4d10-912f-14455edce176'
|
||||||
|
flavor = objects.Flavor.get_by_id(self.context, 1)
|
||||||
inst1 = objects.Instance(context=self.context,
|
inst1 = objects.Instance(context=self.context,
|
||||||
reservation_id='a',
|
reservation_id='a',
|
||||||
image_ref=image_uuid,
|
image_ref=image_uuid,
|
||||||
@@ -1395,7 +1401,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
host='host1',
|
host='host1',
|
||||||
vm_state='active',
|
vm_state='active',
|
||||||
system_metadata={},
|
system_metadata={},
|
||||||
flavor=flavors.get_flavor(1))
|
flavor=flavor)
|
||||||
inst1.create()
|
inst1.create()
|
||||||
inst2 = objects.Instance(context=self.context,
|
inst2 = objects.Instance(context=self.context,
|
||||||
reservation_id='b',
|
reservation_id='b',
|
||||||
@@ -1404,7 +1410,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
host='host1',
|
host='host1',
|
||||||
vm_state='active',
|
vm_state='active',
|
||||||
system_metadata={},
|
system_metadata={},
|
||||||
flavor=flavors.get_flavor(1))
|
flavor=flavor)
|
||||||
inst2.create()
|
inst2.create()
|
||||||
result = self.cloud.describe_instances(self.context)
|
result = self.cloud.describe_instances(self.context)
|
||||||
self.assertEqual(len(result['reservationSet']), 2)
|
self.assertEqual(len(result['reservationSet']), 2)
|
||||||
@@ -1415,6 +1421,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
self._stub_instance_get_with_fixed_ips('get', get_floating=False)
|
self._stub_instance_get_with_fixed_ips('get', get_floating=False)
|
||||||
|
|
||||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||||
|
flavor = objects.Flavor.get_by_id(self.context, 1)
|
||||||
inst = objects.Instance(context=self.context,
|
inst = objects.Instance(context=self.context,
|
||||||
reservation='a',
|
reservation='a',
|
||||||
image_ref=image_uuid,
|
image_ref=image_uuid,
|
||||||
@@ -1423,7 +1430,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
hostname='server-1234',
|
hostname='server-1234',
|
||||||
vm_state='active',
|
vm_state='active',
|
||||||
system_metadata={},
|
system_metadata={},
|
||||||
flavor=flavors.get_flavor(1))
|
flavor=flavor)
|
||||||
inst.create()
|
inst.create()
|
||||||
result = self.cloud.describe_instances(self.context)
|
result = self.cloud.describe_instances(self.context)
|
||||||
result = result['reservationSet'][0]
|
result = result['reservationSet'][0]
|
||||||
@@ -1439,7 +1446,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
inst.vm_state = vm_states.ACTIVE
|
inst.vm_state = vm_states.ACTIVE
|
||||||
inst.host = 'host1'
|
inst.host = 'host1'
|
||||||
inst.system_metadata = {}
|
inst.system_metadata = {}
|
||||||
inst.flavor = flavors.get_flavor(1)
|
inst.flavor = objects.Flavor.get_by_id(self.context, 1)
|
||||||
inst.create()
|
inst.create()
|
||||||
result = self.cloud.describe_instances(self.context)
|
result = self.cloud.describe_instances(self.context)
|
||||||
result = result['reservationSet'][0]
|
result = result['reservationSet'][0]
|
||||||
|
@@ -24,7 +24,6 @@ from oslo_utils import uuidutils
|
|||||||
from nova import block_device
|
from nova import block_device
|
||||||
from nova.cells import filters
|
from nova.cells import filters
|
||||||
from nova.cells import weights
|
from nova.cells import weights
|
||||||
from nova.compute import flavors
|
|
||||||
from nova.compute import vm_states
|
from nova.compute import vm_states
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova import db
|
from nova import db
|
||||||
@@ -98,7 +97,7 @@ class CellsSchedulerTestCase(test.TestCase):
|
|||||||
|
|
||||||
def test_create_instances_here(self):
|
def test_create_instances_here(self):
|
||||||
# Just grab the first instance type
|
# Just grab the first instance type
|
||||||
inst_type = flavors.get_flavor(1)
|
inst_type = objects.Flavor.get_by_id(self.ctxt, 1)
|
||||||
image = {'properties': {}}
|
image = {'properties': {}}
|
||||||
instance_uuids = self.instance_uuids
|
instance_uuids = self.instance_uuids
|
||||||
instance_props = {'id': 'removed',
|
instance_props = {'id': 'removed',
|
||||||
|
@@ -219,8 +219,6 @@ class ComputeValidateDeviceTestCase(test.NoDBTestCase):
|
|||||||
'ephemeral_gb': 10,
|
'ephemeral_gb': 10,
|
||||||
'swap': 0,
|
'swap': 0,
|
||||||
})
|
})
|
||||||
self.stubs.Set(flavors, 'get_flavor',
|
|
||||||
lambda instance_type_id, ctxt=None: self.flavor)
|
|
||||||
device = self._validate_device()
|
device = self._validate_device()
|
||||||
self.assertEqual(device, '/dev/xvdc')
|
self.assertEqual(device, '/dev/xvdc')
|
||||||
|
|
||||||
@@ -229,8 +227,6 @@ class ComputeValidateDeviceTestCase(test.NoDBTestCase):
|
|||||||
'ephemeral_gb': 0,
|
'ephemeral_gb': 0,
|
||||||
'swap': 10,
|
'swap': 10,
|
||||||
})
|
})
|
||||||
self.stubs.Set(flavors, 'get_flavor',
|
|
||||||
lambda instance_type_id, ctxt=None: self.flavor)
|
|
||||||
device = self._validate_device()
|
device = self._validate_device()
|
||||||
self.assertEqual(device, '/dev/xvdb')
|
self.assertEqual(device, '/dev/xvdb')
|
||||||
|
|
||||||
@@ -239,8 +235,6 @@ class ComputeValidateDeviceTestCase(test.NoDBTestCase):
|
|||||||
'ephemeral_gb': 10,
|
'ephemeral_gb': 10,
|
||||||
'swap': 10,
|
'swap': 10,
|
||||||
})
|
})
|
||||||
self.stubs.Set(flavors, 'get_flavor',
|
|
||||||
lambda instance_type_id, ctxt=None: self.flavor)
|
|
||||||
device = self._validate_device()
|
device = self._validate_device()
|
||||||
self.assertEqual(device, '/dev/xvdd')
|
self.assertEqual(device, '/dev/xvdd')
|
||||||
|
|
||||||
@@ -249,8 +243,6 @@ class ComputeValidateDeviceTestCase(test.NoDBTestCase):
|
|||||||
'ephemeral_gb': 0,
|
'ephemeral_gb': 0,
|
||||||
'swap': 10,
|
'swap': 10,
|
||||||
})
|
})
|
||||||
self.stubs.Set(flavors, 'get_flavor',
|
|
||||||
lambda instance_type_id, ctxt=None: self.flavor)
|
|
||||||
device = self._validate_device()
|
device = self._validate_device()
|
||||||
self.assertEqual(device, '/dev/xvdb')
|
self.assertEqual(device, '/dev/xvdb')
|
||||||
self.data.append(self._fake_bdm(device))
|
self.data.append(self._fake_bdm(device))
|
||||||
|
@@ -78,23 +78,6 @@ class InstanceTypeTestCase(test.TestCase):
|
|||||||
self.assertRaises(exception.FlavorNotFound,
|
self.assertRaises(exception.FlavorNotFound,
|
||||||
flavors.get_default_flavor)
|
flavors.get_default_flavor)
|
||||||
|
|
||||||
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_flavor(instance_type_id)
|
|
||||||
self.assertIsInstance(fetched, objects.Flavor)
|
|
||||||
self.assertEqual(default_instance_type.flavorid, fetched.flavorid)
|
|
||||||
|
|
||||||
def test_will_not_get_flavor_by_unknown_id(self):
|
|
||||||
# Ensure get by name returns default flavor with no name.
|
|
||||||
self.assertRaises(exception.FlavorNotFound,
|
|
||||||
flavors.get_flavor, 10000)
|
|
||||||
|
|
||||||
def test_will_not_get_flavor_with_bad_id(self):
|
|
||||||
# Ensure get by name returns default flavor with bad name.
|
|
||||||
self.assertRaises(exception.FlavorNotFound,
|
|
||||||
flavors.get_flavor, 'asdf')
|
|
||||||
|
|
||||||
def test_flavor_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.
|
# Ensure get by name returns default flavor with no name.
|
||||||
default = flavors.get_default_flavor()
|
default = flavors.get_default_flavor()
|
||||||
@@ -481,7 +464,7 @@ class CreateInstanceTypeTest(test.TestCase):
|
|||||||
|
|
||||||
flavors.destroy('flavor')
|
flavors.destroy('flavor')
|
||||||
self.assertRaises(exception.FlavorNotFound,
|
self.assertRaises(exception.FlavorNotFound,
|
||||||
flavors.get_flavor, flavor.id)
|
objects.Flavor.get_by_id, ctxt, flavor.id)
|
||||||
|
|
||||||
# Deleted instance should not be in list anymore
|
# Deleted instance should not be in list anymore
|
||||||
new_list = objects.FlavorList.get_all(ctxt)
|
new_list = objects.FlavorList.get_all(ctxt)
|
||||||
|
@@ -36,7 +36,6 @@ import testtools
|
|||||||
|
|
||||||
from nova.compute import api as compute_api
|
from nova.compute import api as compute_api
|
||||||
from nova.compute import arch
|
from nova.compute import arch
|
||||||
from nova.compute import flavors
|
|
||||||
from nova.compute import hv_type
|
from nova.compute import hv_type
|
||||||
from nova.compute import power_state
|
from nova.compute import power_state
|
||||||
from nova.compute import task_states
|
from nova.compute import task_states
|
||||||
@@ -1516,7 +1515,7 @@ iface eth0 inet6 static
|
|||||||
|
|
||||||
def test_per_instance_usage_running(self):
|
def test_per_instance_usage_running(self):
|
||||||
instance = self._create_instance(spawn=True)
|
instance = self._create_instance(spawn=True)
|
||||||
flavor = flavors.get_flavor(3)
|
flavor = objects.Flavor.get_by_id(self.context, 3)
|
||||||
|
|
||||||
expected = {instance['uuid']: {'memory_mb': flavor['memory_mb'],
|
expected = {instance['uuid']: {'memory_mb': flavor['memory_mb'],
|
||||||
'uuid': instance['uuid']}}
|
'uuid': instance['uuid']}}
|
||||||
|
Reference in New Issue
Block a user