def test_set_traits_resets_changes(self, mock_set_traits, mock_reset): trait = resource_provider.Trait(name="HW_CPU_X86_AVX2") traits = resource_provider.TraitList(objects=[trait]) rp = resource_provider.ResourceProvider(self.context, name='cn1', uuid=uuids.cn1) rp.set_traits(traits) mock_set_traits.assert_called_once_with(self.context, rp, traits) mock_reset.assert_called_once_with()
def set_traits(rp, *traits): tlist = [] for tname in traits: try: trait = rp_obj.Trait.get_by_name(rp._context, tname) except exception.TraitNotFound: trait = rp_obj.Trait(rp._context, name=tname) trait.create() tlist.append(trait) rp.set_traits(rp_obj.TraitList(objects=tlist)) return tlist
def delete_traits_for_resource_provider(req): context = req.environ['placement.context'] uuid = util.wsgi_path_item(req.environ, 'uuid') resource_provider = rp_obj.ResourceProvider.get_by_uuid(context, uuid) try: resource_provider.set_traits(rp_obj.TraitList(objects=[])) except exception.ConcurrentUpdateDetected as e: raise webob.exc.HTTPConflict(explanation=e.format_message()) req.response.status = 204 req.response.content_type = None return req.response
def delete_traits_for_resource_provider(req): context = req.environ['placement.context'] context.can(policies.RP_TRAIT_DELETE) uuid = util.wsgi_path_item(req.environ, 'uuid') resource_provider = rp_obj.ResourceProvider.get_by_uuid(context, uuid) try: resource_provider.set_traits(rp_obj.TraitList(objects=[])) except exception.ConcurrentUpdateDetected as e: raise webob.exc.HTTPConflict(e.format_message(), comment=errors.CONCURRENT_UPDATE) req.response.status = 204 req.response.content_type = None return req.response
def start_fixture(self): super(SharedStorageFixture, self).start_fixture() self.context = context.get_admin_context() cn1_uuid = uuidutils.generate_uuid() cn2_uuid = uuidutils.generate_uuid() ss_uuid = uuidutils.generate_uuid() agg_uuid = uuidutils.generate_uuid() os.environ['CN1_UUID'] = cn1_uuid os.environ['CN2_UUID'] = cn2_uuid os.environ['SS_UUID'] = ss_uuid os.environ['AGG_UUID'] = agg_uuid cn1 = rp_obj.ResourceProvider( self.context, name='cn1', uuid=cn1_uuid) cn1.create() cn2 = rp_obj.ResourceProvider( self.context, name='cn2', uuid=cn2_uuid) cn2.create() ss = rp_obj.ResourceProvider( self.context, name='ss', uuid=ss_uuid) ss.create() # Populate compute node inventory for VCPU and RAM for cn in (cn1, cn2): vcpu_inv = rp_obj.Inventory( self.context, resource_provider=cn, resource_class='VCPU', total=24, reserved=0, max_unit=24, min_unit=1, step_size=1, allocation_ratio=16.0) vcpu_inv.obj_set_defaults() ram_inv = rp_obj.Inventory( self.context, resource_provider=cn, resource_class='MEMORY_MB', total=128 * 1024, reserved=0, max_unit=128 * 1024, min_unit=256, step_size=256, allocation_ratio=1.5) ram_inv.obj_set_defaults() inv_list = rp_obj.InventoryList(objects=[vcpu_inv, ram_inv]) cn.set_inventory(inv_list) t_avx_sse = rp_obj.Trait.get_by_name(self.context, "HW_CPU_X86_SSE") t_avx_sse2 = rp_obj.Trait.get_by_name(self.context, "HW_CPU_X86_SSE2") cn1.set_traits(rp_obj.TraitList(objects=[t_avx_sse, t_avx_sse2])) # Populate shared storage provider with DISK_GB inventory disk_inv = rp_obj.Inventory( self.context, resource_provider=ss, resource_class='DISK_GB', total=2000, reserved=100, max_unit=2000, min_unit=10, step_size=10, allocation_ratio=1.0) disk_inv.obj_set_defaults() inv_list = rp_obj.InventoryList(objects=[disk_inv]) ss.set_inventory(inv_list) # Mark the shared storage pool as having inventory shared among any # provider associated via aggregate t = rp_obj.Trait.get_by_name( self.context, "MISC_SHARES_VIA_AGGREGATE", ) ss.set_traits(rp_obj.TraitList(objects=[t])) # Now associate the shared storage pool and both compute nodes with the # same aggregate cn1.set_aggregates([agg_uuid]) cn2.set_aggregates([agg_uuid]) ss.set_aggregates([agg_uuid])