pkgplan.py revision 2690
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#
import copy
import itertools
import os
"""A package plan takes two package FMRIs and an Image, and produces the
set of actions required to take the Image from the origin FMRI to the
destination FMRI.
If the destination FMRI is None, the package is removed.
"""
__slots__ = [
"__destination_mfst",
"_executed",
"_license_status",
"__origin_mfst",
"__repair_actions",
"__xferfiles",
"__xfersize",
"_autofix_pkgs",
"_hash",
"actions",
"destination_fmri",
"image",
"origin_fmri",
"pkg_summary",
]
#
# we don't serialize __xferfiles or __xfersize since those should be
# recalculated after after a plan is loaded (since the contents of the
# download cache may have changed).
#
# we don't serialize __origin_mfst, __destination_mfst, or
# __repair_actions since we only support serializing pkgplans which
# have had their actions evaluated and merged, and when action
# evaluation is complete these fields are cleared.
#
# we don't serialize our image object pointer. that has to be reset
# after this object is reloaded.
#
"__destination_mfst",
"__origin_mfst",
"__repair_actions",
"__xferfiles",
"__xfersize",
"image",
])
# make sure all __state__noserialize values are valid
# figure out which state we are saving.
# describe our state and the types of all objects
__state__desc = {
"_license_status": {
str: {
},
},
}
])
self.destination_fmri = None
self.origin_fmri = None
self.pkg_summary = None
self._license_status = {}
self.__repair_actions = {}
self._autofix_pkgs = []
"""Returns the serialized state of this object in a format
that that can be easily stored using JSON, pickle, etc."""
# validate unserialized state
# (see comments above __state__noserialize)
assert obj.__repair_actions == {}
# we use __slots__, so create a state dictionary
state = {}
for k in obj.__state__serialize:
"""Update the state of this object using previously serialized
state obtained via getstate()."""
# get the name of the object we're dealing with
# decode serialized state into python objects
# we use __slots__, so directly update attributes
for k in state:
# update unserialized state
# (see comments above __state__noserialize)
obj.__repair_actions = {}
"""Allocate a new object using previously serialized state
obtained via getstate()."""
return rv
return s
"""Adds a license status entry for the given src and dest
license actions.
'src' should be None or the source action for a license.
'dest' must be the destination action for a license."""
"src": src,
"dest": dest,
"accepted": False,
"displayed": False,
}
"""Propose origin and dest fmri, manifest"""
# self.origin_fmri = None
# I'd like a cleaner solution than this; we need to actually
# construct a list of actions as things currently are rather
# than just re-applying the current set of actions.
#
# Create a list of (src, dst) pairs for the actions to send to
# execute_repair.
self.__repair_actions = {
# src is none for repairs.
"install": [(None, x) for x in install],
# dest is none for removals.
"remove": [(x, None) for x in remove],
}
if autofix:
def get_actions(self):
raise NotImplementedError()
def get_nactions(self):
""" updates a set of installed fmris to reflect
proposed new state"""
if self.origin_fmri:
if self.destination_fmri:
"""Determine the actions required to transition the package."""
# If new actions are being installed, check the destination
# manifest for signatures.
if self.destination_fmri is not None:
try:
except apx.UnknownPublisher:
# Since user removed publisher, assume this is
# the same as if they had set signature-policy
# ignore for the publisher.
sig_pol = None
else:
"signature", new_excludes))
# Only perform signature verification logic if
# there are signatures or if signature-policy
# is not 'ignore'.
try:
"check-certificate-revocation"))
except apx.SigningException, e:
)
raise
if can_exclude:
if self.__destination_mfst is not None:
if self.__origin_mfst is not None and \
# figure out how many implicit directories disappear in this
# transition and add directory remove actions. These won't
# do anything unless no pkgs reference that directory in
# new state....
# Retrieving origin_dirs first and then checking it for any
# entries allows avoiding an unnecessary expanddirs for the
# destination manifest when it isn't needed.
# Manifest.get_directories() returns implicit directories, which
# means that this computation ends up re-adding all the explicit
# directories getting removed to the removed list. This is
# ugly, but safe.
if origin_dirs:
absent_dirs = origin_dirs - \
for a in absent_dirs:
# Stash information needed by legacy actions.
self.pkg_summary = \
# Add any install repair actions to the update list
EmptyI))
EmptyI))
# No longer needed.
self.__repair_actions = {}
if not src:
# Initial installs require acceptance.
continue
# If src action required acceptance,
# then license was already accepted
# before, and if the hashes are the
# same for the license payload, then
# it doesn't need to be accepted again.
def get_licenses(self):
"""A generator function that yields tuples of the form (license,
entry). Where 'entry' is a dict containing the license status
information."""
"""Sets the license status for the given license entry.
'plicense' should be the value of the license attribute for the
destination license action.
'accepted' is an optional parameter that can be one of three
values:
None leaves accepted status unchanged
False sets accepted status to False
True sets accepted status to True
'displayed' is an optional parameter that can be one of three
values:
None leaves displayed status unchanged
False sets displayed status to False
True sets displayed status to True"""
if accepted is not None:
if displayed is not None:
def get_xferstats(self):
self.__xfersize += \
self.__xferfiles += \
"").split())
def get_bytes_added(self):
"""Return tuple of compressed bytes possibly downloaded
and number of bytes laid down; ignore removals
because they're usually pinned by snapshots"""
def sum_dest_size(a, b):
if b[1]:
return (a[0], a[1])
(0, 0))
def get_xfername(self):
if self.destination_fmri:
if self.origin_fmri:
return None
def preexecute(self):
"""Perform actions required prior to installation or removal of
a package.
This method executes each action's preremove() or preinstall()
methods, as well as any package-wide steps that need to be taken
at such a time.
"""
# Determine if license acceptance requirements have been met as
# early as possible.
errors = []
if errors:
if dest:
else:
"""Download data for any actions that need it."""
if mfile is None:
return
"""Load previously downloaded data for actions that need it."""
continue
dest)
def gen_install_actions(self):
def gen_removal_actions(self):
def gen_update_actions(self):
""" perform action for installation of package"""
try:
# Don't log these as they're expected, and should be
# handled by the caller.
raise
except Exception, e:
raise
""" handle action updates"""
try:
# Don't log these as they're expected, and should be
# handled by the caller.
raise
except Exception, e:
raise
""" handle action removals"""
try:
# Don't log these as they're expected, and should be
# handled by the caller.
raise
except Exception, e:
raise
def postexecute(self):
"""Perform actions required after install or remove of a pkg.
This method executes each action's postremove() or postinstall()
methods, as well as any package-wide steps that need to be taken
at such a time.
"""
# record that package states are consistent
if dest:
else:
"""Used to save unexpected files or directories found during
plan execution. Salvaged items are tracked in the imageplan.
"""
# get just the file path that was salvaged
"""move unpackaged contents to specified destination"""
# remove leading / if present
break
else:
return
def destination_manifest(self):
return self.__destination_mfst
def clear_dest_manifest(self):
def origin_manifest(self):
return self.__origin_mfst
def clear_origin_manifest(self):