Skip to content

Commit

Permalink
refs #9403 - get rhsm certificate from rhsm configration
Browse files Browse the repository at this point in the history
  • Loading branch information
stbenjam committed Feb 18, 2015
1 parent 71bd219 commit 401c2f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/katello/agent/katelloplugin.py
Expand Up @@ -71,7 +71,7 @@ def bundle(certificate):
return path
finally:
fp.close()


def registration_changed(path):
"""
Expand Down Expand Up @@ -117,10 +117,11 @@ def setup_plugin():
cfg = plugin.cfg()
rhsm_conf = Config(RHSM_CONFIG_PATH)
certificate = ConsumerIdentity.read()
cfg.messaging.cacert = rhsm_conf['rhsm']['repo_ca_cert'] % {'ca_cert_dir': rhsm_conf['rhsm']['ca_cert_dir']}
cfg.messaging.url = 'ssl://%s:5671' % rhsm_conf['server']['hostname']
cfg.messaging.uuid = 'pulp.agent.%s' % certificate.getConsumerId()
bundle(certificate)


@initializer
def init_plugin():
Expand All @@ -137,7 +138,7 @@ def init_plugin():
path_monitor.add(path, registration_changed)
path_monitor.add(REPOSITORY_PATH, send_enabled_report)
path_monitor.start()


class Conduit(HandlerConduit):
"""
Expand Down
8 changes: 6 additions & 2 deletions test/test_plugin.py
Expand Up @@ -165,14 +165,17 @@ class TestSetupPlugin(PluginTest):
@patch('katello.agent.katelloplugin.ConsumerIdentity.read')
@patch('katello.agent.katelloplugin.ConsumerIdentity.existsAndValid')
def test_setup_when_registered(self, fake_valid, fake_read, fake_conf, fake_bundle):
ca_cert_dir = '/etc/rhsm/ca/'
ca_cert = '%(ca_cert_dir)skatello-server-ca.pem'
consumer_id = '1234'
host = 'redhat.com'
fake_valid.return_value = True
fake_certificate = Mock()
fake_certificate.getConsumerId.return_value = consumer_id
fake_valid.return_value = True
fake_read.return_value = fake_certificate
fake_conf.return_value = {'server': {'hostname': host}}
fake_conf.return_value = {'server': {'hostname': host}, 'rhsm': {'repo_ca_cert': ca_cert,
'ca_cert_dir': ca_cert_dir}}

# test
self.plugin.setup_plugin()
Expand All @@ -182,6 +185,7 @@ def test_setup_when_registered(self, fake_valid, fake_read, fake_conf, fake_bund
fake_read.assert_called_with()
fake_bundle.assert_called_with(fake_certificate)
plugin_cfg = self.plugin.plugin.cfg()
self.assertEqual(plugin_cfg.messaging.cacert, '/etc/rhsm/ca/katello-server-ca.pem')
self.assertEqual(plugin_cfg.messaging.url, 'ssl://%s:5671' % host)
self.assertEqual(plugin_cfg.messaging.uuid, 'pulp.agent.%s' % consumer_id)

Expand Down Expand Up @@ -462,4 +466,4 @@ def test_uninstall(self, mock_dispatcher, mock_conduit):

# validation
mock_dispatcher().uninstall.assert_called_with(mock_conduit(), units, options)
self.assertEqual(report, _report.dict())
self.assertEqual(report, _report.dict())

0 comments on commit 401c2f6

Please sign in to comment.