#
# 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 grp
import itertools
import os
import pwd
import six
import stat
"""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",
"__salvage_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",
"__salvage_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": {
},
},
}
])
self.destination_fmri = None
self.origin_fmri = None
self.pkg_summary = None
self._license_status = {}
self.__repair_actions = {}
self.__salvage_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"""
"""Generate the on-disk state (attributes) of the action
that fail verification."""
return
try:
except Exception:
# If file to repair isn't on-disk, treat as install
return
try:
except KeyError:
# If associated user / group can't be determined, treat
# as install. This is not optimal for repairs, but
# ensures proper ownership of file is set.
return
# No need to generate hash of on-disk content as verify
# short-circuits hash comparison by setting replace_required
# flag on action. The same is true for preserved files which
# will automatically handle content replacement if needed based
# on the result of _check_preserve.
return act
# 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.
if autofix:
# If an uninstall causes a fixup to happen, we can't
# generate an on-disk state action because the result
# of needsdata is different between propose and execute.
# Therefore, we explicitly assign None to src for actions
# to be installed.
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],
}
else:
self.__repair_actions = {
# src can be None or an action representing on-disk state
"remove": [(x, None) for x in remove],
}
raise NotImplementedError()
""" 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:
# Repaired packages use a manifest synthesized
# from the installed one; so retrieve the
# installed one for our signature checks.
else:
# Only perform signature verification logic if
# there are signatures or if signature-policy
# is not 'ignore'.
try:
"check-certificate-revocation"))
except apx.SigningException as 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:
implicit="True"), None))
# 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.
# Keep a cache of dir actions with salvage-from attrs.
# Since directories are installed in top-down order,
# we need this list to make sure we salvage contents
# as accurately as possible. For example, where:
#
# and
#
# We must ensure that we don't try to salvage
# is being installed, otherwise that content will
# the salvaged to the wrong place.
"""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:
self.__xfersize += \
self.__xferfiles += \
"").split())
"""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))
if self.destination_fmri:
return self.destination_fmri
if self.origin_fmri:
return self.origin_fmri
return None
"""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)
""" 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 as e:
raise
""" handle action updates"""
try:
# Don't log these as they're expected, and should be
# handled by the caller.
raise
except Exception as e:
raise
""" handle action removals"""
try:
# Don't log these as they're expected, and should be
# handled by the caller.
raise
except Exception as e:
raise
"""handle a retry operation"""
"""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
# The salvaged locations known to us are a list of tuples of
# the form (old dir, lost+found salvage dir) and stored in
# self.image.imageplan.pd._salvaged[:]
#
# Check if this salvage-from is also the best match for other
# possibly previously packaged subdirs of this directory.
# with its files.
#
# On the other hand, if we package another directory, with
# to salvage the .ssh content, not the action that salvages
#
continue
return self.__destination_mfst
return self.__origin_mfst