Beispiel #1
0
    def test_user_present(self):
        '''
        Test to ensure IPMI user and user privileges.
        '''
        name = 'salt'

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

        mock_ret = {'access': {'callback': False, 'link_auth': True,
                               'ipmi_msg': True,
                               'privilege_level': 'administrator'}}
        mock = MagicMock(return_value=mock_ret)
        mock_bool = MagicMock(side_effect=[True, False, False, False])
        with patch.dict(ipmi.__salt__, {'ipmi.get_user': mock,
                                        'ipmi.set_user_password': mock_bool,
                                        'ipmi.ensure_user': mock_bool}):
            comt = ('user already present')
            ret.update({'comment': comt})
            self.assertDictEqual(ipmi.user_present(name, 5, 'salt@123'), ret)

            with patch.dict(ipmi.__opts__, {'test': True}):
                comt = ('would (re)create user')
                ret.update({'comment': comt, 'result': None,
                            'changes': {'new': 'salt', 'old': mock_ret}})
                self.assertDictEqual(ipmi.user_present(name, 5, 'pw@123'), ret)

            with patch.dict(ipmi.__opts__, {'test': False}):
                comt = ('(re)created user')
                ret.update({'comment': comt, 'result': True,
                            'changes': {'new': mock_ret, 'old': mock_ret}})
                self.assertDictEqual(ipmi.user_present(name, 5, 'pw@123'), ret)
Beispiel #2
0
    def test_user_present(self):
        """
        Test to ensure IPMI user and user privileges.
        """
        name = "salt"

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

        mock_ret = {
            "access": {
                "callback": False,
                "link_auth": True,
                "ipmi_msg": True,
                "privilege_level": "administrator",
            }
        }
        mock = MagicMock(return_value=mock_ret)
        mock_bool = MagicMock(side_effect=[True, False, False, False])
        with patch.dict(
                ipmi.__salt__,
            {
                "ipmi.get_user": mock,
                "ipmi.set_user_password": mock_bool,
                "ipmi.ensure_user": mock_bool,
            },
        ):
            comt = "user already present"
            ret.update({"comment": comt})
            self.assertDictEqual(ipmi.user_present(name, 5, "salt@123"), ret)

            with patch.dict(ipmi.__opts__, {"test": True}):
                comt = "would (re)create user"
                ret.update({
                    "comment": comt,
                    "result": None,
                    "changes": {
                        "new": "salt",
                        "old": mock_ret
                    },
                })
                self.assertDictEqual(ipmi.user_present(name, 5, "pw@123"), ret)

            with patch.dict(ipmi.__opts__, {"test": False}):
                comt = "(re)created user"
                ret.update({
                    "comment": comt,
                    "result": True,
                    "changes": {
                        "new": mock_ret,
                        "old": mock_ret
                    },
                })
                self.assertDictEqual(ipmi.user_present(name, 5, "pw@123"), ret)