remove sha512_t
[unleashed-pkg5.git] / src / tests / cli / t_pkg_sysrepo.py
blobdcbb727873f59484b39fe9eec91bbb8d7e0b1347
1 #!/usr/bin/python2.7
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
24 # Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
27 from __future__ import print_function
28 import testutils
29 if __name__ == "__main__":
30 testutils.setup_environment("../../../proto")
31 import pkg5unittest
33 import copy
34 import os
35 import shutil
37 import pkg.client.api_errors as apx
38 import pkg.client.transport.exception as tx
39 import pkg.digest as digest
40 import pkg.misc as misc
42 class PC(object):
43 """This class contains publisher configuration used for setting up the
44 depots and https apache instances needed by the tests."""
46 def __init__(self, url, sticky=True, mirrors=misc.EmptyI, https=False,
47 server_ta=None, client_ta=None, disabled=False, name=None,
48 sig_pol=None, req_names=None, origins=misc.EmptyI):
49 assert (https and server_ta and client_ta) or \
50 not (https or server_ta or client_ta)
51 assert not disabled or name
52 self.url= url
53 self.sticky = sticky
54 self.https = https
55 self.mirrors = mirrors
56 self.server_ta = server_ta
57 self.client_ta = client_ta
58 self.disabled = disabled
59 self.name = name
60 self.signature_policy = sig_pol
61 self.required_names = req_names
62 self.origins = origins
64 class TestSysrepo(pkg5unittest.ApacheDepotTestCase):
65 """Tests pkg interaction with the system repository."""
67 # Tests in this suite use the read only data directory.
68 need_ro_data = True
70 example_pkg10 = """
71 open example_pkg@1.0,5.11-0
72 add file tmp/example_file mode=0555 owner=root group=bin path=/usr/bin/example_path
73 close"""
75 foo10 = """
76 open foo@1.0,5.11-0
77 close"""
79 foo11 = """
80 open foo@1.1,5.11-0
81 add file tmp/example_file mode=0555 owner=root group=bin path=/usr/bin/example_path2
82 close"""
84 bar10 = """
85 open bar@1.0,5.11-0
86 add file tmp/example_two mode=0555 owner=root group=bin path=/usr/bin/example_path3
87 close"""
89 bar11 = """
90 open bar@1.1,5.11-0
91 add file tmp/example_two mode=0555 owner=root group=bin path=/usr/bin/example_path3
92 add file tmp/example_two mode=0555 owner=root group=bin path=/usr/bin/example_path4
93 close"""
95 baz10 = """
96 open baz@1.0,5.11-0
97 add file tmp/example_three mode=0555 owner=root group=bin path=/usr/bin/another_1
98 close"""
100 caz10 = """
101 open caz@1.0,5.11-0
102 add file tmp/example_four mode=0555 owner=root group=bin path=/usr/bin/another_2
103 close"""
105 misc_files = ["tmp/example_file", "tmp/example_two",
106 "tmp/example_three", "tmp/example_four"]
108 expected_all_access = """\
109 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
110 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
111 test12\tfalse\ttrue\ttrue\torigin\tonline\t{durl2}/\thttp://localhost:{port}
112 test3\ttrue\ttrue\ttrue\torigin\tonline\t{durl3}/\thttp://localhost:{port}
113 test4\ttrue\ttrue\ttrue\t\t\t\t
116 def setUp(self):
117 # These need to be set before calling setUp in case setUp fails.
118 self.smf_cmds = {}
120 # These need to set to allow the smf commands to give the right
121 # responses.
122 self.sysrepo_port = self.next_free_port
123 self.next_free_port += 1
124 self.sysrepo_alt_port = self.next_free_port
125 self.next_free_port += 1
127 # Set up the smf commands that these tests use.
128 smf_conf_dict = {"proxy_port": self.sysrepo_port}
129 for n in self.__smf_cmds_template:
130 self.smf_cmds[n] = self.__smf_cmds_template[n].format(**
131 smf_conf_dict)
133 pkg5unittest.ManyDepotTestCase.setUp(self, ["test1", "test12",
134 "test3", "test4", "test12"], start_depots=True)
135 self.testdata_dir = os.path.join(self.test_root, "testdata")
136 self.make_misc_files(self.misc_files)
138 self.durl1 = self.dcs[1].get_depot_url()
139 self.durl2 = self.dcs[2].get_depot_url()
140 self.durl3 = self.dcs[3].get_depot_url()
142 # we make self.durl3 multi-hash aware, to ensure that the
143 # system-repository can serve packages published with multiple
144 # hashes.
145 self.dcs[3].stop()
146 self.dcs[3].set_debug_feature("hash=sha1+sha256")
147 self.dcs[3].start()
149 self.durl4 = self.dcs[4].get_depot_url()
150 self.durl5 = self.dcs[5].get_depot_url()
152 self.rurl1 = self.dcs[1].get_repo_url()
153 self.rurl2 = self.dcs[2].get_repo_url()
154 self.rurl3 = self.dcs[3].get_repo_url()
155 self.rurl4 = self.dcs[4].get_repo_url()
156 self.rurl5 = self.dcs[5].get_repo_url()
158 self.apache_dir = os.path.join(self.test_root, "apache")
159 self.apache_log_dir = os.path.join(self.apache_dir,
160 "apache_logs")
162 self.pkgsend_bulk(self.rurl1, self.example_pkg10)
163 self.pkgsend_bulk(self.rurl2, self.foo10)
164 # We send to rurl3 using multi-hash aware publication
165 self.pkgsend_bulk(self.rurl3, self.bar10,
166 debug_hash="sha1+sha256")
167 self.pkgsend_bulk(self.rurl3, self.baz10,
168 debug_hash="sha1+sha256")
169 self.pkgsend_bulk(self.rurl4, self.bar10)
170 self.pkgsend_bulk(self.rurl5, self.foo11)
172 self.common_config_dir = os.path.join(self.test_root,
173 "apache-serve")
174 self.htdocs_dir = os.path.join(self.common_config_dir, "htdocs")
175 self.apache_confs = {}
177 # Establish the different publisher configurations that tests
178 # will need. self.configs is a dictionary that maps config
179 # names to tuples of (image properties, PC objects). The image
180 # properties are stored in a dictionary that maps the name of
181 # the property to the value. The list of PC objects represent
182 # the configuration of each publisher.
184 # The self.configs dictionary is used to create images whose
185 # configuration is used by pkg.sysrepo to create the
186 # configuration files needed to set up a system-repository
187 # instance for that image.
188 self.configs = {
189 "all-access": ({}, [
190 PC(self.durl1),
191 PC(self.durl2, sticky=False),
192 PC(self.durl3),
193 PC(None, name="test4")]),
194 "all-access-f": ({}, [
195 PC(self.rurl1),
196 PC(self.rurl2, sticky=False),
197 PC(self.rurl3)]),
198 "disabled": ({}, [
199 PC(self.durl1, disabled=True, name="test1"),
200 PC(self.durl2, sticky=False),
201 PC(self.durl3)]),
202 "https-access": ({}, [
203 PC(self.durl1, https=True, server_ta="ta11",
204 client_ta="ta6"),
205 PC(self.durl2, sticky=False, https=True,
206 server_ta="ta7", client_ta="ta8"),
207 PC(self.durl3, https=True, server_ta="ta9",
208 client_ta="ta10")]),
209 "mirror-access": ({}, [
210 PC(self.durl1, mirrors=[("test1", self.rurl1)]),
211 PC(self.durl2, sticky=False,
212 mirrors=[("test12", self.rurl2)]),
213 PC(self.durl3, mirrors=[("test3", self.rurl3)])]),
214 "mirror-access-f": ({}, [
215 PC(self.rurl1, mirrors=[("test1", self.durl1)]),
216 PC(self.rurl2, sticky=False,
217 mirrors=[("test12", self.durl2)]),
218 PC(self.rurl3, mirrors=[("test3", self.durl3)])]),
219 "mirror-access-user": ({}, [
220 PC(self.durl1, mirrors=[("test1", self.rurl1)]),
221 PC(self.durl2, sticky=False),
222 PC(self.durl3, mirrors=[("test3", self.rurl3)])]),
223 "none": ({}, []),
224 "test1": ({}, [PC(self.durl1)]),
225 "test1-test12": ({}, [
226 PC(self.durl1),
227 PC(self.durl2, sticky=False)]),
228 "test1-test12-test12": ({}, [
229 PC(self.durl1),
230 PC(None,
231 name="test12", origins=[self.durl2, self.durl5],
232 sticky=False)]),
233 "test1-test3": ({}, [
234 PC(self.durl1),
235 PC(self.durl3)]),
236 "test1-test3-f": ({}, [
237 PC(self.rurl1),
238 PC(self.rurl3)]),
239 "test12": ({}, [
240 PC(self.durl2, sticky=False)]),
241 "test12-test12": ({}, [
242 PC(None,
243 name="test12", origins=[self.durl2, self.durl5],
244 sticky=False)]),
245 "test12-test3": ({}, [
246 PC(self.durl2, sticky=False),
247 PC(self.durl3)]),
248 "test3": ({}, [PC(self.durl3)]),
249 "nourl": ({}, [PC(None, name="test4")]),
250 "img-sig-ignore": ({"signature-policy": "ignore"}, [
251 PC(self.rurl1),
252 PC(self.rurl2, sticky=False),
253 PC(self.rurl3)]),
254 "img-sig-require": (
255 {"signature-policy": "require-signatures"}, [
256 PC(self.rurl1),
257 PC(self.rurl2, sticky=False),
258 PC(self.rurl3)]),
259 "img-sig-req-names": ({
260 "signature-policy": "require-names",
261 "signature-required-names": ["cs1_ch1_ta3"]
262 }, [
263 PC(self.rurl1),
264 PC(self.rurl2, sticky=False),
265 PC(self.rurl3)]),
266 "pub-sig-ignore": ({}, [
267 PC(self.rurl1, sig_pol="ignore"),
268 PC(self.rurl2, sticky=False,
269 sig_pol="ignore"),
270 PC(self.rurl3, sig_pol="ignore")]),
271 "pub-sig-require": ({}, [
272 PC(self.rurl1, sig_pol="require-signatures"),
273 PC(self.rurl2, sticky=False,
274 sig_pol="require-signatures"),
275 PC(self.rurl3, sig_pol="require-signatures")]),
276 "pub-sig-reqnames": ({}, [
277 PC(self.rurl1, sig_pol="require-names",
278 req_names="cs1_ch1_ta3"),
279 PC(self.rurl2, sticky=False,
280 sig_pol="require-names", req_names=["cs1_ch1_ta3"]),
281 PC(self.rurl3, sig_pol="require-names",
282 req_names="cs1_ch1_ta3")]),
283 "pub-sig-mixed": ({}, [
284 PC(self.rurl1, sig_pol="require-signatures"),
285 PC(self.rurl2, sticky=False),
286 PC(self.rurl3, sig_pol="verify")]),
287 "img-pub-sig-mixed": ({"signature-policy": "ignore"}, [
288 PC(self.rurl1, sig_pol="require-signatures"),
289 PC(self.rurl2, sticky=False, sig_pol="require-names",
290 req_names=["cs1_ch1_ta3", "foo", "bar", "baz"]),
291 PC(self.rurl3, sig_pol="ignore")]),
294 # Config needed for https apache instances.
295 self.path_to_certs = os.path.join(self.ro_data_root,
296 "signing_certs", "produced")
297 self.keys_dir = os.path.join(self.path_to_certs, "keys")
298 self.cs_dir = os.path.join(self.path_to_certs,
299 "code_signing_certs")
300 self.chain_certs_dir = os.path.join(self.path_to_certs,
301 "chain_certs")
302 self.pub_cas_dir = os.path.join(self.path_to_certs,
303 "publisher_cas")
304 self.inter_certs_dir = os.path.join(self.path_to_certs,
305 "inter_certs")
306 self.raw_trust_anchor_dir = os.path.join(self.path_to_certs,
307 "trust_anchors")
308 self.crl_dir = os.path.join(self.path_to_certs, "crl")
310 self.base_conf_dict = {
311 "common_log_format": "%h %l %u %t \\\"%r\\\" %>s %b",
312 "ssl-special": "%{SSL_CLIENT_I_DN_OU}",
314 # Pick a directory to store all the https apache configuration
315 # in.
316 self.base_https_dir = os.path.join(self.test_root, "https")
318 def __start_https(self, pc):
319 # Start up an https apache config
320 cd = copy.copy(self.base_conf_dict)
322 # This apache instance will need a free port.
323 https_port = self.next_free_port
324 self.next_free_port += 1
326 # Set up the directories and configuration this instance of
327 # apache will need.
328 instance_dir = os.path.join(self.base_https_dir,
329 str(https_port))
330 log_dir = os.path.join(instance_dir, "https_logs")
331 content_dir = os.path.join(instance_dir, "content")
332 os.makedirs(instance_dir)
333 os.makedirs(log_dir)
334 os.makedirs(content_dir)
335 cd.update({
336 "https_port": https_port,
337 "log_locs": log_dir,
338 "pidfile": os.path.join(instance_dir, "httpd.pid"),
339 "port": https_port,
340 "proxied-server": pc.url,
341 "server-ca-cert":os.path.join(self.raw_trust_anchor_dir,
342 "{0}_cert.pem".format(pc.client_ta)),
343 "server-ca-taname": pc.client_ta,
344 "serve_root": content_dir,
345 "server-ssl-cert":os.path.join(self.cs_dir,
346 "cs1_{0}_cert.pem".format(pc.server_ta)),
347 "server-ssl-key":os.path.join(self.keys_dir,
348 "cs1_{0}_key.pem".format(pc.server_ta)),
350 conf_path = os.path.join(instance_dir, "https.conf")
351 with open(conf_path, "wb") as fh:
352 fh.write(self.https_conf.format(**cd))
354 ac = pkg5unittest.ApacheController(conf_path, https_port,
355 instance_dir, testcase=self, https=True)
356 self.register_apache_controller(pc.url, ac)
357 ac.start()
358 return ac
360 def __prep_configuration(self, names, port=None,
361 use_config_cache=False):
362 """Prepare the system repository configuration given either
363 a string corresponding to a key in self.configs, or a list
364 of keys.
366 'port' if used overrides the default port to be used.
368 'use_config_cache' causes us to call pkg.sysrepo twice for each
369 configuration, ensuring that we use the pkg.sysrepo config
370 cached in var/cache/pkg for the actual configuration.
373 if not port:
374 port = self.sysrepo_port
375 self.__configured_names = []
376 if isinstance(names, basestring):
377 names = [names]
378 for name in names:
379 props, pcs = self.configs[name]
380 self.image_create(props=props)
381 for pc in pcs:
382 cmd = "set-publisher"
383 if not pc.sticky:
384 cmd += " --non-sticky"
385 if not pc.https and pc.url:
386 cmd += " -p {0}".format(pc.url)
387 elif not pc.https and not pc.url:
388 for o in pc.origins:
389 cmd += " -g {0}".format(o)
390 cmd += " {0}".format(pc.name)
391 else:
392 if pc.url in self.acs:
393 ac = self.acs[pc.url]
394 else:
395 ac = self.__start_https(pc)
396 # Configure image to use apache instance
397 cmd = " --debug " \
398 "ssl_ca_file={ca_file} {cmd} " \
399 "-k {key} -c {cert} " \
400 "-p {url}".format(
401 ca_file=os.path.join(
402 self.raw_trust_anchor_dir,
403 "{0}_cert.pem".format(
404 pc.server_ta)),
405 cert=os.path.join(
406 self.cs_dir,
407 "cs1_{0}_cert.pem".format(
408 pc.client_ta)),
409 cmd=cmd,
410 key=os.path.join(
411 self.keys_dir,
412 "cs1_{0}_key.pem".format(
413 pc.client_ta)),
414 url=ac.url,
416 if pc.signature_policy:
417 cmd += " --set-property " \
418 "signature-policy={0}".format(
419 pc.signature_policy)
420 if pc.required_names:
421 cmd += " --set-property " \
422 "signature-required-names='{0}'".format(
423 pc.required_names)
424 self.pkg(cmd, debug_smf=False)
425 for pub, m in pc.mirrors:
426 self.pkg(
427 "set-publisher -m {0} {1}".format(m, pub))
428 if pc.disabled:
429 self.pkg("set-publisher -d {0}".format(
430 pc.name))
432 if use_config_cache:
433 # Call self.sysrepo so that a config cache is
434 # created. The subsequent call to self.sysrepo
435 # will use that cache to build the Apache
436 # configuration.
437 self.sysrepo("-l {log_locs} -p {port} "
438 "-r {common_serve}".format(
439 log_locs=self.apache_log_dir,
440 port=port,
441 common_serve=self.common_config_dir)
444 self.sysrepo("-l {log_locs} -p {port} "
445 "-r {common_serve}".format(
446 log_locs=self.apache_log_dir,
447 port=port,
448 common_serve=self.common_config_dir)
450 st = os.stat(os.path.join(self.common_config_dir,
451 "htdocs"))
452 uid = st.st_uid
453 gid = st.st_gid
454 conf_dir = os.path.join(self.test_root, "apache-conf",
455 name)
456 shutil.move(self.common_config_dir, conf_dir)
457 st2 = os.stat(conf_dir)
458 new_uid = st2.st_uid
459 new_gid = st2.st_gid
460 if new_uid != uid or new_gid != gid:
461 misc.recursive_chown_dir(conf_dir, uid, gid)
462 self.apache_confs[name] = os.path.join(self.test_root,
463 "apache-conf", name, "sysrepo_httpd.conf")
464 self.__configured_names.append(name)
465 self.pkg("property")
466 self.image_destroy()
468 def __set_responses(self, name, update_conf=True):
469 """Sets the system-repository to use a named configuration
470 when providing responses."""
472 if name not in self.__configured_names:
473 raise RuntimeError("{0} hasn't been prepared for this "
474 "test.".format(name))
475 base_dir = os.path.join(self.test_root, "apache-conf", name,
476 "htdocs")
477 if not os.path.isdir(base_dir):
478 raise RuntimeError("Expected {0} to already exist and "
479 "be a directory but it's not.".format(base_dir))
480 if os.path.isdir(self.htdocs_dir):
481 shutil.rmtree(self.htdocs_dir)
482 shutil.copytree(base_dir, self.htdocs_dir)
483 crypto_path = os.path.join(self.common_config_dir, "crypto.txt")
484 if os.path.exists(crypto_path):
485 os.chmod(crypto_path, 0o600)
486 shutil.copy(os.path.join(self.test_root, "apache-conf", name,
487 "crypto.txt"), self.common_config_dir)
488 os.chmod(crypto_path, 0o400)
489 st = os.stat(base_dir)
490 uid = st.st_uid
491 gid = st.st_gid
492 st2 = os.stat(self.htdocs_dir)
493 new_uid = st2.st_uid
494 new_gid = st2.st_gid
495 if uid != new_gid or gid != new_gid:
496 misc.recursive_chown_dir(self.common_config_dir, uid,
497 gid)
498 if update_conf and "sysrepo" in self.acs:
499 # changing configuration without registering a new
500 # ApacheController is safe even if the new configuration
501 # specifies a different port, because the controller
502 # gets stopped/started by the __set_conf(..)
503 # method of ApacheController if the process is running.
504 self.acs["sysrepo"].conf = self.apache_confs[name]
506 def __check_publisher_info(self, expected, set_debug_value=True,
507 su_wrap=False, env_arg=None):
508 self.pkg("publisher -F tsv", debug_smf=set_debug_value,
509 su_wrap=su_wrap, env_arg=env_arg)
510 output = self.reduceSpaces(self.output)
511 self.assertEqualDiff(expected, output, bound_white_space=True)
513 def __check_package_lists(self, expected):
514 self.pkg("list -Ha")
515 output = self.reduceSpaces(self.output)
516 self.assertEqualDiff(expected, output)
518 def __check_publisher_dirs(self, pubs):
519 pub_dir = os.path.join(self.img_path(), "var/pkg/publisher")
520 for p in pubs:
521 if not os.path.isdir(os.path.join(pub_dir, p)):
522 raise RuntimeError("Publisher {0} was expected "
523 "to exist but its directory is missing "
524 "from the image directory.".format(p))
525 for d in os.listdir(pub_dir):
526 if d not in pubs:
527 raise RuntimeError("{0} was not expected in the "
528 "publisher directory but was found.".format(d))
530 def test_01_basics(self):
531 """Test that an image with no publishers can be created and that
532 it can pick up its publisher configuration from the system
533 repository."""
534 self.base_01_basics()
536 def test_01a_basics(self):
537 """Tests that an image with no publishers can be created and
538 that it can pick up its publisher configuration from the system
539 repository when we're using a cached pkg.sysrepo config."""
540 self.base_01_basics(use_config_cache=True)
542 def base_01_basics(self, use_config_cache=False):
543 """Implementation of test_01_basics, parameterizing
544 use_config_cache"""
546 self.__prep_configuration("all-access",
547 use_config_cache=use_config_cache)
548 self.__set_responses("all-access")
549 sc = pkg5unittest.SysrepoController(
550 self.apache_confs["all-access"], self.sysrepo_port,
551 self.common_config_dir, testcase=self)
552 self.register_apache_controller("sysrepo", sc)
553 sc.start()
554 api_obj = self.image_create(props={"use-system-repo": True})
555 # Make sure that the publisher catalogs were created.
556 for n in ("test1", "test12", "test3"):
557 self.assert_(os.path.isdir(os.path.join(self.img_path(),
558 "var/pkg/publisher/{0}".format(n))))
559 expected = self.expected_all_access.format(
560 durl1=self.durl1, durl2=self.durl2,
561 durl3=self.durl3, port=self.sysrepo_port)
562 self.__check_publisher_info(expected)
564 # make sure none of our sysrepo-provided configuration has
565 # leaked into the image configuration
566 self.pkg("set-property use-system-repo False")
567 expected = """\
568 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
570 self.__check_publisher_info(expected)
571 self.pkg("set-property use-system-repo True")
573 self.pkg("publisher test1")
575 # check we have the correct number of lines, each containing
576 # <system-repository>
577 self.pkg("publisher -H")
578 count = 0
579 for line in self.output.split("\n"):
580 count += 1
581 # publisher 4 does not have any origins set
582 if not line.startswith("test4") and line:
583 self.assert_("<system-repository>" in line,
584 "line {0} does not contain "
585 "'<system-repository>'".format(line))
586 self.assert_(count == 5,
587 "expected 5 lines of output in \n{0}\n, got {1}".format(
588 self.output, count))
590 self.pkg("publisher")
591 self.pkg("publisher test1")
592 self.pkg("publisher test12")
593 self.assert_("Proxy: http://localhost:{0}".format(self.sysrepo_port)
594 in self.output)
595 self.assert_("<system-repository>" not in self.output)
596 self.debug("looking for {0}".format(self.durl1))
598 # Test that the publishers have the right uris and appear in
599 # the correct order.
600 self.pkg("publisher -F tsv")
601 expected = """\
602 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
603 test1\ttrue\ttrue\ttrue\torigin\tonline\t{one}/\thttp://localhost:{port}
604 test12\tfalse\ttrue\ttrue\torigin\tonline\t{two}/\thttp://localhost:{port}
605 test3\ttrue\ttrue\ttrue\torigin\tonline\t{three}/\thttp://localhost:{port}
606 test4\ttrue\ttrue\ttrue\t\t\t\t
607 """.format(port=self.sysrepo_port, one=self.durl1, two=self.durl2,
608 three=self.durl3)
609 output = self.reduceSpaces(self.output)
610 self.assertEqualDiff(expected, output, bound_white_space=True)
612 # Test that a new pkg process will pick up the right catalog.
613 self.pkg("list -a")
614 self.pkg("install example_pkg")
616 # Test that the current api object has the right catalog.
617 self._api_install(api_obj, ["foo", "bar"])
619 # Test that we can install a multi-hash package
620 self.pkg("install baz")
621 self.pkg("contents -m baz")
622 self.assert_("pkg.hash.sha256" in self.output)
624 def test_02_communication(self):
625 """Test that the transport for communicating with the depots is
626 actually going through the proxy. This is done by
627 "misconfiguring" the system repository so that it refuses to
628 proxy to certain depots then operations which would communicate
629 with those depots fail.
631 We also verify that $http_proxy and $no_proxy environment
632 variables are not used for interactions with the system
633 repository.
636 self.__prep_configuration(["all-access", "none", "test12-test3",
637 "test3"])
638 self.__set_responses("all-access")
639 sc = pkg5unittest.SysrepoController(
640 self.apache_confs["none"], self.sysrepo_port,
641 self.common_config_dir, testcase=self)
642 self.register_apache_controller("sysrepo", sc)
644 sc.start()
645 self.assertRaises(apx.CatalogRefreshException,
646 self.image_create, props={"use-system-repo": True})
647 sc.conf = self.apache_confs["all-access"]
648 api_obj = self.image_create(props={"use-system-repo": True})
649 sc.conf = self.apache_confs["none"]
651 expected = self.expected_all_access.format(
652 durl1=self.durl1, durl2=self.durl2,
653 durl3=self.durl3, port=self.sysrepo_port)
654 self.__check_publisher_info(expected)
656 self.pkg("list -a")
657 self.pkg("contents -rm example_pkg", exit=1)
658 self.pkg("contents -rm foo", exit=1)
659 self.pkg("contents -rm bar", exit=1)
660 self.pkg("install --no-refresh example_pkg", exit=1)
661 self.pkg("install --no-refresh foo", exit=1)
662 self.pkg("install --no-refresh bar", exit=1)
663 self.assertRaises(tx.TransportFailures, self._api_install,
664 api_obj, ["example_pkg"], refresh_catalogs=False)
665 self.assertRaises(tx.TransportFailures, self._api_install,
666 api_obj, ["foo"], refresh_catalogs=False)
667 self.assertRaises(tx.TransportFailures, self._api_install,
668 api_obj, ["bar"], refresh_catalogs=False)
670 sc.conf = self.apache_confs["test3"]
671 self.pkg("list -a")
672 self.pkg("contents -rm example_pkg", exit=1)
673 self.pkg("contents -rm foo", exit=1)
674 self.pkg("contents -rm bar")
675 self.assertRaises(tx.TransportFailures, self._api_install,
676 api_obj, ["example_pkg"], refresh_catalogs=False)
677 self.assertRaises(tx.TransportFailures, self._api_install,
678 api_obj, ["foo"], refresh_catalogs=False)
679 self._api_install(api_obj, ["bar"], refresh_catalogs=False)
682 sc.conf = self.apache_confs["test12-test3"]
683 self.pkg("list -a")
684 self.pkg("contents -rm example_pkg", exit=1)
685 self.pkg("contents -rm foo")
686 self.assertRaises(tx.TransportFailures, self._api_install,
687 api_obj, ["example_pkg"], refresh_catalogs=False)
688 self._api_install(api_obj, ["foo"], refresh_catalogs=False)
690 sc.conf = self.apache_confs["all-access"]
691 self.pkg("list -a")
692 self.pkg("contents -rm example_pkg")
693 self._api_install(api_obj, ["example_pkg"])
695 # check that $http_proxy environment variables are ignored
696 # by setting http_proxy and no_proxy values that would otherwise
697 # cause us to bypass the system-repository.
699 env = {"http_proxy": "http://noodles"}
700 # create an image the long way, allowing us to pass an environ
701 self.image_destroy()
702 os.mkdir(self.img_path())
703 self.pkg("image-create {0}".format(self.img_path()))
704 self.pkg("set-property use-system-repo True", env_arg=env)
706 self.pkg("refresh --full", env_arg=env)
707 self.pkg("contents -rm example_pkg", env_arg=env)
708 expected = self.expected_all_access.format(
709 durl1=self.durl1, durl2=self.durl2,
710 durl3=self.durl3, port=self.sysrepo_port)
711 self.__check_publisher_info(expected, env_arg=env)
712 self.pkg("install example_pkg", env_arg=env)
714 env = {"no_proxy": "localhost"}
715 # create an image the long way, allowing us to pass an environ
716 self.image_destroy()
717 os.mkdir(self.img_path())
718 self.pkg("image-create {0}".format(self.img_path()))
719 self.pkg("set-property use-system-repo True", env_arg=env)
721 self.pkg("refresh --full", env_arg=env)
722 self.pkg("contents -rm example_pkg", env_arg=env)
723 self.__check_publisher_info(expected, env_arg=env)
724 self.pkg("install example_pkg", env_arg=env)
726 def test_03_user_modifying_configuration(self):
727 """Test that adding and removing origins to a system publisher
728 works as expected and that modifying other configuration of a
729 system publisher fails."""
731 self.__prep_configuration(["test1", "none",
732 "mirror-access-user"])
733 self.__set_responses("test1")
734 sc = pkg5unittest.SysrepoController(
735 self.apache_confs["test1"], self.sysrepo_port,
736 self.common_config_dir, testcase=self)
737 self.register_apache_controller("sysrepo", sc)
738 sc.start()
739 api_obj = self.image_create(props={"use-system-repo": True})
741 # Test that most modifications to a system publisher fail.
742 self.pkg("set-publisher -d test1", exit=1)
743 self.pkg("set-publisher -e test1", exit=1)
744 self.pkg("set-publisher --non-sticky test1", exit=1)
745 self.pkg("set-publisher --sticky test1", exit=1)
746 self.pkg("set-publisher --set-property foo=bar test1", exit=1)
747 self.pkg("set-publisher --unset-property test-property test1",
748 exit=1)
749 self.pkg("set-publisher --add-property-value test-property=bar "
750 "test1", exit=1)
751 self.pkg("set-publisher --remove-property-value "
752 "test-property=test test1", exit=1)
753 self.pkg("unset-publisher test1", exit=1)
754 self.pkg("set-publisher --search-first test1", exit=1)
756 # Add a mirror to an existing system publisher
757 self.pkg("set-publisher -m {0} test1".format(self.rurl1))
759 # Add an origin to an existing system publisher.
760 self.pkg("set-publisher -g {0} test1".format(self.rurl1))
762 # Check that the publisher information is shown correctly.
763 expected = """\
764 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
765 test1\ttrue\ttrue\ttrue\torigin\tonline\t{rurl1}/\t-
766 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
767 test1\ttrue\ttrue\ttrue\tmirror\tonline\t{rurl1}/\t-
768 """.format(rurl1=self.rurl1, durl1=self.durl1, port=self.sysrepo_port)
769 self.__check_publisher_info(expected)
771 # Check that the publisher specific information has information
772 # for both origins, and that we only have one occurrence of
773 # "Proxy:"
774 self.pkg("publisher test1")
775 self.assert_(self.rurl1 in self.output)
776 self.assert_(self.durl1 in self.output)
777 self.assert_("http://localhost:{0}\n".format(self.sysrepo_port)
778 in self.output)
779 self.assert_(self.output.count("Proxy:") == 1)
781 # Change the proxy configuration so that the image can't use it
782 # to communicate with the depot. This forces communication to
783 # go through the user configured origin.
784 sc.conf = self.apache_confs["none"]
786 # Check that the catalog can't be refreshed and that the
787 # communcation with the repository fails.
788 self.pkg("contents -rm example_pkg")
789 self.pkg("refresh --full", exit=1)
791 # Check that removing the system configured origin fails.
792 self.pkg("set-publisher -G {0} test1".format(self.durl1), exit=1)
793 self.pkg("set-publisher -G {0} test1".format(self.durl1),
794 exit=1)
795 # Check that removing the user configured origin succeeds.
796 # --no-refresh is needed because otherwise we attempt to contact
797 # the publisher to update the catalogs.
798 self.pkg("set-publisher -G {0} --no-refresh test1".format(self.rurl1))
800 # Check that the user configured origin is gone.
801 expected = """\
802 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
803 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
804 test1\ttrue\ttrue\ttrue\tmirror\tonline\t{rurl1}/\t-
805 """.format(durl1=self.durl1, rurl1=self.rurl1, port=self.sysrepo_port)
806 self.__check_publisher_info(expected)
808 # Ensure that previous communication was going through the file
809 # repo by confirming that communication to the depot is still
810 # refused.
811 self.pkg("refresh --full", exit=1)
813 # Reenable access to the depot to make sure nothing has been
814 # broken in the image.
815 sc.conf = self.apache_confs["test1"]
816 self.pkg("refresh --full")
818 # Find the hashes that will be included in the urls of the
819 # proxied file repos.
820 hash1 = digest.DEFAULT_HASH_FUNC("file://" +
821 self.dcs[1].get_repodir().rstrip("/")).hexdigest()
822 hash3 = digest.DEFAULT_HASH_FUNC("file://" +
823 self.dcs[3].get_repodir().rstrip("/")).hexdigest()
825 # Check that a user can add and remove mirrors,
826 # but can't remove repo-provided mirrors
827 sc.conf = self.apache_confs["mirror-access-user"]
828 self.__set_responses("mirror-access-user")
829 self.pkg("set-publisher -m {0} test12".format(self.rurl2))
830 expected_mirrors = """\
831 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
832 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
833 test1\ttrue\ttrue\ttrue\tmirror\tonline\t{rurl1}/\t-
834 test1\ttrue\ttrue\ttrue\tmirror\tonline\thttp://localhost:{port}/test1/{hash1}/\t-
835 test12\tfalse\ttrue\ttrue\torigin\tonline\t{durl2}/\thttp://localhost:{port}
836 test12\tfalse\ttrue\ttrue\tmirror\tonline\t{rurl2}/\t-
837 test3\ttrue\ttrue\ttrue\torigin\tonline\t{durl3}/\thttp://localhost:{port}
838 test3\ttrue\ttrue\ttrue\tmirror\tonline\thttp://localhost:{port}/test3/{hash3}/\t-
839 """.format(port=self.sysrepo_port, hash1=hash1, rurl1=self.rurl1,
840 rurl2=self.rurl2, hash3=hash3, durl1=self.durl1,
841 durl2=self.durl2, durl3=self.durl3)
842 self.__check_publisher_info(expected_mirrors)
844 # turn off the sysrepo property, and ensure the mirror is there
845 self.pkg("set-property use-system-repo False")
846 expected = """\
847 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
848 test1\ttrue\tfalse\ttrue\tmirror\tonline\t{rurl1}/\t-
849 test12\tfalse\tfalse\ttrue\tmirror\tonline\t{rurl2}/\t-
850 """.format(rurl1=self.rurl1, rurl2=self.rurl2)
851 self.__check_publisher_info(expected)
852 self.pkg("set-property use-system-repo True")
854 # ensure we can't remove the sysrepo-provided mirror
855 self.pkg("set-publisher -M {0} test12".format(self.rurl1), exit=1)
856 self.__check_publisher_info(expected_mirrors)
858 # ensure we can remove the user-provided mirror
859 self.pkg("set-publisher -M {0} test12".format(self.rurl2))
860 expected = """\
861 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
862 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
863 test1\ttrue\ttrue\ttrue\tmirror\tonline\t{rurl1}/\t-
864 test1\ttrue\ttrue\ttrue\tmirror\tonline\thttp://localhost:{port}/test1/{hash1}/\t-
865 test12\tfalse\ttrue\ttrue\torigin\tonline\t{durl2}/\thttp://localhost:{port}
866 test3\ttrue\ttrue\ttrue\torigin\tonline\t{durl3}/\thttp://localhost:{port}
867 test3\ttrue\ttrue\ttrue\tmirror\tonline\thttp://localhost:{port}/test3/{hash3}/\t-
868 """.format(port=self.sysrepo_port, hash1=hash1, rurl1=self.rurl1,
869 hash3=hash3, durl1=self.durl1, durl2=self.durl2,
870 durl3=self.durl3)
872 self.__check_publisher_info(expected)
874 def test_04_changing_syspub_configuration(self):
875 """Test that changes to the syspub/0 response are handled
876 correctly by the client."""
878 # Check that a syspub/0 response with no configured publisers
879 # works.
880 self.__prep_configuration(["none", "test1-test12",
881 "test1-test3", "test12"])
882 self.__set_responses("none")
883 sc = pkg5unittest.SysrepoController(
884 self.apache_confs["none"], self.sysrepo_port,
885 self.common_config_dir, testcase=self)
886 self.register_apache_controller("sysrepo", sc)
887 sc.start()
888 api_obj = self.image_create(props={"use-system-repo": True})
890 expected = """\
891 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
893 self.__check_publisher_info(expected)
895 # The user configures test1 as a publisher.
896 self.pkg("set-publisher --non-sticky -p {0}".format(self.durl1))
897 self.__check_publisher_dirs(["test1"])
898 expected = """\
899 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
900 test1\tfalse\tfalse\ttrue\torigin\tonline\t{0}/\t-
901 """.format(self.durl1)
902 self.__check_publisher_info(expected)
904 self.pkg("set-publisher -d test1")
905 expected = """\
906 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
907 test1\tfalse\tfalse\tfalse\torigin\tonline\t{0}/\t-
908 """.format(self.durl1)
909 self.__check_publisher_info(expected)
910 self.__check_publisher_dirs([])
912 # Now the syspub/0 response configures two publishers. The
913 # test12 publisher is totally new while the test1 publisher
914 # overlaps with the publisher the user configured.
915 self.__set_responses("test1-test12")
917 # Check that the syspub/0 sticky setting has masked the user
918 # configuration and that the other publisher information is as
919 # expected. Note that the user-configured origin should be
920 # hidden since we can only have a single path to an origin,
921 # so we use the system repository version.
922 expected = """\
923 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
924 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
925 test12\tfalse\ttrue\ttrue\torigin\tonline\t{durl2}/\thttp://localhost:{port}
926 """.format(durl1=self.durl1, durl2=self.durl2, port=self.sysrepo_port)
927 self.__check_publisher_info(expected)
928 self.__check_publisher_dirs([])
930 expected = """\
931 example_pkg 1.0-0 ---
932 foo (test12) 1.0-0 ---
934 self.__check_package_lists(expected)
935 self.pkg("refresh --full")
937 self.pkg("contents -rm example_pkg")
938 self.pkg("contents -rm foo")
939 self.pkg("contents -rm bar", exit=1)
941 # Now the syspub/0 response configures two publishers, test1 and
942 # test 3.
943 self.__set_responses("test1-test3")
945 expected = """\
946 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
947 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
948 test3\ttrue\ttrue\ttrue\torigin\tonline\t{durl3}/\thttp://localhost:{port}
949 """.format(durl1=self.durl1, durl3=self.durl3, port=self.sysrepo_port)
950 self.__check_publisher_info(expected)
951 # Only test1 is expected to exist because only it was present in
952 # both the old configuration and the current configuration.
953 self.__check_publisher_dirs(["test1"])
955 expected = """\
956 bar (test3) 1.0-0 ---
957 baz (test3) 1.0-0 ---
958 example_pkg 1.0-0 ---
960 self.__check_package_lists(expected)
962 self.pkg("contents -rm example_pkg")
963 self.pkg("contents -rm foo", exit=1)
964 self.pkg("contents -m foo", exit=1)
965 self.pkg("contents -rm bar")
966 self.pkg("refresh --full")
968 # The user tries to add an origin to the system publisher test3
969 # using the same url as the system-repository provides, which
970 # should fail, because There Can Be Only One origin for a given
971 # uri.
972 self.pkg("set-publisher -g {0} test3".format(self.durl3), exit=1)
974 expected = """\
975 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
976 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
977 test3\ttrue\ttrue\ttrue\torigin\tonline\t{durl3}/\thttp://localhost:{port}
978 """.format(durl1=self.durl1, durl3=self.durl3, port=self.sysrepo_port)
979 self.__check_publisher_info(expected)
980 self.__check_publisher_dirs(["test1", "test3"])
982 expected = """\
983 bar (test3) 1.0-0 ---
984 baz (test3) 1.0-0 ---
985 example_pkg 1.0-0 ---
987 self.__check_package_lists(expected)
988 self.pkg("refresh --full")
990 # Now syspub/0 removes test1 and test3 as publishers and returns
991 # test12 as a publisher.
992 self.__set_responses("test12")
994 # test1 should be reinstated as a publisher because the
995 # user added an origin for it before using the system
996 # repository. test1 should also return to
997 # the settings the user had previously configured. test12 should
998 # be listed first since, because it's a system publisher, it's
999 # higher ranked.
1000 expected = """\
1001 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1002 test12\tfalse\ttrue\ttrue\torigin\tonline\t{durl2}/\thttp://localhost:{port}
1003 test1\tfalse\tfalse\tfalse\torigin\tonline\t{durl1}/\t-
1004 """.format(durl2=self.durl2, durl1=self.durl1, port=self.sysrepo_port)
1005 self.__check_publisher_info(expected)
1007 self.pkg("refresh --full")
1009 expected = """\
1010 foo 1.0-0 ---
1012 self.__check_package_lists(expected)
1014 # Install a package from test12.
1015 self.pkg("install foo")
1017 # Now syspub/0 removes test12 as a publisher as well.
1018 self.__set_responses("none")
1020 # test12 should be disabled and at the bottom of the list
1021 # because a package was installed from it prior to its removal
1022 # as a system publisher.
1023 expected = """\
1024 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1025 test1\tfalse\tfalse\tfalse\torigin\tonline\t{durl1}/\t-
1026 test12\tfalse\ttrue\tfalse\t\t\t\t
1027 """.format(durl1=self.durl1)
1028 self.__check_publisher_info(expected)
1030 # Uninstalling foo should remove test12 from the list of
1031 # publishers.
1032 self.pkg("uninstall foo")
1033 expected = """\
1034 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1035 test1\tfalse\tfalse\tfalse\torigin\tonline\t{durl1}/\t-
1036 """.format(durl1=self.durl1, durl3=self.durl3)
1037 self.__check_publisher_info(expected)
1039 def test_05_simultaneous_change(self):
1040 """Test that simultaneous changes in both user configuration and
1041 system publisher state are handled correctly."""
1043 self.__prep_configuration(["none", "test1", "test12"])
1044 # Create an image with no user configured publishers and no
1045 # system configured publishers.
1046 self.__set_responses("none")
1047 sc = pkg5unittest.SysrepoController(
1048 self.apache_confs["none"], self.sysrepo_port,
1049 self.common_config_dir, testcase=self)
1050 self.register_apache_controller("sysrepo", sc)
1051 sc.start()
1052 api_obj = self.image_create(props={"use-system-repo": True})
1053 expected = """\
1054 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1056 self.__check_publisher_info(expected)
1058 # Have the user configure test1 at the same time that test1 is
1059 # made a system publisher.
1060 self.__set_responses("test1")
1062 self.pkg("set-publisher -p {0}".format(self.rurl1))
1063 expected = """\
1064 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1065 test1\ttrue\ttrue\ttrue\torigin\tonline\t{rurl1}/\t-
1066 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
1067 """.format(rurl1=self.rurl1, durl1=self.durl1, port=self.sysrepo_port)
1068 self.__check_publisher_info(expected)
1070 # Adding the origin to the publisher which now exists should
1071 # fail.
1072 self.pkg("set-publisher -g {0} test1".format(self.rurl1), exit=1)
1074 # The user adds an origin to test12 at the same time that test12
1075 # first becomes known to the image.
1076 self.__set_responses("test12")
1077 self.pkg("set-publisher -g {0} test12".format(self.rurl2))
1078 expected = """\
1079 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1080 test12\tfalse\ttrue\ttrue\torigin\tonline\t{rurl2}/\t-
1081 test12\tfalse\ttrue\ttrue\torigin\tonline\t{durl2}/\thttp://localhost:{port}
1082 test1\ttrue\tfalse\ttrue\torigin\tonline\t{rurl1}/\t-
1083 """.format(rurl2=self.rurl2, durl2=self.durl2, rurl1=self.rurl1,
1084 port=self.sysrepo_port)
1085 self.__check_publisher_info(expected)
1087 self.pkg("publisher")
1088 self.debug(self.output)
1089 # The user removes the origin for test12 at the same time that
1090 # test12 stops being a system publisher and test1 is added as a
1091 # system publisher.
1092 self.__set_responses("test1")
1093 self.pkg("set-publisher -G {0} test12".format(self.rurl2))
1094 expected = """\
1095 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1096 test1\ttrue\ttrue\ttrue\torigin\tonline\t{rurl1}/\t-
1097 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
1098 test12\tfalse\tfalse\ttrue\t\t\t\t
1099 """.format(rurl1=self.rurl1, durl1=self.durl1, port=self.sysrepo_port)
1100 self.__check_publisher_info(expected)
1102 # The user now removes the originless publisher
1103 self.pkg("unset-publisher test12")
1104 expected = """\
1105 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1106 test1\ttrue\ttrue\ttrue\torigin\tonline\t{rurl1}/\t-
1107 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
1108 """.format(rurl1=self.rurl1, durl1=self.durl1, port=self.sysrepo_port)
1109 self.__check_publisher_info(expected)
1111 # The user now unsets test1 at the same time that test1 stops
1112 # being a system publisher.
1113 self.__set_responses("none")
1114 self.pkg("unset-publisher test1")
1115 expected = """\
1116 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1118 self.__check_publisher_info(expected)
1120 def test_06_ordering(self):
1121 """Test that publishers have the right search order given both
1122 user configuration and whether a publisher is a system
1123 publisher."""
1125 self.__prep_configuration(["all-access", "none", "test1"])
1126 self.__set_responses("none")
1127 sc = pkg5unittest.SysrepoController(
1128 self.apache_confs["none"], self.sysrepo_port,
1129 self.common_config_dir, testcase=self)
1130 self.register_apache_controller("sysrepo", sc)
1131 sc.start()
1132 api_obj = self.image_create(props={"use-system-repo": True})
1134 self.pkg("set-publisher -p {0}".format(self.rurl3))
1135 self.pkg("set-publisher -p {0}".format(self.rurl2))
1136 self.pkg("set-publisher -p {0}".format(self.rurl1))
1138 expected = """\
1139 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1140 test3\ttrue\tfalse\ttrue\torigin\tonline\t{0}/\t-
1141 test12\ttrue\tfalse\ttrue\torigin\tonline\t{1}/\t-
1142 test1\ttrue\tfalse\ttrue\torigin\tonline\t{2}/\t-
1143 """.format(self.rurl3, self.rurl2, self.rurl1)
1144 self.__check_publisher_info(expected)
1146 self.__set_responses("all-access")
1148 expected = """\
1149 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1150 test1\ttrue\ttrue\ttrue\torigin\tonline\t{rurl1}/\t-
1151 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
1152 test12\tfalse\ttrue\ttrue\torigin\tonline\t{rurl2}/\t-
1153 test12\tfalse\ttrue\ttrue\torigin\tonline\t{durl2}/\thttp://localhost:{port}
1154 test3\ttrue\ttrue\ttrue\torigin\tonline\t{rurl3}/\t-
1155 test3\ttrue\ttrue\ttrue\torigin\tonline\t{durl3}/\thttp://localhost:{port}
1156 test4\ttrue\ttrue\ttrue\t\t\t\t
1157 """.format(rurl1=self.rurl1, durl1=self.durl1, rurl2=self.rurl2,
1158 durl2=self.durl2, rurl3=self.rurl3, durl3=self.durl3,
1159 port=self.sysrepo_port)
1160 self.__check_publisher_info(expected)
1162 self.pkg("set-property use-system-repo False")
1163 expected = """\
1164 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1165 test3\ttrue\tfalse\ttrue\torigin\tonline\t{0}/\t-
1166 test12\ttrue\tfalse\ttrue\torigin\tonline\t{1}/\t-
1167 test1\ttrue\tfalse\ttrue\torigin\tonline\t{2}/\t-
1168 """.format(self.rurl3, self.rurl2, self.rurl1)
1169 self.__check_publisher_info(expected)
1171 self.pkg("set-property use-system-repo True")
1172 expected = """\
1173 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1174 test1\ttrue\ttrue\ttrue\torigin\tonline\t{rurl1}/\t-
1175 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
1176 test12\tfalse\ttrue\ttrue\torigin\tonline\t{rurl2}/\t-
1177 test12\tfalse\ttrue\ttrue\torigin\tonline\t{durl2}/\thttp://localhost:{port}
1178 test3\ttrue\ttrue\ttrue\torigin\tonline\t{rurl3}/\t-
1179 test3\ttrue\ttrue\ttrue\torigin\tonline\t{durl3}/\thttp://localhost:{port}
1180 test4\ttrue\ttrue\ttrue\t\t\t\t
1181 """.format(rurl1=self.rurl1, durl1=self.durl1, rurl2=self.rurl2,
1182 durl2=self.durl2, rurl3=self.rurl3, durl3=self.durl3,
1183 port=self.sysrepo_port)
1184 self.__check_publisher_info(expected)
1186 self.__set_responses("test1")
1187 expected = """\
1188 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1189 test1\ttrue\ttrue\ttrue\torigin\tonline\t{rurl1}/\t-
1190 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
1191 test3\ttrue\tfalse\ttrue\torigin\tonline\t{rurl3}/\t-
1192 test12\ttrue\tfalse\ttrue\torigin\tonline\t{rurl2}/\t-
1193 """.format(rurl1=self.rurl1, durl1=self.durl1, rurl3=self.rurl3,
1194 rurl2=self.rurl2, port=self.sysrepo_port)
1195 self.__check_publisher_info(expected)
1197 self.pkg("set-publisher --search-before test3 test12")
1198 expected = """\
1199 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1200 test1\ttrue\ttrue\ttrue\torigin\tonline\t{rurl1}/\t-
1201 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
1202 test12\ttrue\tfalse\ttrue\torigin\tonline\t{rurl2}/\t-
1203 test3\ttrue\tfalse\ttrue\torigin\tonline\t{rurl3}/\t-
1204 """.format(rurl1=self.rurl1, durl1=self.durl1, rurl2=self.rurl2,
1205 rurl3=self.rurl3, port=self.sysrepo_port)
1206 self.__check_publisher_info(expected)
1208 self.pkg("set-publisher --search-after test3 test12")
1209 expected = """\
1210 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1211 test1\ttrue\ttrue\ttrue\torigin\tonline\t{rurl1}/\t-
1212 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
1213 test3\ttrue\tfalse\ttrue\torigin\tonline\t{rurl3}/\t-
1214 test12\ttrue\tfalse\ttrue\torigin\tonline\t{rurl2}/\t-
1215 """.format(rurl1=self.rurl1, durl1=self.durl1, rurl3=self.rurl3,
1216 rurl2=self.rurl2, port=self.sysrepo_port)
1217 self.__check_publisher_info(expected)
1219 self.pkg("set-publisher --search-before test1 test12", exit=1)
1220 self.pkg("set-publisher -d --search-before test1 test12",
1221 exit=1)
1222 # Ensure that test12 is not disabled.
1223 expected = """\
1224 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1225 test1\ttrue\ttrue\ttrue\torigin\tonline\t{rurl1}/\t-
1226 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
1227 test3\ttrue\tfalse\ttrue\torigin\tonline\t{rurl3}/\t-
1228 test12\ttrue\tfalse\ttrue\torigin\tonline\t{rurl2}/\t-
1229 """.format(rurl1=self.rurl1, durl1=self.durl1, rurl3=self.rurl3,
1230 rurl2=self.rurl2, port=self.sysrepo_port)
1231 self.__check_publisher_info(expected)
1232 self.pkg("set-publisher --search-after test1 test12", exit=1)
1233 self.pkg("set-publisher --non-sticky --search-after test1 "
1234 "test12", exit=1)
1235 # Ensure that test12 is still sticky.
1236 expected = """\
1237 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1238 test1\ttrue\ttrue\ttrue\torigin\tonline\t{rurl1}/\t-
1239 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
1240 test3\ttrue\tfalse\ttrue\torigin\tonline\t{rurl3}/\t-
1241 test12\ttrue\tfalse\ttrue\torigin\tonline\t{rurl2}/\t-
1242 """.format(rurl1=self.rurl1, durl1=self.durl1, rurl3=self.rurl3,
1243 rurl2=self.rurl2, port=self.sysrepo_port)
1244 self.__check_publisher_info(expected)
1246 # Check that attempting to change test12 relative to test1
1247 # fails.
1248 self.pkg("set-publisher --search-before test12 test1", exit=1)
1249 self.pkg("set-publisher --search-after test12 test1", exit=1)
1250 self.pkg("set-publisher --search-first test12")
1251 expected = """\
1252 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1253 test1\ttrue\ttrue\ttrue\torigin\tonline\t{rurl1}/\t-
1254 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
1255 test12\ttrue\tfalse\ttrue\torigin\tonline\t{rurl2}/\t-
1256 test3\ttrue\tfalse\ttrue\torigin\tonline\t{rurl3}/\t-
1257 """.format(rurl1=self.rurl1, durl1=self.durl1, rurl2=self.rurl2,
1258 rurl3=self.rurl3, port=self.sysrepo_port)
1259 self.__check_publisher_info(expected)
1261 self.pkg("set-property use-system-repo False")
1262 expected = """\
1263 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1264 test12\ttrue\tfalse\ttrue\torigin\tonline\t{0}/\t-
1265 test3\ttrue\tfalse\ttrue\torigin\tonline\t{1}/\t-
1266 test1\ttrue\tfalse\ttrue\torigin\tonline\t{2}/\t-
1267 """.format(self.rurl2, self.rurl3, self.rurl1)
1268 self.__check_publisher_info(expected)
1270 def test_07_environment_variable(self):
1271 """Test that setting the environment variable PKG_SYSREPO_URL
1272 sets the url that pkg uses to communicate with the system
1273 repository."""
1275 self.__prep_configuration(["all-access"],
1276 port=self.sysrepo_alt_port)
1277 self.__set_responses("all-access")
1278 sc = pkg5unittest.SysrepoController(
1279 self.apache_confs["all-access"],
1280 self.sysrepo_alt_port, self.common_config_dir,
1281 testcase=self)
1282 self.register_apache_controller("sysrepo", sc)
1283 sc.start()
1284 old_psu = os.environ.get("PKG_SYSREPO_URL", None)
1285 os.environ["PKG_SYSREPO_URL"] = "localhost:{0}".format(
1286 self.sysrepo_alt_port)
1287 api_obj = self.image_create(props={"use-system-repo": True})
1288 expected = self.expected_all_access.format(
1289 durl1=self.durl1, durl2=self.durl2,
1290 durl3=self.durl3, port=self.sysrepo_alt_port)
1291 self.__check_publisher_info(expected, set_debug_value=False)
1292 if old_psu:
1293 os.environ["PKG_SYSREPO_URL"] = old_psu
1294 else:
1295 del os.environ["PKG_SYSREPO_URL"]
1297 def test_08_file_repos(self):
1298 """Test that proxied file repos work correctly."""
1300 for i in self.dcs:
1301 self.dcs[i].kill(now=True)
1302 self.__prep_configuration(["all-access-f", "none"])
1303 self.__set_responses("all-access-f")
1304 sc = pkg5unittest.SysrepoController(
1305 self.apache_confs["all-access-f"], self.sysrepo_port,
1306 self.common_config_dir, testcase=self)
1307 self.register_apache_controller("sysrepo", sc)
1308 sc.start()
1309 api_obj = self.image_create(props={"use-system-repo": True})
1311 # Find the hashes that will be included in the urls of the
1312 # proxied file repos.
1313 hash1 = digest.DEFAULT_HASH_FUNC("file://" +
1314 self.dcs[1].get_repodir().rstrip("/")).hexdigest()
1315 hash2 = digest.DEFAULT_HASH_FUNC("file://" +
1316 self.dcs[2].get_repodir().rstrip("/")).hexdigest()
1317 hash3 = digest.DEFAULT_HASH_FUNC("file://" +
1318 self.dcs[3].get_repodir().rstrip("/")).hexdigest()
1320 expected = """\
1321 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1322 test1\ttrue\ttrue\ttrue\torigin\tonline\thttp://localhost:{port}/test1/{hash1}/\t-
1323 test12\tfalse\ttrue\ttrue\torigin\tonline\thttp://localhost:{port}/test12/{hash2}/\t-
1324 test3\ttrue\ttrue\ttrue\torigin\tonline\thttp://localhost:{port}/test3/{hash3}/\t-
1325 """.format(port=self.sysrepo_port, hash1=hash1, hash2=hash2,
1326 hash3=hash3)
1328 self.__check_publisher_info(expected)
1330 # Check connectivity with the proxied repos.
1331 self.pkg("install example_pkg")
1332 self.pkg("contents -rm foo")
1333 self.pkg("contents -rm bar")
1335 # Check that proxied file repos that disappear vanish correctly,
1336 # and that those with installed packages remain as disabled
1337 # publishers.
1338 self.__set_responses("none")
1339 expected = """\
1340 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1341 test1\ttrue\ttrue\tfalse\t\t\t\t
1343 self.__check_publisher_info(expected)
1345 # Check that when the user adds an origin to a former system
1346 # publisher with an installed package, the publisher becomes
1347 # enabled and is not a system publisher.
1348 self.pkg("set-publisher -g {0} test1".format(self.rurl1))
1349 expected = """\
1350 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1351 test1\ttrue\tfalse\ttrue\torigin\tonline\t{rurl1}/\t-
1352 """.format(rurl1=self.rurl1)
1353 self.__check_publisher_info(expected)
1355 def test_09_test_file_http_transitions(self):
1356 """Test that changing publishers from http to file repos and
1357 back in the sysrepo works as expected."""
1359 self.__prep_configuration(["all-access", "all-access-f",
1360 "none"])
1361 self.__set_responses("all-access-f")
1362 sc = pkg5unittest.SysrepoController(
1363 self.apache_confs["all-access-f"], self.sysrepo_port,
1364 self.common_config_dir, testcase=self)
1365 self.register_apache_controller("sysrepo", sc)
1366 sc.start()
1367 api_obj = self.image_create(props={"use-system-repo": True})
1369 # Find the hashes that will be included in the urls of the
1370 # proxied file repos.
1371 hash1 = digest.DEFAULT_HASH_FUNC("file://" +
1372 self.dcs[1].get_repodir().rstrip("/")).hexdigest()
1373 hash2 = digest.DEFAULT_HASH_FUNC("file://" +
1374 self.dcs[2].get_repodir().rstrip("/")).hexdigest()
1375 hash3 = digest.DEFAULT_HASH_FUNC("file://" +
1376 self.dcs[3].get_repodir().rstrip("/")).hexdigest()
1378 self.__set_responses("all-access-f")
1379 expected = """\
1380 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1381 test1\ttrue\ttrue\ttrue\torigin\tonline\thttp://localhost:{port}/test1/{hash1}/\t-
1382 test12\tfalse\ttrue\ttrue\torigin\tonline\thttp://localhost:{port}/test12/{hash2}/\t-
1383 test3\ttrue\ttrue\ttrue\torigin\tonline\thttp://localhost:{port}/test3/{hash3}/\t-
1384 """.format(port=self.sysrepo_port, hash1=hash1, hash2=hash2,
1385 hash3=hash3)
1387 self.__check_publisher_info(expected)
1389 self.__set_responses("all-access")
1390 expected = self.expected_all_access.format(
1391 durl1=self.durl1, durl2=self.durl2,
1392 durl3=self.durl3, port=self.sysrepo_port)
1393 self.__check_publisher_info(expected)
1395 def test_10_test_mirrors(self):
1396 """Test that mirror information from the sysrepo is handled
1397 correctly."""
1399 self.__prep_configuration(["all-access", "all-access-f",
1400 "mirror-access", "mirror-access-f", "none"])
1401 self.__set_responses("mirror-access")
1402 sc = pkg5unittest.SysrepoController(
1403 self.apache_confs["mirror-access"], self.sysrepo_port,
1404 self.common_config_dir, testcase=self)
1405 self.register_apache_controller("sysrepo", sc)
1406 sc.start()
1407 api_obj = self.image_create(props={"use-system-repo": True})
1409 # Find the hashes that will be included in the urls of the
1410 # proxied file repos.
1411 hash1 = digest.DEFAULT_HASH_FUNC("file://" +
1412 self.dcs[1].get_repodir().rstrip("/")).hexdigest()
1413 hash2 = digest.DEFAULT_HASH_FUNC("file://" +
1414 self.dcs[2].get_repodir().rstrip("/")).hexdigest()
1415 hash3 = digest.DEFAULT_HASH_FUNC("file://" +
1416 self.dcs[3].get_repodir().rstrip("/")).hexdigest()
1418 expected = """\
1419 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1420 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
1421 test1\ttrue\ttrue\ttrue\tmirror\tonline\thttp://localhost:{port}/test1/{hash1}/\t-
1422 test12\tfalse\ttrue\ttrue\torigin\tonline\t{durl2}/\thttp://localhost:{port}
1423 test12\tfalse\ttrue\ttrue\tmirror\tonline\thttp://localhost:{port}/test12/{hash2}/\t-
1424 test3\ttrue\ttrue\ttrue\torigin\tonline\t{durl3}/\thttp://localhost:{port}
1425 test3\ttrue\ttrue\ttrue\tmirror\tonline\thttp://localhost:{port}/test3/{hash3}/\t-
1426 """.format(port=self.sysrepo_port, hash1=hash1, hash2=hash2,
1427 hash3=hash3, durl1=self.durl1, durl2=self.durl2,
1428 durl3=self.durl3)
1430 self.__check_publisher_info(expected)
1432 self.__set_responses("mirror-access-f")
1433 expected = """\
1434 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1435 test1\ttrue\ttrue\ttrue\torigin\tonline\thttp://localhost:{port}/test1/{hash1}/\t-
1436 test1\ttrue\ttrue\ttrue\tmirror\tonline\t{durl1}/\thttp://localhost:{port}
1437 test12\tfalse\ttrue\ttrue\torigin\tonline\thttp://localhost:{port}/test12/{hash2}/\t-
1438 test12\tfalse\ttrue\ttrue\tmirror\tonline\t{durl2}/\thttp://localhost:{port}
1439 test3\ttrue\ttrue\ttrue\torigin\tonline\thttp://localhost:{port}/test3/{hash3}/\t-
1440 test3\ttrue\ttrue\ttrue\tmirror\tonline\t{durl3}/\thttp://localhost:{port}
1441 """.format(port=self.sysrepo_port, hash1=hash1, hash2=hash2,
1442 hash3=hash3, durl1=self.durl1, durl2=self.durl2,
1443 durl3=self.durl3)
1445 self.__check_publisher_info(expected)
1447 self.__set_responses("none")
1448 expected = """\
1449 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1451 self.__check_publisher_info(expected)
1453 self.__set_responses("mirror-access-f")
1454 expected = """\
1455 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1456 test1\ttrue\ttrue\ttrue\torigin\tonline\thttp://localhost:{port}/test1/{hash1}/\t-
1457 test1\ttrue\ttrue\ttrue\tmirror\tonline\t{durl1}/\thttp://localhost:{port}
1458 test12\tfalse\ttrue\ttrue\torigin\tonline\thttp://localhost:{port}/test12/{hash2}/\t-
1459 test12\tfalse\ttrue\ttrue\tmirror\tonline\t{durl2}/\thttp://localhost:{port}
1460 test3\ttrue\ttrue\ttrue\torigin\tonline\thttp://localhost:{port}/test3/{hash3}/\t-
1461 test3\ttrue\ttrue\ttrue\tmirror\tonline\t{durl3}/\thttp://localhost:{port}
1462 """.format(port=self.sysrepo_port, hash1=hash1, hash2=hash2,
1463 hash3=hash3, durl1=self.durl1, durl2=self.durl2,
1464 durl3=self.durl3)
1466 self.__check_publisher_info(expected)
1468 self.__set_responses("all-access")
1469 expected = self.expected_all_access.format(
1470 durl1=self.durl1, durl2=self.durl2,
1471 durl3=self.durl3, port=self.sysrepo_port)
1472 self.__check_publisher_info(expected)
1474 self.__set_responses("mirror-access")
1475 expected = """\
1476 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1477 test1\ttrue\ttrue\ttrue\torigin\tonline\t{durl1}/\thttp://localhost:{port}
1478 test1\ttrue\ttrue\ttrue\tmirror\tonline\thttp://localhost:{port}/test1/{hash1}/\t-
1479 test12\tfalse\ttrue\ttrue\torigin\tonline\t{durl2}/\thttp://localhost:{port}
1480 test12\tfalse\ttrue\ttrue\tmirror\tonline\thttp://localhost:{port}/test12/{hash2}/\t-
1481 test3\ttrue\ttrue\ttrue\torigin\tonline\t{durl3}/\thttp://localhost:{port}
1482 test3\ttrue\ttrue\ttrue\tmirror\tonline\thttp://localhost:{port}/test3/{hash3}/\t-
1483 """.format(port=self.sysrepo_port, hash1=hash1, hash2=hash2,
1484 hash3=hash3, durl1=self.durl1, durl2=self.durl2,
1485 durl3=self.durl3)
1487 self.__check_publisher_info(expected)
1489 def test_11_https_repos(self, use_config_cache=False):
1490 """Test that https repos are proxied correctly."""
1491 self.base_11_https_repos()
1493 def test_11a_https_repos(self):
1494 """Ensure https configurations are created properly when
1495 using a cached configuration."""
1496 self.base_11_https_repos(use_config_cache=True)
1498 def base_11_https_repos(self, use_config_cache=False):
1499 """Implementation of test_11_https_repos, parameterizing
1500 use_config_cache."""
1502 self.__prep_configuration(["https-access", "none"],
1503 use_config_cache=use_config_cache)
1504 self.__set_responses("https-access")
1505 sc = pkg5unittest.SysrepoController(
1506 self.apache_confs["https-access"], self.sysrepo_port,
1507 self.common_config_dir, testcase=self)
1508 self.register_apache_controller("sysrepo", sc)
1509 sc.start()
1510 api_obj = self.image_create(props={"use-system-repo": True})
1512 expected = """\
1513 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1514 test1\ttrue\ttrue\ttrue\torigin\tonline\t{ac1url}/\thttp://localhost:{port}
1515 test12\tfalse\ttrue\ttrue\torigin\tonline\t{ac2url}/\thttp://localhost:{port}
1516 test3\ttrue\ttrue\ttrue\torigin\tonline\t{ac3url}/\thttp://localhost:{port}
1517 """.format(
1518 ac1url=self.acs[self.durl1].url.replace("https", "http"),
1519 ac2url=self.acs[self.durl2].url.replace("https", "http"),
1520 ac3url=self.acs[self.durl3].url.replace("https", "http"),
1521 port=self.sysrepo_port)
1523 self.__check_publisher_info(expected)
1525 api_obj = self.get_img_api_obj()
1526 self._api_install(api_obj, ["example_pkg", "foo", "bar"])
1527 api_obj = self.get_img_api_obj()
1528 self._api_uninstall(api_obj, ["example_pkg", "foo", "bar"])
1529 self.__set_responses("none")
1530 expected = """\
1531 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1533 self.__check_publisher_info(expected)
1534 self.pkg("contents -rm example_pkg", exit=1)
1536 def test_12_disabled_repos(self):
1537 """Test that repos which are disabled in the global zone do not
1538 create problems."""
1539 self.base_12_disabled_repos()
1541 def test_12a_disabled_repos(self):
1542 """Ensure disable configurations are created properly when
1543 using a cached configuration."""
1544 self.base_12_disabled_repos(use_config_cache=True)
1546 def base_12_disabled_repos(self, use_config_cache=False):
1547 """Implementation of test_12_disabled_repos, parameterizing
1548 use_config_cache."""
1550 self.__prep_configuration(["disabled"],
1551 use_config_cache=use_config_cache)
1552 self.__set_responses("disabled")
1553 sc = pkg5unittest.SysrepoController(
1554 self.apache_confs["disabled"], self.sysrepo_port,
1555 self.common_config_dir, testcase=self)
1556 self.register_apache_controller("sysrepo", sc)
1557 sc.start()
1558 api_obj = self.image_create(props={"use-system-repo": True})
1559 expected = """\
1560 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1561 test12\tfalse\ttrue\ttrue\torigin\tonline\t{durl2}/\thttp://localhost:{port}
1562 test3\ttrue\ttrue\ttrue\torigin\tonline\t{durl3}/\thttp://localhost:{port}
1563 """.format(durl2=self.durl2, durl3=self.durl3, port=self.sysrepo_port)
1564 self.__check_publisher_info(expected)
1566 def test_13_no_url(self):
1567 """Test that publishers with no urls are allowed as syspubs
1568 and that we can add/remove origins."""
1569 self.base_13_no_url()
1571 def test_13a_no_url(self):
1572 """Test that publishers which use no url are allowed as syspubs
1573 when using cached configurations."""
1574 self.base_13_no_url(use_config_cache=True)
1576 def base_13_no_url(self, use_config_cache=False):
1577 """Implementation of test_13[a]_no_url, parameterizing
1578 use_config_cache."""
1580 self.__prep_configuration(["nourl"],
1581 use_config_cache=use_config_cache)
1582 self.__set_responses("nourl")
1583 sc = pkg5unittest.SysrepoController(
1584 self.apache_confs["nourl"], self.sysrepo_port,
1585 self.common_config_dir, testcase=self)
1586 self.register_apache_controller("sysrepo", sc)
1587 sc.start()
1588 api_obj = self.image_create(props={"use-system-repo": True})
1589 expected_empty = """\
1590 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1591 test4\ttrue\ttrue\ttrue\t\t\t\t
1593 self.pkg("publisher -F tsv")
1594 self.__check_publisher_info(expected_empty)
1595 self.pkg("unset-publisher test4", exit=1)
1596 self.pkg("set-publisher -g {0} test4".format(self.durl4))
1598 expected = """\
1599 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1600 test4\ttrue\ttrue\ttrue\torigin\tonline\t{0}/\t-
1601 """.format(self.durl4)
1602 self.__check_publisher_info(expected)
1603 self.pkg("set-publisher -G {0} test4".format(self.durl4))
1604 self.__check_publisher_info(expected_empty)
1606 # add another empty publisher
1607 self.pkg("set-publisher empty")
1608 expected = """\
1609 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1610 test4\ttrue\ttrue\ttrue\t\t\t\t
1611 empty\ttrue\tfalse\ttrue\t\t\t\t
1613 self.__check_publisher_info(expected)
1614 # toggle the system publisher and verify that
1615 # our configuration made it to the image
1616 self.pkg("set-property use-system-repo False")
1618 expected_nonsyspub = """\
1619 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1620 test4\ttrue\tfalse\ttrue\t\t\t\t
1621 empty\ttrue\tfalse\ttrue\t\t\t\t
1623 # because we've added and removed local configuration for a
1624 # publisher, that makes that publisher hang around in the user
1625 # image configuration.
1626 # The user needs to unset the publisher to make it go away.
1627 self.__check_publisher_info(expected_nonsyspub)
1629 # verify the sysrepo configuration is still there
1630 self.pkg("set-property use-system-repo True")
1631 self.__check_publisher_info(expected)
1633 def test_bug_18326(self):
1634 """Test that an unprivileged user can use non-image modifying
1635 commands and that image modifying commands don't trace back."""
1637 self.__prep_configuration(["all-access", "none"])
1638 self.__set_responses("all-access")
1639 sc = pkg5unittest.SysrepoController(
1640 self.apache_confs["all-access"], self.sysrepo_port,
1641 self.common_config_dir, testcase=self)
1642 self.register_apache_controller("sysrepo", sc)
1643 sc.start()
1644 api_obj = self.image_create(props={"use-system-repo": True})
1646 expected = self.expected_all_access.format(
1647 durl1=self.durl1, durl2=self.durl2,
1648 durl3=self.durl3, port=self.sysrepo_port)
1649 self.__check_publisher_info(expected, su_wrap=True)
1650 self.pkg("property", su_wrap=True)
1651 self.pkg("install foo", su_wrap=True, exit=1)
1653 self.__set_responses("none")
1654 expected = """\
1655 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1657 self.__check_publisher_info(expected, su_wrap=True)
1658 self.__check_publisher_info(expected)
1659 self.__set_responses("all-access")
1660 expected = self.expected_all_access.format(
1661 durl1=self.durl1, durl2=self.durl2,
1662 durl3=self.durl3, port=self.sysrepo_port)
1663 self.__check_publisher_info(expected, su_wrap=True)
1665 # Test that when the sysrepo isn't available, unprivileged users
1666 # don't lose functionality.
1667 sc.stop()
1668 # Since the last privileged command was done when no
1669 # system-publishers were available, that's what's expected when
1670 # the system repository isn't available.
1671 expected = """\
1672 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
1674 self.__check_publisher_info(expected, su_wrap=True)
1675 self.pkg("property", su_wrap=True)
1676 self.pkg("install foo", su_wrap=True, exit=1)
1678 # Now do a privileged command command to change what the state
1679 # on disk is.
1680 sc.start()
1681 expected = self.expected_all_access.format(
1682 durl1=self.durl1, durl2=self.durl2,
1683 durl3=self.durl3, port=self.sysrepo_port)
1684 self.__check_publisher_info(expected)
1685 sc.stop()
1687 self.__check_publisher_info(expected, su_wrap=True)
1688 self.pkg("property", su_wrap=True)
1689 self.pkg("install foo", su_wrap=True, exit=1)
1691 def test_signature_policy_1(self):
1692 """Test that the image signature policy of ignore is propagated
1693 by the system-repository."""
1695 conf_name = "img-sig-ignore"
1696 self.__prep_configuration([conf_name])
1697 self.__set_responses(conf_name)
1698 sc = pkg5unittest.SysrepoController(
1699 self.apache_confs[conf_name], self.sysrepo_port,
1700 self.common_config_dir, testcase=self)
1701 self.register_apache_controller("sysrepo", sc)
1702 sc.start()
1703 api_obj = self.image_create(props={"use-system-repo": True})
1705 self.pkg("property -H signature-policy", su_wrap=True)
1706 self.assertEqualDiff("signature-policy ignore",
1707 self.output.strip())
1708 self.pkg("property -H signature-policy")
1709 self.assertEqualDiff("signature-policy ignore",
1710 self.output.strip())
1712 def test_signature_policy_2(self):
1713 """Test that the image signature policy of require is propagated
1714 by the system-repository."""
1716 conf_name = "img-sig-require"
1717 self.__prep_configuration([conf_name])
1718 self.__set_responses(conf_name)
1719 sc = pkg5unittest.SysrepoController(
1720 self.apache_confs[conf_name], self.sysrepo_port,
1721 self.common_config_dir, testcase=self)
1722 self.register_apache_controller("sysrepo", sc)
1723 sc.start()
1724 api_obj = self.image_create(props={"use-system-repo": True})
1726 self.pkg("property -H signature-policy")
1727 self.assertEqualDiff("signature-policy require-signatures",
1728 self.output.strip())
1729 self.pkg("property -H signature-policy", su_wrap=True)
1730 self.assertEqualDiff("signature-policy require-signatures",
1731 self.output.strip())
1733 def test_signature_policy_3(self):
1734 """Test that the image signature policy of require-names and the
1735 corresponding required names are propagated by the
1736 system-repository."""
1738 conf_name = "img-sig-req-names"
1739 self.__prep_configuration([conf_name])
1740 self.__set_responses(conf_name)
1741 sc = pkg5unittest.SysrepoController(
1742 self.apache_confs[conf_name], self.sysrepo_port,
1743 self.common_config_dir, testcase=self)
1744 self.register_apache_controller("sysrepo", sc)
1745 sc.start()
1747 api_obj = self.image_create(props={"use-system-repo": True})
1749 self.pkg("property -H signature-policy", su_wrap=True)
1750 self.assertEqualDiff("signature-policy require-names",
1751 self.output.strip())
1752 self.pkg("property -H signature-required-names", su_wrap=True)
1753 self.assertEqualDiff("signature-required-names ['cs1_ch1_ta3']",
1754 self.output.strip())
1755 self.pkg("property -H signature-policy")
1756 self.assertEqualDiff("signature-policy require-names",
1757 self.output.strip())
1758 self.pkg("property -H signature-required-names")
1759 self.assertEqualDiff("signature-required-names ['cs1_ch1_ta3']",
1760 self.output.strip())
1762 def test_signature_policy_4(self):
1763 """Test that the publisher signature policies of ignore are
1764 propagated by the system-repository."""
1766 conf_name = "pub-sig-ignore"
1767 self.__prep_configuration([conf_name])
1768 self.__set_responses(conf_name)
1769 sc = pkg5unittest.SysrepoController(
1770 self.apache_confs[conf_name], self.sysrepo_port,
1771 self.common_config_dir, testcase=self)
1772 self.register_apache_controller("sysrepo", sc)
1773 sc.start()
1774 api_obj = self.image_create(props={"use-system-repo": True})
1776 self.pkg("publisher test1", su_wrap=True)
1777 self.assert_("signature-policy = ignore" in self.output)
1778 pubs = api_obj.get_publishers()
1779 for p in pubs:
1780 self.assertEqualDiff(
1781 p.prefix + ":" + p.properties["signature-policy"],
1782 p.prefix + ":" + "ignore")
1784 def test_signature_policy_5(self):
1785 """Test that the publisher signature policies of
1786 require-signatures are propagated by the system-repository."""
1788 conf_name = "pub-sig-require"
1789 self.__prep_configuration([conf_name])
1790 self.__set_responses(conf_name)
1791 sc = pkg5unittest.SysrepoController(
1792 self.apache_confs[conf_name], self.sysrepo_port,
1793 self.common_config_dir, testcase=self)
1794 self.register_apache_controller("sysrepo", sc)
1795 sc.start()
1796 api_obj = self.image_create(props={"use-system-repo": True})
1798 pubs = api_obj.get_publishers()
1799 for p in pubs:
1800 self.assertEqualDiff(
1801 p.prefix + ":" + p.properties["signature-policy"],
1802 p.prefix + ":" + "require-signatures")
1804 def test_signature_policy_6(self):
1805 """Test that publishers signature policies of require-names and
1806 the corresponding required names are propagated by the
1807 system-repository."""
1809 conf_name = "pub-sig-reqnames"
1810 self.__prep_configuration([conf_name])
1811 self.__set_responses(conf_name)
1812 sc = pkg5unittest.SysrepoController(
1813 self.apache_confs[conf_name], self.sysrepo_port,
1814 self.common_config_dir, testcase=self)
1815 self.register_apache_controller("sysrepo", sc)
1816 sc.start()
1817 api_obj = self.image_create(props={"use-system-repo": True})
1819 pubs = api_obj.get_publishers()
1820 for p in pubs:
1821 self.assertEqualDiff(
1822 p.prefix + ":" + p.properties["signature-policy"],
1823 p.prefix + ":" + "require-names")
1824 self.assertEqualDiff(
1825 p.prefix + ":" +
1826 " ".join(p.properties["signature-required-names"]),
1827 p.prefix + ":" + "cs1_ch1_ta3")
1829 def test_signature_policy_7(self):
1830 """Test that a mixture of publisher signature policies are
1831 correctly propagated."""
1833 conf_name = "pub-sig-mixed"
1834 self.__prep_configuration([conf_name])
1835 self.__set_responses(conf_name)
1836 sc = pkg5unittest.SysrepoController(
1837 self.apache_confs[conf_name], self.sysrepo_port,
1838 self.common_config_dir, testcase=self)
1839 self.register_apache_controller("sysrepo", sc)
1840 sc.start()
1841 api_obj = self.image_create(props={"use-system-repo": True})
1843 pubs = api_obj.get_publishers()
1844 for p in pubs:
1845 if p.prefix == "test1":
1846 self.assertEqualDiff(
1847 p.prefix + ":" +
1848 p.properties["signature-policy"],
1849 p.prefix + ":" + "require-signatures")
1850 elif p.prefix == "test12":
1851 self.assert_("signature-policy" not in
1852 p.properties)
1853 else:
1854 self.assertEqualDiff(
1855 p.prefix + ":" +
1856 p.properties["signature-policy"],
1857 p.prefix + ":" + "verify")
1859 def test_signature_policy_8(self):
1860 """Test that a mixture of image and publisher signature policies
1861 are correctly propagated."""
1863 conf_name = "img-pub-sig-mixed"
1864 self.__prep_configuration([conf_name])
1865 self.__set_responses(conf_name)
1866 sc = pkg5unittest.SysrepoController(
1867 self.apache_confs[conf_name], self.sysrepo_port,
1868 self.common_config_dir, testcase=self)
1869 self.register_apache_controller("sysrepo", sc)
1870 sc.start()
1872 api_obj = self.image_create(props={"use-system-repo": True})
1874 self.pkg("property -H signature-policy")
1875 self.assertEqualDiff("signature-policy ignore",
1876 self.output.strip())
1878 pubs = api_obj.get_publishers()
1879 for p in pubs:
1880 if p.prefix == "test1":
1881 self.assertEqualDiff(
1882 p.prefix + ":" +
1883 p.properties["signature-policy"],
1884 p.prefix + ":" + "require-signatures")
1885 elif p.prefix == "test12":
1886 self.assertEqualDiff(
1887 p.prefix + ":" +
1888 p.properties["signature-policy"],
1889 p.prefix + ":" + "require-names")
1890 self.assertEqualDiff(
1891 p.prefix + ":" +
1892 " ".join(p.properties[
1893 "signature-required-names"]),
1894 p.prefix + ":" + "cs1_ch1_ta3 foo bar baz")
1895 else:
1896 self.assertEqualDiff(
1897 p.prefix + ":" +
1898 p.properties["signature-policy"],
1899 p.prefix + ":" + "ignore")
1901 def test_catalog_is_not_cached_http(self):
1902 """Test that the catalog response is not cached when dealing
1903 with an http repo."""
1905 conf_name = "test1-test3"
1906 self.__prep_configuration([conf_name])
1907 self.__set_responses(conf_name)
1908 sc = pkg5unittest.SysrepoController(
1909 self.apache_confs[conf_name], self.sysrepo_port,
1910 self.common_config_dir, testcase=self)
1911 self.register_apache_controller("sysrepo", sc)
1912 sc.start()
1913 api_obj = self.image_create(props={"use-system-repo": True})
1914 self.pkgsend_bulk(self.rurl1, self.foo11)
1915 self.pkgsend_bulk(self.rurl3, self.bar11)
1916 self.pkg("install bar@1.1")
1917 self.pkg("install foo@1.1")
1919 def test_catalog_is_not_cached_file(self):
1920 """Test that the catalog response is not cached when dealing
1921 with an http repo."""
1923 conf_name = "test1-test3-f"
1924 self.__prep_configuration([conf_name])
1925 self.__set_responses(conf_name)
1926 sc = pkg5unittest.SysrepoController(
1927 self.apache_confs[conf_name], self.sysrepo_port,
1928 self.common_config_dir, testcase=self)
1929 self.register_apache_controller("sysrepo", sc)
1930 sc.start()
1931 api_obj = self.image_create(props={"use-system-repo": True})
1932 self.pkgsend_bulk(self.rurl1, self.foo11)
1933 self.pkgsend_bulk(self.rurl3, self.bar11)
1934 self.pkg("install foo@1.1")
1935 self.pkg("install bar@1.1")
1937 def test_no_unnecessary_refresh(self):
1938 """Test that the pkg client doesn't rebuild the known image
1939 catalog unnecessarily.
1941 The way we test this is kinda obtuse. To test this we use a
1942 staged image operation. This allows us to break up pkg
1943 execution into three stages, planning, preparation, and
1944 execution. At the end of the planning stage, we create and
1945 save an image plan to disk. This image plan includes the last
1946 modified timestamp for the known catalog. Subsequently when
1947 we go to load the plan from disk (during preparation and
1948 execution) we check that timestamp to make sure the image
1949 hasn't changed since the plan was generated (this ensures that
1950 the image plan is still valid). So if the pkg client decides
1951 to update the known catalog unnecessarily then we'll fail when
1952 we try to reload the plan during preparation
1953 (--stage=prepare)."""
1955 self.__prep_configuration(["test1-test12-test12",
1956 "test12-test12"])
1957 self.__set_responses("test1-test12-test12")
1958 sc = pkg5unittest.SysrepoController(
1959 self.apache_confs["test1-test12-test12"], self.sysrepo_port,
1960 self.common_config_dir, testcase=self)
1961 self.register_apache_controller("sysrepo", sc)
1962 sc.start()
1964 # enable the test1 and test12 publishers
1965 self.__set_responses("test1-test12-test12")
1967 api_obj = self.image_create(props={"use-system-repo": True})
1969 # install a package from the test1 and test12 publisher
1970 self.pkg("install example_pkg foo@1.0")
1972 # disable the test1 publisher
1973 self.__set_responses("test12-test12")
1975 # do a staged update
1976 self.pkg("update --stage=plan")
1977 self.pkg("update --stage=prepare")
1978 self.pkg("update --stage=execute")
1980 def test_automatic_refresh(self):
1981 """Test that sysrepo publishers get refreshed automatically
1982 when sysrepo configuration changes."""
1984 self.__prep_configuration(["test1", "test1-test12",
1985 "test1-test12-test12"])
1986 self.__set_responses("test1-test12")
1987 sc = pkg5unittest.SysrepoController(
1988 self.apache_confs["test1-test12"], self.sysrepo_port,
1989 self.common_config_dir, testcase=self)
1990 self.register_apache_controller("sysrepo", sc)
1991 sc.start()
1993 api_obj = self.image_create(props={"use-system-repo": True})
1995 # the client should see packages from the test1 and test12 pubs.
1996 self.pkg("list -afH")
1997 expected = (
1998 "example_pkg 1.0-0 ---\n"
1999 "foo (test12) 1.0-0 ---\n")
2000 output = self.reduceSpaces(self.output)
2001 self.assertEqualDiff(expected, output)
2003 # remove the test12 pub.
2004 self.__set_responses("test1")
2005 self.pkg("list -afH")
2006 expected = "example_pkg 1.0-0 ---\n"
2007 output = self.reduceSpaces(self.output)
2008 self.assertEqualDiff(expected, output)
2010 # add the test12 pub.
2011 self.__set_responses("test1-test12")
2012 self.pkg("list -afH")
2013 expected = (
2014 "example_pkg 1.0-0 ---\n"
2015 "foo (test12) 1.0-0 ---\n")
2016 output = self.reduceSpaces(self.output)
2017 self.assertEqualDiff(expected, output)
2019 # add an origin (with new packages) to the test12 pub.
2020 self.__set_responses("test1-test12-test12")
2021 self.pkg("list -afH")
2022 expected = (
2023 "example_pkg 1.0-0 ---\n"
2024 "foo (test12) 1.1-0 ---\n"
2025 "foo (test12) 1.0-0 ---\n")
2026 output = self.reduceSpaces(self.output)
2027 self.assertEqualDiff(expected, output)
2029 # push a new package into one of the test12 repos.
2030 # (we have to do an explicit refresh since "list" won't do it
2031 # because last_refreshed is too recent.)
2032 self.pkgsend_bulk(self.rurl2, self.bar10)
2033 self.pkg("refresh")
2034 self.pkg("list -afH")
2035 expected = (
2036 "bar (test12) 1.0-0 ---\n"
2037 "example_pkg 1.0-0 ---\n"
2038 "foo (test12) 1.1-0 ---\n"
2039 "foo (test12) 1.0-0 ---\n")
2040 output = self.reduceSpaces(self.output)
2041 self.assertEqualDiff(expected, output)
2043 # remove an origin from the test12 pub.
2044 self.__set_responses("test1-test12")
2045 self.pkg("list -afH")
2046 expected = (
2047 "bar (test12) 1.0-0 ---\n"
2048 "example_pkg 1.0-0 ---\n"
2049 "foo (test12) 1.0-0 ---\n")
2050 output = self.reduceSpaces(self.output)
2051 self.assertEqualDiff(expected, output)
2053 # install a package from the test12 pub.
2054 # then re-do a bunch of the tests above.
2055 self.pkg("install foo")
2057 # remove the test12 pub.
2058 self.__set_responses("test1")
2059 self.pkg("list -afH")
2060 expected = (
2061 "example_pkg 1.0-0 ---\n"
2062 "foo (test12) 1.0-0 i--\n")
2063 output = self.reduceSpaces(self.output)
2064 self.assertEqualDiff(expected, output)
2066 # add the test12 pub.
2067 self.__set_responses("test1-test12")
2068 self.pkg("list -afH")
2069 expected = (
2070 "bar (test12) 1.0-0 ---\n"
2071 "example_pkg 1.0-0 ---\n"
2072 "foo (test12) 1.0-0 i--\n")
2073 output = self.reduceSpaces(self.output)
2074 self.assertEqualDiff(expected, output)
2076 # add an origin (with new packages) to the test12 pub.
2077 self.__set_responses("test1-test12-test12")
2078 self.pkg("list -afH")
2079 expected = (
2080 "bar (test12) 1.0-0 ---\n"
2081 "example_pkg 1.0-0 ---\n"
2082 "foo (test12) 1.1-0 ---\n"
2083 "foo (test12) 1.0-0 i--\n")
2084 output = self.reduceSpaces(self.output)
2085 self.assertEqualDiff(expected, output)
2087 # push a new package into one of the test12 repos.
2088 # (we have to do an explicit refresh since "list" won't do it
2089 # because last_refreshed is too recent.)
2090 self.pkgsend_bulk(self.rurl2, self.bar11)
2091 self.pkg("refresh")
2092 self.pkg("list -afH")
2093 expected = (
2094 "bar (test12) 1.1-0 ---\n"
2095 "bar (test12) 1.0-0 ---\n"
2096 "example_pkg 1.0-0 ---\n"
2097 "foo (test12) 1.1-0 ---\n"
2098 "foo (test12) 1.0-0 i--\n")
2099 output = self.reduceSpaces(self.output)
2100 self.assertEqualDiff(expected, output)
2102 # remove an origin from the test12 pub.
2103 self.__set_responses("test1-test12")
2104 self.pkg("list -afH")
2105 expected = (
2106 "bar (test12) 1.1-0 ---\n"
2107 "bar (test12) 1.0-0 ---\n"
2108 "example_pkg 1.0-0 ---\n"
2109 "foo (test12) 1.0-0 i--\n")
2110 output = self.reduceSpaces(self.output)
2111 self.assertEqualDiff(expected, output)
2113 def test_syspub_toggle(self):
2114 """Test that sysrepo publishers get refreshed automatically
2115 when sysrepo configuration changes."""
2117 self.__prep_configuration(["test1"])
2118 self.__set_responses("test1")
2119 sc = pkg5unittest.SysrepoController(
2120 self.apache_confs["test1"], self.sysrepo_port,
2121 self.common_config_dir, testcase=self)
2122 self.register_apache_controller("sysrepo", sc)
2123 sc.start()
2125 api_obj = self.image_create(props={"use-system-repo": True})
2127 # the client should see packages from the test1 pubs.
2128 self.pkg("list -afH")
2129 expected = (
2130 "example_pkg 1.0-0 ---\n")
2131 output = self.reduceSpaces(self.output)
2132 self.assertEqualDiff(expected, output)
2134 # push a new package into one of the test12 repos.
2135 self.pkgsend_bulk(self.rurl1, self.bar10)
2137 # verify that the client only sees the new package after an
2138 # explicit refresh
2139 self.pkg("list -afH")
2140 expected = (
2141 "example_pkg 1.0-0 ---\n")
2142 output = self.reduceSpaces(self.output)
2143 self.assertEqualDiff(expected, output)
2144 self.pkg("refresh")
2145 self.pkg("list -afH")
2146 expected = (
2147 "bar 1.0-0 ---\n"
2148 "example_pkg 1.0-0 ---\n")
2149 output = self.reduceSpaces(self.output)
2150 self.assertEqualDiff(expected, output)
2152 # disable the sysrepo.
2153 self.pkg("set-property use-system-repo False")
2155 # the client should not see any packages.
2156 self.pkg("list -afH", exit=1)
2157 expected = ("")
2158 output = self.reduceSpaces(self.output)
2159 self.assertEqualDiff(expected, output)
2161 # push a new package into one of the test12 repos.
2162 self.pkgsend_bulk(self.rurl1, self.bar11)
2164 # enable the sysrepo.
2165 self.pkg("set-property use-system-repo True")
2167 # the client should see packages from the test1 pubs.
2168 self.pkg("list -afH")
2169 expected = (
2170 "bar 1.1-0 ---\n"
2171 "bar 1.0-0 ---\n"
2172 "example_pkg 1.0-0 ---\n")
2173 output = self.reduceSpaces(self.output)
2174 self.assertEqualDiff(expected, output)
2176 # install a package from the test12 pub.
2177 # then re-do a bunch of the tests above.
2178 self.pkg("install example_pkg")
2180 # disable the sysrepo.
2181 self.pkg("set-property use-system-repo False")
2183 # the client should only see the installed package.
2184 self.pkg("list -afH")
2185 expected = (
2186 "example_pkg 1.0-0 i--\n")
2187 output = self.reduceSpaces(self.output)
2188 self.assertEqualDiff(expected, output)
2190 # push a new package into one of the test12 repos.
2191 self.pkgsend_bulk(self.rurl1, self.foo10)
2193 # enable the sysrepo.
2194 self.pkg("set-property use-system-repo True")
2196 # the client should see packages from the test1 pubs.
2197 self.pkg("list -afH")
2198 expected = (
2199 "bar 1.1-0 ---\n"
2200 "bar 1.0-0 ---\n"
2201 "example_pkg 1.0-0 i--\n"
2202 "foo 1.0-0 ---\n")
2203 output = self.reduceSpaces(self.output)
2204 self.assertEqualDiff(expected, output)
2206 __smf_cmds_template = { \
2207 "usr/bin/svcprop" : """\
2208 #!/usr/bin/python
2210 import getopt
2211 import sys
2213 if __name__ == "__main__":
2214 try:
2215 opts, pargs = getopt.getopt(sys.argv[1:], "cp:")
2216 except getopt.GetoptError as e:
2217 usage(_("illegal global option -- {{0}}").format(e.opt))
2219 prop_dict = {{
2220 "config/listen_host" : "localhost",
2221 "config/listen_port" : "{proxy_port}",
2222 "general/enabled" : "true",
2225 found_c = False
2226 prop = None
2227 for opt, arg in opts:
2228 if opt == "-c":
2229 found_c = True
2230 elif opt == "-p":
2231 prop = arg
2232 if prop:
2233 prop = prop_dict.get(prop, None)
2234 if not found_c or not prop:
2235 sys.exit(1)
2236 print(prop)
2237 sys.exit(0)
2238 for k, v in prop_dict.iteritems():
2239 print("{{0}} {{1}}".format(k, v))
2240 sys.exit(0)
2241 """,
2243 "usr/sbin/svcadm" : """\
2244 #!/usr/bin/python
2246 import getopt
2247 import sys
2249 if __name__ == "__main__":
2250 try:
2251 opts, pargs = getopt.getopt(sys.argv[1:], "cp:")
2252 except getopt.GetoptError as e:
2253 usage(_("illegal global option -- {{0}}").format(e.opt))
2255 prop_dict = {{
2256 "config/proxy_host" : "localhost",
2257 "config/proxy_port" : "{proxy_port}"
2260 if len(pargs) != 2 or pargs[0] != "restart" or \
2261 pargs[1] != "svc:/application/pkg/system-repository":
2262 sys.exit(1)
2263 sys.exit(0)
2264 """}
2266 https_conf = """\
2267 # Configuration and logfile names: If the filenames you specify for many
2268 # of the server's control files begin with "/" (or "drive:/" for Win32), the
2269 # server will use that explicit path. If the filenames do *not* begin
2270 # with "/", the value of ServerRoot is prepended -- so "/var/apache2/2.2/logs/foo_log"
2271 # with ServerRoot set to "/usr/apache2/2.2" will be interpreted by the
2272 # server as "/usr/apache2/2.2//var/apache2/2.2/logs/foo_log".
2275 # ServerRoot: The top of the directory tree under which the server's
2276 # configuration, error, and log files are kept.
2278 # Do not add a slash at the end of the directory path. If you point
2279 # ServerRoot at a non-local disk, be sure to point the LockFile directive
2280 # at a local disk. If you wish to share the same ServerRoot for multiple
2281 # httpd daemons, you will need to change at least LockFile and PidFile.
2283 ServerRoot "/usr/apache2/2.2"
2285 PidFile "{pidfile}"
2288 # Listen: Allows you to bind Apache to specific IP addresses and/or
2289 # ports, instead of the default. See also the <VirtualHost>
2290 # directive.
2292 # Change this to Listen on specific IP addresses as shown below to
2293 # prevent Apache from glomming onto all bound IP addresses.
2295 Listen 0.0.0.0:{https_port}
2298 # Dynamic Shared Object (DSO) Support
2300 # To be able to use the functionality of a module which was built as a DSO you
2301 # have to place corresponding `LoadModule' lines within the appropriate
2302 # (32-bit or 64-bit module) /etc/apache2/2.2/conf.d/modules-*.load file so that
2303 # the directives contained in it are actually available _before_ they are used.
2305 <IfDefine 64bit>
2306 Include /etc/apache2/2.2/conf.d/modules-64.load
2307 </IfDefine>
2308 <IfDefine !64bit>
2309 Include /etc/apache2/2.2/conf.d/modules-32.load
2310 </IfDefine>
2312 <IfModule !mpm_netware_module>
2314 # If you wish httpd to run as a different user or group, you must run
2315 # httpd as root initially and it will switch.
2317 # User/Group: The name (or #number) of the user/group to run httpd as.
2318 # It is usually good practice to create a dedicated user and group for
2319 # running httpd, as with most system services.
2321 User webservd
2322 Group webservd
2324 </IfModule>
2326 # 'Main' server configuration
2328 # The directives in this section set up the values used by the 'main'
2329 # server, which responds to any requests that aren't handled by a
2330 # <VirtualHost> definition. These values also provide defaults for
2331 # any <VirtualHost> containers you may define later in the file.
2333 # All of these directives may appear inside <VirtualHost> containers,
2334 # in which case these default settings will be overridden for the
2335 # virtual host being defined.
2339 # ServerName gives the name and port that the server uses to identify itself.
2340 # This can often be determined automatically, but we recommend you specify
2341 # it explicitly to prevent problems during startup.
2343 # If your host doesn't have a registered DNS name, enter its IP address here.
2345 ServerName 127.0.0.1
2348 # DocumentRoot: The directory out of which you will serve your
2349 # documents. By default, all requests are taken from this directory, but
2350 # symbolic links and aliases may be used to point to other locations.
2352 DocumentRoot "/"
2355 # Each directory to which Apache has access can be configured with respect
2356 # to which services and features are allowed and/or disabled in that
2357 # directory (and its subdirectories).
2359 # First, we configure the "default" to be a very restrictive set of
2360 # features.
2362 <Directory />
2363 Options None
2364 AllowOverride None
2365 Order deny,allow
2366 Deny from all
2367 </Directory>
2370 # Note that from this point forward you must specifically allow
2371 # particular features to be enabled - so if something's not working as
2372 # you might expect, make sure that you have specifically enabled it
2373 # below.
2377 # This should be changed to whatever you set DocumentRoot to.
2381 # DirectoryIndex: sets the file that Apache will serve if a directory
2382 # is requested.
2384 <IfModule dir_module>
2385 DirectoryIndex index.html
2386 </IfModule>
2389 # The following lines prevent .htaccess and .htpasswd files from being
2390 # viewed by Web clients.
2392 <FilesMatch "^\.ht">
2393 Order allow,deny
2394 Deny from all
2395 Satisfy All
2396 </FilesMatch>
2399 # ErrorLog: The location of the error log file.
2400 # If you do not specify an ErrorLog directive within a <VirtualHost>
2401 # container, error messages relating to that virtual host will be
2402 # logged here. If you *do* define an error logfile for a <VirtualHost>
2403 # container, that host's errors will be logged there and not here.
2405 ErrorLog "{log_locs}/error_log"
2408 # LogLevel: Control the number of messages logged to the error_log.
2409 # Possible values include: debug, info, notice, warn, error, crit,
2410 # alert, emerg.
2412 LogLevel debug
2416 <IfModule log_config_module>
2418 # The following directives define some format nicknames for use with
2419 # a CustomLog directive (see below).
2421 LogFormat "{common_log_format}" common
2424 # The location and format of the access logfile (Common Logfile Format).
2425 # If you do not define any access logfiles within a <VirtualHost>
2426 # container, they will be logged here. Contrariwise, if you *do*
2427 # define per-<VirtualHost> access logfiles, transactions will be
2428 # logged therein and *not* in this file.
2430 CustomLog "{log_locs}/access_log" common
2431 </IfModule>
2434 # DefaultType: the default MIME type the server will use for a document
2435 # if it cannot otherwise determine one, such as from filename extensions.
2436 # If your server contains mostly text or HTML documents, "text/plain" is
2437 # a good value. If most of your content is binary, such as applications
2438 # or images, you may want to use "application/octet-stream" instead to
2439 # keep browsers from trying to display binary files as though they are
2440 # text.
2442 DefaultType text/plain
2444 <IfModule mime_module>
2446 # TypesConfig points to the file containing the list of mappings from
2447 # filename extension to MIME-type.
2449 TypesConfig /etc/apache2/2.2/mime.types
2452 # AddType allows you to add to or override the MIME configuration
2453 # file specified in TypesConfig for specific file types.
2455 AddType application/x-compress .Z
2456 AddType application/x-gzip .gz .tgz
2458 # Add a new mime.type for .p5i file extension so that clicking on
2459 # this file type on a web page launches PackageManager in a Webinstall mode.
2460 AddType application/vnd.pkg5.info .p5i
2461 </IfModule>
2464 # Note: The following must must be present to support
2465 # starting without SSL on platforms with no /dev/random equivalent
2466 # but a statically compiled-in mod_ssl.
2468 <IfModule ssl_module>
2469 SSLRandomSeed startup builtin
2470 SSLRandomSeed connect builtin
2471 </IfModule>
2473 <VirtualHost 0.0.0.0:{https_port}>
2474 AllowEncodedSlashes On
2475 ProxyRequests Off
2476 MaxKeepAliveRequests 10000
2478 SSLEngine On
2480 # Cert paths
2481 SSLCertificateFile {server-ssl-cert}
2482 SSLCertificateKeyFile {server-ssl-key}
2484 # Combined product CA certs for client verification
2485 SSLCACertificateFile {server-ca-cert}
2487 SSLVerifyClient require
2489 <Location />
2490 SSLVerifyDepth 1
2492 # The client's certificate must pass verification, and must have
2493 # a CN which matches this repository.
2494 SSLRequire ( {ssl-special} =~ m/{server-ca-taname}/ )
2496 # set max to number of threads in depot
2497 ProxyPass {proxied-server}/ nocanon max=500
2498 </Location>
2499 </VirtualHost>