The validation output order shouldn't really matter.

Since we are getting json back with the rpm name requested
we can just extract the set of names that were found from
the desired set and use that to raise an error if a dependency
is missing.

Change-Id: I03d93f41fef9dcd356e23255047bc76e66d78c91
This commit is contained in:
Joshua Harlow 2013-08-02 22:28:19 -07:00
parent e34a64a7ed
commit 3555762f22

@ -640,19 +640,22 @@ class YumDependencyHandler(base.DependencyHandler):
# Ensure we select the right versions that is required and not a # Ensure we select the right versions that is required and not a
# version that doesn't match the requirements. # version that doesn't match the requirements.
preq_rpms = [] desired_rpms = []
just_names = [] desired_rpm_names = set()
preq_formatted = [] desired_rpms_formatted = []
def format_name(rpm_name, py_req):
full_name = str(rpm_name).strip()
if py_req is not None:
full_name += ",%s" % (py_req)
return full_name
def capture_rpm(rpm_name, py_req): def capture_rpm(rpm_name, py_req):
if rpm_name in just_names or not rpm_name: if rpm_name in desired_rpm_names or not rpm_name:
return return
if not py_req: desired_rpms_formatted.append(format_name(rpm_name, py_req))
preq_formatted.append(str(rpm_name)) desired_rpms.append((rpm_name, py_req))
else: desired_rpm_names.add(rpm_name)
preq_formatted.append("%s,%s" % (rpm_name, py_req))
preq_rpms.append((rpm_name, py_req))
just_names.append(rpm_name)
for (rpm_name, req) in zip(rpm_names, reqs): for (rpm_name, req) in zip(rpm_names, reqs):
capture_rpm(rpm_name, req) capture_rpm(rpm_name, req)
@ -672,33 +675,44 @@ class YumDependencyHandler(base.DependencyHandler):
capture_rpm(rpm_name, None) capture_rpm(rpm_name, None)
cmd = [self.yumfind_executable, '-j'] cmd = [self.yumfind_executable, '-j']
preq_formatted = sorted(preq_formatted) desired_rpms_formatted = sorted(desired_rpms_formatted)
for p in preq_formatted: for p in desired_rpms_formatted:
cmd.extend(['-p', p]) cmd.extend(['-p', p])
utils.log_iterable(preq_formatted, header = "Validating %s required packages are still available" % (len(desired_rpms))
header="Validating %s required packages are still available" % (len(preq_formatted)), utils.log_iterable(desired_rpms_formatted, header=header, logger=LOG)
logger=LOG)
the_rpms = [] rpms_located = []
for i, matched in enumerate(sh.execute(cmd)[0].splitlines()): rpm_names_located = set()
for matched in sh.execute(cmd)[0].splitlines():
matched = matched.strip() matched = matched.strip()
pkg = None
if matched: if matched:
pkg = json.loads(matched) pkg = json.loads(matched)
if not pkg: if isinstance(pkg, dict):
rpm_name, py_req = preq_rpms[i] rpm_names_located.add(pkg['name'])
msg = "Could not find available rpm package '%s'" % (rpm_name) rpms_located.append((pkg['name'], pkg['version']))
if py_req:
msg += " matching requirement '%s'" % (py_req)
raise excp.DependencyException(msg)
else:
the_rpms.append((pkg['name'], pkg['version']))
LOG.info("All %s required packages are still available!", len(the_rpms))
# Now format correctly rpm_names_missing = desired_rpm_names - rpm_names_located
just_rpms = [] if rpm_names_missing:
for (name, ver) in the_rpms: # Include the python version required information (if applicable)
just_rpms.append("%s,%s" % (name, ver)) missing_formatted = []
return list(sorted(just_rpms)) for n in sorted(rpm_names_missing):
source_found = False
for (n2, py_req) in desired_rpms:
if n2 == n:
missing_formatted.append(format_name(n2, py_req))
source_found = True
break
if not source_found:
missing_formatted.append(format_name(n, None))
msg = "Could not find available rpm packages: %s"
msg = msg % (", ".join(missing_formatted))
raise excp.DependencyException(msg)
LOG.info("All %s required packages are still available!", len(desired_rpms))
desired_rpms = []
for (name, version) in rpms_located:
desired_rpms.append("%s,%s" % (name, version))
return list(sorted(desired_rpms))
def install(self): def install(self):
super(YumDependencyHandler, self).install() super(YumDependencyHandler, self).install()