conf: Remove deprecated 'multi_instance_display_name_template' opt

This flag was deprecated in a previous cycle. The flag and any uses of
it can now be removed.

There is still a bit of simplification that can now be done around this
feature, but this is kept separate to avoid confusing matters.

Change-Id: I8ae8507a089df4d0a32be5fbc615e2166f44516e
This commit is contained in:
Stephen Finucane 2017-10-27 10:54:44 +01:00
parent 2d738f7082
commit 0e43002c90
6 changed files with 35 additions and 81 deletions

View File

@ -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

View File

@ -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``
"""),
]

View File

@ -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,

View File

@ -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):

View File

@ -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):

View File

@ -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.