Пример #1
0
    def check_limit(path, expected_value, limit_name):
        """
        Matches the expected and actual output
        (1) Match the output of the virsh memtune
        (2) Match the output of the respective cgroup fs value

        :params: path: memory controller path for a domain
        :params: expected_value: the expected limit value
        :params: limit_name: the limit to be checked
                             hard_limit/soft_limit/swap_hard_limit
        :return: True or False based on the checks
        """
        status_value = True
        # Check 1
        actual_value = virsh.memtune_get(domname, limit_name)
        if actual_value == -1:
            raise error.TestFail("the key %s not found in the "
                                 "virsh memtune output" % limit_name)
        if actual_value != int(expected_value):
            status_value = False
            logging.error("%s virsh output:\n\tExpected value:%d"
                          "\n\tActual value: "
                          "%d", limit_name,
                          int(expected_value), int(actual_value))

        # Check 2
        if limit_name == 'hard_limit':
            cg_file_name = '%s/memory.limit_in_bytes' % path
        elif limit_name == 'soft_limit':
            cg_file_name = '%s/memory.soft_limit_in_bytes' % path
        elif limit_name == 'swap_hard_limit':
            cg_file_name = '%s/memory.memsw.limit_in_bytes' % path

        cg_file = None
        try:
            try:
                cg_file = open(cg_file_name)
                output = cg_file.read()
                value = int(output) / 1024
                if int(expected_value) != int(value):
                    status_value = False
                    logging.error("%s cgroup fs:\n\tExpected Value: %d"
                                  "\n\tActual Value: "
                                  "%d", limit_name,
                                  int(expected_value), int(value))
            except IOError:
                status_value = False
                logging.error("Error while reading:\n%s", cg_file_name)
        finally:
            if cg_file is not None:
                cg_file.close()

        return status_value
Пример #2
0
    def check_limit(path, expected_value, limit_name):
        """
        Matches the expected and actual output
        (1) Match the output of the virsh memtune
        (2) Match the output of the respective cgroup fs value

        :params: path: memory controller path for a domain
        :params: expected_value: the expected limit value
        :params: limit_name: the limit to be checked
                             hard_limit/soft_limit/swap_hard_limit
        :return: True or False based on the checks
        """
        status_value = True
        # Check 1
        actual_value = virsh.memtune_get(domname, limit_name)
        if actual_value == -1:
            raise error.TestFail("the key %s not found in the "
                                 "virsh memtune output" % limit_name)
        if actual_value != int(expected_value):
            status_value = False
            logging.error(
                "%s virsh output:\n\tExpected value:%d"
                "\n\tActual value: "
                "%d", limit_name, int(expected_value), int(actual_value))

        # Check 2
        if limit_name == 'hard_limit':
            cg_file_name = '%s/memory.limit_in_bytes' % path
        elif limit_name == 'soft_limit':
            cg_file_name = '%s/memory.soft_limit_in_bytes' % path
        elif limit_name == 'swap_hard_limit':
            cg_file_name = '%s/memory.memsw.limit_in_bytes' % path

        cg_file = None
        try:
            try:
                cg_file = open(cg_file_name)
                output = cg_file.read()
                value = int(output) / 1024
                if int(expected_value) != int(value):
                    status_value = False
                    logging.error(
                        "%s cgroup fs:\n\tExpected Value: %d"
                        "\n\tActual Value: "
                        "%d", limit_name, int(expected_value), int(value))
            except IOError:
                status_value = False
                logging.error("Error while reading:\n%s", cg_file_name)
        finally:
            if cg_file is not None:
                cg_file.close()

        return status_value
Пример #3
0
    def check_softlimit(path, expected_value):
        """
        Matches the expected and actual output
        (1) Match the output of the virsh memtune
        (2) Match the output of the respective cgroup fs value

        @params: path: memory controller path for a domain
        @params: expected_value: the expected soft limit value
        @return: True or False based on the checks
        """

        status_value = True
        # Check 1
        actual_value = virsh.memtune_get(domname, "soft_limit")
        if actual_value == -1:
            raise error.TestFail("the key soft_limit not found in the "
                                 "virsh memtune output")

        if actual_value != int(expected_value):
            status_value = False
            logging.error(
                "Soft limit virsh output:\n\tExpected value: %d"
                "\n\tActual value: "
                "%d", int(expected_value), int(actual_value))

        # Check 2
        cmd = "cat %s/memory.soft_limit_in_bytes" % path
        (status, output) = commands.getstatusoutput(cmd)
        # To normalize to kB
        value = int(output) / 1024
        if status == 0:
            if int(expected_value) != int(value):
                status_value = False
                logging.error(
                    "Soft limit cgroup fs:\n\tExpected Value: %d"
                    "\n\tActual Value: "
                    "%d", int(expected_value), int(value))
        else:
            status_value = False
            logging.error("Error while reading:\n%s", output)
        return status_value
Пример #4
0
    def check_hardswaplimit(path, expected_value):
        """
        Matches the expected and actual output
        (1) Match the output of the virsh memtune
        (2) Match the output of the respective cgroup fs value

        @params: path: memory controller path for a domain
        @params: expected_value: the expected hardswap limit value
        @return: True or False based on the checks
        """

        status_value = True
        # Check 1
        actual_value = virsh.memtune_get(domname, "swap_hard_limit")
        if actual_value == -1:
            raise error.TestFail("the key swap_hard_limit not found in the "
                                 "virsh memtune output")
        if actual_value != int(expected_value):
            status_value = False
            logging.error("Swap hard limit virsh output:\n\tExpected value: "
                        "%d\n\tActual value: "
                        "%d", int(expected_value), int(actual_value))

        # Check 2
        cmd = "cat %s/memory.memsw.limit_in_bytes" % path
        (status, output) = commands.getstatusoutput(cmd)
        # To normalize to kB
        value = int(output)/1024
        if status == 0:
            if int(expected_value) != int(value):
                status_value = False
                logging.error("Swap hard limit cgroup fs:\n\tExpected Value: "
                            "%d\n\tActual Value: "
                            "%d", int(expected_value), int(value))

        else:
            status_value = False
            logging.error("Error while reading:\n%s", output)
        return status_value
Пример #5
0
def check_limit(path,
                expected_value,
                limit_name,
                cgname,
                vm,
                test,
                acceptable_minus=8):
    """
    Matches the expected and actual output
    1) Match the output of the virsh memtune
    2) Match the output of the respective cgroup fs value
    3) Match the output of the virsh dumpxml
    4) Check if vm is alive

    :params path: memory controller path for a domain
    :params expected_value: the expected limit value
    :params limit_name: the limit type to be checked
                        hard-limit/soft-limit/swap-hard-limit
    :params cgname: the cgroup postfix
    :params vm: vm instance
    :params test: test instance
    """

    status_value = True

    logging.info("Check 1: Match the output of the virsh memtune")
    actual_value = virsh.memtune_get(vm.name, limit_name)
    minus = int(expected_value) - int(actual_value)
    if minus > acceptable_minus:
        status_value = False
        logging.error(
            "%s virsh output:\n\tExpected value:%d"
            "\n\tActual value: "
            "%d", limit_name, int(expected_value), int(actual_value))

    logging.info("Check 2: Match the output of the respective cgroup fs value")
    if int(expected_value) != -1:
        cg_file_name = '%s/%s' % (path, cgname)
        cg_file = None
        try:
            with open(cg_file_name) as cg_file:
                output = cg_file.read()
            logging.debug("cgroup file output is: %s", output)
            value = int(output) // 1024
            minus = int(expected_value) - int(value)
            if minus > acceptable_minus:
                status_value = False
                logging.error(
                    "%s cgroup fs:\n\tExpected Value: %d"
                    "\n\tActual Value: "
                    "%d", limit_name, int(expected_value), int(value))
        except IOError as e:
            status_value = False
            logging.error("Error while reading:\n%s", cg_file_name)
            logging.error(e)

    logging.info("Check 3: Match the output of the virsh dumpxml")
    if int(expected_value) != -1:
        guest_xml = vm_xml.VMXML.new_from_dumpxml(vm.name)
        memtune_element = guest_xml.memtune
        logging.debug("Expected memtune XML is:\n%s", memtune_element)
        actual_fromxml = getattr(memtune_element, limit_name)
        if int(expected_value) != int(actual_fromxml):
            status_value = False
            logging.error("Expect memtune:\n%s\nBut got:\n "
                          "%s" % (expected_value, actual_fromxml))

    logging.info("Check 4: Check if vm is alive")
    if not vm.is_alive():
        status_value = False
        logging.error("Error: vm is not alive")

    if not status_value:
        test.fail("Failed to restore domain %s" % vm.name)
Пример #6
0
def check_limit(path, expected_value, limit_type, cgname, vm, test, acceptable_minus=8):
    """
    Matches the expected and actual output
    1) Match the output of the virsh memtune
    2) Match the output of the respective cgroup fs value
    3) Match the output of the virsh dumpxml
    4) Check if vm is alive

    :params path: memory controller path for a domain
    :params expected_value: the expected limit value
    :params limit_type: the limit type to be checked
                        hard-limit/soft-limit/swap-hard-limit
    :params cgname: the cgroup postfix
    :params vm: vm instance
    :params test: test instance
    """

    status_value = True
    limit_name = re.sub('-', '_', limit_type)

    # Check 1
    # Match the output of the virsh memtune
    actual_value = virsh.memtune_get(vm.name, limit_name)
    minus = int(expected_value) - int(actual_value)
    if minus > acceptable_minus:
        status_value = False
        logging.error("%s virsh output:\n\tExpected value:%d"
                      "\n\tActual value: "
                      "%d", limit_name,
                      int(expected_value), int(actual_value))

    # Check 2
    # Match the output of the respective cgroup fs value
    if int(expected_value) != -1:
        cg_file_name = '%s/memory.%s' % (path, cgname)
        cg_file = None
        try:
            with open(cg_file_name) as cg_file:
                output = cg_file.read()
            value = int(output) // 1024
            minus = int(expected_value) - int(value)
            if minus > acceptable_minus:
                status_value = False
                logging.error("%s cgroup fs:\n\tExpected Value: %d"
                              "\n\tActual Value: "
                              "%d", limit_name,
                              int(expected_value), int(value))
        except IOError:
            status_value = False
            logging.error("Error while reading:\n%s", cg_file_name)

    # Check 3
    # Match the output of the virsh dumpxml
    if int(expected_value) != -1:
        guest_xml = vm_xml.VMXML.new_from_dumpxml(vm.name)
        memtune_element = guest_xml.memtune
        logging.debug("Expected memtune XML is:\n%s", memtune_element)
        actual_fromxml = getattr(memtune_element, limit_name)
        if int(expected_value) != int(actual_fromxml):
            status_value = False
            logging.error("Expect memtune:\n%s\nBut got:\n "
                          "%s" % (expected_value, actual_fromxml))

    # Check 4
    # Check if vm is alive
    if not vm.is_alive():
        status_value = False
        logging.error("Error: vm is not alive")

    if not status_value:
        test.fail("Failed to restore domain %s" % vm.name)