Merge "deployment vmedia ops should not be run when not deploying"

This commit is contained in:
Jenkins 2016-04-12 21:17:30 +00:00 committed by Gerrit Code Review
commit ca69aa83f6
4 changed files with 50 additions and 0 deletions

View File

@ -32,6 +32,7 @@ from ironic.common.i18n import _LE
from ironic.common.i18n import _LW
from ironic.common import image_service
from ironic.common import images
from ironic.common import states
from ironic.common import swift
from ironic.conductor import utils as manager_utils
from ironic.drivers import base
@ -293,6 +294,12 @@ class IloVirtualMediaBoot(base.BootInterface):
"""
node = task.node
# NOTE(TheJulia): If this method is being called by something
# aside from a deployment, such as conductor takeover, we should
# treat this as a no-op and move on otherwise we would modify
# the state of the node due to virtual media operations.
if node.provision_state != states.DEPLOYING:
return
# Clear ilo_boot_iso if it's a glance image to force recreate
# another one again (or use existing one in glance).

View File

@ -603,6 +603,13 @@ class IRMCVirtualMediaBoot(base.BootInterface):
:raises: IRMCOperationError, if some operation on iRMC fails.
"""
# NOTE(TheJulia): If this method is being called by something
# aside from a deployment, such as conductor takeover, we should
# treat this as a no-op and move on otherwise we would modify
# the state of the node due to virtual media operations.
if task.node.provision_state != states.DEPLOYING:
return
deploy_nic_mac = deploy_utils.get_single_nic_with_vif_port_id(task)
ramdisk_params['BOOTIF'] = deploy_nic_mac

View File

@ -27,6 +27,7 @@ from ironic.common import exception
from ironic.common.glance_service import service_utils
from ironic.common import image_service
from ironic.common import images
from ironic.common import states
from ironic.common import swift
from ironic.conductor import task_manager
from ironic.conductor import utils as manager_utils
@ -499,7 +500,24 @@ class IloVirtualMediaBootTestCase(db_base.DbTestCase):
setup_vmedia_mock.assert_called_once_with(task, 'deploy-iso',
expected_ramdisk_opts)
@mock.patch.object(service_utils, 'is_glance_image', spec_set=True,
autospec=True)
def test_prepare_ramdisk_not_deploying(self, mock_is_image):
"""Ensure ramdisk build operations are blocked when not deploying"""
for state in states.STABLE_STATES:
mock_is_image.reset_mock()
self.node.provision_state = state
self.node.save()
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
self.assertIsNone(
task.driver.boot.prepare_ramdisk(task, None))
self.assertFalse(mock_is_image.called)
def test_prepare_ramdisk_glance_image(self):
self.node.provision_state = states.DEPLOYING
self.node.save()
self._test_prepare_ramdisk(
ilo_boot_iso='swift:abcdef',
image_source='6b2f0c0c-79e8-4db6-842e-43c9764204af')
@ -507,6 +525,8 @@ class IloVirtualMediaBootTestCase(db_base.DbTestCase):
self.assertNotIn('ilo_boot_iso', self.node.instance_info)
def test_prepare_ramdisk_not_a_glance_image(self):
self.node.provision_state = states.DEPLOYING
self.node.save()
self._test_prepare_ramdisk(
ilo_boot_iso='http://mybootiso',
image_source='http://myimage')

View File

@ -907,6 +907,7 @@ class IRMCVirtualMediaBootTestCase(db_base.DbTestCase):
instance_info['irmc_boot_iso'] = 'glance://abcdef'
instance_info['image_source'] = '6b2f0c0c-79e8-4db6-842e-43c9764204af'
self.node.instance_info = instance_info
self.node.provision_state = states.DEPLOYING
self.node.save()
ramdisk_params = {'a': 'b'}
@ -923,6 +924,21 @@ class IRMCVirtualMediaBootTestCase(db_base.DbTestCase):
self.assertEqual('glance://abcdef',
self.node.instance_info['irmc_boot_iso'])
@mock.patch.object(irmc_boot, '_setup_deploy_iso', spec_set=True,
autospec=True)
def test_prepare_ramdisk_not_deploying(self, mock_is_image):
"""Ensure ramdisk build operations are blocked when not deploying"""
for state in states.STABLE_STATES:
mock_is_image.reset_mock()
self.node.provision_state = state
self.node.save()
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
self.assertIsNone(
task.driver.boot.prepare_ramdisk(task, None))
self.assertFalse(mock_is_image.called)
@mock.patch.object(irmc_boot, '_cleanup_vmedia_boot', spec_set=True,
autospec=True)
def test_clean_up_ramdisk(self, _cleanup_vmedia_boot_mock):