コード例 #1
0
    def test_tenant_present(self):
        '''
        Test to ensures that the keystone tenant exists
        '''
        name = 'nova'
        description = 'OpenStack Compute Service'

        ret = {'name': name,
               'changes': {},
               'result': True,
               'comment': 'Tenant / project "{0}" already exists'.format(name)}

        mock_dict = MagicMock(side_effect=[{name: {'description': 'desc'}},
                                           {name: {'description': description,
                                                   'enabled': False}},
                                           {'Error': 'error'},
                                           {'Error': 'error'}])
        mock_t = MagicMock(return_value=True)
        with patch.dict(keystone.__salt__, {'keystone.tenant_get': mock_dict,
                                            'keystone.tenant_create': mock_t}):
            with patch.dict(keystone.__opts__, {'test': True}):
                comt = ('Tenant / project "{0}" will be updated'.format(name))
                ret.update({'comment': comt, 'result': None,
                            'changes': {'Description': 'Will be updated'}})
                self.assertDictEqual(keystone.tenant_present(name), ret)

                comt = ('Tenant / project "{0}" will be updated'.format(name))
                ret.update({'comment': comt, 'result': None,
                            'changes': {'Enabled': 'Will be True'}})
                self.assertDictEqual(keystone.tenant_present(name,
                                                             description), ret)

                comt = ('Tenant / project "{0}" will be added'.format(name))
                ret.update({'comment': comt, 'result': None,
                            'changes': {'Tenant': 'Will be created'}})
                self.assertDictEqual(keystone.tenant_present(name), ret)

            with patch.dict(keystone.__opts__, {'test': False}):
                comt = ('Tenant / project "{0}" has been added'.format(name))
                ret.update({'comment': comt, 'result': True,
                            'changes': {'Tenant': 'Created'}})
                self.assertDictEqual(keystone.tenant_present(name), ret)
コード例 #2
0
ファイル: keystone_test.py プロジェクト: bryson/salt
    def test_tenant_present(self):
        '''
        Test to ensures that the keystone tenant exists
        '''
        name = 'nova'
        description = 'OpenStack Compute Service'

        ret = {'name': name,
               'changes': {},
               'result': True,
               'comment': 'Tenant / project "{0}" already exists'.format(name)}

        mock_dict = MagicMock(side_effect=[{name: {'description': 'desc'}},
                                           {name: {'description': description,
                                                   'enabled': False}},
                                           {'Error': 'error'},
                                           {'Error': 'error'}])
        mock_t = MagicMock(return_value=True)
        with patch.dict(keystone.__salt__, {'keystone.tenant_get': mock_dict,
                                            'keystone.tenant_create': mock_t}):
            with patch.dict(keystone.__opts__, {'test': True}):
                comt = ('Tenant / project "{0}" will be updated'.format(name))
                ret.update({'comment': comt, 'result': None,
                            'changes': {'Description': 'Will be updated'}})
                self.assertDictEqual(keystone.tenant_present(name), ret)

                comt = ('Tenant / project "{0}" will be updated'.format(name))
                ret.update({'comment': comt, 'result': None,
                            'changes': {'Enabled': 'Will be True'}})
                self.assertDictEqual(keystone.tenant_present(name,
                                                             description), ret)

                comt = ('Tenant / project "{0}" will be added'.format(name))
                ret.update({'comment': comt, 'result': None,
                            'changes': {'Tenant': 'Will be created'}})
                self.assertDictEqual(keystone.tenant_present(name), ret)

            with patch.dict(keystone.__opts__, {'test': False}):
                comt = ('Tenant / project "{0}" has been added'.format(name))
                ret.update({'comment': comt, 'result': True,
                            'changes': {'Tenant': 'Created'}})
                self.assertDictEqual(keystone.tenant_present(name), ret)
コード例 #3
0
ファイル: keystone_test.py プロジェクト: DaveQB/salt
    def test_tenant_present(self):
        """
        Test to ensures that the keystone tenant exists
        """
        name = "nova"
        description = "OpenStack Compute Service"

        ret = {"name": name, "changes": {}, "result": True, "comment": 'Tenant "{0}" already exists'.format(name)}

        mock_dict = MagicMock(
            side_effect=[
                {name: {"description": "desc"}},
                {name: {"description": description, "enabled": False}},
                {"Error": "error"},
                {"Error": "error"},
            ]
        )
        mock_t = MagicMock(return_value=True)
        with patch.dict(keystone.__salt__, {"keystone.tenant_get": mock_dict, "keystone.tenant_create": mock_t}):
            with patch.dict(keystone.__opts__, {"test": True}):
                comt = 'Tenant "{0}" will be updated'.format(name)
                ret.update({"comment": comt, "result": None, "changes": {"Description": "Will be updated"}})
                self.assertDictEqual(keystone.tenant_present(name), ret)

                comt = 'Tenant "{0}" will be updated'.format(name)
                ret.update({"comment": comt, "result": None, "changes": {"Enabled": "Will be True"}})
                self.assertDictEqual(keystone.tenant_present(name, description), ret)

                comt = 'Tenant "{0}" will be added'.format(name)
                ret.update({"comment": comt, "result": None, "changes": {"Tenant": "Will be created"}})
                self.assertDictEqual(keystone.tenant_present(name), ret)

            with patch.dict(keystone.__opts__, {"test": False}):
                comt = 'Tenant "{0}" has been added'.format(name)
                ret.update({"comment": comt, "result": True, "changes": {"Tenant": "Created"}})
                self.assertDictEqual(keystone.tenant_present(name), ret)
コード例 #4
0
    def test_tenant_present(self):
        """
        Test to ensures that the keystone tenant exists
        """
        name = "nova"
        description = "OpenStack Compute Service"

        ret = {
            "name": name,
            "changes": {},
            "result": True,
            "comment": 'Tenant / project "{}" already exists'.format(name),
        }

        mock_dict = MagicMock(
            side_effect=[
                {name: {"description": "desc"}},
                {name: {"description": description, "enabled": False}},
                {"Error": "error"},
                {"Error": "error"},
            ]
        )
        mock_t = MagicMock(return_value=True)
        with patch.dict(
            keystone.__salt__,
            {"keystone.tenant_get": mock_dict, "keystone.tenant_create": mock_t},
        ):
            with patch.dict(keystone.__opts__, {"test": True}):
                comt = 'Tenant / project "{}" will be updated'.format(name)
                ret.update(
                    {
                        "comment": comt,
                        "result": None,
                        "changes": {"Description": "Will be updated"},
                    }
                )
                self.assertDictEqual(keystone.tenant_present(name), ret)

                comt = 'Tenant / project "{}" will be updated'.format(name)
                ret.update(
                    {
                        "comment": comt,
                        "result": None,
                        "changes": {"Enabled": "Will be True"},
                    }
                )
                self.assertDictEqual(keystone.tenant_present(name, description), ret)

                comt = 'Tenant / project "{}" will be added'.format(name)
                ret.update(
                    {
                        "comment": comt,
                        "result": None,
                        "changes": {"Tenant": "Will be created"},
                    }
                )
                self.assertDictEqual(keystone.tenant_present(name), ret)

            with patch.dict(keystone.__opts__, {"test": False}):
                comt = 'Tenant / project "{}" has been added'.format(name)
                ret.update(
                    {"comment": comt, "result": True, "changes": {"Tenant": "Created"}}
                )
                self.assertDictEqual(keystone.tenant_present(name), ret)