Tested against b2aaf2b3f5c8d758825028dacdeadbdd2e50e4a8. Please commit.
Purpose of patch:
Examples:
(1) Prior to patch, try running 'cobbler report --format=mediawiki
--fields=hostname --what=repos'. In this case, one will receive a stack
trace, since 'hostname' is not a field for a "distro" item.
(2) Prior to patch, try running 'cobbler report --format=mediawiki
--fields=ks_meta[X] --what=systems', where "X" is some metavariable key
in an 'X=Y' statement. In this case, if some set of systems contain
"ks_meta: 'X=Y,...'" and others do not, then a stack trace will occur
when reporting encounters one of the latter items.
---
Everything should be fixed now w.r.t. these kinds of edge case issues.
If there are more, please post them to the cobbler-devel list.
Regards,
- A.
From c7f08e43d3f1782b1b64931fccb3f6e36d2e8edd Mon Sep 17 00:00:00 2001
From: Adam Rosenwald <thestrider(a)gmail.com>
Date: Mon, 6 Apr 2009 22:28:10 -0400
Subject: [PATCH] Fixed issues when reporting on a set of fields that do not exist
within a collection.
ARos
---
cobbler/action_report.py | 47 +++++++++++++++++++++++++++++----------------
1 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/cobbler/action_report.py b/cobbler/action_report.py
index 6e6c5ea..9f4367e 100644
--- a/cobbler/action_report.py
+++ b/cobbler/action_report.py
@@ -45,23 +45,21 @@ class Report:
item = {}
for field in fields_list:
-
+
+ internal = self.array_re.search(field)
+ # check if field is primary field
if field in structure.keys():
item[field] = structure[field]
-
- # exception for fields within fields (depth=1 for now)
- elif self.array_re.search(field):
- internal = self.array_re.search(field)
- item[internal.group(2)] =
structure[internal.group(1)][internal.group(2)]
- # exception for systems which could have > 1 interface
+ # check if subfield in 'interfaces' field
+ elif internal and internal.group(1) in structure.keys():
+ outer = internal.group(1)
+ inner = internal.group(2)
+ if type(structure[outer]) is type({}) and inner in structure[outer]:
+ item[field] = structure[outer][inner]
elif "interfaces" in structure.keys():
for device in structure['interfaces'].keys():
if field in structure['interfaces'][device]:
item[field] = device + ': ' +
structure['interfaces'][device][field]
- else:
- raise CX(_("The field \"%s\" does not exist, see
cobbler dumpvars for available fields.") % field)
- else:
- raise CX(_("The field \"%s\" does not exist, see cobbler
dumpvars for available fields.") % field)
return item
def reporting_csv(self, info, order, noheaders):
@@ -81,7 +79,10 @@ class Report:
if info_count == 0:
outputheaders += str(key) + sep
- outputbody += str(item[key]) + sep
+ if key in item.keys():
+ outputbody += str(item[key]) + sep
+ else:
+ outputbody += '-' + sep
item_count = item_count + 1
@@ -113,7 +114,10 @@ class Report:
if info_count == 0:
outputheaders += sep + str(key)
- outputbody += sep + str(item[key])
+ if key in item.keys():
+ outputbody += sep + str(item[key])
+ else:
+ outputbody += sep + '-'
item_count = item_count + 1
@@ -146,7 +150,10 @@ class Report:
if info_count == 0:
outputheaders += sep1 + key
- outputbody += sep2 + item[key]
+ if key in item.keys():
+ outputbody += sep2 + item[key]
+ else:
+ outputbody += sep2 + '-'
item_count = item_count + 1
@@ -185,9 +192,15 @@ class Report:
outputheaders += sep1 + key
if item_count == 0:
- outputbody += sep2 + str(item[key])
+ if key in item.keys():
+ outputbody += sep2 + str(item[key])
+ else:
+ outputbody += sep2 + '-'
else:
- outputbody += sep1 + str(item[key])
+ if key in item.keys():
+ outputbody += sep1 + str(item[key])
+ else:
+ outputbody += sep1 + '-'
item_count = item_count + 1
@@ -308,7 +321,7 @@ class Report:
item = self.fielder(structure, fields_list)
data.append(item)
- self.print_formatted_data(data = data, order = item.keys(), report_type =
report_type, noheaders = report_noheaders)
+ self.print_formatted_data(data = data, order = fields_list, report_type =
report_type, noheaders = report_noheaders)
return True
--
1.5.5.1