Limit length of File object names
The Virtual I/O Server limits the name of a virtual optical device file to 37 characters and that of a virtual disk backing file to 15 characters. Recent pypowervm change set Iea735799149e8d809e7bea020f3ee9e2497a17c3 implemented new constants for these values as well as an optional parameter to the sanitize_file_name_for_api utility. This change set takes advantage of that enhancement and implements length restrictions accordingly for virtual disk and config ISO names. Change-Id: Iad59d8e90eb41741872c067062bd0f9aaa16bb5c
This commit is contained in:
parent
26f158ac90
commit
6a18330aed
@ -82,8 +82,16 @@ class TestConfigDrivePowerVM(test.TestCase):
|
||||
iso_path, file_name = cfg_dr_builder._create_cfg_dr_iso(mock_instance,
|
||||
mock_files,
|
||||
mock_net)
|
||||
self.assertEqual('config_fake_instance.iso', file_name)
|
||||
self.assertEqual('/tmp/cfgdrv/config_fake_instance.iso', iso_path)
|
||||
self.assertEqual('cfg_fake_instance.iso', file_name)
|
||||
self.assertEqual('/tmp/cfgdrv/cfg_fake_instance.iso', iso_path)
|
||||
# Make sure the length is limited properly
|
||||
mock_instance.name = 'fake-instance-with-name-that-is-too-long'
|
||||
iso_path, file_name = cfg_dr_builder._create_cfg_dr_iso(mock_instance,
|
||||
mock_files,
|
||||
mock_net)
|
||||
self.assertEqual('cfg_fake_instance_with_name_that_.iso', file_name)
|
||||
self.assertEqual('/tmp/cfgdrv/cfg_fake_instance_with_name_that_.iso',
|
||||
iso_path)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.media.ConfigDrivePowerVM.'
|
||||
'_create_cfg_dr_iso')
|
||||
|
@ -23,6 +23,7 @@ import six
|
||||
|
||||
from nova.i18n import _LW
|
||||
from nova import image
|
||||
import pypowervm.const as pvm_const
|
||||
import pypowervm.tasks.scsi_mapper as tsk_map
|
||||
import pypowervm.util as pvm_util
|
||||
import pypowervm.wrappers.virtual_io_server as pvm_vios
|
||||
@ -224,7 +225,9 @@ class DiskAdapter(object):
|
||||
prefix = '%s_' % (disk_type[0] if short else disk_type)
|
||||
base = ('%s_%s' % (instance.name[:8], instance.uuid[:4]) if short
|
||||
else instance.name)
|
||||
return pvm_util.sanitize_file_name_for_api(base, prefix=prefix)
|
||||
return pvm_util.sanitize_file_name_for_api(
|
||||
base, prefix=prefix, max_len=pvm_const.MaxLen.VDISK_NAME if short
|
||||
else pvm_const.MaxLen.FILENAME_DEFAULT)
|
||||
|
||||
@staticmethod
|
||||
def _get_image_name(image_meta):
|
||||
|
@ -24,6 +24,7 @@ import os
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
||||
from pypowervm import const as pvm_const
|
||||
from pypowervm.tasks import scsi_mapper as tsk_map
|
||||
from pypowervm.tasks import storage as tsk_stg
|
||||
from pypowervm import util as pvm_util
|
||||
@ -92,7 +93,8 @@ class ConfigDrivePowerVM(object):
|
||||
os.mkdir(im_path)
|
||||
|
||||
file_name = pvm_util.sanitize_file_name_for_api(
|
||||
instance.name, prefix='config_', suffix='.iso')
|
||||
instance.name, prefix='cfg_', suffix='.iso',
|
||||
max_len=pvm_const.MaxLen.VOPT_NAME)
|
||||
iso_path = os.path.join(im_path, file_name)
|
||||
with configdrive.ConfigDriveBuilder(instance_md=inst_md) as cdb:
|
||||
LOG.info(_LI("Config drive ISO being built for instance %(inst)s "
|
||||
|
Loading…
Reference in New Issue
Block a user