From b12d184b73f6decb20f733ae642a54ae49e90b88 Mon Sep 17 00:00:00 2001 From: Aparna Date: Mon, 18 Apr 2016 11:06:31 +0000 Subject: [PATCH] Deployment vmedia operations to run when cleaning The virtual media operations in task.driver.boot.prepare_ramdisk() should be performed while the provision state of the node is in 'cleaning'. Change-Id: I4f563586523ea6e4a5a630c5fe44f70fe473bdf8 Closes-Bug: #1570283 --- ironic/drivers/modules/ilo/boot.py | 7 +++--- ironic/drivers/modules/irmc/boot.py | 7 +++--- .../unit/drivers/modules/ilo/test_boot.py | 23 +++++++++++++++++-- .../unit/drivers/modules/irmc/test_boot.py | 21 ++++++++++++----- .../notes/bug-1570283-6cdc62e4ef43cb02.yaml | 4 ++++ 5 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 releasenotes/notes/bug-1570283-6cdc62e4ef43cb02.yaml diff --git a/ironic/drivers/modules/ilo/boot.py b/ironic/drivers/modules/ilo/boot.py index 481e3ebd33..1a5c5dae4c 100644 --- a/ironic/drivers/modules/ilo/boot.py +++ b/ironic/drivers/modules/ilo/boot.py @@ -295,10 +295,11 @@ 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 + # aside from deployment and clean, 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: + if (node.provision_state != states.DEPLOYING and + node.provision_state != states.CLEANING): return # Clear ilo_boot_iso if it's a glance image to force recreate diff --git a/ironic/drivers/modules/irmc/boot.py b/ironic/drivers/modules/irmc/boot.py index 89c58a8d57..0c39d7bb61 100644 --- a/ironic/drivers/modules/irmc/boot.py +++ b/ironic/drivers/modules/irmc/boot.py @@ -604,10 +604,11 @@ class IRMCVirtualMediaBoot(base.BootInterface): """ # 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 + # aside from deployment and clean, 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: + if (task.node.provision_state != states.DEPLOYING and + task.node.provision_state != states.CLEANING): return deploy_nic_mac = deploy_utils.get_single_nic_with_vif_port_id(task) diff --git a/ironic/tests/unit/drivers/modules/ilo/test_boot.py b/ironic/tests/unit/drivers/modules/ilo/test_boot.py index 93ea84c4b2..6cf6009f1d 100644 --- a/ironic/tests/unit/drivers/modules/ilo/test_boot.py +++ b/ironic/tests/unit/drivers/modules/ilo/test_boot.py @@ -502,8 +502,8 @@ class IloVirtualMediaBootTestCase(db_base.DbTestCase): @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""" + def test_prepare_ramdisk_not_deploying_not_cleaning(self, mock_is_image): + """Ensure deploy ops are blocked when not deploying and not cleaning""" for state in states.STABLE_STATES: mock_is_image.reset_mock() @@ -534,6 +534,25 @@ class IloVirtualMediaBootTestCase(db_base.DbTestCase): self.assertEqual('http://mybootiso', self.node.instance_info['ilo_boot_iso']) + def test_prepare_ramdisk_glance_image_cleaning(self): + self.node.provision_state = states.CLEANING + self.node.save() + self._test_prepare_ramdisk( + ilo_boot_iso='swift:abcdef', + image_source='6b2f0c0c-79e8-4db6-842e-43c9764204af') + self.node.refresh() + self.assertNotIn('ilo_boot_iso', self.node.instance_info) + + def test_prepare_ramdisk_not_a_glance_image_cleaning(self): + self.node.provision_state = states.CLEANING + self.node.save() + self._test_prepare_ramdisk( + ilo_boot_iso='http://mybootiso', + image_source='http://myimage') + self.node.refresh() + self.assertEqual('http://mybootiso', + self.node.instance_info['ilo_boot_iso']) + @mock.patch.object(manager_utils, 'node_set_boot_device', spec_set=True, autospec=True) @mock.patch.object(ilo_common, 'setup_vmedia_for_boot', spec_set=True, diff --git a/ironic/tests/unit/drivers/modules/irmc/test_boot.py b/ironic/tests/unit/drivers/modules/irmc/test_boot.py index a607282ead..a06ca4e7ab 100644 --- a/ironic/tests/unit/drivers/modules/irmc/test_boot.py +++ b/ironic/tests/unit/drivers/modules/irmc/test_boot.py @@ -900,14 +900,13 @@ class IRMCVirtualMediaBootTestCase(db_base.DbTestCase): spec_set=True, autospec=True) @mock.patch.object(deploy_utils, 'get_single_nic_with_vif_port_id', spec_set=True, autospec=True) - def test_prepare_ramdisk(self, - get_single_nic_with_vif_port_id_mock, - _setup_deploy_iso_mock): + def _test_prepare_ramdisk(self, + get_single_nic_with_vif_port_id_mock, + _setup_deploy_iso_mock): instance_info = self.node.instance_info 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'} @@ -924,10 +923,20 @@ class IRMCVirtualMediaBootTestCase(db_base.DbTestCase): self.assertEqual('glance://abcdef', self.node.instance_info['irmc_boot_iso']) + def test_prepare_ramdisk_glance_image_deploying(self): + self.node.provision_state = states.DEPLOYING + self.node.save() + self._test_prepare_ramdisk() + + def test_prepare_ramdisk_glance_image_cleaning(self): + self.node.provision_state = states.CLEANING + self.node.save() + self._test_prepare_ramdisk() + @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""" + def test_prepare_ramdisk_not_deploying_not_cleaning(self, mock_is_image): + """Ensure deploy ops are blocked when not deploying and not cleaning""" for state in states.STABLE_STATES: mock_is_image.reset_mock() diff --git a/releasenotes/notes/bug-1570283-6cdc62e4ef43cb02.yaml b/releasenotes/notes/bug-1570283-6cdc62e4ef43cb02.yaml new file mode 100644 index 0000000000..7d6ec791ac --- /dev/null +++ b/releasenotes/notes/bug-1570283-6cdc62e4ef43cb02.yaml @@ -0,0 +1,4 @@ +--- +fixes: + -Fixes the issue of not attaching virtual media during cleaning operation + for vmedia based drivers.