* [PATCH 0/3] Add migration function and test for libvirt.
@ 2012-01-17 3:21 tangchen
2012-01-17 3:24 ` [Autotest] [PATCH 1/3] " tangchen
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: tangchen @ 2012-01-17 3:21 UTC (permalink / raw)
To: Lucas Meneghel Rodrigues, autotest, kvm
Hi~
1. There is no muigrate() function in class VM in libvirt_vm.py.
2. There is no tests for libvirt in client/tests/libvirt.
So, I would like to add some tests for libvirt.
Here are three patches,
1. Add a migrate() function for class VM in libvirt_vm.py, which
encapsulates "virsh migrate" command.
2. Add a "tests" directory in client/tests/libvirt/, and a test
for "virsh migrate" command.
3. Add configuration for this test.
--
Best Regards,
Tang chen
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Autotest] [PATCH 1/3] Add migration function and test for libvirt.
2012-01-17 3:21 [PATCH 0/3] Add migration function and test for libvirt tangchen
@ 2012-01-17 3:24 ` tangchen
2012-01-17 3:24 ` [PATCH 0/3] " tangchen
2012-01-17 3:25 ` [PATCH 3/3] " tangchen
2 siblings, 0 replies; 4+ messages in thread
From: tangchen @ 2012-01-17 3:24 UTC (permalink / raw)
To: Lucas Meneghel Rodrigues, autotest, kvm
This patch adds a migrate() function for libvirt, which is a encapsulation for "virsh migrate" command.
Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com>
---
client/virt/libvirt_vm.py | 212 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 212 insertions(+), 0 deletions(-)
diff --git a/client/virt/libvirt_vm.py b/client/virt/libvirt_vm.py
index c825661..773e170 100644
--- a/client/virt/libvirt_vm.py
+++ b/client/virt/libvirt_vm.py
@@ -293,6 +293,36 @@ def virsh_domain_exists(name, uri = ""):
logging.warning("VM %s does not exist", name)
return False
+def virsh_migrate(name, migrate_cmd, params = None, uri = ""):
+ """
+ Migrate a guest to another host.
+
+ @params name: VM name
+ @params migrate_cmd: Migrate command to be executed
+ @param params: A dict containing VM params
+ """
+ uri_arg = ""
+ if uri:
+ uri_arg = "-c " + uri
+ destpwd = params.get("destpwd")
+ destuser = params.get("destuser")
+ try:
+ cmd = "virsh %s %s" % (uri_arg, migrate_cmd)
+ session = aexpect.ShellSession(cmd, linesep="\n")
+ virt_utils._remote_login(session, destuser, destpwd, "", timeout=60)
+ return True
+ # If migration succeeds, migrate command will terminate the session
+ # automically. So we have to catch the LoginProcessTerminatedError.
+ except virt_utils.LoginProcessTerminatedError, e:
+ logging.info("%s", e)
+ session.close()
+ if str(e).find("status: 0") >= 0:
+ return True
+ else:
+ return False
+ except error.CmdError:
+ logging.error("Migrating VM %s failed", name)
+ return False
class VM(virt_vm.BaseVM):
"""
@@ -978,6 +1008,188 @@ class VM(virt_vm.BaseVM):
fcntl.lockf(lockfile, fcntl.LOCK_UN)
lockfile.close()
+ def __make_migrate_command(self, name=None, params=None):
+ """
+ Generate a migrate command line.
+
+ @param name: The name of the object
+ @param params: A dict containing VM params
+
+ @note: The params dict should contain:
+ live -- yes/no
+ method -- direct/p2p/p2p_tunnelled
+ persistent -- yes/no
+ undefinesource -- yes/no
+ suspend -- yes/no
+ copy-storage -- all/inc
+ change-protection -- yes/no
+ verbose -- /yes/no
+ domain -- VM name
+ desturi -- Destination URI
+ migrateuri -- Migration URI
+ dname -- VM name on destination
+ timeout -- timeout > 0
+ xml -- Path to xml file to be used on destination
+ """
+ def add_live():
+ return " --live"
+
+ def add_method(method):
+ if method == "direct":
+ return " --direct"
+ elif method == "p2p":
+ return " --p2p"
+ # Cannot use --tunnelled without --p2p.
+ elif method == "p2p_tunnelled":
+ return " --p2p --tunnelled"
+ else:
+ logging.warning("Unknown migrate method, using default.")
+ return ""
+
+ def add_persistent():
+ return " --persistent"
+
+ def add_undefinesource():
+ return " --undefinesource"
+
+ def add_suspend():
+ return " --suspend"
+
+ def add_copy_storage(copy_storage_mode):
+ if copy_storage_mode == "all":
+ return " --copy-storage-all"
+ elif copy_storage_mode == "inc":
+ return " --copy-storage-inc"
+ else:
+ logging.warning("Unknown copy storage mode, using default.")
+ return ""
+
+ def add_change_protection():
+ return " --change-protection"
+
+ def add_verbose():
+ return " --verbose"
+
+ # Domain name must be specified.
+ def add_domain(domain_name):
+ if virsh_domain_exists(domain_name):
+ return " --domain %s" % domain_name
+ else:
+ raise virt_vm.VMMigrateError("Wrong domain name.")
+
+ # Destination uri must be specified.
+ def add_desturi(desturi):
+ if desturi:
+ return " --desturi %s" % desturi
+ else:
+ raise virt_vm.VMMigrateError("Wrong destination uri.")
+
+ def add_migrateuri(migrateuri):
+ if migrateuri:
+ return " --migrateuri %s" % migrateuri
+ else:
+ return ""
+
+ def add_dname(dname):
+ if dname:
+ return " --dname %s" % dname
+ else:
+ return ""
+
+ def add_timeout(timeout):
+ if int(timeout) > 0:
+ return " --timeout %s" % timeout
+ else:
+ logging.warning("Invalid timeout value. Ingoring it.")
+ return ""
+
+ def add_xml(xml_file):
+ if os.path.isfile(xml_file):
+ return " --xml %s" % xml_file
+ else:
+ logging.warning("%s: No such xml file is found. Ingoring it.", xml_file)
+ return ""
+
+ migrate_cmd = "migrate "
+
+ if name is None:
+ name = self.name
+ if params is None:
+ params = self.params
+
+ live = params.get("live")
+ if live == "yes":
+ migrate_cmd += add_live()
+
+ method = params.get("method")
+ if method:
+ migrate_cmd += add_method(method)
+
+ persistent = params.get("persistent")
+ if persistent == "yes":
+ migrate_cmd += add_persistent()
+
+ undefinesource = params.get("undefinesource")
+ if undefinesource == "yes":
+ migrate_cmd += add_undefinesource()
+
+ suspend = params.get("suspend")
+ if suspend == "yes":
+ migrate_cmd += add_suspend()
+
+ copy_storage_mode = params.get("copy_storage_mode")
+ if copy_storage_mode:
+ migrate_cmd += add_copy_storage(copy_storage_mode)
+
+ change_protection = params.get("change_protection")
+ if change_protection == "yes":
+ migrate_cmd += add_change_protection()
+
+ verbose = params.get("verbose")
+ if verbose == "yes":
+ migrate_cmd += add_verbose()
+
+ # --domain and --desturi must be specified.
+ domain_name = params.get("main_vm")
+ if domain_name:
+ migrate_cmd += add_domain(domain_name)
+
+ desturi = params.get("desturi")
+ if desturi:
+ migrate_cmd += add_desturi(desturi)
+
+ migrateuri = params.get("migrateuri")
+ if migrateuri:
+ migrate_cmd += add_migrateuri(migrateuri)
+
+ dname = params.get("dname")
+ if dname:
+ migrate_cmd += add_dname(dname)
+
+ timeout = params.get("timeout")
+ if timeout:
+ migrate_cmd += add_timeout(timeout)
+
+ xml_file = params.get("xml_file")
+ if xml_file:
+ migrate_cmd += add_xml(xml_file)
+
+ logging.info("Migrate command: %s" % migrate_cmd)
+ return migrate_cmd
+
+ def migrate(self, name=None):
+ """
+ Migrate a VM to a remote host.
+ """
+ migrate_cmd = ""
+
+ migrate_cmd = self.__make_migrate_command(name, self.params)
+
+ ret = virsh_migrate(self.name, migrate_cmd, self.params, self.connect_uri)
+ if ret == True:
+ return True
+ else:
+ return False
def destroy(self, gracefully=True, free_mac_addresses=True):
"""
--
1.7.3.1
--
Best Regards,
Tang chen
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/3] Add migration function and test for libvirt.
2012-01-17 3:21 [PATCH 0/3] Add migration function and test for libvirt tangchen
2012-01-17 3:24 ` [Autotest] [PATCH 1/3] " tangchen
@ 2012-01-17 3:24 ` tangchen
2012-01-17 3:25 ` [PATCH 3/3] " tangchen
2 siblings, 0 replies; 4+ messages in thread
From: tangchen @ 2012-01-17 3:24 UTC (permalink / raw)
To: Lucas Meneghel Rodrigues, autotest, kvm
This patch tests the "virsh migrate" command with --live parameter.
Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com>
---
client/tests/libvirt/tests/virsh_migrate.py | 33 +++++++++++++++++++++++++++
1 files changed, 33 insertions(+), 0 deletions(-)
create mode 100644 client/tests/libvirt/tests/virsh_migrate.py
diff --git a/client/tests/libvirt/tests/virsh_migrate.py b/client/tests/libvirt/tests/virsh_migrate.py
new file mode 100644
index 0000000..5576e78
--- /dev/null
+++ b/client/tests/libvirt/tests/virsh_migrate.py
@@ -0,0 +1,33 @@
+import re, os, logging, commands, shutil
+from autotest_lib.client.common_lib import utils, error
+from autotest_lib.client.virt import virt_vm, virt_utils, virt_env_process
+
+def run_virsh_migrate(test, params, env):
+ """
+ Test the migrate command with parameter --live.
+ """
+
+ vm_name = params.get("main_vm")
+ vm = env.get_vm(params["main_vm"])
+ vm.verify_alive()
+
+ destuser = params.get("destuser")
+ destpwd = params.get("destpwd")
+ destip = params.get("destip")
+ destprompt = params.get("destprompt")
+
+ # Migrate the guest.
+ ret = vm.migrate()
+ if ret == False:
+ raise error.TestFail("Migration of %s failed." % vm_name)
+
+ session = virt_utils.remote_login("ssh", destip, "22", destuser, destpwd, destprompt)
+ status, output = session.cmd_status_output("virsh domstate %s" % vm_name)
+ logging.info("Out put of virsh domstate %s: %s" % (vm_name, output))
+
+ if status == 0 and output.find("running") >= 0:
+ logging.info("Running guest %s is found on destination." % vm_name)
+ session.cmd("virsh destroy %s" % vm_name)
+ else:
+ raise error.TestFail("Destination has no running guest named %s." % vm_name)
+
--
1.7.3.1
--
Best Regards,
Tang chen
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 3/3] Add migration function and test for libvirt.
2012-01-17 3:21 [PATCH 0/3] Add migration function and test for libvirt tangchen
2012-01-17 3:24 ` [Autotest] [PATCH 1/3] " tangchen
2012-01-17 3:24 ` [PATCH 0/3] " tangchen
@ 2012-01-17 3:25 ` tangchen
2 siblings, 0 replies; 4+ messages in thread
From: tangchen @ 2012-01-17 3:25 UTC (permalink / raw)
To: Lucas Meneghel Rodrigues, autotest, kvm
This adds configuration for "virsh migrate" test.
Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com>
---
client/virt/subtests.cfg.sample | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/client/virt/subtests.cfg.sample b/client/virt/subtests.cfg.sample
index 843de30..97e62e9 100644
--- a/client/virt/subtests.cfg.sample
+++ b/client/virt/subtests.cfg.sample
@@ -323,6 +323,19 @@ variants:
create_image_stg = yes
image_size_stg = 10M
+ - virsh_migrate: install setup image_copy unattended_install.cdrom
+ type = virsh_migrate
+ live = yes
+ verbose = yes
+ desturi = qemu+ssh://Destination Host IP/system
+ destuser = Destination Host Username
+ destpwd = Destination Host Password
+ destip = Destination Host IP
+ destprompt = "#"
+ timeout = 30
+ variants:
+ - live:
+
- migrate: install setup image_copy unattended_install.cdrom
type = migration
migration_test_command = help
--
1.7.3.1
--
Best Regards,
Tang chen
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-01-17 4:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-17 3:21 [PATCH 0/3] Add migration function and test for libvirt tangchen
2012-01-17 3:24 ` [Autotest] [PATCH 1/3] " tangchen
2012-01-17 3:24 ` [PATCH 0/3] " tangchen
2012-01-17 3:25 ` [PATCH 3/3] " tangchen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).