candlepin/python-rhsm — pull request #122 by dgoodwin (2014-06-09 15:13:58+00:00)
Title: Detect when operating in container mode and load host system's config.

With the end goal of being able to generate correct redhat.repo for a
container, we need a way to access the host's /etc/rhsm configuration in as
futureproof a way as possible. (as this may change) To accommodate this we
check for existence of a (presumably) symlink at /etc/rhsm-host, and if found,
we assume we're operating inside a container and load the host's config. The
symlink allows for possibility of the actual location of host's config
changing, and *not* re-using /etc/rhsm/ helps prevent any complications with
rpm's and file ownership. (as /etc/rhsm is owned by our packages)

However there is an additional problem with the contents of rhsm.conf, while it
may live at /etc/rhsm-host in container mode, it still contains two properties
referencing full paths under /etc/rhsm for ca certificates and the CDN cert. We
need the hosts values in a Satellite use-case, so these must be adjusted.

To accommodate this we check if we're in container mode, and if so load a
config sub-class which replaces /etc/rhsm with /etc/rhsm-host in these values,
if it looks like we should.

A similar replacement will be done for entitlement directory at
/etc/pki/entitlement-host for the same reasons.

(dgoodwin@lenovo {dgoodwin/host-config} ~/src/python-rhsm) $ cat test.py
#!/usr/bin/python

from rhsm.config import initConfig

c = initConfig()
print c
print "ca_cert_dir = %s" % c.get('rhsm', 'ca_cert_dir')
print "repo_ca_cert = %s" % c.get('rhsm', 'repo_ca_cert')
print "entitlementcertdir = %s" % c.get('rhsm', 'entitlementcertdir')
(dgoodwin@lenovo {dgoodwin/host-config} ~/src/python-rhsm) $ python test.py

ca_cert_dir = /etc/rhsm/ca/
repo_ca_cert = /etc/rhsm/ca/candlepin-local.pem
entitlementcertdir = /etc/pki/entitlement
(dgoodwin@lenovo {dgoodwin/host-config} ~/src/python-rhsm) $ sudo ln -s /etc/rhsm /etc/rhsm-host
(dgoodwin@lenovo {dgoodwin/host-config} ~/src/python-rhsm) $ python test.py

ca_cert_dir = /etc/rhsm-host/ca/
repo_ca_cert = /etc/rhsm-host/ca/candlepin-local.pem
entitlementcertdir = /etc/pki/entitlement-host
(dgoodwin@lenovo {dgoodwin/host-config} ~/src/python-rhsm) $

![rdmjks0](https://cloud.githubusercontent.com/assets/51265/3216630/1c05d81a-efd5-11e3-8bb1-251d72bbbab8.gif)