licensing: properly set KMS host and product key

If a trial license key was set, the KMS default product key and host was
not properly configured, as the execution of the licensing plugin ended
abruptly.

The fix is to set the kms and product key without checking the evaluation
date corresponding for the trial key.

Change-Id: I45e9364661208c454ddf2be0ff925d149fe0a6b0
This commit is contained in:
Adrian Vladu 2020-06-02 11:31:58 +03:00
parent d53e765b26
commit 1582ebec2c
2 changed files with 32 additions and 42 deletions

View File

@ -64,17 +64,15 @@ class WindowsLicensingPlugin(base.BasePlugin):
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 @@ class WindowsLicensingPlugin(base.BasePlugin):
if osutils.is_nano_server():
LOG.info("Licensing info and activation are not available on "
"Nano Server")
else:
manager = licensing.get_licensing_manager()
return base.PLUGIN_EXECUTION_DONE, False
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()
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

View File

@ -94,9 +94,8 @@ class WindowsLicensingPluginTests(unittest.TestCase):
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 @@ class WindowsLicensingPluginTests(unittest.TestCase):
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 @@ class WindowsLicensingPluginTests(unittest.TestCase):
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()