예제 #1
0
def assert_lessthan(found: Any, boundary: Any, api: Optional[str] = None):
    """
        Verifies that the specified return result from the specified API has a value less than the
        boundary specified. If the verification fails then an :class:`AKitAssertionError` is created
        and returned, otherwise None is returned. It is the resposibility of the calling test to raise
        the returned error.

        :param found: The value being compared
        :param boundry: The boundary value being compared against
        :param api: The name of the API that returned the result being inspected.
        
        :returns: None or an :class:`AKitAssertionError` for the caller to raise.
    """

    if not found < boundary:

        msg_prefix = PREFIX_STD if api is None else PREFIX_API.format(api)

        err_msg_lines = [
            "{} verification failed because the found value was not less than the boundary value:"
            .format(msg_prefix)
        ]

        bndry_format_lines = pformat(boundary, indent=4).strip().splitlines()
        if len(bndry_format_lines) == 1:
            err_msg_lines.append("BOUNDARY: {}".format(bndry_format_lines[0]))
        elif len(bndry_format_lines) > 1:
            err_msg_lines.append("BOUNDARY:")
            bndry_format_lines = indent_lines(bndry_format_lines, 1)
            err_msg_lines.extend(bndry_format_lines)

        found_format_lines = pformat(found, indent=4).splitlines()
        if len(found_format_lines) == 1:
            err_msg_lines.append("FOUND: {}".format(found_format_lines[0]))
        elif len(found_format_lines) > 1:
            err_msg_lines.append("FOUND:")
            found_format_lines = indent_lines(found_format_lines, 1)
            err_msg_lines.extend(found_format_lines)

        errmsg = os.linesep.join(err_msg_lines)
        raise AKitAssertionError(errmsg)

    return
예제 #2
0
def assert_equal(found: Any, expected: Any, api: Optional[str] = None):
    """
        Verifies that the specified return result from the specified API has the specified expected value.
        If the verification fails then an :class:`AKitAssertionError` is created and returned, otherwise None
        is returned. It is the resposibility of the calling test to raise the returned error.

        :param found: The value to be compared
        :param expected: The expected value
        :param api: The name of the API that returned the result being inspected.
        
        :returns: None or an :class:`AKitAssertionError` for the caller to raise.
    """

    if found != expected:

        msg_prefix = PREFIX_STD if api is None else PREFIX_API.format(api)

        err_msg_lines = [
            "{} verification failed because the found value did not match expected value:"
            .format(msg_prefix), "EXPECTED:"
        ]

        exp_format_lines = pformat(expected, indent=4).strip().splitlines()
        if len(exp_format_lines) == 1:
            err_msg_lines.append("EXPECTED: {}".format(exp_format_lines[0]))
        elif len(exp_format_lines) > 1:
            err_msg_lines.append("EXPECTED:")
            exp_format_lines = indent_lines(exp_format_lines, 1)
            err_msg_lines.extend(exp_format_lines)

        found_format_lines = pformat(found, indent=4).splitlines()
        if len(found_format_lines) == 1:
            err_msg_lines.append("FOUND: {}".format(found_format_lines[0]))
        elif len(found_format_lines) > 1:
            err_msg_lines.append("FOUND:")
            found_format_lines = indent_lines(found_format_lines, 1)
            err_msg_lines.extend(found_format_lines)

        errmsg = os.linesep.join(err_msg_lines)
        raise AKitAssertionError(errmsg)

    return
예제 #3
0
    def execute(self,
                parameters: Optional[dict] = None,
                topology: Optional[dict] = None,
                **kwargs) -> int:

        self._logger.info("STEP: %s - %d" % (self._label, self._ordinal))

        locals().update({"parameters": parameters, "topology": topology})
        locals().update(kwargs)

        script_content = os.linesep.join(self._script)
        script_content = indent_lines(script_content, level=3)

        exit_status = 0

        try:
            # Execute the inline python script in the context of the current
            # globals and locals.
            exec(script_content, globals(), locals())
        except:
            exit_status = 1

        return exit_status
    def establish_connectivity(cls):
        """
            This API is called so the `IntegrationMixIn` can establish connectivity with any compute or storage
            resources.

            :raises :class:`akit.exceptins.AKitInitialConnectivityError`:
        """

        upnp_agent = UpnpAgent(interface=cls.correspondance_interface)
        cls.upnp_agent = upnp_agent

        upnp_agent.start()
        upnp_agent.begin_search()

        upnp_hint_list = cls.landscape.get_upnp_devices()

        # IMPORTANT: We need to make sure all the devices have been found by the UpnpAgent before we continue
        # the setup of the automation run.
        upnp_agent.wait_for_devices(upnp_hint_list)

        found_msg = "==================== DEVICES FOUND ====================\n"
        for device in upnp_agent.children:
            devstr = str(device)
            found_msg += devstr
        found_msg += "\n\n"

        cls.logger.info(found_msg)

        # Go through all the devices found and pull out references to all the devices
        # that are in the expected list.  These are the devices we want to work with
        # in automation
        expected_devices_found = []
        expected_devices_missing = [dev for dev in upnp_hint_list]
        for device in upnp_agent.children:
            devmac = device.MACAddress
            if devmac in expected_devices_missing:
                expected_devices_found.append(device)
                expected_devices_missing.remove(devmac)

        # IMPORTANT: Make sure there were no expected devices missing and fail loudly if there were
        if len(expected_devices_missing) > 0:
            # If we got here, then there are devices missing from the testbed that were
            # expected to be there.  We should not continue the automation run
            missingmsg = "ERROR: The following devices were missing:\n"
            for devmac in expected_devices_missing:
                missingmsg += "    %s\n" % devmac
            raise AKitMissingResourceError(missingmsg)

        cls.logger.info("All expected devices were found.")

        cls.expected_device_table = {}
        for device in expected_devices_found:
            devmac = device.MACAddress
            cls.expected_device_table[devmac] = device

        # IMPORTANT: Make sure we have the minimum automation connectivity with each device
        failing_devices = HardwarePlayerPoolMixin.verify_expected_device_table_connectivity(
            cls.expected_device_table)
        if len(failing_devices) > 0:
            # If there were devices that failed to have the minimum amount of connectivity\
            # then we need to fail loudly here.
            conn_err_msg = "ERROR: Device connectivity issues were encountered:\n"

            for device, failurereport in failing_devices:
                dev_msg += "    DEVICE: %s\n" % device
                dev_msg += indent_lines(failurereport, 2)
                conn_err_msg += "%s\n" % dev_msg

            raise AKitInitialConnectivityError(conn_err_msg)

        return