diff --git a/cloudbaseinit/plugins/windows/licensing.py b/cloudbaseinit/plugins/windows/licensing.py index b06ed2a4..cd57fa0d 100644 --- a/cloudbaseinit/plugins/windows/licensing.py +++ b/cloudbaseinit/plugins/windows/licensing.py @@ -64,17 +64,15 @@ def _set_kms_host(self, service, manager): manager.set_kms_host(*kms_host.split(':')) def _activate_windows(self, service, manager): - if CONF.activate_windows: - # note(alexpilotti): KMS clients activate themselves - # so this could be skipped if a KMS host is set - LOG.info("Activating Windows") - activation_result = manager.activate_windows() - LOG.debug("Activation result:\n%s" % activation_result) + # note(alexpilotti): KMS clients activate themselves + # so this could be skipped if a KMS host is set + LOG.info("Activating Windows") + activation_result = manager.activate_windows() + LOG.debug("Activation result:\n%s" % activation_result) def _log_licensing_info(self, manager): - if CONF.log_licensing_info: - license_info = manager.get_licensing_info() - LOG.info('Microsoft Windows license info:\n%s' % license_info) + license_info = manager.get_licensing_info() + LOG.info('Microsoft Windows license info:\n%s' % license_info) def execute(self, service, shared_data): osutils = osutils_factory.get_os_utils() @@ -82,19 +80,19 @@ def execute(self, service, shared_data): if osutils.is_nano_server(): LOG.info("Licensing info and activation are not available on " "Nano Server") - else: - manager = licensing.get_licensing_manager() - - eval_end_date = manager.is_eval() - if eval_end_date: - LOG.info("Evaluation license, skipping activation. " - "Evaluation end date: %s", eval_end_date) - else: - self._set_product_key(service, manager) - self._set_kms_host(service, manager) - self._activate_windows(service, manager) - manager.refresh_status() + return base.PLUGIN_EXECUTION_DONE, False + + manager = licensing.get_licensing_manager() + # set kms / avma product keys and kms hosts if any + self._set_product_key(service, manager) + self._set_kms_host(service, manager) + + if CONF.activate_windows: + self._activate_windows(service, manager) + + if CONF.log_licensing_info: + manager.refresh_status() self._log_licensing_info(manager) return base.PLUGIN_EXECUTION_DONE, False diff --git a/cloudbaseinit/tests/plugins/windows/test_licensing.py b/cloudbaseinit/tests/plugins/windows/test_licensing.py index 1fd49239..2db4a072 100644 --- a/cloudbaseinit/tests/plugins/windows/test_licensing.py +++ b/cloudbaseinit/tests/plugins/windows/test_licensing.py @@ -94,9 +94,8 @@ def test_activate_windows(self): expected_logs = [ "Activating Windows", "Activation result:\n%s" % activate_result] - with testutils.ConfPatcher('activate_windows', True): - with self.snatcher: - self._licensing._activate_windows(mock_service, mock_manager) + with self.snatcher: + self._licensing._activate_windows(mock_service, mock_manager) self.assertEqual(self.snatcher.output, expected_logs) mock_manager.activate_windows.assert_called_once_with() @@ -110,37 +109,33 @@ def _test_execute(self, mock_get_licensing_manager, mock_set_product_key, mock_set_kms_host, mock_activate_windows, - nano=False, is_eval=True): + nano=False): mock_service = mock.Mock() mock_manager = mock.Mock() mock_get_licensing_manager.return_value = mock_manager mock_osutils = mock.MagicMock() mock_osutils.is_nano_server.return_value = nano mock_get_os_utils.return_value = mock_osutils - mock_manager.is_eval.return_value = is_eval mock_manager.get_licensing_info.return_value = "fake" expected_logs = [] - with self.snatcher: - response = self._licensing.execute(service=mock_service, - shared_data=None) + with testutils.ConfPatcher('activate_windows', True): + with self.snatcher: + response = self._licensing.execute(service=mock_service, + shared_data=None) mock_get_os_utils.assert_called_once_with() if nano: expected_logs = ["Licensing info and activation are " "not available on Nano Server"] self.assertEqual(self.snatcher.output, expected_logs) - return # no activation available + return else: - if not is_eval: - mock_set_product_key.assert_called_once_with(mock_service, - mock_manager) - mock_set_kms_host.assert_called_once_with(mock_service, + mock_set_product_key.assert_called_once_with(mock_service, + mock_manager) + mock_set_kms_host.assert_called_once_with(mock_service, + mock_manager) + mock_activate_windows.assert_called_once_with(mock_service, mock_manager) - mock_activate_windows.assert_called_once_with(mock_service, - mock_manager) - else: - expected_logs.append("Evaluation license, skipping activation" - ". Evaluation end date: %s" % is_eval) expected_logs.append('Microsoft Windows license info:\nfake') mock_manager.get_licensing_info.assert_called_once_with() @@ -150,8 +145,5 @@ def _test_execute(self, mock_get_licensing_manager, def test_execute_nano(self): self._test_execute(nano=True) - def test_execute_is_evaluated(self): - self._test_execute() - def test_execute(self): - self._test_execute(is_eval=False) + self._test_execute()