Browse Source

Merge "Allow passing an agent-name as a command line argument" into stable/queens

tags/9.3.1
Zuul 1 week ago
parent
commit
76b30fcb3a

+ 18
- 0
tripleoclient/tests/v1/overcloud_image/test_overcloud_image.py View File

@@ -14,6 +14,7 @@
14 14
 #
15 15
 
16 16
 import mock
17
+import os
17 18
 
18 19
 from osc_lib import exceptions
19 20
 from tripleoclient.tests.v1.test_plugin import TestPluginV1
@@ -169,6 +170,23 @@ class TestUploadOvercloudImage(TestPluginV1):
169 170
             update_mock.call_count
170 171
         )
171 172
 
173
+    @mock.patch.dict(os.environ, {'KEY': 'VALUE', 'OLD_KEY': 'OLD_VALUE'})
174
+    def test_get_environment_var(self):
175
+        self.assertEqual('default-value',
176
+                         self.cmd._get_environment_var('MISSING',
177
+                                                       'default-value'))
178
+        self.assertEqual('VALUE',
179
+                         self.cmd._get_environment_var('KEY',
180
+                                                       'default-value'))
181
+        self.assertEqual('VALUE',
182
+                         self.cmd._get_environment_var('KEY',
183
+                                                       'default-value',
184
+                                                       deprecated=['MISSING']))
185
+        self.assertEqual('OLD_VALUE',
186
+                         self.cmd._get_environment_var('KEY',
187
+                                                       'default-value',
188
+                                                       deprecated=['OLD_KEY']))
189
+
172 190
     @mock.patch('os.path.isfile', autospec=True)
173 191
     def test_file_try_update_need_update(self, mock_isfile):
174 192
         mock_isfile.return_value = True

+ 27
- 14
tripleoclient/v1/overcloud_image.py View File

@@ -143,9 +143,6 @@ class UploadOvercloudImage(command.Command):
143 143
     """Create overcloud glance images from existing image files."""
144 144
     log = logging.getLogger(__name__ + ".UploadOvercloudImage")
145 145
 
146
-    def _env_variable_or_set(self, key_name, default_value):
147
-        os.environ[key_name] = os.environ.get(key_name, default_value)
148
-
149 146
     def _get_image(self, name):
150 147
         try:
151 148
             image = utils.find_resource(self.app.client_manager.image.images,
@@ -230,21 +227,39 @@ class UploadOvercloudImage(command.Command):
230 227
         else:
231 228
             return GlanceV1ClientAdapter(self.app.client_manager.image)
232 229
 
230
+    def _get_environment_var(self, envvar, default, deprecated=[]):
231
+        for env_key in deprecated:
232
+            if env_key in os.environ:
233
+                self.log.warn(('Found deprecated environment var \'%s\', '
234
+                               'please use \'%s\' instead' % (env_key,
235
+                                                              envvar)))
236
+                return os.environ.get(env_key)
237
+        return os.environ.get(envvar, default)
238
+
233 239
     def get_parser(self, prog_name):
234 240
         parser = super(UploadOvercloudImage, self).get_parser(prog_name)
235 241
         parser.add_argument(
236 242
             "--image-path",
237
-            default=os.environ.get('IMAGE_PATH', './'),
243
+            default=self._get_environment_var('IMAGE_PATH', './'),
238 244
             help=_("Path to directory containing image files"),
239 245
         )
240 246
         parser.add_argument(
241 247
             "--os-image-name",
242
-            default=os.environ.get('OS_IMAGE_NAME', 'overcloud-full.qcow2'),
248
+            default=self._get_environment_var('OS_IMAGE_NAME',
249
+                                              'overcloud-full.qcow2'),
243 250
             help=_("OpenStack disk image filename"),
244 251
         )
252
+        parser.add_argument(
253
+            "--ironic-python-agent-name",
254
+            dest='ipa_name',
255
+            default=self._get_environment_var('IRONIC_PYTHON_AGENT_NAME',
256
+                                              'ironic-python-agent',
257
+                                              deprecated=['AGENT_NAME']),
258
+            help=_("OpenStack ironic-python-agent (agent) image filename"),
259
+        )
245 260
         parser.add_argument(
246 261
             "--http-boot",
247
-            default=os.environ.get('HTTP_BOOT', '/httpboot'),
262
+            default=self._get_environment_var('HTTP_BOOT', '/httpboot'),
248 263
             help=_("Root directory for the introspection image")
249 264
         )
250 265
         parser.add_argument(
@@ -268,8 +283,6 @@ class UploadOvercloudImage(command.Command):
268 283
         glance_client_adaptor = self._get_glance_client_adaptor()
269 284
         self.updated = False
270 285
 
271
-        self._env_variable_or_set('AGENT_NAME', 'ironic-python-agent')
272
-
273 286
         self.log.debug("checking if image files exist")
274 287
 
275 288
         if parsed_args.whole_disk:
@@ -279,8 +292,8 @@ class UploadOvercloudImage(command.Command):
279 292
             overcloud_image_type = 'whole disk'
280 293
         else:
281 294
             image_files = [
282
-                '%s.initramfs' % os.environ['AGENT_NAME'],
283
-                '%s.kernel' % os.environ['AGENT_NAME'],
295
+                '%s.initramfs' % parsed_args.ipa_name,
296
+                '%s.kernel' % parsed_args.ipa_name,
284 297
                 parsed_args.os_image_name
285 298
             ]
286 299
             overcloud_image_type = 'partition'
@@ -379,7 +392,7 @@ class UploadOvercloudImage(command.Command):
379 392
         deploy_kernel_name = 'bm-deploy-kernel'
380 393
         deploy_kernel_extension = '.kernel'
381 394
         deploy_kernel_file = os.path.join(parsed_args.image_path,
382
-                                          os.environ['AGENT_NAME'] +
395
+                                          parsed_args.ipa_name +
383 396
                                           deploy_kernel_extension)
384 397
         self._image_try_update(deploy_kernel_name, deploy_kernel_file,
385 398
                                parsed_args) or \
@@ -394,7 +407,7 @@ class UploadOvercloudImage(command.Command):
394 407
         deploy_ramdisk_name = 'bm-deploy-ramdisk'
395 408
         deploy_ramdisk_extension = '.initramfs'
396 409
         deploy_ramdisk_file = os.path.join(parsed_args.image_path,
397
-                                           os.environ['AGENT_NAME'] +
410
+                                           parsed_args.ipa_name +
398 411
                                            deploy_ramdisk_extension)
399 412
         self._image_try_update(deploy_ramdisk_name, deploy_ramdisk_file,
400 413
                                parsed_args) or \
@@ -409,14 +422,14 @@ class UploadOvercloudImage(command.Command):
409 422
 
410 423
         self._file_create_or_update(
411 424
             os.path.join(parsed_args.image_path,
412
-                         '%s.kernel' % os.environ['AGENT_NAME']),
425
+                         '%s.kernel' % parsed_args.ipa_name),
413 426
             os.path.join(parsed_args.http_boot, 'agent.kernel'),
414 427
             parsed_args.update_existing
415 428
         )
416 429
 
417 430
         self._file_create_or_update(
418 431
             os.path.join(parsed_args.image_path,
419
-                         '%s.initramfs' % os.environ['AGENT_NAME']),
432
+                         '%s.initramfs' % parsed_args.ipa_name),
420 433
             os.path.join(parsed_args.http_boot, 'agent.ramdisk'),
421 434
             parsed_args.update_existing
422 435
         )

Loading…
Cancel
Save