# HG changeset patch
# User atse@xxxxxxxxxxxxxxxxxxxxxxxx
# Date 1159443969 -3600
# Node ID 3dea280880e2244c3628b9bcfb75e40825b49de7
# Parent 98c369711006c73ef9ff2891052c5d3db8a235fd
[XM] Report proper ACMError(s) instead of silently exiting.
Remove try except blocks so that ACMError(s) are properly reported to
the user rather than silently fail.
Signed-off-by: Alastair Tse <atse@xxxxxxxxxxxxx>
---
tools/python/xen/xm/addlabel.py | 72 +++++++++++++++++++-------------------
tools/python/xen/xm/dry-run.py | 41 ++++++++++-----------
tools/python/xen/xm/dumppolicy.py | 20 +++++-----
tools/python/xen/xm/rmlabel.py | 31 ++++++++--------
4 files changed, 83 insertions(+), 81 deletions(-)
diff -r 98c369711006 -r 3dea280880e2 tools/python/xen/xm/addlabel.py
--- a/tools/python/xen/xm/addlabel.py Thu Sep 28 12:29:52 2006 +0100
+++ b/tools/python/xen/xm/addlabel.py Thu Sep 28 12:46:09 2006 +0100
@@ -115,43 +115,45 @@ def add_domain_label(label, configfile,
config_fd.close()
-def main (argv):
+def main(argv):
+ policyref = None
+ if len(argv) not in (4, 5):
+ raise OptionError('Needs either 2 or 3 arguments')
+
+ label = argv[1]
+
+ if len(argv) == 5:
+ policyref = argv[4]
+ elif security.on():
+ policyref = security.active_policy
+ else:
+ raise OptionError("No active policy. Must specify policy on the "
+ "command line.")
+
+ if argv[2].lower() == "dom":
+ configfile = argv[3]
+ if configfile[0] != '/':
+ for prefix in [".", "/etc/xen"]:
+ configfile = prefix + "/" + configfile
+ if os.path.isfile(configfile):
+ break
+ if not validate_config_file(configfile):
+ raise OptionError('Invalid config file')
+ else:
+ add_domain_label(label, configfile, policyref)
+ elif argv[2].lower() == "res":
+ resource = argv[3]
+ add_resource_label(label, resource, policyref)
+ else:
+ raise OptionError('Need to specify either "dom" or "res" as '
+ 'object to add label to.')
+
+if __name__ == '__main__':
try:
- policyref = None
- if len(argv) not in (4, 5):
- raise OptionError('Needs either 2 or 3 arguments')
-
- label = argv[1]
-
- if len(argv) == 5:
- policyref = argv[4]
- elif security.on():
- policyref = security.active_policy
- else:
- security.err("No active policy. Policy must be specified in
command line.")
-
- if argv[2].lower() == "dom":
- configfile = argv[3]
- if configfile[0] != '/':
- for prefix in [".", "/etc/xen"]:
- configfile = prefix + "/" + configfile
- if os.path.isfile(configfile):
- break
- if not validate_config_file(configfile):
- raise OptionError('Invalid config file')
- else:
- add_domain_label(label, configfile, policyref)
- elif argv[2].lower() == "res":
- resource = argv[3]
- add_resource_label(label, resource, policyref)
- else:
- raise OptionError('Need to specify either "dom" or "res" as object
to add label to.')
-
- except security.ACMError:
+ main(sys.argv)
+ except Exception, e:
+ sys.stderr.write('Error: %s\n' % str(e))
sys.exit(-1)
-
-if __name__ == '__main__':
- main(sys.argv)
diff -r 98c369711006 -r 3dea280880e2 tools/python/xen/xm/dry-run.py
--- a/tools/python/xen/xm/dry-run.py Thu Sep 28 12:29:52 2006 +0100
+++ b/tools/python/xen/xm/dry-run.py Thu Sep 28 12:46:09 2006 +0100
@@ -32,27 +32,26 @@ def help():
individually along with the final security decision."""
def main (argv):
- try:
- if len(argv) != 2:
- raise OptionError('Invalid number of arguments')
-
- passed = 0
- (opts, config) = create.parseCommandLine(argv)
- if create.check_domain_label(config, verbose=1):
- if create.config_security_check(config, verbose=1):
- passed = 1
- else:
- print "Checking resources: (skipped)"
-
- if passed:
- print "Dry Run: PASSED"
- else:
- print "Dry Run: FAILED"
- sys.exit(-1)
-
- except security.ACMError:
+ if len(argv) != 2:
+ raise OptionError('Invalid number of arguments')
+
+ passed = 0
+ (opts, config) = create.parseCommandLine(argv)
+ if create.check_domain_label(config, verbose=1):
+ if create.config_security_check(config, verbose=1):
+ passed = 1
+ else:
+ print "Checking resources: (skipped)"
+
+ if passed:
+ print "Dry Run: PASSED"
+ else:
+ print "Dry Run: FAILED"
sys.exit(-1)
-
if __name__ == '__main__':
- main(sys.argv)
+ try:
+ main(sys.argv)
+ except Exception, e:
+ sys.stderr.write('Error: %s\n' % str(e))
+ sys.exit(-1)
diff -r 98c369711006 -r 3dea280880e2 tools/python/xen/xm/dumppolicy.py
--- a/tools/python/xen/xm/dumppolicy.py Thu Sep 28 12:29:52 2006 +0100
+++ b/tools/python/xen/xm/dumppolicy.py Thu Sep 28 12:46:09 2006 +0100
@@ -19,7 +19,7 @@
"""
import sys
from xen.util.security import ACMError, err, dump_policy
-
+from xen.xm.opts import OptionError
def help():
return """
@@ -27,16 +27,16 @@ def help():
(low-level)."""
def main(argv):
+ if len(argv) != 1:
+ raise OptionError("No arguments expected.")
+
+ dump_policy()
+
+if __name__ == '__main__':
try:
- if len(argv) != 1:
- usage()
-
- dump_policy()
- except ACMError:
+ main(sys.argv)
+ except Exception, e:
+ sys.stderr.write('Error: %s\n' % str(e))
sys.exit(-1)
-if __name__ == '__main__':
- main(sys.argv)
-
-
diff -r 98c369711006 -r 3dea280880e2 tools/python/xen/xm/rmlabel.py
--- a/tools/python/xen/xm/rmlabel.py Thu Sep 28 12:29:52 2006 +0100
+++ b/tools/python/xen/xm/rmlabel.py Thu Sep 28 12:46:09 2006 +0100
@@ -42,14 +42,14 @@ def rm_resource_label(resource):
try:
access_control = dictio.dict_read("resources", file)
except:
- security.err("Resource file not found, cannot remove label!")
+ raise security.ACMError("Resource file not found, cannot remove
label!")
# remove the entry and update file
if access_control.has_key(resource):
del access_control[resource]
dictio.dict_write(access_control, "resources", file)
else:
- security.err("Resource not labeled.")
+ raise security.ACMError("Resource not labeled")
def rm_domain_label(configfile):
@@ -65,8 +65,8 @@ def rm_domain_label(configfile):
fd = open(file, "rb")
break
if not fd:
- security.err("Configuration file '"+configfile+"' not found.")
-
+ raise OptionError("Configuration file '%s' not found." % configfile)
+
# read in the domain config file, removing label
ac_entry_re = re.compile("^access_control\s*=.*", re.IGNORECASE)
ac_exit_re = re.compile(".*'\].*")
@@ -86,7 +86,7 @@ def rm_domain_label(configfile):
# send error message if we didn't find anything to remove
if not removed:
- security.err("Domain not labeled.")
+ raise security.ACMError('Domain not labeled')
# write the data back out to the file
fd = open(file, "wb")
@@ -102,17 +102,18 @@ def main (argv):
if argv[1].lower() not in ('dom', 'res'):
raise OptionError('Unrecognised type argument: %s' % argv[1])
- try:
- if argv[1].lower() == "dom":
- configfile = argv[2]
- rm_domain_label(configfile)
- elif argv[1].lower() == "res":
- resource = argv[2]
- rm_resource_label(resource)
- except security.ACMError:
- sys.exit(-1)
+ if argv[1].lower() == "dom":
+ configfile = argv[2]
+ rm_domain_label(configfile)
+ elif argv[1].lower() == "res":
+ resource = argv[2]
+ rm_resource_label(resource)
if __name__ == '__main__':
- main(sys.argv)
+ try:
+ main(sys.argv)
+ except Exception, e:
+ sys.stderr.write('Error: %s\n' % str(e))
+ sys.exit(-1)
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|