Fix xm commands so that the Traceback does not occur
PATCH 1/1 Fix xm commands so that the Traceback does not occur
Hi,
When we tested xm commands, the xm commands occurred the Traceback. The following are the examples.
# xm sched-sedf domUtemp -s xx Unexpected error: exceptions.ValueError
Please report to [email protected]
Traceback (most recent call last):
File "/usr/sbin/xm", line 10, in ?
main.main(sys.argv)
File "//usr/lib/python/xen/xm/main.py", line 1169, in main
rc = cmd(args)
File "//usr/lib/python/xen/xm/main.py", line 701, in xm_sched_sedf
opts['slice'] = ms_to_ns(v)
File "//usr/lib/python/xen/xm/main.py", line 665, in ms_to_ns
return (float(val) / 0.000001)ValueError: invalid literal for float(): xx
# xm vcpu-pin domUtemp x 1 Unexpected error: exceptions.ValueError
Please report to [email protected] Traceback (most recent call last):
File "/usr/sbin/xm", line 10, in ?
main.main(sys.argv)
File "//usr/lib/python/xen/xm/main.py", line 1173, in main
rc = cmd(args)
File "//usr/lib/python/xen/xm/main.py", line 600, in xm_vcpu_pin
vcpu = int(args[1])
ValueError: invalid literal for int(): x
The cause of the Traceback are entering wrong xm commands. We suggest this patch so that the Traceback does not occur.
Best regards,
Kan
tools/python/xen/xm/main.py +71 -28
@@ -597,8 +597,16 @@ def xm_vcpu_pin(args): arg_check(args, "vcpu-pin", 3) dom = args[0] - vcpu = int(args[1]) - cpumap = cpu_make_map(args[2]) + try: + vcpu = int(args[1]) + except (ValueError, OverflowError): + err('Invalid argument: %s' % args[1]) + sys.exit(1) + try: + cpumap = cpu_make_map(args[2]) + except (ValueError, OverflowError): + err('Invalid argument: %s' % args[2]) + sys.exit(1) server.xend.domain.pincpu(dom, vcpu, cpumap)
@@ -606,7 +614,11 @@ def xm_mem_max(args): arg_check(args, "mem-max", 2) dom = args[0] - mem = int_unit(args[1], 'm') + try: + mem = int_unit(args[1], 'm') + except (ValueError, OverflowError): + err('Invalid argument: %s' % args[1]) + sys.exit(1) server.xend.domain.maxmem_set(dom, mem)
@@ -614,15 +626,25 @@ def xm_mem_set(args): arg_check(args, "mem-set", 2) dom = args[0] - mem_target = int_unit(args[1], 'm') + try: + mem_target = int_unit(args[1], 'm') + except (ValueError, OverflowError): + err('Invalid argument: %s' % args[1]) + sys.exit(1) server.xend.domain.setMemoryTarget(dom, mem_target) def xm_vcpu_set(args): arg_check(args, "vcpu-set", 2) - - server.xend.domain.setVCpuCount(args[0], int(args[1])) - + + dom = args[0] + try: + vcpus = int(args[1]) + except (ValueError, OverflowError): + err('Invalid argument: %s' % args[1]) + sys.exit(1) + + server.xend.domain.setVCpuCount(dom, vcpus) def xm_destroy(args): arg_check(args, "destroy", 1)
@@ -647,14 +669,27 @@ def xm_domname(args): def xm_sched_bvt(args): arg_check(args, "sched-bvt", 6) + + v = [] dom = args[0] - v = map(long, args[1:6]) + for o in range(1, 6): + try: + v.append(long(args[o])) + except (ValueError, OverflowError): + err('Invalid argument: %s' % args[o]) + sys.exit(1) + server.xend.domain.cpu_bvt_set(dom, *v) def xm_sched_bvt_ctxallow(args): arg_check(args, "sched-bvt-ctxallow", 1) - slice = int(args[0]) + try: + slice = int(args[0]) + except (ValueError, OverflowError): + err('Invalid argument: %s' % args[0]) + sys.exit(1) + server.xend.node.cpu_bvt_slice_set(slice) def xm_sched_sedf(args):
@@ -695,16 +730,20 @@ def xm_sched_sedf(args): # convert to nanoseconds if needed for (k, v) in options: - if k in ['-p', '--period']: - opts['period'] = ms_to_ns(v) - elif k in ['-s', '--slice']: - opts['slice'] = ms_to_ns(v) - elif k in ['-l', '--latency']: - opts['latency'] = ms_to_ns(v) - elif k in ['-e', '--extratime']: - opts['extratime'] = v - elif k in ['-w', '--weight']: - opts['weight'] = v + try: + if k in ['-p', '--period']: + opts['period'] = ms_to_ns(v) + elif k in ['-s', '--slice']: + opts['slice'] = ms_to_ns(v) + elif k in ['-l', '--latency']: + opts['latency'] = ms_to_ns(v) + elif k in ['-e', '--extratime']: + opts['extratime'] = int(v) + elif k in ['-w', '--weight']: + opts['weight'] = int(v) + except (ValueError, OverflowError): + err('invalid %s value: %s' % (k, str(v))) + sys.exit(1) # print header if we aren't setting any parameters if len(opts.keys()) == 0:
@@ -756,12 +795,16 @@ def xm_sched_credit(args): cap = None for o, a in opts: - if o == "-d": - domain = a - elif o == "-w": - weight = int(a) - elif o == "-c": - cap = int(a); + try: + if o == "-d": + domain = a + elif o == "-w": + weight = int(a) + elif o == "-c": + cap = int(a) + except (ValueError, OverflowError): + err('invalid %s value: %s' % (o, str(a))) + sys.exit(1) if domain is None: # place holder for system-wide scheduler parameters
@@ -776,9 +819,9 @@ def xm_sched_credit(args): if cap is None: cap = int(~0) - err = server.xend.domain.sched_credit_set(domain, weight, cap) - if err != 0: - print err + error = server.xend.domain.sched_credit_set(domain, weight, cap) + if error != 0: + print error def xm_info(args): arg_check(args, "info", 0)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
On Wed, Jun 14, 2006 at 11:42:49AM +0900, Masaki Kanno wrote:
Content-Description: Mail message body
Quoted 45 lines
Hi,
When we tested xm commands, the xm commands occurred the Traceback. The following are the examples.
# xm sched-sedf domUtemp -s xx Unexpected error: exceptions.ValueErrorPlease report to [email protected]
Traceback (most recent call last):
File "/usr/sbin/xm", line 10, in ?
main.main(sys.argv)
File "//usr/lib/python/xen/xm/main.py", line 1169, in main
rc = cmd(args)
File "//usr/lib/python/xen/xm/main.py", line 701, inxm_sched_sedfopts['slice'] = ms_to_ns(v) File "//usr/lib/python/xen/xm/main.py", line 665, in ms_to_ns return (float(val) / 0.000001)ValueError: invalid literal for
float(): xx[Snip]
The cause of the Traceback are entering wrong xm commands. We suggest this patch so that the Traceback does not occur.
Signed-off-by Hiroyuki Yamamoto <[email protected]>Signed-off-by Masaki Kanno <[email protected]>Best regards,
Kandiff -r
aa2298739112tools/python/xen/xm/main.pytools/python/xen/xm/main.py +4
-2@@ -597,8 +597,16 @@ def xm_vcpu_pin(args): arg_check(args, "vcpu-pin", 3) dom = args[0] - vcpu = int(args[1]) - cpumap = cpu_make_map(args[2]) + try: + vcpu = int(args[1]) + except (ValueError, OverflowError): + err('Invalid argument: %s' % args[1])
tools/python/xen/xm/main.py def xm_vcpu_pin(args): · line 612
Quoted 10 lines
tools/python/xen/xm/main.py +6
-0+ sys.exit(1) + try: + cpumap = cpu_make_map(args[2]) + except (ValueError, OverflowError): + err('Invalid argument: %s' % args[2]) + sys.exit(1) server.xend.domain.pincpu(dom, vcpu, cpumap)
It would be a lot nicer if you let the exceptions propagate, and then caught them in the main exception handler at the bottom of main.py. It would also be better if you printed out the usage of the command to tell the user what error they made.
Thanks,
Ewan.
Hi Ewan,
Thanks for your comment.
We will correct and resend our patch.
Best regards,
Kan
Quoted 69 lines · Masaki Kanno
Content-Description: Mail message body
Quoted 45 lines
Hi,
When we tested xm commands, the xm commands occurred the Traceback. The following are the examples.
# xm sched-sedf domUtemp -s xx Unexpected error: exceptions.ValueErrorPlease report to [email protected]
Traceback (most recent call last):
File "/usr/sbin/xm", line 10, in ?
main.main(sys.argv)
File "//usr/lib/python/xen/xm/main.py", line 1169, in main
rc = cmd(args)
File "//usr/lib/python/xen/xm/main.py", line 701, inxm_sched_sedfopts['slice'] = ms_to_ns(v) File "//usr/lib/python/xen/xm/main.py", line 665, in ms_to_ns return (float(val) / 0.000001)ValueError: invalid literal for
float(): xx[Snip]
The cause of the Traceback are entering wrong xm commands. We suggest this patch so that the Traceback does not occur.
Signed-off-by Hiroyuki Yamamoto <[email protected]>Signed-off-by Masaki Kanno <[email protected]>Best regards,
Kandiff -r
aa2298739112tools/python/xen/xm/main.pytools/python/xen/xm/main.py +4
-2@@ -597,8 +597,16 @@ def xm_vcpu_pin(args): arg_check(args, "vcpu-pin", 3) dom = args[0] - vcpu = int(args[1]) - cpumap = cpu_make_map(args[2]) + try: + vcpu = int(args[1]) + except (ValueError, OverflowError): + err('Invalid argument: %s' % args[1])tools/python/xen/xm/main.py def xm_vcpu_pin(args): · line 612
Quoted 10 lines
tools/python/xen/xm/main.py +6
-0+ sys.exit(1) + try: + cpumap = cpu_make_map(args[2]) + except (ValueError, OverflowError): + err('Invalid argument: %s' % args[2]) + sys.exit(1) server.xend.domain.pincpu(dom, vcpu, cpumap)It would be a lot nicer if you let the exceptions propagate, and then caught them in the main exception handler at the bottom of
main.py. It would also be
better if you printed out the usage of the command to tell the user what error
they made.Thanks,
Ewan.
PATCH RESEND 1/1 Fix xm commands so that the Traceback does not occur
In reply to Ewan MellorHi,
We reflected comment to our patch. Our patch has become very small. :-)
Best regards,
Kan
Quoted 66 lines · Masaki Kanno
Content-Description: Mail message body
Quoted 45 lines
Hi,
When we tested xm commands, the xm commands occurred the Traceback. The following are the examples.
# xm sched-sedf domUtemp -s xx Unexpected error: exceptions.ValueErrorPlease report to [email protected]
Traceback (most recent call last):
File "/usr/sbin/xm", line 10, in ?
main.main(sys.argv)
File "//usr/lib/python/xen/xm/main.py", line 1169, in main
rc = cmd(args)
File "//usr/lib/python/xen/xm/main.py", line 701, inxm_sched_sedfopts['slice'] = ms_to_ns(v) File "//usr/lib/python/xen/xm/main.py", line 665, in ms_to_ns return (float(val) / 0.000001)ValueError: invalid literal for
float(): xx[Snip]
The cause of the Traceback are entering wrong xm commands. We suggest this patch so that the Traceback does not occur.
Signed-off-by Hiroyuki Yamamoto <[email protected]>Signed-off-by Masaki Kanno <[email protected]>Best regards,
Kandiff -r
aa2298739112tools/python/xen/xm/main.pytools/python/xen/xm/main.py +4
-2@@ -597,8 +597,16 @@ def xm_vcpu_pin(args): arg_check(args, "vcpu-pin", 3) dom = args[0] - vcpu = int(args[1]) - cpumap = cpu_make_map(args[2]) + try: + vcpu = int(args[1]) + except (ValueError, OverflowError): + err('Invalid argument: %s' % args[1])tools/python/xen/xm/main.py def xm_vcpu_pin(args): · line 612
Quoted 10 lines
tools/python/xen/xm/main.py +6
-0+ sys.exit(1) + try: + cpumap = cpu_make_map(args[2]) + except (ValueError, OverflowError): + err('Invalid argument: %s' % args[2]) + sys.exit(1) server.xend.domain.pincpu(dom, vcpu, cpumap)It would be a lot nicer if you let the exceptions propagate, and then caught them in the main exception handler at the bottom of
main.py. It would also be
better if you printed out the usage of the command to tell the user what error
they made.
Quoted 3 lines
Thanks,
Ewan.
tools/python/xen/xm/main.py +3 -0
@@ -1193,6 +1193,9 @@ def main(argv=sys.argv): else: print >>sys.stderr, "Error: %s" % ex.faultString sys.exit(1) + except (ValueError, OverflowError): + err("Invalid argument.") + usage(argv[1]) except: print "Unexpected error:", sys.exc_info()[0] print
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Ewan Mellor
AppliedOn Thu, Jun 15, 2006 at 07:41:39PM +0900, Masaki Kanno wrote:
Content-Description: Mail message body
Quoted 7 lines
Hi,
We reflected comment to our patch. Our patch has become very small. :-)
Signed-off-by Hiroyuki Yamamoto <[email protected]>Signed-off-by Masaki Kanno <[email protected]>
That's a lot better ;-)
Applied, thank you.
Ewan.