Merge "Allow clean_up with missing image ref"

This commit is contained in:
Jenkins 2014-09-16 17:37:56 +00:00 committed by Gerrit Code Review
commit 93c7ccfffd
2 changed files with 26 additions and 8 deletions

View File

@ -396,10 +396,17 @@ class PXEDeploy(base.DeployInterface):
:param task: a TaskManager instance containing the node to act on.
"""
node = task.node
pxe_info = _get_image_info(node, task.context)
for label in pxe_info:
path = pxe_info[label][1]
utils.unlink_without_raise(path)
try:
pxe_info = _get_image_info(node, task.context)
except exception.MissingParameterValue as e:
LOG.warning(_LW('Could not get image info to clean up images '
'for node %(node)s: %(err)s'),
{'node': node.uuid, 'err': e})
else:
for label in pxe_info:
path = pxe_info[label][1]
utils.unlink_without_raise(path)
TFTPImageCache().clean_up()
pxe_utils.clean_up_pxe_config(task)

View File

@ -678,7 +678,8 @@ class PXEDriverTestCase(db_base.DbTestCase):
"_continue_deploy was not called once.")
@mock.patch.object(pxe, '_get_image_info')
def clean_up_config(self, get_image_info_mock, master=None):
def clean_up_config(self, get_image_info_mock, master=None,
fail_get_image_info=False):
temp_dir = tempfile.mkdtemp()
self.config(tftp_root=temp_dir, group='pxe')
tftp_master_dir = os.path.join(CONF.pxe.tftp_root,
@ -699,11 +700,14 @@ class PXEDriverTestCase(db_base.DbTestCase):
uuid='bb43dc0b-03f2-4d2e-ae87-c02d7f33cc53')
)
d_kernel_path = os.path.join(CONF.pxe.tftp_root,
self.node.uuid, 'deploy_kernel')
d_kernel_path = os.path.join(tftp_master_dir, 'deploy_kernel')
image_info = {'deploy_kernel': ('deploy_kernel_uuid', d_kernel_path)}
get_image_info_mock.return_value = image_info
if fail_get_image_info:
get_image_info_mock.side_effect = exception.MissingParameterValue(
'image_source')
else:
get_image_info_mock.return_value = image_info
pxecfg_dir = os.path.join(CONF.pxe.tftp_root, 'pxelinux.cfg')
os.makedirs(pxecfg_dir)
@ -740,6 +744,8 @@ class PXEDriverTestCase(db_base.DbTestCase):
else:
open(deploy_kernel_path, 'w').close()
open(image_path, 'w').close()
open(d_kernel_path, 'w').close()
token_path = self._create_token_file()
self.config(image_cache_size=0, group='pxe')
@ -751,10 +757,15 @@ class PXEDriverTestCase(db_base.DbTestCase):
assert_false_path = [config_path, deploy_kernel_path, image_path,
pxe_mac_path, image_dir, instance_dir,
token_path]
if not fail_get_image_info:
assert_false_path.append(d_kernel_path)
for path in assert_false_path:
self.assertFalse(os.path.exists(path))
def test_clean_up_fail_get_image_info(self):
self.clean_up_config(fail_get_image_info=True)
def test_clean_up_no_master_images(self):
self.clean_up_config(master=None)