def _check(self, dep_action, which): """Performs the subprocess invocation and returns (status, outputbuffer) to the caller""" # leverage smf test infrastructure cmds_dir = DebugValues["smf_cmds_dir"] if DebugValues["firmware-dependency-bypass"]: return (True, None) if cmds_dir: # we're testing; firmware_dir = cmds_dir else: firmware_dir = "/usr/lib/fwenum" args = [os.path.join(firmware_dir, which)] args.extend([ "{0}={1}".format(k, quote_attr_value(v)) for k, v in sorted(six.iteritems(dep_action.attrs)) ]) # Set up the default return values ret = 0 buf = "" # use a cache since each check may be expensive and each # pkg version may have the same dependency. # ignore non-solaris systems here if portable.osname != "sunos" and key not in self._cache: self._cache[key] = (True, None) if str(args) not in self._cache: try: proc = subprocess.Popen( args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) # output from proc is bytes buf = [misc.force_str(l) for l in proc.stdout.readlines()] ret = proc.wait() except OSError as e: # we have no enumerator installed. This can # occur if this driver is being installed for # the first time or, more likely, we just added # enumerators and a firmware dependency for the # first time. For now, drive on and ignore this # to permit the addition of such dependencies # concurrently with their enumerarators. buf = (_("Firmware dependency error:" " Cannot exec {0}: {1}").format( " ".join(args), str(e))) ret = -1 return (ret, buf, args)
def astr(aout): # Number of attribute values for first line and remaining. first_line = True first_attr_count = 0 rem_attr_count = 0 # Total number of remaining attribute values to output. total_count = sum(len(act.attrlist(k)) for k in sattrs) rem_count = total_count # Now build the action output string an attribute at a time. for k, v in sorted(six.iteritems(sattrs), key=key_func): # Newline breaks are only forced when there is more than # one value for an attribute. if not (isinstance(v, list) or isinstance(v, set)): nv = [v] use_force_nl = False else: nv = v use_force_nl = True cmp_attrs = None if k == "alias": cmp_attrs = cmp_to_key(cmp_aliases) for lmt in sorted(nv, key=cmp_attrs): force_nl = use_force_nl and \ (k == "alias" or (opt_format == FMT_V2 and k.startswith("pkg.debug"))) aout = grow(aout, "=".join((k, quote_attr_value(lmt))), rem_count, force_nl=force_nl) # Must be done for each value. if first_line and JOIN_TOK in aout: first_line = False first_attr_count = \ (total_count - rem_count) if ahash and ahash != "NOHASH": first_attr_count += 1 rem_attr_count = rem_count rem_count -= 1 return first_attr_count, rem_attr_count, aout
def astr(aout): # Number of attribute values for first line and remaining. first_line = True first_attr_count = 0 rem_attr_count = 0 # Total number of remaining attribute values to output. total_count = sum(len(act.attrlist(k)) for k in sattrs) rem_count = total_count # Now build the action output string an attribute at a time. for k, v in sorted(sattrs.iteritems(), cmp=cmpkv): # Newline breaks are only forced when there is more than # one value for an attribute. if not (isinstance(v, list) or isinstance(v, set)): nv = [v] use_force_nl = False else: nv = v use_force_nl = True cmp_attrs = None if k == "alias": cmp_attrs = cmp_aliases for lmt in sorted(nv, cmp=cmp_attrs): force_nl = use_force_nl and \ (k == "alias" or (opt_format == FMT_V2 and k.startswith("pkg.debug"))) aout = grow(aout, "=".join((k, quote_attr_value(lmt))), rem_count, force_nl=force_nl) # Must be done for each value. if first_line and JOIN_TOK in aout: first_line = False first_attr_count = \ (total_count - rem_count) if ahash and ahash != "NOHASH": first_attr_count += 1 rem_attr_count = rem_count rem_count -= 1 return first_attr_count, rem_attr_count, aout
def check_firmware(self, dep_action, firmware_name): """Check firmware dependency. returns ((true, false, none (internal error)), error text)""" firmware_dir = "/usr/lib/fwenum" # leverage smf test infrastructure cmds_dir = DebugValues["smf_cmds_dir"] if DebugValues["firmware-dependency-bypass"]: return (True, None) if cmds_dir: # we're testing; firmware_dir = cmds_dir args = [os.path.join(firmware_dir, firmware_name[len("feature/firmware/"):])] args.extend([ "{0}={1}".format(k, quote_attr_value(v)) for k,v in sorted(six.iteritems(dep_action.attrs)) if k not in ["type", "root-image", "fmri"] ]) key = str(args) # use a cache since each check may be expensive and each # pkg version may have the same dependency. # ignore non-solaris systems here if portable.osname != "sunos" and key not in self.firmware: self.__firmware[key] = (True, None) if key not in self.__firmware: try: proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) # output from proc is bytes buf = [misc.force_str(l) for l in proc.stdout.readlines()] ret = proc.wait() # if there was output, something went wrong. # Since generic errors are often exit(1), # map this to an internal error. if ret == 1 and len(buf) > 0: ret = 255 if ret == 0: ans = (True, None) elif 0 < ret <= 239: ans = (False, (_("There are {0} instances" " of downrev firmware for the '{1}' " " devices present on this system. " "Update each to version {2} or better." ).format(ret, args[1], dep_action.attrs.get("minimum-version", _("UNSPECIFIED"))))) elif ret == 240: ans = (False, (_("There are 240 or more " "instances of downrev firmware for the" "'{0}' devices present on this system. " "Update each to version {1} or better." ).format(args[1], dep_action.attrs.get("minimum-version", _("UNSPECIFIED"))))) elif ret < 0: ans = (None, (_("Firmware dependency error: {0} " " exited due to signal {1}").format( " ".join(args), misc.signame(-ret)))) else: ans = (None, (_("Firmware dependency error: General " "internal error {0} running '{1}': '{2}'" ).format(str(ret), " ".join(args), "\n".join(buf)))) except OSError as e: # we have no enumerator installed. This can # occur if this driver is being installed # for the first time or, more likely, we # just added enumerators & a firmware dependency # for the first time. For now, drive on and # ignore this to permit the addition of such # dependencies concurrently with their # enumerarators. # ans = (None, (_("Firmware dependency error:" # " Cannot exec {0}: {1}").format(" ".join(args) # , str(e)))) ans = (True, 0) self.__firmware[key] = ans return self.__firmware[key]