def skip_check_predicate_podm_2_5(discovery_container, requirement): if requirement.base in [MetadataConstants.MEMORY, MetadataConstants.PROCESSOR, MetadataConstants.VLAN_NETWORK_INTERFACE_COLLECTION]: num_systems = discovery_container.count_resources(MetadataConstants.COMPUTER_SYSTEM, any_child_version=True) num_virtual_systems = len(discovery_container.get_resources(MetadataConstants.COMPUTER_SYSTEM, any_child_version=True, constraints=[equal("SystemType", "Virtual")])) return (num_systems > 0 and num_systems == num_virtual_systems)
def skip_check_predicate_podm_2_4(discovery_container, requirement): if requirement.base in [MetadataConstants.MEMORY, MetadataConstants.PROCESSOR, MetadataConstants.VLAN_NETWORK_INTERFACE_COLLECTION]: num_systems = discovery_container.count_resources(MetadataConstants.COMPUTER_SYSTEM, any_child_version=True) num_virtual_systems = len(discovery_container.get_resources(MetadataConstants.COMPUTER_SYSTEM, any_child_version=True, constraints=[equal("SystemType", "Virtual")])) return (num_systems > 0 and num_systems == num_virtual_systems)
def test_dataframes(self): metadata_container = MetadataManager(["qualifier"]).\ read_metadata_from_strings("Unknown", self.TEST_METADATA) dc = DiscoveryContainer(service_root="/redfish/v1", metadata_container=metadata_container) chassis1_2_1 = { "@odata.context": "/redfish/v1/$metadata#Chassis/Members/$entity", "@odata.id": "/redfish/v1/Chassis/Rack1", "@odata.type": "#Chassis.v1_2_0.Chassis", "ChassisType": "Rack", "SomeValue": 1, } chassis1_2_2 = { "@odata.context": "/redfish/v1/$metadata#Chassis/Members/$entity", "@odata.id": "/redfish/v1/Chassis/Rack2", "@odata.type": "#Chassis.v1_2_0.Chassis", "ChassisType": "Rack", "SomeValue": 3, } chassis1_0_1 = { "@odata.context": "/redfish/v1/$metadata#Chassis/Members/$entity", "@odata.id": "/redfish/v1/Chassis/Module1", "@odata.type": "#Chassis.v1_0_0.Chassis", "ChassisType": "Module", "SomeValue": 2, } chassis1_0_2 = { "@odata.context": "/redfish/v1/$metadata#Chassis/Members/$entity", "@odata.id": "/redfish/v1/Chassis/Module2", "@odata.type": "#Chassis.v1_0_0.Chassis", "ChassisType": "Module", "SomeValue": 4, } dc.add_resource( ApiResource("/redfish/v1/Chassis/Rack1", 'netloc', chassis1_2_1, "Chassis.v1_2_0.Chassis")) dc.add_resource( ApiResource("/redfish/v1/Chassis/Rack2", 'netloc', chassis1_2_2, "Chassis.v1_2_0.Chassis")) dc.add_resource( ApiResource("/redfish/v1/Chassis/Module1", 'netloc', chassis1_0_1, "Chassis.v1_0_0.Chassis")) dc.add_resource( ApiResource("/redfish/v1/Chassis/Module2", 'netloc', chassis1_0_2, "Chassis.v1_0_0.Chassis")) def _some_values(resource_list): return [ resource.body["SomeValue"] for _, resource in resource_list ] self.assertEqual(2, dc.count_resources("Chassis.v1_2_0.Chassis")) self.assertEqual( 2, dc.count_resources("Chassis.v1_2_0.Chassis", any_child_version=True)) self.assertEqual(2, dc.count_resources("Chassis.v1_0_0.Chassis")) self.assertEqual( 4, dc.count_resources("Chassis.v1_0_0.Chassis", any_child_version=True)) self.assertEqual(0, dc.count_resources("Chassis.Chassis")) self.assertEqual( 4, dc.count_resources("Chassis.Chassis", any_child_version=True)) self.assertEqual([1, 2, 3, 4], _some_values( dc.get_resources( "Chassis.Chassis", any_child_version=True, constraints=[order_by("SomeValue")]))) self.assertEqual(2, len(dc.get_resources("Chassis.v1_2_0.Chassis"))) self.assertEqual( 4, len(dc.get_resources("Chassis.Chassis", any_child_version=True))) self.assertEqual([1, 2, 3], _some_values( dc.get_resources( "Chassis.Chassis", any_child_version=True, constraints=[order_by("SomeValue"), first(3)]))) self.assertEqual([2, 1], _some_values( dc.get_resources("Chassis.Chassis", any_child_version=True, constraints=[ order_by("SomeValue", ascending=False), last(2) ]))) self.assertEqual([3, 4], _some_values( dc.get_resources( "Chassis.Chassis", any_child_version=True, constraints=[order_by("SomeValue"), last(2)]))) self.assertEqual( 2, len( dc.get_resources("Chassis.Chassis", any_child_version=True, constraints=[less("SomeValue", 3)]))) self.assertEqual( 3, len( dc.get_resources("Chassis.Chassis", any_child_version=True, constraints=[less_or_equal("SomeValue", 3)]))) self.assertEqual( 1, len( dc.get_resources("Chassis.Chassis", any_child_version=True, constraints=[equal("SomeValue", 3)]))) self.assertEqual( 3, len( dc.get_resources("Chassis.Chassis", any_child_version=True, constraints=[not_equal("SomeValue", 3)]))) self.assertEqual( 0, len( dc.get_resources("Chassis.Chassis", any_child_version=False, constraints=[order_by("SomeValue")]))) self.assertEqual( 0, len( dc.get_resources("Chassis.v1_2_0.Chassis", any_child_version=False, constraints=[greater("SomeValue", 3)]))) self.assertEqual( 1, len( dc.get_resources("Chassis.v1_0_0.Chassis", any_child_version=True, constraints=[greater("SomeValue", 3)]))) self.assertEqual( 2, len( dc.get_resources( "Chassis.v1_0_0.Chassis", any_child_version=True, constraints=[greater_or_equal("SomeValue", 3)]))) self.assertEqual( 4, len( dc.get_resources( "Chassis.v1_0_0.Chassis", any_child_version=True, constraints=[from_collection("/redfish/v1/Chassis")]))) chassis1_0_2["@odata.id"] = "/redfish/v1/Chassis2/Module2" dc.add_resource( ApiResource("/redfish/v1/Chassis2/Module2", 'netloc', chassis1_0_2, "Chassis.v1_0_0.Chassis")) self.assertEqual( 4, len( dc.get_resources( "Chassis.v1_0_0.Chassis", any_child_version=True, constraints=[from_collection("/redfish/v1/Chassis")]))) self.assertEqual( 1, len( dc.get_resources( "Chassis.v1_0_0.Chassis", any_child_version=True, constraints=[from_collection("/redfish/v1/Chassis2")]))) self.assertEqual( 2, len( dc.get_resources("Chassis.v1_0_0.Chassis", any_child_version=True, constraints=[ urls([ "/redfish/v1/Chassis/Rack1", "/redfish/v1/Chassis/Module1" ]) ])))
def crud_remote_target(self): """ Test is checking for rsa compute blade presence """ ld_created_for_crud = False target_iqn = "cts.target:cts_test_target" target_iqns = set() chosen_logical_drive, chosen_remote_target_collection = None, None if not self.discovery_container.count_resources(MetadataConstants.LOGICAL_DRIVE, any_child_version=True): cts_error("Insufficient resources for API test. No logical drives found.") return ValidationStatus.BLOCKED logical_drives = dict(self.discovery_container.get_resources(MetadataConstants.LOGICAL_DRIVE, any_child_version=True, constraints=[equal("Mode", "LV"), equal("Protected", False)])) if not logical_drives: logical_drives = dict(self.discovery_container.get_resources(MetadataConstants.LOGICAL_DRIVE, any_child_version=True, constraints=[equal("Mode", "RBD"), equal("Protected", False)])) try: chosen_remote_target_collection = self.discovery_container.get_resources( MetadataConstants.REMOTE_TARGET_COLLECTION, any_child_version=True)[0][0] chosen_logical_drive = [link for link, resource in logical_drives.iteritems() if not len(resource.body["Links"]["Targets"])][0] except (KeyError, IndexError): pass if not chosen_remote_target_collection: cts_error("Insufficient resources available on API for test. Could not find any remote target collection") return ValidationStatus.BLOCKED if not chosen_logical_drive: cts_warning("Insufficient resources available on API for test. Could not find an unprotected logical drive " "with no targets attached") print "MESSAGE::Trying to create a new logical volume for the target, then proceeding with remote target "\ "CRUD test" if self.crud_logical_drive(create_logical_drive_for_target_crud=True) == ValidationStatus.PASSED: chosen_logical_drive = self.created_logical_drive ld_created_for_crud = True else: cts_error("Creating a new logical volume for the target failed, skipping remote target tests") return ValidationStatus.BLOCKED targets = [link for link, resource in self.discovery_container.get_resources(MetadataConstants.REMOTE_TARGET, any_child_version=True, constraints=[ from_collection(chosen_remote_target_collection) ])] for target in targets: addresses = self.discovery_container[target].body["Addresses"] for address in addresses: try: target_iqns.add(address["iSCSI"]["TargetIQN"]) except KeyError: pass if target_iqn in target_iqns: iqn_number = 0 while target_iqn + str(iqn_number) in target_iqns: iqn_number += 1 target_iqn = target_iqn + str(iqn_number) print "MESSAGE::Remote Target CRUD test will be performed on remote target collection %s, creating remote "\ "target based on %s with first lowest consecutive \'cts.target:cts_test_target<number>\' target IQN "\ "available: %s" % (chosen_remote_target_collection, chosen_logical_drive, target_iqn) self.post_remote_target_payload = dict( Addresses=[dict( iSCSI=dict( TargetIQN=target_iqn, TargetLUN=[dict( LUN=1, LogicalDrive={"@odata.id": urlparse(chosen_logical_drive).path} )], ) )], Initiator=[dict( iSCSI=dict( InitiatorIQN="cts.initiator:initiator_cts_test" ) )] ) status = self._test_case_create_remote_target(chosen_remote_target_collection) if status == ValidationStatus.PASSED: # only perform other tests if creation was successful status = ValidationStatus.join_statuses(status, self._test_case_get_created_remote_target()) status = ValidationStatus.join_statuses(status, self._test_case_logical_drive_has_link_to_created_target( chosen_logical_drive)) status = ValidationStatus.join_statuses(status, self._test_case_update_created_remote_target()) status = ValidationStatus.join_statuses(status, self._test_case_delete_created_remote_target()) status = ValidationStatus.join_statuses(status, self._test_case_get_deleted_remote_target()) if ld_created_for_crud: ld = self.created_logical_drive del_status = self._test_case_delete_created_logical_drive(ld) del_status = ValidationStatus.join_statuses(del_status, self._test_case_get_deleted_logical_drive(ld)) if status == ValidationStatus.PASSED and del_status != status: cts_error("Remote target CRUD test passed, but the logical drive it created failed to delete properly") status = ValidationStatus.PASSED_WITH_WARNINGS return status
def crud_logical_drive(self, create_logical_drive_for_target_crud=None): """ Test is trying to perform CRUD (create, read, update, delete) operations on a logical drive :type create_logical_drive_for_target_crud: Boolean """ status = ValidationStatus.BLOCKED lvm_found = False chosen_logical_drive_type, chosen_logical_drive_mode = None, None chosen_logical_drive_collection, chosen_logical_drive, chosen_logical_drive_group = None, None, None inherited_bootable = None # to speed things up, always look for the lowest capacity logical drive LVM_LV_SPECIFIC_CONSTRAINTS = [equal("Mode", "LV"), greater("CapacityGiB", 0), not_equal("Snapshot", True), order_by("CapacityGiB")] CEPH_RBD_SPECIFIC_CONSTRAINTS = [equal("Mode", "RBD"), greater("CapacityGiB", 0), order_by("CapacityGiB")] logical_drive_collections = dict(self.discovery_container.get_resources( MetadataConstants.LOGICAL_DRIVE_COLLECTION, any_child_version=True)) for collection in logical_drive_collections.keys(): chosen_logical_drive_collection = collection logical_drive_groups = dict(self.discovery_container.get_resources(MetadataConstants.LOGICAL_DRIVE, any_child_version=True, constraints=[equal("Mode", "LVG"), from_collection(collection)])) if logical_drive_groups: lvm_found = True else: logical_drive_groups = dict(self.discovery_container.get_resources(MetadataConstants.LOGICAL_DRIVE, any_child_version=True, constraints=[equal("Mode", "Pool"), from_collection( collection)])) if logical_drive_groups: specific_constraints = LVM_LV_SPECIFIC_CONSTRAINTS if lvm_found else CEPH_RBD_SPECIFIC_CONSTRAINTS for lvg_link, lvg in logical_drive_groups.iteritems(): chosen_logical_drive_group = lvg.odata_id try: child_lvs = [lv["@odata.id"] for lv in lvg.body["Links"]["LogicalDrives"]] chosen_logical_drive, _ = self.discovery_container.get_resources( MetadataConstants.LOGICAL_DRIVE, any_child_version=True, constraints=specific_constraints + [odata_ids(child_lvs)])[0] lv = self.discovery_container[chosen_logical_drive] inherited_bootable = lv.body["Bootable"] chosen_logical_drive_type = lv.body["Type"] chosen_logical_drive_mode = lv.body["Mode"] except (KeyError,IndexError) as error: cts_error("Exception while parsing {id:id}: {error:exception}", id=chosen_logical_drive, error=error) chosen_logical_drive = None pass else: break if not chosen_logical_drive_group: resource = "logical drive group" if lvm_found else "Pool" cts_warning("Could not find a {resource} resource in collection {collection}", **locals()) if lvm_found and not chosen_logical_drive: cts_warning("Could not find a logical volume in collection {collection}", **locals()) if lvm_found and not chosen_logical_drive: cts_error("Could not find any logical volume") return status if not chosen_logical_drive_group: cts_error("Could not find any logical drive group, aborting") return status self.post_logical_drive_payload = dict( Name="LVM Logical Drive created by CTS", Type=chosen_logical_drive_type, Mode=chosen_logical_drive_mode, Protected=False, CapacityGiB=self.discovery_container[chosen_logical_drive].body["CapacityGiB"], Image="CTS test image", Bootable=inherited_bootable if inherited_bootable else False, Snapshot=True, Links=dict( LogicalDrives=[{"@odata.id": chosen_logical_drive_group}], MasterDrive={"@odata.id": urlparse(chosen_logical_drive).path} ) ) # Creating the first RBD if no other was found if not chosen_logical_drive: if lvm_found: print "ERROR::Could not find a logical drive suitable for snapshot" return status cts_warning("Could not find any logical drive suitable for snapshot. Since CEPH was detected, CTS will "\ "try to create the first RBD") self.post_logical_drive_payload = dict( Name="CEPH Logical Drive created by CTS", Type="CEPH", Mode="RBD", Protected=False, CapacityGiB=self.discovery_container[chosen_logical_drive_group].body["CapacityGiB"]/2, Bootable=False, Snapshot=False, Links=dict( LogicalDrives=[{"@odata.id": urlparse(chosen_logical_drive_group).path}], MasterDrive=None ) ) print "MESSAGE::Logical drive CRUD test will be performed on logical drive collection %s, creating logical " \ "drive based on %s on group %s" % (chosen_logical_drive_collection, chosen_logical_drive, chosen_logical_drive_group) self.expected_created_logical_drive_body = deepcopy(self.post_logical_drive_payload) # The logical drive in LogicalDrives link is really the volume group and is going to be seen under # UsedBy on REST self.expected_created_logical_drive_body["Links"]["UsedBy"] = \ self.expected_created_logical_drive_body["Links"]["LogicalDrives"] self.expected_created_logical_drive_body["Links"]["LogicalDrives"] = [] status = self._test_case_create_logical_drive(chosen_logical_drive_collection) if status == ValidationStatus.PASSED: # only perform other tests if creation was successful ld = self.created_logical_drive status = ValidationStatus.join_statuses(status, self._test_case_get_created_logical_drive(ld)) if create_logical_drive_for_target_crud: return status if status == ValidationStatus.PASSED: status = ValidationStatus.join_statuses(status, self._test_case_update_created_logical_drive()) status = ValidationStatus.join_statuses(status, self._test_case_delete_created_logical_drive(ld)) status = ValidationStatus.join_statuses(status, self._test_case_get_deleted_logical_drive(ld)) return status
def test_dataframes(self): metadata_container = MetadataManager(["qualifier"]).\ read_metadata_from_strings("Unknown", self.TEST_METADATA) dc = DiscoveryContainer(service_root="/redfish/v1", metadata_container=metadata_container) chassis1_2_1 = { "@odata.context": "/redfish/v1/$metadata#Chassis/Members/$entity", "@odata.id": "/redfish/v1/Chassis/Rack1", "@odata.type": "#Chassis.v1_2_0.Chassis", "ChassisType": "Rack", "SomeValue": 1, } chassis1_2_2 = { "@odata.context": "/redfish/v1/$metadata#Chassis/Members/$entity", "@odata.id": "/redfish/v1/Chassis/Rack2", "@odata.type": "#Chassis.v1_2_0.Chassis", "ChassisType": "Rack", "SomeValue": 3, } chassis1_0_1 = { "@odata.context": "/redfish/v1/$metadata#Chassis/Members/$entity", "@odata.id": "/redfish/v1/Chassis/Module1", "@odata.type": "#Chassis.v1_0_0.Chassis", "ChassisType": "Module", "SomeValue": 2, } chassis1_0_2 = { "@odata.context": "/redfish/v1/$metadata#Chassis/Members/$entity", "@odata.id": "/redfish/v1/Chassis/Module2", "@odata.type": "#Chassis.v1_0_0.Chassis", "ChassisType": "Module", "SomeValue": 4, } dc.add_resource(ApiResource("/redfish/v1/Chassis/Rack1", 'netloc', chassis1_2_1, "Chassis.v1_2_0.Chassis")) dc.add_resource(ApiResource("/redfish/v1/Chassis/Rack2", 'netloc',chassis1_2_2, "Chassis.v1_2_0.Chassis")) dc.add_resource(ApiResource("/redfish/v1/Chassis/Module1", 'netloc',chassis1_0_1, "Chassis.v1_0_0.Chassis")) dc.add_resource(ApiResource("/redfish/v1/Chassis/Module2", 'netloc',chassis1_0_2, "Chassis.v1_0_0.Chassis")) def _some_values(resource_list): return [resource.body["SomeValue"] for _, resource in resource_list] self.assertEqual(2, dc.count_resources("Chassis.v1_2_0.Chassis")) self.assertEqual(2, dc.count_resources("Chassis.v1_2_0.Chassis", any_child_version=True)) self.assertEqual(2, dc.count_resources("Chassis.v1_0_0.Chassis")) self.assertEqual(4, dc.count_resources("Chassis.v1_0_0.Chassis", any_child_version=True)) self.assertEqual(0, dc.count_resources("Chassis.Chassis")) self.assertEqual(4, dc.count_resources("Chassis.Chassis", any_child_version=True)) self.assertEqual([1,2,3,4], _some_values(dc.get_resources("Chassis.Chassis", any_child_version=True, constraints=[order_by("SomeValue")]))) self.assertEqual(2, len(dc.get_resources("Chassis.v1_2_0.Chassis"))) self.assertEqual(4, len(dc.get_resources("Chassis.Chassis", any_child_version=True))) self.assertEqual([1,2,3], _some_values(dc.get_resources("Chassis.Chassis", any_child_version=True, constraints=[order_by("SomeValue"), first(3)]))) self.assertEqual([2,1], _some_values(dc.get_resources("Chassis.Chassis", any_child_version=True, constraints=[order_by("SomeValue", ascending=False), last(2)]))) self.assertEqual([3,4], _some_values(dc.get_resources("Chassis.Chassis", any_child_version=True, constraints=[order_by("SomeValue"), last(2)]))) self.assertEqual(2, len(dc.get_resources("Chassis.Chassis", any_child_version=True, constraints=[less("SomeValue", 3)]))) self.assertEqual(3, len(dc.get_resources("Chassis.Chassis", any_child_version=True, constraints=[less_or_equal("SomeValue", 3)]))) self.assertEqual(1, len(dc.get_resources("Chassis.Chassis", any_child_version=True, constraints=[equal("SomeValue", 3)]))) self.assertEqual(3, len(dc.get_resources("Chassis.Chassis", any_child_version=True, constraints=[not_equal("SomeValue", 3)]))) self.assertEqual(0, len(dc.get_resources("Chassis.Chassis", any_child_version=False, constraints=[order_by("SomeValue")]))) self.assertEqual(0, len(dc.get_resources("Chassis.v1_2_0.Chassis", any_child_version=False, constraints=[greater("SomeValue", 3)]))) self.assertEqual(1, len(dc.get_resources("Chassis.v1_0_0.Chassis", any_child_version=True, constraints=[greater("SomeValue", 3)]))) self.assertEqual(2, len(dc.get_resources("Chassis.v1_0_0.Chassis", any_child_version=True, constraints=[greater_or_equal("SomeValue", 3)]))) self.assertEqual(4, len(dc.get_resources("Chassis.v1_0_0.Chassis", any_child_version=True, constraints=[from_collection("/redfish/v1/Chassis")]))) chassis1_0_2["@odata.id"] = "/redfish/v1/Chassis2/Module2" dc.add_resource(ApiResource("/redfish/v1/Chassis2/Module2", 'netloc', chassis1_0_2, "Chassis.v1_0_0.Chassis")) self.assertEqual(4, len(dc.get_resources("Chassis.v1_0_0.Chassis", any_child_version=True, constraints=[from_collection("/redfish/v1/Chassis")]))) self.assertEqual(1, len(dc.get_resources("Chassis.v1_0_0.Chassis", any_child_version=True, constraints=[from_collection("/redfish/v1/Chassis2")]))) self.assertEqual(2, len(dc.get_resources("Chassis.v1_0_0.Chassis", any_child_version=True, constraints=[urls(["/redfish/v1/Chassis/Rack1", "/redfish/v1/Chassis/Module1"])])))