def test_find_best_non_leaf_coalesce_parent_coalescing(self, mocklock, mocklog, mockMetabase): # Setup the mocks callbacks = mock.MagicMock() mockDB = mock.MagicMock() mockMetabase.return_value = mockDB mockDB.write_context.side_effect = test_context mockDB.find_non_leaf_coalesceable.return_value = [ VHD( 3, 2, 0, 10*1024, 10*1024 ) ] callbacks.volumeTryLock.side_effect = [ None ] # Call the method child, parent = coalesce.find_best_non_leaf_coalesceable_2("test-uri", callbacks) # Check the result self.assertEquals((None, None), (child, parent)) # Check the calls callbacks.volumeStartOperations.assert_called_with("test-uri", 'w') callbacks.volumeStopOperations.assert_called() callbacks.volumeTryLock.assert_has_call(mock.ANY, "vhd-2.lock") self.assertEquals(1, callbacks.volumeTryLock.call_count) callbacks.volumeUnlock.assert_not_called() mockDB.write_context.assert_not_called() mockDB.update_vhd_gc_status.assert_not_called()
def test_find_best_non_leaf_coalesce_one_coalescing_success(self, mocklock, mocklog, mockMetabase): # Setup the mocks callbacks = mock.MagicMock() mockDB = mock.MagicMock() mockMetabase.return_value = mockDB mockDB.write_context.side_effect = test_context mockDB.find_non_leaf_coalesceable.return_value = [ VHD( 3, 2, 0, 10*1024, 10*1024), VHD( 5, 4, 0, 10*1024, 10*1024 ) ] mockDB.get_vhd_by_id.side_effect = [ VHD( 4, 1, 0, 10*1024, 10*1024 ) ] parent_lock = mock.MagicMock() callbacks.volumeTryLock.side_effect = [ parent_lock, None, mock.MagicMock(), mock.MagicMock() ] # Call the method child, parent = coalesce.find_best_non_leaf_coalesceable_2("test-uri", callbacks) # Check the result self.assertEquals(5, child.vhd.id) self.assertEquals(4, parent.vhd.id) # Check the calls callbacks.volumeStartOperations.assert_called_with("test-uri", 'w') callbacks.volumeStopOperations.assert_called() callbacks.volumeTryLock.assert_has_calls( [ mock.call(mock.ANY, "vhd-2.lock"), mock.call(mock.ANY, "vhd-3.lock"), mock.call(mock.ANY, "vhd-5.lock"), mock.call(mock.ANY, "vhd-4.lock"), ], any_order=True) self.assertEquals(4, callbacks.volumeTryLock.call_count) callbacks.volumeUnlock.assert_has_call(mock.call(mock.ANY, parent_lock)) self.assertEquals(1, callbacks.volumeUnlock.call_count) mockDB.write_context.assert_called() mockDB.get_vhd_by_id.assert_called() mockDB.update_vhd_gc_status.assert_not_called()
def test_find_best_non_leaf_coalesce_no_results(self, mocklock, mocklog, mockMetabase): # Setup the mocks callbacks = mock.MagicMock() mockDB = mock.MagicMock() mockMetabase.return_value = mockDB mockDB.find_non_leaf_coalesceable.return_value = [] # Call the method child, parent = coalesce.find_best_non_leaf_coalesceable_2("test-uri", callbacks) # Check the result self.assertEquals((None, None), (child, parent)) # Check the calls callbacks.volumeStartOperations.assert_called_with("test-uri", 'w') callbacks.volumeStopOperations.assert_called() mockDB.write_context.assert_not_called() mockDB.update_vhd_gc_status.assert_not_called()