def test_create(self, mock_vm_crt, mock_stg, mock_bld, mock_ftsk): nvram_mgr = mock.Mock() nvram_mgr.fetch.return_value = 'data' mock_ftsk.name = 'vio_feed_task' lpar_entry = mock.Mock() # Test create with normal (non-recreate) ftsk crt = tf_vm.Create(self.apt, 'host_wrapper', self.instance, stg_ftsk=mock_ftsk, nvram_mgr=nvram_mgr, slot_mgr='slot_mgr') mock_vm_crt.return_value = lpar_entry crt_entry = crt.execute() mock_ftsk.execute.assert_not_called() mock_vm_crt.assert_called_once_with(self.apt, 'host_wrapper', self.instance, nvram='data', slot_mgr='slot_mgr') self.assertEqual(lpar_entry, crt_entry) nvram_mgr.fetch.assert_called_once_with(self.instance) mock_ftsk.name = 'create_scrubber' mock_bld.return_value = mock_ftsk # Test create with recreate ftsk rcrt = tf_vm.Create(self.apt, 'host_wrapper', self.instance, stg_ftsk=None, nvram_mgr=nvram_mgr, slot_mgr='slot_mgr') mock_bld.assert_called_once_with( self.apt, name='create_scrubber', xag={pvmc.XAG.VIO_SMAP, pvmc.XAG.VIO_FMAP}) rcrt.execute() mock_ftsk.execute.assert_called_once_with() # Validate args on taskflow.task.Task instantiation with mock.patch('taskflow.task.Task.__init__') as tf: tf_vm.Create(self.apt, 'host_wrapper', self.instance) tf.assert_called_once_with(name='crt_vm', provides='lpar_wrap')
def test_create(self, mock_vm_crt, mock_stg, mock_bld, mock_ftsk): nvram_mgr = mock.Mock() nvram_mgr.fetch.return_value = 'data' lpar_entry = mock.Mock() # Test create with normal (non-recreate) ftsk crt = tf_vm.Create(self.apt, 'host_wrapper', self.instance, 'flavor', mock_ftsk, nvram_mgr=nvram_mgr, slot_mgr='slot_mgr') mock_vm_crt.return_value = lpar_entry crt_entry = crt.execute() mock_ftsk.execute.assert_not_called() mock_vm_crt.assert_called_once_with(self.apt, 'host_wrapper', self.instance, 'flavor', nvram='data', slot_mgr='slot_mgr') self.assertEqual(lpar_entry, crt_entry) nvram_mgr.fetch.assert_called_once_with(self.instance) mock_ftsk.name = 'create_scrubber' mock_bld.return_value = mock_ftsk # Test create with recreate ftsk rcrt = tf_vm.Create(self.apt, 'host_wrapper', self.instance, 'flavor', None, nvram_mgr=nvram_mgr, slot_mgr='slot_mgr') mock_bld.assert_called_once_with( self.apt, name='create_scrubber', xag={pvmc.XAG.VIO_SMAP, pvmc.XAG.VIO_FMAP}) rcrt.execute() mock_ftsk.execute.assert_called_once_with()
def test_create_revert(self, mock_vm_dlt, mock_crt_exc, mock_get_pvm_uuid): mock_crt_exc.side_effect = exception.NovaException() crt = tf_vm.Create(self.apt, 'host_wrapper', self.instance, 'stg_ftsk', None) # Assert that a failure while building does not revert crt.instance.task_state = task_states.SPAWNING flow_test = tf_lf.Flow("test_revert") flow_test.add(crt) self.assertRaises(exception.NovaException, tf_eng.run, flow_test) self.assertEqual(0, mock_vm_dlt.call_count) # Assert that a failure when rebuild results in revert crt.instance.task_state = task_states.REBUILD_SPAWNING flow_test = tf_lf.Flow("test_revert") flow_test.add(crt) self.assertRaises(exception.NovaException, tf_eng.run, flow_test) self.assertEqual(1, mock_vm_dlt.call_count)