pkgplan.py revision 2627
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# CDDL HEADER START
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# The contents of this file are subject to the terms of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# Common Development and Distribution License (the "License").
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# You may not use this file except in compliance with the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# See the License for the specific language governing permissions
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# and limitations under the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# When distributing Covered Code, include this CDDL HEADER in each
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# If applicable, add the following below this CDDL HEADER, with the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# fields enclosed by brackets "[]" replaced with your own identifying
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# information: Portions Copyright [yyyy] [name of copyright owner]
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# CDDL HEADER END
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync# Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfrom pkg.misc import expanddirs, get_pkg_otw_size, EmptyI
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync """A package plan takes two package FMRIs and an Image, and produces the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync set of actions required to take the Image from the origin FMRI to the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync destination FMRI.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync If the destination FMRI is None, the package is removed.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "__destination_mfst",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "__executed",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "__license_status",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "__origin_mfst",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "__repair_actions",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "__xferfiles",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "__xfersize",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "_autofix_pkgs",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "destination_fmri",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "origin_fmri",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "pkg_summary",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync self.__destination_mfst = manifest.NullFactoredManifest
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync self.actions = manifest.ManifestDifference([], [], [])
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync s = "%s -> %s\n" % (self.origin_fmri, self.destination_fmri)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync """Adds a license status entry for the given src and dest
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync license actions.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 'src' should be None or the source action for a license.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 'dest' must be the destination action for a license."""
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync """Update the state of this object using the contents of
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync the supplied dictionary."""
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # convert fmri strings into objects
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if state[i] is not None:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # convert lists into tuples/sets
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # convert action object list into string list
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if src is not None:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if dst is not None:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync state["added"], state["changed"], state["removed"])
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # update the license actions associated with this package
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for src, dest in itertools.chain(self.gen_update_actions(),
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync """Returns a dictionary containing the state of this object
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync so that it can be easily stored using JSON."""
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # convert fmri objects into strings
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # convert tuples/sets into lists
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # convert actions objects into strings
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if src is not None:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if dst is not None:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync """Propose origin and dest fmri, manifest"""
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync def propose_repair(self, fmri, mfst, install, remove, autofix=False):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # self.origin_fmri = None
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # I'd like a cleaner solution than this; we need to actually
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # construct a list of actions as things currently are rather
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # than just re-applying the current set of actions.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # Create a list of (src, dst) pairs for the actions to send to
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # execute_repair.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # src is none for repairs.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # dest is none for removals.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return len(self.actions.added) + len(self.actions.changed) + \
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync """ updates a set of installed fmris to reflect
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync proposed new state"""
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync def evaluate(self, old_excludes=EmptyI, new_excludes=EmptyI,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync """Determine the actions required to transition the package."""
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # If new actions are being installed, check the destination
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # manifest for signatures.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # Since user removed publisher, assume this is
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # the same as if they had set signature-policy
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # ignore for the publisher.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync sigs = list(self.__destination_mfst.gen_actions_by_type(
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # Only perform signature verification logic if
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # there are signatures or if signature-policy
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # is not 'ignore'.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "check-certificate-revocation"))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # figure out how many implicit directories disappear in this
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # transition and add directory remove actions. These won't
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # do anything unless no pkgs reference that directory in
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # new state....
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # Retrieving origin_dirs first and then checking it for any
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # entries allows avoiding an unnecessary expanddirs for the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # destination manifest when it isn't needed.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync origin_dirs = expanddirs(self.__origin_mfst.get_directories(
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # Manifest.get_directories() returns implicit directories, which
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # means that this computation ends up re-adding all the explicit
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # directories getting removed to the removed list. This is
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # ugly, but safe.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync expanddirs(self.__destination_mfst.get_directories(
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # Stash information needed by legacy actions.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync self.__destination_mfst.get("description", "none provided"))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # Add any install repair actions to the update list
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync self.actions.changed.extend(self.__repair_actions.get("install",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync self.actions.removed.extend(self.__repair_actions.get("remove",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # No longer needed.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for src, dest in itertools.chain(self.gen_update_actions(),
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # Initial installs require acceptance.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # If src action required acceptance,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # then license was already accepted
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # before, and if the hashes are the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # same for the license payload, then
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync # it doesn't need to be accepted again.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync """A generator function that yields tuples of the form (license,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync entry). Where 'entry' is a dict containing the license status
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync information."""
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for lic, entry in self.__license_status.iteritems():
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync def set_license_status(self, plicense, accepted=None, displayed=None):
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync """Sets the license status for the given license entry.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 'plicense' should be the value of the license attribute for the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync destination license action.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 'accepted' is an optional parameter that can be one of three
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync None leaves accepted status unchanged
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync False sets accepted status to False
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync True sets accepted status to True
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 'displayed' is an optional parameter that can be one of three
if accepted is not None:
if displayed is not None:
def sum_dest_size(a, b):
errors = []
if errors:
if dest:
if mfile is None:
except Exception, e:
except Exception, e:
except Exception, e:
if dest: