From eb5a4dda1fc221bf29c45eef47f0bfadec250943 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 6 Apr 2016 13:27:23 -0400 Subject: rh_subscription: only check subscription if configured The rh_subscription config module would attempt to connect to the RHN servers even when no config is provided. Now, instead check to make sure that valid config is provided first. That consists of username and password or a activation key. LP: #1536706 --- cloudinit/config/cc_rh_subscription.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'cloudinit') diff --git a/cloudinit/config/cc_rh_subscription.py b/cloudinit/config/cc_rh_subscription.py index 6087c45c..2871984a 100644 --- a/cloudinit/config/cc_rh_subscription.py +++ b/cloudinit/config/cc_rh_subscription.py @@ -19,9 +19,14 @@ from cloudinit import util -def handle(_name, cfg, _cloud, log, _args): +def handle(name, cfg, _cloud, log, _args): sm = SubscriptionManager(cfg) sm.log = log + if not sm.is_configured(): + log.debug("Activation key not provided, config module %s disabled.", + _name) + return None + if not sm.is_registered: try: verify, verify_msg = sm._verify_keys() @@ -95,7 +100,6 @@ class SubscriptionManager(object): self.disable_repo = self.rhel_cfg.get('disable-repo') self.servicelevel = self.rhel_cfg.get('service-level') self.subman = ['subscription-manager'] - self.is_registered = self._is_registered() def log_success(self, msg): '''Simple wrapper for logging info messages. Useful for unittests''' @@ -134,7 +138,7 @@ class SubscriptionManager(object): return False, no_auto return True, None - def _is_registered(self): + def is_registered(self): ''' Checks if the system is already registered and returns True if so, else False @@ -400,3 +404,6 @@ class SubscriptionManager(object): self.log.debug("Disabled the following repos: %s" % (", ".join(disable_list)).replace('--disable=', '')) return True + + def is_configured(self): + return (self.userid and self.password) or self.activation_key -- cgit v1.2.3 From 578fed15061293ce421eec1c9c1e2e056631a734 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 6 Apr 2016 13:57:00 -0400 Subject: fix tests and hopefully actually work --- cloudinit/config/cc_rh_subscription.py | 7 +++---- tests/unittests/test_rh_subscription.py | 9 +++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'cloudinit') diff --git a/cloudinit/config/cc_rh_subscription.py b/cloudinit/config/cc_rh_subscription.py index 2871984a..3a113aea 100644 --- a/cloudinit/config/cc_rh_subscription.py +++ b/cloudinit/config/cc_rh_subscription.py @@ -23,11 +23,10 @@ def handle(name, cfg, _cloud, log, _args): sm = SubscriptionManager(cfg) sm.log = log if not sm.is_configured(): - log.debug("Activation key not provided, config module %s disabled.", - _name) + log.debug("%s: module not configured.", name) return None - if not sm.is_registered: + if not sm.is_registered(): try: verify, verify_msg = sm._verify_keys() if verify is not True: @@ -406,4 +405,4 @@ class SubscriptionManager(object): return True def is_configured(self): - return (self.userid and self.password) or self.activation_key + return bool((self.userid and self.password) or self.activation_key) diff --git a/tests/unittests/test_rh_subscription.py b/tests/unittests/test_rh_subscription.py index 38d5763a..8c586ad7 100644 --- a/tests/unittests/test_rh_subscription.py +++ b/tests/unittests/test_rh_subscription.py @@ -126,7 +126,8 @@ class TestBadInput(unittest.TestCase): 'enable-repo': 'not_a_list' }} config_badkey = {'rh_subscription': - {'activation_key': 'abcdef1234', + {'activation-key': 'abcdef1234', + 'fookey': 'bar', 'org': '123', }} @@ -138,7 +139,11 @@ class TestBadInput(unittest.TestCase): ''' Attempt to register without the password key/value ''' - self.input_is_missing_data(self.config_no_password) + self.SM._sub_man_cli = mock.MagicMock( + side_effect=[util.ProcessExecutionError, (self.reg, 'bar')]) + self.handle(self.name, self.config_no_password, self.cloud_init, + self.log, self.args) + self.assertEqual(self.SM._sub_man_cli.call_count, 0) def test_no_org(self): ''' -- cgit v1.2.3