[lnst] XmlProcessing: Fix warnings from the lxml module
by Jiří Pírko
commit cce3f0082140e351c9aa70a148946c90e1ca2dc7
Author: Radek Pazdera <rpazdera(a)redhat.com>
Date: Wed Sep 4 11:04:19 2013 +0200
XmlProcessing: Fix warnings from the lxml module
In case you test for None using an instance associated with the lxml
module like this
if obj:
the module will output "future warnings". This patch changes those
checks to:
if obj is not None:
Reported-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Common/XmlProcessing.py | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)
---
diff --git a/lnst/Common/XmlProcessing.py b/lnst/Common/XmlProcessing.py
index f4d9105..5ea297d 100644
--- a/lnst/Common/XmlProcessing.py
+++ b/lnst/Common/XmlProcessing.py
@@ -24,16 +24,15 @@ class XmlProcessingError(Exception):
super(XmlProcessingError, self).__init__()
self._msg = msg
- if obj and hasattr(obj, "loc"):
+ if obj is not None and hasattr(obj, "loc"):
self.set_loc(obj.loc)
loc = {}
- if obj:
- if hasattr(obj, "base") and obj.base != None:
- loc["file"] = os.path.basename(obj.base)
- if hasattr(obj, "sourceline"):
- loc["line"] = obj.sourceline
- self.set_loc(loc)
+ if obj is not None and hasattr(obj, "base") and obj.base != None:
+ loc["file"] = os.path.basename(obj.base)
+ if hasattr(obj, "sourceline"):
+ loc["line"] = obj.sourceline
+ self.set_loc(loc)
def set_loc(self, loc):
9 years, 6 months
[PATCH] XmlProcessing: Fix warnings from the lxml module
by Radek Pazdera
In case you test for None using an instance associated with the lxml
module like this
if obj:
the module will output "future warnings". This patch changes those
checks to:
if obj is not None:
Reported-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
---
lnst/Common/XmlProcessing.py | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/lnst/Common/XmlProcessing.py b/lnst/Common/XmlProcessing.py
index f4d9105..5ea297d 100644
--- a/lnst/Common/XmlProcessing.py
+++ b/lnst/Common/XmlProcessing.py
@@ -24,16 +24,15 @@ class XmlProcessingError(Exception):
super(XmlProcessingError, self).__init__()
self._msg = msg
- if obj and hasattr(obj, "loc"):
+ if obj is not None and hasattr(obj, "loc"):
self.set_loc(obj.loc)
loc = {}
- if obj:
- if hasattr(obj, "base") and obj.base != None:
- loc["file"] = os.path.basename(obj.base)
- if hasattr(obj, "sourceline"):
- loc["line"] = obj.sourceline
- self.set_loc(loc)
+ if obj is not None and hasattr(obj, "base") and obj.base != None:
+ loc["file"] = os.path.basename(obj.base)
+ if hasattr(obj, "sourceline"):
+ loc["line"] = obj.sourceline
+ self.set_loc(loc)
def set_loc(self, loc):
--
1.8.3.1
9 years, 6 months
[PATCH] lnst-ctl: Adding return value
by Radek Pazdera
The lnst-ctl always exited with 0. This is impractical, especially for
scripting. This commit adds return values to the lnst-ctl command that
properly reflect what happened during the execution.
Currently supported return values:
* RETVAL_PASS = 0: When everything passed with no error
* RETVAL_FAIL = 1: One or more tests failed
* RETVAL_ERR = 2: There was an error in the recipe, during the
matching or configuration
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
---
lnst-ctl | 51 +++++++++++++++++++++++++++++++++------------------
1 file changed, 33 insertions(+), 18 deletions(-)
diff --git a/lnst-ctl b/lnst-ctl
index 55e2dd1..9548428 100755
--- a/lnst-ctl
+++ b/lnst-ctl
@@ -23,7 +23,10 @@ from lnst.Common.Colours import load_presets_from_config
from lnst.Controller.NetTestController import NetTestController, NetTestError
from lnst.Controller.NetTestResultSerializer import NetTestResultSerializer
-def usage():
+RETVAL_PASS = 0
+RETVAL_FAIL = 1
+RETVAL_ERR = 2
+def usage(retval=0):
"""
Print usage of this app
"""
@@ -43,7 +46,7 @@ def usage():
print " -c, --cleanup perform config cleanup\n" \
" machines"
print " -x, --result=FILE file to write xml_result"
- sys.exit()
+ sys.exit(retval)
def process_recipe(action, file_path, cleanup, res_serializer,
packet_capture, log_ctl, pool_checks):
@@ -64,6 +67,8 @@ def get_recipe_result(args, file_path, cleanup, res_serializer, packet_capture,
res_serializer.add_recipe(file_path)
log_ctl.set_recipe(file_path)
+ retval = RETVAL_PASS
+
res = {}
try:
res = process_recipe(args, file_path, cleanup, res_serializer,
@@ -73,10 +78,15 @@ def get_recipe_result(args, file_path, cleanup, res_serializer, packet_capture,
logging.error(err)
res["passed"] = False
res["err_msg"] = str(err)
+ retval = RETVAL_ERR
res_serializer.set_recipe_result(res)
- return ((file_path, res))
+ # The test failed, but don't override erro
+ if not res["passed"] and retval < RETVAL_FAIL:
+ retval = RETVAL_FAIL
+
+ return (file_path, res, retval)
def main():
"""
@@ -91,8 +101,7 @@ def main():
)
except getopt.GetoptError as err:
print str(err)
- usage()
- sys.exit()
+ usage(RETVAL_ERR)
lnst_config.controller_init()
dirname = os.path.dirname(sys.argv[0])
@@ -122,7 +131,7 @@ def main():
if opt in ("-d", "--debug"):
debug += 1
elif opt in ("-h", "--help"):
- usage()
+ usage(RETVAL_PASS)
elif opt in ("-c", "--cleanup"):
cleanup = True
elif opt in ("-x", "--result"):
@@ -143,15 +152,16 @@ def main():
if len(args) <= 0:
logging.error("No action specified")
- usage()
+ usage(RETVAL_ERR)
action = args.pop()
if not action in ['run', 'dump', 'config_only', 'match_setup']:
logging.error("Action '%s' not recognised" % action)
- usage()
+ usage(RETVAL_ERR)
summary = []
+ retval = RETVAL_PASS
res_serializer = NetTestResultSerializer()
for recipe_path in args:
if os.path.isdir(recipe_path):
@@ -165,16 +175,19 @@ def main():
recipe_file = os.path.join(recipe_path, f)
if re.match(r'^.*\.xml$', recipe_file):
logging.info("Processing recipe file \"%s\"" % recipe_file)
- summary.append(get_recipe_result(action, recipe_file,
- cleanup,
- res_serializer,
- packet_capture,
- log_ctl, pool_checks))
+ fp, res, rv = get_recipe_result(action, recipe_file,
+ cleanup, res_serializer,
+ packet_capture,
+ log_ctl, pool_checks)
else:
- summary.append(get_recipe_result(action, recipe_path,
- cleanup, res_serializer,
- packet_capture,
- log_ctl, pool_checks))
+ fp, res, rv = get_recipe_result(action, recipe_path,
+ cleanup, res_serializer,
+ packet_capture,
+ log_ctl, pool_checks)
+
+ summary.append((fp, res))
+ if rv > retval:
+ retval = rv
log_ctl.set_recipe("", clean=False)
@@ -186,5 +199,7 @@ def main():
handle.write(str(res_serializer))
handle.close()
+ return retval
+
if __name__ == "__main__":
- main()
+ sys.exit(main())
--
1.8.3.1
9 years, 6 months