Skip to content

Commit

Permalink
rename certmgr.py to action_client
Browse files Browse the repository at this point in the history
  • Loading branch information
alikins committed Apr 30, 2014
1 parent 5235b36 commit b53fdb9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
8 changes: 4 additions & 4 deletions src/daemons/rhsmcertd-worker.py
Expand Up @@ -27,7 +27,7 @@
from subscription_manager.injectioninit import init_dep_injection
init_dep_injection()

from subscription_manager import certmgr
from subscription_manager import action_client
from subscription_manager import managerlib
from subscription_manager.certlib import ConsumerIdentity
from subscription_manager.i18n_optparse import OptionParser, \
Expand All @@ -46,11 +46,11 @@ def main(options, log):

try:
if options.autoheal:
action_client = certmgr.HealingActionClient()
actionclient = action_client.HealingActionClient()
else:
action_client = certmgr.ActionCertClient()
actionclient = action_client.ActionCertClient()

update_reports = action_client.update(options.autoheal)
update_reports = actionclient.update(options.autoheal)

for update_report in update_reports:
# FIXME: make sure we don't get None reports
Expand Down
Expand Up @@ -140,7 +140,7 @@ def _get_libset(self):
# *Lib things are weird, since some are idempotent, but
# some arent. entcertlib/repolib .update can both install
# certs, and/or delete all of them.
class UnregisterCertManager(BaseActionClient):
class UnregisterActionClient(BaseActionClient):
"""CertManager for cleaning up on unregister.
This class should not need a consumer id, or a uep connection, since it
Expand Down
2 changes: 1 addition & 1 deletion src/subscription_manager/gui/registergui.py
Expand Up @@ -32,7 +32,7 @@
from rhsm.connection import GoneException

from subscription_manager.branding import get_branding
from subscription_manager.certmgr import ActionClient
from subscription_manager.action_client import ActionClient
from subscription_manager.gui import networkConfig
from subscription_manager.gui import widgets
from subscription_manager.injection import IDENTITY, PLUGIN_MANAGER, require, \
Expand Down
4 changes: 2 additions & 2 deletions src/subscription_manager/managercli.py
Expand Up @@ -35,7 +35,7 @@

from subscription_manager.branding import get_branding
from subscription_manager.entcertlib import EntCertLib
from subscription_manager.certmgr import ActionClient, UnregisterCertManager
from subscription_manager.action_client import ActionClient, UnregisterActionClient
from subscription_manager.cert_sorter import ComplianceManager, FUTURE_SUBSCRIBED, \
SUBSCRIBED, NOT_SUBSCRIBED, EXPIRED, PARTIALLY_SUBSCRIBED, UNKNOWN
from subscription_manager.cli import AbstractCLICommand, CLI, system_exit
Expand Down Expand Up @@ -1183,7 +1183,7 @@ def _do_command(self):
try:
# there is no consumer cert at this point, a uep object
# is not useful
cleanup_certmgr = UnregisterCertManager()
cleanup_certmgr = UnregisterActionClient()
cleanup_certmgr.update()
except Exception, e:
pass
Expand Down
66 changes: 33 additions & 33 deletions test/test_certmgr.py
Expand Up @@ -19,7 +19,7 @@
import stubs

from rhsm import ourjson as json
from subscription_manager import certmgr
from subscription_manager import action_client
from subscription_manager import entcertlib
from subscription_manager import identitycertlib
from subscription_manager import repolib
Expand Down Expand Up @@ -142,45 +142,45 @@ def tearDown(self):
class TestActionClient(ActionClientTestBase):

def test_init(self):
mgr = certmgr.ActionClient()
mgr.update()
actionclient = action_client.ActionClient()
actionclient.update()

# see bz #852706
@mock.patch.object(entcertlib.EntCertLib, 'update')
def test_gone_exception(self, mock_update):
mock_update.side_effect = GoneException(410, "bye bye", " 234234")
mgr = certmgr.ActionClient()
self.assertRaises(GoneException, mgr.update)
actionclient = action_client.ActionClient()
self.assertRaises(GoneException, actionclient.update)

# see bz #852706, except this time for idcertlib
@mock.patch.object(identitycertlib.IdentityCertLib, 'update')
def test_idcertlib_gone_exception(self, mock_update):
mock_update.side_effect = GoneException(410, "bye bye", " 234234")
mgr = certmgr.ActionClient()
self.assertRaises(GoneException, mgr.update)
actionclient = action_client.ActionClient()
self.assertRaises(GoneException, actionclient.update)

# just verify the certlib update worked
report = mgr.entcertlib.report
report = actionclient.entcertlib.report
self.assertTrue(self.stub_ent1.serial in report.valid)

@mock.patch.object(entcertlib.EntCertLib, 'update')
@mock.patch('subscription_manager.certmgr.log')
@mock.patch('subscription_manager.action_client.log')
def test_entcertlib_update_exception(self, mock_log, mock_update):
mock_update.side_effect = ExceptionalException()
mgr = certmgr.ActionClient()
mgr.update()
actionclient = action_client.ActionClient()
actionclient.update()

for call in mock_log.method_calls:
if call[0] == 'exception' and isinstance(call[1][0], ExceptionalException):
return
self.fail("Did not ExceptionException in the logged exceptions")

@mock.patch.object(identitycertlib.IdentityCertLib, 'update')
@mock.patch('subscription_manager.certmgr.log')
@mock.patch('subscription_manager.action_client.log')
def test_idcertlib_update_exception(self, mock_log, mock_update):
mock_update.side_effect = ExceptionalException()
mgr = certmgr.ActionClient()
mgr.update()
actionclient = action_client.ActionClient()
actionclient.update()

for call in mock_log.method_calls:
if call[0] == 'exception' and isinstance(call[1][0], ExceptionalException):
Expand Down Expand Up @@ -210,21 +210,21 @@ def test_missing(self, cert_build_mock):
self._stub_certificate_calls()

cert_build_mock.return_value = (mock.Mock(), self.stub_ent1)
mgr = certmgr.ActionClient()
mgr.update()
actionclient = action_client.ActionClient()
actionclient.update()

report = mgr.entcertlib.report
report = actionclient.entcertlib.report
self.assertTrue(self.stub_ent1 in report.added)

def test_rogue(self):
# to mock "rogue" certs we need some local, that are not known to the
# server so getCertificateSerials to return nothing
self.mock_uep.getCertificateSerials = mock.Mock(return_value=[])
self.set_consumer_auth_cp(self.mock_uep)
mgr = certmgr.ActionClient()
mgr.update()
actionclient = action_client.ActionClient()
actionclient.update()

report = mgr.entcertlib.report
report = actionclient.entcertlib.report
# our local ent certs should be showing up as rogue
self.assertTrue(self.local_ent_certs[0] in report.rogue)
self.assertTrue(self.local_ent_certs[1] in report.rogue)
Expand All @@ -242,10 +242,10 @@ def test_expired(self, cert_build_mock):
self.mock_uep.getCertificateSerials = mock.Mock(return_value=[])
self.set_consumer_auth_cp(self.mock_uep)

mgr = certmgr.ActionClient()
mgr.update()
actionclient = action_client.ActionClient()
actionclient.update()

report = mgr.entcertlib.report
report = actionclient.entcertlib.report
# the expired certs should be delete/rogue and expired
#report = self.update_action_syslog_mock.call_args[0][0]
self.assertTrue(self.stub_ent1 in report.rogue)
Expand All @@ -258,10 +258,10 @@ def test_exception_on_cert_write(self, mock_log, mock_cert_build):
self._stub_certificate_calls()

mock_cert_build.side_effect = ExceptionalException()
mgr = certmgr.ActionClient()
actionclient = action_client.ActionClient()
# we should fail on the certlib.update, but keep going...
# and handle it well.
mgr.update()
actionclient.update()

for call in mock_log.method_calls:
if call[0] == 'exception' and isinstance(call[1][0], ExceptionalException):
Expand All @@ -274,16 +274,16 @@ def test_healing_no_heal(self):
self.mock_cert_sorter.is_valid = mock.Mock(return_value=True)
self.mock_cert_sorter.compliant_until = datetime.now() + \
timedelta(days=15)
mgr = certmgr.HealingActionClient()
mgr.update(autoheal=True)
actionclient = action_client.HealingActionClient()
actionclient.update(autoheal=True)
self.assertFalse(self.mock_uep.bind.called)

def test_healing_needs_heal(self):
# need a stub product dir with prods with no entitlements,
# don't have to mock here since we can actually pass in a product
self.mock_cert_sorter.is_valid = mock.Mock(return_value=False)
mgr = certmgr.HealingActionClient()
mgr.update(autoheal=True)
actionclient = action_client.HealingActionClient()
actionclient.update(autoheal=True)
self.assertTrue(self.mock_uep.bind.called)

@mock.patch.object(entcertlib.EntitlementCertBundleInstaller, 'build_cert')
Expand All @@ -296,8 +296,8 @@ def test_healing_needs_heal_tomorrow(self, cert_build_mock):
self.stub_ent_expires_tomorrow)

self._stub_certificate_calls([self.stub_ent_expires_tomorrow])
mgr = certmgr.HealingActionClient()
mgr.update(autoheal=True)
actionclient = action_client.HealingActionClient()
actionclient.update(autoheal=True)
# see if we tried to update certs
self.assertTrue(self.mock_uep.bind.called)

Expand All @@ -308,8 +308,8 @@ def test_healing_trigger_exception(self, mock_log):
# cert sorter using the product dir. Just making sure an unexpected
# exception is logged and not bubbling up.
self.mock_cert_sorter.is_valid = mock.Mock(side_effect=TypeError())
mgr = certmgr.HealingActionClient()
mgr.update(autoheal=True)
actionclient = action_client.HealingActionClient()
actionclient.update(autoheal=True)
for call in mock_log.method_calls:
if call[0] == 'exception' and isinstance(call[1][0], TypeError):
return
Expand Down

0 comments on commit b53fdb9

Please sign in to comment.