Exemple #1
0
    def test_present(self):
        """
            Test to ensure that a group is present
        """
        ret = {"name": "salt", "changes": {}, "result": True, "comment": {}}

        ret.update({
            "comment": 'Error: Conflicting options "members" with'
            ' "addusers" and/or "delusers" can not be used together. ',
            "result": None,
        })
        self.assertDictEqual(
            group.present("salt", delusers=True, members=True), ret)

        ret.update({
            "comment":
            "Error. Same user(s) can not be"
            " added and deleted simultaneously"
        })
        self.assertDictEqual(
            group.present("salt", addusers=["a"], delusers=["a"]), ret)

        ret.update({
            "comment":
            "The following group attributes are set"
            " to be changed:\nkey0: value0\nkey1: value1\n"
        })

        mock = MagicMock(side_effect=[
            OrderedDict((("key0", "value0"), ("key1", "value1"))),
            False,
            False,
            False,
        ])
        with patch.object(group, "_changes", mock):
            with patch.dict(group.__opts__, {"test": True}):
                self.assertDictEqual(group.present("salt"), ret)

                ret.update({"comment": "Group salt set to be added"})
                self.assertDictEqual(group.present("salt"), ret)

            with patch.dict(group.__opts__, {"test": False}):
                mock = MagicMock(return_value=[{"gid": 1, "name": "stack"}])
                with patch.dict(group.__salt__, {"group.getent": mock}):
                    ret.update({
                        "result":
                        False,
                        "comment":
                        "Group salt is not present but"
                        " gid 1 is already taken by group stack",
                    })
                    self.assertDictEqual(group.present("salt", 1), ret)

                    mock = MagicMock(return_value=False)
                    with patch.dict(group.__salt__, {"group.add": mock}):
                        ret.update(
                            {"comment": "Failed to create new group salt"})
                        self.assertDictEqual(group.present("salt"), ret)
Exemple #2
0
    def test_present(self):
        '''
            Test to ensure that a group is present
        '''
        ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': {}}

        ret.update({
            'comment': 'Error: Conflicting options "members" with'
            ' "addusers" and/or "delusers" can not be used together. ',
            'result': None
        })
        self.assertDictEqual(
            group.present("salt", delusers=True, members=True), ret)

        ret.update({
            'comment':
            'Error. Same user(s) can not be'
            ' added and deleted simultaneously'
        })
        self.assertDictEqual(
            group.present("salt", addusers=['a'], delusers=['a']), ret)

        ret.update({
            'comment':
            'The following group attributes are set'
            ' to be changed:\nkey0: value0\nkey1: value1\n'
        })

        mock = MagicMock(side_effect=[
            OrderedDict((('key0', 'value0'), ('key1',
                                              'value1'))), False, False, False
        ])
        with patch.object(group, '_changes', mock):
            with patch.dict(group.__opts__, {"test": True}):
                self.assertDictEqual(group.present("salt"), ret)

                ret.update({'comment': 'Group salt set to be added'})
                self.assertDictEqual(group.present("salt"), ret)

            with patch.dict(group.__opts__, {"test": False}):
                mock = MagicMock(return_value=[{'gid': 1, 'name': 'stack'}])
                with patch.dict(group.__salt__, {'group.getent': mock}):
                    ret.update({
                        'result':
                        False,
                        'comment':
                        'Group salt is not present but'
                        ' gid 1 is already taken by group stack'
                    })
                    self.assertDictEqual(group.present("salt", 1), ret)

                    mock = MagicMock(return_value=False)
                    with patch.dict(group.__salt__, {'group.add': mock}):
                        ret.update(
                            {'comment': 'Failed to create new group salt'})
                        self.assertDictEqual(group.present("salt"), ret)
Exemple #3
0
    def test_present(self):
        '''
            Test to ensure that a group is present
        '''
        ret = {'name': 'salt',
               'changes': {},
               'result': True,
               'comment': {}
               }

        ret.update({'comment': 'Error: Conflicting options "members" with'
                    ' "addusers" and/or "delusers" can not be used together. ',
                    'result': None})
        self.assertDictEqual(group.present("salt", delusers=True,
                                           members=True), ret)

        ret.update({'comment': 'Error. Same user(s) can not be'
                    ' added and deleted simultaneously'})
        self.assertDictEqual(group.present("salt", addusers=['a'],
                                           delusers=['a']), ret)

        ret.update({'comment': 'The following group attributes are set'
                    ' to be changed:\nkey1: value1\nkey0: value0\n'})
        mock = MagicMock(side_effect=[{'key0': 'value0',
                                       'key1': 'value1'}, False, False, False])
        with patch.object(group, '_changes', mock):
            with patch.dict(group.__opts__, {"test": True}):
                self.assertDictEqual(group.present("salt"), ret)

                ret.update({'comment': 'Group salt set to be added'})
                self.assertDictEqual(group.present("salt"), ret)

            with patch.dict(group.__opts__, {"test": False}):
                mock = MagicMock(return_value=[{'gid': 1, 'name': 'stack'}])
                with patch.dict(group.__salt__, {'group.getent': mock}):
                    ret.update({'result': False,
                                'comment': 'Group salt is not present but'
                                ' gid 1 is already taken by group stack'})
                    self.assertDictEqual(group.present("salt", 1), ret)

                    mock = MagicMock(return_value=False)
                    with patch.dict(group.__salt__, {'group.add': mock}):
                        ret.update({'comment':
                                    'Failed to create new group salt'})
                        self.assertDictEqual(group.present("salt"), ret)