Ejemplo n.º 1
0
 def start_stop_hook():
     """
     Do start/stop operation and check the results.
     """
     logging.info("Try to test start/stop hooks...")
     hook_para = "%s %s" % (hook_file, vm_name)
     prepare_hook_file(hook_script %
                       (vm_name, hook_log))
     vm.start()
     vm.wait_for_login().close()
     try:
         hook_str = hook_para + " prepare begin -"
         assert check_hooks(hook_str)
         hook_str = hook_para + " start begin -"
         assert check_hooks(hook_str)
         hook_str = hook_para + " started begin -"
         assert check_hooks(hook_str)
         # stop the vm
         vm.destroy()
         hook_str = hook_para + " stopped end -"
         assert check_hooks(hook_str)
         hook_str = hook_para + " release end -"
         assert check_hooks(hook_str)
     except AssertionError:
         utils.log_last_traceback()
         raise error.TestFail("Failed to check "
                              "start/stop hooks.")
Ejemplo n.º 2
0
    def daemon_hook():
        """
        Check the libvirtd hooks.
        """
        # stop daemon first
        libvirtd.stop()
        prepare_hook_file(hook_script % hook_log)
        try:
            libvirtd.start()
            hook_str = hook_file + " - start - start"
            assert check_hooks(hook_str)
            # Restart libvirtd and test again
            if os.path.exists(hook_log):
                os.remove(hook_log)
            libvirtd.restart()
            hook_str = hook_file + " - shutdown - shutdown"
            assert check_hooks(hook_str)
            hook_str = hook_file + " - start - start"
            assert check_hooks(hook_str)

            # kill the daemon with SIGHUP
            if os.path.exists(hook_log):
                os.remove(hook_log)
            utils_misc.signal_program('libvirtd', 1,
                                      '/var/run')
            hook_str = hook_file + " - reload begin SIGHUP"
            assert check_hooks(hook_str)

        except AssertionError:
            utils.log_last_traceback()
            raise error.TestFail("Failed to check"
                                 " daemon hooks")
Ejemplo n.º 3
0
 def start_stop_hook():
     """
     Do start/stop operation and check the results.
     """
     logging.info("Try to test start/stop hooks...")
     hook_para = "%s %s" % (hook_file, vm_name)
     prepare_hook_file(hook_script % (vm_name, hook_log))
     vm.start()
     vm.wait_for_login().close()
     try:
         hook_str = hook_para + " prepare begin -"
         assert check_hooks(hook_str)
         hook_str = hook_para + " start begin -"
         assert check_hooks(hook_str)
         hook_str = hook_para + " started begin -"
         assert check_hooks(hook_str)
         # stop the vm
         vm.destroy()
         hook_str = hook_para + " stopped end -"
         assert check_hooks(hook_str)
         hook_str = hook_para + " release end -"
         assert check_hooks(hook_str)
     except AssertionError:
         utils.log_last_traceback()
         raise error.TestFail("Failed to check " "start/stop hooks.")
Ejemplo n.º 4
0
    def daemon_hook():
        """
        Check the libvirtd hooks.
        """
        # stop daemon first
        libvirtd.stop()
        prepare_hook_file(hook_script % hook_log)
        try:
            libvirtd.start()
            hook_str = hook_file + " - start - start"
            assert check_hooks(hook_str)
            # Restart libvirtd and test again
            if os.path.exists(hook_log):
                os.remove(hook_log)
            libvirtd.restart()
            hook_str = hook_file + " - shutdown - shutdown"
            assert check_hooks(hook_str)
            hook_str = hook_file + " - start - start"
            assert check_hooks(hook_str)

            # kill the daemon with SIGHUP
            if os.path.exists(hook_log):
                os.remove(hook_log)
            utils_misc.signal_program('libvirtd', 1, '/var/run')
            hook_str = hook_file + " - reload begin SIGHUP"
            assert check_hooks(hook_str)

        except AssertionError:
            utils.log_last_traceback()
            raise error.TestFail("Failed to check" " daemon hooks")
Ejemplo n.º 5
0
    def check_dom_xml(at_mem=False, dt_mem=False):
        """
        Check domain xml options.
        """
        # Global variable to store max/current memory
        global new_max_mem
        global new_cur_mem
        if attach_option.count("config"):
            dom_xml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
        else:
            dom_xml = vm_xml.VMXML.new_from_dumpxml(vm_name)
        try:
            xml_max_mem_rt = int(dom_xml.max_mem_rt)
            xml_max_mem = int(dom_xml.max_mem)
            xml_cur_mem = int(dom_xml.current_mem)
            assert int(max_mem_rt) == xml_max_mem_rt

            # Check attached/detached memory
            if at_mem:
                if at_times:
                    assert int(max_mem) + (int(tg_size) *
                                           at_times) == xml_max_mem
                else:
                    assert int(max_mem) + int(tg_size) == xml_max_mem
                # Bug 1220702, skip the check for current memory
                if at_times:
                    assert int(cur_mem) + (int(tg_size) *
                                           at_times) == xml_cur_mem
                else:
                    assert int(cur_mem) + int(tg_size) == xml_cur_mem
                new_max_mem = xml_max_mem
                new_cur_mem = xml_cur_mem
                mem_dev = dom_xml.get_devices("memory")
                memory_devices = 1
                if at_times:
                    memory_devices = at_times
                if len(mem_dev) != memory_devices:
                    raise exceptions.TestFail("Found wrong number of"
                                              " memory device")
                assert int(tg_size) == int(mem_dev[0].target.size)
                assert int(tg_node) == int(mem_dev[0].target.node)
            elif dt_mem:
                if at_times:
                    assert int(new_max_mem) - (int(tg_size) *
                                               at_times) == xml_max_mem
                    assert int(new_cur_mem) - (int(tg_size) *
                                               at_times) == xml_cur_mem
                else:
                    assert int(new_max_mem) - int(tg_size) == xml_max_mem
                    # Bug 1220702, skip the check for current memory
                    assert int(new_cur_mem) - int(tg_size) == xml_cur_mem
        except AssertionError:
            utils.log_last_traceback()
            raise exceptions.TestFail("Found unmatched memory setting"
                                      " from domain xml")
Ejemplo n.º 6
0
 def libvirtd_hook():
     """
     Check the libvirtd hooks.
     """
     prepare_hook_file(hook_script % (vm_name, hook_log))
     hook_para = "%s %s" % (hook_file, vm_name)
     libvirtd.restart()
     try:
         hook_str = hook_para + " reconnect begin -"
         assert check_hooks(hook_str)
     except AssertionError:
         utils.log_last_traceback()
         raise error.TestFail("Failed to check" " libvirtd hooks")
Ejemplo n.º 7
0
    def network_hook():
        """
        Check network hooks.
        """
        # Set interface to use default network
        net_name = params.get("net_name", "default")
        edit_iface(net_name)
        prepare_hook_file(hook_script %
                          (net_name, hook_log))
        try:
            # destroy the network
            ret = virsh.net_destroy(net_name, **virsh_dargs)
            libvirt.check_exit_status(ret)
            hook_str = hook_file + " " + net_name + " stopped end -"
            assert check_hooks(hook_str)

            # start network
            ret = virsh.net_start(net_name, **virsh_dargs)
            libvirt.check_exit_status(ret)
            hook_str = hook_file + " " + net_name + " start begin -"
            assert check_hooks(hook_str)
            hook_str = hook_file + " " + net_name + " started begin -"
            assert check_hooks(hook_str)

            # plug a interface
            if vm.is_dead():
                vm.start()
                vm.wait_for_login().close()
            mac_addr = "52:54:00:9a:53:a9"
            ret = virsh.attach_interface(vm_name,
                                         ("network %s --mac %s" %
                                          (net_name, mac_addr)))
            libvirt.check_exit_status(ret)
            hook_str = hook_file + " " + net_name + " plugged begin -"
            assert check_hooks(hook_str)
            ret = virsh.detach_interface(vm_name,
                                         "network --mac %s" % mac_addr)
            libvirt.check_exit_status(ret)
            hook_str = hook_file + " " + net_name + " unplugged begin -"
            assert check_hooks(hook_str)
            # remove the log file
            if os.path.exists(hook_log):
                os.remove(hook_log)
            # destroy the domain
            vm.destroy()
            hook_str = hook_file + " " + net_name + " unplugged begin -"
            assert check_hooks(hook_str)
        except AssertionError:
            utils.log_last_traceback()
            raise error.TestFail("Failed to check"
                                 " network hooks")
Ejemplo n.º 8
0
    def run_bandwidth_test(check_net=False, check_iface=False):
        """
        Test bandwidth option for network or interface by tc command.
        """
        iface_inbound = ast.literal_eval(iface_bandwidth_inbound)
        iface_outbound = ast.literal_eval(iface_bandwidth_outbound)
        net_inbound = ast.literal_eval(net_bandwidth_inbound)
        net_outbound = ast.literal_eval(net_bandwidth_outbound)
        net_bridge_name = ast.literal_eval(net_bridge)["name"]
        iface_name = libvirt.get_ifname_host(vm_name, iface_mac)

        try:
            if check_net and net_inbound:
                # Check qdisc rules
                cmd = "tc -d qdisc show dev %s" % net_bridge_name
                qdisc_output = utils.run(cmd).stdout
                logging.debug("Bandwidth qdisc output: %s", qdisc_output)
                if not qdisc_output.count("qdisc ingress ffff:"):
                    raise error.TestFail("Can't find ingress setting")
                check_class_rules(net_bridge_name, "1:1", {
                    "average": net_inbound["average"],
                    "peak": net_inbound["peak"]
                })
                check_class_rules(net_bridge_name, "1:2", net_inbound)

            # Check filter rules on bridge interface
            if check_net and net_outbound:
                check_filter_rules(net_bridge_name, net_outbound)

            # Check class rules on interface inbound settings
            if check_iface and iface_inbound:
                check_class_rules(
                    iface_name, "1:1", {
                        'average': iface_inbound['average'],
                        'peak': iface_inbound['peak'],
                        'burst': iface_inbound['burst']
                    })
                if iface_inbound.has_key("floor"):
                    if not libvirt_version.version_compare(1, 0, 1):
                        raise error.TestNAError("Not supported Qos"
                                                " options 'floor'")

                    check_class_rules(net_bridge_name, "1:3",
                                      {'floor': iface_inbound["floor"]})

            # Check filter rules on interface outbound settings
            if check_iface and iface_outbound:
                check_filter_rules(iface_name, iface_outbound)
        except AssertionError:
            utils.log_last_traceback()
            raise error.TestFail("Failed to check network bandwidth")
Ejemplo n.º 9
0
    def run_bandwidth_test(check_net=False, check_iface=False):
        """
        Test bandwidth option for network or interface by tc command.
        """
        iface_inbound = ast.literal_eval(iface_bandwidth_inbound)
        iface_outbound = ast.literal_eval(iface_bandwidth_outbound)
        net_inbound = ast.literal_eval(net_bandwidth_inbound)
        net_outbound = ast.literal_eval(net_bandwidth_outbound)
        net_bridge_name = ast.literal_eval(net_bridge)["name"]
        iface_name = libvirt.get_ifname_host(vm_name, iface_mac)

        try:
            if check_net and net_inbound:
                # Check qdisc rules
                cmd = "tc -d qdisc show dev %s" % net_bridge_name
                qdisc_output = utils.run(cmd).stdout
                logging.debug("Bandwidth qdisc output: %s", qdisc_output)
                if not qdisc_output.count("qdisc ingress ffff:"):
                    raise error.TestFail("Can't find ingress setting")
                check_class_rules(
                    net_bridge_name, "1:1", {"average": net_inbound["average"], "peak": net_inbound["peak"]}
                )
                check_class_rules(net_bridge_name, "1:2", net_inbound)

            # Check filter rules on bridge interface
            if check_net and net_outbound:
                check_filter_rules(net_bridge_name, net_outbound)

            # Check class rules on interface inbound settings
            if check_iface and iface_inbound:
                check_class_rules(
                    iface_name,
                    "1:1",
                    {
                        "average": iface_inbound["average"],
                        "peak": iface_inbound["peak"],
                        "burst": iface_inbound["burst"],
                    },
                )
                if iface_inbound.has_key("floor"):
                    if not libvirt_version.version_compare(1, 0, 1):
                        raise error.TestNAError("Not supported Qos" " options 'floor'")

                    check_class_rules(net_bridge_name, "1:3", {"floor": iface_inbound["floor"]})

            # Check filter rules on interface outbound settings
            if check_iface and iface_outbound:
                check_filter_rules(iface_name, iface_outbound)
        except AssertionError:
            utils.log_last_traceback()
            raise error.TestFail("Failed to check network bandwidth")
Ejemplo n.º 10
0
 def libvirtd_hook():
     """
     Check the libvirtd hooks.
     """
     prepare_hook_file(hook_script %
                       (vm_name, hook_log))
     hook_para = "%s %s" % (hook_file, vm_name)
     libvirtd.restart()
     try:
         hook_str = hook_para + " reconnect begin -"
         assert check_hooks(hook_str)
     except AssertionError:
         utils.log_last_traceback()
         raise error.TestFail("Failed to check"
                              " libvirtd hooks")
Ejemplo n.º 11
0
    def network_hook():
        """
        Check network hooks.
        """
        # Set interface to use default network
        net_name = params.get("net_name", "default")
        edit_iface(net_name)
        prepare_hook_file(hook_script % (net_name, hook_log))
        try:
            # destroy the network
            ret = virsh.net_destroy(net_name, **virsh_dargs)
            libvirt.check_exit_status(ret)
            hook_str = hook_file + " " + net_name + " stopped end -"
            assert check_hooks(hook_str)

            # start network
            ret = virsh.net_start(net_name, **virsh_dargs)
            libvirt.check_exit_status(ret)
            hook_str = hook_file + " " + net_name + " start begin -"
            assert check_hooks(hook_str)
            hook_str = hook_file + " " + net_name + " started begin -"
            assert check_hooks(hook_str)

            # plug a interface
            if vm.is_dead():
                vm.start()
                vm.wait_for_login().close()
            mac_addr = "52:54:00:9a:53:a9"
            ret = virsh.attach_interface(vm_name, ("network %s --mac %s" %
                                                   (net_name, mac_addr)))
            libvirt.check_exit_status(ret)
            hook_str = hook_file + " " + net_name + " plugged begin -"
            assert check_hooks(hook_str)
            ret = virsh.detach_interface(vm_name,
                                         "network --mac %s" % mac_addr)
            libvirt.check_exit_status(ret)
            hook_str = hook_file + " " + net_name + " unplugged begin -"
            assert check_hooks(hook_str)
            # remove the log file
            if os.path.exists(hook_log):
                os.remove(hook_log)
            # destroy the domain
            vm.destroy()
            hook_str = hook_file + " " + net_name + " unplugged begin -"
            assert check_hooks(hook_str)
        except AssertionError:
            utils.log_last_traceback()
            raise error.TestFail("Failed to check" " network hooks")
Ejemplo n.º 12
0
    def check_dom_xml(at_mem=False, dt_mem=False):
        """
        Check domain xml options.
        """
        # Global variable to store max/current memory
        global new_max_mem
        global new_cur_mem
        if attach_option.count("config"):
            dom_xml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
        else:
            dom_xml = vm_xml.VMXML.new_from_dumpxml(vm_name)
        try:
            xml_max_mem_rt = int(dom_xml.max_mem_rt)
            xml_max_mem = int(dom_xml.max_mem)
            xml_cur_mem = int(dom_xml.current_mem)
            assert int(max_mem_rt) == xml_max_mem_rt

            # Check attached/detached memory
            if at_mem:
                assert int(max_mem) + int(tg_size) == xml_max_mem
                # Bug 1220702, skip the check for current memory
                #assert int(cur_mem) + int(tg_size) == xml_cur_mem
                new_max_mem = xml_max_mem
                new_cur_mem = xml_cur_mem
                mem_dev = dom_xml.get_devices("memory")
                if len(mem_dev) != 1:
                    raise error.TestFail("Found wrong number of"
                                         " memory device")
                assert int(tg_size) == int(mem_dev[0].target.size)
                assert int(tg_node) == int(mem_dev[0].target.node)
            elif dt_mem:
                assert int(new_max_mem) - int(tg_size) == xml_max_mem
                # Bug 1220702, skip the check for current memory
                #assert int(new_cur_mem) - int(tg_size) == xml_cur_mem
        except AssertionError:
            utils.log_last_traceback()
            raise error.TestFail("Found unmatched memory setting"
                                 " from domain xml")