def test_add_volume_bricks(self): ''' Test to add brick(s) to an existing volume ''' name = 'salt' bricks = {'bricks': {'host1': '/srv/gluster/drive1'}} ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=['does not exist', 'is not started', bricks, bricks, bricks, '']) mock_t = MagicMock(side_effect=['bricks successfully added', 'Bricks already in volume', '']) with patch.dict(glusterfs.__salt__, {'glusterfs.status': mock, 'glusterfs.add_volume_bricks': mock_t}): ret.update({'comment': 'does not exist'}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret) ret.update({'comment': 'is not started'}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret) ret.update({'comment': 'bricks successfully added', 'result': True, 'changes': {'new': ['host1'], 'old': ['host1']}}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret) ret.update({'comment': 'Bricks already in volume', 'changes': {}}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret) ret.update({'comment': '', 'result': False}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret)
def test_add_volume_bricks(self): """ Test to add brick(s) to an existing volume """ name = "salt" bricks = ["host1:/drive1"] old_bricks = ["host1:/drive2"] ret = {"name": name, "result": False, "comment": "", "changes": {}} stopped_volinfo = {"salt": {"status": "0"}} volinfo = { "salt": {"status": "1", "bricks": {"brick1": {"path": old_bricks[0]}}} } new_volinfo = { "salt": { "status": "1", "bricks": { "brick1": {"path": old_bricks[0]}, "brick2": {"path": bricks[0]}, }, } } mock_info = MagicMock(return_value={}) mock_add = MagicMock(side_effect=[False, True]) with patch.dict( glusterfs.__salt__, {"glusterfs.info": mock_info, "glusterfs.add_volume_bricks": mock_add}, ): ret.update({"comment": "Volume salt does not exist"}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret) mock_info.return_value = stopped_volinfo ret.update({"comment": "Volume salt is not started"}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret) mock_info.return_value = volinfo ret.update({"comment": "Adding bricks to volume salt failed"}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret) ret.update({"result": True}) ret.update({"comment": "Bricks already added in volume salt"}) self.assertDictEqual(glusterfs.add_volume_bricks(name, old_bricks), ret) mock_info.side_effect = [volinfo, new_volinfo] ret.update( { "comment": "Bricks successfully added to volume salt", "changes": {"new": bricks + old_bricks, "old": old_bricks}, } ) # Let's sort ourselves because the test under python 3 sometimes fails # just because of the new changes list order result = glusterfs.add_volume_bricks(name, bricks) ret["changes"]["new"] = sorted(ret["changes"]["new"]) result["changes"]["new"] = sorted(result["changes"]["new"]) self.assertDictEqual(result, ret)
def test_add_volume_bricks(self): ''' Test to add brick(s) to an existing volume ''' name = 'salt' bricks = ['host1:/drive1'] old_bricks = ['host1:/drive2'] ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} stopped_volinfo = {'salt': {'status': '0'}} volinfo = { 'salt': { 'status': '1', 'bricks': {'brick1': {'path': old_bricks[0]}} } } new_volinfo = { 'salt': { 'status': '1', 'bricks': { 'brick1': {'path': old_bricks[0]}, 'brick2': {'path': bricks[0]} } } } mock_info = MagicMock(return_value={}) mock_add = MagicMock(side_effect=[False, True]) with patch.dict(glusterfs.__salt__, {'glusterfs.info': mock_info, 'glusterfs.add_volume_bricks': mock_add}): ret.update({'comment': 'Volume salt does not exist'}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret) mock_info.return_value = stopped_volinfo ret.update({'comment': 'Volume salt is not started'}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret) mock_info.return_value = volinfo ret.update({'comment': 'Adding bricks to volume salt failed'}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret) ret.update({'result': True}) ret.update({'comment': 'Bricks already added in volume salt'}) self.assertDictEqual(glusterfs.add_volume_bricks(name, old_bricks), ret) mock_info.side_effect = [volinfo, new_volinfo] ret.update({'comment': 'Bricks successfully added to volume salt', 'changes': {'new': bricks + old_bricks, 'old': old_bricks}}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret)
def test_add_volume_bricks(self): ''' Test to add brick(s) to an existing volume ''' name = 'salt' bricks = {'bricks': {'host1': '/srv/gluster/drive1'}} ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=[ 'does not exist', 'is not started', bricks, bricks, bricks, '' ]) mock_t = MagicMock(side_effect=[ 'bricks successfully added', 'Bricks already in volume', '' ]) with patch.dict(glusterfs.__salt__, { 'glusterfs.status': mock, 'glusterfs.add_volume_bricks': mock_t }): ret.update({'comment': 'does not exist'}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret) ret.update({'comment': 'is not started'}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret) ret.update({ 'comment': 'bricks successfully added', 'result': True, 'changes': { 'new': ['host1'], 'old': ['host1'] } }) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret) ret.update({'comment': 'Bricks already in volume', 'changes': {}}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret) ret.update({'comment': '', 'result': False}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret)
def test_add_volume_bricks(self): ''' Test to add brick(s) to an existing volume ''' name = 'salt' bricks = ['host1:/drive1'] old_bricks = ['host1:/drive2'] ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} stopped_volinfo = {'salt': {'status': '0'}} volinfo = { 'salt': { 'status': '1', 'bricks': {'brick1': {'path': old_bricks[0]}} } } new_volinfo = { 'salt': { 'status': '1', 'bricks': { 'brick1': {'path': old_bricks[0]}, 'brick2': {'path': bricks[0]} } } } mock_info = MagicMock(return_value={}) mock_add = MagicMock(side_effect=[False, True]) with patch.dict(glusterfs.__salt__, {'glusterfs.info': mock_info, 'glusterfs.add_volume_bricks': mock_add}): ret.update({'comment': 'Volume salt does not exist'}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret) mock_info.return_value = stopped_volinfo ret.update({'comment': 'Volume salt is not started'}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret) mock_info.return_value = volinfo ret.update({'comment': 'Adding bricks to volume salt failed'}) self.assertDictEqual(glusterfs.add_volume_bricks(name, bricks), ret) ret.update({'result': True}) ret.update({'comment': 'Bricks already added in volume salt'}) self.assertDictEqual(glusterfs.add_volume_bricks(name, old_bricks), ret) mock_info.side_effect = [volinfo, new_volinfo] ret.update({'comment': 'Bricks successfully added to volume salt', 'changes': {'new': bricks + old_bricks, 'old': old_bricks}}) # Let's sort ourselves because the test under python 3 sometimes fails # just because of the new changes list order result = glusterfs.add_volume_bricks(name, bricks) ret['changes']['new'] = sorted(ret['changes']['new']) result['changes']['new'] = sorted(result['changes']['new']) self.assertDictEqual(result, ret)