From 7609583108349f6590ddc47a9d269d2cbe9fe6c5 Mon Sep 17 00:00:00 2001 From: lcheng Date: Thu, 26 Sep 2024 11:17:28 +0800 Subject: [PATCH] migration: Add 4 cases about keepalive XXX-298208 - [VM migration] p2p migration with default keepalive configuration XXX-298209 - [VM migration] p2p migration with src keepalive disabled XXX-298211 - [VM migration] p2p migration with src and target keepalive disabled XXX-298214 - [VM migration] p2p migration with customized keepalive_* settings Signed-off-by: lcheng --- .../migration_network_data_transport_tls.cfg | 1 + .../migration_with_shared_tpm.cfg | 1 + .../p2p_keepalive/customized_keepalive.cfg | 75 ++++++ .../p2p_keepalive/default_keepalive.cfg | 76 +++++++ .../src_and_dest_keepalive_disabled.cfg | 57 +++++ .../p2p_keepalive/src_keepalive_disabled.cfg | 70 ++++++ .../migration/p2p_keepalive/p2p_keepalive.py | 215 ++++++++++++++++++ provider/migration/base_steps.py | 38 +++- spell.ignore | 1 + 9 files changed, 524 insertions(+), 10 deletions(-) create mode 100644 libvirt/tests/cfg/migration/p2p_keepalive/customized_keepalive.cfg create mode 100644 libvirt/tests/cfg/migration/p2p_keepalive/default_keepalive.cfg create mode 100644 libvirt/tests/cfg/migration/p2p_keepalive/src_and_dest_keepalive_disabled.cfg create mode 100644 libvirt/tests/cfg/migration/p2p_keepalive/src_keepalive_disabled.cfg create mode 100644 libvirt/tests/src/migration/p2p_keepalive/p2p_keepalive.py diff --git a/libvirt/tests/cfg/migration/migration_uri/migration_network_data_transport_tls.cfg b/libvirt/tests/cfg/migration/migration_uri/migration_network_data_transport_tls.cfg index 16d6ec8775..e085a2bb8f 100644 --- a/libvirt/tests/cfg/migration/migration_uri/migration_network_data_transport_tls.cfg +++ b/libvirt/tests/cfg/migration/migration_uri/migration_network_data_transport_tls.cfg @@ -48,6 +48,7 @@ client_cn = "ENTER.YOUR.EXAMPLE.CLIENT_CN" set_remote_libvirtd_log = "yes" libvirtd_file_type = "virtqemud" + remote_file_type = "virtqemud" libvirtd_debug_level = "1" libvirtd_debug_filters = "1:*" check_str_local_log = '['"dir":"/etc/pki/qemu","endpoint":"client","verify-peer":true']' diff --git a/libvirt/tests/cfg/migration/migration_with_vtpm/migration_with_shared_tpm.cfg b/libvirt/tests/cfg/migration/migration_with_vtpm/migration_with_shared_tpm.cfg index 330781b12d..21b74119b8 100644 --- a/libvirt/tests/cfg/migration/migration_with_vtpm/migration_with_shared_tpm.cfg +++ b/libvirt/tests/cfg/migration/migration_with_vtpm/migration_with_shared_tpm.cfg @@ -26,6 +26,7 @@ check_str_remote_log = "migration release-lock-outgoing,incoming" set_remote_libvirtd_log = "yes" libvirtd_file_type = "virtqemud" + remote_file_type = "virtqemud" libvirtd_debug_level = "1" libvirtd_debug_filters = "1:*" libvirtd_debug_file = '/var/log/libvirt/virtqemud.log' diff --git a/libvirt/tests/cfg/migration/p2p_keepalive/customized_keepalive.cfg b/libvirt/tests/cfg/migration/p2p_keepalive/customized_keepalive.cfg new file mode 100644 index 0000000000..34aa3502f9 --- /dev/null +++ b/libvirt/tests/cfg/migration/p2p_keepalive/customized_keepalive.cfg @@ -0,0 +1,75 @@ +- migration.p2p_keepalive.customized_keepalive: + type = p2p_keepalive + migration_setup = 'yes' + storage_type = 'nfs' + setup_local_nfs = 'yes' + disk_type = "file" + disk_source_protocol = "netfs" + mnt_path_name = ${nfs_mount_dir} + # Console output can only be monitored via virsh console output + only_pty = True + take_regular_screendumps = no + # Extra options to pass after + virsh_migrate_extra = '' + # SSH connection time out + ssh_timeout = 60 + # Local URI + virsh_migrate_connect_uri = 'qemu:///system' + image_convert = 'no' + server_ip = "${migrate_dest_host}" + server_user = "root" + server_pwd = "${migrate_dest_pwd}" + client_ip = "${migrate_source_host}" + client_user = "root" + client_pwd = "${migrate_source_pwd}" + libvirtd_file_type = "virtqemud" + libvirtd_debug_level = "1" + libvirtd_debug_filters = "1:*" + set_remote_libvirtd_log = "yes" + virsh_migrate_options = "--live --p2p --timeout 2 --timeout-suspend --verbose" + virsh_migrate_extra = "--bandwidth 10" + virsh_migrate_dest_state = "running" + virsh_migrate_src_state = "shut off" + variants: + - with_precopy: + variants: + - desturi_ssh: + migrate_desturi_type = "ssh" + new_ssh_port = "6666" + migrate_desturi_port = "${new_ssh_port}" + conf_on_src = '{"keepalive_interval": "3", "keepalive_count": "3"}' + src_conf_type = "qemu" + conf_on_target = '{r".*keepalive_interval\s*=.*": "keepalive_interval = 2", r".*keepalive_count\s*=.*": "keepalive_count = 4"}' + target_conf_type = "virtqemud" + remote_file_type = "virtqemud" + firewall_rule_on_dest = "ipv4 filter INPUT 0 -p tcp -j DROP --dport ${migrate_desturi_port} -s ${migrate_source_host}" + firewall_rule_on_src = "ipv4 filter INPUT 0 -p tcp -j DROP --sport ${migrate_desturi_port} -s ${migrate_dest_host}" + virsh_migrate_desturi = "qemu+${migrate_desturi_type}://${migrate_dest_host}:${new_ssh_port}/system" + - desturi_tcp: + migrate_desturi_port = "16509" + migrate_desturi_type = "tcp" + conf_on_src = '{"keepalive_interval": "3", "keepalive_count": "3"}' + src_conf_type = "qemu" + conf_on_target = '{r".*keepalive_interval\s*=.*": "keepalive_interval = 2", r".*keepalive_count\s*=.*": "keepalive_count = 4"}' + target_conf_type = "virtproxyd" + remote_file_type = "virtproxyd" + firewall_rule_on_dest = "ipv4 filter INPUT 0 -p tcp -j DROP --dport ${migrate_desturi_port} -s ${migrate_source_host}" + firewall_rule_on_src = "ipv4 filter INPUT 0 -p tcp -j DROP --sport ${migrate_desturi_port} -s ${migrate_dest_host}" + virsh_migrate_desturi = "qemu+${migrate_desturi_type}://${migrate_dest_host}/system" + variants test_case: + - after_keepalive_timeout: + status_error = "yes" + migrate_again = "yes" + expected_event_src = ["lifecycle.*Suspended Migrated", "lifecycle.*Resumed Migrated"] + expected_event_target = ["lifecycle.*: Stopped Destroyed|lifecycle.*: Stopped Failed"] + check_str_local_log = '["countToDeath=3 idle=3", "countToDeath=2 idle=6", "countToDeath=1 idle=9", "countToDeath=0 idle=12", "No response from client.*after 4 keepalive messages in 12 seconds", "internal error: connection closed due to keepalive timeout"]' + check_str_remote_log = '["countToDeath=4 idle=2", "countToDeath=3 idle=4", "countToDeath=2 idle=6", "countToDeath=1 idle=8", "countToDeath=0 idle=10", "No response from client.*after 5 keepalive messages in 10 seconds", "internal error: connection closed due to keepalive timeout"]' + migrate_src_state = "running" + migrate_dest_state = "nonexist" + virsh_migrate_extra_mig_again = " " + action_during_mig = '[{"func": "libvirt_network.setup_firewall_rule", "after_event": "iteration: '1'", "func_param": "params", "need_sleep_time": "4"}]' + - before_keepalive_timeout: + status_error = "no" + check_str_local_log = '["client=.* countToDeath=3 idle=3", "client=.* countToDeath=2 idle=6", "client=.* countToDeath=3 idle=3", "client=.* countToDeath=3 idle=3"]' + check_str_remote_log = '["client=.* countToDeath=4 idle=2", "client=.* countToDeath=3 idle=4", "client=.* countToDeath=4 idle=2", "client=.* countToDeath=4 idle=2"]' + action_during_mig = [{"func": "libvirt_network.setup_firewall_rule", "after_event": "iteration: '1'", "func_param": "params"}, {"func": "libvirt_network.cleanup_firewall_rule", "func_param": "params", "need_sleep_time": "3"}] diff --git a/libvirt/tests/cfg/migration/p2p_keepalive/default_keepalive.cfg b/libvirt/tests/cfg/migration/p2p_keepalive/default_keepalive.cfg new file mode 100644 index 0000000000..17582fd136 --- /dev/null +++ b/libvirt/tests/cfg/migration/p2p_keepalive/default_keepalive.cfg @@ -0,0 +1,76 @@ +- migration.p2p_keepalive.default_keepalive: + type = p2p_keepalive + migration_setup = 'yes' + storage_type = 'nfs' + setup_local_nfs = 'yes' + disk_type = "file" + disk_source_protocol = "netfs" + mnt_path_name = ${nfs_mount_dir} + # Console output can only be monitored via virsh console output + only_pty = True + take_regular_screendumps = no + # Extra options to pass after + virsh_migrate_extra = '' + # SSH connection time out + ssh_timeout = 60 + # Local URI + virsh_migrate_connect_uri = 'qemu:///system' + image_convert = 'no' + server_ip = "${migrate_dest_host}" + server_user = "root" + server_pwd = "${migrate_dest_pwd}" + client_ip = "${migrate_source_host}" + client_user = "root" + client_pwd = "${migrate_source_pwd}" + libvirtd_file_type = "virtqemud" + libvirtd_debug_level = "1" + libvirtd_debug_filters = "1:*" + set_remote_libvirtd_log = "yes" + virsh_migrate_options = "--live --p2p --timeout 2 --timeout-suspend --verbose" + virsh_migrate_extra = "--bandwidth 10" + virsh_migrate_dest_state = "running" + virsh_migrate_src_state = "shut off" + variants: + - with_precopy: + variants: + - desturi_ssh: + migrate_desturi_type = "ssh" + new_ssh_port = "6666" + migrate_desturi_port = ${new_ssh_port} + default_conf_on_src = ["keepalive_interval", "keepalive_count"] + src_conf_type = "qemu" + default_conf_on_target = ["keepalive_interval", "keepalive_count"] + target_conf_type = "virtqemud" + remote_file_type = "virtqemud" + firewall_rule_on_dest = "ipv4 filter INPUT 0 -p tcp -j DROP --dport ${migrate_desturi_port} -s ${migrate_source_host}" + firewall_rule_on_src = "ipv4 filter INPUT 0 -p tcp -j DROP --sport ${migrate_desturi_port} -s ${migrate_dest_host}" + virsh_migrate_desturi = "qemu+${migrate_desturi_type}://${migrate_dest_host}:${migrate_desturi_port}/system" + - desturi_tcp: + migrate_desturi_port = "16509" + migrate_desturi_type = "tcp" + default_conf_on_src = ["keepalive_interval", "keepalive_count"] + src_conf_type = "qemu" + default_conf_on_target = ["keepalive_interval", "keepalive_count"] + target_conf_type = "virtproxyd" + remote_file_type = "virtproxyd" + firewall_rule_on_dest = "ipv4 filter INPUT 0 -p tcp -j DROP --dport ${migrate_desturi_port} -s ${migrate_source_host}" + firewall_rule_on_src = "ipv4 filter INPUT 0 -p tcp -j DROP --sport ${migrate_desturi_port} -s ${migrate_dest_host}" + virsh_migrate_desturi = "qemu+${migrate_desturi_type}://${migrate_dest_host}/system" + variants keepalive_timeout: + - after_keepalive_timeout: + status_error = "yes" + migrate_again = "yes" + expected_event_src = ["lifecycle.*Suspended Migrated", "lifecycle.*Resumed Migrated"] + expected_event_target = ["lifecycle.*: Stopped Failed|lifecycle.*: Stopped Destroyed"] + #expected_event_target = ["lifecycle.*: Stopped Destroyed"] + check_str_local_log = '["countToDeath=5 idle=5", "countToDeath=4 idle=10", "countToDeath=3 idle=15", "countToDeath=2 idle=20", "countToDeath=1 idle=25", "countToDeath=0 idle=30", "No response from client.*after 5 keepalive messages in 30 seconds", "internal error: connection closed due to keepalive timeout"]' + check_str_remote_log = '["countToDeath=5 idle=5", "countToDeath=4 idle=10", "countToDeath=3 idle=15", "countToDeath=2 idle=20", "countToDeath=1 idle=25", "countToDeath=0 idle=30", "No response from client.*after 5 keepalive messages in 30 seconds", "internal error: connection closed due to keepalive timeout"]' + migrate_src_state = "running" + migrate_dest_state = "nonexist" + virsh_migrate_extra_mig_again = " " + action_during_mig = '[{"func": "libvirt_network.setup_firewall_rule", "after_event": "iteration: '1'", "func_param": "params", "need_sleep_time": "5"}]' + - before_keepalive_timeout: + status_error = "no" + check_str_local_log = '["client=.* countToDeath=5 idle=5", "client=.* countToDeath=4 idle=10", "client=.* countToDeath=5 idle=5", "client=.* countToDeath=5 idle=5"]' + check_str_remote_log = '["client=.* countToDeath=5 idle=5", "client=.* countToDeath=4 idle=10", "client=.* countToDeath=5 idle=5", "client=.* countToDeath=5 idle=5"]' + action_during_mig = [{"func": "libvirt_network.setup_firewall_rule", "after_event": "iteration: '1'", "func_param": "params"}, {"func": "libvirt_network.cleanup_firewall_rule", "func_param": "params", "need_sleep_time": "10"}] diff --git a/libvirt/tests/cfg/migration/p2p_keepalive/src_and_dest_keepalive_disabled.cfg b/libvirt/tests/cfg/migration/p2p_keepalive/src_and_dest_keepalive_disabled.cfg new file mode 100644 index 0000000000..3bbc34e180 --- /dev/null +++ b/libvirt/tests/cfg/migration/p2p_keepalive/src_and_dest_keepalive_disabled.cfg @@ -0,0 +1,57 @@ +- migration.p2p_keepalive.src_and_dest_keepalive_disabled: + type = p2p_keepalive + migration_setup = 'yes' + storage_type = 'nfs' + setup_local_nfs = 'yes' + disk_type = "file" + disk_source_protocol = "netfs" + mnt_path_name = ${nfs_mount_dir} + # Console output can only be monitored via virsh console output + only_pty = True + take_regular_screendumps = no + # Extra options to pass after + virsh_migrate_extra = '' + # SSH connection time out + ssh_timeout = 60 + # Local URI + virsh_migrate_connect_uri = 'qemu:///system' + image_convert = 'no' + server_ip = "${migrate_dest_host}" + server_user = "root" + server_pwd = "${migrate_dest_pwd}" + client_ip = "${migrate_source_host}" + client_user = "root" + client_pwd = "${migrate_source_pwd}" + virsh_migrate_options = "--live --p2p --timeout 2 --timeout-suspend --verbose" + virsh_migrate_extra = "--bandwidth 10" + virsh_migrate_dest_state = "running" + virsh_migrate_src_state = "shut off" + status_error = "no" + action_during_mig = '[{"func": "libvirt_network.setup_firewall_rule", "after_event": "iteration: '1'", "func_param": "params", "need_sleep_time": "5"}, {"func": "libvirt_network.cleanup_firewall_rule", "func_param": "params", "need_sleep_time": "30"}]' + test_case = "src_and_dest_keepalive_disabled" + variants: + - with_precopy: + variants: + - desturi_ssh: + migrate_desturi_type = "ssh" + new_ssh_port = "6666" + migrate_desturi_port = "${new_ssh_port}" + conf_on_src = '{"keepalive_interval": "-1"}' + src_conf_type = "qemu" + conf_on_target = '{r".*keepalive_interval\s*=.*": "keepalive_interval = -1"}' + target_conf_type = "virtqemud" + remote_file_type = "virtqemud" + firewall_rule_on_dest = "ipv4 filter INPUT 0 -p tcp -j DROP --dport ${migrate_desturi_port} -s ${migrate_source_host}" + firewall_rule_on_src = "ipv4 filter INPUT 0 -p tcp -j DROP --sport ${migrate_desturi_port} -s ${migrate_dest_host}" + virsh_migrate_desturi = "qemu+${migrate_desturi_type}://${migrate_dest_host}:${new_ssh_port}/system" + - desturi_tcp: + migrate_desturi_port = "16509" + migrate_desturi_type = "tcp" + conf_on_src = '{"keepalive_interval": "-1"}' + src_conf_type = "qemu" + conf_on_target = '{r".*keepalive_interval\s*=.*": "keepalive_interval = -1"}' + target_conf_type = "virtproxyd" + remote_file_type = "virtproxyd" + firewall_rule_on_dest = "ipv4 filter INPUT 0 -p tcp -j DROP --dport ${migrate_desturi_port} -s ${migrate_source_host}" + firewall_rule_on_src = "ipv4 filter INPUT 0 -p tcp -j DROP --sport ${migrate_desturi_port} -s ${migrate_dest_host}" + virsh_migrate_desturi = "qemu+${migrate_desturi_type}://${migrate_dest_host}/system" diff --git a/libvirt/tests/cfg/migration/p2p_keepalive/src_keepalive_disabled.cfg b/libvirt/tests/cfg/migration/p2p_keepalive/src_keepalive_disabled.cfg new file mode 100644 index 0000000000..faf43877d0 --- /dev/null +++ b/libvirt/tests/cfg/migration/p2p_keepalive/src_keepalive_disabled.cfg @@ -0,0 +1,70 @@ +- migration.p2p_keepalive.src_keepalive_disabled: + type = p2p_keepalive + migration_setup = 'yes' + storage_type = 'nfs' + setup_local_nfs = 'yes' + disk_type = "file" + disk_source_protocol = "netfs" + mnt_path_name = ${nfs_mount_dir} + # Console output can only be monitored via virsh console output + only_pty = True + take_regular_screendumps = no + # Extra options to pass after + virsh_migrate_extra = '' + # SSH connection time out + ssh_timeout = 60 + # Local URI + virsh_migrate_connect_uri = 'qemu:///system' + image_convert = 'no' + server_ip = "${migrate_dest_host}" + server_user = "root" + server_pwd = "${migrate_dest_pwd}" + client_ip = "${migrate_source_host}" + client_user = "root" + client_pwd = "${migrate_source_pwd}" + libvirtd_file_type = "virtqemud" + libvirtd_debug_level = "1" + libvirtd_debug_filters = "1:*" + set_remote_libvirtd_log = "yes" + virsh_migrate_options = "--live --p2p --timeout 2 --timeout-suspend --verbose" + virsh_migrate_extra = "--bandwidth 10" + virsh_migrate_dest_state = "running" + virsh_migrate_src_state = "shut off" + variants: + - with_precopy: + variants: + - desturi_ssh: + migrate_desturi_type = "ssh" + new_ssh_port = "6666" + migrate_desturi_port = "${new_ssh_port}" + conf_on_src = '{"keepalive_interval": "-1"}' + src_conf_type = "qemu" + remote_file_type = "virtqemud" + firewall_rule_on_dest = "ipv4 filter INPUT 0 -p tcp -j DROP --dport ${migrate_desturi_port} -s ${migrate_source_host}" + firewall_rule_on_src = "ipv4 filter INPUT 0 -p tcp -j DROP --sport ${migrate_desturi_port} -s ${migrate_dest_host}" + virsh_migrate_desturi = "qemu+${migrate_desturi_type}://${migrate_dest_host}:${new_ssh_port}/system" + - desturi_tcp: + migrate_desturi_port = "16509" + migrate_desturi_type = "tcp" + conf_on_src = '{"keepalive_interval": "-1"}' + src_conf_type = "qemu" + remote_file_type = "virtproxyd" + firewall_rule_on_dest = "ipv4 filter INPUT 0 -p tcp -j DROP --dport ${migrate_desturi_port} -s ${migrate_source_host}" + firewall_rule_on_src = "ipv4 filter INPUT 0 -p tcp -j DROP --sport ${migrate_desturi_port} -s ${migrate_dest_host}" + virsh_migrate_desturi = "qemu+${migrate_desturi_type}://${migrate_dest_host}/system" + variants keepalive_timeout: + - after_keepalive_timeout: + status_error = "yes" + migrate_again = "yes" + expected_event_src = ["lifecycle.*Suspended Migrated", "lifecycle.*Resumed Migrated"] + expected_event_target = ["lifecycle.*: Stopped Destroyed|lifecycle.*: Stopped Failed"] + check_no_str_local_log = '["No response.*after 5 keepalive messages in 30 seconds"]' + check_str_remote_log = '["countToDeath=5 idle=5", "countToDeath=4 idle=10", "countToDeath=3 idle=15", "countToDeath=2 idle=20", "countToDeath=1 idle=25", "countToDeath=0 idle=30", "No response from client.*after 5 keepalive messages in 30 seconds", "internal error: connection closed due to keepalive timeout"]' + migrate_src_state = "running" + migrate_dest_state = "nonexist" + virsh_migrate_extra_mig_again = " " + action_during_mig = '[{"func": "libvirt_network.setup_firewall_rule", "after_event": "iteration: '1'", "func_param": "params", "need_sleep_time": "5"}]' + - before_keepalive_timeout: + status_error = "no" + check_str_remote_log = '["client=.* countToDeath=5 idle=5", "client=.* countToDeath=4 idle=10", "client=.* countToDeath=5 idle=5", "client=.* countToDeath=5 idle=5"]' + action_during_mig = [{"func": "libvirt_network.setup_firewall_rule", "after_event": "iteration: '1'", "func_param": "params"}, {"func": "libvirt_network.cleanup_firewall_rule", "func_param": "params", "need_sleep_time": "10"}] diff --git a/libvirt/tests/src/migration/p2p_keepalive/p2p_keepalive.py b/libvirt/tests/src/migration/p2p_keepalive/p2p_keepalive.py new file mode 100644 index 0000000000..913cc242f1 --- /dev/null +++ b/libvirt/tests/src/migration/p2p_keepalive/p2p_keepalive.py @@ -0,0 +1,215 @@ +from virttest import libvirt_remote +from virttest import remote +from virttest import utils_config +from virttest import virsh + +from virttest.utils_test import libvirt +from virttest.utils_libvirt import libvirt_config +from virttest.utils_libvirt import libvirt_network + +from provider.migration import base_steps +from provider.migration import migration_base + + +def update_conf_on_src(params, test, local_obj): + """ + Update configure file on source host + + :param params: Dictionary with the test parameters + :param test: test object + :param local_obj: local conf object + """ + default_conf_on_src = eval(params.get("default_conf_on_src", "[]")) + src_conf_type = params.get("src_conf_type") + conf_on_src = eval(params.get("conf_on_src", "{}")) + + if default_conf_on_src: + local_obj.append(libvirt_config.remove_key_in_conf(default_conf_on_src, + conf_type=src_conf_type, + restart_libvirt=True)) + + if conf_on_src: + local_obj.append(libvirt.customize_libvirt_config(conf_on_src, + config_type=src_conf_type, + remote_host=False, + extra_params=params)) + + +def update_conf_on_target(params, test, remote_obj): + """ + Update configure file on target host + + :param params: Dictionary with the test parameters + :param test: test object + :param remote_obj: remote conf object + """ + default_conf_on_target = eval(params.get("default_conf_on_target", "[]")) + target_conf_type = params.get("target_conf_type") + conf_on_target = params.get("conf_on_target") + + if default_conf_on_target: + file_path = utils_config.get_conf_obj(target_conf_type).conf_path + params["file_path"] = file_path + remote_obj.append(libvirt_config.remove_key_in_conf(default_conf_on_target, + conf_type=target_conf_type, + remote_params=params, + restart_libvirt=True)) + if conf_on_target: + file_path = utils_config.get_conf_obj(target_conf_type).conf_path + remote_obj.append(libvirt_remote.update_remote_file(params, + conf_on_target, + file_path)) + + +def add_port_for_ssh(params): + """ + Add new port for sshd + + :param params: Dictionary with the test parameters + """ + new_ssh_port = params.get("new_ssh_port") + server_ip = params.get("server_ip") + server_user = params.get("server_user") + server_pwd = params.get("server_pwd") + + remote_session = remote.remote_login("ssh", server_ip, "22", + server_user, server_pwd, + r'[$#%]') + cmd = "echo 'Port 22' >> /etc/ssh/sshd_config; echo 'Port %s' >> /etc/ssh/sshd_config" % new_ssh_port + remote_session.cmd(cmd) + cmd = "semanage port -a -t ssh_port_t -p tcp %s" % new_ssh_port + remote_session.cmd(cmd) + cmd = "firewall-cmd --add-port=%s/tcp" % new_ssh_port + remote_session.cmd(cmd) + cmd = "systemctl restart sshd" + remote_session.cmd(cmd) + remote_session.close() + + +def del_port_for_ssh(params): + """ + Delete new port for sshd + + :param params: Dictionary with the test parameters + """ + new_ssh_port = params.get("new_ssh_port") + server_ip = params.get("server_ip") + server_user = params.get("server_user") + server_pwd = params.get("server_pwd") + + remote_session = remote.remote_login("ssh", server_ip, "22", + server_user, server_pwd, + r'[$#%]') + cmd = "sed -i '/^Port .*/d' /etc/ssh/sshd_config" + remote_session.cmd(cmd) + cmd = "firewall-cmd --remove-port=%s/tcp" % new_ssh_port + remote_session.cmd(cmd) + cmd = "systemctl restart sshd" + remote_session.cmd(cmd) + remote_session.close() + + +def run(test, params, env): + """ + Test P2P migration with different keepalive configuration. + + :param test: test object + :param params: Dictionary with the test parameters + :param env: Dictionary with test environment. + """ + def setup_test(): + """ + Setup steps + + """ + test.log.info("Setup steps.") + new_ssh_port = params.get("new_ssh_port") + + if new_ssh_port: + add_port_for_ssh(params) + migration_obj.setup_connection() + update_conf_on_src(params, test, local_obj) + update_conf_on_target(params, test, remote_obj) + + def verify_test(): + """ + Verify steps + + """ + migrate_dest_state = params.get("migrate_dest_state") + migrate_src_state = params.get("migrate_src_state") + dest_uri = params.get("virsh_migrate_desturi") + keepalive_timeout = params.get("keepalive_timeout") + + test.log.info("Verify steps.") + if keepalive_timeout == "after_keepalive_timeout": + libvirt_network.cleanup_firewall_rule(params) + func_returns = dict(migration_obj.migration_test.func_ret) + migration_obj.migration_test.func_ret.clear() + test.log.debug("Migration returns function results:%s", func_returns) + if int(migration_obj.migration_test.ret.exit_status) == 0: + test.fail("Expected failed, but migrate successfully.") + if not libvirt.check_vm_state(vm.name, migrate_src_state, uri=migration_obj.src_uri): + test.faile("Check vm state on source host fail.") + dest_vm_list = virsh.dom_list(options="--all --persistent", debug=True, uri=dest_uri) + if migrate_dest_state == "nonexist": + if vm_name in dest_vm_list.stdout.strip(): + test.fail("%s should not exist." % vm_name) + else: + migration_obj.verify_default() + + def cleanup_test(): + """ + Cleanup steps + + """ + test.log.info("Cleanup steps.") + src_conf_type = params.get("src_conf_type") + new_ssh_port = params.get("new_ssh_port") + dest_uri = params.get("virsh_migrate_desturi") + + libvirt_network.cleanup_firewall_rule(params) + if new_ssh_port: + if virsh.is_alive(vm_name, uri=dest_uri): + virsh.destroy(vm_name, uri=dest_uri) + del_port_for_ssh(params) + migration_obj.cleanup_connection() + if remote_obj: + for obj in remote_obj: + del obj + if local_obj: + for obj in local_obj: + libvirt.customize_libvirt_config(None, + config_type=src_conf_type, + remote_host=False, + is_recover=True, + extra_params=params, + config_object=obj) + + test_case = params.get('test_case', '') + migrate_again = "yes" == params.get("migrate_again", "no") + vm_name = params.get("migrate_main_vm") + + virsh_session = None + remote_virsh_session = None + + vm = env.get_vm(vm_name) + migration_obj = base_steps.MigrationBase(test, vm, params) + + remote_obj = [] + local_obj = [] + + try: + setup_test() + if test_case != "src_and_dest_keepalive_disabled": + # Monitor event on source/target host + virsh_session, remote_virsh_session = migration_base.monitor_event(params) + migration_obj.run_migration() + verify_test() + if test_case != "src_and_dest_keepalive_disabled": + migration_base.check_event_output(params, test, virsh_session, remote_virsh_session) + if migrate_again: + migration_obj.run_migration_again() + migration_obj.verify_default() + finally: + cleanup_test() diff --git a/provider/migration/base_steps.py b/provider/migration/base_steps.py index 49c4259033..c23c9c487a 100644 --- a/provider/migration/base_steps.py +++ b/provider/migration/base_steps.py @@ -343,9 +343,9 @@ def set_remote_log(self): log_level = self.params.get("libvirtd_debug_level") log_file = self.params.get("libvirtd_debug_file") log_filters = self.params.get("libvirtd_debug_filters") - file_type = self.params.get("libvirtd_file_type") + remote_file_type = self.params.get("remote_file_type") - service_name = utils_libvirtd.Libvirtd(file_type).service_name + service_name = utils_libvirtd.Libvirtd(remote_file_type).service_name file_path = utils_config.get_conf_obj(service_name).conf_path self.test.log.debug("Config file path: %s" % file_path) cmd = "ls {0} || mkdir -p {0}".format(os.path.dirname(log_file)) @@ -365,24 +365,42 @@ def check_local_and_remote_log(self, local_str_in_log=True, remote_str_in_log=Tr otherwise, False """ check_str_local_log = eval(self.params.get("check_str_local_log", "[]")) - check_str_remote_log = self.params.get("check_str_remote_log", "") + check_no_str_local_log = eval(self.params.get("check_no_str_local_log", "[]")) + check_str_remote_log = eval(self.params.get("check_str_remote_log", "[]")) + check_no_str_remote_log = eval(self.params.get("check_no_str_remote_log", "[]")) log_file = self.params.get("libvirtd_debug_file") + runner_on_target = None + if check_str_local_log: for check_log in check_str_local_log: libvirt.check_logfile(check_log, log_file, str_in_log=local_str_in_log) - if check_str_remote_log: - runner_on_target = None + if check_no_str_local_log: + for check_log in check_no_str_local_log: + local_str_in_log = False + libvirt.check_logfile(check_log, log_file, str_in_log=local_str_in_log) + if check_str_remote_log or check_no_str_remote_log: server_ip = self.params.get("server_ip") server_user = self.params.get("server_user", "root") server_pwd = self.params.get("server_pwd") runner_on_target = remote.RemoteRunner(host=server_ip, username=server_user, password=server_pwd) - libvirt.check_logfile(check_str_remote_log, - log_file, - str_in_log=remote_str_in_log, - cmd_parms=self.params, - runner_on_target=runner_on_target) + + if check_str_remote_log: + for check_log in check_str_remote_log: + libvirt.check_logfile(check_log, + log_file, + str_in_log=remote_str_in_log, + cmd_parms=self.params, + runner_on_target=runner_on_target) + if check_no_str_remote_log: + remote_str_in_log = False + for check_log in check_no_str_remote_log: + libvirt.check_logfile(check_log, + log_file, + str_in_log=remote_str_in_log, + cmd_parms=self.params, + runner_on_target=runner_on_target) def remote_add_or_remove_port(self, port, add=True): """ diff --git a/spell.ignore b/spell.ignore index c18394405c..5d3f8c4683 100644 --- a/spell.ignore +++ b/spell.ignore @@ -482,6 +482,7 @@ kallsysm kb kconfig kdump +keepalive kexec keycodes keypresses