[Spice-commits] 8 commits - tests/migrate.py
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Mar 4 16:10:04 UTC 2020
tests/migrate.py | 126 ++++++++++++++++++++++++++++++++++---------------------
1 file changed, 78 insertions(+), 48 deletions(-)
New commits:
commit 84f257e26387dc723e0f47304c894b3490c04ef3
Author: Victor Toso <me at victortoso.com>
Date: Fri Oct 4 16:40:47 2019 +0200
migrate.py: add seamless migration option
Now we always add seamless-migration option to qemu command line and
disabled (off) by default although seamless migration is supported for
over 7 years already!
Signed-off-by: Victor Toso <victortoso at redhat.com>
Acked-by: Kevin Pouget <kpouget at redhat.com>
diff --git a/tests/migrate.py b/tests/migrate.py
index 7df04f2c..97fb5552 100755
--- a/tests/migrate.py
+++ b/tests/migrate.py
@@ -76,6 +76,8 @@ def get_args():
help="Wait spice client to connect to move to next step of migration (default False)")
parser.add_argument('--count', dest='counter', type=int, default=100,
help="Number of migrations to run (set 0 for infinite)")
+ parser.add_argument('--seamless', dest="seamless_migration", action='store_true', default=False,
+ help="Enable seamless-migration support")
args = parser.parse_args(sys.argv[1:])
if os.path.exists(args.qemu):
args.qemu_exec = args.qemu
@@ -86,11 +88,12 @@ def get_args():
sys.exit(1)
return args
-def start_qemu(qemu_exec, image, spice_port, qmp_filename, incoming_port=None, with_agent=False):
+def start_qemu(qemu_exec, seamless_migration, image, spice_port, qmp_filename, incoming_port=None, with_agent=False):
+ seamless_option = "on" if seamless_migration else "off"
args = [
qemu_exec,
"-qmp", f"unix:{qmp_filename},server,nowait",
- "-spice", f"disable-ticketing,port={spice_port}"
+ "-spice", f"seamless-migration={seamless_option},disable-ticketing,port={spice_port}"
]
if incoming_port:
args += (f"-incoming tcp::{incoming_port}").split()
@@ -164,7 +167,7 @@ class Migrator(object):
migration_count = 0
def __init__(self, log, client, qemu_exec, image, monitor_files,
- spice_ports, migration_port, vdagent, hostname):
+ spice_ports, migration_port, vdagent, hostname, seamless_migration):
self.client = client if client != "none" else None
self.log = log
self.qemu_exec = qemu_exec
@@ -174,16 +177,19 @@ class Migrator(object):
self.spice_ports = spice_ports
self.vdagent = vdagent
self.hostname = hostname
+ self.seamless_migration = seamless_migration
self.active = start_qemu(qemu_exec=qemu_exec,
image=image,
spice_port=spice_ports[0],
qmp_filename=monitor_files[0],
+ seamless_migration=self.seamless_migration,
with_agent=self.vdagent)
self.target = start_qemu(qemu_exec=qemu_exec,
image=image,
spice_port=spice_ports[1],
qmp_filename=monitor_files[1],
+ seamless_migration=self.seamless_migration,
with_agent=self.vdagent,
incoming_port=migration_port)
self.remove_monitor_files()
@@ -255,6 +261,7 @@ class Migrator(object):
qemu_exec=self.qemu_exec,
image=self.image,
qmp_filename=new_qmp_filename,
+ seamless_migration=self.seamless_migration,
with_agent=self.vdagent,
incoming_port=self.migration_port)
self.migration_count += 1
@@ -277,6 +284,7 @@ def main():
migration_port=args.migrate_port,
spice_ports=[args.spice_port1, args.spice_port2],
vdagent=args.vdagent,
+ seamless_migration=args.seamless_migration,
hostname=args.hostname)
atexit.register(cleanup, migrator)
atexit.register(remove_image_file, newimage)
commit 81d28cac55dc4007d8218c0d78fba1bd8d5e482d
Author: Victor Toso <me at victortoso.com>
Date: Fri Oct 4 16:56:15 2019 +0200
migrate.py: cosmetic changes
Make one argument per line;
Indent with arguments;
Signed-off-by: Victor Toso <victortoso at redhat.com>
Acked-by: Kevin Pouget <kpouget at redhat.com>
diff --git a/tests/migrate.py b/tests/migrate.py
index 5c4f8c3d..7df04f2c 100755
--- a/tests/migrate.py
+++ b/tests/migrate.py
@@ -175,10 +175,16 @@ class Migrator(object):
self.vdagent = vdagent
self.hostname = hostname
- self.active = start_qemu(qemu_exec=qemu_exec, image=image, spice_port=spice_ports[0],
- qmp_filename=monitor_files[0], with_agent=self.vdagent)
- self.target = start_qemu(qemu_exec=qemu_exec, image=image, spice_port=spice_ports[1],
- qmp_filename=monitor_files[1], with_agent=self.vdagent,
+ self.active = start_qemu(qemu_exec=qemu_exec,
+ image=image,
+ spice_port=spice_ports[0],
+ qmp_filename=monitor_files[0],
+ with_agent=self.vdagent)
+ self.target = start_qemu(qemu_exec=qemu_exec,
+ image=image,
+ spice_port=spice_ports[1],
+ qmp_filename=monitor_files[1],
+ with_agent=self.vdagent,
incoming_port=migration_port)
self.remove_monitor_files()
self.connected_client = None
@@ -246,10 +252,11 @@ class Migrator(object):
del dead
self.active = self.target
self.target = start_qemu(spice_port=new_spice_port,
- qemu_exec=self.qemu_exec, image=self.image,
- qmp_filename=new_qmp_filename,
- with_agent=self.vdagent,
- incoming_port=self.migration_port)
+ qemu_exec=self.qemu_exec,
+ image=self.image,
+ qmp_filename=new_qmp_filename,
+ with_agent=self.vdagent,
+ incoming_port=self.migration_port)
self.migration_count += 1
print(self.migration_count)
@@ -262,15 +269,21 @@ def main():
qemu_img = run_shell_command("dirname %s" % args.qemu_exec) + '/qemu-img'
run_shell_command('%s create -f qcow2 -b %s %s' % (qemu_img, args.image, newimage))
print('using new image %s' % newimage)
- migrator = Migrator(client=args.client, qemu_exec=args.qemu_exec,
- image=newimage, log=log, monitor_files=[args.qmp1, args.qmp2],
- migration_port=args.migrate_port, spice_ports=[args.spice_port1,
- args.spice_port2], vdagent=args.vdagent, hostname=args.hostname)
+ migrator = Migrator(client=args.client,
+ qemu_exec=args.qemu_exec,
+ image=newimage,
+ log=log,
+ monitor_files=[args.qmp1, args.qmp2],
+ migration_port=args.migrate_port,
+ spice_ports=[args.spice_port1, args.spice_port2],
+ vdagent=args.vdagent,
+ hostname=args.hostname)
atexit.register(cleanup, migrator)
atexit.register(remove_image_file, newimage)
counter = 0
while args.counter == 0 or counter < args.counter:
- migrator.iterate(args.wait_user_input, args.wait_user_connect)
+ migrator.iterate(wait_for_user_input=args.wait_user_input,
+ wait_user_connect=args.wait_user_connect)
counter += 1
if __name__ == '__main__':
commit 4882e01370832fcb4aa5d7d7eae2ec060320ba03
Author: Victor Toso <me at victortoso.com>
Date: Fri Oct 4 15:41:57 2019 +0200
migrate.py: add option for hostname change
This is used in the migrate message and being able to tweak it allows
clients from different machines to test this local migration test.
Example of usage:
./migrate.py --hostname 192.168.122.1 --wait-user-connect
In a VM with access to 192.168.122.1:
remote-viewer spice://192.168.122.1:5911
Signed-off-by: Victor Toso <victortoso at redhat.com>
Acked-by: Kevin Pouget <kpouget at redhat.com>
diff --git a/tests/migrate.py b/tests/migrate.py
index 39f61a38..5c4f8c3d 100755
--- a/tests/migrate.py
+++ b/tests/migrate.py
@@ -20,7 +20,7 @@ Will leave a log file, migrate_test.log, in current directory.
# and repeat:
# active wait until it's active
# active client_migrate_info
-# active migrate tcp:localhost:9000
+# active migrate tcp:$hostname:9000
# _wait for event of quit
# active stop, active<->passive
#
@@ -64,6 +64,8 @@ def get_args():
parser.add_argument('--qemu', dest='qemu', default='../../qemu/x86_64-softmmu/qemu-system-x86_64')
parser.add_argument('--log_filename', dest='log_filename', default='migrate.log')
parser.add_argument('--image', dest='image', default='')
+ parser.add_argument("--hostname", dest='hostname', default='localhost',
+ help="Set hostname used in migration message (default: localhost")
parser.add_argument('--client', dest='client', default='none', choices=['spicy', 'remote-viewer', 'none'],
help="Automatically lunch one of supported clients or none (default)")
parser.add_argument('--vdagent', dest="vdagent", action='store_true', default=False,
@@ -123,10 +125,10 @@ def start_qemu(qemu_exec, image, spice_port, qmp_filename, incoming_port=None, w
proc.incoming_port = incoming_port
return proc
-def start_client(client, spice_port):
- client_cmd = "spicy --uri spice://localhost:%s" % (spice_port)
+def start_client(client, hostname, spice_port):
+ client_cmd = f"spicy --uri spice://{hostname}:{spice_port}"
if client == "remote-viewer":
- client_cmd = "remote-viewer spice://localhost:%s" % (spice_port)
+ client_cmd = f"remote-viewer spice://{hostname}:{spice_port}"
return Popen(client_cmd.split(), executable=client)
@@ -162,7 +164,7 @@ class Migrator(object):
migration_count = 0
def __init__(self, log, client, qemu_exec, image, monitor_files,
- spice_ports, migration_port, vdagent):
+ spice_ports, migration_port, vdagent, hostname):
self.client = client if client != "none" else None
self.log = log
self.qemu_exec = qemu_exec
@@ -171,6 +173,7 @@ class Migrator(object):
self.monitor_files = monitor_files
self.spice_ports = spice_ports
self.vdagent = vdagent
+ self.hostname = hostname
self.active = start_qemu(qemu_exec=qemu_exec, image=image, spice_port=spice_ports[0],
qmp_filename=monitor_files[0], with_agent=self.vdagent)
@@ -200,7 +203,9 @@ class Migrator(object):
wait_active(self.target.qmp, False)
if not self.connected_client:
if self.client:
- self.connected_client = start_client(client=self.client, spice_port=self.spice_ports[0])
+ self.connected_client = start_client(client=self.client,
+ hostname=self.hostname,
+ spice_port=self.spice_ports[0])
if wait_for_user_input:
print("waiting for Enter to start migrations")
@@ -212,11 +217,12 @@ class Migrator(object):
self.active.qmp.cmd('client_migrate_info', {
'protocol' : 'spice',
- 'hostname' : 'localhost',
+ 'hostname' : self.hostname,
'port' : self.target.spice_port
})
self.active.qmp.cmd('migrate', {
- 'uri': f'tcp:localhost:self.migration_port'
+ 'uri': f'tcp:localhost:self.migration_port',
+ 'uri': f'tcp:{self.hostname}:{self.migration_port}'
})
wait_active(self.active.qmp, False)
wait_active(self.target.qmp, True)
@@ -259,7 +265,7 @@ def main():
migrator = Migrator(client=args.client, qemu_exec=args.qemu_exec,
image=newimage, log=log, monitor_files=[args.qmp1, args.qmp2],
migration_port=args.migrate_port, spice_ports=[args.spice_port1,
- args.spice_port2], vdagent=args.vdagent)
+ args.spice_port2], vdagent=args.vdagent, hostname=args.hostname)
atexit.register(cleanup, migrator)
atexit.register(remove_image_file, newimage)
counter = 0
commit 49e3e7a6d4003df91293f0d97b67de9b21da5405
Author: Victor Toso <me at victortoso.com>
Date: Fri Oct 4 13:45:02 2019 +0200
migrate.py: style, break line of qmp's command
Preparatory patch for adding support to change hostname.
Signed-off-by: Victor Toso <victortoso at redhat.com>
Acked-by: Kevin Pouget <kpouget at redhat.com>
diff --git a/tests/migrate.py b/tests/migrate.py
index 509b7db8..39f61a38 100755
--- a/tests/migrate.py
+++ b/tests/migrate.py
@@ -210,9 +210,14 @@ class Migrator(object):
if self.connected_client or wait_user_connect:
wait_for_event(self.active.qmp, 'SPICE_INITIALIZED')
- self.active.qmp.cmd('client_migrate_info', {'protocol':'spice',
- 'hostname':'localhost', 'port':self.target.spice_port})
- self.active.qmp.cmd('migrate', {'uri': 'tcp:localhost:%s' % self.migration_port})
+ self.active.qmp.cmd('client_migrate_info', {
+ 'protocol' : 'spice',
+ 'hostname' : 'localhost',
+ 'port' : self.target.spice_port
+ })
+ self.active.qmp.cmd('migrate', {
+ 'uri': f'tcp:localhost:self.migration_port'
+ })
wait_active(self.active.qmp, False)
wait_active(self.target.qmp, True)
commit 632cfa1c3d4a015451fe88a0c7c74ec7450c3424
Author: Victor Toso <me at victortoso.com>
Date: Fri Oct 4 14:02:56 2019 +0200
migrate.py: cosmetic changes on start_qemu()
This function can be tweak quite a bit due all possibilities around
QEMU configuration. This patch removes incoming_args and extra_args
and move their values to the right place in the function.
I'm also applying a more extensive coding style for parameters, so
when we need to do changes it should happen with fewer lines.
While at it, change to string interpolation from 3.6+, suggested by
Kevin Pouget.
Signed-off-by: Victor Toso <victortoso at redhat.com>
Acked-by: Kevin Pouget <kpouget at redhat.com>
diff --git a/tests/migrate.py b/tests/migrate.py
index ef7d4f79..509b7db8 100755
--- a/tests/migrate.py
+++ b/tests/migrate.py
@@ -85,28 +85,30 @@ def get_args():
return args
def start_qemu(qemu_exec, image, spice_port, qmp_filename, incoming_port=None, with_agent=False):
- incoming_args = []
+ args = [
+ qemu_exec,
+ "-qmp", f"unix:{qmp_filename},server,nowait",
+ "-spice", f"disable-ticketing,port={spice_port}"
+ ]
if incoming_port:
- incoming_args = ("-incoming tcp::%s" % incoming_port).split()
+ args += (f"-incoming tcp::{incoming_port}").split()
- extra_args = []
if with_agent:
- extra_args = ['-device', 'virtio-serial',
- '-chardev', 'spicevmc,name=vdagent,id=vdagent',
- '-device', 'virtserialport,chardev=vdagent,name=com.redhat.spice.0']
+ args += [
+ '-device', 'virtio-serial',
+ '-chardev', 'spicevmc,name=vdagent,id=vdagent',
+ '-device', 'virtserialport,chardev=vdagent,name=com.redhat.spice.0'
+ ]
- args = ([qemu_exec, "-qmp", "unix:%s,server,nowait" % qmp_filename,
- "-spice", "disable-ticketing,port=%s" % spice_port]
- + incoming_args + extra_args)
if os.path.exists(image):
- args += ["-m", "512", "-enable-kvm", "-drive",
- "file=%s,index=0,media=disk,cache=writeback" % image]
-
- # print qemu command line for the first run
- if not incoming_port:
- print('qemu command line: %s' % ' '.join(args))
+ args += [
+ "-m", "512",
+ "-enable-kvm",
+ "-drive", f"file={image},index=0,media=disk,cache=writeback"
+ ]
proc = Popen(args, executable=qemu_exec, stdin=PIPE, stdout=PIPE)
+
while not os.path.exists(qmp_filename):
time.sleep(0.1)
proc.qmp_filename = qmp_filename
commit 57af035749fb9cddad001c27b530c4030249a056
Author: Victor Toso <me at victortoso.com>
Date: Mon Sep 30 11:22:37 2019 +0200
migrate.py: simplify wait_active()
We are only interested in the running state of qmp (or VCPUS) here
which is what we check. Moving this check to the try branch allows
removing some extra checks.
Signed-off-by: Victor Toso <victortoso at redhat.com>
Acked-by: Kevin Pouget <kpouget at redhat.com>
diff --git a/tests/migrate.py b/tests/migrate.py
index a1478ce9..ef7d4f79 100755
--- a/tests/migrate.py
+++ b/tests/migrate.py
@@ -129,20 +129,16 @@ def start_client(client, spice_port):
return Popen(client_cmd.split(), executable=client)
def wait_active(q, active):
- events = ["RESUME"] if active else ["STOP"]
while True:
try:
ret = q.cmd("query-status")
+ if ret["return"]["running"] == active:
+ break
except:
# ValueError
time.sleep(0.1)
continue
- if ret and "return" in ret.keys():
- if ret["return"]["running"] == active:
- break
- for e in q.get_events():
- if e["event"] in events:
- break
+
time.sleep(0.5)
def wait_for_event(q, event):
commit f75236bf423bc400bda8c4ad409c44b09bd080d4
Author: Victor Toso <me at victortoso.com>
Date: Fri Oct 4 14:12:18 2019 +0200
migrate.py: migrate count starts with 1
As this is not some index but a counter. The first print happens after
first migration was done, meaning 1 instead of 0
Signed-off-by: Victor Toso <victortoso at redhat.com>
Acked-by: Kevin Pouget <kpouget at redhat.com>
diff --git a/tests/migrate.py b/tests/migrate.py
index a172c060..a1478ce9 100755
--- a/tests/migrate.py
+++ b/tests/migrate.py
@@ -241,8 +241,8 @@ class Migrator(object):
qmp_filename=new_qmp_filename,
with_agent=self.vdagent,
incoming_port=self.migration_port)
- print(self.migration_count)
self.migration_count += 1
+ print(self.migration_count)
def main():
args = get_args()
commit b124ebe53e19a38c8eeb6ef5da442b23b5130e25
Author: Victor Toso <me at victortoso.com>
Date: Fri Oct 4 15:26:09 2019 +0200
migrate.py: fix events race
Currently, when we run migrate.py with --client option we get stuck
waiting for SPICE_CONNECTED event on target qmp (while receiving only
QMP). Problem is, only after event SPICE_INITIALIZED in the source qmp
is that the client will be able to do migration (to properly exchange
spice messages).
So, it is a must that if we have a test where a client is connected,
to wait for SPICE_INITIALIZED event in the source qmp.
To clarify, this patches fixes the following test:
./migrate.py --client spicy
Signed-off-by: Victor Toso <victortoso at redhat.com>
Acked-by: Kevin Pouget <kpouget at redhat.com>
diff --git a/tests/migrate.py b/tests/migrate.py
index a0739ba3..a172c060 100755
--- a/tests/migrate.py
+++ b/tests/migrate.py
@@ -209,7 +209,7 @@ class Migrator(object):
raw_input()
# Tester can launch its own client or we wait start_client() to connect
- if wait_user_connect:
+ if self.connected_client or wait_user_connect:
wait_for_event(self.active.qmp, 'SPICE_INITIALIZED')
self.active.qmp.cmd('client_migrate_info', {'protocol':'spice',
More information about the Spice-commits
mailing list