Ejemplo n.º 1
0
    def test_init(self, mock_create):
        mock_create.return_value = self.conn
        kc = kv3.KeystoneClient({'k': 'v'})

        mock_create.assert_called_once_with({'k': 'v'})
        self.assertEqual(self.conn, kc.conn)
        self.assertEqual(self.conn.session, kc.session)
Ejemplo n.º 2
0
    def test_validate_regions(self, mock_create):
        self.conn.identity.regions.return_value = [
            {
                'id': 'R1',
                'parent_region_id': None
            },
            {
                'id': 'R2',
                'parent_region_id': None
            },
            {
                'id': 'R3',
                'parent_region_id': 'R1'
            },
        ]
        mock_create.return_value = self.conn

        kc = kv3.KeystoneClient({'k': 'v'})

        res = kc.validate_regions(['R1', 'R4'])

        self.assertIn('R1', res)
        self.assertNotIn('R4', res)

        res = kc.validate_regions([])
        self.assertEqual([], res)
Ejemplo n.º 3
0
    def test_trust_create_conf_roles(self, mock_create):
        cfg.CONF.set_override('trust_roles', ['r1', 'r2'])
        self.conn.identity.create_trust.return_value = 'new_trust'
        mock_create.return_value = self.conn
        kc = kv3.KeystoneClient({'k': 'v'})

        res = kc.trust_create('ID_JOHN', 'ID_DOE', 'PROJECT_ID',
                              ['r1', 'r2', 'r3'])

        self.assertEqual('new_trust', res)
        self.conn.identity.create_trust.assert_called_once_with(
            trustor_user_id='ID_JOHN',
            trustee_user_id='ID_DOE',
            project_id='PROJECT_ID',
            impersonation=True,
            allow_redelegation=True,
            roles=[{
                'name': 'r1'
            }, {
                'name': 'r2'
            }])
        self.conn.reset_mock()

        cfg.CONF.set_override('trust_roles', [])
        res = kc.trust_create('ID_JOHN', 'ID_DOE', 'PROJECT_ID', ['r1', 'r2'])

        self.assertEqual('new_trust', res)
        self.conn.identity.create_trust.assert_called_once_with(
            trustor_user_id='ID_JOHN',
            trustee_user_id='ID_DOE',
            project_id='PROJECT_ID',
            impersonation=True,
            allow_redelegation=True,
            roles=[{
                'name': 'r1'
            }, {
                'name': 'r2'
            }])
        self.conn.reset_mock()

        # impersonation
        res = kc.trust_create('ID_JOHN',
                              'ID_DOE',
                              'PROJECT_ID',
                              impersonation=False)

        self.assertEqual('new_trust', res)
        self.conn.identity.create_trust.assert_called_once_with(
            trustor_user_id='ID_JOHN',
            trustee_user_id='ID_DOE',
            project_id='PROJECT_ID',
            impersonation=False,
            allow_redelegation=True,
            roles=[])
        self.conn.reset_mock()
Ejemplo n.º 4
0
    def test_get_senlin_endpoint(self, mock_create):
        cfg.CONF.set_override('default_region_name', 'RegionN')
        self.conn.session.get_endpoint.return_value = 'http://web.com:1234/v1'
        mock_create.return_value = self.conn
        kc = kv3.KeystoneClient({'k': 'v'})

        res = kc.get_senlin_endpoint()

        self.assertEqual('http://web.com:1234/v1', res)
        self.conn.session.get_endpoint.assert_called_once_with(
            service_type='clustering',
            interface='public',
            region_name='RegionN')
Ejemplo n.º 5
0
    def test_trust_get_by_trustor(self, mock_create):
        trust1 = mock.Mock()
        trust1.trustee_user_id = 'USER_A_ID'
        trust1.project_id = 'PROJECT_ID_1'

        trust2 = mock.Mock()
        trust2.trustee_user_id = 'USER_B_ID'
        trust2.project_id = 'PROJECT_ID_1'

        trust3 = mock.Mock()
        trust3.trustee_user_id = 'USER_A_ID'
        trust3.project_id = 'PROJECT_ID_2'

        self.conn.identity.trusts.return_value = [trust1, trust2, trust3]
        mock_create.return_value = self.conn
        kc = kv3.KeystoneClient({'k': 'v'})

        # no trustee/project filter, matching 1st
        res = kc.trust_get_by_trustor('USER_A')
        self.assertEqual(trust1, res)

        # trustee specified, matching 2nd
        res = kc.trust_get_by_trustor('USER_A', 'USER_B_ID')
        self.assertEqual(trust2, res)

        # project specified, matching 3rd
        res = kc.trust_get_by_trustor('USER_A', project='PROJECT_ID_2')
        self.assertEqual(trust3, res)

        # both trustee and project specified, matching 3rd
        res = kc.trust_get_by_trustor('USER_A', 'USER_A_ID', 'PROJECT_ID_2')
        self.assertEqual(trust3, res)

        # No matching record found
        res = kc.trust_get_by_trustor('USER_A', 'USER_C_ID')
        self.assertIsNone(res)

        get_calls = [mock.call(trustor_user_id='USER_A')]
        self.conn.identity.trusts.assert_has_calls(get_calls * 5)