def test_init_trust_token_none(self, mock_ks): self.ctx.tenant = None self.ctx.trust_id = None self.ctx.auth_token_info = {'not_this': 'urg'} solum_ks_client = solum_keystoneclient.KeystoneClientV3(self.ctx) self.assertRaises(exception.AuthorizationFailure, solum_ks_client._v3_client_init)
def test_init_v3_bad_nocreds(self, mock_ks): """Test creating the client, no credentials.""" self.ctx.auth_token = None self.ctx.trust_id = None self.ctx.username = None solum_ks_client = solum_keystoneclient.KeystoneClientV3(self.ctx) self.assertRaises(exception.AuthorizationFailure, solum_ks_client._v3_client_init)
def test_init_trust_token_none(self, mock_ks): # TODO(zhurong): should unskip the test self.skipTest('Skipping this test for bug #1686560') self.ctx.tenant = None self.ctx.trust_id = None self.ctx.auth_token_info = {'not_this': 'urg'} solum_ks_client = solum_keystoneclient.KeystoneClientV3(self.ctx) self.assertRaises(exception.AuthorizationFailure, solum_ks_client._v3_client_init)
def test_init_v3_token(self, mock_ks): """Test creating the client, token auth.""" self.ctx.tenant = None self.ctx.trust_id = None solum_ks_client = solum_keystoneclient.KeystoneClientV3(self.ctx) solum_ks_client.client self.assertIsNotNone(solum_ks_client._client) mock_ks.assert_called_once_with(token='abcd1234', project_id=None, auth_url='http://server.test:5000/v3', endpoint='http://server.test:5000/v3') mock_ks.return_value.authenticate.assert_called_once_with()
def test_trust_init_token(self, mock_ks): """Test trust_id takes precedence when token specified.""" self.ctx.username = None self.ctx.trust_id = 'atrust123' solum_ks_client = solum_keystoneclient.KeystoneClientV3(self.ctx) self.assertIsNotNone(solum_ks_client._client) mock_ks.assert_called_once_with(username='******', auth_url='http://server.test:5000/v3', password='******', endpoint='http://server.test:5000/v3', trust_id='atrust123') mock_ks.return_value.authenticate.assert_called_once_with()
def test_create_trust_context_trust_id(self, mock_ks): """Test create_trust_context with existing trust_id.""" self.ctx.trust_id = 'atrust123' solum_ks_client = solum_keystoneclient.KeystoneClientV3(self.ctx) trust_context = solum_ks_client.create_trust_context() self.assertEqual(self.ctx.to_dict(), trust_context.to_dict()) mock_ks.assert_called_once_with(username='******', auth_url='http://server.test:5000/v3', password='******', endpoint='http://server.test:5000/v3', trust_id='atrust123') mock_ks.return_value.authenticate.assert_called_once_with()
def test_init_v3_token(self, mock_ks): """Test creating the client, token auth.""" # TODO(zhurong): should unskip the test self.skipTest('Skipping this test for bug #1686560') self.ctx.tenant = None self.ctx.trust_id = None solum_ks_client = solum_keystoneclient.KeystoneClientV3(self.ctx) solum_ks_client.client self.assertIsNotNone(solum_ks_client._client) mock_ks.assert_called_once_with(token='abcd1234', project_id=None, auth_url='http://server.test:5000/v3', endpoint='http://server.test:5000/v3') mock_ks.return_value.authenticate.assert_called_once_with()
def test_init_trust_token_token(self, mock_ks): self.ctx.tenant = None self.ctx.trust_id = None self.ctx.auth_token_info = {'token': {}} solum_ks_client = solum_keystoneclient.KeystoneClientV3(self.ctx) solum_ks_client.client self.assertIsNotNone(solum_ks_client._client) mock_ks.assert_called_once_with(auth_ref={ 'auth_token': 'abcd1234', 'version': 'v3' }, endpoint='http://server.test:5000/v3', auth_url='http://server.test:5000/v3')
def test_trust_init_token(self, mock_ks): """Test trust_id takes precedence when token specified.""" # TODO(zhurong): should unskip the test self.skipTest('Skipping this test for bug #1686560') self.ctx.username = None self.ctx.trust_id = 'atrust123' solum_ks_client = solum_keystoneclient.KeystoneClientV3(self.ctx) self.assertIsNotNone(solum_ks_client._client) mock_ks.assert_called_once_with(username='******', auth_url='http://server.test:5000/v3', password='******', endpoint='http://server.test:5000/v3', trust_id='atrust123') mock_ks.return_value.authenticate.assert_called_once_with()
def test_init_admin_client_denied(self, mock_ks): """Test the admin_client property, auth failure path.""" self.ctx.username = None self.ctx.password = None self.ctx.trust_id = None mock_ks.return_value.authenticate.return_value = False solum_ks_client = solum_keystoneclient.KeystoneClientV3(self.ctx) # Define wrapper for property or the property raises the exception # outside of the assertRaises which fails the test def get_admin_client(): solum_ks_client.admin_client self.assertRaises(exception.AuthorizationFailure, get_admin_client)
def test_init_trust_token_token(self, mock_ks): # TODO(zhurong): should unskip the test self.skipTest('Skipping this test for bug #1686560') self.ctx.tenant = None self.ctx.trust_id = None self.ctx.auth_token_info = {'token': {}} solum_ks_client = solum_keystoneclient.KeystoneClientV3(self.ctx) solum_ks_client.client self.assertIsNotNone(solum_ks_client._client) mock_ks.assert_called_once_with(auth_ref={ 'auth_token': 'abcd1234', 'version': 'v3' }, endpoint='http://server.test:5000/v3', auth_url='http://server.test:5000/v3')
def test_create_trust_context_trust_create(self, mock_ks): """Test create_trust_context when creating a trust.""" # TODO(zhurong): should unskip the test self.skipTest('Skipping this test for bug #1686560') class FakeTrust(object): id = 'atrust123' cfg.CONF.set_override('trusts_delegated_roles', ['solum_assembly_update']) getter_mock = mock.PropertyMock(side_effect=['1234', '5678']) type(mock_ks.return_value.auth_ref).user_id = getter_mock mock_ks.return_value.auth_ref.project_id = '42' mock_ks.return_value.trusts.create.return_value = FakeTrust() self.ctx.trust_id = None solum_ks_client = solum_keystoneclient.KeystoneClientV3(self.ctx) trust_context = solum_ks_client.create_trust_context() # admin_client and user client expected = [ mock.call(username='******', project_name='service', password='******', auth_url='http://server.test:5000/v3', endpoint='http://server.test:5000/v3'), mock.call(token='abcd1234', project_id='fake_project_id', auth_url='http://server.test:5000/v3', endpoint='http://server.test:5000/v3') ] self.assertEqual(expected, mock_ks.call_args_list) self.assertEqual([mock.call(), mock.call()], mock_ks.return_value.authenticate.call_args_list) # trust creation self.assertEqual('atrust123', trust_context.trust_id) mock_ks.return_value.trusts.create.assert_called_once_with( trustor_user='******', trustee_user='******', project='42', impersonation=True, role_names=['solum_assembly_update'])
def test_init_trust_token_access(self, mock_ks): """Test creating the client, token auth.""" self.ctx.tenant = 'abcd1234' self.ctx.trust_id = None self.ctx.auth_token_info = {'access': {'token': {'id': 'placeholder'}}} solum_ks_client = solum_keystoneclient.KeystoneClientV3(self.ctx) solum_ks_client.client self.assertIsNotNone(solum_ks_client._client) mock_ks.assert_called_once_with(auth_ref={ 'version': 'v2.0', 'token': { 'id': 'abcd1234' } }, endpoint='http://server.test:5000/v3', auth_url='http://server.test:5000/v3')
def test_init_lp_admin_client_denied(self, mock_ks): """Test the get_lp_admin_client property, auth failure path.""" # TODO(zhurong): should unskip the test self.skipTest('Skipping this test for bug #1686560') self.ctx.username = None self.ctx.password = None self.ctx.trust_id = None mock_ks.return_value.authenticate.return_value = False solum_ks_client = solum_keystoneclient.KeystoneClientV3(self.ctx) # Define wrapper for property or the property raises the exception # outside of the assertRaises which fails the test def get_lp_admin_client(): solum_ks_client.lp_admin_client self.assertRaises(exception.AuthorizationFailure, get_lp_admin_client)
def _get_environment(self, ctxt): kc = solum_keystoneclient.KeystoneClientV3(ctxt) image_url = kc.client.service_catalog.url_for( service_type='image', endpoint_type='publicURL') # create a minimal environment user_env = {} for var in ['PATH', 'LOGNAME', 'LANG', 'HOME', 'USER', 'TERM']: if var in os.environ: user_env[var] = os.environ[var] user_env['OS_AUTH_TOKEN'] = ctxt.auth_token user_env['OS_AUTH_URL'] = ctxt.auth_url user_env['OS_IMAGE_URL'] = image_url user_env['PROJECT_ID'] = ctxt.tenant user_env['BUILD_ID'] = uuidutils.generate_uuid() user_env['SOLUM_TASK_DIR'] = cfg.CONF.worker.task_log_dir return user_env
def keystone(self): if self._keystone: return self._keystone self._keystone = solum_keystoneclient.KeystoneClientV3(self.context) return self._keystone
def test_delete_trust_not_found(self, mock_ks): """Test delete_trust when trust already deleted.""" mock_delete = mock_ks.return_value.trusts.delete mock_delete.side_effect = kc_exception.NotFound() solum_ks_client = solum_keystoneclient.KeystoneClientV3(self.ctx) self.assertIsNone(solum_ks_client.delete_trust(trust_id='atrust123'))
def test_delete_trust(self, mock_ks): """Test delete_trust when deleting trust.""" mock_ks.return_value.trusts.delete.return_value = None solum_ks_client = solum_keystoneclient.KeystoneClientV3(self.ctx) self.assertIsNone(solum_ks_client.delete_trust(trust_id='atrust123')) mock_ks.return_value.trusts.delete.assert_called_once_with('atrust123')
def test_init_with_no_context(self, mock_ks): """Init with no context.""" mock_ks.return_value.authenticate.return_value = False solum_ks_client = solum_keystoneclient.KeystoneClientV3(None) self.assertEqual(solum_ks_client.endpoint, 'http://server.test:5000/v3')