summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ironic/tests/unit/conductor/test_manager.py342
1 files changed, 208 insertions, 134 deletions
diff --git a/ironic/tests/unit/conductor/test_manager.py b/ironic/tests/unit/conductor/test_manager.py
index 9c5b98c..2117f7a 100644
--- a/ironic/tests/unit/conductor/test_manager.py
+++ b/ironic/tests/unit/conductor/test_manager.py
@@ -944,7 +944,8 @@ class VendorPassthruTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
944 mock_get_if.assert_called_once_with(mock.ANY, 'vendor', 'fake') 944 mock_get_if.assert_called_once_with(mock.ANY, 'vendor', 'fake')
945 945
946 @mock.patch.object(driver_factory, 'get_interface', autospec=True) 946 @mock.patch.object(driver_factory, 'get_interface', autospec=True)
947 @mock.patch.object(manager.ConductorManager, '_spawn_worker') 947 @mock.patch.object(manager.ConductorManager, '_spawn_worker',
948 autospec=True)
948 def test_driver_vendor_passthru_async(self, mock_spawn, mock_iface): 949 def test_driver_vendor_passthru_async(self, mock_spawn, mock_iface):
949 test_method = mock.MagicMock() 950 test_method = mock.MagicMock()
950 mock_iface.return_value.driver_routes = { 951 mock_iface.return_value.driver_routes = {
@@ -963,8 +964,8 @@ class VendorPassthruTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
963 964
964 self.assertIsNone(response['return']) 965 self.assertIsNone(response['return'])
965 self.assertTrue(response['async']) 966 self.assertTrue(response['async'])
966 mock_spawn.assert_called_once_with(test_method, self.context, 967 mock_spawn.assert_called_once_with(self.service, test_method,
967 **vendor_args) 968 self.context, **vendor_args)
968 969
969 @mock.patch.object(driver_factory, 'get_interface', autospec=True) 970 @mock.patch.object(driver_factory, 'get_interface', autospec=True)
970 def test_driver_vendor_passthru_http_method_not_supported(self, 971 def test_driver_vendor_passthru_http_method_not_supported(self,
@@ -1163,7 +1164,8 @@ class ServiceDoNodeDeployTestCase(mgr_utils.ServiceSetUpMixin,
1163 mock_iwdi.return_value = False 1164 mock_iwdi.return_value = False
1164 self._start_service() 1165 self._start_service()
1165 thread = self.service._spawn_worker(lambda: None) 1166 thread = self.service._spawn_worker(lambda: None)
1166 with mock.patch.object(self.service, '_spawn_worker') as mock_spawn: 1167 with mock.patch.object(self.service, '_spawn_worker',
1168 autospec=True) as mock_spawn:
1167 mock_spawn.return_value = thread 1169 mock_spawn.return_value = thread
1168 1170
1169 node = obj_utils.create_test_node(self.context, 1171 node = obj_utils.create_test_node(self.context,
@@ -1342,7 +1344,8 @@ class ServiceDoNodeDeployTestCase(mgr_utils.ServiceSetUpMixin,
1342 driver='fake-hardware') 1344 driver='fake-hardware')
1343 self._start_service() 1345 self._start_service()
1344 1346
1345 with mock.patch.object(self.service, '_spawn_worker') as mock_spawn: 1347 with mock.patch.object(self.service, '_spawn_worker',
1348 autospec=True) as mock_spawn:
1346 mock_spawn.side_effect = exception.NoFreeConductorWorker() 1349 mock_spawn.side_effect = exception.NoFreeConductorWorker()
1347 1350
1348 exc = self.assertRaises(messaging.rpc.ExpectedException, 1351 exc = self.assertRaises(messaging.rpc.ExpectedException,
@@ -1850,7 +1853,8 @@ class DoNodeDeployTearDownTestCase(mgr_utils.ServiceSetUpMixin,
1850 # deletion -- not that such a node's deletion could later be 1853 # deletion -- not that such a node's deletion could later be
1851 # completed. 1854 # completed.
1852 1855
1853 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 1856 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
1857 autospec=True)
1854 def test_do_node_tear_down_worker_pool_full(self, mock_spawn): 1858 def test_do_node_tear_down_worker_pool_full(self, mock_spawn):
1855 prv_state = states.ACTIVE 1859 prv_state = states.ACTIVE
1856 tgt_prv_state = states.NOSTATE 1860 tgt_prv_state = states.NOSTATE
@@ -1882,7 +1886,8 @@ class DoNodeDeployTearDownTestCase(mgr_utils.ServiceSetUpMixin,
1882 # Verify reservation has been cleared. 1886 # Verify reservation has been cleared.
1883 self.assertIsNone(node.reservation) 1887 self.assertIsNone(node.reservation)
1884 1888
1885 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 1889 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
1890 autospec=True)
1886 def test_do_provisioning_action_worker_pool_full(self, mock_spawn): 1891 def test_do_provisioning_action_worker_pool_full(self, mock_spawn):
1887 prv_state = states.MANAGEABLE 1892 prv_state = states.MANAGEABLE
1888 tgt_prv_state = states.NOSTATE 1893 tgt_prv_state = states.NOSTATE
@@ -1908,7 +1913,8 @@ class DoNodeDeployTearDownTestCase(mgr_utils.ServiceSetUpMixin,
1908 # Verify reservation has been cleared. 1913 # Verify reservation has been cleared.
1909 self.assertIsNone(node.reservation) 1914 self.assertIsNone(node.reservation)
1910 1915
1911 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 1916 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
1917 autospec=True)
1912 def test_do_provision_action_provide(self, mock_spawn): 1918 def test_do_provision_action_provide(self, mock_spawn):
1913 # test when a node is cleaned going from manageable to available 1919 # test when a node is cleaned going from manageable to available
1914 node = obj_utils.create_test_node( 1920 node = obj_utils.create_test_node(
@@ -1923,9 +1929,11 @@ class DoNodeDeployTearDownTestCase(mgr_utils.ServiceSetUpMixin,
1923 self.assertEqual(states.CLEANING, node.provision_state) 1929 self.assertEqual(states.CLEANING, node.provision_state)
1924 self.assertEqual(states.AVAILABLE, node.target_provision_state) 1930 self.assertEqual(states.AVAILABLE, node.target_provision_state)
1925 self.assertIsNone(node.last_error) 1931 self.assertIsNone(node.last_error)
1926 mock_spawn.assert_called_with(self.service._do_node_clean, mock.ANY) 1932 mock_spawn.assert_called_with(self.service,
1933 self.service._do_node_clean, mock.ANY)
1927 1934
1928 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 1935 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
1936 autospec=True)
1929 def test_do_provision_action_manage(self, mock_spawn): 1937 def test_do_provision_action_manage(self, mock_spawn):
1930 # test when a node is verified going from enroll to manageable 1938 # test when a node is verified going from enroll to manageable
1931 node = obj_utils.create_test_node( 1939 node = obj_utils.create_test_node(
@@ -1940,9 +1948,11 @@ class DoNodeDeployTearDownTestCase(mgr_utils.ServiceSetUpMixin,
1940 self.assertEqual(states.VERIFYING, node.provision_state) 1948 self.assertEqual(states.VERIFYING, node.provision_state)
1941 self.assertEqual(states.MANAGEABLE, node.target_provision_state) 1949 self.assertEqual(states.MANAGEABLE, node.target_provision_state)
1942 self.assertIsNone(node.last_error) 1950 self.assertIsNone(node.last_error)
1943 mock_spawn.assert_called_with(self.service._do_node_verify, mock.ANY) 1951 mock_spawn.assert_called_with(self.service,
1952 self.service._do_node_verify, mock.ANY)
1944 1953
1945 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 1954 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
1955 autospec=True)
1946 def _do_provision_action_abort(self, mock_spawn, manual=False): 1956 def _do_provision_action_abort(self, mock_spawn, manual=False):
1947 tgt_prov_state = states.MANAGEABLE if manual else states.AVAILABLE 1957 tgt_prov_state = states.MANAGEABLE if manual else states.AVAILABLE
1948 node = obj_utils.create_test_node( 1958 node = obj_utils.create_test_node(
@@ -1957,8 +1967,8 @@ class DoNodeDeployTearDownTestCase(mgr_utils.ServiceSetUpMixin,
1957 self.assertEqual(states.CLEANFAIL, node.provision_state) 1967 self.assertEqual(states.CLEANFAIL, node.provision_state)
1958 self.assertEqual(tgt_prov_state, node.target_provision_state) 1968 self.assertEqual(tgt_prov_state, node.target_provision_state)
1959 self.assertIsNone(node.last_error) 1969 self.assertIsNone(node.last_error)
1960 mock_spawn.assert_called_with(self.service._do_node_clean_abort, 1970 mock_spawn.assert_called_with(
1961 mock.ANY) 1971 self.service, self.service._do_node_clean_abort, mock.ANY)
1962 1972
1963 def test_do_provision_action_abort_automated_clean(self): 1973 def test_do_provision_action_abort_automated_clean(self):
1964 self._do_provision_action_abort() 1974 self._do_provision_action_abort()
@@ -2044,7 +2054,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2044 self.deploy_raid = { 2054 self.deploy_raid = {
2045 'step': 'build_raid', 'priority': 0, 'interface': 'deploy'} 2055 'step': 'build_raid', 'priority': 0, 'interface': 'deploy'}
2046 2056
2047 @mock.patch('ironic.drivers.modules.fake.FakePower.validate') 2057 @mock.patch('ironic.drivers.modules.fake.FakePower.validate',
2058 autospec=True)
2048 def test_do_node_clean_maintenance(self, mock_validate): 2059 def test_do_node_clean_maintenance(self, mock_validate):
2049 node = obj_utils.create_test_node( 2060 node = obj_utils.create_test_node(
2050 self.context, driver='fake-hardware', 2061 self.context, driver='fake-hardware',
@@ -2059,7 +2070,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2059 self.assertEqual(exception.NodeInMaintenance, exc.exc_info[0]) 2070 self.assertEqual(exception.NodeInMaintenance, exc.exc_info[0])
2060 self.assertFalse(mock_validate.called) 2071 self.assertFalse(mock_validate.called)
2061 2072
2062 @mock.patch('ironic.conductor.task_manager.TaskManager.process_event') 2073 @mock.patch('ironic.conductor.task_manager.TaskManager.process_event',
2074 autospec=True)
2063 def _test_do_node_clean_validate_fail(self, mock_validate, mock_process): 2075 def _test_do_node_clean_validate_fail(self, mock_validate, mock_process):
2064 mock_validate.side_effect = exception.InvalidParameterValue('error') 2076 mock_validate.side_effect = exception.InvalidParameterValue('error')
2065 node = obj_utils.create_test_node( 2077 node = obj_utils.create_test_node(
@@ -2072,19 +2084,23 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2072 self.context, node.uuid, []) 2084 self.context, node.uuid, [])
2073 # Compare true exception hidden by @messaging.expected_exceptions 2085 # Compare true exception hidden by @messaging.expected_exceptions
2074 self.assertEqual(exception.InvalidParameterValue, exc.exc_info[0]) 2086 self.assertEqual(exception.InvalidParameterValue, exc.exc_info[0])
2075 mock_validate.assert_called_once_with(mock.ANY) 2087 mock_validate.assert_called_once_with(mock.ANY, mock.ANY)
2076 self.assertFalse(mock_process.called) 2088 self.assertFalse(mock_process.called)
2077 2089
2078 @mock.patch('ironic.drivers.modules.fake.FakePower.validate') 2090 @mock.patch('ironic.drivers.modules.fake.FakePower.validate',
2091 autospec=True)
2079 def test_do_node_clean_power_validate_fail(self, mock_validate): 2092 def test_do_node_clean_power_validate_fail(self, mock_validate):
2080 self._test_do_node_clean_validate_fail(mock_validate) 2093 self._test_do_node_clean_validate_fail(mock_validate)
2081 2094
2082 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate') 2095 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate',
2096 autospec=True)
2083 def test_do_node_clean_network_validate_fail(self, mock_validate): 2097 def test_do_node_clean_network_validate_fail(self, mock_validate):
2084 self._test_do_node_clean_validate_fail(mock_validate) 2098 self._test_do_node_clean_validate_fail(mock_validate)
2085 2099
2086 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate') 2100 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate',
2087 @mock.patch('ironic.drivers.modules.fake.FakePower.validate') 2101 autospec=True)
2102 @mock.patch('ironic.drivers.modules.fake.FakePower.validate',
2103 autospec=True)
2088 def test_do_node_clean_invalid_state(self, mock_power_valid, 2104 def test_do_node_clean_invalid_state(self, mock_power_valid,
2089 mock_network_valid): 2105 mock_network_valid):
2090 # test node.provision_state is incorrect for clean 2106 # test node.provision_state is incorrect for clean
@@ -2098,14 +2114,17 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2098 self.context, node.uuid, []) 2114 self.context, node.uuid, [])
2099 # Compare true exception hidden by @messaging.expected_exceptions 2115 # Compare true exception hidden by @messaging.expected_exceptions
2100 self.assertEqual(exception.InvalidStateRequested, exc.exc_info[0]) 2116 self.assertEqual(exception.InvalidStateRequested, exc.exc_info[0])
2101 mock_power_valid.assert_called_once_with(mock.ANY) 2117 mock_power_valid.assert_called_once_with(mock.ANY, mock.ANY)
2102 mock_network_valid.assert_called_once_with(mock.ANY) 2118 mock_network_valid.assert_called_once_with(mock.ANY, mock.ANY)
2103 node.refresh() 2119 node.refresh()
2104 self.assertNotIn('clean_steps', node.driver_internal_info) 2120 self.assertNotIn('clean_steps', node.driver_internal_info)
2105 2121
2106 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 2122 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
2107 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate') 2123 autospec=True)
2108 @mock.patch('ironic.drivers.modules.fake.FakePower.validate') 2124 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate',
2125 autospec=True)
2126 @mock.patch('ironic.drivers.modules.fake.FakePower.validate',
2127 autospec=True)
2109 def test_do_node_clean_ok(self, mock_power_valid, mock_network_valid, 2128 def test_do_node_clean_ok(self, mock_power_valid, mock_network_valid,
2110 mock_spawn): 2129 mock_spawn):
2111 node = obj_utils.create_test_node( 2130 node = obj_utils.create_test_node(
@@ -2115,10 +2134,10 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2115 self._start_service() 2134 self._start_service()
2116 clean_steps = [self.deploy_raid] 2135 clean_steps = [self.deploy_raid]
2117 self.service.do_node_clean(self.context, node.uuid, clean_steps) 2136 self.service.do_node_clean(self.context, node.uuid, clean_steps)
2118 mock_power_valid.assert_called_once_with(mock.ANY) 2137 mock_power_valid.assert_called_once_with(mock.ANY, mock.ANY)
2119 mock_network_valid.assert_called_once_with(mock.ANY) 2138 mock_network_valid.assert_called_once_with(mock.ANY, mock.ANY)
2120 mock_spawn.assert_called_with(self.service._do_node_clean, mock.ANY, 2139 mock_spawn.assert_called_with(
2121 clean_steps) 2140 self.service, self.service._do_node_clean, mock.ANY, clean_steps)
2122 node.refresh() 2141 node.refresh()
2123 # Node will be moved to CLEANING 2142 # Node will be moved to CLEANING
2124 self.assertEqual(states.CLEANING, node.provision_state) 2143 self.assertEqual(states.CLEANING, node.provision_state)
@@ -2126,9 +2145,12 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2126 self.assertNotIn('clean_steps', node.driver_internal_info) 2145 self.assertNotIn('clean_steps', node.driver_internal_info)
2127 self.assertIsNone(node.last_error) 2146 self.assertIsNone(node.last_error)
2128 2147
2129 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 2148 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
2130 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate') 2149 autospec=True)
2131 @mock.patch('ironic.drivers.modules.fake.FakePower.validate') 2150 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate',
2151 autospec=True)
2152 @mock.patch('ironic.drivers.modules.fake.FakePower.validate',
2153 autospec=True)
2132 def test_do_node_clean_worker_pool_full(self, mock_power_valid, 2154 def test_do_node_clean_worker_pool_full(self, mock_power_valid,
2133 mock_network_valid, mock_spawn): 2155 mock_network_valid, mock_spawn):
2134 prv_state = states.MANAGEABLE 2156 prv_state = states.MANAGEABLE
@@ -2145,10 +2167,10 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2145 # Compare true exception hidden by @messaging.expected_exceptions 2167 # Compare true exception hidden by @messaging.expected_exceptions
2146 self.assertEqual(exception.NoFreeConductorWorker, exc.exc_info[0]) 2168 self.assertEqual(exception.NoFreeConductorWorker, exc.exc_info[0])
2147 self._stop_service() 2169 self._stop_service()
2148 mock_power_valid.assert_called_once_with(mock.ANY) 2170 mock_power_valid.assert_called_once_with(mock.ANY, mock.ANY)
2149 mock_network_valid.assert_called_once_with(mock.ANY) 2171 mock_network_valid.assert_called_once_with(mock.ANY, mock.ANY)
2150 mock_spawn.assert_called_with(self.service._do_node_clean, mock.ANY, 2172 mock_spawn.assert_called_with(
2151 clean_steps) 2173 self.service, self.service._do_node_clean, mock.ANY, clean_steps)
2152 node.refresh() 2174 node.refresh()
2153 # Make sure states were rolled back 2175 # Make sure states were rolled back
2154 self.assertEqual(prv_state, node.provision_state) 2176 self.assertEqual(prv_state, node.provision_state)
@@ -2157,7 +2179,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2157 self.assertIsNotNone(node.last_error) 2179 self.assertIsNotNone(node.last_error)
2158 self.assertIsNone(node.reservation) 2180 self.assertIsNone(node.reservation)
2159 2181
2160 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 2182 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
2183 autospec=True)
2161 def test_continue_node_clean_worker_pool_full(self, mock_spawn): 2184 def test_continue_node_clean_worker_pool_full(self, mock_spawn):
2162 # Test the appropriate exception is raised if the worker pool is full 2185 # Test the appropriate exception is raised if the worker pool is full
2163 prv_state = states.CLEANWAIT 2186 prv_state = states.CLEANWAIT
@@ -2174,7 +2197,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2174 self.service.continue_node_clean, 2197 self.service.continue_node_clean,
2175 self.context, node.uuid) 2198 self.context, node.uuid)
2176 2199
2177 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 2200 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
2201 autospec=True)
2178 def test_continue_node_clean_wrong_state(self, mock_spawn): 2202 def test_continue_node_clean_wrong_state(self, mock_spawn):
2179 # Test the appropriate exception is raised if node isn't already 2203 # Test the appropriate exception is raised if node isn't already
2180 # in CLEANWAIT state 2204 # in CLEANWAIT state
@@ -2198,7 +2222,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2198 # Verify reservation has been cleared. 2222 # Verify reservation has been cleared.
2199 self.assertIsNone(node.reservation) 2223 self.assertIsNone(node.reservation)
2200 2224
2201 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 2225 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
2226 autospec=True)
2202 def _continue_node_clean(self, return_state, mock_spawn, manual=False): 2227 def _continue_node_clean(self, return_state, mock_spawn, manual=False):
2203 # test a node can continue cleaning via RPC 2228 # test a node can continue cleaning via RPC
2204 prv_state = return_state 2229 prv_state = return_state
@@ -2217,7 +2242,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2217 node.refresh() 2242 node.refresh()
2218 self.assertEqual(states.CLEANING, node.provision_state) 2243 self.assertEqual(states.CLEANING, node.provision_state)
2219 self.assertEqual(tgt_prv_state, node.target_provision_state) 2244 self.assertEqual(tgt_prv_state, node.target_provision_state)
2220 mock_spawn.assert_called_with(self.service._do_next_clean_step, 2245 mock_spawn.assert_called_with(self.service,
2246 self.service._do_next_clean_step,
2221 mock.ANY, self.next_clean_step_index) 2247 mock.ANY, self.next_clean_step_index)
2222 2248
2223 def test_continue_node_clean_automated(self): 2249 def test_continue_node_clean_automated(self):
@@ -2226,7 +2252,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2226 def test_continue_node_clean_manual(self): 2252 def test_continue_node_clean_manual(self):
2227 self._continue_node_clean(states.CLEANWAIT, manual=True) 2253 self._continue_node_clean(states.CLEANWAIT, manual=True)
2228 2254
2229 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 2255 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
2256 autospec=True)
2230 def _continue_node_clean_skip_step(self, mock_spawn, skip=True): 2257 def _continue_node_clean_skip_step(self, mock_spawn, skip=True):
2231 # test that skipping current step mechanism works 2258 # test that skipping current step mechanism works
2232 driver_info = {'clean_steps': self.clean_steps, 2259 driver_info = {'clean_steps': self.clean_steps,
@@ -2248,7 +2275,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2248 self.assertNotIn( 2275 self.assertNotIn(
2249 'skip_current_clean_step', node.driver_internal_info) 2276 'skip_current_clean_step', node.driver_internal_info)
2250 expected_step_index = 0 2277 expected_step_index = 0
2251 mock_spawn.assert_called_with(self.service._do_next_clean_step, 2278 mock_spawn.assert_called_with(self.service,
2279 self.service._do_next_clean_step,
2252 mock.ANY, expected_step_index) 2280 mock.ANY, expected_step_index)
2253 2281
2254 def test_continue_node_clean_skip_step(self): 2282 def test_continue_node_clean_skip_step(self):
@@ -2327,32 +2355,40 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2327 node.refresh() 2355 node.refresh()
2328 self.assertEqual(states.CLEANFAIL, node.provision_state) 2356 self.assertEqual(states.CLEANFAIL, node.provision_state)
2329 self.assertEqual(tgt_prov_state, node.target_provision_state) 2357 self.assertEqual(tgt_prov_state, node.target_provision_state)
2330 mock_validate.assert_called_once_with(mock.ANY) 2358 mock_validate.assert_called_once_with(mock.ANY, mock.ANY)
2331 2359
2332 @mock.patch('ironic.drivers.modules.fake.FakePower.validate') 2360 @mock.patch('ironic.drivers.modules.fake.FakePower.validate',
2361 autospec=True)
2333 def test__do_node_clean_automated_power_validate_fail(self, mock_validate): 2362 def test__do_node_clean_automated_power_validate_fail(self, mock_validate):
2334 self.__do_node_clean_validate_fail(mock_validate) 2363 self.__do_node_clean_validate_fail(mock_validate)
2335 2364
2336 @mock.patch('ironic.drivers.modules.fake.FakePower.validate') 2365 @mock.patch('ironic.drivers.modules.fake.FakePower.validate',
2366 autospec=True)
2337 def test__do_node_clean_manual_power_validate_fail(self, mock_validate): 2367 def test__do_node_clean_manual_power_validate_fail(self, mock_validate):
2338 self.__do_node_clean_validate_fail(mock_validate, clean_steps=[]) 2368 self.__do_node_clean_validate_fail(mock_validate, clean_steps=[])
2339 2369
2340 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate') 2370 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate',
2371 autospec=True)
2341 def test__do_node_clean_automated_network_validate_fail(self, 2372 def test__do_node_clean_automated_network_validate_fail(self,
2342 mock_validate): 2373 mock_validate):
2343 self.__do_node_clean_validate_fail(mock_validate) 2374 self.__do_node_clean_validate_fail(mock_validate)
2344 2375
2345 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate') 2376 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate',
2377 autospec=True)
2346 def test__do_node_clean_manual_network_validate_fail(self, mock_validate): 2378 def test__do_node_clean_manual_network_validate_fail(self, mock_validate):
2347 self.__do_node_clean_validate_fail(mock_validate, clean_steps=[]) 2379 self.__do_node_clean_validate_fail(mock_validate, clean_steps=[])
2348 2380
2349 @mock.patch.object(manager, 'LOG', autospec=True) 2381 @mock.patch.object(manager, 'LOG', autospec=True)
2350 @mock.patch.object(conductor_utils, 'set_node_cleaning_steps') 2382 @mock.patch.object(conductor_utils, 'set_node_cleaning_steps',
2383 autospec=True)
2351 @mock.patch('ironic.conductor.manager.ConductorManager.' 2384 @mock.patch('ironic.conductor.manager.ConductorManager.'
2352 '_do_next_clean_step') 2385 '_do_next_clean_step', autospec=True)
2353 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.prepare_cleaning') 2386 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.prepare_cleaning',
2354 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate') 2387 autospec=True)
2355 @mock.patch('ironic.drivers.modules.fake.FakeBIOS.cache_bios_settings') 2388 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate',
2389 autospec=True)
2390 @mock.patch('ironic.drivers.modules.fake.FakeBIOS.cache_bios_settings',
2391 autospec=True)
2356 def _test__do_node_clean_cache_bios(self, mock_bios, mock_validate, 2392 def _test__do_node_clean_cache_bios(self, mock_bios, mock_validate,
2357 mock_prep, mock_next_step, mock_steps, 2393 mock_prep, mock_next_step, mock_steps,
2358 mock_log, clean_steps=None, 2394 mock_log, clean_steps=None,
@@ -2368,20 +2404,20 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2368 with task_manager.acquire( 2404 with task_manager.acquire(
2369 self.context, node.uuid, shared=False) as task: 2405 self.context, node.uuid, shared=False) as task:
2370 self.service._do_node_clean(task, clean_steps=clean_steps) 2406 self.service._do_node_clean(task, clean_steps=clean_steps)
2371 node.refresh() 2407 node.refresh()
2372 mock_bios.assert_called_once_with(task) 2408 mock_bios.assert_called_once_with(mock.ANY, task)
2373 if clean_steps: 2409 if clean_steps:
2374 self.assertEqual(states.CLEANING, node.provision_state) 2410 self.assertEqual(states.CLEANING, node.provision_state)
2375 self.assertEqual(tgt_prov_state, node.target_provision_state) 2411 self.assertEqual(tgt_prov_state, node.target_provision_state)
2376 else: 2412 else:
2377 self.assertEqual(states.CLEANING, node.provision_state) 2413 self.assertEqual(states.CLEANING, node.provision_state)
2378 self.assertEqual(states.AVAILABLE, node.target_provision_state) 2414 self.assertEqual(states.AVAILABLE, node.target_provision_state)
2379 mock_validate.assert_called_once_with(task) 2415 mock_validate.assert_called_once_with(mock.ANY, task)
2380 if enable_exception: 2416 if enable_exception:
2381 mock_log.exception.assert_called_once_with( 2417 mock_log.exception.assert_called_once_with(
2382 'Caching of bios settings failed on node {}. ' 2418 'Caching of bios settings failed on node {}. '
2383 'Continuing with node cleaning.' 2419 'Continuing with node cleaning.'
2384 .format(node.uuid)) 2420 .format(node.uuid))
2385 2421
2386 def test__do_node_clean_manual_cache_bios(self): 2422 def test__do_node_clean_manual_cache_bios(self):
2387 self._test__do_node_clean_cache_bios(clean_steps=[self.deploy_raid]) 2423 self._test__do_node_clean_cache_bios(clean_steps=[self.deploy_raid])
@@ -2396,7 +2432,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2396 def test__do_node_clean_automated_cache_bios_exception(self): 2432 def test__do_node_clean_automated_cache_bios_exception(self):
2397 self._test__do_node_clean_cache_bios(enable_exception=True) 2433 self._test__do_node_clean_cache_bios(enable_exception=True)
2398 2434
2399 @mock.patch('ironic.drivers.modules.fake.FakePower.validate') 2435 @mock.patch('ironic.drivers.modules.fake.FakePower.validate',
2436 autospec=True)
2400 def test__do_node_clean_automated_disabled(self, mock_validate): 2437 def test__do_node_clean_automated_disabled(self, mock_validate):
2401 self.config(automated_clean=False, group='conductor') 2438 self.config(automated_clean=False, group='conductor')
2402 2439
@@ -2420,8 +2457,10 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2420 self.assertNotIn('clean_steps', node.driver_internal_info) 2457 self.assertNotIn('clean_steps', node.driver_internal_info)
2421 self.assertNotIn('clean_step_index', node.driver_internal_info) 2458 self.assertNotIn('clean_step_index', node.driver_internal_info)
2422 2459
2423 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate') 2460 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate',
2424 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.prepare_cleaning') 2461 autospec=True)
2462 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.prepare_cleaning',
2463 autospec=True)
2425 def __do_node_clean_prepare_clean_fail(self, mock_prep, mock_validate, 2464 def __do_node_clean_prepare_clean_fail(self, mock_prep, mock_validate,
2426 clean_steps=None): 2465 clean_steps=None):
2427 # Exception from task.driver.deploy.prepare_cleaning should cause node 2466 # Exception from task.driver.deploy.prepare_cleaning should cause node
@@ -2435,11 +2474,11 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2435 with task_manager.acquire( 2474 with task_manager.acquire(
2436 self.context, node.uuid, shared=False) as task: 2475 self.context, node.uuid, shared=False) as task:
2437 self.service._do_node_clean(task, clean_steps=clean_steps) 2476 self.service._do_node_clean(task, clean_steps=clean_steps)
2438 node.refresh() 2477 node.refresh()
2439 self.assertEqual(states.CLEANFAIL, node.provision_state) 2478 self.assertEqual(states.CLEANFAIL, node.provision_state)
2440 self.assertEqual(tgt_prov_state, node.target_provision_state) 2479 self.assertEqual(tgt_prov_state, node.target_provision_state)
2441 mock_prep.assert_called_once_with(mock.ANY) 2480 mock_prep.assert_called_once_with(mock.ANY, task)
2442 mock_validate.assert_called_once_with(task) 2481 mock_validate.assert_called_once_with(mock.ANY, task)
2443 2482
2444 def test__do_node_clean_automated_prepare_clean_fail(self): 2483 def test__do_node_clean_automated_prepare_clean_fail(self):
2445 self.__do_node_clean_prepare_clean_fail() 2484 self.__do_node_clean_prepare_clean_fail()
@@ -2447,8 +2486,10 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2447 def test__do_node_clean_manual_prepare_clean_fail(self): 2486 def test__do_node_clean_manual_prepare_clean_fail(self):
2448 self.__do_node_clean_prepare_clean_fail(clean_steps=[self.deploy_raid]) 2487 self.__do_node_clean_prepare_clean_fail(clean_steps=[self.deploy_raid])
2449 2488
2450 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate') 2489 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate',
2451 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.prepare_cleaning') 2490 autospec=True)
2491 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.prepare_cleaning',
2492 autospec=True)
2452 def __do_node_clean_prepare_clean_wait(self, mock_prep, mock_validate, 2493 def __do_node_clean_prepare_clean_wait(self, mock_prep, mock_validate,
2453 clean_steps=None): 2494 clean_steps=None):
2454 mock_prep.return_value = states.CLEANWAIT 2495 mock_prep.return_value = states.CLEANWAIT
@@ -2463,8 +2504,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2463 node.refresh() 2504 node.refresh()
2464 self.assertEqual(states.CLEANWAIT, node.provision_state) 2505 self.assertEqual(states.CLEANWAIT, node.provision_state)
2465 self.assertEqual(tgt_prov_state, node.target_provision_state) 2506 self.assertEqual(tgt_prov_state, node.target_provision_state)
2466 mock_prep.assert_called_once_with(mock.ANY) 2507 mock_prep.assert_called_once_with(mock.ANY, mock.ANY)
2467 mock_validate.assert_called_once_with(mock.ANY) 2508 mock_validate.assert_called_once_with(mock.ANY, mock.ANY)
2468 2509
2469 def test__do_node_clean_automated_prepare_clean_wait(self): 2510 def test__do_node_clean_automated_prepare_clean_wait(self):
2470 self.__do_node_clean_prepare_clean_wait() 2511 self.__do_node_clean_prepare_clean_wait()
@@ -2473,7 +2514,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2473 self.__do_node_clean_prepare_clean_wait(clean_steps=[self.deploy_raid]) 2514 self.__do_node_clean_prepare_clean_wait(clean_steps=[self.deploy_raid])
2474 2515
2475 @mock.patch.object(n_flat.FlatNetwork, 'validate', autospec=True) 2516 @mock.patch.object(n_flat.FlatNetwork, 'validate', autospec=True)
2476 @mock.patch.object(conductor_utils, 'set_node_cleaning_steps') 2517 @mock.patch.object(conductor_utils, 'set_node_cleaning_steps',
2518 autospec=True)
2477 def __do_node_clean_steps_fail(self, mock_steps, mock_validate, 2519 def __do_node_clean_steps_fail(self, mock_steps, mock_validate,
2478 clean_steps=None, invalid_exc=True): 2520 clean_steps=None, invalid_exc=True):
2479 if invalid_exc: 2521 if invalid_exc:
@@ -2504,11 +2546,14 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2504 self.__do_node_clean_steps_fail(clean_steps=[self.deploy_raid], 2546 self.__do_node_clean_steps_fail(clean_steps=[self.deploy_raid],
2505 invalid_exc=invalid) 2547 invalid_exc=invalid)
2506 2548
2507 @mock.patch.object(conductor_utils, 'set_node_cleaning_steps') 2549 @mock.patch.object(conductor_utils, 'set_node_cleaning_steps',
2550 autospec=True)
2508 @mock.patch('ironic.conductor.manager.ConductorManager.' 2551 @mock.patch('ironic.conductor.manager.ConductorManager.'
2509 '_do_next_clean_step') 2552 '_do_next_clean_step', autospec=True)
2510 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate') 2553 @mock.patch('ironic.drivers.modules.network.flat.FlatNetwork.validate',
2511 @mock.patch('ironic.drivers.modules.fake.FakePower.validate') 2554 autospec=True)
2555 @mock.patch('ironic.drivers.modules.fake.FakePower.validate',
2556 autospec=True)
2512 def __do_node_clean(self, mock_power_valid, mock_network_valid, 2557 def __do_node_clean(self, mock_power_valid, mock_network_valid,
2513 mock_next_step, mock_steps, clean_steps=None): 2558 mock_next_step, mock_steps, clean_steps=None):
2514 if clean_steps: 2559 if clean_steps:
@@ -2531,16 +2576,16 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2531 self.context, node.uuid, shared=False) as task: 2576 self.context, node.uuid, shared=False) as task:
2532 self.service._do_node_clean(task, clean_steps=clean_steps) 2577 self.service._do_node_clean(task, clean_steps=clean_steps)
2533 2578
2534 self._stop_service() 2579 self._stop_service()
2535 node.refresh() 2580 node.refresh()
2536 2581
2537 mock_power_valid.assert_called_once_with(task) 2582 mock_power_valid.assert_called_once_with(mock.ANY, task)
2538 mock_network_valid.assert_called_once_with(task) 2583 mock_network_valid.assert_called_once_with(mock.ANY, task)
2539 mock_next_step.assert_called_once_with(mock.ANY, 0) 2584 mock_next_step.assert_called_once_with(mock.ANY, task, 0)
2540 mock_steps.assert_called_once_with(task) 2585 mock_steps.assert_called_once_with(task)
2541 if clean_steps: 2586 if clean_steps:
2542 self.assertEqual(clean_steps, 2587 self.assertEqual(clean_steps,
2543 node.driver_internal_info['clean_steps']) 2588 node.driver_internal_info['clean_steps'])
2544 2589
2545 # Check that state didn't change 2590 # Check that state didn't change
2546 self.assertEqual(states.CLEANING, node.provision_state) 2591 self.assertEqual(states.CLEANING, node.provision_state)
@@ -2552,7 +2597,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2552 def test__do_node_clean_manual(self): 2597 def test__do_node_clean_manual(self):
2553 self.__do_node_clean(clean_steps=[self.deploy_raid]) 2598 self.__do_node_clean(clean_steps=[self.deploy_raid])
2554 2599
2555 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.execute_clean_step') 2600 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.execute_clean_step',
2601 autospec=True)
2556 def _do_next_clean_step_first_step_async(self, return_state, mock_execute, 2602 def _do_next_clean_step_first_step_async(self, return_state, mock_execute,
2557 clean_steps=None): 2603 clean_steps=None):
2558 # Execute the first async clean step on a node 2604 # Execute the first async clean step on a node
@@ -2587,7 +2633,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2587 self.assertEqual(tgt_prov_state, node.target_provision_state) 2633 self.assertEqual(tgt_prov_state, node.target_provision_state)
2588 self.assertEqual(expected_first_step, node.clean_step) 2634 self.assertEqual(expected_first_step, node.clean_step)
2589 self.assertEqual(0, node.driver_internal_info['clean_step_index']) 2635 self.assertEqual(0, node.driver_internal_info['clean_step_index'])
2590 mock_execute.assert_called_once_with(mock.ANY, expected_first_step) 2636 mock_execute.assert_called_once_with(
2637 mock.ANY, mock.ANY, expected_first_step)
2591 2638
2592 def test_do_next_clean_step_automated_first_step_async(self): 2639 def test_do_next_clean_step_automated_first_step_async(self):
2593 self._do_next_clean_step_first_step_async(states.CLEANWAIT) 2640 self._do_next_clean_step_first_step_async(states.CLEANWAIT)
@@ -2596,7 +2643,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2596 self._do_next_clean_step_first_step_async( 2643 self._do_next_clean_step_first_step_async(
2597 states.CLEANWAIT, clean_steps=[self.deploy_raid]) 2644 states.CLEANWAIT, clean_steps=[self.deploy_raid])
2598 2645
2599 @mock.patch('ironic.drivers.modules.fake.FakePower.execute_clean_step') 2646 @mock.patch('ironic.drivers.modules.fake.FakePower.execute_clean_step',
2647 autospec=True)
2600 def _do_next_clean_step_continue_from_last_cleaning(self, return_state, 2648 def _do_next_clean_step_continue_from_last_cleaning(self, return_state,
2601 mock_execute, 2649 mock_execute,
2602 manual=False): 2650 manual=False):
@@ -2625,7 +2673,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2625 self.assertEqual(tgt_prov_state, node.target_provision_state) 2673 self.assertEqual(tgt_prov_state, node.target_provision_state)
2626 self.assertEqual(self.clean_steps[1], node.clean_step) 2674 self.assertEqual(self.clean_steps[1], node.clean_step)
2627 self.assertEqual(1, node.driver_internal_info['clean_step_index']) 2675 self.assertEqual(1, node.driver_internal_info['clean_step_index'])
2628 mock_execute.assert_called_once_with(mock.ANY, self.clean_steps[1]) 2676 mock_execute.assert_called_once_with(
2677 mock.ANY, mock.ANY, self.clean_steps[1])
2629 2678
2630 def test_do_next_clean_step_continue_from_last_cleaning(self): 2679 def test_do_next_clean_step_continue_from_last_cleaning(self):
2631 self._do_next_clean_step_continue_from_last_cleaning(states.CLEANWAIT) 2680 self._do_next_clean_step_continue_from_last_cleaning(states.CLEANWAIT)
@@ -2634,7 +2683,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2634 self._do_next_clean_step_continue_from_last_cleaning(states.CLEANWAIT, 2683 self._do_next_clean_step_continue_from_last_cleaning(states.CLEANWAIT,
2635 manual=True) 2684 manual=True)
2636 2685
2637 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.execute_clean_step') 2686 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.execute_clean_step',
2687 autospec=True)
2638 def _do_next_clean_step_last_step_noop(self, mock_execute, manual=False): 2688 def _do_next_clean_step_last_step_noop(self, mock_execute, manual=False):
2639 # Resume where last_step is the last cleaning step, should be noop 2689 # Resume where last_step is the last cleaning step, should be noop
2640 tgt_prov_state = states.MANAGEABLE if manual else states.AVAILABLE 2690 tgt_prov_state = states.MANAGEABLE if manual else states.AVAILABLE
@@ -2671,8 +2721,10 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2671 def test__do_next_clean_step_manual_last_step_noop(self): 2721 def test__do_next_clean_step_manual_last_step_noop(self):
2672 self._do_next_clean_step_last_step_noop(manual=True) 2722 self._do_next_clean_step_last_step_noop(manual=True)
2673 2723
2674 @mock.patch('ironic.drivers.modules.fake.FakePower.execute_clean_step') 2724 @mock.patch('ironic.drivers.modules.fake.FakePower.execute_clean_step',
2675 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.execute_clean_step') 2725 autospec=True)
2726 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.execute_clean_step',
2727 autospec=True)
2676 def _do_next_clean_step_all(self, mock_deploy_execute, 2728 def _do_next_clean_step_all(self, mock_deploy_execute,
2677 mock_power_execute, manual=False): 2729 mock_power_execute, manual=False):
2678 # Run all steps from start to finish (all synchronous) 2730 # Run all steps from start to finish (all synchronous)
@@ -2703,12 +2755,11 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2703 self.assertEqual({}, node.clean_step) 2755 self.assertEqual({}, node.clean_step)
2704 self.assertNotIn('clean_step_index', node.driver_internal_info) 2756 self.assertNotIn('clean_step_index', node.driver_internal_info)
2705 self.assertIsNone(node.driver_internal_info['clean_steps']) 2757 self.assertIsNone(node.driver_internal_info['clean_steps'])
2706 mock_power_execute.assert_called_once_with(mock.ANY, 2758 mock_power_execute.assert_called_once_with(mock.ANY, mock.ANY,
2707 self.clean_steps[1]) 2759 self.clean_steps[1])
2708 mock_deploy_execute.assert_has_calls = [ 2760 mock_deploy_execute.assert_has_calls(
2709 mock.call(self.clean_steps[0]), 2761 [mock.call(mock.ANY, mock.ANY, self.clean_steps[0]),
2710 mock.call(self.clean_steps[2]) 2762 mock.call(mock.ANY, mock.ANY, self.clean_steps[2])])
2711 ]
2712 2763
2713 def test_do_next_clean_step_automated_all(self): 2764 def test_do_next_clean_step_automated_all(self):
2714 self._do_next_clean_step_all() 2765 self._do_next_clean_step_all()
@@ -2716,7 +2767,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2716 def test_do_next_clean_step_manual_all(self): 2767 def test_do_next_clean_step_manual_all(self):
2717 self._do_next_clean_step_all(manual=True) 2768 self._do_next_clean_step_all(manual=True)
2718 2769
2719 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.execute_clean_step') 2770 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.execute_clean_step',
2771 autospec=True)
2720 @mock.patch.object(fake.FakeDeploy, 'tear_down_cleaning', autospec=True) 2772 @mock.patch.object(fake.FakeDeploy, 'tear_down_cleaning', autospec=True)
2721 def _do_next_clean_step_execute_fail(self, tear_mock, mock_execute, 2773 def _do_next_clean_step_execute_fail(self, tear_mock, mock_execute,
2722 manual=False): 2774 manual=False):
@@ -2749,7 +2801,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2749 self.assertNotIn('clean_step_index', node.driver_internal_info) 2801 self.assertNotIn('clean_step_index', node.driver_internal_info)
2750 self.assertIsNotNone(node.last_error) 2802 self.assertIsNotNone(node.last_error)
2751 self.assertTrue(node.maintenance) 2803 self.assertTrue(node.maintenance)
2752 mock_execute.assert_called_once_with(mock.ANY, self.clean_steps[0]) 2804 mock_execute.assert_called_once_with(
2805 mock.ANY, mock.ANY, self.clean_steps[0])
2753 2806
2754 def test__do_next_clean_step_automated_execute_fail(self): 2807 def test__do_next_clean_step_automated_execute_fail(self):
2755 self._do_next_clean_step_execute_fail() 2808 self._do_next_clean_step_execute_fail()
@@ -2817,7 +2870,8 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2817 def test__do_next_clean_step_manual_fail_in_tear_down_cleaning(self): 2870 def test__do_next_clean_step_manual_fail_in_tear_down_cleaning(self):
2818 self._do_next_clean_step_fail_in_tear_down_cleaning(manual=True) 2871 self._do_next_clean_step_fail_in_tear_down_cleaning(manual=True)
2819 2872
2820 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.execute_clean_step') 2873 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.execute_clean_step',
2874 autospec=True)
2821 def _do_next_clean_step_no_steps(self, mock_execute, manual=False): 2875 def _do_next_clean_step_no_steps(self, mock_execute, manual=False):
2822 2876
2823 for info in ({'clean_steps': None, 'clean_step_index': None}, 2877 for info in ({'clean_steps': None, 'clean_step_index': None},
@@ -2856,8 +2910,10 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2856 def test__do_next_clean_step_manual_no_steps(self): 2910 def test__do_next_clean_step_manual_no_steps(self):
2857 self._do_next_clean_step_no_steps(manual=True) 2911 self._do_next_clean_step_no_steps(manual=True)
2858 2912
2859 @mock.patch('ironic.drivers.modules.fake.FakePower.execute_clean_step') 2913 @mock.patch('ironic.drivers.modules.fake.FakePower.execute_clean_step',
2860 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.execute_clean_step') 2914 autospec=True)
2915 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.execute_clean_step',
2916 autospec=True)
2861 def _do_next_clean_step_bad_step_return_value( 2917 def _do_next_clean_step_bad_step_return_value(
2862 self, deploy_exec_mock, power_exec_mock, manual=False): 2918 self, deploy_exec_mock, power_exec_mock, manual=False):
2863 # When a clean step fails, go to CLEANFAIL 2919 # When a clean step fails, go to CLEANFAIL
@@ -2888,7 +2944,7 @@ class DoNodeCleanTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
2888 self.assertNotIn('clean_step_index', node.driver_internal_info) 2944 self.assertNotIn('clean_step_index', node.driver_internal_info)
2889 self.assertIsNotNone(node.last_error) 2945 self.assertIsNotNone(node.last_error)
2890 self.assertTrue(node.maintenance) 2946 self.assertTrue(node.maintenance)
2891 deploy_exec_mock.assert_called_once_with(mock.ANY, 2947 deploy_exec_mock.assert_called_once_with(mock.ANY, mock.ANY,
2892 self.clean_steps[0]) 2948 self.clean_steps[0])
2893 # Make sure we don't execute any other step and return 2949 # Make sure we don't execute any other step and return
2894 self.assertFalse(power_exec_mock.called) 2950 self.assertFalse(power_exec_mock.called)
@@ -3201,7 +3257,8 @@ class DoNodeRescueTestCase(mgr_utils.CommonMixIn, mgr_utils.ServiceSetUpMixin,
3201 self.assertTrue('Driver returned unexpected state' in 3257 self.assertTrue('Driver returned unexpected state' in
3202 node.last_error) 3258 node.last_error)
3203 3259
3204 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 3260 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
3261 autospec=True)
3205 def test_provision_rescue_abort(self, mock_spawn): 3262 def test_provision_rescue_abort(self, mock_spawn):
3206 node = obj_utils.create_test_node( 3263 node = obj_utils.create_test_node(
3207 self.context, driver='fake-hardware', 3264 self.context, driver='fake-hardware',
@@ -3214,8 +3271,8 @@ class DoNodeRescueTestCase(mgr_utils.CommonMixIn, mgr_utils.ServiceSetUpMixin,
3214 self.assertEqual(states.RESCUEFAIL, node.provision_state) 3271 self.assertEqual(states.RESCUEFAIL, node.provision_state)
3215 self.assertIsNone(node.last_error) 3272 self.assertIsNone(node.last_error)
3216 self.assertNotIn('rescue_password', node.instance_info) 3273 self.assertNotIn('rescue_password', node.instance_info)
3217 mock_spawn.assert_called_with(self.service._do_node_rescue_abort, 3274 mock_spawn.assert_called_with(
3218 mock.ANY) 3275 self.service, self.service._do_node_rescue_abort, mock.ANY)
3219 3276
3220 @mock.patch.object(fake.FakeRescue, 'clean_up', autospec=True) 3277 @mock.patch.object(fake.FakeRescue, 'clean_up', autospec=True)
3221 def test__do_node_rescue_abort(self, clean_up_mock): 3278 def test__do_node_rescue_abort(self, clean_up_mock):
@@ -4166,7 +4223,8 @@ class SensorsTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
4166 self.assertFalse(get_sensors_data_mock.called) 4223 self.assertFalse(get_sensors_data_mock.called)
4167 self.assertTrue(debug_log.called) 4224 self.assertTrue(debug_log.called)
4168 4225
4169 @mock.patch.object(manager.ConductorManager, '_spawn_worker') 4226 @mock.patch.object(manager.ConductorManager, '_spawn_worker',
4227 autospec=True)
4170 @mock.patch.object(manager.ConductorManager, '_mapped_to_this_conductor') 4228 @mock.patch.object(manager.ConductorManager, '_mapped_to_this_conductor')
4171 @mock.patch.object(dbapi.IMPL, 'get_nodeinfo_list') 4229 @mock.patch.object(dbapi.IMPL, 'get_nodeinfo_list')
4172 def test___send_sensor_data(self, get_nodeinfo_list_mock, 4230 def test___send_sensor_data(self, get_nodeinfo_list_mock,
@@ -4181,11 +4239,12 @@ class SensorsTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
4181 _mapped_to_this_conductor_mock.return_value = True 4239 _mapped_to_this_conductor_mock.return_value = True
4182 get_nodeinfo_list_mock.return_value = [('fake_uuid', 'fake', None)] 4240 get_nodeinfo_list_mock.return_value = [('fake_uuid', 'fake', None)]
4183 self.service._send_sensor_data(self.context) 4241 self.service._send_sensor_data(self.context)
4184 mock_spawn.assert_called_with(self.service._sensors_nodes_task, 4242 mock_spawn.assert_called_with(self.service,
4185 self.context, 4243 self.service._sensors_nodes_task,
4186 mock.ANY) 4244 self.context, mock.ANY)
4187 4245
4188 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 4246 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
4247 autospec=True)
4189 @mock.patch.object(manager.ConductorManager, '_mapped_to_this_conductor') 4248 @mock.patch.object(manager.ConductorManager, '_mapped_to_this_conductor')
4190 @mock.patch.object(dbapi.IMPL, 'get_nodeinfo_list') 4249 @mock.patch.object(dbapi.IMPL, 'get_nodeinfo_list')
4191 def test___send_sensor_data_multiple_workers( 4250 def test___send_sensor_data_multiple_workers(
@@ -6013,7 +6072,8 @@ class NodeInspectHardware(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
6013 self.assertEqual(states.MANAGEABLE, node.target_provision_state) 6072 self.assertEqual(states.MANAGEABLE, node.target_provision_state)
6014 self.assertIsNotNone(node.last_error) 6073 self.assertIsNotNone(node.last_error)
6015 6074
6016 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 6075 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
6076 autospec=True)
6017 def test_inspect_hardware_worker_pool_full(self, mock_spawn): 6077 def test_inspect_hardware_worker_pool_full(self, mock_spawn):
6018 prv_state = states.MANAGEABLE 6078 prv_state = states.MANAGEABLE
6019 tgt_prv_state = states.NOSTATE 6079 tgt_prv_state = states.NOSTATE
@@ -6802,7 +6862,8 @@ class DoNodeAdoptionTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
6802 self.assertFalse(mock_start_console.called) 6862 self.assertFalse(mock_start_console.called)
6803 self.assertTrue(mock_boot_validate.called) 6863 self.assertTrue(mock_boot_validate.called)
6804 6864
6805 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 6865 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
6866 autospec=True)
6806 def test_do_provisioning_action_adopt_node(self, mock_spawn): 6867 def test_do_provisioning_action_adopt_node(self, mock_spawn):
6807 """Test an adoption request results in the node in ADOPTING""" 6868 """Test an adoption request results in the node in ADOPTING"""
6808 node = obj_utils.create_test_node( 6869 node = obj_utils.create_test_node(
@@ -6816,9 +6877,11 @@ class DoNodeAdoptionTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
6816 self.assertEqual(states.ADOPTING, node.provision_state) 6877 self.assertEqual(states.ADOPTING, node.provision_state)
6817 self.assertEqual(states.ACTIVE, node.target_provision_state) 6878 self.assertEqual(states.ACTIVE, node.target_provision_state)
6818 self.assertIsNone(node.last_error) 6879 self.assertIsNone(node.last_error)
6819 mock_spawn.assert_called_with(self.service._do_adoption, mock.ANY) 6880 mock_spawn.assert_called_with(self.service,
6881 self.service._do_adoption, mock.ANY)
6820 6882
6821 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 6883 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
6884 autospec=True)
6822 def test_do_provisioning_action_adopt_node_retry(self, mock_spawn): 6885 def test_do_provisioning_action_adopt_node_retry(self, mock_spawn):
6823 """Test a retried adoption from ADOPTFAIL results in ADOPTING state""" 6886 """Test a retried adoption from ADOPTFAIL results in ADOPTING state"""
6824 node = obj_utils.create_test_node( 6887 node = obj_utils.create_test_node(
@@ -6832,7 +6895,8 @@ class DoNodeAdoptionTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
6832 self.assertEqual(states.ADOPTING, node.provision_state) 6895 self.assertEqual(states.ADOPTING, node.provision_state)
6833 self.assertEqual(states.ACTIVE, node.target_provision_state) 6896 self.assertEqual(states.ACTIVE, node.target_provision_state)
6834 self.assertIsNone(node.last_error) 6897 self.assertIsNone(node.last_error)
6835 mock_spawn.assert_called_with(self.service._do_adoption, mock.ANY) 6898 mock_spawn.assert_called_with(self.service,
6899 self.service._do_adoption, mock.ANY)
6836 6900
6837 def test_do_provisioning_action_manage_of_failed_adoption(self): 6901 def test_do_provisioning_action_manage_of_failed_adoption(self):
6838 """Test a node in ADOPTFAIL can be taken to MANAGEABLE""" 6902 """Test a node in ADOPTFAIL can be taken to MANAGEABLE"""
@@ -6849,8 +6913,10 @@ class DoNodeAdoptionTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
6849 self.assertEqual(states.NOSTATE, node.target_provision_state) 6913 self.assertEqual(states.NOSTATE, node.target_provision_state)
6850 self.assertIsNone(node.last_error) 6914 self.assertIsNone(node.last_error)
6851 6915
6852 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.heartbeat') 6916 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.heartbeat',
6853 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 6917 autospec=True)
6918 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
6919 autospec=True)
6854 def test_heartbeat(self, mock_spawn, mock_heartbeat): 6920 def test_heartbeat(self, mock_spawn, mock_heartbeat):
6855 """Test heartbeating.""" 6921 """Test heartbeating."""
6856 node = obj_utils.create_test_node( 6922 node = obj_utils.create_test_node(
@@ -6862,16 +6928,19 @@ class DoNodeAdoptionTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
6862 6928
6863 mock_spawn.reset_mock() 6929 mock_spawn.reset_mock()
6864 6930
6865 def fake_spawn(func, *args, **kwargs): 6931 def fake_spawn(conductor_obj, func, *args, **kwargs):
6866 func(*args, **kwargs) 6932 func(*args, **kwargs)
6867 return mock.MagicMock() 6933 return mock.MagicMock()
6868 mock_spawn.side_effect = fake_spawn 6934 mock_spawn.side_effect = fake_spawn
6869 6935
6870 self.service.heartbeat(self.context, node.uuid, 'http://callback') 6936 self.service.heartbeat(self.context, node.uuid, 'http://callback')
6871 mock_heartbeat.assert_called_with(mock.ANY, 'http://callback', '3.0.0') 6937 mock_heartbeat.assert_called_with(mock.ANY, mock.ANY,
6938 'http://callback', '3.0.0')
6872 6939
6873 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.heartbeat') 6940 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.heartbeat',
6874 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 6941 autospec=True)
6942 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
6943 autospec=True)
6875 def test_heartbeat_agent_version(self, mock_spawn, mock_heartbeat): 6944 def test_heartbeat_agent_version(self, mock_spawn, mock_heartbeat):
6876 """Test heartbeating.""" 6945 """Test heartbeating."""
6877 node = obj_utils.create_test_node( 6946 node = obj_utils.create_test_node(
@@ -6883,18 +6952,23 @@ class DoNodeAdoptionTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
6883 6952
6884 mock_spawn.reset_mock() 6953 mock_spawn.reset_mock()
6885 6954
6886 def fake_spawn(func, *args, **kwargs): 6955 def fake_spawn(conductor_obj, func, *args, **kwargs):
6887 func(*args, **kwargs) 6956 func(*args, **kwargs)
6888 return mock.MagicMock() 6957 return mock.MagicMock()
6889 mock_spawn.side_effect = fake_spawn 6958 mock_spawn.side_effect = fake_spawn
6890 6959
6891 self.service.heartbeat( 6960 self.service.heartbeat(
6892 self.context, node.uuid, 'http://callback', '1.4.1') 6961 self.context, node.uuid, 'http://callback', '1.4.1')
6893 mock_heartbeat.assert_called_with(mock.ANY, 'http://callback', '1.4.1') 6962 mock_heartbeat.assert_called_with(mock.ANY, mock.ANY,
6963 'http://callback', '1.4.1')
6894 6964
6965 # NOTE(rloo): We cannot use autospec=True for FakeDeploy.heartbeat
6966 # since we are testing whether our code makes a call to the old
6967 # .heartbeat method that doesn't support 'agent_version' parameter.
6895 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.heartbeat') 6968 @mock.patch('ironic.drivers.modules.fake.FakeDeploy.heartbeat')
6896 @mock.patch.object(manager, 'LOG', autospec=True) 6969 @mock.patch.object(manager, 'LOG', autospec=True)
6897 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker') 6970 @mock.patch('ironic.conductor.manager.ConductorManager._spawn_worker',
6971 autospec=True)
6898 def test_heartbeat_agent_version_deprecated(self, mock_spawn, log_mock, 6972 def test_heartbeat_agent_version_deprecated(self, mock_spawn, log_mock,
6899 mock_heartbeat): 6973 mock_heartbeat):
6900 """Test heartbeating.""" 6974 """Test heartbeating."""
@@ -6907,7 +6981,7 @@ class DoNodeAdoptionTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
6907 6981
6908 mock_spawn.reset_mock() 6982 mock_spawn.reset_mock()
6909 6983
6910 def fake_spawn(func, *args, **kwargs): 6984 def fake_spawn(conductor_obj, func, *args, **kwargs):
6911 func(*args, **kwargs) 6985 func(*args, **kwargs)
6912 return mock.MagicMock() 6986 return mock.MagicMock()
6913 mock_spawn.side_effect = fake_spawn 6987 mock_spawn.side_effect = fake_spawn