Example #1
0
    def test_keystone_get_session(self, auth_url):
        credential = oscredential.OpenStackCredential(auth_url, "user", "pass",
                                                      "tenant")
        self.set_up_keystone_mocks()
        keystone = osclients.Keystone(credential, {})

        version_data = mock.Mock(return_value=[{"version": (1, 0)}])
        self.ksa_auth.discover.Discover.return_value = (mock.Mock(
            version_data=version_data))

        self.assertEqual(
            (self.ksa_session.Session.return_value, self.ksa_identity_plugin),
            keystone.get_session())
        if auth_url.endswith("v2.0"):
            self.ksa_password.assert_called_once_with(auth_url=auth_url,
                                                      password="******",
                                                      tenant_name="tenant",
                                                      username="******")
        else:
            self.ksa_password.assert_called_once_with(auth_url=auth_url,
                                                      password="******",
                                                      tenant_name="tenant",
                                                      username="******",
                                                      domain_name=None,
                                                      project_domain_name=None,
                                                      user_domain_name=None)
        self.assertEqual([
            mock.call(timeout=180.0, verify=True, cert=None),
            mock.call(auth=self.ksa_identity_plugin,
                      timeout=180.0,
                      verify=True,
                      cert=None)
        ], self.ksa_session.Session.call_args_list)
Example #2
0
    def test_create_client(self):
        # NOTE(bigjools): This is a very poor testing strategy as it
        # tightly couples the test implementation to the tested
        # function's implementation. Ideally, we'd use a fake keystone
        # but all that's happening here is that it's checking the right
        # parameters were passed to the various parts that create a
        # client. Hopefully one day we'll get a real fake from the
        # keystone guys.
        self.set_up_keystone_mocks()
        keystone = osclients.Keystone(self.credential, mock.MagicMock())
        keystone.get_session = mock.Mock(return_value=(
            self.ksa_session,
            self.ksa_identity_plugin,
        ))
        client = keystone.create_client(version=3)

        kwargs_session = self.credential.to_dict()
        kwargs_session.update({
            "auth_url": "http://auth_url/",
            "session": self.ksa_session,
            "timeout": 180.0
        })
        keystone.get_session.assert_called_with()
        called_with = self.ksc_client.Client.call_args_list[0][1]
        self.assertEqual(
            {
                "session": self.ksa_session,
                "timeout": 180.0,
                "version": "3"
            }, called_with)
        self.ksc_client.Client.assert_called_once_with(
            session=self.ksa_session, timeout=180.0, version="3")
        self.assertIs(client, self.ksc_client.Client())
Example #3
0
    def test_auth_ref_fails_debug(self, mock_is_debug, mock_log_exception):
        mock_is_debug.return_value = True
        keystone = osclients.Keystone(self.credential, {})
        session = mock.Mock()
        auth_plugin = mock.Mock()
        auth_plugin.get_access.side_effect = Exception
        keystone.get_session = mock.Mock(return_value=(session, auth_plugin))

        self.assertRaises(osclients.AuthenticationFailed,
                          lambda: keystone.auth_ref)

        mock_log_exception.assert_called_once_with(mock.ANY)
        mock_is_debug.assert_called_once_with()
        auth_plugin.get_access.assert_called_once_with(session)
Example #4
0
    def test_auth_ref(self, mock_keystone_get_session):
        session = mock.MagicMock()
        auth_plugin = mock.MagicMock()
        mock_keystone_get_session.return_value = (session, auth_plugin)
        cache = {}
        keystone = osclients.Keystone(self.credential, cache)

        self.assertEqual(auth_plugin.get_access.return_value,
                         keystone.auth_ref)
        self.assertEqual(auth_plugin.get_access.return_value,
                         cache["keystone_auth_ref"])

        # check that auth_ref was cached.
        keystone.auth_ref
        mock_keystone_get_session.assert_called_once_with()
Example #5
0
    def test_auth_ref_fails_debug_with_native_keystone_error(
            self, mock_is_debug, mock_log_exception):
        from keystoneauth1 import exceptions as ks_exc

        mock_is_debug.return_value = True
        keystone = osclients.Keystone(self.credential, {})
        session = mock.Mock()
        auth_plugin = mock.Mock()
        auth_plugin.get_access.side_effect = ks_exc.ConnectFailure("foo")
        keystone.get_session = mock.Mock(return_value=(session, auth_plugin))

        self.assertRaises(osclients.AuthenticationFailed,
                          lambda: keystone.auth_ref)

        self.assertFalse(mock_log_exception.called)
        mock_is_debug.assert_called_once_with()
        auth_plugin.get_access.assert_called_once_with(session)
Example #6
0
    def test_create_client_removes_url_path_if_version_specified(self):
        # If specifying a version on the client creation call, ensure
        # the auth_url is versionless and the version required is passed
        # into the Client() call.
        self.set_up_keystone_mocks()
        auth_kwargs, all_kwargs = self.make_auth_args()
        keystone = osclients.Keystone(self.credential, mock.MagicMock())
        keystone.get_session = mock.Mock(return_value=(
            self.ksa_session,
            self.ksa_identity_plugin,
        ))
        client = keystone.create_client(version="3")

        self.assertIs(client, self.ksc_client.Client())
        called_with = self.ksc_client.Client.call_args_list[0][1]
        self.assertEqual(
            {
                "session": self.ksa_session,
                "timeout": 180.0,
                "version": "3"
            }, called_with)
    def test__configure_identity(self, auth_url, data, ex_uri,
                                 ex_uri_v3, ex_auth_version, ex_v2_off=False):
        self.tempest.conf.add_section("identity")
        self.tempest.conf.add_section("identity-feature-enabled")
        self.tempest.credential.auth_url = auth_url
        process_url = osclients.Keystone(
            self.tempest.credential, 0)._remove_url_version
        self.tempest.clients.keystone._remove_url_version = process_url

        from keystoneauth1 import discover
        from keystoneauth1 import session

        with mock.patch.object(discover, "Discover") as mock_discover:
            with mock.patch.object(session, "Session") as mock_session:
                mock_discover.return_value.version_data.return_value = data

                self.tempest._configure_identity()

                mock_discover.assert_called_once_with(
                    mock_session.return_value, auth_url)

        expected = {"region": CRED["region_name"],
                    "auth_version": ex_auth_version,
                    "uri": ex_uri, "uri_v3": ex_uri_v3,
                    "disable_ssl_certificate_validation": str(
                        CRED["https_insecure"]),
                    "ca_certificates_file": CRED["https_cacert"]}
        self.assertEqual(expected, dict(self.tempest.conf.items("identity")))
        if ex_v2_off:
            self.assertEqual(
                "False",
                self.tempest.conf.get("identity-feature-enabled", "api_v2"))

        # Test a conf setting with a None value
        try:
            self.tempest.conf.set("identity", "region", None)
        except TypeError as e:
            self.fail("self.tempest.conf.set('identity', 'region', None) "
                      "raised a TypeError: " + str(e))
Example #8
0
 def test_keystone_property(self):
     keystone = osclients.Keystone(self.credential, None)
     self.assertRaises(exceptions.RallyException, lambda: keystone.keystone)
Example #9
0
 def test__remove_url_version(self, original, cropped):
     credential = oscredential.OpenStackCredential(original, "user", "pass",
                                                   "tenant")
     keystone = osclients.Keystone(credential, {})
     self.assertEqual(cropped, keystone._remove_url_version())