"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "ironic/tests/unit/conductor/test_cleaning.py" between
ironic-16.0.2.tar.gz and ironic-16.0.3.tar.gz

About: OpenStack Ironic (Optional Service: Bare-Metal Provisioning) aims to provision bare metal machines instead of virtual machines, forked from the Nova baremetal driver.
The "Victoria" series (latest release).

test_cleaning.py  (ironic-16.0.2):test_cleaning.py  (ironic-16.0.3)
skipping to change at line 21 skipping to change at line 21
# under the License. # under the License.
"""Tests for cleaning bits.""" """Tests for cleaning bits."""
from unittest import mock from unittest import mock
from oslo_config import cfg from oslo_config import cfg
from oslo_utils import uuidutils from oslo_utils import uuidutils
from ironic.common import exception from ironic.common import exception
from ironic.common import faults
from ironic.common import states from ironic.common import states
from ironic.conductor import cleaning from ironic.conductor import cleaning
from ironic.conductor import steps as conductor_steps from ironic.conductor import steps as conductor_steps
from ironic.conductor import task_manager from ironic.conductor import task_manager
from ironic.conductor import utils as conductor_utils
from ironic.drivers.modules import fake from ironic.drivers.modules import fake
from ironic.drivers.modules.network import flat as n_flat from ironic.drivers.modules.network import flat as n_flat
from ironic.tests.unit.db import base as db_base from ironic.tests.unit.db import base as db_base
from ironic.tests.unit.objects import utils as obj_utils from ironic.tests.unit.objects import utils as obj_utils
CONF = cfg.CONF CONF = cfg.CONF
class DoNodeCleanTestCase(db_base.DbTestCase): class DoNodeCleanTestCase(db_base.DbTestCase):
def setUp(self): def setUp(self):
super(DoNodeCleanTestCase, self).setUp() super(DoNodeCleanTestCase, self).setUp()
skipping to change at line 64 skipping to change at line 66
node = obj_utils.create_test_node( node = obj_utils.create_test_node(
self.context, driver='fake-hardware', self.context, driver='fake-hardware',
provision_state=states.CLEANING, provision_state=states.CLEANING,
target_provision_state=tgt_prov_state) target_provision_state=tgt_prov_state)
with task_manager.acquire( with task_manager.acquire(
self.context, node.uuid, shared=False) as task: self.context, node.uuid, shared=False) as task:
cleaning.do_node_clean(task, clean_steps=clean_steps) cleaning.do_node_clean(task, clean_steps=clean_steps)
node.refresh() node.refresh()
self.assertEqual(states.CLEANFAIL, node.provision_state) self.assertEqual(states.CLEANFAIL, node.provision_state)
self.assertEqual(tgt_prov_state, node.target_provision_state) self.assertEqual(tgt_prov_state, node.target_provision_state)
self.assertFalse(node.maintenance)
self.assertIsNone(node.fault)
mock_validate.assert_called_once_with(mock.ANY, mock.ANY) mock_validate.assert_called_once_with(mock.ANY, mock.ANY)
@mock.patch('ironic.drivers.modules.fake.FakePower.validate', @mock.patch('ironic.drivers.modules.fake.FakePower.validate',
autospec=True) autospec=True)
def test__do_node_clean_automated_power_validate_fail(self, mock_validate): def test__do_node_clean_automated_power_validate_fail(self, mock_validate):
self.__do_node_clean_validate_fail(mock_validate) self.__do_node_clean_validate_fail(mock_validate)
@mock.patch('ironic.drivers.modules.fake.FakePower.validate', @mock.patch('ironic.drivers.modules.fake.FakePower.validate',
autospec=True) autospec=True)
def test__do_node_clean_manual_power_validate_fail(self, mock_validate): def test__do_node_clean_manual_power_validate_fail(self, mock_validate):
skipping to change at line 309 skipping to change at line 313
maintenance_reason='Original reason') maintenance_reason='Original reason')
with task_manager.acquire( with task_manager.acquire(
self.context, node.uuid, shared=False) as task: self.context, node.uuid, shared=False) as task:
cleaning.do_node_clean(task) cleaning.do_node_clean(task)
node.refresh() node.refresh()
self.assertEqual(states.CLEANFAIL, node.provision_state) self.assertEqual(states.CLEANFAIL, node.provision_state)
self.assertEqual(states.AVAILABLE, node.target_provision_state) self.assertEqual(states.AVAILABLE, node.target_provision_state)
self.assertIn('is not allowed', node.last_error) self.assertIn('is not allowed', node.last_error)
self.assertTrue(node.maintenance) self.assertTrue(node.maintenance)
self.assertEqual('Original reason', node.maintenance_reason) self.assertEqual('Original reason', node.maintenance_reason)
self.assertIsNone(node.fault) # no clean step running
self.assertFalse(mock_prep.called) self.assertFalse(mock_prep.called)
self.assertFalse(mock_tear_down.called) self.assertFalse(mock_tear_down.called)
@mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate', @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate',
autospec=True) autospec=True)
@mock.patch('ironic.drivers.modules.fake.FakeDeploy.prepare_cleaning', @mock.patch('ironic.drivers.modules.fake.FakeDeploy.prepare_cleaning',
autospec=True) autospec=True)
def __do_node_clean_prepare_clean_fail(self, mock_prep, mock_validate, def __do_node_clean_prepare_clean_fail(self, mock_prep, mock_validate,
clean_steps=None): clean_steps=None):
# Exception from task.driver.deploy.prepare_cleaning should cause node # Exception from task.driver.deploy.prepare_cleaning should cause node
skipping to change at line 334 skipping to change at line 339
provision_state=states.CLEANING, provision_state=states.CLEANING,
target_provision_state=tgt_prov_state) target_provision_state=tgt_prov_state)
with task_manager.acquire( with task_manager.acquire(
self.context, node.uuid, shared=False) as task: self.context, node.uuid, shared=False) as task:
cleaning.do_node_clean(task, clean_steps=clean_steps) cleaning.do_node_clean(task, clean_steps=clean_steps)
node.refresh() node.refresh()
self.assertEqual(states.CLEANFAIL, node.provision_state) self.assertEqual(states.CLEANFAIL, node.provision_state)
self.assertEqual(tgt_prov_state, node.target_provision_state) self.assertEqual(tgt_prov_state, node.target_provision_state)
mock_prep.assert_called_once_with(mock.ANY, task) mock_prep.assert_called_once_with(mock.ANY, task)
mock_validate.assert_called_once_with(mock.ANY, task) mock_validate.assert_called_once_with(mock.ANY, task)
self.assertFalse(node.maintenance)
self.assertIsNone(node.fault)
def test__do_node_clean_automated_prepare_clean_fail(self): def test__do_node_clean_automated_prepare_clean_fail(self):
self.__do_node_clean_prepare_clean_fail() self.__do_node_clean_prepare_clean_fail()
def test__do_node_clean_manual_prepare_clean_fail(self): def test__do_node_clean_manual_prepare_clean_fail(self):
self.__do_node_clean_prepare_clean_fail(clean_steps=[self.deploy_raid]) self.__do_node_clean_prepare_clean_fail(clean_steps=[self.deploy_raid])
@mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate', @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate',
autospec=True) autospec=True)
@mock.patch('ironic.drivers.modules.fake.FakeDeploy.prepare_cleaning', @mock.patch('ironic.drivers.modules.fake.FakeDeploy.prepare_cleaning',
skipping to change at line 391 skipping to change at line 398
provision_state=states.CLEANING, provision_state=states.CLEANING,
target_provision_state=tgt_prov_state) target_provision_state=tgt_prov_state)
with task_manager.acquire( with task_manager.acquire(
self.context, node.uuid, shared=False) as task: self.context, node.uuid, shared=False) as task:
cleaning.do_node_clean(task, clean_steps=clean_steps) cleaning.do_node_clean(task, clean_steps=clean_steps)
mock_validate.assert_called_once_with(mock.ANY, task) mock_validate.assert_called_once_with(mock.ANY, task)
node.refresh() node.refresh()
self.assertEqual(states.CLEANFAIL, node.provision_state) self.assertEqual(states.CLEANFAIL, node.provision_state)
self.assertEqual(tgt_prov_state, node.target_provision_state) self.assertEqual(tgt_prov_state, node.target_provision_state)
mock_steps.assert_called_once_with(mock.ANY) mock_steps.assert_called_once_with(mock.ANY)
self.assertFalse(node.maintenance)
self.assertIsNone(node.fault)
def test__do_node_clean_automated_steps_fail(self): def test__do_node_clean_automated_steps_fail(self):
for invalid in (True, False): for invalid in (True, False):
self.__do_node_clean_steps_fail(invalid_exc=invalid) self.__do_node_clean_steps_fail(invalid_exc=invalid)
def test__do_node_clean_manual_steps_fail(self): def test__do_node_clean_manual_steps_fail(self):
for invalid in (True, False): for invalid in (True, False):
self.__do_node_clean_steps_fail(clean_steps=[self.deploy_raid], self.__do_node_clean_steps_fail(clean_steps=[self.deploy_raid],
invalid_exc=invalid) invalid_exc=invalid)
skipping to change at line 438 skipping to change at line 447
node.refresh() node.refresh()
mock_power_valid.assert_called_once_with(mock.ANY, task) mock_power_valid.assert_called_once_with(mock.ANY, task)
mock_network_valid.assert_called_once_with(mock.ANY, task) mock_network_valid.assert_called_once_with(mock.ANY, task)
mock_next_step.assert_called_once_with(task, 0) mock_next_step.assert_called_once_with(task, 0)
mock_steps.assert_called_once_with(task) mock_steps.assert_called_once_with(task)
if clean_steps: if clean_steps:
self.assertEqual(clean_steps, self.assertEqual(clean_steps,
node.driver_internal_info['clean_steps']) node.driver_internal_info['clean_steps'])
self.assertFalse(node.maintenance)
# Check that state didn't change # Check that state didn't change
self.assertEqual(states.CLEANING, node.provision_state) self.assertEqual(states.CLEANING, node.provision_state)
self.assertEqual(tgt_prov_state, node.target_provision_state) self.assertEqual(tgt_prov_state, node.target_provision_state)
def test__do_node_clean_automated(self): def test__do_node_clean_automated(self):
self.__do_node_clean() self.__do_node_clean()
def test__do_node_clean_manual(self): def test__do_node_clean_manual(self):
self.__do_node_clean(clean_steps=[self.deploy_raid]) self.__do_node_clean(clean_steps=[self.deploy_raid])
skipping to change at line 729 skipping to change at line 739
node.refresh() node.refresh()
# Make sure we go to CLEANFAIL, clear clean_steps # Make sure we go to CLEANFAIL, clear clean_steps
self.assertEqual(states.CLEANFAIL, node.provision_state) self.assertEqual(states.CLEANFAIL, node.provision_state)
self.assertEqual(tgt_prov_state, node.target_provision_state) self.assertEqual(tgt_prov_state, node.target_provision_state)
self.assertEqual({}, node.clean_step) self.assertEqual({}, node.clean_step)
self.assertNotIn('clean_step_index', node.driver_internal_info) self.assertNotIn('clean_step_index', node.driver_internal_info)
self.assertIsNotNone(node.last_error) self.assertIsNotNone(node.last_error)
self.assertTrue(node.maintenance) self.assertTrue(node.maintenance)
self.assertEqual(faults.CLEAN_FAILURE, node.fault)
mock_execute.assert_called_once_with( mock_execute.assert_called_once_with(
mock.ANY, mock.ANY, self.clean_steps[0]) mock.ANY, mock.ANY, self.clean_steps[0])
mock_collect_logs.assert_called_once_with(mock.ANY, label='cleaning') mock_collect_logs.assert_called_once_with(mock.ANY, label='cleaning')
def test__do_next_clean_step_automated_execute_fail(self): def test__do_next_clean_step_automated_execute_fail(self):
self._do_next_clean_step_execute_fail() self._do_next_clean_step_execute_fail()
def test__do_next_clean_step_manual_execute_fail(self): def test__do_next_clean_step_manual_execute_fail(self):
self._do_next_clean_step_execute_fail(manual=True) self._do_next_clean_step_execute_fail(manual=True)
skipping to change at line 841 skipping to change at line 852
self.assertEqual(states.CLEANFAIL, node.provision_state) self.assertEqual(states.CLEANFAIL, node.provision_state)
self.assertEqual(tgt_prov_state, node.target_provision_state) self.assertEqual(tgt_prov_state, node.target_provision_state)
self.assertEqual({}, node.clean_step) self.assertEqual({}, node.clean_step)
self.assertNotIn('clean_step_index', node.driver_internal_info) self.assertNotIn('clean_step_index', node.driver_internal_info)
self.assertNotIn('skip_current_clean_step', node.driver_internal_info) self.assertNotIn('skip_current_clean_step', node.driver_internal_info)
self.assertIsNotNone(node.last_error) self.assertIsNotNone(node.last_error)
self.assertTrue(node.maintenance) self.assertTrue(node.maintenance)
mock_execute.assert_called_once_with( mock_execute.assert_called_once_with(
mock.ANY, mock.ANY, self.clean_steps[0]) mock.ANY, mock.ANY, self.clean_steps[0])
@mock.patch.object(cleaning, 'LOG', autospec=True) @mock.patch.object(conductor_utils, 'LOG', autospec=True)
@mock.patch('ironic.drivers.modules.fake.FakeDeploy.execute_clean_step', @mock.patch('ironic.drivers.modules.fake.FakeDeploy.execute_clean_step',
autospec=True) autospec=True)
@mock.patch('ironic.drivers.modules.fake.FakePower.execute_clean_step', @mock.patch('ironic.drivers.modules.fake.FakePower.execute_clean_step',
autospec=True) autospec=True)
@mock.patch.object(fake.FakeDeploy, 'tear_down_cleaning', autospec=True) @mock.patch.object(fake.FakeDeploy, 'tear_down_cleaning', autospec=True)
def _do_next_clean_step_fail_in_tear_down_cleaning( def _do_next_clean_step_fail_in_tear_down_cleaning(
self, tear_mock, power_exec_mock, deploy_exec_mock, log_mock, self, tear_mock, power_exec_mock, deploy_exec_mock, log_mock,
manual=True): manual=True):
tgt_prov_state = states.MANAGEABLE if manual else states.AVAILABLE tgt_prov_state = states.MANAGEABLE if manual else states.AVAILABLE
skipping to change at line 878 skipping to change at line 889
node.refresh() node.refresh()
# Make sure we go to CLEANFAIL, clear clean_steps # Make sure we go to CLEANFAIL, clear clean_steps
self.assertEqual(states.CLEANFAIL, node.provision_state) self.assertEqual(states.CLEANFAIL, node.provision_state)
self.assertEqual(tgt_prov_state, node.target_provision_state) self.assertEqual(tgt_prov_state, node.target_provision_state)
self.assertEqual({}, node.clean_step) self.assertEqual({}, node.clean_step)
self.assertNotIn('clean_step_index', node.driver_internal_info) self.assertNotIn('clean_step_index', node.driver_internal_info)
self.assertIsNotNone(node.last_error) self.assertIsNotNone(node.last_error)
self.assertEqual(1, tear_mock.call_count) self.assertEqual(1, tear_mock.call_count)
self.assertTrue(node.maintenance) self.assertFalse(node.maintenance) # no step is running
deploy_exec_calls = [ deploy_exec_calls = [
mock.call(mock.ANY, mock.ANY, self.clean_steps[0]), mock.call(mock.ANY, mock.ANY, self.clean_steps[0]),
mock.call(mock.ANY, mock.ANY, self.clean_steps[2]), mock.call(mock.ANY, mock.ANY, self.clean_steps[2]),
] ]
self.assertEqual(deploy_exec_calls, deploy_exec_mock.call_args_list) self.assertEqual(deploy_exec_calls, deploy_exec_mock.call_args_list)
power_exec_calls = [ power_exec_calls = [
mock.call(mock.ANY, mock.ANY, self.clean_steps[1]), mock.call(mock.ANY, mock.ANY, self.clean_steps[1]),
] ]
self.assertEqual(power_exec_calls, power_exec_mock.call_args_list) self.assertEqual(power_exec_calls, power_exec_mock.call_args_list)
log_mock.exception.assert_called_once_with( log_mock.error.assert_called_once_with(
'Failed to tear down from cleaning for node {}, reason: boom' 'Failed to tear down from cleaning for node {}, reason: boom'
.format(node.uuid)) .format(node.uuid), exc_info=True)
def test__do_next_clean_step_automated_fail_in_tear_down_cleaning(self): def test__do_next_clean_step_automated_fail_in_tear_down_cleaning(self):
self._do_next_clean_step_fail_in_tear_down_cleaning() self._do_next_clean_step_fail_in_tear_down_cleaning()
def test__do_next_clean_step_manual_fail_in_tear_down_cleaning(self): def test__do_next_clean_step_manual_fail_in_tear_down_cleaning(self):
self._do_next_clean_step_fail_in_tear_down_cleaning(manual=True) self._do_next_clean_step_fail_in_tear_down_cleaning(manual=True)
@mock.patch('ironic.drivers.modules.fake.FakeDeploy.execute_clean_step', @mock.patch('ironic.drivers.modules.fake.FakeDeploy.execute_clean_step',
autospec=True) autospec=True)
def _do_next_clean_step_no_steps(self, mock_execute, manual=False, def _do_next_clean_step_no_steps(self, mock_execute, manual=False,
skipping to change at line 985 skipping to change at line 996
cleaning.do_next_clean_step(task, 0) cleaning.do_next_clean_step(task, 0)
node.refresh() node.refresh()
# Make sure we go to CLEANFAIL, clear clean_steps # Make sure we go to CLEANFAIL, clear clean_steps
self.assertEqual(states.CLEANFAIL, node.provision_state) self.assertEqual(states.CLEANFAIL, node.provision_state)
self.assertEqual(tgt_prov_state, node.target_provision_state) self.assertEqual(tgt_prov_state, node.target_provision_state)
self.assertEqual({}, node.clean_step) self.assertEqual({}, node.clean_step)
self.assertNotIn('clean_step_index', node.driver_internal_info) self.assertNotIn('clean_step_index', node.driver_internal_info)
self.assertIsNotNone(node.last_error) self.assertIsNotNone(node.last_error)
self.assertTrue(node.maintenance) self.assertTrue(node.maintenance) # the 1st clean step was running
deploy_exec_mock.assert_called_once_with(mock.ANY, mock.ANY, deploy_exec_mock.assert_called_once_with(mock.ANY, mock.ANY,
self.clean_steps[0]) self.clean_steps[0])
# Make sure we don't execute any other step and return # Make sure we don't execute any other step and return
self.assertFalse(power_exec_mock.called) self.assertFalse(power_exec_mock.called)
def test__do_next_clean_step_automated_bad_step_return_value(self): def test__do_next_clean_step_automated_bad_step_return_value(self):
self._do_next_clean_step_bad_step_return_value() self._do_next_clean_step_bad_step_return_value()
def test__do_next_clean_step_manual_bad_step_return_value(self): def test__do_next_clean_step_manual_bad_step_return_value(self):
self._do_next_clean_step_bad_step_return_value(manual=True) self._do_next_clean_step_bad_step_return_value(manual=True)
 End of changes. 13 change blocks. 
5 lines changed or deleted 16 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)