def test_op_version(self):
        """
        Test setting the Glusterfs op-version
        """
        name = "salt"
        current = 30707
        new = 31200

        ret = {"name": name, "result": False, "comment": "", "changes": {}}

        mock_get_version = MagicMock(return_value={})
        mock_set_version = MagicMock(return_value={})

        with patch.dict(
                glusterfs.__salt__,
            {
                "glusterfs.get_op_version": mock_get_version,
                "glusterfs.set_op_version": mock_set_version,
            },
        ):
            mock_get_version.return_value = [False, "some error message"]
            ret.update({"result": False})
            ret.update({"comment": "some error message"})
            self.assertDictEqual(glusterfs.op_version(name, current), ret)

            mock_get_version.return_value = current
            ret.update({"result": True})
            ret.update({
                "comment":
                "Glusterfs cluster.op-version for {0} already set to {1}".
                format(name, current)
            })
            self.assertDictEqual(glusterfs.op_version(name, current), ret)

            with patch.dict(glusterfs.__opts__, {"test": True}):
                mock_set_version.return_value = [
                    False, "Failed to set version"
                ]
                ret.update({"result": None})
                ret.update({
                    "comment":
                    "An attempt would be made to set the cluster.op-version for {0} to {1}."
                    .format(name, new)
                })
                self.assertDictEqual(glusterfs.op_version(name, new), ret)

            with patch.dict(glusterfs.__opts__, {"test": False}):
                mock_set_version.return_value = [
                    False, "Failed to set version"
                ]
                ret.update({"result": False})
                ret.update({"comment": "Failed to set version"})
                self.assertDictEqual(glusterfs.op_version(name, new), ret)

                mock_set_version.return_value = "some success message"
                ret.update({"comment": "some success message"})
                ret.update({"changes": {"old": current, "new": new}})
                ret.update({"result": True})
                self.assertDictEqual(glusterfs.op_version(name, new), ret)
Exemple #2
0
    def test_op_version(self):
        '''
        Test setting the Glusterfs op-version
        '''
        name = 'salt'
        current = 30707
        new = 31200

        ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}

        mock_get_version = MagicMock(return_value={})
        mock_set_version = MagicMock(return_value={})

        with patch.dict(
                glusterfs.__salt__, {
                    'glusterfs.get_op_version': mock_get_version,
                    'glusterfs.set_op_version': mock_set_version
                }):
            mock_get_version.return_value = [False, 'some error message']
            ret.update({'result': False})
            ret.update({'comment': 'some error message'})
            self.assertDictEqual(glusterfs.op_version(name, current), ret)

            mock_get_version.return_value = current
            ret.update({'result': True})
            ret.update({
                'comment':
                'Glusterfs cluster.op-version for {0} already set to {1}'.
                format(name, current)
            })
            self.assertDictEqual(glusterfs.op_version(name, current), ret)

            with patch.dict(glusterfs.__opts__, {'test': True}):
                mock_set_version.return_value = [
                    False, 'Failed to set version'
                ]
                ret.update({'result': None})
                ret.update({
                    'comment':
                    'An attempt would be made to set the cluster.op-version for {0} to {1}.'
                    .format(name, new)
                })
                self.assertDictEqual(glusterfs.op_version(name, new), ret)

            with patch.dict(glusterfs.__opts__, {'test': False}):
                mock_set_version.return_value = [
                    False, 'Failed to set version'
                ]
                ret.update({'result': False})
                ret.update({'comment': 'Failed to set version'})
                self.assertDictEqual(glusterfs.op_version(name, new), ret)

                mock_set_version.return_value = 'some success message'
                ret.update({'comment': 'some success message'})
                ret.update({'changes': {'old': current, 'new': new}})
                ret.update({'result': True})
                self.assertDictEqual(glusterfs.op_version(name, new), ret)