From 6862edbe757b367ad0eeb95cad678825ea719673 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 16 Dec 2014 16:06:50 +0000 Subject: pxeboot.check: Fail with a nice error if PXEBOOT_MODE is needed and not set This is needed because now pxeboot.check doesn't fail if the options specified in the environment match more than one mode. --- pxeboot.check | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pxeboot.check b/pxeboot.check index df1fcc0e..fabe8138 100755 --- a/pxeboot.check +++ b/pxeboot.check @@ -61,8 +61,15 @@ elif len(complete_matches) > 1: if 'PXEBOOT_MODE' in os.environ: mode = os.environ['PXEBOOT_MODE'] else: - mode, = (mode for (mode, opt_set) in valid_option_sets - if all(o in os.environ for o in opt_set)) + try: + mode, = (mode for (mode, opt_set) in valid_option_sets + if all(o in os.environ for o in opt_set)) + + except ValueError as e: + print ('More than one candidate for PXEBOOT_MODE, please ' + 'set a value for it. Type `morph help pxeboot.write for ' + 'more info') + sys.exit(1) if mode not in valid_modes: print('%s is not a valid PXEBOOT_MODE' % mode) -- cgit v1.2.1