← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~smoser/cloud-init/trunk.1536706 into lp:cloud-init

 

Scott Moser has proposed merging lp:~smoser/cloud-init/trunk.1536706 into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)
Related bugs:
  Bug #1536706 in cloud-init: "rh_subscription plugin attemps connection even when no config is provided"
  https://bugs.launchpad.net/cloud-init/+bug/1536706

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/trunk.1536706/+merge/291656
-- 
Your team cloud init development team is requested to review the proposed merge of lp:~smoser/cloud-init/trunk.1536706 into lp:cloud-init.
=== modified file 'cloudinit/config/cc_rh_subscription.py'
--- cloudinit/config/cc_rh_subscription.py	2016-03-04 15:51:05 +0000
+++ cloudinit/config/cc_rh_subscription.py	2016-04-12 17:01:26 +0000
@@ -19,10 +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_registered:
+    if not sm.is_configured():
+        log.debug("%s: module not configured.", name)
+        return None
+
+    if not sm.is_registered():
         try:
             verify, verify_msg = sm._verify_keys()
             if verify is not True:
@@ -95,7 +99,6 @@
         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 +137,7 @@
             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 +403,6 @@
             self.log.debug("Disabled the following repos: %s" %
                            (", ".join(disable_list)).replace('--disable=', ''))
         return True
+
+    def is_configured(self):
+        return bool((self.userid and self.password) or self.activation_key)

=== modified file 'tests/unittests/test_rh_subscription.py'
--- tests/unittests/test_rh_subscription.py	2015-05-29 14:18:49 +0000
+++ tests/unittests/test_rh_subscription.py	2016-04-12 17:01:26 +0000
@@ -126,7 +126,8 @@
                        'enable-repo': 'not_a_list'
                        }}
     config_badkey = {'rh_subscription':
-                     {'activation_key': 'abcdef1234',
+                     {'activation-key': 'abcdef1234',
+                      'fookey': 'bar',
                       'org': '123',
                       }}
 
@@ -138,7 +139,11 @@
         '''
         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):
         '''


Follow ups