summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Levy <alevy@redhat.com>2011-11-05 14:09:57 +0200
committerAlon Levy <alevy@redhat.com>2011-11-05 14:09:57 +0200
commit6f204696e8c3543ca77d037b940f438942e6cce3 (patch)
treee2560609bcf495d27557229d543704df232757ff
parent92c879fea4cb09a8a3a15f88ee23f87e4b6cdaae (diff)
exceptions for starting conditions, --clients -1
which launches just the client
-rwxr-xr-xspice2111
1 files changed, 66 insertions, 45 deletions
diff --git a/spice2 b/spice2
index 99402c1..7e1b661 100755
--- a/spice2
+++ b/spice2
@@ -307,10 +307,10 @@ def get_image(args):
image_base_fullpath = args.image
if not os.path.exists(image_base_fullpath):
print("missing image %s" % image_base_fullpath)
- sys.exit(1)
+ return None
if not args.second and file_in_use(image_base_fullpath):
print("image in use and --second not in arguments")
- sys.exit(1)
+ return None
if args.backing_file:
base_image_name = os.path.basename(args.image)
image_fullpath = create_qcow_with_backing_file(
@@ -372,20 +372,24 @@ def build_spice_option(args):
ret.append('image-compression=%s' % args.image_compression)
return ['-spice', ','.join(ret)]
-def exit_unless_exists(msg, filename):
+class MissingFileException(Exception):
+ pass
+
+def raise_unless_exists(msg, filename):
if not os.path.exists(filename):
- print(msg % filename)
- sys.exit(1)
+ raise MissingFileException(msg % filename)
return filename
+class NoRootDirException(Exception):
+ pass
+
def get_root_dir(args):
- exit_unless_exists("root-dir %r is missing", args.root_dir)
+ raise_unless_exists("root-dir %r is missing", args.root_dir)
if not args.root:
- print("root is None")
- sys.exit(1)
+ raise NoRootDirException()
install_root = roots[args.root]
root = os.path.join(args.root_dir, install_root)
- exit_unless_exists("missing %r", root)
+ raise_unless_exists("missing %r", root)
return root
def get_bios_dir(args):
@@ -413,7 +417,7 @@ def get_qemu_exec(args):
qemu_exec_name is hardcoded to qemu-system-x86_64
"""
if args.qemu_exec:
- exit_unless_exists("--qemu-exec doesn't exist: %r",
+ raise_unless_exists("--qemu-exec doesn't exist: %r",
args.qemu_exec)
qemu_exec = args.qemu_exec
else:
@@ -423,7 +427,7 @@ def get_qemu_exec(args):
bindir = os.path.join(root, 'bin')
os.environ['PATH'] = bindir + ':' + os.environ['PATH']
qemu_exec = os.path.join(bindir, qemu_exec_name)
- return exit_unless_exists("missing qemu-exec %r", qemu_exec)
+ return raise_unless_exists("missing qemu-exec %r", qemu_exec)
def bridge_participants(brname):
interfaces = []
@@ -459,10 +463,17 @@ def build_qemu_cmdline_and_env(args):
the config file, .spice_launcher).
"""
environment = []
+ qemu_exec = 'no-qemu-exec-defined'
+ bios_dir = 'no-bios-dir-defined'
if args.test_prog:
return build_test_cmdline_and_env(args)
- bios_dir = get_bios_dir(args)
- qemu_exec = get_qemu_exec(args)
+ try:
+ bios_dir = get_bios_dir(args)
+ qemu_exec = get_qemu_exec(args)
+ except (NoRootDirException, MissingFileException), e:
+ if args.clients >= 0:
+ print "no root dir - %s" % str(e)
+ sys.exit(1)
args.image_fullpath = image_fullpath = get_image(args)
if args.record_cmd:
print("recording cmd ring to %r" % args.record_cmd)
@@ -484,7 +495,7 @@ def build_qemu_cmdline_and_env(args):
addr = 'path=%s' % args.qmp_path
args.qmp_port = 0
else:
- addr = 'host=localhost,port=%s' % args.qmp_port
+ addr = 'host=127.0.0.1,port=%s' % args.qmp_port
cmdline.extend(["-chardev",
"socket,id=qmpmon,%s,server,nowait,ipv4" % addr,
"-mon", "chardev=qmpmon,mode=control"])
@@ -536,14 +547,14 @@ def build_qemu_cmdline_and_env(args):
cmdline.extend(['-chardev', 'spicevmc,name=vdagent,id=vdagent',
'-device', 'virtserialport,chardev=vdagent,name=com.redhat.spice.0'])
if False and args.kdvirtserial:
- cmdline.extend(['-chardev', 'socket,host=localhost,port=12000,id=kd',
+ cmdline.extend(['-chardev', 'socket,host=127.0.0.1,port=12000,id=kd',
'-device', 'virtserialport,chardev=kd,name=qemu.kd'])
if args.ehci:
cmdline.extend(['-readconfig', '/home/alon/src/spice_rhel6/qemu-kvm-rhel6/docs/ich9-ehci-uhci.cfg'])
if args.kd or args.kdlisten:
# TODO - connect to a kd running on host (wine) or on vm2 (like
# --windbg-server and --windbg-client)
- socket_param = 'socket,id=kd,host=localhost,port=%s' % (
+ socket_param = 'socket,id=kd,host=127.0.0.1,port=%s' % (
args.kd or args.kdlisten)
if args.kdlisten:
socket_param += ',server'
@@ -585,7 +596,7 @@ def build_qemu_cmdline_and_env(args):
cmdline.extend(('-serial tcp::%d,server,nowait' % args.windbg_server).split())
if args.windbg_client:
if port_is_available(args.windbg_client):
- cmdline.extend(('-serial tcp:localhost:%d' % args.windbg_client).split())
+ cmdline.extend(('-serial tcp:127.0.0.1:%d' % args.windbg_client).split())
else:
print("nothing listening on %d, do you want to start something there? (p.s. maybe systemd service?)" % args.windbg_client)
# smartcard
@@ -601,7 +612,7 @@ def build_qemu_cmdline_and_env(args):
cmdline.extend('-device isa-debugcon,iobase=0x402,chardev=muxstdio'.split())
# incoming migration
if args.incoming:
- cmdline.extend(('-incoming tcp:localhost:%d' % args.incoming).split())
+ cmdline.extend(('-incoming tcp:127.0.0.1:%d' % args.incoming).split())
if args.freeze:
cmdline.extend(['-S'])
# vnc server
@@ -743,7 +754,7 @@ def port_is_available_evil_opens_port(port):
s = socket.socket(socket.AF_INET)
ret = False
try:
- s.connect(('localhost', port))
+ s.connect(('127.0.0.1', port))
s.close()
ret = True
except:
@@ -753,11 +764,12 @@ def port_is_available_evil_opens_port(port):
def wait_for_port(port):
if not port:
return
+ print "waiting for port %d to be available" % port
# TODO: do this without actually opening the port - maybe just look at /proc/qemu_process_id/fd?
s = socket.socket(socket.AF_INET)
while True:
try:
- s.connect(('localhost', port))
+ s.connect(('127.0.0.1', port))
s.close()
break
except:
@@ -822,7 +834,7 @@ def parseargs():
disk_group.add_argument('--copy-in', action='append')
disk_group.add_argument('--no-backing-file', default=True, action='store_false', dest='backing_file', help='use the image as a backing file for the actual image')
disk_group.add_argument('--startup')
- disk_group.add_argument('--cache', choices=['unsafe','off','writeback','writethrough'], default='unsafe')
+ disk_group.add_argument('--cache', choices=['unsafe','off','writeback','writethrough'], default='unsafe') # second best performance is writeback
disk_group.add_argument('--runonce')
disk_group.add_argument('--clear-runonce', default=False, action='store_true')
client_group.add_argument('--client', default='spicec')
@@ -925,7 +937,7 @@ def parseargs():
tests_group.add_argument('--replay-file', dest='replay_file')
tests_group.add_argument('--print-events', action='store_true', default=False)
tests_group.add_argument('--reset-on-shutdown', action='store_true', default=False)
- tests_group.add_argument('--qmp-port', default=default_qmp_port)
+ tests_group.add_argument('--qmp-port', default=default_qmp_port, type=int)
tests_group.add_argument('--qmp-path', default=None)
# extract extra parameters, those after "--", from default_args
# the same is done for sys.argv[1:] by parse_known_args
@@ -1111,6 +1123,24 @@ def exit_on_hup():
old = signal.signal(signal.SIGHUP, on_exit)
print("SIGHUP old:", old)
+def launch_clients(args, display, clients, num_clients):
+ print("starting clients")
+ cur_display = display.next()
+ run_xephyr(display=cur_display, debug=(args.xephyr=='debug'))
+ wait_for_port(args.spice_port)
+ wait_for_port(args.tls_port)
+ for i in xrange(num_clients):
+ client_process = run_client(
+ host=args.spice_host, port=args.spice_port,
+ client=args.client, smartcard=args.smartcard,
+ certs=args.certs, dbdir=args.dbdir,
+ display=cur_display,
+ tls_port=args.tls_port,
+ ca_file=args.ca_cert,
+ host_subject=args.host_subject)
+ clients.append(client_process)
+
+
################################################################################
clients = []
vnc_clients = []
@@ -1177,28 +1207,33 @@ def main():
print("dropping super user privileges")
os.setuid(args.uid)
os.setgid(args.gid)
- test_process = start_process(args=cmdline, show_output=True)
+ if args.xephyr:
+ display = xephyr_get_display()
+ else:
+ display = default_get_display()
+ if args.clients >= 0:
+ test_process = start_process(args=cmdline, show_output=True)
+ else:
+ # hack to just launch a client without yet another command line argument.
+ launch_clients(args, display, clients, -args.clients)
+ sys.exit(0)
# some qmp using apps require some forking
qmp_handlers = []
if args.qmp_port:
wait_for_port(args.qmp_port)
- qmp_address = ('localhost', args.qmp_port)
+ qmp_address = ('127.0.0.1', args.qmp_port)
if args.print_events:
qmp_handlers.append(qmp_helpers.print_events())
if args.reset_on_shutdown:
qmp_handlers.append(qmp_helpers.reset_on_shutdown())
if len(qmp_handlers) > 0:
qmp_helpers.fork_and_handle(qmp_address, qmp_handlers)
- if args.xephyr:
- display = xephyr_get_display()
- else:
- display = default_get_display()
if args.spicedump:
print("running spicedump")
real_spice_port = args.spice_port
args.spice_port = proxy_port = real_spice_port + 1000
# run a spicedump proxy in the middle
- start_process(args=('%s %s -p -l %s -r localhost:%s%s' %
+ start_process(args=('%s %s -p -l %s -r 127.0.0.1:%s%s' %
(python_exe, spicedump_exe, proxy_port, real_spice_port,
' -f %s' % args.spicedump_filter if args.spicedump_filter else ''
)).split())
@@ -1210,7 +1245,7 @@ def main():
real_spice_port = args.spice_port
args.spice_port = proxy_port = real_spice_port + 1000
proxy_args = [bandwidthmon_exe, '--listen-port', str(proxy_port),
- '--remote-port', str(real_spice_port), '--remote-host', 'localhost']
+ '--remote-port', str(real_spice_port), '--remote-host', '127.0.0.1']
# TODO - go over the ports once, to avoid errors later
if args.vnc_port:
real_vnc_port = args.vnc_port
@@ -1223,21 +1258,7 @@ def main():
test_func(server=test_process, args=args)
else:
if args.clients > 0:
- print("starting clients")
- cur_display = display.next()
- run_xephyr(display=cur_display, debug=(args.xephyr=='debug'))
- wait_for_port(args.spice_port)
- wait_for_port(args.tls_port)
- for i in xrange(args.clients):
- client_process = run_client(
- host=args.spice_host, port=args.spice_port,
- client=args.client, smartcard=args.smartcard,
- certs=args.certs, dbdir=args.dbdir,
- display=cur_display,
- tls_port=args.tls_port,
- ca_file=args.ca_cert,
- host_subject=args.host_subject)
- clients.append(client_process)
+ launch_clients(args, display, clients, args.clients)
if args.vnc_port and args.vnc_clients > 0:
if not vncviewer:
print("vncviewer not in path - not starting")