def test_get_service_id_with_name_conflict(self, client_keystone): self._client.client.services.get.side_effect = (keystone_exceptions .NotFound) self._client.client.services.list.return_value = [ self._get_mock_service(), self._get_mock_service() ] client_keystone.return_value = self._client client_plugin = client.KeystoneClientPlugin( context=mock.MagicMock() ) ex = self.assertRaises(exception.KeystoneServiceNameConflict, client_plugin.get_service_id, self.sample_name) msg = ("Keystone has more than one service with same name " "%s. Please use service id instead of name" % self.sample_name) self.assertEqual(msg, six.text_type(ex)) self.assertRaises(keystone_exceptions.NotFound, self._client.client.services.get, self.sample_name) self._client.client.services.list.assert_called_once_with( name=self.sample_name)
def test_parse_entity_without_domain(self, client_keystone): client_keystone.return_value = self._client client_plugin = keystone.KeystoneClientPlugin(context=mock.MagicMock()) client_plugin.get_domain_id = mock.MagicMock() client_plugin.get_domain_id.return_value = self.sample_uuid self.assertEqual( client_plugin.parse_entity_with_domain('entity', 'entity_type'), ('entity', None))
def test_get_user_id(self, client_keystone): self._client.client.users.get.return_value = self._get_mock_user() client_keystone.return_value = self._client client_plugin = keystone.KeystoneClientPlugin(context=mock.MagicMock()) self.assertEqual(self.sample_uuid, client_plugin.get_user_id(self.sample_uuid)) self._client.client.users.get.assert_called_once_with(self.sample_uuid)
def test_get_user_id_with_name_and_domain_invalid_input( self, client_keystone): self._client.client.users.get.side_effect = ( keystone_exceptions.NotFound) self._client.client.users.list.return_value = [] client_keystone.return_value = self._client client_plugin = keystone.KeystoneClientPlugin(context=mock.MagicMock()) self.assertRaises(exception.EntityNotFound, client_plugin.get_user_id, self.sample_name_and_domain_invalid_input)
def test_get_service_id(self, client_keystone): self._client.client.services.get.return_value = ( self._get_mock_service()) client_keystone.return_value = self._client client_plugin = client.KeystoneClientPlugin(context=mock.MagicMock()) self.assertEqual(self.sample_uuid, client_plugin.get_service_id(self.sample_uuid))
def test_get_region_id_not_found(self, client_keystone): self._client.client.regions.get.side_effect = ( keystone_exceptions.NotFound) client_keystone.return_value = self._client client_plugin = keystone.KeystoneClientPlugin(context=mock.MagicMock()) ex = self.assertRaises(exception.EntityNotFound, client_plugin.get_region_id, self.sample_name) msg = ('The KeystoneRegion (%(name)s) could not be found.' % { 'name': self.sample_name }) self.assertEqual(msg, six.text_type(ex))
def test_get_service_id_not_found(self, client_keystone): self._client.client.services.get.side_effect = ( keystone_exceptions.NotFound) self._client.client.services.list.return_value = [] client_keystone.return_value = self._client client_plugin = client.KeystoneClientPlugin(context=mock.MagicMock()) ex = self.assertRaises(exception.KeystoneServiceNotFound, client_plugin.get_service_id, self.sample_name) msg = ("Keystone service %s not found" % self.sample_name) self.assertEqual(msg, six.text_type(ex))
def test_get_service_id_with_name(self, client_keystone): self._client.client.services.get.side_effect = ( keystone_exceptions.NotFound) self._client.client.services.list.return_value = [ self._get_mock_service() ] client_keystone.return_value = self._client client_plugin = client.KeystoneClientPlugin(context=mock.MagicMock()) self.assertEqual(self.sample_uuid, client_plugin.get_service_id(self.sample_name))
def test_get_user_id_with_name(self, client_keystone): self._client.client.users.get.side_effect = ( keystone_exceptions.NotFound) self._client.client.users.list.return_value = [self._get_mock_user()] client_keystone.return_value = self._client client_plugin = keystone.KeystoneClientPlugin(context=mock.MagicMock()) self.assertEqual(self.sample_uuid, client_plugin.get_user_id(self.sample_name)) self.assertRaises(keystone_exceptions.NotFound, self._client.client.users.get, self.sample_name) self._client.client.users.list.assert_called_once_with( name=self.sample_name)
def test_get_group_id_not_found(self, client_keystone): self._client.client.groups.get.side_effect = ( keystone_exceptions.NotFound) self._client.client.groups.list.return_value = [] client_keystone.return_value = self._client client_plugin = keystone.KeystoneClientPlugin(context=mock.MagicMock()) ex = self.assertRaises(exception.EntityNotFound, client_plugin.get_group_id, self.sample_name) msg = ("The KeystoneGroup (%(name)s) could not be found." % { 'name': self.sample_name }) self.assertEqual(msg, six.text_type(ex)) self.assertRaises(keystone_exceptions.NotFound, self._client.client.groups.get, self.sample_name) self._client.client.groups.list.assert_called_once_with( name=self.sample_name)
def test_get_user_id_not_found(self, client_keystone): self._client.client.users.get.side_effect = ( keystone_exceptions.NotFound) self._client.client.users.find.side_effect = ( keystone_exceptions.NotFound) client_keystone.return_value = self._client client_plugin = keystone.KeystoneClientPlugin(context=mock.MagicMock()) ex = self.assertRaises(exception.EntityNotFound, client_plugin.get_user_id, self.sample_name) msg = ('The KeystoneUser (%(name)s) could not be found.' % { 'name': self.sample_name }) self.assertEqual(msg, str(ex)) self.assertRaises(keystone_exceptions.NotFound, self._client.client.users.get, self.sample_name) self._client.client.users.find.assert_called_once_with( domain=None, name=self.sample_name)
def test_get_project_id_with_domain_not_found(self, client_keystone): self._client.client.projects.get.side_effect = ( keystone_exceptions.NotFound) self._client.client.projects.list.return_value = [] client_keystone.return_value = self._client client_plugin = keystone.KeystoneClientPlugin(context=mock.MagicMock()) ex = self.assertRaises(exception.EntityNotFound, client_plugin.get_project_id, self.sample_name_and_domain) msg = ("The KeystoneProject (%(name)s) could not be found." % { 'name': self.sample_name }) self.assertEqual(msg, str(ex)) self.assertRaises(keystone_exceptions.NotFound, self._client.client.projects.get, self.sample_name) self._client.client.projects.list.assert_called_once_with( domain=client_plugin.get_domain_id(self.sample_domain_uuid), name=self.sample_name)