def crud_nvme(self):
        status = ValidationStatus.PASSED

        cts_message("CRUD NVME")

        # test pre check
        self.__find_volumes_without_any_links(optional_pre_check=True)

        try:
            status = ValidationStatus.join_statuses(status, self._test_create_volume())
        except:
            self._test_delete_all_created_endpoints_and_zones()
            status = ValidationStatus.FAILED

        self.__find_and_choose_endpoint_collection()
        self.__find_and_choose_volume()

        if not (self.chosen_volume and self.chosen_endpoint and self.chosen_zone):
            self.set_status_blocked()
            return ValidationStatus.BLOCKED

        cts_message("Chosen Volume for test: {volume_url}".format(volume_url=self.chosen_volume))

        try:
            status = ValidationStatus.join_statuses(status, self._test_create_initiator_endpoint())
            status = ValidationStatus.join_statuses(status, self._test_create_target_endpoint())
            status = ValidationStatus.join_statuses(status, self._test_create_zone_with_only_one_endpoint())
            status = ValidationStatus.join_statuses(status, self._test_patch_zone_with_target_endpoint())
        except:
            status = ValidationStatus.FAILED
        finally:
            status = ValidationStatus.join_statuses(status, self._test_delete_all_created_endpoints_and_zones())

        return status
Example #2
0
    def _test_create_volume(self):
        print "TEST_CASE::Create volume"

        post_volume_payload = dict(
            CapacityBytes=10000000,
            CapacitySources=[],
            AccessCapabilities=[]
        )

        status, status_code, response_body, headers = self.api_caller.post_resource(
            self.chosen_volume_collection,
            self.discovery_container,
            payload=post_volume_payload,
            acceptable_return_codes=[ReturnCodes.OK, ReturnCodes.ACCEPTED, ReturnCodes.CREATED]
        )

        if not status:
            cts_error("CTS cannot create volume")
            self.set_status_failed()
            return ValidationStatus.FAILED

        self.created_volume = headers['location']
        cts_message("Volume created at {location}".format(location=self.created_volume))

        if not self._verify_size_of_created_volume(self.created_volume, post_volume_payload):
            cts_error("Service create volume with wrong capacity")
            self.set_status_failed()
            return ValidationStatus.FAILED

        self.set_status_passed()
        return ValidationStatus.PASSED
Example #3
0
    def crud_fabrics_target(self):
        status = ValidationStatus.PASSED

        cts_message("CRUD FABRICS TARGET")

        # test pre check
        self.__find_volumes_without_any_links(optional_pre_check=True)

        try:
            status = ValidationStatus.join_statuses(status, self._test_create_volume())
        except:
            self._test_delete_all_created_endpoints_and_zones()
            status = ValidationStatus.FAILED

        self.__find_and_choose_endpoint_collection()
        self.__find_and_choose_volume()

        if not (self.chosen_volume and self.chosen_endpoint and self.chosen_zone):
            self.set_status_blocked()
            return ValidationStatus.BLOCKED

        cts_message("Chosen Volume for test: {volume_url}".format(volume_url=self.chosen_volume))

        try:
            status = ValidationStatus.join_statuses(status, self._test_create_initiator_endpoint())
            status = ValidationStatus.join_statuses(status, self._test_create_target_endpoint())
            status = ValidationStatus.join_statuses(status, self._test_create_zone_with_only_one_endpoint())
            status = ValidationStatus.join_statuses(status, self._test_patch_zone_with_target_endpoint())
        except:
            status = ValidationStatus.FAILED
        finally:
            status = ValidationStatus.join_statuses(status, self._test_delete_all_created_endpoints_and_zones())

        return status
Example #4
0
    def read_metadata_for_services(self, *services):
        """
        :type services: list[string]
        """

        digest = DirDigest(self._metadata_home(), '.xml',
                           DirDigest.LABEL_METADATA)
        if not digest.is_valid() and not getenv('CTS_SKIP', None):
            cts_error(
                "Metadata located in {dir} is corrupted or has been tampered. Expected: {expected}, "
                "Is: {current}",
                dir=self._metadata_home(),
                expected=digest.official_digest,
                current=digest.digest)
            cts_message("{count} xml files have been found in {dir}".format(
                count=len(digest), dir=self._metadata_home()))
            digest.report_differences()

        for service in services:
            try:
                self.metadata_dir = os.path.join(
                    self._metadata_home(),
                    MetadataManager.SERVICE_TO_DIR[service])
                self.read_metadata_from_dir(self.metadata_dir)
            except KeyError:
                cts_error(
                    "Internal error. Unknown metadata for service {service}",
                    service=service)
                return False
        return True
Example #5
0
    def _test_create_volume(self):
        print "TEST_CASE::Create volume"

        post_volume_payload = dict(CapacityBytes=10000000)

        status, status_code, response_body, headers = self.api_caller.post_resource(
            self.chosen_volume_collection,
            self.discovery_container,
            payload=post_volume_payload,
            acceptable_return_codes=[
                ReturnCodes.OK, ReturnCodes.ACCEPTED, ReturnCodes.CREATED
            ])

        if not status:
            cts_error("CTS cannot create volume")
            self.set_status_failed()
            return ValidationStatus.FAILED

        self.created_volume = headers['location']
        cts_message("Volume created at {location}".format(
            location=self.created_volume))

        if not self._verify_size_of_created_volume(self.created_volume,
                                                   post_volume_payload):
            cts_error("Service create volume with wrong capacity")
            self.set_status_failed()
            return ValidationStatus.FAILED

        self.set_status_passed()
        return ValidationStatus.PASSED
Example #6
0
    def validate_redfish_uris_consistency(self, api_resource,
                                          metadata_container):
        odata_id = api_resource.odata_id
        odata_type = api_resource.odata_type
        entity = metadata_container.entities.get(odata_type)

        if entity is None:
            mapped_type = metadata_container._map_types.get(odata_type)
            entity = metadata_container.entities.get(mapped_type)
            if entity is None:
                cts_error(
                    "No entity in metadata with @odata.type={odata_type}".
                    format(odata_type=odata_type))
                return ValidationStatus.FAILED

        if Annotation.REDFISH_URIS not in entity._annotations:
            return ValidationStatus.PASSED

        redfish_uris_list = entity._annotations[
            Annotation.REDFISH_URIS].redfish_uris
        matched_uris = [
            redfish_uri for redfish_uri in redfish_uris_list
            if re.match(re.sub(r"{.+}", ".+", redfish_uri), odata_id)
        ]

        if not matched_uris:
            cts_error(
                "Resource {res} does not match expected RedfishUri in metadata. Expected {expected}"
                .format(res=odata_id, expected=redfish_uris_list))
            return ValidationStatus.FAILED
        else:
            cts_message(
                "Resource {res} is compliant with expected RedfishUri in metadata"
                .format(res=odata_id))
            return ValidationStatus.PASSED
 def __verify_resource_non_exist(self, location_url_verification):
     status, _, _, _, _ = self.api_caller.get_resource(location_url_verification,
                                                       self.discovery_container,
                                                       acceptable_return_codes=[ReturnCodes.BAD_REQUEST,
                                                                                ReturnCodes.NOT_FOUND])
     if not status:
         cts_error("Resource at %s was not properly deleted" % location_url_verification)
         return False
     cts_message("Resource at %s was properly deleted" % location_url_verification)
     return True
Example #8
0
 def __verify_resource_non_exist(self, location_url_verification):
     status, _, _, _, _ = self.api_caller.get_resource(location_url_verification,
                                                       self.discovery_container,
                                                       acceptable_return_codes=[ReturnCodes.BAD_REQUEST,
                                                                                ReturnCodes.NOT_FOUND])
     if not status:
         cts_error("Resource at %s was not properly deleted" % location_url_verification)
         return False
     cts_message("Resource at %s was properly deleted" % location_url_verification)
     return True
Example #9
0
    def __verify_command_type(external_cmd):
        command_type, command_location = (None, ) * 2
        try:
            command_type = external_cmd[0]
            if command_type.lower() != 'python':
                cts_message('CTS support only Python external scripts')
                return False

            command_location = external_cmd[1]
        except IndexError:
            cts_error('Missing verification command details')
        return command_type, command_location
Example #10
0
    def __verify_command_type(external_cmd):
        command_type, command_location = (None,) * 2
        try:
            command_type = external_cmd[0]
            if command_type.lower() != 'python':
                cts_message('CTS support only Python external scripts')
                return False

            command_location = external_cmd[1]
        except IndexError:
            cts_error('Missing verification command details')
        return command_type, command_location
Example #11
0
    def _test_patch_zone_with_target_endpoint(self):
        print "TEST_CASE::Patch zone with target endpoint"

        initiator_or_target_missing = False

        try:
            initiator_endpoint_link = self.__get_odata_id_links(
                self.initiator_endpoint)
        except:
            cts_error("No valid initiator endpoint for zone patching")
            initiator_or_target_missing = True

        try:
            target_endpoint_link = self.__get_odata_id_links(
                self.target_endpoint)
        except:
            cts_error("No valid target endpoint for zone patching")
            initiator_or_target_missing = True

        if initiator_or_target_missing:
            cts_error("Missing resources for zone patching")
            self.set_status_blocked()

            return ValidationStatus.BLOCKED

        patch_create_zone_payload = dict(Links=dict(
            Endpoints=[{
                "@odata.id": initiator_endpoint_link
            }, {
                "@odata.id": target_endpoint_link
            }]))

        status, status_code, _, headers = self.api_caller.patch_resource(
            self.zone_endpoint,
            self.discovery_container,
            payload=patch_create_zone_payload,
            acceptable_return_codes=[ReturnCodes.ACCEPTED, ReturnCodes.OK])
        if not status:
            cts_error("CTS can not PATCH Zone")
            self.set_status_failed()
            return ValidationStatus.FAILED

        cts_message(
            "Zone PATCHED at {location}".format(location=self.zone_endpoint))

        if not self.__verify_patched_zone(self.zone_endpoint,
                                          patch_create_zone_payload):
            cts_error("Service zone patched with wrong value")
            self.set_status_failed()
            return ValidationStatus.FAILED

        self.set_status_passed()
        return ValidationStatus.PASSED
Example #12
0
    def _test_create_target_endpoint(self):
        print "TEST_CASE::Create target endpoint"

        selected_volume = self.discovery_container.get(self.chosen_volume)
        random_suffix = random.randrange(1, RANDOM_RANGE, 1)
        post_target_endpoint_payload = dict(
            Identifiers=[
                dict(DurableName="iqn.initiator" + str(random_suffix),
                     DurableNameFormat="iQN")
            ],
            ConnectedEntities=[
                dict(
                    EntityRole="Target",
                    EntityLink={"@odata.id": selected_volume.odata_id},
                )
            ],
            IPTransportDetails=[],
            Oem=dict(Intel_RackScale=dict(
                Authentication=dict(Username="******" +
                                    str(random_suffix),
                                    Password="******"))))

        status, status_code, response, headers = self.api_caller.post_resource(
            self.chosen_endpoint,
            self.discovery_container,
            payload=post_target_endpoint_payload,
            acceptable_return_codes=[
                ReturnCodes.OK, ReturnCodes.ACCEPTED, ReturnCodes.CREATED
            ])

        if not status:
            cts_error("CTS can not create Target Endpoint")
            self.set_status_failed()
            return ValidationStatus.FAILED

        self.target_endpoint = headers['location']
        cts_message("Target Endpoint created at {location}".format(
            location=self.target_endpoint))

        try:
            verify = self.__verify_created_target_endpoint(
                self.target_endpoint, post_target_endpoint_payload)
        except:
            verify = False

        if not verify:
            cts_error("Service create target endpoint with wrong value")
            self.set_status_failed()
            return ValidationStatus.FAILED

        self.set_status_passed()
        return ValidationStatus.PASSED
Example #13
0
    def _test_create_target_endpoint(self):
        print "TEST_CASE::Create target endpoint"

        selected_volume = self.discovery_container.get(self.chosen_volume)
        random_suffix = random.randrange(1, RANDOM_RANGE, 1)
        post_target_endpoint_payload = dict(
            Identifiers=[dict(
                DurableName="iqn.initiator" + str(random_suffix),
                DurableNameFormat="iQN"
            )],
            ConnectedEntities=[dict(
                EntityRole="Target",
                EntityLink={"@odata.id": selected_volume.odata_id},
            )],
            IPTransportDetails=[],
            Oem=dict(
                Intel_RackScale=dict(
                    Authentication=dict(
                        Username="******" + str(random_suffix),
                        Password="******"
                    ))))

        status, status_code, response, headers = self.api_caller.post_resource(
                                                                          self.chosen_endpoint,
                                                                          self.discovery_container,
                                                                          payload=post_target_endpoint_payload,
                                                                          acceptable_return_codes=[ReturnCodes.OK,
                                                                                                   ReturnCodes.ACCEPTED,
                                                                                                   ReturnCodes.CREATED])

        if not status:
            cts_error("CTS can not create Target Endpoint")
            self.set_status_failed()
            return ValidationStatus.FAILED

        self.target_endpoint = headers['location']
        cts_message("Target Endpoint created at {location}".format(location=self.target_endpoint))

        try:
            verify = self.__verify_created_target_endpoint(self.target_endpoint, post_target_endpoint_payload)
        except:
            verify = False

        if not verify:
            cts_error("Service create target endpoint with wrong value")
            self.set_status_failed()
            return ValidationStatus.FAILED

        self.set_status_passed()
        return ValidationStatus.PASSED
Example #14
0
    def _test_patch_zone_with_target_endpoint(self):
        print "TEST_CASE::Patch zone with target endpoint"

        initiator_or_target_missing = False

        try:
            initiator_endpoint_link = self.__get_odata_id_links(self.initiator_endpoint)
        except:
            cts_error("No valid initiator endpoint for zone patching")
            initiator_or_target_missing = True

        try:
            target_endpoint_link = self.__get_odata_id_links(self.target_endpoint)
        except:
            cts_error("No valid target endpoint for zone patching")
            initiator_or_target_missing = True

        if initiator_or_target_missing:
            cts_error("Missing resources for zone patching")
            self.set_status_blocked()

            return ValidationStatus.BLOCKED

        patch_create_zone_payload = dict(
            Links=dict(
                Endpoints=[
                    {"@odata.id": initiator_endpoint_link},
                    {"@odata.id": target_endpoint_link}]
        ))

        status, status_code, _, headers = self.api_caller.patch_resource(self.zone_endpoint,
                                                                         self.discovery_container,
                                                                         payload=patch_create_zone_payload,
                                                                         acceptable_return_codes=[ReturnCodes.ACCEPTED,
                                                                                                  ReturnCodes.OK])
        if not status:
            cts_error("CTS can not PATCH Zone")
            self.set_status_failed()
            return ValidationStatus.FAILED

        cts_message("Zone PATCHED at {location}".format(location=self.zone_endpoint))

        if not self.__verify_patched_zone(self.zone_endpoint, patch_create_zone_payload):
            cts_error("Service zone patched with wrong value")
            self.set_status_failed()
            return ValidationStatus.FAILED

        self.set_status_passed()
        return ValidationStatus.PASSED
Example #15
0
    def _verification_phase(self, action, raw_response=None):
        external_command = action['response']['command']
        expected_response = action['response']['result']

        command_type, command_location = self.__verify_command_type(external_command)
        command_args = self.__verify_command_args(external_command)

        external_action = ExecuteExternalScript(script_path=command_location,
                                                raw_response=raw_response,
                                                expected_result=expected_response)
        if not external_action(**command_args):
            cts_error('Script response IS NOT equal to excepted.')
            return False
        cts_message('Script response is equal to excepted.')
        return True
Example #16
0
    def tree_deep_search(body, key):
        """
        Use this method for looking a last property on the tree
        :return ValidationStatus
        """
        resource_tree = objectpath.Tree(json.loads(json.dumps(body)))

        result_tuple = tuple(resource_tree.execute('$..{}'.format(key)))
        if not result_tuple:
            cts_warning("\t{status} Key {key} was not found".format(
                status=get_warning(), key=key))
            return ValidationStatus.PASSED_WITH_WARNINGS
        cts_message("\t{status} Key {key} was found".format(status=get_ok(),
                                                            key=key))
        return ValidationStatus.PASSED
Example #17
0
    def _verification_phase(self, action, raw_response=None):
        external_command = action['response']['command']
        expected_response = action['response']['result']

        command_type, command_location = self.__verify_command_type(
            external_command)
        command_args = self.__verify_command_args(external_command)

        external_action = ExecuteExternalScript(
            script_path=command_location,
            raw_response=raw_response,
            expected_result=expected_response)
        if not external_action(**command_args):
            cts_error('Script response IS NOT equal to excepted.')
            return False
        cts_message('Script response is equal to excepted.')
        return True
Example #18
0
    def _test_create_initiator_endpoint(self):
        print "TEST_CASE::Create initiator endpoint"

        post_initiator_endpoint_payload = dict(
            Identifiers=[
                dict(DurableName=self.initiator_unique_name,
                     DurableNameFormat="NQN")
            ],
            IPTransportDetails=[],
            ConnectedEntities=[dict(
                EntityRole="Initiator",
                Identifiers=[],
            )],
            Links=dict(Oem=dict(Intel_RackScale=dict())))

        status, status_code, response_body, headers = self.api_caller.post_resource(
            self.chosen_endpoint,
            self.discovery_container,
            payload=post_initiator_endpoint_payload,
            acceptable_return_codes=[
                ReturnCodes.OK, ReturnCodes.ACCEPTED, ReturnCodes.CREATED
            ])

        if not status:
            cts_error("CTS cannot create Initiator Endpoint")
            self.set_status_failed()
            return ValidationStatus.FAILED

        self.initiator_endpoint = headers['location']
        cts_message("Initiator Endpoint created at {location}".format(
            location=self.initiator_endpoint))

        try:
            verify = self.__verify_created_initiator_endpoint(
                self.initiator_endpoint, post_initiator_endpoint_payload)
        except:
            verify = False

        if not verify:
            cts_error("Service create initiator endpoint with wrong value")
            self.set_status_failed()
            return ValidationStatus.FAILED

        self.set_status_passed()
        return ValidationStatus.PASSED
Example #19
0
    def read_requirement(api, key):
        """
        Verify that the resource exists in the list and that it can be read with GET
        :param api:
        :param key:
        :return:
        """
        resource_tree = objectpath.Tree(json.loads(json.dumps(api)))

        phase_status = ValidationStatus.PASSED

        for element_key, element_property in key.iteritems():
            result_tuple = tuple(
                resource_tree.execute('$..{key}'.format(key=element_key)))

            if not result_tuple:
                if element_property == "Mandatory":
                    cts_error(
                        "\t{status} Element {element_key} is {element_property}"
                        .format(status=get_fail(),
                                element_key=element_key,
                                element_property=element_property))
                    phase_status = ValidationStatus.join_statuses(
                        ValidationStatus.FAILED)
                elif element_property == "IfImplemented":
                    continue
                else:
                    cts_color_message(
                        "\t{status} Element {element_key} is {element_property}"
                        .format(status=get_info(),
                                element_key=element_key,
                                element_property=element_property))
                    phase_status = ValidationStatus.join_statuses(
                        ValidationStatus.PASSED_WITH_WARNINGS)
            else:
                cts_message(
                    "\t{status} Element {element_key} is {element_property}".
                    format(status=get_ok(),
                           element_key=element_key,
                           element_property=element_property))
                phase_status = ValidationStatus.join_statuses(
                    ValidationStatus.PASSED)
        return phase_status
Example #20
0
    def test_roulette(self, api, value_element):
        test_phases = {
            self.tree_deep_search: [
                "last_property",
                "Test phase: Verify that the \"PropertyRequirements\" fields exists"
            ],
            self.min_count_search: [
                "min_count",
                "Test phase: Verify the number of elements meets the minimum criterion "
                "(\"MinCount\")"
            ],
            self.read_requirement: [
                "read_requirement",
                "Test phase: Verify that the \"ReadRequirement\" fields exist and are readable"
            ],
            self.write_requirement: [
                "write_requirement",
                "Test phase: ONLY Verify that the \"WriteRequirement\" elements are exist"
            ]
        }
        test_case_status = ValidationStatus.PASSED
        for test_to_do, test_description in test_phases.iteritems():
            phase_status = ValidationStatus.PASSED
            each_value_element = value_element[test_description[0]]
            try:
                if len(each_value_element) > 0:
                    cts_message(test_description[1])
                    each_value_element = set(
                        value_element[test_description[0]])
                else:
                    continue
            except TypeError:
                pass

            for each in each_value_element:
                phase_status = ValidationStatus.join_statuses(
                    test_to_do(api.body, each))
            print("STATUS::{status}".format(status=phase_status))
            test_case_status = ValidationStatus.join_statuses(phase_status)
        cts_color_message("Tested element {odata_type} ({odata_id})".format(
            odata_type=api.odata_type, odata_id=api.odata_id),
                          font_color="LIGHT_BLUE")
        print("STATUS::{status}".format(status=test_case_status))
Example #21
0
    def case_information_wrapper(*args, **kwargs):
        name = args[1]
        step = args[4]

        cts_message('')
        cts_message('Step: %s' % step)
        cts_message('Name: %s' % name)

        result = fn(*args, **kwargs)

        cts_message('End of %s (%s)' % (name, step))
        return result
Example #22
0
    def case_information_wrapper(*args, **kwargs):
        name = args[1]
        step = args[4]

        cts_message('')
        cts_message('Step: %s' % step)
        cts_message('Name: %s' % name)

        result = fn(*args, **kwargs)

        cts_message('End of %s (%s)' % (name, step))
        return result
Example #23
0
    def _test_create_zone_with_only_one_endpoint(self):
        print "TEST_CASE::Create zone with only one endpoint"

        try:
            initiator_endpoint_link = self.__get_odata_id_links(
                self.initiator_endpoint)
        except:
            cts_error("No valid initiator endpoint for zone creation")
            self.set_status_blocked()
            return ValidationStatus.BLOCKED

        post_create_zone_payload = dict(Links=dict(
            Endpoints=[{
                "@odata.id": initiator_endpoint_link
            }]))

        status, status_code, _, headers = self.api_caller.post_resource(
            self.chosen_zone,
            self.discovery_container,
            payload=post_create_zone_payload,
            acceptable_return_codes=[
                ReturnCodes.ACCEPTED, ReturnCodes.CREATED, ReturnCodes.OK
            ])

        if not status:
            cts_error("CTS can not create Zone")
            self.set_status_failed()
            return ValidationStatus.FAILED

        self.zone_endpoint = headers['location']
        cts_message(
            "Zone created at {location}".format(location=self.zone_endpoint))

        if not self.__verify_created_zone(self.zone_endpoint,
                                          post_create_zone_payload):
            cts_error("Service zone created with wrong value")
            self.set_status_failed()
            return ValidationStatus.FAILED

        self.set_status_passed()
        return ValidationStatus.PASSED
Example #24
0
 def _log_response(self, response, response_body):
     pretty_response = json.dumps(response_body, indent=4) \
         if response.status_code != ReturnCodes.NO_CONTENT else "No content"
     cts_message("status code: %d" % response.status_code)
     cts_message("response:")
     for r in pretty_response.split('\n'):
         cts_message("{line}\n", line=r)
Example #25
0
 def _log_response(response, response_body):
     pretty_response = json.dumps(response_body, indent=4) \
         if response.status_code != ReturnCodes.NO_CONTENT else "No content"
     cts_message("status code: %d" % response.status_code)
     cts_message("response:")
     for r in pretty_response.split('\n'):
         cts_message("{line}\n", line=r)
Example #26
0
    def _test_create_zone_with_only_one_endpoint(self):
        print "TEST_CASE::Create zone with only one endpoint"

        try:
            initiator_endpoint_link = self.__get_odata_id_links(self.initiator_endpoint)
        except:
            cts_error("No valid initiator endpoint for zone creation")
            self.set_status_blocked()
            return ValidationStatus.BLOCKED


        post_create_zone_payload = dict(
            Links=dict(
                Endpoints=[{"@odata.id": initiator_endpoint_link}]
            )
        )

        status, status_code, _, headers = self.api_caller.post_resource(self.chosen_zone,
                                                                        self.discovery_container,
                                                                        payload=post_create_zone_payload,
                                                                        acceptable_return_codes=[ReturnCodes.ACCEPTED,
                                                                                                 ReturnCodes.CREATED,
                                                                                                 ReturnCodes.OK])

        if not status:
            cts_error("CTS can not create Zone")
            self.set_status_failed()
            return ValidationStatus.FAILED

        self.zone_endpoint = headers['location']
        cts_message("Zone created at {location}".format(location=self.zone_endpoint))

        if not self.__verify_created_zone(self.zone_endpoint, post_create_zone_payload):
            cts_error("Service zone created with wrong value")
            self.set_status_failed()
            return ValidationStatus.FAILED

        self.set_status_passed()
        return ValidationStatus.PASSED
Example #27
0
    def detect(self, profile_name, purpose, profile=None):
        cts_color_message(
            "Testing a profile: {name}".format(name=profile_name), "HEADER")
        cts_color_message("Purpose: {purpose}".format(purpose=purpose))

        status = ValidationStatus.PASSED

        self.main_resource_validation(profile)
        self.show_results(profile_name)

        if self.missing_main_elements:
            status = ValidationStatus.join_statuses(ValidationStatus.BLOCKED)
            cts_warning("Some elements are missing for all tests")
            print("STATUS::{status}".format(status=status))
        else:
            status = ValidationStatus.join_statuses(ValidationStatus.PASSED)
            cts_message("All main elements are available")
            print("STATUS::{status}".format(status=status))

        self.run(self.profile_container)

        cts_color_message("Deeper verification", font_color="HEADER")
        self.validate_profile_container()
        return status
    def print_report(self):
        for enu, element in enumerate(self._time_container, 1):
            cts_message("[{}/{}] {} : {}".format(enu,
                                                 self._entity_len,
                                                 element.get_request_method,
                                                 element.get_object_url))
            cts_message("Status code:\t{}".format(element.get_status))
            cts_message("Duration: \t{} ms\n".format(element.get_duration))

        self.calculate_statics()
Example #29
0
 def perform_timeout(step_counter, timeout=1):
     cts_message("Step: %s" % step_counter)
     cts_message("Timeout: %s" % timeout)
     sleep(float(timeout))
Example #30
0
    def perform_action(self,
                       test_name,
                       case_name,
                       action,
                       step_counter,
                       retry=0,
                       timeout=0):
        case_action = CaseAction(**action)

        cts_message("_____")
        cts_message("{name}: {step}\n\t\t {description}".format(
            name=test_name, step=step_counter, description=case_name))

        cts_message("{request_method}: {request}".format(
            request_method=action['request_method'],
            request=action['request'].replace("{", "(").replace("}", ")")))

        resource_type, resource_id, resource_action = self._get_target_information(
            case_action.request)
        discovered_systems = self.discovery_container.get_resources(
            resource_type, any_child_version=True)

        if not discovered_systems:
            cts_error('Cannot find %s' % resource_type)
            return ValidationStatus.BLOCKED

        try:
            computer_odata_id = self.discovery_container.get(
                discovered_systems[resource_id][0]).odata_id
        except IndexError:
            cts_error('Cannot find %s' % resource_type)
            return ValidationStatus.BLOCKED

        action_endpoint = '{odata_id}/{action_name}'.format(
            odata_id=computer_odata_id, action_name='/'.join(resource_action))

        status, _, _, _ = self.api_caller.post_resource(
            action_endpoint,
            self.discovery_container,
            case_action.payload,
            acceptable_return_codes=case_action.response)

        if (not status) and (retry > 0):
            cts_message("Operation failed, left retry %s" % retry)
            cts_message("Timeout: %s" % timeout)
            sleep(float(timeout))

            self.perform_action(test_name,
                                case_name,
                                action,
                                step_counter,
                                retry=(retry - 1),
                                timeout=timeout)

        if not status:
            cts_error('Cannot execute action %s' % action_endpoint)
            return ValidationStatus.FAILED

        cts_message('End of: %s' % case_name)
        return ValidationStatus.PASSED
Example #31
0
    def perform_action(self, test_name, case_name, action, step_counter, retry=0, timeout=0):
        case_action = CaseAction(**action)

        cts_message("_____")
        cts_message("{name}: {step}\n\t\t {description}".format(name=test_name,
                                                                step=step_counter,
                                                                description=case_name))

        cts_message("{request_method}: {request}".format(request_method=action['request_method'],
                                                         request=action['request'].replace("{", "(").replace("}", ")")))

        resource_type, resource_id, resource_action = self._get_target_information(case_action.request)
        discovered_systems = self.discovery_container.get_resources(resource_type,
                                                                    any_child_version=True)

        if not discovered_systems:
            cts_error('Cannot find %s' % resource_type)
            return ValidationStatus.BLOCKED

        try:
            computer_odata_id = self.discovery_container.get(discovered_systems[resource_id][0]).odata_id
        except IndexError:
            cts_error('Cannot find %s' % resource_type)
            return ValidationStatus.BLOCKED

        action_endpoint = '{odata_id}/{action_name}'.format(odata_id=computer_odata_id,
                                                            action_name='/'.join(resource_action))

        status, _, _, _ = self.api_caller.post_resource(action_endpoint,
                                                        self.discovery_container,
                                                        case_action.payload,
                                                        acceptable_return_codes=case_action.response)

        if (not status) and (retry > 0):
            cts_message("Operation failed, left retry %s" % retry)
            cts_message("Timeout: %s" % timeout)
            sleep(float(timeout))

            self.perform_action(test_name, case_name, action, step_counter, retry=(retry - 1), timeout=timeout)

        if not status:
            cts_error('Cannot execute action %s' % action_endpoint)
            return ValidationStatus.FAILED

        cts_message('End of: %s' % case_name)
        return ValidationStatus.PASSED
Example #32
0
 def perform_timeout(step_counter, timeout=1):
     cts_message("Step: %s" % step_counter)
     cts_message("Timeout: %s" % timeout)
     sleep(float(timeout))
    def print_statistics(self):
        self.calculate_statics()

        # TODO verify that keys are exist
        try:
            cts_message('')
            cts_message('Average time: \t{time} [{unit}]'.format(time=self._statistics['average_time'],
                                                                 unit=self._statistics['average_time_unit']))
            cts_message('Total duration:{time} [{unit}]'.format(time=self._statistics['total_duration'],
                                                                unit=self._statistics['total_duration_unit']))
            cts_message('Latencies [50, 95, 99, max]: [{}, {}, {}, {}] ms'.format(
                self._statistics['latency50'],
                self._statistics['latency95'],
                self._statistics['latency99'],
                self._statistics['latency_max']
            ))
            cts_message('Success rate: \t{percent}%'.format(percent=float(self._statistics['success_rate'])*100))
            cts_message('Status codes: \t{codes}'.
                        format(codes=["{key}: {val}".format(key=k, val=v) for k, v
                                      in self._statistics['status_codes'].iteritems()]))
        except:
            cts_error("Can not show statistics")
Example #34
0
 def _log_request(self, kwargs):
     cts_message(" request parameters:")
     for key, value in kwargs.iteritems():
         cts_message("     {key}:{value}", key=str(key), value=str(value))
Example #35
0
 def _log_request(kwargs):
     cts_message(" request parameters:")
     for key, value in kwargs.iteritems():
         cts_message("     {key}:{value}", key=str(key), value=str(value))
Example #36
0
 def warn_on_null(self, resource_collection, name):
     if len(resource_collection) == 0:
         cts_message("Warning! Collection of " + name + " is empty!")
Example #37
0
    def _validate_property(self, context, variable_path, property_description,
                           skip_collection=False, ignore_list=[]):
        """
        :type context: Context
        :type variable_path: list [str or int]
        :type property_description: cts_core.metadata.model.property.Property
        :type skip_collection: bool
        :rtype: str
        """
        applicability = None
        if property_description.patch_status == PatchStatus.NONTRIVIAL:
            applicability, validation_result = self.handle_nontrivial(context, variable_path, property_description)
            if applicability == ApplicabilityTestResult.MATCHED:
                return validation_result
            if applicability in [ApplicabilityTestResult.NOT_MATCHED, ApplicabilityTestResult.SKIP_PROPERTY]:
                return validation_result

        api_resource = context.api_resource

        if not skip_collection:
            variable_path = variable_path + [property_description.name]

        try:
            property_body = api_resource.get_value_from_path(variable_path)
            if len(ignore_list) == 1 and ignore_list[0] in property_body:
                path_s = "->".join([str(segment) for segment in variable_path])
                cts_message("Patching %s->%s" % (api_resource.odata_id, path_s))
                cts_message("This property {ignore_element} is marked in IgnoredElement list as element to skip".format(
                    ignore_element=ignore_list[0]
                ))
        except KeyError as error:
            if property_description.is_required:
                path_s = "->".join([str(segment) for segment in variable_path])
                print "TEST_CASE::Patching %s->%s" % (api_resource.odata_id, path_s)
                cts_error("Unable to patch {error}", error=error)
                status = ValidationStatus.FAILED
                print "STATUS::%s" % status
            else:
                status = ValidationStatus.PASSED

            return status

        if property_description.is_collection and not skip_collection:
            status = ValidationStatus.PASSED

            for path_element, _ in enumerate(property_body):
                status = \
                    ValidationStatus.join_statuses(status,
                                                   self._validate_property(context,
                                                                           variable_path + [path_element],
                                                                           property_description,
                                                                           skip_collection=True,
                                                                           ignore_list=ignore_list))
            return status
        else:
            try:
                if self._metadata_container.types[property_description.type].type_category \
                        == MetadataTypeCategories.COMPLEX_TYPE:
                    return self._validate_property_list(context,
                                                        variable_path,
                                                        self._metadata_container.types[property_description.type].
                                                        properties.itervalues(),
                                                        ignore_list)
                else:
                    if str(property_description) in ignore_list:
                        return ValidationStatus.PASSED
                    return self._validate_leaf_property(context,
                                                        variable_path,
                                                        property_description)
            except KeyError as key:
                cts_error("Unable to find definition of type {type} referenced by {odata_id:id}",
                          type=key,
                          odata_id=api_resource.odata_id)
                return ValidationStatus.FAILED
Example #38
0
 def _print_available_profiles_names(profiles_in_json):
     for xid, profile, in enumerate(profiles_in_json, start=1):
         cts_message("{id}: {profile_name}".format(
             id=xid, profile_name=profile['ProfileName']))