--- a/doc/image.txt Wed Dec 17 12:04:15 2008 -0600
+++ b/doc/image.txt Wed Dec 17 13:24:33 2008 -0600
@@ -88,6 +88,7 @@
/prefix pkg: authority
/origin http:, https:, or ftp: URL
/mirrors list of URLs
+ /disabled boolean indicating whether authority should be used
Image properties. The image has a collection of simple properties,
like machine type and policies that control the behavior of the pkg(5)
--- a/src/client.py Wed Dec 17 12:04:15 2008 -0600
+++ b/src/client.py Wed Dec 17 13:24:33 2008 -0600
@@ -139,12 +139,12 @@
pkg unset-property propname ...
pkg property [-H] [propname ...]
- pkg set-authority [-P] [-k ssl_key] [-c ssl_cert] [--reset-uuid]
+ pkg set-authority [-Ped] [-k ssl_key] [-c ssl_cert] [--reset-uuid]
[-O origin_url] [-m mirror_to_add | --add-mirror=mirror_to_add]
[-M mirror_to_remove | --remove-mirror=mirror_to_remove]
- [--no-refresh] authority
+ [--enable] [--disable] [--no-refresh] authority
pkg unset-authority authority ...
- pkg authority [-HP] [authority ...]
+ pkg authority [-HPa] [authority ...]
pkg history [-Hl]
pkg purge-history
pkg rebuild-index
@@ -1454,7 +1454,7 @@
try:
api_inst.refresh(full_refresh, pargs)
except api_errors.UnrecognizedAuthorityException, e:
- tmp = _("%s is not a recognized authority to " \
+ tmp = _("%s is not a recognized or enabled authority to " \
"refresh. \n'pkg authority' will show a" \
" list of authorities.")
error(tmp % e.auth)
@@ -1468,9 +1468,9 @@
return 0
def authority_set(img, args):
- """pkg set-authority [-P] [-k ssl_key] [-c ssl_cert] [--reset-uuid]
+ """pkg set-authority [-Ped] [-k ssl_key] [-c ssl_cert] [--reset-uuid]
[-O origin_url] [-m mirror to add] [-M mirror to remove]
- [--no-refresh] authority"""
+ [--enable] [--disable] [--no-refresh] authority"""
preferred = False
ssl_key = None
@@ -1480,9 +1480,11 @@
add_mirror = None
remove_mirror = None
refresh_catalogs = True
+ disable = None
- opts, pargs = getopt.getopt(args, "Pk:c:O:M:m:",
- ["add-mirror=", "remove-mirror=", "no-refresh", "reset-uuid"])
+ opts, pargs = getopt.getopt(args, "Pedk:c:O:M:m:",
+ ["add-mirror=", "remove-mirror=", "no-refresh", "reset-uuid",
+ "enable", "disable"])
for opt, arg in opts:
if opt == "-P":
@@ -1501,6 +1503,10 @@
refresh_catalogs = False
if opt == "--reset-uuid":
reset_uuid = True
+ if opt == "-e" or opt == "--enable":
+ disable = False
+ if opt == "-d" or opt == "--disable":
+ disable = True
if len(pargs) == 0:
usage(
@@ -1539,6 +1545,10 @@
error(_("set-authority: authority URL is invalid"))
return 1
+ if disable and auth == img.get_default_authority():
+ error(_("set-authority: cannot disable the preferred authority"))
+ return 1
+
uuid = None
if reset_uuid:
uuid = pkg.Uuid25.uuid1()
@@ -1546,7 +1556,8 @@
try:
img.set_authority(auth, origin_url=origin_url,
ssl_key=ssl_key, ssl_cert=ssl_cert,
- refresh_allowed=refresh_catalogs, uuid=uuid)
+ refresh_allowed=refresh_catalogs, uuid=uuid,
+ disabled=disable)
except api_errors.CatalogRefreshException, e:
text = "Could not refresh the catalog for %s"
error(_(text) % auth)
@@ -1558,9 +1569,11 @@
return 1
if preferred:
+ if img.get_authority(auth)["disabled"]:
+ error(_("set-authority: the preferred authority must be enabled"))
+ return 1
img.set_preferred_authority(auth)
-
if add_mirror:
if not misc.valid_auth_url(add_mirror):
@@ -1625,13 +1638,16 @@
omit_headers = False
preferred_only = False
preferred_authority = img.get_default_authority()
+ inc_disabled = False
- opts, pargs = getopt.getopt(args, "HP")
+ opts, pargs = getopt.getopt(args, "HPa")
for opt, arg in opts:
if opt == "-H":
omit_headers = True
if opt == "-P":
preferred_only = True
+ if opt == "-a":
+ inc_disabled = True
if len(pargs) == 0:
if not omit_headers:
@@ -1640,7 +1656,7 @@
if preferred_only:
auths = [img.get_authority(preferred_authority)]
else:
- auths = img.gen_authorities()
+ auths = img.gen_authorities(inc_disabled=inc_disabled)
for a in auths:
# summary list
@@ -1649,6 +1665,8 @@
if not preferred_only and pfx == preferred_authority:
pfx += " (preferred)"
+ if a["disabled"]:
+ pfx += " (disabled)"
msg("%-35s %s" % (pfx, url))
else:
img.load_catalogs(get_tracker())
@@ -1701,6 +1719,10 @@
msg(" UUID:", auth["uuid"])
msg(" Catalog Updated:", dt)
msg(" Mirrors:", mir)
+ e = "Yes"
+ if auth["disabled"]:
+ e = "No"
+ msg(" Enabled:", e)
return 0
--- a/src/man/pkg.1.txt Wed Dec 17 12:04:15 2008 -0600
+++ b/src/man/pkg.1.txt Wed Dec 17 13:24:33 2008 -0600
@@ -29,12 +29,12 @@
/usr/bin/pkg unset-property propname ...
/usr/bin/pkg property [-H] [propname ...]
- /usr/bin/pkg set-authority [-P] [-k ssl_key] [-c ssl_cert]
+ /usr/bin/pkg set-authority [-Ped] [-k ssl_key] [-c ssl_cert]
[-O origin_url] [-m mirror_to_add | --add-mirror=mirror_to_add]
[-M mirror_to_remove | --remove-mirror=mirror_to_remove]
- [--no-refresh] [--reset-uuid] authority
+ [--enable] [--disable] [--no-refresh] [--reset-uuid] authority
/usr/bin/pkg unset-authority authority ...
- /usr/bin/pkg authority [-HP] [authority ...]
+ /usr/bin/pkg authority [-HPa] [authority ...]
/usr/bin/pkg history [-Hl]
/usr/bin/pkg purge-history
@@ -256,10 +256,10 @@
property names is requested, display the names and values for those
properties. With -H, omit the headers from the listing.
- set-authority [-P] [-k ssl_key] [-c ssl_cert] [-O origin_url]
+ set-authority [-Ped] [-k ssl_key] [-c ssl_cert] [-O origin_url]
[-m mirror_to_add | --add-mirror=mirror_to_add]
[-M mirror_to_remove | --remove-mirror=mirror_to_remove]
- [--no-refresh] [--reset-uuid] authority
+ [--enable] [--disable] [--no-refresh] [--reset-uuid] authority
Update an existing authority or add an additional package
authority. With -P, set the specified authority as the
preferred authority. With -c and -k, specify client SSL
@@ -278,17 +278,25 @@
With -M (--remove-mirror), remove the URL from the list of mirrors
for the given authority.
+ With -e (--enable), enable the authority; with -d (--disable), disable
+ the authority. A disabled authority is not used when populating the
+ package list or in certain package operations (install, uninstall, and
+ image-update). However, the properties for a disabled authority can
+ still be set and viewed. If only one authority exists, it cannot be
+ disabled.
+
unset-authority authority ...
Remove the configuration associated with the given authority
or authorities.
- authority [-HP] [authority ...]
+ authority [-HPa] [authority ...]
Display authority information. With no arguments, display the
- list of configured authorities, and their origin URLs. If
+ list of enabled authorities, and their origin URLs. If
specific authorities are requested, display the configuration
values, including mirrors, associated with those authorities. With
-H, omit the headers from the listing. With -P, display only the
- preferred authority.
+ preferred authority. With -a, display all authorities (including those
+ that are disabled).
history [-Hl]
Displays the command history of the applicable image. With -H, omit
--- a/src/modules/client/api.py Wed Dec 17 12:04:15 2008 -0600
+++ b/src/modules/client/api.py Wed Dec 17 13:24:33 2008 -0600
@@ -557,10 +557,12 @@
auths = []
for auth in auths:
try:
- auth = self.img.get_authority(auth)
+ a = self.img.get_authority(auth)
except KeyError:
raise api_errors.UnrecognizedAuthorityException(auth)
- auths_to_refresh.append(auth)
+ if a["disabled"]:
+ raise api_errors.UnrecognizedAuthorityException(auth)
+ auths_to_refresh.append(a)
# Ensure Image directory structure is valid.
--- a/src/modules/client/image.py Wed Dec 17 12:04:15 2008 -0600
+++ b/src/modules/client/image.py Wed Dec 17 13:24:33 2008 -0600
@@ -207,12 +207,12 @@
rv = None
if os.path.isdir(os.path.join(d, img_user_prefix)) and \
os.path.isfile(os.path.join(d, img_user_prefix,
- "cfg_cache")) and \
+ imageconfig.CFG_FILE)) and \
self._check_subdirs(d, img_user_prefix):
rv = IMG_USER
elif os.path.isdir(os.path.join(d, img_root_prefix)) \
and os.path.isfile(os.path.join(d,
- img_root_prefix, "cfg_cache")) and \
+ img_root_prefix, imageconfig.CFG_FILE)) and \
self._check_subdirs(d, img_root_prefix):
rv = IMG_ENTIRE
return rv
@@ -275,14 +275,12 @@
raise RuntimeError, "self.root must be set"
ic = imageconfig.ImageConfig()
-
- if os.path.isfile("%s/cfg_cache" % self.imgdir):
- ic.read("%s/cfg_cache" % self.imgdir)
+ ic.read(self.imgdir)
self.cfg_cache = ic
def save_config(self):
- self.cfg_cache.write("%s/cfg_cache" % self.imgdir)
+ self.cfg_cache.write(self.imgdir)
# XXX mkdirs and set_attrs() need to be combined into a create
# operation.
@@ -315,7 +313,7 @@
ssl_key = None, ssl_cert = None):
self.__set_dirs(imgtype=type, root=root)
- if not os.path.exists(os.path.join(self.imgdir, "cfg_cache")):
+ if not os.path.exists(os.path.join(self.imgdir, imageconfig.CFG_FILE)):
self.history.operation_name = "image-create"
else:
self.history.operation_name = "image-set-attributes"
@@ -331,6 +329,7 @@
self.cfg_cache.authorities[auth_name]["prefix"] = auth_name
self.cfg_cache.authorities[auth_name]["origin"] = \
misc.url_affix_trailing_slash(auth_url)
+ self.cfg_cache.authorities[auth_name]["disabled"] = False
self.cfg_cache.authorities[auth_name]["mirrors"] = []
self.cfg_cache.authorities[auth_name]["ssl_key"] = ssl_key
self.cfg_cache.authorities[auth_name]["ssl_cert"] = ssl_cert
@@ -351,13 +350,15 @@
def get_root(self):
return self.root
- def gen_authorities(self):
+ def gen_authorities(self, inc_disabled = False):
if not self.cfg_cache:
raise RuntimeError, "empty ImageConfig"
if not self.cfg_cache.authorities:
raise RuntimeError, "no defined authorities"
for a in self.cfg_cache.authorities:
- yield self.cfg_cache.authorities[a]
+ auth = self.cfg_cache.authorities[a]
+ if inc_disabled or not auth["disabled"]:
+ yield self.cfg_cache.authorities[a]
def get_url_by_authority(self, authority = None):
"""Return the URL prefix associated with the given authority.
@@ -623,12 +624,19 @@
self.history.operation_result = \
history.RESULT_FAILED_UNKNOWN
raise KeyError, error
+ if self.get_authority(auth_name)["disabled"]:
+ error = "authority '%s' is disabled" % auth_name
+ self.history.operation_errors.append(error)
+ self.history.operation_result = \
+ history.RESULT_FAILED_BAD_REQUEST
+ raise KeyError, error
self.cfg_cache.preferred_authority = auth_name
self.save_config()
self.history.operation_result = history.RESULT_SUCCEEDED
def set_authority(self, auth_name, origin_url = None, ssl_key = None,
- ssl_cert = None, refresh_allowed = True, uuid = None):
+ ssl_cert = None, refresh_allowed = True, uuid = None,
+ disabled = None):
self.history.operation_name = "set-authority"
auths = self.cfg_cache.authorities
@@ -647,6 +655,13 @@
auths[auth_name]["ssl_cert"] = ssl_cert
if uuid:
auths[auth_name]["uuid"] = uuid
+ if disabled != None:
+ # don't make the perferred authority disabled
+ # the caller is responsible for checking this
+ assert(not disabled or \
+ auth_name != self.get_default_authority())
+ auths[auth_name]["disabled"] = disabled
+ refresh_needed = True
else:
auths[auth_name] = {}
@@ -659,6 +674,9 @@
if not uuid:
uuid = pkg.Uuid25.uuid1()
auths[auth_name]["uuid"] = uuid
+ if disabled is None:
+ disabled = False
+ auths[auth_name]["disabled"] = disabled
refresh_needed = True
self.save_config()
@@ -1371,6 +1389,9 @@
progtrack.refresh_start(len(auths))
for auth in auths:
+ if auth["disabled"]:
+ continue
+
total += 1
if progtrack:
progtrack.refresh_progress(auth["prefix"])
--- a/src/modules/client/imageconfig.py Wed Dec 17 12:04:15 2008 -0600
+++ b/src/modules/client/imageconfig.py Wed Dec 17 13:24:33 2008 -0600
@@ -26,10 +26,12 @@
import ConfigParser
import re
import errno
+import os.path
import pkg.fmri as fmri
import pkg.misc as misc
import pkg.client.api_errors as api_errors
from pkg.misc import msg
+import pkg.portable as portable
class DepotStatus(object):
"""An object that encapsulates status about a depot server.
@@ -82,6 +84,10 @@
SEND_UUID: False,
}
+# names of image configuration files managed by this module
+CFG_FILE = "cfg_cache"
+DA_FILE = "disabled_auth"
+
class ImageConfig(object):
"""An ImageConfig object is a collection of configuration information:
URLs, authorities, properties, etc. that allow an Image to operate."""
@@ -119,61 +125,23 @@
return policystr.lower() in ("true", "yes")
return default_policies[policy]
- def read(self, path):
- """Read the given file as if it were a configuration cache for
- pkg(1)."""
+ def read(self, dir):
+ """Read the config files for the image from the given directory."""
cp = ConfigParser.SafeConfigParser()
- r = cp.read(path)
+ ccfile = os.path.join(dir, CFG_FILE)
+ r = cp.read(ccfile)
if len(r) == 0:
- raise RuntimeError("Couldn't read configuration %s" % path)
+ raise RuntimeError("Couldn't read configuration from %s" % ccfile)
- assert r[0] == path
+ assert r[0] == ccfile
for s in cp.sections():
if re.match("authority_.*", s):
- # authority block has prefix, origin, and
- # mirrors
- a = {}
+ k, a = self.read_authority(cp, s)
ms = []
- k = cp.get(s, "prefix")
-
- if k.startswith(fmri.PREF_AUTH_PFX):
- raise RuntimeError(
- "Invalid Authority name: %s" % k)
-
- a["prefix"] = k
- a["origin"] = cp.get(s, "origin")
- mir_str = cp.get(s, "mirrors")
- if mir_str == "None":
- a["mirrors"] = []
- else:
- a["mirrors"] = self.read_list(mir_str)
-
- try:
- a["ssl_key"] = cp.get(s, "ssl_key")
- if a["ssl_key"] == "None":
- a["ssl_key"] = None
- except ConfigParser.NoOptionError:
- a["ssl_key"] = None
-
- try:
- a["ssl_cert"] = cp.get(s, "ssl_cert")
- if a["ssl_cert"] == "None":
- a["ssl_cert"] = None
- except ConfigParser.NoOptionError:
- a["ssl_cert"] = None
-
- try:
- a["uuid"] = cp.get(s, "uuid")
- except ConfigParser.NoOptionError:
- a["uuid"] = "None"
-
- a["origin"] = \
- misc.url_affix_trailing_slash(a["origin"])
-
self.authorities[k] = a
self.authority_status[k] = DepotStatus(k,
a["origin"])
@@ -204,9 +172,28 @@
if "preferred-authority" in self.properties:
self.preferred_authority = self.properties["preferred-authority"]
- def write(self, path):
+ # read disabled authority file
+ # XXX when compatility with the old code is no longer needed,
+ # this can be removed
cp = ConfigParser.SafeConfigParser()
+ dafile = os.path.join(dir, DA_FILE)
+ if os.path.exists(dafile):
+ r = cp.read(dafile)
+ if len(r) == 0:
+ raise RuntimeError("Couldn't read configuration from %s" % dafile)
+ for s in cp.sections():
+ if re.match("authority_.*", s):
+ k, a = self.read_authority(cp, s)
+ self.authorities[k] = a
+ # status objects are not created for
+ # disabled authorities
+ def write(self, dir):
+ """Write the configuration to the given directory"""
+ cp = ConfigParser.SafeConfigParser()
+ # XXX the use of the disabled_auth file can be removed when
+ # compatibility with the older code is no longer needed
+ da = ConfigParser.SafeConfigParser()
self.properties["preferred-authority"] = self.preferred_authority
cp.add_section("property")
@@ -218,33 +205,38 @@
cp.set("filter", f, str(self.filters[f]))
for a in self.authorities:
- section = "authority_%s" % self.authorities[a]["prefix"]
+ auth = self.authorities[a]
+ section = "authority_%s" % auth["prefix"]
- cp.add_section(section)
+ c = cp
+ if auth["disabled"]:
+ c = da
- cp.set(section, "prefix",
- self.authorities[a]["prefix"])
- cp.set(section, "origin",
- self.authorities[a]["origin"])
- cp.set(section, "mirrors",
- str(self.authorities[a]["mirrors"]))
- cp.set(section, "ssl_key",
- str(self.authorities[a]["ssl_key"]))
- cp.set(section, "ssl_cert",
- str(self.authorities[a]["ssl_cert"]))
- cp.set(section, "uuid",
- str(self.authorities[a]["uuid"]))
+ c.add_section(section)
+ c.set(section, "prefix", auth["prefix"])
+ c.set(section, "origin", auth["origin"])
+ c.set(section, "disabled", str(auth["disabled"]))
+ c.set(section, "mirrors", str(auth["mirrors"]))
+ c.set(section, "ssl_key", str(auth["ssl_key"]))
+ c.set(section, "ssl_cert", str(auth["ssl_cert"]))
+ c.set(section, "uuid", str(auth["uuid"]))
# XXX Child images
- try:
- f = open(path, "w")
- except EnvironmentError, e:
- if e.errno == errno.EACCES:
- raise api_errors.PermissionsException(
- e.filename)
- raise
- cp.write(f)
+ for afile, acp in [(CFG_FILE, cp), (DA_FILE, da)]:
+ thefile = os.path.join(dir, afile)
+ if len(acp.sections()) == 0:
+ if os.path.exists(thefile):
+ portable.remove(thefile)
+ continue
+ try:
+ f = open(thefile, "w")
+ except EnvironmentError, e:
+ if e.errno == errno.EACCES:
+ raise api_errors.PermissionsException(
+ e.filename)
+ raise
+ acp.write(f)
def delete_authority(self, auth):
del self.authorities[auth]
@@ -264,3 +256,50 @@
lst = [ s for s in lst if s != '' ]
return lst
+
+ def read_authority(self, cp, s):
+ # authority block has prefix, origin, and mirrors
+ a = {}
+ k = cp.get(s, "prefix")
+
+ if k.startswith(fmri.PREF_AUTH_PFX):
+ raise RuntimeError(
+ "Invalid Authority name: %s" % k)
+
+ a["prefix"] = k
+ a["origin"] = cp.get(s, "origin")
+ try:
+ d = cp.get(s, "disabled")
+ except ConfigParser.NoOptionError:
+ d = 'False'
+ a["disabled"] = d.lower() in ("true", "yes")
+
+ mir_str = cp.get(s, "mirrors")
+ if mir_str == "None":
+ a["mirrors"] = []
+ else:
+ a["mirrors"] = self.read_list(mir_str)
+
+ try:
+ a["ssl_key"] = cp.get(s, "ssl_key")
+ if a["ssl_key"] == "None":
+ a["ssl_key"] = None
+ except ConfigParser.NoOptionError:
+ a["ssl_key"] = None
+
+ try:
+ a["ssl_cert"] = cp.get(s, "ssl_cert")
+ if a["ssl_cert"] == "None":
+ a["ssl_cert"] = None
+ except ConfigParser.NoOptionError:
+ a["ssl_cert"] = None
+
+ try:
+ a["uuid"] = cp.get(s, "uuid")
+ except ConfigParser.NoOptionError:
+ a["uuid"] = "None"
+
+ a["origin"] = \
+ misc.url_affix_trailing_slash(a["origin"])
+
+ return k, a
--- a/src/tests/api/t_imageconfig.py Wed Dec 17 12:04:15 2008 -0600
+++ b/src/tests/api/t_imageconfig.py Wed Dec 17 13:24:33 2008 -0600
@@ -25,6 +25,7 @@
import unittest
import os
+import shutil
import sys
import tempfile
import pkg.client.imageconfig as imageconfig
@@ -36,11 +37,11 @@
class TestImageConfig(pkg5unittest.Pkg5TestCase):
def setUp(self):
+ self.sample_dir = tempfile.mkdtemp()
+ cfgfile = os.path.join(self.sample_dir, imageconfig.CFG_FILE)
+ f = open(cfgfile, "w")
- fd, self.sample_conf = tempfile.mkstemp()
- f = os.fdopen(fd, "w")
-
- f.write("""\
+ f.write("""\
[policy]
Display-Copyrights: False
@@ -55,35 +56,35 @@
ssl_cert:
""")
f.close()
- self.ic = imageconfig.ImageConfig()
+ self.ic = imageconfig.ImageConfig()
def tearDown(self):
- try:
- os.remove(self.sample_conf)
- except:
- pass
+ try:
+ shutil.rmtree(self.sample_dir)
+ except:
+ pass
- def test_read(self):
- self.ic.read(self.sample_conf)
+ def test_read(self):
+ self.ic.read(self.sample_dir)
def test_unicode(self):
- self.ic.read(self.sample_conf)
+ self.ic.read(self.sample_dir)
ustr = u'abc\u3041def'
self.ic.properties['name'] = ustr
- fd, fname = tempfile.mkstemp()
- os.close(fd)
- self.ic.write(fname)
+ newdir = tempfile.mkdtemp()
+ self.ic.write(newdir)
ic2 = imageconfig.ImageConfig()
- ic2.read(fname)
+ ic2.read(newdir)
ustr2 = ic2.properties['name']
+ shutil.rmtree(newdir)
self.assert_(ustr == ustr2)
- def test_missing_conffile(self):
- #
- # See what happens if the conf file is missing.
- #
- os.remove(self.sample_conf)
- self.assertRaises(RuntimeError, self.ic.read, self.sample_conf)
+ def test_missing_conffile(self):
+ #
+ # See what happens if the conf file is missing.
+ #
+ shutil.rmtree(self.sample_dir)
+ self.assertRaises(RuntimeError, self.ic.read, self.sample_dir)
# XXX more test cases needed.
--- a/src/tests/baseline.txt Wed Dec 17 12:04:15 2008 -0600
+++ b/src/tests/baseline.txt Wed Dec 17 13:24:33 2008 -0600
@@ -228,6 +228,7 @@
cli.t_pkg_authority.py TestPkgAuthorityBasics.test_mirror_longopt|pass
cli.t_pkg_authority.py TestPkgAuthorityBasics.test_missing_perms|pass
cli.t_pkg_authority.py TestPkgAuthorityBasics.test_pkg_authority_bogus_opts|pass
+cli.t_pkg_authority.py TestPkgAuthorityMany.test_enable_disable|pass
cli.t_pkg_contents.py TestPkgContentsBasics.test_contents_1|pass
cli.t_pkg_contents.py TestPkgContentsBasics.test_contents_2|pass
cli.t_pkg_contents.py TestPkgContentsBasics.test_contents_3|pass
--- a/src/tests/cli/t_pkg_authority.py Wed Dec 17 12:04:15 2008 -0600
+++ b/src/tests/cli/t_pkg_authority.py Wed Dec 17 13:24:33 2008 -0600
@@ -38,7 +38,7 @@
def test_pkg_authority_bogus_opts(self):
""" pkg bogus option checks """
- durl = self.dc.get_depot_url()
+ durl = self.dc.get_depot_url()
self.image_create(durl)
self.pkg("set-authority -@ test3", exit=2)
@@ -222,5 +222,60 @@
self.pkg("set-authority --remove-mirror=%s7 mtest" %
self.bogus_url, exit=1)
+class TestPkgAuthorityMany(testutils.ManyDepotTestCase):
+ # Only start/stop the depot once (instead of for every test)
+ persistent_depot = True
+
+ foo1 = """
+ open foo@1,5.11-0
+ close """
+
+ bar1 = """
+ open bar@1,5.11-0
+ close """
+
+ def setUp(self):
+ testutils.ManyDepotTestCase.setUp(self, 2)
+
+ durl1 = self.dcs[1].get_depot_url()
+ self.pkgsend_bulk(durl1, self.foo1)
+
+ durl2 = self.dcs[2].get_depot_url()
+ self.pkgsend_bulk(durl2, self.bar1)
+
+ self.image_create(durl1, prefix = "test1")
+ self.pkg("set-authority -O " + durl2 + " test2")
+
+ def tearDown(self):
+ testutils.ManyDepotTestCase.tearDown(self)
+
+ def test_enable_disable(self):
+ """Test enable and disable."""
+
+ self.pkg("authority | grep test1")
+ self.pkg("authority | grep test2")
+
+ self.pkg("set-authority -d test2")
+ self.pkg("authority | grep test2", exit=1)
+ self.pkg("list -a bar", exit=1)
+ self.pkg("authority -a | grep test2")
+ self.pkg("set-authority -P test2", exit=1)
+ self.pkg("authority test2")
+ self.pkg("set-authority -e test2")
+ self.pkg("authority | grep test2")
+ self.pkg("list -a bar")
+
+ self.pkg("set-authority --disable test2")
+ self.pkg("authority | grep test2", exit=1)
+ self.pkg("list -a bar", exit=1)
+ self.pkg("authority -a | grep test2")
+ self.pkg("set-authority --enable test2")
+ self.pkg("authority | grep test2")
+ self.pkg("list -a bar")
+
+ # should fail because test is the preferred authority
+ self.pkg("set-authority -d test1", exit=1)
+ self.pkg("set-authority --disable test1", exit=1)
+
if __name__ == "__main__":
unittest.main()