def test_early_fail(self, get):
        """Test if we get a keystoneauth exception.

        If we get a random keystoneauth exception, fall back and
        assume the project exists.

        """
        get.side_effect = kse.ConnectionError()
        self.assertTrue(identity.verify_project_id(mock.MagicMock(), "foo"))
Exemplo n.º 2
0
    def test_early_fail(self, mock_load):
        """Test if we get a keystoneauth exception.

        If we get a random keystoneauth exception, fall back and
        assume the project exists.

        """
        session = mock.create_autospec(Session)
        session.get.side_effect = kse.ConnectionError()
        mock_load.return_value = session
        self.assertTrue(identity.verify_project_id(mock.MagicMock(), "foo"))
Exemplo n.º 3
0
    def test_init(self):
        from keystoneauth1 import exceptions as ks_exc

        actual_exc = ks_exc.ConnectionError("Something")
        exc = osclients.AuthenticationFailed(error=actual_exc,
                                             url="https://example.com",
                                             username="******",
                                             project="project")
        # only original exc should be used
        self.assertEqual("Something", exc.format_message())

        actual_exc = Exception("Something")
        exc = osclients.AuthenticationFailed(error=actual_exc,
                                             url="https://example.com",
                                             username="******",
                                             project="project")
        # additional info should be added
        self.assertEqual(
            "Failed to authenticate to https://example.com for "
            "user 'user' in project 'project': "
            "[Exception] Something", exc.format_message())

        # check cutting message
        actual_exc = ks_exc.DiscoveryFailure(
            "Could not find versioned identity endpoints when attempting to "
            "authenticate. Please check that your auth_url is correct. "
            "Unable to establish connection to https://example.com: "
            "HTTPConnectionPool(host='example.com', port=80): Max retries "
            "exceeded with url: / (Caused by NewConnectionError('"
            "<urllib3.connection.HTTPConnection object at 0x7f32ab9809d0>: "
            "Failed to establish a new connection: [Errno -2] Name or service"
            " not known',))")
        exc = osclients.AuthenticationFailed(error=actual_exc,
                                             url="https://example.com",
                                             username="******",
                                             project="project")
        # original message should be simplified
        self.assertEqual(
            "Could not find versioned identity endpoints when attempting to "
            "authenticate. Please check that your auth_url is correct. "
            "Unable to establish connection to https://example.com",
            exc.format_message())
Exemplo n.º 4
0
    def test_get_failed_connection_error(self, mock_novaclient):
        mock_novaclient.return_value.servers.get.side_effect = (
            keystone_exception.ConnectionError(''))

        self.assertRaises(exception.MasakariException,
                  self.api.get_server, self.ctx, uuidsentinel.fake_server)
Exemplo n.º 5
0
    def test_authentication_failed_exception(self):
        from keystoneauth1 import exceptions as ks_exc

        original_e = KeyError("Oops")
        e = osclients.AuthenticationFailed(url="https://example.com",
                                           username="******",
                                           project="project",
                                           error=original_e)
        self.assertEqual(
            "Failed to authenticate to https://example.com for user 'foo' in "
            "project 'project': [KeyError] 'Oops'", e.format_message())

        original_e = ks_exc.Unauthorized(
            "The request you have made requires "
            "authentication.",
            request_id="ID")
        e = osclients.AuthenticationFailed(url="https://example.com",
                                           username="******",
                                           project="project",
                                           error=original_e)
        self.assertEqual(
            "Failed to authenticate to https://example.com for user 'foo' in "
            "project 'project': The request you have made requires "
            "authentication.", e.format_message())

        original_e = ks_exc.ConnectionError("Some user-friendly native error")
        e = osclients.AuthenticationFailed(url="https://example.com",
                                           username="******",
                                           project="project",
                                           error=original_e)
        self.assertEqual("Some user-friendly native error", e.format_message())

        original_e = ks_exc.ConnectionError(
            "Unable to establish connection to https://example.com:500: "
            "HTTPSConnectionPool(host='example.com', port=500): Max retries "
            "exceeded with url: / (Caused by NewConnectionError('<urllib3."
            "connection.VerifiedHTTPSConnection object at 0x7fb87a48e510>: "
            "Failed to establish a new connection: [Errno 101] Network "
            "is unreachable")
        e = osclients.AuthenticationFailed(url="https://example.com",
                                           username="******",
                                           project="project",
                                           error=original_e)
        self.assertEqual(
            "Unable to establish connection to https://example.com:500",
            e.format_message())

        original_e = ks_exc.ConnectionError(
            "Unable to establish connection to https://example.com:500: "
            # another pool class
            "HTTPConnectionPool(host='example.com', port=500): Max retries "
            "exceeded with url: / (Caused by NewConnectionError('<urllib3."
            "connection.VerifiedHTTPSConnection object at 0x7fb87a48e510>: "
            "Failed to establish a new connection: [Errno 101] Network "
            "is unreachable")
        e = osclients.AuthenticationFailed(url="https://example.com",
                                           username="******",
                                           project="project",
                                           error=original_e)
        self.assertEqual(
            "Unable to establish connection to https://example.com:500",
            e.format_message())