This patch introduces no new features and (hopefully) no new bugs. It
just reformats the code to be more readable and maintainable - now the
semantics and variables are very similar to those used in rpmlint and
rpmguard tests, so it's easy to read through the code.
---
tests/upgradepath/upgradepath.py | 99 ++++++++++++++++++++++++++------------
1 files changed, 68 insertions(+), 31 deletions(-)
diff --git a/tests/upgradepath/upgradepath.py b/tests/upgradepath/upgradepath.py
index 028b8aa..bc382d3 100755
--- a/tests/upgradepath/upgradepath.py
+++ b/tests/upgradepath/upgradepath.py
@@ -36,52 +36,58 @@ from autotest_lib.client.bin.test_config import config_loader
class upgradepath(AutoQATest):
version = 1 # increment if setup() changes
- test_result = 'PASS'
- log = []
- envr_list = set()
def initialize(self, config):
self.config = config_loader(config, self.tmpdir)
#URL of logs/results stored on autotest-server
self.autotest_url = autoqa.util.make_autotest_url(self.config)
+ self.result = 'PASSED'
+ # order for evaluation of final result; higher index means preference
+ self.result_order =
('PASSED','INFO','FAILED','ABORTED')
+ self.envr_results = {} # results for invidual packages
+ self.outputs = []
+ self.highlights = []
+ self.log =
open(os.path.join(self.resultsdir,'upgradepath.log'),'wb') # where to log
output
+
def setup(self):
pass
def compare(self, matching_build, tags, op, opstr):
koji = autoqa.koji_utils.SimpleKojiClientSession()
+ result = 'PASSED'
for tag in tags:
latest_build = koji.latest_by_tag(tag, matching_build['name'])
if latest_build is None:
msg ='{0:<7}{1}'.format('[ OK ]', tag)
- self.log.append(msg)
print msg
+ self.outputs.append(msg)
msg = "\tNo such package: %s" % matching_build['name']
- self.log.append(msg)
print msg
+ self.outputs.append(msg)
else:
- result = autoqa.koji_utils.compareEVR(matching_build, latest_build)
+ res = autoqa.koji_utils.compareEVR(matching_build, latest_build)
- if op(result, 0):
+ if op(res, 0):
ok = True
msg ='{0:<7}{1}'.format('[ OK ]', tag)
print msg
- self.log.append(msg)
+ self.outputs.append(msg)
else:
ok = False
- self.test_result = 'FAIL'
msg ='{0:<7}{1}'.format('[FAIL]', tag)
print msg
- self.log.append(msg)
- self.envr_list.add(matching_build['envr'])
+ self.outputs.append(msg)
msg = "\tLatest package: %s" % latest_build['nvr']
- self.log.append(msg)
print msg
+ self.outputs.append(msg)
if not ok:
msg = '\tFailed condition: Requested package %s Latest
package' % opstr
- self.log.append(msg)
print msg
+ self.outputs.append(msg)
+ result = 'FAILED'
+ return result
@ExceptionCatcher("self.run_once_failed")
def run_once(self, envrs, kojitag, **kwargs):
@@ -99,10 +105,12 @@ class upgradepath(AutoQATest):
hi_tags = repotags[(current_tag + 1):] # tags higher than current
low_eq_tags = repotags[:(current_tag + 1)] # tags lower or equal
+ koji = autoqa.koji_utils.SimpleKojiClientSession()
+
for envr in envrs:
msg = '%s\n%s into %s\n%s' % (40*'=', envr, kojitag,
40*'=')
print msg
- self.log.append(msg)
+ self.outputs.append(msg)
# our testing package
(name, version, release, epoch, arch) =
rpmUtils.miscutils.splitFilename(envr)
@@ -114,34 +122,63 @@ class upgradepath(AutoQATest):
'envr' : envr,
}
- if kojitag.find('updates') == -1 and repotags[current_tag] !=
repotags[-1]:
- msg = "Warning: Pushing into stable repository"
- self.log.append(msg)
+ if kojitag.find('updates') < 0 and repotags[current_tag] !=
repotags[-1]:
+ # not *-updates* and not rawhide
+ # FIXME: don't warn about pushing into base repo for both rawhide and
branched (but possibly only before change deadline?)
+ msg = "Warning: Pushing into the base 'fedora'
repository"
print msg
+ self.outputs.append(msg)
+ if msg not in self.highlights:
+ # this message would be repeated for every package, highlight only
once
+ self.highlights.append(msg)
- koji = autoqa.koji_utils.SimpleKojiClientSession()
latest_build = koji.latest_by_tag(kojitag, matching_build['name'])
if latest_build is not None:
- result = autoqa.koji_utils.compareEVR(matching_build, latest_build)
- if result <= 0:
- msg = "Warning: Same or newer build already exists: %s" %
latest_build['nvr']
- self.log.append(msg)
+ if autoqa.koji_utils.compareEVR(matching_build, latest_build) <= 0:
+ msg = "Warning: Same or newer build already exists in the same
repo: %s" % latest_build['nvr']
print msg
+ self.outputs.append(msg)
+ self.highlights.append(msg)
# compare with lower or equal tags, so version has to be greater or equal
- self.compare(matching_build, low_eq_tags, operator.ge, '>=')
+ result = self.compare(matching_build, low_eq_tags, operator.ge,
'>=')
# compare with higher tags, so version has to be lower or equal
- self.compare(matching_build, hi_tags, operator.le, '<=')
+ result2 = self.compare(matching_build, hi_tags, operator.le,
'<=')
+
+ # compute pkg result
+ if self.result_order.index(result2) > self.result_order.index(result):
+ result = result2
+ self.envr_results[envr] = result
+
+ msg = 'RESULT: %s' % result
+ print msg
+ self.outputs.append(msg)
+
+ # update self.result
+ if self.result_order.index(result) >
self.result_order.index(self.result):
+ self.result = result
+
+ # create summary like "1 PASSED, 2 FAILED, 3 INFO"
+ summary = []
+ for res in self.result_order:
+ if res in self.envr_results.values():
+ count = len([k for k in self.envr_results.keys() if self.envr_results[k]
== res])
+ summary.append('%d %s' % (count, res))
+ summary = ', '.join(summary)
- summary = str(len(envrs) - len(self.envr_list)) + ' OK, ' +
str(len(self.envr_list)) + ' FAILED'
+ # print summary
msg = 'SUMMARY: ' + summary
- self.log.append(msg)
print msg
+ self.outputs.append(msg)
+ self.highlights.append(msg)
- self.result = self.test_result
- self.outputs = ""
- for i in self.log:
- self.outputs += i + '\n'
- self.outputs += '\n \n'
self.summary = '%s for %s' % (summary, update_id)
+ # reformat result variables
+ self.outputs = '\n'.join(self.outputs)
+ self.highlights = '\n'.join(self.highlights)
+
+ # log outputs
+ self.log.write(self.outputs)
+ self.log.close()
+
--
1.7.2.3