def test_delete_volume(self): """ Test if it deletes a gluster volume. """ mock_info = MagicMock(return_value={"Newvolume1": {"status": "1"}}) with patch.object(glusterfs, "info", mock_info): # volume doesn't exist self.assertFalse(glusterfs.delete_volume("Newvolume3")) mock_stop_volume = MagicMock(return_value=True) mock_run = MagicMock(return_value=xml_command_success) with patch.dict(glusterfs.__salt__, {"cmd.run": mock_run}): with patch.object(glusterfs, "stop_volume", mock_stop_volume): # volume exists, should not be stopped, and is started self.assertFalse( glusterfs.delete_volume("Newvolume1", False)) self.assertFalse(mock_run.called) self.assertFalse(mock_stop_volume.called) # volume exists, should be stopped, and is started self.assertTrue(glusterfs.delete_volume("Newvolume1")) self.assertTrue(mock_run.called) self.assertTrue(mock_stop_volume.called) # volume exists and isn't started mock_info = MagicMock(return_value={"Newvolume1": {"status": "2"}}) with patch.object(glusterfs, "info", mock_info): mock_run = MagicMock(return_value=xml_command_success) with patch.dict(glusterfs.__salt__, {"cmd.run": mock_run}): self.assertTrue(glusterfs.delete_volume("Newvolume1")) mock_run.return_value = xml_command_fail self.assertFalse(glusterfs.delete_volume("Newvolume1"))
def test_delete_volume(self): ''' Test if it deletes a gluster volume. ''' mock_info = MagicMock(return_value={'Newvolume1': {'status': '1'}}) with patch.object(glusterfs, 'info', mock_info): # volume doesn't exist self.assertFalse(glusterfs.delete_volume('Newvolume3')) mock_stop_volume = MagicMock(return_value=True) mock_run = MagicMock(return_value=xml_command_success) with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}): with patch.object(glusterfs, 'stop_volume', mock_stop_volume): # volume exists, should not be stopped, and is started self.assertFalse( glusterfs.delete_volume('Newvolume1', False)) self.assertFalse(mock_run.called) self.assertFalse(mock_stop_volume.called) # volume exists, should be stopped, and is started self.assertTrue(glusterfs.delete_volume('Newvolume1')) self.assertTrue(mock_run.called) self.assertTrue(mock_stop_volume.called) # volume exists and isn't started mock_info = MagicMock(return_value={'Newvolume1': {'status': '2'}}) with patch.object(glusterfs, 'info', mock_info): mock_run = MagicMock(return_value=xml_command_success) with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}): self.assertTrue(glusterfs.delete_volume('Newvolume1')) mock_run.return_value = xml_command_fail self.assertFalse(glusterfs.delete_volume('Newvolume1'))
def test_delete_volume(self): ''' Test if it deletes a gluster volume. ''' mock_info = MagicMock(return_value={'Newvolume1': {'status': '1'}}) with patch.object(glusterfs, 'info', mock_info): # volume doesn't exist self.assertFalse(glusterfs.delete_volume('Newvolume3')) mock_stop_volume = MagicMock(return_value=True) mock_run = MagicMock(return_value=xml_command_success) with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}): with patch.object(glusterfs, 'stop_volume', mock_stop_volume): # volume exists, should not be stopped, and is started self.assertFalse(glusterfs.delete_volume('Newvolume1', False)) self.assertFalse(mock_run.called) self.assertFalse(mock_stop_volume.called) # volume exists, should be stopped, and is started self.assertTrue(glusterfs.delete_volume('Newvolume1')) self.assertTrue(mock_run.called) self.assertTrue(mock_stop_volume.called) # volume exists and isn't started mock_info = MagicMock(return_value={'Newvolume1': {'status': '2'}}) with patch.object(glusterfs, 'info', mock_info): mock_run = MagicMock(return_value=xml_command_success) with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}): self.assertTrue(glusterfs.delete_volume('Newvolume1')) mock_run.return_value = xml_command_fail self.assertFalse(glusterfs.delete_volume('Newvolume1'))