Beispiel #1
0
    def conn_recover(self):
        """
        Do the clean up work.

        (1).initialize variables.
        (2).Delete remote file.
        (3).Restart libvirtd on server.
        """
        # initialize variables
        server_ip = self.server_ip
        server_user = self.server_user
        server_pwd = self.server_pwd

        del self.client_hosts
        del self.server_syslibvirtd
        del self.server_libvirtdconf
        # restart libvirtd service on server
        try:
            utils_libvirtd.service_libvirtd_control(
                action='restart',
                remote_ip=server_ip,
                remote_user=server_user,
                remote_pwd=server_pwd,
            )
        except utils_libvirtd.LibvirtdError, detail:
            raise ConnServerRestartError(detail)
Beispiel #2
0
    def conn_recover(self):
        """
        Clean up for TCP connection.

        (1).initialize variables.
        (2).Delete the RemoteFile.
        (3).restart libvirtd on server.
        """
        # initialize variables
        server_ip = self.server_ip
        server_user = self.server_user
        server_pwd = self.server_pwd
        # delete the RemoteFile object to recover remote file.
        del self.remote_syslibvirtd
        del self.remote_libvirtdconf
        # restart libvirtd service on server
        try:
            utils_libvirtd.service_libvirtd_control(
                action='restart',
                remote_ip=server_ip,
                remote_user=server_user,
                remote_pwd=server_pwd,
            )
        except utils_libvirtd.LibvirtdError, detail:
            raise ConnServerRestartError(detail)
Beispiel #3
0
    def conn_setup(self):
        """
        Enable tcp connect of libvirtd on server.

        (1).initialization for variables.
        (2).edit /etc/sysconfig/libvirtd on server.
        (3).edit /etc/libvirt/libvirtd.conf on server.
        (4).restart libvirtd service on server.
        """
        # initialize variables
        server_ip = self.server_ip
        server_user = self.server_user
        server_pwd = self.server_pwd
        tcp_port = self.tcp_port

        # edit the /etc/sysconfig/libvirtd to add --listen args in libvirtd
        pattern2repl = {
            r".*LIBVIRTD_ARGS\s*=\s*\"\s*--listen\s*\".*":
            "LIBVIRTD_ARGS=\"--listen\""
        }
        self.remote_syslibvirtd.sub_else_add(pattern2repl)

        # edit the /etc/libvirt/libvirtd.conf
        # listen_tcp=1, tcp_port=$tcp_port, auth_tcp="none"
        pattern2repl = {
            r".*listen_tls\s*=.*": 'listen_tls=0',
            r".*listen_tcp\s*=.*": 'listen_tcp=1',
            r".*tcp_port\s*=.*": 'tcp_port="%s"' % (tcp_port),
            r'.*auth_tcp\s*=.*': 'auth_tcp="none"'
        }
        self.remote_libvirtdconf.sub_else_add(pattern2repl)

        # restart libvirtd service on server
        try:
            utils_libvirtd.service_libvirtd_control(
                action='restart',
                remote_ip=server_ip,
                remote_user=server_user,
                remote_pwd=server_pwd,
            )
        except utils_libvirtd.LibvirtdError, detail:
            raise ConnServerRestartError(detail)
Beispiel #4
0
def remotely_control_libvirtd(server_ip, server_user, server_pwd,
                              action='restart', status_error='no'):
    """
    Remotely restart libvirt service
    """
    session = None
    try:
        session = remote.wait_for_login('ssh', server_ip, '22',
                                        server_user, server_pwd,
                                        r"[\#\$]\s*$")
        logging.info("%s libvirt daemon\n", action)
        service_libvirtd_control(action, session)
        session.close()
    except (remote.LoginError, aexpect.ShellError, error.CmdError), detail:
        if session:
            session.close()
        if status_error == "no":
            raise error.TestFail("Failed to %s libvirtd service on "
                                 "server: %s\n", action, detail)
        else:
            logging.info("It is an expect %s", detail)
Beispiel #5
0
    def conn_recover(self):
        """
        Clean up for TCP connection.

        (1).initialize variables.
        (2).Delete the RemoteFile.
        (3).restart libvirtd on server.
        """
        # initialize variables
        server_ip = self.server_ip
        server_user = self.server_user
        server_pwd = self.server_pwd
        # delete the RemoteFile object to recover remote file.
        del self.remote_syslibvirtd
        del self.remote_libvirtdconf
        # restart libvirtd service on server
        try:
            utils_libvirtd.service_libvirtd_control(action='restart',
                                                    remote_ip=server_ip,
                                                    remote_user=server_user,
                                                    remote_pwd=server_pwd,)
        except utils_libvirtd.LibvirtdError, detail:
            raise ConnServerRestartError(detail)
Beispiel #6
0
    def conn_recover(self):
        """
        Do the clean up work.

        (1).initialize variables.
        (2).Delete remote file.
        (3).Restart libvirtd on server.
        """
        # initialize variables
        server_ip = self.server_ip
        server_user = self.server_user
        server_pwd = self.server_pwd

        del self.client_hosts
        del self.server_syslibvirtd
        del self.server_libvirtdconf
        # restart libvirtd service on server
        try:
            utils_libvirtd.service_libvirtd_control(action='restart',
                                                    remote_ip=server_ip,
                                                    remote_user=server_user,
                                                    remote_pwd=server_pwd,)
        except utils_libvirtd.LibvirtdError, detail:
            raise ConnServerRestartError(detail)
Beispiel #7
0
    def conn_setup(self):
        """
        Enable tcp connect of libvirtd on server.

        (1).initialization for variables.
        (2).edit /etc/sysconfig/libvirtd on server.
        (3).edit /etc/libvirt/libvirtd.conf on server.
        (4).restart libvirtd service on server.
        """
        # initialize variables
        server_ip = self.server_ip
        server_user = self.server_user
        server_pwd = self.server_pwd
        tcp_port = self.tcp_port

        # edit the /etc/sysconfig/libvirtd to add --listen args in libvirtd
        pattern2repl = {r".*LIBVIRTD_ARGS\s*=\s*\"\s*--listen\s*\".*":
                        "LIBVIRTD_ARGS=\"--listen\""}
        self.remote_syslibvirtd.sub_else_add(pattern2repl)

        # edit the /etc/libvirt/libvirtd.conf
        # listen_tcp=1, tcp_port=$tcp_port, auth_tcp="none"
        pattern2repl = {r".*listen_tls\s*=.*": 'listen_tls=0',
                        r".*listen_tcp\s*=.*": 'listen_tcp=1',
                        r".*tcp_port\s*=.*": 'tcp_port="%s"' % (tcp_port),
                        r'.*auth_tcp\s*=.*': 'auth_tcp="none"'}
        self.remote_libvirtdconf.sub_else_add(pattern2repl)

        # restart libvirtd service on server
        try:
            utils_libvirtd.service_libvirtd_control(action='restart',
                                                    remote_ip=server_ip,
                                                    remote_user=server_user,
                                                    remote_pwd=server_pwd,)
        except utils_libvirtd.LibvirtdError, detail:
            raise ConnServerRestartError(detail)
def run(test, params, env):
    """
    Test the network transaction and cover virsh iface-{begin,commit,rollback}

    1. Positive testing
       1.1 begin or/and commit testing with libvirtd running
       1.2 begin or/and rollback testing with libvirtd running
    2. Negative testing
       2.1 no pending transaction testing
       2.2 there is already an open transaction testing
       2.3 break network transaction testing
           2.3.1 begin and commit testing with libvirtd restart
           2.3.2 begin and rollback testing with libvirtd restart
    """

    if not utils_package.package_install(["mlocate"]):
        test.cancel("Failed to install dependency package mlocate" " on host")

    if process.system("updatedb", shell=True):
        test.cancel("update a database for mlocate failed")

    # Run test case
    status_error = params.get("status_error", "no")
    libvirtd = params.get("libvirtd", "on")
    exist_trans = params.get("exist_trans", "no")
    iface_name = params.get("iface_name", "ifcfg-test")
    transaction = params.get("iface_transaction", "")

    network_script_dir = "/etc/sysconfig/network-scripts"

    iface_cfg = os.path.join(network_script_dir, iface_name)
    netcf_snap_dir = netcf_trans_control(test, "snapshot-dir")

    params['iface_cfg'] = iface_cfg
    params['netcf_snap_dir'] = netcf_snap_dir

    # positive and negative testing #########

    try:
        if status_error == "no":
            # Do begin-commit testing
            if transaction == "begin_commit":
                iface_trans_begin(params, test)
                write_iface_cfg(iface_cfg, test)
                # Break begin-commit operation
                if libvirtd == "restart":
                    utils_libvirtd.service_libvirtd_control("restart")
                try:
                    iface_trans_commit(params, test)
                except exceptions.TestError:
                    cleanup(iface_cfg, test, exist_trans)

                # Only cleanup temporary network configuration file
                cleanup(iface_cfg, test)

            # Do begin-rollback testing
            elif transaction == "begin_rollback":
                iface_trans_begin(params, test)
                write_iface_cfg(iface_cfg, test)
                # Break begin-rollback operation
                if libvirtd == "restart":
                    utils_libvirtd.service_libvirtd_control("restart")
                try:
                    iface_trans_rollback(params, test)
                except exceptions.TestError:
                    cleanup(iface_cfg, test, exist_trans)
            else:
                test.fail("The 'transaction' must be 'begin_commit' or"
                          " 'begin_rollback': %s" % status_error)

        if status_error == "yes":
            # No pending transaction
            if exist_trans != "yes":
                iface_trans_commit(params, test)
                iface_trans_rollback(params, test)
            # There is already an open transaction
            else:
                netcf_trans_control(test, 'change-begin')
                iface_trans_begin(params, test)
    finally:
        # Cleanup network transaction and temporary configuration file
        cleanup(iface_cfg, test, exist_trans)
Beispiel #9
0
                raise ConnSCPError('AdminHost', local_path,
                                   server_ip, remote_path, detail)

        # edit the /etc/sysconfig/libvirtd to add --listen args in libvirtd
        pattern2repl = {r".*LIBVIRTD_ARGS\s*=\s*\"\s*--listen\s*\".*":
                        "LIBVIRTD_ARGS=\"--listen\""}
        self.server_syslibvirtd.sub_else_add(pattern2repl)

        # edit the /etc/libvirt/libvirtd.conf to add listen_tls=1
        pattern2repl = {r".*listen_tls\s*=\s*.*": "listen_tls=1"}
        self.server_libvirtdconf.sub_else_add(pattern2repl)

        # restart libvirtd service on server
        try:
            utils_libvirtd.service_libvirtd_control(action='restart',
                                                    remote_ip=server_ip,
                                                    remote_user=server_user,
                                                    remote_pwd=server_pwd,)
        except utils_libvirtd.LibvirtdError, detail:
            raise ConnServerRestartError(detail)

    def client_setup(self):
        """
        setup private key and certificate file for client.

        (1).initialization for variables.
        (2).build a key for client.
        (3).copy files to client.
        (4).edit /etc/hosts on client.
        """
        # initialize variables
        tmp_dir = self.tmp_dir
Beispiel #10
0
def run_virsh_emulatorpin(test, params, env):
    """
    Test emulatorpin tuning

    1) Positive testing
       1.1) get the current emulatorpin parameters for a running/shutoff guest
       1.2) set the current emulatorpin parameters for a running/shutoff guest
    2) Negative testing
       2.1) get emulatorpin parameters for a running/shutoff guest
       2.2) set emulatorpin parameters running/shutoff guest
    """

    # Run test case
    vm_name = params.get("main_vm")
    vm = env.get_vm(vm_name)
    cgconfig = params.get("cgconfig", "on")
    cpulist = params.get("emulatorpin_cpulist")
    status_error = params.get("status_error", "no")
    change_parameters = params.get("change_parameters", "no")

    test_dicts = dict(params)
    test_dicts['vm'] = vm

    host_cpus = int(open('/proc/cpuinfo').read().count('processor'))
    test_dicts['host_cpus'] = host_cpus

    cpu_list = None

    if cpulist:
        cpu_list = cpus_parser(cpulist)
        test_dicts['cpu_list'] = cpu_list
        logging.debug("CPU list is %s", cpu_list)

    # If the physical CPU N doesn't exist, it's an expected error
    if cpu_list and max(cpu_list) > host_cpus - 1:
        test_dicts["status_error"] = "yes"

    # positive and negative testing #########

    if status_error == "no":
        if change_parameters == "no":
            get_emulatorpin_parameter(test_dicts)
        else:
            set_emulatorpin_parameter(test_dicts)

    cg = utils_cgroup.CgconfigService()

    if cgconfig == "off":
        if cg.cgconfig_is_running():
            cg.cgconfig_stop()

    if status_error == "yes":
        if change_parameters == "no":
            get_emulatorpin_parameter(test_dicts)
        else:
            set_emulatorpin_parameter(test_dicts)

    # Recover cgconfig and libvirtd service
    if not cg.cgconfig_is_running():
        cg.cgconfig_restart()()
        utils_libvirtd.service_libvirtd_control("restart")
def run(test, params, env):
    """
    Test the network transaction and cover virsh iface-{begin,commit,rollback}

    1. Positive testing
       1.1 begin or/and commit testing with libvirtd running
       1.2 begin or/and rollback testing with libvirtd running
    2. Negative testing
       2.1 no pending transaction testing
       2.2 there is already an open transaction testing
       2.3 break network transaction testing
           2.3.1 begin and commit testing with libvirtd restart
           2.3.2 begin and rollback testing with libvirtd restart
    """
    # Run test case
    status_error = params.get("status_error", "no")
    libvirtd = params.get("libvirtd", "on")
    exist_trans = params.get("exist_trans", "no")
    iface_name = params.get("iface_name", "ifcfg-test")
    transaction = params.get("iface_transaction", "")

    network_script_dir = "/etc/sysconfig/network-scripts"

    iface_cfg = os.path.join(network_script_dir, iface_name)
    netcf_snap_dir = netcf_trans_control("snapshot-dir")

    params['iface_cfg'] = iface_cfg
    params['netcf_snap_dir'] = netcf_snap_dir

    # positive and negative testing #########

    if status_error == "no":
        # Do begin-commit testing
        if transaction == "begin_commit":
            iface_trans_begin(params)
            write_iface_cfg(iface_cfg)
            # Break begin-commit operation
            if libvirtd == "restart":
                utils_libvirtd.service_libvirtd_control("restart")
            try:
                iface_trans_commit(params)
            except error.TestError:
                cleanup(iface_cfg, exist_trans)

            # Only cleanup temporary network configuration file
            cleanup(iface_cfg)

        # Do begin-rollback testing
        elif transaction == "begin_rollback":
            iface_trans_begin(params)
            write_iface_cfg(iface_cfg)
            # Break begin-rollback operation
            if libvirtd == "restart":
                utils_libvirtd.service_libvirtd_control("restart")
            try:
                iface_trans_rollback(params)
            except error.TestError:
                cleanup(iface_cfg, exist_trans)
        else:
            raise error.TestFail("The 'transaction' must be 'begin_commit' or"
                                 " 'begin_rollback': %s" % status_error)

    if status_error == "yes":
        # No pending transaction
        if exist_trans != "yes":
            iface_trans_commit(params)
            iface_trans_rollback(params)
        # There is already an open transaction
        else:
            netcf_trans_control('change-begin')
            iface_trans_begin(params)

    # Cleanup network transaction and temporary configuration file
    cleanup(iface_cfg, exist_trans)
Beispiel #12
0
        # edit the /etc/sysconfig/libvirtd to add --listen args in libvirtd
        pattern2repl = {
            r".*LIBVIRTD_ARGS\s*=\s*\"\s*--listen\s*\".*":
            "LIBVIRTD_ARGS=\"--listen\""
        }
        self.server_syslibvirtd.sub_else_add(pattern2repl)

        # edit the /etc/libvirt/libvirtd.conf to add listen_tls=1
        pattern2repl = {r".*listen_tls\s*=\s*.*": "listen_tls=1"}
        self.server_libvirtdconf.sub_else_add(pattern2repl)

        # restart libvirtd service on server
        try:
            utils_libvirtd.service_libvirtd_control(
                action='restart',
                remote_ip=server_ip,
                remote_user=server_user,
                remote_pwd=server_pwd,
            )
        except utils_libvirtd.LibvirtdError, detail:
            raise ConnServerRestartError(detail)

    def client_setup(self):
        """
        setup private key and certificate file for client.

        (1).initialization for variables.
        (2).build a key for client.
        (3).copy files to client.
        (4).edit /etc/hosts on client.
        """
        # initialize variables
Beispiel #13
0
def run(test, params, env):
    """
    Test the network transaction and cover virsh iface-{begin,commit,rollback}

    1. Positive testing
       1.1 begin or/and commit testing with libvirtd running
       1.2 begin or/and rollback testing with libvirtd running
    2. Negative testing
       2.1 no pending transaction testing
       2.2 there is already an open transaction testing
       2.3 break network transaction testing
           2.3.1 begin and commit testing with libvirtd restart
           2.3.2 begin and rollback testing with libvirtd restart
    """
    # Run test case
    status_error = params.get("status_error", "no")
    libvirtd = params.get("libvirtd", "on")
    exist_trans = params.get("exist_trans", "no")
    iface_name = params.get("iface_name", "ifcfg-test")
    transaction = params.get("iface_transaction", "")

    network_script_dir = "/etc/sysconfig/network-scripts"

    iface_cfg = os.path.join(network_script_dir, iface_name)
    netcf_snap_dir = netcf_trans_control("snapshot-dir")

    params['iface_cfg'] = iface_cfg
    params['netcf_snap_dir'] = netcf_snap_dir

    # positive and negative testing #########

    if status_error == "no":
        # Do begin-commit testing
        if transaction == "begin_commit":
            iface_trans_begin(params)
            write_iface_cfg(iface_cfg)
            # Break begin-commit operation
            if libvirtd == "restart":
                utils_libvirtd.service_libvirtd_control("restart")
            try:
                iface_trans_commit(params)
            except error.TestError:
                cleanup(iface_cfg, exist_trans)

            # Only cleanup temporary network configuration file
            cleanup(iface_cfg)

        # Do begin-rollback testing
        elif transaction == "begin_rollback":
            iface_trans_begin(params)
            write_iface_cfg(iface_cfg)
            # Break begin-rollback operation
            if libvirtd == "restart":
                utils_libvirtd.service_libvirtd_control("restart")
            try:
                iface_trans_rollback(params)
            except error.TestError:
                cleanup(iface_cfg, exist_trans)
        else:
            raise error.TestFail("The 'transaction' must be 'begin_commit' or"
                                 " 'begin_rollback': %s" % status_error)

    if status_error == "yes":
        # No pending transaction
        if exist_trans != "yes":
            iface_trans_commit(params)
            iface_trans_rollback(params)
        # There is already an open transaction
        else:
            netcf_trans_control('change-begin')
            iface_trans_begin(params)

    # Cleanup network transaction and temporary configuration file
    cleanup(iface_cfg, exist_trans)
def run(test, params, env):
    """
    Test the network transaction and cover virsh iface-{begin,commit,rollback}

    1. Positive testing
       1.1 begin or/and commit testing with libvirtd running
       1.2 begin or/and rollback testing with libvirtd running
    2. Negative testing
       2.1 no pending transaction testing
       2.2 there is already an open transaction testing
       2.3 break network transaction testing
           2.3.1 begin and commit testing with libvirtd restart
           2.3.2 begin and rollback testing with libvirtd restart
    """

    if not utils_package.package_install(["mlocate"]):
        test.cancel("Failed to install dependency package mlocate"
                    " on host")

    if process.system("updatedb", shell=True):
        test.cancel("update a database for mlocate failed")

    # Run test case
    status_error = params.get("status_error", "no")
    libvirtd = params.get("libvirtd", "on")
    exist_trans = params.get("exist_trans", "no")
    iface_name = params.get("iface_name", "ifcfg-test")
    transaction = params.get("iface_transaction", "")

    network_script_dir = "/etc/sysconfig/network-scripts"

    iface_cfg = os.path.join(network_script_dir, iface_name)
    netcf_snap_dir = netcf_trans_control(test, "snapshot-dir")

    params['iface_cfg'] = iface_cfg
    params['netcf_snap_dir'] = netcf_snap_dir

    # positive and negative testing #########

    try:
        if status_error == "no":
            # Do begin-commit testing
            if transaction == "begin_commit":
                iface_trans_begin(params, test)
                write_iface_cfg(iface_cfg, test)
                # Break begin-commit operation
                if libvirtd == "restart":
                    utils_libvirtd.service_libvirtd_control("restart")
                try:
                    iface_trans_commit(params, test)
                except exceptions.TestError:
                    cleanup(iface_cfg, test, exist_trans)

                # Only cleanup temporary network configuration file
                cleanup(iface_cfg, test)

            # Do begin-rollback testing
            elif transaction == "begin_rollback":
                iface_trans_begin(params, test)
                write_iface_cfg(iface_cfg, test)
                # Break begin-rollback operation
                if libvirtd == "restart":
                    utils_libvirtd.service_libvirtd_control("restart")
                try:
                    iface_trans_rollback(params, test)
                except exceptions.TestError:
                    cleanup(iface_cfg, test, exist_trans)
            else:
                test.fail("The 'transaction' must be 'begin_commit' or"
                          " 'begin_rollback': %s" % status_error)

        if status_error == "yes":
            # No pending transaction
            if exist_trans != "yes":
                iface_trans_commit(params, test)
                iface_trans_rollback(params, test)
            # There is already an open transaction
            else:
                netcf_trans_control(test, 'change-begin')
                iface_trans_begin(params, test)
    finally:
        # Cleanup network transaction and temporary configuration file
        cleanup(iface_cfg, test, exist_trans)