Removes the creation of duplicate flavors
- Updated flavor extra_specs - Updated custom resources for child nodes. - Updated existing unit tests Change-Id: I1c147dbd63c1f496923da119b5808a7d52cff590 Signed-off-by: Helena McGough <helena.mcgough@intel.com>
This commit is contained in:
parent
57c197abd4
commit
9c1d9202bf
@ -140,7 +140,8 @@ class TestRSDDriver(base.BaseTestCase):
|
||||
self.node_collection = node.NodeCollection(
|
||||
self.root_conn, '/redfish/v1/Nodes', redfish_version='1.0.2')
|
||||
|
||||
with open('rsd_virt_for_nova/tests/json_samples/node.json', 'r') as f:
|
||||
with open('rsd_virt_for_nova/tests/json_samples/node.json',
|
||||
'r') as f:
|
||||
self.root_conn.get.return_value.json.return_value = json.loads(
|
||||
f.read())
|
||||
self.node_inst = node.Node(
|
||||
@ -411,12 +412,12 @@ class TestRSDDriver(base.BaseTestCase):
|
||||
'local_gb': 0,
|
||||
'local_gb_used': 0,
|
||||
'memory_mb': mem_info.return_value,
|
||||
'memory_mb_used': mem_info.return_value,
|
||||
'memory_mb_used': 0,
|
||||
'numa_topology': None,
|
||||
'supported_instances':
|
||||
[('x86_64', 'baremetal', 'hvm')],
|
||||
'vcpus': proc_info.return_value,
|
||||
'vcpus_used': proc_info.return_value}, resources)
|
||||
'vcpus_used': 0}, resources)
|
||||
|
||||
@mock.patch.object(driver.RSDDriver, '_create_flavors')
|
||||
@mock.patch.object(driver.RSDDriver, 'check_flavors')
|
||||
@ -455,8 +456,6 @@ class TestRSDDriver(base.BaseTestCase):
|
||||
self.ptree.new_root('/redfish/v1/Chassis/Chassis1', uuids.cn)
|
||||
|
||||
# Setup other mocked calls for a successful test
|
||||
sys_col = self.RSD.driver.PODM.get_system_collection.return_value
|
||||
sys_col.get_member.return_value = self.system_inst
|
||||
chas_col = self.RSD.driver.PODM.get_chassis_collection.return_value
|
||||
chas_col.members_identities = ['/redfish/v1/Chassis/Chassis1']
|
||||
chas_col.get_member.return_value = self.chassis_inst
|
||||
@ -470,8 +469,7 @@ class TestRSDDriver(base.BaseTestCase):
|
||||
self.RSD.driver.PODM.get_chassis_collection.assert_called()
|
||||
chas_col.get_member.assert_called_with('/redfish/v1/Chassis/Chassis1')
|
||||
check_chas.assert_called_with(self.chassis_inst)
|
||||
sys_col.get_member.assert_called_with('/redfish/v1/Systems/System1')
|
||||
create_child_inv.assert_called_once_with(self.system_inst.identity)
|
||||
create_child_inv.assert_called_once_with('/redfish/v1/Systems/System1')
|
||||
create_inv.assert_called_once_with(check_chas.return_value)
|
||||
|
||||
@mock.patch.object(driver.RSDDriver, 'create_child_inventory')
|
||||
@ -677,16 +675,27 @@ class TestRSDDriver(base.BaseTestCase):
|
||||
'allocation_ratio': 1}
|
||||
})
|
||||
|
||||
@mock.patch.object(driver.RSDDriver, 'conv_GiB_to_MiB')
|
||||
@mock.patch.object(fields.ResourceClass, 'normalize_name')
|
||||
def test_create_child_inventory(self, norm_name):
|
||||
def test_create_child_inventory(self, norm_name, conv_mem):
|
||||
"""Test creating inventory for the child RP's."""
|
||||
# Set up a test to create the inventory for child resource providers
|
||||
sys_col = self.RSD.driver.PODM.get_system_collection.return_value
|
||||
sys_col.get_member.return_value = self.system_inst
|
||||
mem = conv_mem.return_value - 512
|
||||
proc = self.system_inst.processors.summary.count
|
||||
flav_id = str(mem) + 'MB-' + str(proc) + 'vcpus'
|
||||
child_inv = self.RSD.create_child_inventory(
|
||||
[self.system_inst.identity])
|
||||
'/redfish/v1/Systems/System1')
|
||||
|
||||
# Check that the correct functions are called and the inventory
|
||||
# is generated correctly
|
||||
norm_name.assert_called_once_with([self.system_inst.identity])
|
||||
self.RSD.driver.PODM.get_system_collection.assert_called_once()
|
||||
sys_col.get_member.assert_called_once_with(
|
||||
'/redfish/v1/Systems/System1')
|
||||
conv_mem.assert_called_once_with(
|
||||
self.system_inst.memory_summary.size_gib)
|
||||
norm_name.assert_called_once_with(flav_id)
|
||||
self.assertEqual(child_inv, {norm_name.return_value: {
|
||||
'total': 1,
|
||||
'reserved': 0,
|
||||
@ -728,6 +737,10 @@ class TestRSDDriver(base.BaseTestCase):
|
||||
sys_col = self.RSD.driver.PODM.get_system_collection.return_value
|
||||
sys_col.members_identities = ['/redfish/v1/Systems/System1']
|
||||
sys_col.get_member.return_value = self.system_inst
|
||||
spec = 'resources:' + norm_name.return_value
|
||||
mem = conv_mem.return_value - 512
|
||||
proc = self.system_inst.processors.summary.count
|
||||
flav_id = str(mem) + 'MB-' + str(proc) + 'vcpus'
|
||||
# Run test
|
||||
self.RSD._create_flavors()
|
||||
|
||||
@ -735,14 +748,10 @@ class TestRSDDriver(base.BaseTestCase):
|
||||
self.RSD.driver.PODM.get_system_collection.assert_called_once()
|
||||
sys_col.get_member.assert_called_with('/redfish/v1/Systems/System1')
|
||||
conv_mem.assert_called_with(self.system_inst.memory_summary.size_gib)
|
||||
norm_name.assert_called_with(self.system_inst.identity)
|
||||
norm_name.assert_called_with(flav_id)
|
||||
admin_context.assert_called()
|
||||
|
||||
# Flavor creation call check
|
||||
spec = 'resources:' + norm_name.return_value
|
||||
mem = conv_mem.return_value - 512
|
||||
proc = self.system_inst.processors.summary.count
|
||||
flav_id = str(mem) + 'MB-' + str(proc) + 'vcpus'
|
||||
flav_create.assert_called_once_with(
|
||||
admin_context.return_value,
|
||||
{'name': 'RSD-' + flav_id,
|
||||
@ -781,7 +790,7 @@ class TestRSDDriver(base.BaseTestCase):
|
||||
self.RSD.driver.PODM.get_system_collection.assert_called_once()
|
||||
sys_col.get_member.assert_called_with('/redfish/v1/Systems/System1')
|
||||
conv_mem.assert_called_with(self.system_inst.memory_summary.size_gib)
|
||||
norm_name.assert_called_with(self.system_inst.identity)
|
||||
norm_name.assert_called_with(flav_id)
|
||||
admin_context.assert_called()
|
||||
|
||||
# Flavor creation call check
|
||||
@ -815,19 +824,25 @@ class TestRSDDriver(base.BaseTestCase):
|
||||
flav_create.assert_not_called()
|
||||
flav_from_db.assert_not_called()
|
||||
|
||||
@mock.patch.object(objects.FlavorList, 'get_all')
|
||||
@mock.patch.object(context, 'get_admin_context')
|
||||
@mock.patch.object(flavor, '_flavor_destroy')
|
||||
def test_check_flavors_failure(self, flav_destroy):
|
||||
def test_check_flavors_failure(self, flav_destroy, get_context, flav_list):
|
||||
"""Test for failing to check existing flavors."""
|
||||
# Setup for the test to fail to check flavors
|
||||
sys_col = self.RSD.driver.PODM.get_system_collection.return_value
|
||||
self.RSD.check_flavors(self.system_col, [])
|
||||
|
||||
# Confirm that checking the available flavors failed
|
||||
get_context.assert_called()
|
||||
flav_list.assert_called_with(get_context.return_value)
|
||||
sys_col.get_member.assert_not_called()
|
||||
flav_destroy.assert_not_called()
|
||||
|
||||
@mock.patch.object(objects.FlavorList, 'get_all')
|
||||
@mock.patch.object(context, 'get_admin_context')
|
||||
@mock.patch.object(flavor, '_flavor_destroy')
|
||||
def test_check_flavors_success(self, flav_destroy):
|
||||
def test_check_flavors_success(self, flav_destroy, get_context, flav_list):
|
||||
"""Test for successfully checking existing flavors."""
|
||||
# Setup for check flavor that exists
|
||||
sys_col = self.RSD.driver.PODM.get_system_collection.return_value
|
||||
@ -839,6 +854,8 @@ class TestRSDDriver(base.BaseTestCase):
|
||||
|
||||
# Confirm the list of available flavors
|
||||
# No flavors need to be deleted
|
||||
get_context.assert_called()
|
||||
flav_list.assert_called_with(get_context.return_value)
|
||||
sys_col.get_member.assert_called_with('/redfish/v1/Systems/System1')
|
||||
flav_destroy.assert_not_called()
|
||||
|
||||
@ -857,6 +874,6 @@ class TestRSDDriver(base.BaseTestCase):
|
||||
# Confirm the list of availbable flavors
|
||||
# Delete all flavors that no longer have associated systems
|
||||
sys_col.get_member.assert_called_with(sys_str)
|
||||
get_context.assert_called_once()
|
||||
get_context.assert_called()
|
||||
flav_destroy.assert_called_with(get_context.return_value, 'flav_id')
|
||||
self.assertEqual(self.RSD.rsd_flavors, {})
|
||||
|
@ -29,6 +29,8 @@ from nova import context
|
||||
|
||||
from nova import exception
|
||||
|
||||
from nova import objects
|
||||
|
||||
from nova import rc_fields as fields
|
||||
|
||||
from nova.compute import power_state
|
||||
@ -202,8 +204,8 @@ class RSDDriver(driver.ComputeDriver):
|
||||
'vcpus': self.get_sys_proc_info(cha_sys),
|
||||
'memory_mb': self.get_sys_memory_info(cha_sys),
|
||||
'local_gb': 0,
|
||||
'vcpus_used': self.get_sys_proc_info(cha_sys),
|
||||
'memory_mb_used': self.get_sys_memory_info(cha_sys),
|
||||
'vcpus_used': 0,
|
||||
'memory_mb_used': 0,
|
||||
'local_gb_used': 0,
|
||||
'hypervisor_type': 'composable',
|
||||
'hypervisor_version': versionutils.convert_version_to_int('1.0'),
|
||||
@ -245,8 +247,7 @@ class RSDDriver(driver.ComputeDriver):
|
||||
cha_sys = self.check_chassis_systems(chas)
|
||||
if cha_sys != []:
|
||||
for s in cha_sys:
|
||||
system = SYSTEM_COL.get_member(s)
|
||||
sys_inv = self.create_child_inventory(system.identity)
|
||||
sys_inv = self.create_child_inventory(s)
|
||||
try:
|
||||
provider_tree.new_child(s, nodename)
|
||||
except Exception as ex:
|
||||
@ -375,7 +376,12 @@ class RSDDriver(driver.ComputeDriver):
|
||||
|
||||
def create_child_inventory(self, system):
|
||||
"""Create custom resources for all of the child RP's."""
|
||||
res = fields.ResourceClass.normalize_name(system)
|
||||
SYSTEM_COL = self.driver.PODM.get_system_collection()
|
||||
sys = SYSTEM_COL.get_member(system)
|
||||
mem = self.conv_GiB_to_MiB(sys.memory_summary.size_gib) - 512
|
||||
proc = sys.processors.summary.count
|
||||
flav_id = str(mem) + 'MB-' + str(proc) + 'vcpus'
|
||||
res = fields.ResourceClass.normalize_name(flav_id)
|
||||
return {
|
||||
res: {
|
||||
'total': 1,
|
||||
@ -403,7 +409,7 @@ class RSDDriver(driver.ComputeDriver):
|
||||
mem = self.conv_GiB_to_MiB(sys.memory_summary.size_gib) - 512
|
||||
proc = sys.processors.summary.count
|
||||
flav_id = str(mem) + 'MB-' + str(proc) + 'vcpus'
|
||||
res = fields.ResourceClass.normalize_name(sys.identity)
|
||||
res = fields.ResourceClass.normalize_name(flav_id)
|
||||
spec = 'resources:' + res
|
||||
values = {
|
||||
'name': 'RSD-' + flav_id,
|
||||
@ -441,10 +447,26 @@ class RSDDriver(driver.ComputeDriver):
|
||||
def check_flavors(self, collection, systems):
|
||||
"""Check if flavors should be deleted based on system removal."""
|
||||
sys_ids = []
|
||||
flav_ids = []
|
||||
LOG.debug("Checking existing flavors.")
|
||||
for s in systems:
|
||||
sys = collection.get_member(s)
|
||||
sys_ids.append(sys.identity)
|
||||
mem = self.conv_GiB_to_MiB(sys.memory_summary.size_gib) - 512
|
||||
proc = sys.processors.summary.count
|
||||
flav_id = str(mem) + 'MB-' + str(proc) + 'vcpus'
|
||||
flav_ids.append(flav_id)
|
||||
|
||||
f_list = objects.FlavorList.get_all(context.get_admin_context())
|
||||
for f in f_list:
|
||||
if 'RSD' in f.name:
|
||||
if f.flavorid not in flav_ids:
|
||||
try:
|
||||
flavor._flavor_destroy(
|
||||
context.get_admin_context(),
|
||||
flavor_id=f.flavorid)
|
||||
except exception.FlavorNotFound as ex:
|
||||
LOG.warn("Flavor not found exception: %s", ex)
|
||||
|
||||
for k in list(self.rsd_flavors):
|
||||
sys_list = self.rsd_flavors[k]['rsd_systems']
|
||||
|
Loading…
Reference in New Issue
Block a user