Esempio n. 1
0
    def test_user_present(self):
        '''
        Test to ensure that the keystone user is present
        with the specified properties.
        '''
        name = 'nova'
        password = '******'
        email = '*****@*****.**'
        tenant = 'demo'

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

        mock_f = MagicMock(return_value=False)
        mock_lst = MagicMock(return_value=['Error'])
        with patch.dict(keystone.__salt__, {'keystone.tenant_get': mock_lst}):
            comt = ('Tenant / project "{0}" does not exist'.format(tenant))
            ret.update({'comment': comt})
            self.assertDictEqual(keystone.user_present(name, password, email,
                                                       tenant), ret)

        mock_dict = MagicMock(side_effect=[{name: {'email': '*****@*****.**'}},
                                           {name: {'email': email,
                                                   'enabled': False}},
                                           {name: {'email': email,
                                                   'enabled': True}},
                                           {name: {'email': email,
                                                   'enabled': True}},
                                           {'Error': 'error'},
                                           {'Error': 'error'}])
        mock_l = MagicMock(return_value={tenant: {'id': 'abc'}})
        with patch.dict(keystone.__salt__,
                        {'keystone.user_get': mock_dict,
                         'keystone.tenant_get': mock_l,
                         'keystone.user_verify_password': mock_f,
                         'keystone.user_create': mock_f}):
            with patch.dict(keystone.__opts__, {'test': True}):
                comt = ('User "{0}" will be updated'.format(name))
                ret.update({'comment': comt, 'result': None,
                            'changes': {'Email': 'Will be updated',
                                        'Enabled': 'Will be True',
                                        'Password': '******'}})
                self.assertDictEqual(keystone.user_present(name, password,
                                                           email), ret)

                ret.update({'comment': comt, 'result': None,
                            'changes': {'Enabled': 'Will be True',
                                        'Password': '******'}})
                self.assertDictEqual(keystone.user_present(name, password,
                                                           email), ret)

                ret.update({'comment': comt, 'result': None,
                            'changes': {'Tenant': 'Will be added to "demo" tenant',
                                        'Password': '******'}})
                self.assertDictEqual(keystone.user_present(name, password,
                                                           email, tenant), ret)

                ret.update({'comment': comt, 'result': None,
                            'changes': {'Password': '******'}})
                self.assertDictEqual(keystone.user_present(name, password,
                                                           email), ret)

                comt = ('Keystone user "nova" will be added')
                ret.update({'comment': comt, 'result': None,
                            'changes': {'User': '******'}})
                self.assertDictEqual(keystone.user_present(name, password,
                                                           email), ret)

            with patch.dict(keystone.__opts__, {'test': False}):
                comt = ('Keystone user {0} has been added'.format(name))
                ret.update({'comment': comt, 'result': True,
                            'changes': {'User': '******'}})
                self.assertDictEqual(keystone.user_present(name, password,
                                                           email), ret)
Esempio n. 2
0
    def test_user_present(self):
        """
        Test to ensure that the keystone user is present
        with the specified properties.
        """
        name = "nova"
        password = "******"
        email = "*****@*****.**"
        tenant = "demo"

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

        mock_f = MagicMock(return_value=False)
        mock_lst = MagicMock(return_value=["Error"])
        with patch.dict(keystone.__salt__, {"keystone.tenant_get": mock_lst}):
            comt = 'Tenant "{0}" does not exist'.format(tenant)
            ret.update({"comment": comt})
            self.assertDictEqual(keystone.user_present(name, password, email, tenant), ret)

        mock_dict = MagicMock(
            side_effect=[
                {name: {"email": "*****@*****.**"}},
                {name: {"email": email, "enabled": False}},
                {name: {"email": email, "enabled": True}},
                {name: {"email": email, "enabled": True}},
                {"Error": "error"},
                {"Error": "error"},
            ]
        )
        mock_l = MagicMock(return_value={tenant: {"id": "abc"}})
        with patch.dict(
            keystone.__salt__,
            {
                "keystone.user_get": mock_dict,
                "keystone.tenant_get": mock_l,
                "keystone.user_verify_password": mock_f,
                "keystone.user_create": mock_f,
            },
        ):
            with patch.dict(keystone.__opts__, {"test": True}):
                comt = 'User "{0}" is already present'.format(name)
                ret.update({"comment": comt, "result": None, "changes": {"Email": "Will be updated"}})
                self.assertDictEqual(keystone.user_present(name, password, email), ret)

                ret.update({"comment": comt, "result": None, "changes": {"Enabled": "Will be True"}})
                self.assertDictEqual(keystone.user_present(name, password, email), ret)

                ret.update({"comment": comt, "result": None, "changes": {"Tenant": 'Will be added to "demo" tenant'}})
                self.assertDictEqual(keystone.user_present(name, password, email, tenant), ret)

                ret.update({"comment": comt, "result": None, "changes": {"Password": "******"}})
                self.assertDictEqual(keystone.user_present(name, password, email), ret)

                comt = 'Keystone user "nova" will be added'
                ret.update({"comment": comt, "result": None, "changes": {"User": "******"}})
                self.assertDictEqual(keystone.user_present(name, password, email), ret)

            with patch.dict(keystone.__opts__, {"test": False}):
                comt = "Keystone user {0} has been added".format(name)
                ret.update({"comment": comt, "result": True, "changes": {"User": "******"}})
                self.assertDictEqual(keystone.user_present(name, password, email), ret)
Esempio n. 3
0
    def test_user_present(self):
        '''
        Test to ensure that the keystone user is present
        with the specified properties.
        '''
        name = 'nova'
        password = '******'
        email = '*****@*****.**'
        tenant = 'demo'

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

        mock_f = MagicMock(return_value=False)
        mock_lst = MagicMock(return_value=['Error'])
        with patch.dict(keystone.__salt__, {'keystone.tenant_get': mock_lst}):
            comt = ('Tenant / project "{0}" does not exist'.format(tenant))
            ret.update({'comment': comt})
            self.assertDictEqual(keystone.user_present(name, password, email,
                                                       tenant), ret)

        mock_dict = MagicMock(side_effect=[{name: {'email': '*****@*****.**'}},
                                           {name: {'email': email,
                                                   'enabled': False}},
                                           {name: {'email': email,
                                                   'enabled': True}},
                                           {name: {'email': email,
                                                   'enabled': True}},
                                           {'Error': 'error'},
                                           {'Error': 'error'}])
        mock_l = MagicMock(return_value={tenant: {'id': 'abc'}})
        with patch.dict(keystone.__salt__,
                        {'keystone.user_get': mock_dict,
                         'keystone.tenant_get': mock_l,
                         'keystone.user_verify_password': mock_f,
                         'keystone.user_create': mock_f}):
            with patch.dict(keystone.__opts__, {'test': True}):
                comt = ('User "{0}" will be updated'.format(name))
                ret.update({'comment': comt, 'result': None,
                            'changes': {'Email': 'Will be updated',
                                        'Enabled': 'Will be True',
                                        'Password': '******'}})
                self.assertDictEqual(keystone.user_present(name, password,
                                                           email), ret)

                ret.update({'comment': comt, 'result': None,
                            'changes': {'Enabled': 'Will be True',
                                        'Password': '******'}})
                self.assertDictEqual(keystone.user_present(name, password,
                                                           email), ret)

                ret.update({'comment': comt, 'result': None,
                            'changes': {'Tenant': 'Will be added to "demo" tenant',
                                        'Password': '******'}})
                self.assertDictEqual(keystone.user_present(name, password,
                                                           email, tenant), ret)

                ret.update({'comment': comt, 'result': None,
                            'changes': {'Password': '******'}})
                self.assertDictEqual(keystone.user_present(name, password,
                                                           email), ret)

                comt = ('Keystone user "nova" will be added')
                ret.update({'comment': comt, 'result': None,
                            'changes': {'User': '******'}})
                self.assertDictEqual(keystone.user_present(name, password,
                                                           email), ret)

            with patch.dict(keystone.__opts__, {'test': False}):
                comt = ('Keystone user {0} has been added'.format(name))
                ret.update({'comment': comt, 'result': True,
                            'changes': {'User': '******'}})
                self.assertDictEqual(keystone.user_present(name, password,
                                                           email), ret)
Esempio n. 4
0
    def test_user_present(self):
        """
        Test to ensure that the keystone user is present
        with the specified properties.
        """
        name = "nova"
        password = "******"
        email = "*****@*****.**"
        tenant = "demo"

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

        mock_f = MagicMock(return_value=False)
        mock_lst = MagicMock(return_value=["Error"])
        with patch.dict(keystone.__salt__, {"keystone.tenant_get": mock_lst}):
            comt = 'Tenant / project "{}" does not exist'.format(tenant)
            ret.update({"comment": comt})
            self.assertDictEqual(
                keystone.user_present(name, password, email, tenant), ret
            )

        mock_dict = MagicMock(
            side_effect=[
                {name: {"email": "*****@*****.**"}},
                {name: {"email": email, "enabled": False}},
                {name: {"email": email, "enabled": True}},
                {name: {"email": email, "enabled": True}},
                {"Error": "error"},
                {"Error": "error"},
            ]
        )
        mock_l = MagicMock(return_value={tenant: {"id": "abc"}})
        with patch.dict(
            keystone.__salt__,
            {
                "keystone.user_get": mock_dict,
                "keystone.tenant_get": mock_l,
                "keystone.user_verify_password": mock_f,
                "keystone.user_create": mock_f,
            },
        ):
            with patch.dict(keystone.__opts__, {"test": True}):
                comt = 'User "{}" will be updated'.format(name)
                ret.update(
                    {
                        "comment": comt,
                        "result": None,
                        "changes": {
                            "Email": "Will be updated",
                            "Enabled": "Will be True",
                            "Password": "******",
                        },
                    }
                )
                self.assertDictEqual(keystone.user_present(name, password, email), ret)

                ret.update(
                    {
                        "comment": comt,
                        "result": None,
                        "changes": {
                            "Enabled": "Will be True",
                            "Password": "******",
                        },
                    }
                )
                self.assertDictEqual(keystone.user_present(name, password, email), ret)

                ret.update(
                    {
                        "comment": comt,
                        "result": None,
                        "changes": {
                            "Tenant": 'Will be added to "demo" tenant',
                            "Password": "******",
                        },
                    }
                )
                self.assertDictEqual(
                    keystone.user_present(name, password, email, tenant), ret
                )

                ret.update(
                    {
                        "comment": comt,
                        "result": None,
                        "changes": {"Password": "******"},
                    }
                )
                self.assertDictEqual(keystone.user_present(name, password, email), ret)

                comt = 'Keystone user "nova" will be added'
                ret.update(
                    {
                        "comment": comt,
                        "result": None,
                        "changes": {"User": "******"},
                    }
                )
                self.assertDictEqual(keystone.user_present(name, password, email), ret)

            with patch.dict(keystone.__opts__, {"test": False}):
                comt = "Keystone user {} has been added".format(name)
                ret.update(
                    {"comment": comt, "result": True, "changes": {"User": "******"}}
                )
                self.assertDictEqual(keystone.user_present(name, password, email), ret)