diff --git a/nova/compute/api.py b/nova/compute/api.py index 6594c29981b6..bf7342f2f0dd 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -506,25 +506,9 @@ class API(base.Base): 'auto_disk_config': auto_disk_config } - def _new_instance_name_from_template(self, uuid, display_name, index): - params = { - 'uuid': uuid, - 'name': display_name, - 'count': index + 1, - } - try: - new_name = (CONF.multi_instance_display_name_template % - params) - except (KeyError, TypeError): - LOG.exception('Failed to set instance name using ' - 'multi_instance_display_name_template.') - new_name = display_name - return new_name - - def _apply_instance_name_template(self, context, instance, index): + def _apply_instance_name_template(self, instance, index): original_name = instance.display_name - new_name = self._new_instance_name_from_template(instance.uuid, - instance.display_name, index) + new_name = '%s-%d' % (original_name, index + 1) instance.display_name = new_name if not instance.get('hostname', None): if utils.sanitize_hostname(original_name) == "": @@ -1506,8 +1490,7 @@ class API(base.Base): self._populate_instance_names(instance, num_instances) instance.shutdown_terminate = shutdown_terminate if num_instances > 1 and self.cell_type != 'api': - instance = self._apply_instance_name_template(context, instance, - index) + instance = self._apply_instance_name_template(instance, index) return instance diff --git a/nova/conf/compute.py b/nova/conf/compute.py index a2e516fb96b5..73c7923f84ea 100644 --- a/nova/conf/compute.py +++ b/nova/conf/compute.py @@ -74,25 +74,6 @@ Possible values: img_signature, img_signature_key_type, img_signature_certificate_uuid -"""), - cfg.StrOpt('multi_instance_display_name_template', - default='%(name)s-%(count)d', - deprecated_for_removal=True, - deprecated_since='15.0.0', - deprecated_reason=""" -This config changes API behaviour. All changes in API behaviour should be -discoverable. -""", - help=""" -When creating multiple instances with a single request using the -os-multiple-create API extension, this template will be used to build -the display name for each instance. The benefit is that the instances -end up with different hostnames. Example display names when creating -two VM's: name-1, name-2. - -Possible values: - -* Valid keys for the template are: name, uuid, count. """), cfg.IntOpt('max_local_block_devices', default=3, @@ -1105,10 +1086,6 @@ Possible values: default) * A string with a list of named database columns, for example ``%(id)d`` or ``%(uuid)s`` or ``%(hostname)s``. - -Related options: - -* not to be confused with: ``multi_instance_display_name_template`` """), ] diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index ea644c91e0fc..09b3b5354d6b 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -9670,40 +9670,30 @@ class ComputeAPITestCase(BaseTestCase): for instance in refs: self.assertEqual(instance['reservation_id'], resv_id) - def test_multi_instance_display_name_template(self, cells_enabled=False): - num_instances = 2 - self.flags(multi_instance_display_name_template='%(name)s') - (refs, resv_id) = self.compute_api.create(self.context, + def test_single_instance_display_name(self): + """Verify building one instance doesn't do anything funky with + the display and host names. + """ + # TODO(stephenfin): Remove cells_enabled parameter when we removed + # cells v1 + num_instances = 1 + refs, _ = self.compute_api.create(self.context, flavors.get_default_flavor(), image_href=uuids.image_href_id, min_count=num_instances, max_count=num_instances, display_name='x') - for i in range(num_instances): - hostname = None if cells_enabled else 'x' - self.assertEqual(refs[i]['display_name'], 'x') - self.assertEqual(refs[i]['hostname'], hostname) + name = 'x' + self.assertEqual(refs[0]['display_name'], name) + self.assertEqual(refs[0]['hostname'], name) - self.flags(multi_instance_display_name_template='%(name)s-%(count)d') - self._multi_instance_display_name_default(cells_enabled=cells_enabled) - - self.flags(multi_instance_display_name_template='%(name)s-%(uuid)s') - (refs, resv_id) = self.compute_api.create(self.context, - flavors.get_default_flavor(), - image_href=uuids.image_href_id, - min_count=num_instances, max_count=num_instances, - display_name='x') - for i in range(num_instances): - name = 'x' if cells_enabled else 'x-%s' % refs[i]['uuid'] - hostname = None if cells_enabled else name - self.assertEqual(refs[i]['display_name'], name) - self.assertEqual(refs[i]['hostname'], hostname) - - def test_multi_instance_display_name_default(self): - self._multi_instance_display_name_default() - - def _multi_instance_display_name_default(self, cells_enabled=False): + def test_multi_instance_display_name(self, cells_enabled=False): + """Verify building two instances at once results in a unique + display and host name. + """ + # TODO(stephenfin): Remove cells_enabled parameter when we removed + # cells v1 num_instances = 2 - (refs, resv_id) = self.compute_api.create(self.context, + refs, _ = self.compute_api.create(self.context, flavors.get_default_flavor(), image_href=uuids.image_href_id, min_count=num_instances, max_count=num_instances, diff --git a/nova/tests/unit/compute/test_compute_api.py b/nova/tests/unit/compute/test_compute_api.py index f24721122271..a37401f10222 100644 --- a/nova/tests/unit/compute/test_compute_api.py +++ b/nova/tests/unit/compute/test_compute_api.py @@ -5011,16 +5011,14 @@ class _ComputeAPIUnitTestMixIn(object): params = dict(display_name="vm") instance = self._create_instance_obj(params=params) with mock.patch.object(instance, 'save'): - self.compute_api._apply_instance_name_template(self.context, - instance, 1) + self.compute_api._apply_instance_name_template(instance, 1) self.assertEqual('vm-2', instance.hostname) def test_populate_instance_names_host_name_is_empty_multi(self): params = dict(display_name=u'\u865a\u62df\u673a\u662f\u4e2d\u6587') instance = self._create_instance_obj(params=params) with mock.patch.object(instance, 'save'): - self.compute_api._apply_instance_name_template(self.context, - instance, 1) + self.compute_api._apply_instance_name_template(instance, 1) self.assertEqual('Server-%s' % instance.uuid, instance.hostname) def test_host_statuses(self): diff --git a/nova/tests/unit/compute/test_compute_cells.py b/nova/tests/unit/compute/test_compute_cells.py index dcdd4cce6c2e..1f37e69bbbc9 100644 --- a/nova/tests/unit/compute/test_compute_cells.py +++ b/nova/tests/unit/compute/test_compute_cells.py @@ -514,13 +514,9 @@ class CellsComputeAPITestCase(test_compute.ComputeAPITestCase): super(CellsComputeAPITestCase, self).test_populate_instance_for_create( num_instances=2) - def test_multi_instance_display_name_default(self): - self._multi_instance_display_name_default(cells_enabled=True) - - def test_multi_instance_display_name_template(self): + def test_multi_instance_display_name(self): super(CellsComputeAPITestCase, - self).test_multi_instance_display_name_template( - cells_enabled=True) + self).test_multi_instance_display_name(cells_enabled=True) class CellsShelveComputeAPITestCase(test_shelve.ShelveComputeAPITestCase): diff --git a/releasenotes/notes/remove-deprecated-compute-opts-b640061349806d9e.yaml b/releasenotes/notes/remove-deprecated-compute-opts-b640061349806d9e.yaml new file mode 100644 index 000000000000..9628500585cc --- /dev/null +++ b/releasenotes/notes/remove-deprecated-compute-opts-b640061349806d9e.yaml @@ -0,0 +1,10 @@ +--- +upgrade: + - | + The following deprecated configuration options have been removed from the + ``compute`` section of ``nova.conf``: + + - ``multi_instance_display_name_template`` + + These were deprecated in the 15.0.0 release as they allowed for + inconsistent API behavior across deployments.