Пример #1
0
    def crud_vlan(self):
        """
        Test is trying to perform CRUD (create, read, update, delete) operations on a VLAN Network Interface resource
        """
        requirements = [
            Requirement(MetadataConstants.SERVICE_ROOT, min=1, max=1),
            Requirement(MetadataConstants.VLAN_NETWORK_INTERFACE_COLLECTION,
                        min=1),
        ]
        preconditions = Preconditions(self.metadata_container, requirements)
        status = preconditions.validate(self.discovery_container)

        if status is ValidationStatus.PASSED_WITH_WARNINGS:
            cts_warning(
                "Without some components it is not possible to perform tests.")
            print "STATUS::{status}".format(status=status)
            return ValidationStatus.PASSED_WITH_WARNINGS

        if status is ValidationStatus.FAILED:
            return ValidationStatus.BLOCKED

        vlan_network_interface_collections = \
            dict(self.discovery_container.get_resources(MetadataConstants.VLAN_NETWORK_INTERFACE_COLLECTION,
                 any_child_version=True))

        chosen_vlan_network_interface_collection = None
        new_vlan_id = 0

        for vlan_network_interface_collection in vlan_network_interface_collections:
            present_vlan_ids = []
            vlan_network_interfaces = \
                dict(self.discovery_container.
                     get_resources(MetadataConstants.VLAN_NETWORK_INTERFACE,
                                   constraints=[from_collection(vlan_network_interface_collection)],
                                   any_child_version=True))

            if len(vlan_network_interfaces) > MAX_VLAN_ID - MIN_VLAN_ID:
                continue
            for resource_link, resource in vlan_network_interfaces.iteritems():
                try:
                    present_vlan_ids.append(resource.body["VLANId"])
                except:
                    cts_error("Inorrect resource {resource_link:id} structure",
                              **locals())

            for possible_id in range(MIN_VLAN_ID, MAX_VLAN_ID + 1):
                if possible_id not in present_vlan_ids:
                    chosen_vlan_network_interface_collection = vlan_network_interface_collection
                    new_vlan_id = possible_id
                    break

            if chosen_vlan_network_interface_collection:
                break

        if chosen_vlan_network_interface_collection:
            print "MESSAGE::CRUD test will be performed on vlan network interface collection %s" % \
                  chosen_vlan_network_interface_collection
        else:
            cts_warning('No free VLAN id available')
            return ValidationStatus.BLOCKED

        self.post_vlan_payload = dict(
            VLANId=new_vlan_id,
            VLANEnable=True,
            Oem=dict(Intel_RackScale=dict(Tagged=True)))

        if self._test_case_create_vlan(
                chosen_vlan_network_interface_collection):
            self._test_case_get_created_vlan()
            self._test_case_delete_created_vlan()
            self._test_case_get_deleted_vlan()
Пример #2
0
    def crud_acl_rule(self):
        """
        Test is trying to perform CRUD (create, read, update, delete) as well as binding operations on an ACL and ACL
        Rule resource
        """
        switches = \
            dict(self.discovery_container.get_resources(MetadataConstants.ETHERNET_SWITCH, any_child_version=True))

        all_ports = []

        if not switches:
            cts_error(
                "Could not find any Ethernet Switch to perform the test on, aborting"
            )
            return ValidationStatus.BLOCKED

        chosen_switch, chosen_acl_collection, chosen_port, mirrored_port = None, None, None, None

        for switch in switches.keys():
            acl_collections = dict(
                self.discovery_container.get_resources(
                    MetadataConstants.ETHERNET_SWITCH_ACL_COLLECTION,
                    any_child_version=True,
                    constraints=[from_collection(switch)]))
            if acl_collections:
                chosen_switch = switch
                chosen_acl_collection = choice(acl_collections.keys())

                all_ports = [
                    port[1].odata_id
                    for port in self.discovery_container.get_resources(
                        MetadataConstants.ETHERNET_SWITCH_PORT,
                        any_child_version=True,
                        constraints=[from_collection(chosen_switch)])
                ]

                try:
                    chosen_port = choice(all_ports)
                    all_ports.remove(chosen_port)
                    mirrored_port = choice(all_ports)
                except IndexError:
                    if not chosen_port:
                        print "MESSAGE::Could not find a proper port for ACL binding on the switch"
                        continue
                    else:
                        print "WARNING::Only one proper port found, unable to create a Mirror rule"
                        break

        if not chosen_acl_collection:
            cts_error(
                "Could not find any ACL collection on any of the present Ethernet Switches, aborting"
            )
            return ValidationStatus.BLOCKED

        if not chosen_port:
            cts_error(
                "Could not find any proper port for ACL binding on any of the present Ethernet Switches, aborting"
            )
            return ValidationStatus.BLOCKED


        print "MESSAGE:CRUD test will be performed on ACL collection: {collection}, the test will attempt to bind and "\
              "unbind the ACL from the port: {port}".format(collection=chosen_acl_collection, port=chosen_port)

        self.post_acl_payload = dict()
        self.rules_payloads = dict()

        self.rules_payloads["Deny"] = dict(
            Action="Deny",
            Condition=dict(MACSource=dict(MACAddress="AA:BB:CC:DD:EE:FF",
                                          Mask="FF:FF:FF:00:00:00")))

        self.rules_payloads["Permit"] = dict(
            Action="Permit",
            Condition=dict(IPSource=dict(IPv4Address="192.168.0.1",
                                         Mask="255.255.255.0")))

        self.rules_payloads["Forward"] = dict(
            Action="Forward",
            ForwardMirrorInterface={"@odata.id": chosen_port},
            Condition=dict(IPDestination=dict(IPv4Address="1.1.1.1")))

        if mirrored_port:
            self.rules_payloads["Mirror"] = dict(
                RuleId=1111,
                Action="Mirror",
                ForwardMirrorInterface={"@odata.id": chosen_port},
                MirrorPortRegion=[{
                    "@odata.id": mirrored_port
                }],
                MirrorType="Egress",
                Condition=dict(VLANId=dict(Id=1, Mask=None)))

        # basic rules (Deny and Permit actions) should be supported by any PSME service; therefore failure in adding
        # them triggers FAILED status for the test. If the mandatory rules are added successfully, but there is an
        # error while adding the optional (Forward and Mirror actions) rules, the test's result is PASSED WITH WARNINGS
        self.mandatory_rules = ["Deny", "Permit"]

        if self._test_case_create_acl(chosen_acl_collection):
            self._test_case_get_created_acl()
            if self._test_case_add_rules_to_acl(
            ):  # Rules need to be added before binding
                if self._test_case_bind_acl_to_port(chosen_port):
                    if self._test_case_bound_acl_and_port_are_linked(
                            chosen_port, True):
                        if self._test_case_unbind_acl_from_port(chosen_port):
                            self._test_case_bound_acl_and_port_are_linked(
                                chosen_port, False)
                self._test_case_delete_rules_from_acl()
            self._test_case_delete_created_acl()
            self._test_case_get_deleted_acl()
Пример #3
0
    def crud_static_mac(self):
        """
            Test is trying to perform CRUD (create, read, update, delete) operations on a Static MAC resource
            """
        def _find_unique_mac_address_vlan_id_pair(present_pairs):
            MAX_ADDRESS = 281474976710656 - 1  # 16^12 - 1

            def address_to_string(address):
                parts = []
                for _ in range(6):
                    parts.append(address % 256)
                    address = address / 256
                return ":".join("{0:02x}".format(part)
                                for part in parts).upper()

            address = 0
            vlan_id = MIN_VLAN_ID
            while (address_to_string(address), vlan_id) in present_pairs:
                address = address + 1
                if address > MAX_ADDRESS:
                    address = 0
                    vlan_id = vlan_id + 1
                    if vlan_id > MAX_VLAN_ID:
                        return None
            return (address_to_string(address), vlan_id)

        requirements = [
            Requirement(MetadataConstants.SERVICE_ROOT, min=1, max=1),
            Requirement(MetadataConstants.ETHERNET_SWITCH, min=1),
            Requirement(MetadataConstants.ETHERNET_SWITCH_PORT, min=1),
            Requirement(MetadataConstants.STATIC_MAC_COLLECTION, min=1),
        ]
        preconditions = Preconditions(self.metadata_container, requirements)

        if preconditions.validate(
                self.discovery_container) == ValidationStatus.FAILED:
            return ValidationStatus.BLOCKED

        static_mac_collections = \
            dict(self.discovery_container.get_resources(MetadataConstants.STATIC_MAC_COLLECTION,
                 any_child_version=True))

        chosen_static_mac_collection = static_mac_collections.keys()[0]

        print "MESSAGE::\nMESSAGE::Static MAC CRUD test will be performed on collection: {}"\
            .format(chosen_static_mac_collection)

        present_vlan_id_mac_address_pairs = []

        for resource_link, resource in self.discovery_container.get_resources(
                MetadataConstants.STATIC_MAC,
                any_child_version=True,
                constraints=[from_collection(chosen_static_mac_collection)]):
            try:
                present_vlan_id_mac_address_pairs.append(
                    (resource.body["MACAddress"], resource.body["VLANId"]))
            except Exception as err:
                cts_warning(
                    "{link:id} Incorrect resource structure; err={err:exception}",
                    link=resource_link,
                    err=err)

        initial_values = _find_unique_mac_address_vlan_id_pair(
            present_vlan_id_mac_address_pairs)

        if not initial_values:
            cts_error("Cannot create a Static MAC on the chosen collection - "
                      "all MAC addresses and VLAN ids already occupied")
            return ValidationStatus.BLOCKED

        self.post_static_mac_payload = dict(MACAddress=initial_values[0],
                                            VLANId=initial_values[1])

        # PSME does not support patching Static MAC
        if self._test_case_create_static_mac(chosen_static_mac_collection):
            self._test_case_get_created_static_mac()
            self._test_case_delete_created_static_mac()
            self._test_case_get_deleted_static_mac()
Пример #4
0
    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"
                                     ])
                                 ])))
Пример #5
0
    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
Пример #6
0
    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
Пример #7
0
    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"])])))
Пример #8
0
    def crud_vlan(self):
        """
        Test is trying to perform CRUD (create, read, update, delete) operations on a VLAN Network Interface resource
        """
        requirements = [
            Requirement(MetadataConstants.SERVICE_ROOT, min=1, max=1),
            Requirement(MetadataConstants.VLAN_NETWORK_INTERFACE_COLLECTION, min=1),
        ]
        preconditions = Preconditions(self.metadata_container, requirements)
        status = preconditions.validate(self.discovery_container)

        if status is ValidationStatus.PASSED_WITH_WARNINGS:
            cts_warning("Without some components it is not possible to perform tests.")
            print "STATUS::{status}".format(status=status)
            return ValidationStatus.PASSED_WITH_WARNINGS

        if status is ValidationStatus.FAILED:
            return ValidationStatus.BLOCKED

        vlan_network_interface_collections = \
            dict(self.discovery_container.get_resources(MetadataConstants.VLAN_NETWORK_INTERFACE_COLLECTION,
                 any_child_version=True))

        chosen_vlan_network_interface_collection = None
        new_vlan_id = 0

        for vlan_network_interface_collection in vlan_network_interface_collections:
            try:
                parent_port = get_parent_odata_id(vlan_network_interface_collection)
                parent_port_id = self.discovery_container[parent_port].body["PortId"]
            except:
                continue

            # For arista setup, only ever try adding VLANs on the main /1 port
            if parent_port_id.endswith("/2") or parent_port_id.endswith("/3") or parent_port_id.endswith("/4"):
                continue

            present_vlan_ids = []
            vlan_network_interfaces = \
                dict(self.discovery_container.
                     get_resources(MetadataConstants.VLAN_NETWORK_INTERFACE,
                                   constraints=[from_collection(vlan_network_interface_collection)],
                                   any_child_version=True))

            if len(vlan_network_interfaces) > MAX_VLAN_ID - MIN_VLAN_ID:
                print "MESSAGE::No free VLAN id available on collection {}".format(vlan_network_interface_collection)
                continue

            for resource_link, resource in vlan_network_interfaces.iteritems():
                    try:
                        present_vlan_ids.append(resource.body["VLANId"])
                    except:
                        cts_error("Inorrect resource {resource_link:id} structure", **locals())

            for possible_id in range(MIN_VLAN_ID, MAX_VLAN_ID + 1):
                if possible_id not in present_vlan_ids:
                    chosen_vlan_network_interface_collection = vlan_network_interface_collection
                    new_vlan_id = possible_id
                    break

            if chosen_vlan_network_interface_collection:
                break

        if chosen_vlan_network_interface_collection:
            print "MESSAGE::CRUD test will be performed on vlan network interface collection %s" % \
                  chosen_vlan_network_interface_collection
        else:
            cts_warning('No free VLAN id available on any of the suitable ports (perhaps there are no suitable ports)')
            return ValidationStatus.BLOCKED

        self.post_vlan_payload = dict(VLANId=new_vlan_id,
                                      VLANEnable=True,
                                      Oem=dict(
                                        Intel_RackScale=dict(
                                            Tagged=True
                                        )))

        if self._test_case_create_vlan(chosen_vlan_network_interface_collection):
            self._test_case_get_created_vlan()
            self._test_case_delete_created_vlan()
            self._test_case_get_deleted_vlan()