コード例 #1
0
    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)
コード例 #2
0
 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))
コード例 #3
0
    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)
コード例 #4
0
    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)
コード例 #5
0
    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))
コード例 #6
0
    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))
コード例 #7
0
    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))
コード例 #8
0
    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))
コード例 #9
0
    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)
コード例 #10
0
    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)
コード例 #11
0
    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)
コード例 #12
0
    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)