#
# 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
#
#
#
from . import testutils
if __name__ == "__main__":
import pkg5unittest
import os
import shutil
import subprocess
import tempfile
import unittest
# Cleanup after every test.
# The 1.0 version of each package will be in the reference repo,
# the 2.0 version in the target.
# Since we publish the expected package to an additional repo, we have
# to set the timestamps to make sure the target and expected packages
# are equal.
# The test cases are mainly in the different types of packages we
# have in the repo.
# Test cases:
# Pkg with no content change, should be reversioned.
# Pkg has all sorts of actions to make sure everything gets moved
# correctly.
tiger_ref = """
open tiger@1.0,5.11-0:20000101T000000Z
add group groupname=galeocerdones gid=123
close
"""
tiger_targ = """
open tiger@2.0,5.11-0:20000101T000000Z
add group groupname=galeocerdones gid=123
close
"""
# Another basic pkg which gets reversioned
sandtiger_ref = """
open sandtiger@1.0,5.11-0:20000101T000000Z
close
"""
sandtiger_targ = """
open sandtiger@2.0,5.11-0:20000101T000000Z
close
"""
# Basic package with content change, should not be reversioned.
# These packages deliver the same file but the target one's gelf signed
# content-hash value will be changed.
elftest_ref = """
open elftest@1.0,5.11-0:20000101T000000Z
add file ro_data/elftest.so.1 mode=0755 owner=root group=bin path=/bin/true
close
"""
elftest_targ = """
open elftest@2.0,5.11-0:20000101T000000Z
add file ro_data/elftest.so.1 mode=0755 owner=root group=bin path=/bin/true
close
"""
# Basic package with content change, should not be reversioned.
# These packages deliver different files, but they have the same gelf
# content-hash values.
elfdiff_ref = """
open elfdiff@1.0,5.11-0:20000101T000000Z
add file ro_data/elftest.so.1 mode=0755 owner=root group=bin path=/bin/false
close
"""
elfdiff_targ = """
open elfdiff@2.0,5.11-0:20000101T000000Z
add file ro_data/elftest.so.2 mode=0755 owner=root group=bin path=/bin/false
close
"""
# Basic package with content change, should not be reversioned.
hammerhead_ref = """
open hammerhead@1.0,5.11-0:20000101T000000Z
add file tmp/bat mode=0444 owner=root group=bin path=/etc/hammerhead
close
"""
hammerhead_targ = """
open hammerhead@2.0,5.11-0:20000101T000000Z
add file tmp/bat mode=0644 owner=root group=bin path=/etc/hammerhead
close
"""
# Package has only dep change but dependency package changed,
# should not be reversioned.
blue_ref = """
open blue@1.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/hammerhead@1.0 type=require
close
"""
blue_targ = """
open blue@2.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/hammerhead@2.0 type=require
close
"""
# Same as above but let's try an additional level in the dep chain.
bull_ref = """
open bull@1.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/blue@1.0 type=require
close
"""
bull_targ = """
open bull@2.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/blue@2.0 type=require
close
"""
# Package has only dep change and dependency package didn't change,
# should be reversioned.
mako_ref = """
open mako@1.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/tiger@1.0 type=require
close
"""
mako_targ = """
open mako@2.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/tiger@2.0 type=require
close
"""
# Same as above but let's try an additional level in the dep chain.
white_ref = """
open white@1.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/mako@1.0 type=require
close
"""
white_targ = """
open white@2.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/mako@2.0 type=require
close
"""
# Package has content change but depends on package which got reversioned,
# dependencies should be fixed.
# Pkg has all sorts of actions to make sure everything gets moved
# correctly.
angel_ref = """
open angel@1.0,5.11-0:20000101T000000Z
add group groupname=squatinae gid=123
add depend fmri=pkg:/tiger@1.0 type=require
add depend fmri=pkg:/hammerhead@1.0 type=require
close
"""
angel_targ = """
open angel@2.0,5.11-0:20000101T000000Z
add group groupname=squatinae gid=123
add depend fmri=pkg:/tiger@2.0 type=require
add depend fmri=pkg:/hammerhead@2.0 type=require
close
"""
angel_exp = """
open angel@2.0,5.11-0:20000101T000000Z
add group groupname=squatinae gid=123
add depend fmri=pkg:/tiger@1.0 type=require
add depend fmri=pkg:/hammerhead@2.0 type=require
close
"""
# Package has content change and depends on package which didn't get
# reversioned, shouldn't be touched.
horn_ref = """
open horn@1.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/hammerhead@1.0 type=require
close
"""
horn_targ = """
open horn@2.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/hammerhead@2.0 type=require
close
"""
# Package has content change but has require-any dep on package which
# got reversioned, dependencies should be fixed.
lemon_ref = """
open lemon@1.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/angel@1.0 fmri=pkg:/tiger@1.0 type=require-any
close
"""
lemon_targ = """
open lemon@2.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/angel@2.0 fmri=pkg:/tiger@2.0 type=require-any
close
"""
lemon_exp = """
open lemon@2.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/angel@2.0 fmri=pkg:/tiger@1.0 type=require-any
close
"""
# Package has content change but has require-any dep on package which
# got reversioned, however, the require-any dependency wasn't in the old
# version. The version of the pkg in the ref repo should be substituted
# for tiger but not for sandtiger (since dep pkg is still successor of
# dep FMRI).
leopard_ref = """
open leopard@1.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/blue@1.0 fmri=pkg:/angel@1.0 type=require-any
close
"""
leopard_targ = """
open leopard@2.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/blue@2.0 fmri=pkg:/angel@2.0 fmri=pkg:/tiger@2.0 fmri=pkg:/sandtiger@1.0 type=require-any
close
"""
leopard_exp = """
open leopard@2.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/blue@2.0 fmri=pkg:/angel@2.0 fmri=pkg:/tiger@1.0-0 fmri=pkg:/sandtiger@1.0 type=require-any
close
"""
# Package has no content change but dependency stem changed, should
# always be treated as content change.
blacktip_ref = """
open blacktip@1.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/tiger@1.0 type=require
close
"""
blacktip_targ = """
open blacktip@2.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/hammerhead@2.0 type=require
close
"""
# Package has no content change but dependency got added, should
# always be treated as content change, other dependencies should be
# adjusted.
whitetip_ref = """
open whitetip@1.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/tiger@1.0 type=require
close
"""
whitetip_targ = """
open whitetip@2.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/tiger@2.0 type=require
add depend fmri=pkg:/hammerhead@2.0 type=require
close
"""
whitetip_exp = """
open whitetip@2.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/tiger@1.0 type=require
add depend fmri=pkg:/hammerhead@2.0 type=require
close
"""
# Package has no content change but a change in an attribute,
# should be treated as content change by default but reversioned if
# proper CLI options are given (goblin_exp is just for the default
# behavior, gets modified in actual test case)
goblin_ref = """
open goblin@1.0,5.11-0:20000101T000000Z
add set name=info.home value="deep sea"
close
"""
goblin_targ = """
open goblin@2.0,5.11-0:20000101T000000Z
add set name=info.home value="deeper sea"
close
"""
# Package only found in target, not in ref, with dependency on
# reversioned package. Dependency should be fixed.
reef_targ = """
open reef@2.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/tiger@2.0 type=require
close
"""
reef_exp = """
open reef@2.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/tiger@1.0-0 type=require
close
"""
# Package is exactly the same as in ref repo, shouldn't be touched
sandbar_targ = """
open sandbar@1.0,5.11-0:20000101T000000Z
close
"""
sandbar_ref = """
open sandbar@1.0,5.11-0:20000101T000000Z
close
"""
# Packages with circular dependency and no change in dep chain.
greenland_ref = """
open greenland@1.0,5.11-0:20000101T000000Z
add depend fmri=sleeper@1.0 type=require
close
"""
greenland_targ = """
open greenland@2.0,5.11-0:20000101T000000Z
add depend fmri=sleeper@2.0 type=require
close
"""
sleeper_ref = """
open sleeper@1.0,5.11-0:20000101T000000Z
add depend fmri=greenland@1.0 type=require
close
"""
sleeper_targ = """
open sleeper@2.0,5.11-0:20000101T000000Z
add depend fmri=greenland@2.0 type=require
close
"""
# Check for correct handling of Varcets. Pkg contains same dep FMRI stem
# twice. It also covers the case where a facet changes and the tool has
# to sustitute the version in the ref repo (sandtiger case).
whale_ref = """
open whale@1.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/tiger@1.0 facet.version-lock=True type=require
add depend fmri=pkg:/tiger type=require
add depend fmri=pkg:/sandtiger@1.0 facet.version-lock=False type=require
close
"""
whale_targ = """
open whale@2.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/tiger@2.0 facet.version-lock=True type=require
add depend fmri=pkg:/tiger type=require
add depend fmri=pkg:/sandtiger@2.0 facet.version-lock=True type=require
close
"""
whale_exp = """
open whale@2.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/tiger@1.0 facet.version-lock=True type=require
add depend fmri=pkg:/tiger type=require
add depend fmri=pkg:/sandtiger@1.0-0 facet.version-lock=True type=require
close
"""
# Pkg in ref repo is newer than the one in target.
# Should not be reversioned.
thresher_ref = """
open thresher@2.0,5.11-0:20000101T000000Z
close
"""
thresher_targ = """
open thresher@1.0,5.11-0:20000101T000000Z
close
"""
# Package only found in target, not in ref.
# Package has a dep on a reversioned pkg, but the reversioned pkg is
# still a successor of the dep FMRI.
# The dep should not be changed.
bamboo_targ = """
open bamboo@2.0,5.11-0:20000101T000000Z
add depend fmri=pkg:/tiger@1 type=require
close
"""
# Create some packages for an additional publisher
humpback_targ = """
close
"""
humpback_ref = """
close
"""
"white", "angel", "horn", "lemon", "leopard", "blacktip",
"whitetip", "goblin", "reef", "sandbar", "greenland", "sleeper",
"whale", "thresher", "bamboo", "elftest", "elfdiff"]
"""Start 3 depots, 1 for reference repo, 1 for the target and
1 which should be equal to the reversioned target.
"""
ref = s + "_ref"
targ = s + "_targ"
exp = s + "_exp"
try:
except AttributeError:
# reef_ref, bamboo_ref don't exist intentionally
pass
# keep a tmp repo to copy the target into for each new test
"""Check for correct input handling."""
# invalid patterns for -c
# Check that -n doesn't modify repo.
"""Change the content-hash attr in the manifest located at the
target and expected repos."""
# Find elftest package
if "elftest" in s:
break
# load manifest, change content-hash attr and store back
# to disk
for a in mani.gen_actions():
# change the signed version of hash of
# the ELF file
a.attrs["pkg.content-hash"][
0] = "gelf:sha512t_256:foo"
# rebuild repo catalog since manifest digest changed
"""Test basic resurfacing operation."""
# Copy target repo to tmp repo
{ "selachii": "selachii" })
# The new repository won't have a catalog, so rebuild it.
# Check that empty repos get handled correctly
# No repo at all
# Repo empty
# No packages
# Now check if it actually works.
for s in self.published_exp:
# Load target manifest
# Load expected manifest
# Check that pkgsurf informed the user that there is a newer
# version of a pkg in the ref repo.
# Check that ignore option works.
# Just run again and see if goblin pkg now gets reversioned.
# Find goblin package
for s in self.published_ref:
if "goblin" in s:
break
# Check that running the tool again doesn't find any pkgs
# to reversion. Use http for accessing reference repo this time.
# Copy target repo to tmp repo
{"selachii": "selachii"})
# The new repository won't have a catalog, so rebuild it.
# If '-u' is enabled, we just check the unsigned version of
# hashes so that the target basic package is treated as no
# content change and should be reversioned.
# Replace elftest package in the expected repo.
if "elftest" in s:
if "elfdiff" in s:
# Check that '-u' option works and should not affect other
# packages.
for s in self.published_exp:
# Load target manifest
# Load expected manifest
"""Tests for correct publisher handling."""
# Copy target repo to tmp repo
{ "selachii": "selachii" })
# The new repository won't have a catalog, so rebuild it.
# Add a package from a different publisher to target
# Test that unknown publisher in ref repo gets skipped without
# issue.
# Test that we also print a skipping notice
# Test that we fail if we specify a publisher which is not in
# reference repo.
# Now add packages from the 2nd pub to the ref repo
# Test that only specified publisher is processed
# Now do an actual resurfacing of just one publisher
# Check if we see anything about the unspecified publisher
# in the output.
# Check if we didn't reversion packages of the unspecified
# publisher.
"""Test for correct handling of user specified packages which
should not get reversioned."""
# Copy target repo to tmp repo
{ "selachii": "selachii" })
# The new repository won't have a catalog, so rebuild it.
# Check multiple patterns with globbing
# Check specific name.
if __name__ == "__main__":