Skip to content

Commit 1582ebe

Browse files
committed
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
1 parent d53e765 commit 1582ebe

File tree

2 files changed

+33
-43
lines changed

2 files changed

+33
-43
lines changed

cloudbaseinit/plugins/windows/licensing.py

+19-21
Original file line numberDiff line numberDiff line change
@@ -64,37 +64,35 @@ def _set_kms_host(self, service, manager):
6464
manager.set_kms_host(*kms_host.split(':'))
6565

6666
def _activate_windows(self, service, manager):
67-
if CONF.activate_windows:
68-
# note(alexpilotti): KMS clients activate themselves
69-
# so this could be skipped if a KMS host is set
70-
LOG.info("Activating Windows")
71-
activation_result = manager.activate_windows()
72-
LOG.debug("Activation result:\n%s" % activation_result)
67+
# note(alexpilotti): KMS clients activate themselves
68+
# so this could be skipped if a KMS host is set
69+
LOG.info("Activating Windows")
70+
activation_result = manager.activate_windows()
71+
LOG.debug("Activation result:\n%s" % activation_result)
7372

7473
def _log_licensing_info(self, manager):
75-
if CONF.log_licensing_info:
76-
license_info = manager.get_licensing_info()
77-
LOG.info('Microsoft Windows license info:\n%s' % license_info)
74+
license_info = manager.get_licensing_info()
75+
LOG.info('Microsoft Windows license info:\n%s' % license_info)
7876

7977
def execute(self, service, shared_data):
8078
osutils = osutils_factory.get_os_utils()
8179

8280
if osutils.is_nano_server():
8381
LOG.info("Licensing info and activation are not available on "
8482
"Nano Server")
85-
else:
86-
manager = licensing.get_licensing_manager()
87-
88-
eval_end_date = manager.is_eval()
89-
if eval_end_date:
90-
LOG.info("Evaluation license, skipping activation. "
91-
"Evaluation end date: %s", eval_end_date)
92-
else:
93-
self._set_product_key(service, manager)
94-
self._set_kms_host(service, manager)
95-
self._activate_windows(service, manager)
96-
manager.refresh_status()
83+
return base.PLUGIN_EXECUTION_DONE, False
84+
85+
manager = licensing.get_licensing_manager()
9786

87+
# set kms / avma product keys and kms hosts if any
88+
self._set_product_key(service, manager)
89+
self._set_kms_host(service, manager)
90+
91+
if CONF.activate_windows:
92+
self._activate_windows(service, manager)
93+
94+
if CONF.log_licensing_info:
95+
manager.refresh_status()
9896
self._log_licensing_info(manager)
9997

10098
return base.PLUGIN_EXECUTION_DONE, False

cloudbaseinit/tests/plugins/windows/test_licensing.py

+14-22
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ def test_activate_windows(self):
9494
expected_logs = [
9595
"Activating Windows",
9696
"Activation result:\n%s" % activate_result]
97-
with testutils.ConfPatcher('activate_windows', True):
98-
with self.snatcher:
99-
self._licensing._activate_windows(mock_service, mock_manager)
97+
with self.snatcher:
98+
self._licensing._activate_windows(mock_service, mock_manager)
10099
self.assertEqual(self.snatcher.output, expected_logs)
101100
mock_manager.activate_windows.assert_called_once_with()
102101

@@ -110,37 +109,33 @@ def _test_execute(self, mock_get_licensing_manager,
110109
mock_set_product_key,
111110
mock_set_kms_host,
112111
mock_activate_windows,
113-
nano=False, is_eval=True):
112+
nano=False):
114113
mock_service = mock.Mock()
115114
mock_manager = mock.Mock()
116115
mock_get_licensing_manager.return_value = mock_manager
117116
mock_osutils = mock.MagicMock()
118117
mock_osutils.is_nano_server.return_value = nano
119118
mock_get_os_utils.return_value = mock_osutils
120-
mock_manager.is_eval.return_value = is_eval
121119
mock_manager.get_licensing_info.return_value = "fake"
122120
expected_logs = []
123-
with self.snatcher:
124-
response = self._licensing.execute(service=mock_service,
125-
shared_data=None)
121+
with testutils.ConfPatcher('activate_windows', True):
122+
with self.snatcher:
123+
response = self._licensing.execute(service=mock_service,
124+
shared_data=None)
126125

127126
mock_get_os_utils.assert_called_once_with()
128127
if nano:
129128
expected_logs = ["Licensing info and activation are "
130129
"not available on Nano Server"]
131130
self.assertEqual(self.snatcher.output, expected_logs)
132-
return # no activation available
131+
return
133132
else:
134-
if not is_eval:
135-
mock_set_product_key.assert_called_once_with(mock_service,
136-
mock_manager)
137-
mock_set_kms_host.assert_called_once_with(mock_service,
133+
mock_set_product_key.assert_called_once_with(mock_service,
134+
mock_manager)
135+
mock_set_kms_host.assert_called_once_with(mock_service,
136+
mock_manager)
137+
mock_activate_windows.assert_called_once_with(mock_service,
138138
mock_manager)
139-
mock_activate_windows.assert_called_once_with(mock_service,
140-
mock_manager)
141-
else:
142-
expected_logs.append("Evaluation license, skipping activation"
143-
". Evaluation end date: %s" % is_eval)
144139
expected_logs.append('Microsoft Windows license info:\nfake')
145140
mock_manager.get_licensing_info.assert_called_once_with()
146141

@@ -150,8 +145,5 @@ def _test_execute(self, mock_get_licensing_manager,
150145
def test_execute_nano(self):
151146
self._test_execute(nano=True)
152147

153-
def test_execute_is_evaluated(self):
154-
self._test_execute()
155-
156148
def test_execute(self):
157-
self._test_execute(is_eval=False)
149+
self._test_execute()

0 commit comments

Comments
 (0)