def test_version_data_override_version_url(self):
        # if the request url is versioned already, just return it.
        self.requests_mock.get(
            V3_URL,
            status_code=200,
            json={
                'version': fixture.V3Discovery('http://override/identity/v3')
            })

        disc = discover.Discover(self.session, V3_URL)
        version_data = disc.version_data()

        for v in version_data:
            self.assertEqual(v['version'], (3, 0))
            self.assertEqual(v['status'], discover.Status.CURRENT)
            self.assertEqual(v['raw_status'], 'stable')
            self.assertEqual(v['url'], V3_URL)

        # if the request url is not versioned, just add version info to it.(
        # do not changed the url's netloc or path)
        self.requests_mock.get(
            BASE_URL,
            status_code=200,
            json={
                'version': fixture.V3Discovery('http://override/identity/v3')
            })

        disc = discover.Discover(self.session, BASE_URL)
        version_data = disc.version_data()

        for v in version_data:
            self.assertEqual(v['version'], (3, 0))
            self.assertEqual(v['status'], discover.Status.CURRENT)
            self.assertEqual(v['raw_status'], 'stable')
            self.assertEqual(v['url'], V3_URL)
Exemple #2
0
    def _discover_auth_versions(self, session, auth_url):
        # discover the API versions the server is supporting based on the
        # given URL
        v2_auth_url = None
        v3_auth_url = None
        try:
            ks_discover = discover.Discover(session=session, url=auth_url)
            v2_auth_url = ks_discover.url_for('2.0')
            v3_auth_url = ks_discover.url_for('3.0')
        except exceptions.DiscoveryFailure:
            # Discovery response mismatch. Raise the error
            raise
        except Exception:
            # Some public clouds throw some other exception or doesn't support
            # discovery. In that case try to determine version from auth_url
            # API version from the original URL
            url_parts = urlparse.urlparse(auth_url)
            (scheme, netloc, path, params, query, fragment) = url_parts
            path = path.lower()
            if path.startswith('/v3'):
                v3_auth_url = auth_url
            elif path.startswith('/v2'):
                v2_auth_url = auth_url
            else:
                raise exc.CommandError('Unable to determine the Keystone'
                                       ' version to authenticate with '
                                       'using the given auth_url.')

        return (v2_auth_url, v3_auth_url)
Exemple #3
0
def get_trusted_client(conf, trust_id):
    # Ideally we would use load_session_from_conf_options, but we can't do that
    # *and* specify a trust, so let's create the object manually.
    if conf[CFG_GROUP].auth_type == "password-aodh-legacy":
        auth_url = conf[CFG_GROUP].os_auth_url
        try:
            auth_url_noneversion = auth_url.replace('/v2.0', '/')
            discover = ka_discover.Discover(auth_url=auth_url_noneversion)
            v3_auth_url = discover.url_for('3.0')
            if v3_auth_url:
                auth_url = v3_auth_url
            else:
                auth_url = auth_url
        except Exception:
            auth_url = auth_url.replace('/v2.0', '/v3')
        auth_plugin = password.Password(username=conf[CFG_GROUP].os_username,
                                        password=conf[CFG_GROUP].os_password,
                                        auth_url=auth_url,
                                        user_domain_id='default',
                                        trust_id=trust_id)
    else:
        auth_plugin = password.Password(
            username=conf[CFG_GROUP].username,
            password=conf[CFG_GROUP].password,
            auth_url=conf[CFG_GROUP].auth_url,
            user_domain_id=conf[CFG_GROUP].user_domain_id,
            trust_id=trust_id)

    sess = session.Session(auth=auth_plugin)
    return ks_client_v3.Client(session=sess)
Exemple #4
0
    def test_version_data_basics(self):
        examples = {
            'keystone': V3_VERSION_LIST,
            'cinder': CINDER_EXAMPLES,
            'glance': GLANCE_EXAMPLES
        }

        for path, data in examples.items():
            url = "%s%s" % (BASE_URL, path)

            mock = self.requests_mock.get(url, status_code=300, json=data)

            disc = discover.Discover(self.session, url)
            raw_data = disc.raw_version_data()
            clean_data = disc.version_data()

            for v in raw_data:
                for n in ('id', 'status', 'links'):
                    msg = '%s missing from %s version data' % (n, path)
                    self.assertThat(
                        v, matchers.Annotate(msg, matchers.Contains(n)))

            for v in clean_data:
                for n in ('version', 'url', 'raw_status'):
                    msg = '%s missing from %s version data' % (n, path)
                    self.assertThat(
                        v, matchers.Annotate(msg, matchers.Contains(n)))

            self.assertTrue(mock.called_once)
    def test_version_data_legacy_ironic_microversions(self):
        """Validate detection of legacy Ironic microversion ranges."""
        ironic_url = 'https://bare-metal.example.com/v1/'
        self.requests_mock.get(ironic_url,
                               status_code=200,
                               json={
                                   'id': 'v1',
                                   'links': [{
                                       "href": ironic_url,
                                       "rel": "self"
                                   }]
                               },
                               headers={
                                   'X-OpenStack-Ironic-API-Minimum-Version':
                                   '1.3',
                                   'X-OpenStack-Ironic-API-Maximum-Version':
                                   '1.21',
                               })

        self.assertEqual([
            {
                'collection': None,
                'version': (1, 0),
                'url': ironic_url,
                'status': discover.Status.CURRENT,
                'raw_status': discover.Status.CURRENT,
                'min_microversion': (1, 3),
                'max_microversion': (1, 21),
                'next_min_version': None,
                'not_before': None,
            },
        ],
                         discover.Discover(self.session,
                                           ironic_url).version_data())
Exemple #6
0
    def test_allow_deprecated(self):
        status = 'deprecated'
        version_list = [{
            'id': 'v3.0',
            'links': [{
                'href': V3_URL,
                'rel': 'self'
            }],
            'media-types': V3_MEDIA_TYPES,
            'status': status,
            'updated': UPDATED
        }]
        self.requests_mock.get(BASE_URL, json={'versions': version_list})

        disc = discover.Discover(self.session, BASE_URL)

        # deprecated is allowed by default
        versions = disc.version_data(allow_deprecated=False)
        self.assertEqual(0, len(versions))

        versions = disc.version_data(allow_deprecated=True)
        self.assertEqual(1, len(versions))
        self.assertEqual(status, versions[0]['raw_status'])
        self.assertEqual(V3_URL, versions[0]['url'])
        self.assertEqual((3, 0), versions[0]['version'])
Exemple #7
0
    def test_ignoring_invalid_links(self):
        version_list = [{'id': 'v3.0',
                         'links': [{'href': V3_URL, 'rel': 'self'}],
                         'media-types': V3_MEDIA_TYPES,
                         'status': 'stable',
                         'updated': UPDATED},
                        {'id': 'v3.1',
                         'media-types': V3_MEDIA_TYPES,
                         'status': 'stable',
                         'updated': UPDATED},
                        {'media-types': V3_MEDIA_TYPES,
                         'status': 'stable',
                         'updated': UPDATED,
                         'links': [{'href': V3_URL, 'rel': 'self'}],
                         }]

        self.requests_mock.get(BASE_URL, json={'versions': version_list})

        disc = discover.Discover(self.session, BASE_URL)

        # raw_version_data will return all choices, even invalid ones
        versions = disc.raw_version_data()
        self.assertEqual(3, len(versions))

        # only the version with both id and links will be actually returned
        versions = disc.version_data()
        self.assertEqual(1, len(versions))
def _discover_auth_versions(session, auth_url):
    # discover the API versions the server is supporting based on the
    # given URL
    v2_auth_url = None
    v3_auth_url = None
    try:
        ks_discover = discover.Discover(session=session, url=auth_url)
        v2_auth_url = ks_discover.url_for('2.0')
        v3_auth_url = ks_discover.url_for('3.0')
    except ka_exc.DiscoveryFailure:
        raise
    except exceptions.ClientException:
        # Identity service may not support discovery. In that case,
        # try to determine version from auth_url
        url_parts = urlparse.urlparse(auth_url)
        (scheme, netloc, path, params, query, fragment) = url_parts
        path = path.lower()
        if path.startswith('/v3'):
            v3_auth_url = auth_url
        elif path.startswith('/v2'):
            v2_auth_url = auth_url
        else:
            raise exc.CommandError('Unable to determine the Keystone '
                                   'version to authenticate with '
                                   'using the given auth_url.')
    return v2_auth_url, v3_auth_url
Exemple #9
0
    def _discover_auth_versions(self, session, auth_url):
        # discover the API versions the server is supporting base on the
        # given URL
        v2_auth_url = None
        v3_auth_url = None
        try:
            ks_discover = discover.Discover(session=session, url=auth_url)
            v2_auth_url = ks_discover.url_for('2.0')
            v3_auth_url = ks_discover.url_for('3.0')
        except ks_exc.ClientException as e:
            # Identity service may not support discover API version.
            # Lets trying to figure out the API version from the original URL.
            url_parts = urlparse.urlparse(auth_url)
            (scheme, netloc, path, params, query, fragment) = url_parts
            path = path.lower()
            if path.startswith('/v3'):
                v3_auth_url = auth_url
            elif path.startswith('/v2'):
                v2_auth_url = auth_url
            else:
                # not enough information to determine the auth version
                msg = ('Unable to determine the Keystone version '
                       'to authenticate with using the given '
                       'auth_url. Identity service may not support API '
                       'version discovery. Please provide a versioned '
                       'auth_url instead. error=%s') % (e)
                raise exc.CommandError(msg)

        return (v2_auth_url, v3_auth_url)
Exemple #10
0
        def get_versions(auth_url):
            from keystoneauth1 import discover
            from keystoneauth1 import session

            temp_session = session.Session(
                verify=(self.credential.https_cacert or
                        not self.credential.https_insecure),
                timeout=CONF.openstack_client_http_timeout)
            data = discover.Discover(temp_session, auth_url).version_data()
            return dict([(v["version"][0], v["url"]) for v in data])
    def test_version_data_unknown(self):
        discovery_fixture = fixture.V3Discovery(V3_URL)
        discovery_fixture.status = 'hungry'
        discovery_doc = _create_single_version(discovery_fixture)

        self.requests_mock.get(V3_URL, status_code=200, json=discovery_doc)

        disc = discover.Discover(self.session, V3_URL)
        clean_data = disc.version_data(allow_unknown=True)

        self.assertEqual(discover.Status.UNKNOWN, clean_data[0]['status'])
Exemple #12
0
    def get_session(self, version=None):
        key = "keystone_session_and_plugin_%s" % version
        if key not in self.cache:
            from keystoneauth1 import discover
            from keystoneauth1 import identity
            from keystoneauth1 import session

            version = self.choose_version(version)
            auth_url = self.credential.auth_url
            if version is not None:
                auth_url = self._remove_url_version()

            password_args = {
                "auth_url": auth_url,
                "username": self.credential.username,
                "password": self.credential.password,
                "tenant_name": self.credential.tenant_name
            }

            if version is None:
                # NOTE(rvasilets): If version not specified than we discover
                # available version with the smallest number. To be able to
                # discover versions we need session
                temp_session = session.Session(
                    verify=(self.credential.https_cacert
                            or not self.credential.https_insecure),
                    cert=self.credential.https_cert,
                    timeout=CONF.openstack_client_http_timeout)
                version = str(
                    discover.Discover(
                        temp_session,
                        password_args["auth_url"]).version_data()[0]["version"]
                    [0])
                temp_session.session.close()

            if "v2.0" not in password_args["auth_url"] and version != "2":
                password_args.update({
                    "user_domain_name":
                    self.credential.user_domain_name,
                    "domain_name":
                    self.credential.domain_name,
                    "project_domain_name":
                    self.credential.project_domain_name
                })
            identity_plugin = identity.Password(**password_args)
            sess = session.Session(
                auth=identity_plugin,
                verify=(self.credential.https_cacert
                        or not self.credential.https_insecure),
                cert=self.credential.https_cert,
                timeout=CONF.openstack_client_http_timeout)
            self.cache[key] = (sess, identity_plugin)
        return self.cache[key]
Exemple #13
0
    def test_data_for_url(self):
        mock = self.requests_mock.get(V3_URL,
                                      status_code=200,
                                      json=V3_VERSION_ENTRY)

        disc = discover.Discover(self.session, V3_URL)
        for url in (V3_URL, V3_URL + '/'):
            data = disc.versioned_data_for(url=url)
            self.assertEqual(data['version'], (3, 0))
            self.assertEqual(data['raw_status'], 'stable')
            self.assertEqual(data['url'], V3_URL)

        self.assertTrue(mock.called_once)
Exemple #14
0
    def get_endpoint(self, session, interface=None, version=None, **kwargs):
        """Return an endpoint for the client.

        There are no required keyword arguments to ``get_endpoint`` as a plugin
        implementation should use best effort with the information available to
        determine the endpoint.

        :param session: The session object that the auth_plugin belongs to.
        :type session: keystoneauth1.session.Session
        :param version: The version number required for this endpoint.
        :type version: tuple or str
        :param str interface: what visibility the endpoint should have.

        :returns: The base URL that will be used to talk to the required
                  service or None if not available.
        :rtype: string
        """
        if interface == plugin.AUTH_INTERFACE:
            return self._identity_uri

        if not version:
            # NOTE(jamielennox): This plugin can only be used within auth_token
            # and auth_token will always provide version= with requests.
            return None

        if not self._discover:
            self._discover = discover.Discover(session,
                                               url=self._identity_uri,
                                               authenticated=False)

        if not self._discover.url_for(version):
            # NOTE(jamielennox): The requested version is not supported by the
            # identity server.
            return None

        # NOTE(jamielennox): for backwards compatibility here we don't
        # actually use the URL from discovery we hack it up instead. :(
        # NOTE(blk-u): Normalizing the version is a workaround for bug 1450272.
        # This can be removed once that's fixed. Also fix the docstring for the
        # version parameter to be just "tuple".
        version = discover.normalize_version_number(version)
        if discover.version_match((2, 0), version):
            return '%s/v2.0' % self._identity_uri
        elif discover.version_match((3, 0), version):
            return '%s/v3' % self._identity_uri

        # NOTE(jamielennox): This plugin will only get called from auth_token
        # middleware. The middleware should never request a version that the
        # plugin doesn't know how to handle.
        msg = _('Invalid version asked for in auth_token plugin')
        raise NotImplementedError(msg)
Exemple #15
0
    def test_data_for_no_version(self):
        mock = self.requests_mock.get(V3_URL,
                                      status_code=200,
                                      json=V3_VERSION_ENTRY)

        disc = discover.Discover(self.session, V3_URL)

        data = disc.versioned_data_for()
        self.assertEqual(data['version'], (3, 0))
        self.assertEqual(data['raw_status'], 'stable')
        self.assertEqual(data['url'], V3_URL)
        self.assertRaises(TypeError, disc.data_for, version=None)

        self.assertTrue(mock.called_once)
Exemple #16
0
 def test_ok(versions_in, versions_out):
     setup_mock(versions_in)
     # Ensure the output contains the expected microversions
     self.assertEqual([
         dict(
             {
                 'collection': None,
                 'version': (2, 2),
                 'url': V3_URL,
                 'raw_status': 'CURRENT',
             }, **versions_out)
     ],
                      discover.Discover(self.session,
                                        V3_URL).version_data())
Exemple #17
0
def get_auth_uri(v3=True):
    # Look for the keystone auth_uri in the configuration. First we
    # check the [clients_keystone] section, and if it is not set we
    # look in [keystone_authtoken]
    if cfg.CONF.clients_keystone.auth_uri:
        session = ks_session.Session(**config.get_ssl_options('keystone'))
        discover = ks_discover.Discover(session=session,
                                        url=cfg.CONF.clients_keystone.auth_uri)
        return discover.url_for('3.0')
    else:
        # Import auth_token to have keystone_authtoken settings setup.
        importutils.import_module('keystonemiddleware.auth_token')
        auth_uri = cfg.CONF.keystone_authtoken.www_authenticate_uri
        return auth_uri.replace('v2.0', 'v3') if auth_uri and v3 else auth_uri
Exemple #18
0
    def get_discovery(self, session, url, authenticated=None):
        """Return the discovery object for a URL.

        Check the session and the plugin cache to see if we have already
        performed discovery on the URL and if so return it, otherwise create
        a new discovery object, cache it and return it.

        This function is expected to be used by subclasses and should not
        be needed by users.

        :param session: A session object to discover with.
        :type session: keystonauth.session.Session
        :param str url: The url to lookup.
        :param bool authenticated: Include a token in the discovery call.
                                   (optional) Defaults to None (use a token
                                   if a plugin is installed).

        :raises keystonauth.exceptions.DiscoveryFailure: if for some reason
                                                            the lookup fails.
        :raises keystonauth.exceptions.HttpError: An error from an invalid
                                                     HTTP response.

        :returns: A discovery object with the results of looking up that URL.
        """
        # NOTE(jamielennox): we want to cache endpoints on the session as well
        # so that they maintain sharing between auth plugins. Create a cache on
        # the session if it doesn't exist already.
        try:
            session_endpoint_cache = session._identity_endpoint_cache
        except AttributeError:
            session_endpoint_cache = session._identity_endpoint_cache = {}

        # NOTE(jamielennox): There is a cache located on both the session
        # object and the auth plugin object so that they can be shared and the
        # cache is still usable
        for cache in (self._endpoint_cache, session_endpoint_cache):
            disc = cache.get(url)

            if disc:
                break
        else:
            disc = discover.Discover(session, url,
                                     authenticated=authenticated)
            self._endpoint_cache[url] = disc
            session_endpoint_cache[url] = disc

        return disc
Exemple #19
0
    def test_allow_unknown(self):
        status = 'abcdef'
        version_list = fixture.DiscoveryList(BASE_URL,
                                             v2=False,
                                             v3_status=status)
        self.requests_mock.get(BASE_URL, json=version_list)

        disc = discover.Discover(self.session, BASE_URL)

        versions = disc.version_data()
        self.assertEqual(0, len(versions))

        versions = disc.version_data(allow_unknown=True)
        self.assertEqual(1, len(versions))
        self.assertEqual(status, versions[0]['raw_status'])
        self.assertEqual(V3_URL, versions[0]['url'])
        self.assertEqual((3, 0), versions[0]['version'])
Exemple #20
0
    def _get_session(self, auth_url=None, version=None):
        from keystoneauth1 import discover
        from keystoneauth1 import session
        from keystoneclient.auth import identity

        password_args = {
            "auth_url": auth_url or self.credential.auth_url,
            "username": self.credential.username,
            "password": self.credential.password,
            "tenant_name": self.credential.tenant_name
        }

        version = OSClient.get("keystone")(self.credential, self.api_info,
                                           self.cache).choose_version(version)
        if version is None:
            # NOTE(rvasilets): If version not specified than we discover
            # available version with the smallest number. To be able to
            # discover versions we need session
            temp_session = session.Session(
                verify=(self.credential.cacert
                        or not self.credential.insecure),
                timeout=CONF.openstack_client_http_timeout)
            version = str(
                discover.Discover(
                    temp_session,
                    password_args["auth_url"]).version_data()[0]["version"][0])

        if "v2.0" not in password_args["auth_url"] and (version != "2"):
            password_args.update({
                "user_domain_name":
                self.credential.user_domain_name,
                "domain_name":
                self.credential.domain_name,
                "project_domain_name":
                self.credential.project_domain_name,
            })
        identity_plugin = identity.Password(**password_args)
        sess = session.Session(auth=identity_plugin,
                               verify=(self.credential.cacert
                                       or not self.credential.insecure),
                               timeout=CONF.openstack_client_http_timeout)
        return sess, identity_plugin
Exemple #21
0
    def test_version_data_individual(self):
        mock = self.requests_mock.get(V3_URL,
                                      status_code=200,
                                      json=V3_VERSION_ENTRY)

        disc = discover.Discover(self.session, V3_URL)
        raw_data = disc.raw_version_data()
        clean_data = disc.version_data()

        for v in raw_data:
            self.assertEqual(v['id'], 'v3.0')
            self.assertEqual(v['status'], 'stable')
            self.assertIn('media-types', v)
            self.assertIn('links', v)

        for v in clean_data:
            self.assertEqual(v['version'], (3, 0))
            self.assertEqual(v['raw_status'], 'stable')
            self.assertEqual(v['url'], V3_URL)

        self.assertTrue(mock.called_once)
Exemple #22
0
    def Client(self):
        sess = None
        keystone = None
        version = self.conf.os_identity_api_version
        # switch on keystoneauth1
        if self.conf.use_keystoneauth1:
            globals()['v2'] = authv2
            globals()['v3'] = authv3
            globals()['session'] = auth_session

            if self.conf.keystoneauth1.use_loading:
                if self.conf.debug:
                    plugin_loaders = loading.get_available_plugin_loaders()
                    avail_plugins = loading.get_available_plugin_names()
                    logger.debug('Available plugin loaders: %s' %
                                 sorted(plugin_loaders.iteritems()))
                    logger.debug('Available plugins: %s' %
                                 sorted(avail_plugins))
                loader = loading.get_plugin_loader('password')
                self.logger.debug('loader: %s' % loader)
                auth_args = self._get_auth_args()
                auth = loader.load_from_options(**auth_args)
                # Discover with session
                if self.conf.keystoneauth1.use_discovery:
                    if self.conf.null_session_discovery:
                        # gem from ceilometerclient.client...
                        s = session.Session()
                    else:
                        s = session.Session(auth=auth)
                    url = self.os_service_endpoint
                    discover = kauth_discover.Discover(session=s, url=url)
                    self.logger.debug('discover: %s' % discover)
                    self.logger.debug('discovered version data: %s' %
                                      discover.version_data())
                    disc_auth_url = discover.url_for(version)
                    self.logger.debug('discovered urls: %s' % disc_auth_url)
                    # Re-init auth args and auth...
                    #  Not doing this generates interesting error using Identity v3: (remove and attempt v2 for magic!!)
                    #  keystoneauth1.exceptions.http.Forbidden: You are not authorized to perform the requested action: identity:list_projects
                    auth_kwargs = self._get_auth_args(auth_url=disc_auth_url,
                                                      version=version)
                    auth = loader.load_from_options(**auth_kwargs)
                else:
                    raise Exception('Non-discovery approach not implemented.')
            else:
                auth = self._get_password_auth()

            if not self.conf.keystoneauth1.use_sessions:
                raise Exception('Non-session approach not supported.')
            sess = session.Session(auth=auth)
            keystone = keystoneclient.client.Client(version, session=sess)
        else:
            # Using deprecated keystoneclient mechanisms
            # TODO: try generic passwords -- not possible w/o keystoneauth1
            auth = self._get_password_auth()
            if self.conf.keystoneclient.use_sessions:
                # TODO: use discovery
                if self.conf.keystoneclient.use_discovery:
                    # ^^^ seems not possible without versioned urls?
                    auth_args = self._get_auth_args()
                    # TODO: could i use keystoneauth1 loading here...?
                    auth = self._get_password_auth(**auth_args)
                    sess = legacy_session.Session(auth=auth)
                    # /home/kmidzi/projects/rdtibcc-679/local/lib/python2.7/site-packages/keystoneclient/session.py:17
                    # what is implication of import keystoneauth1? advent?
                    try:
                        url = self.os_service_endpoint
                        discover = ks_discover.Discover(session=sess, url=url)
                        self.logger.debug('discover: %s' % discover)
                        self.logger.debug('discovered version data: %s' %
                                          discover.version_data())
                        disc_auth_url = discover.url_for(version)
                        self.logger.debug('discovered urls: %s' %
                                          disc_auth_url)
                    except Exception as e:
                        raise (Exception('Could not discover: %s' % e.message))
                else:
                    sess = keystoneclient.session.Session(auth=auth)
                # keystoneclient.exceptions.DiscoveryFailure: Not enough information to determine URL. Provide either auth_url or endpoint
                keystone = keystoneclient.client.Client(version, session=sess)
            else:
                raise Exception('Non-session approach not implemented.')

        self._sess = sess
        self.logger.info('Auth object: %s' % auth)
        self.logger.info('Session object: %s' % sess)
        return keystone
Exemple #23
0
    def test_glance_version_data(self):
        mock = self.requests_mock.get(BASE_URL,
                                      status_code=200,
                                      json=GLANCE_EXAMPLES)

        disc = discover.Discover(self.session, BASE_URL)
        raw_data = disc.raw_version_data()
        clean_data = disc.version_data()

        self.assertEqual(5, len(raw_data))

        for v in raw_data:
            if v['id'] in ('v2.2', 'v1.1'):
                self.assertEqual(v['status'], 'CURRENT')
            elif v['id'] in ('v2.1', 'v2.0', 'v1.0'):
                self.assertEqual(v['status'], 'SUPPORTED')
            else:
                self.fail("Invalid version found")

        v1_url = '%sv1/' % BASE_URL
        v2_url = '%sv2/' % BASE_URL

        self.assertEqual(clean_data, [
            {
                'collection': None,
                'max_microversion': None,
                'min_microversion': None,
                'next_min_version': None,
                'not_before': None,
                'version': (1, 0),
                'url': v1_url,
                'raw_status': 'SUPPORTED',
            },
            {
                'collection': None,
                'max_microversion': None,
                'min_microversion': None,
                'next_min_version': None,
                'not_before': None,
                'version': (1, 1),
                'url': v1_url,
                'raw_status': 'CURRENT',
            },
            {
                'collection': None,
                'max_microversion': None,
                'min_microversion': None,
                'next_min_version': None,
                'not_before': None,
                'version': (2, 0),
                'url': v2_url,
                'raw_status': 'SUPPORTED',
            },
            {
                'collection': None,
                'max_microversion': None,
                'min_microversion': None,
                'next_min_version': None,
                'not_before': None,
                'version': (2, 1),
                'url': v2_url,
                'raw_status': 'SUPPORTED',
            },
            {
                'collection': None,
                'max_microversion': None,
                'min_microversion': None,
                'next_min_version': None,
                'not_before': None,
                'version': (2, 2),
                'url': v2_url,
                'raw_status': 'CURRENT',
            },
        ])

        for ver in (2, 2.1, 2.2):
            for version in (disc.data_for(ver),
                            disc.versioned_data_for(
                                min_version=ver,
                                max_version=(2, discover.LATEST))):
                self.assertEqual((2, 2), version['version'])
                self.assertEqual('CURRENT', version['raw_status'])
                self.assertEqual(v2_url, version['url'])
                self.assertEqual(v2_url, disc.url_for(ver))

        for ver in (1, 1.1):
            for version in (disc.data_for(ver),
                            disc.versioned_data_for(
                                min_version=ver,
                                max_version=(1, discover.LATEST))):
                self.assertEqual((1, 1), version['version'])
                self.assertEqual('CURRENT', version['raw_status'])
                self.assertEqual(v1_url, version['url'])
                self.assertEqual(v1_url, disc.url_for(ver))

        self.assertIsNone(disc.url_for('v3'))
        self.assertIsNone(
            disc.versioned_url_for(min_version='v3', max_version='v3.latest'))
        self.assertIsNone(disc.url_for('v2.3'))
        self.assertIsNone(
            disc.versioned_url_for(min_version='v2.3',
                                   max_version='v2.latest'))

        self.assertTrue(mock.called_once)
Exemple #24
0
    def test_cinder_version_data(self):
        mock = self.requests_mock.get(BASE_URL,
                                      status_code=300,
                                      json=CINDER_EXAMPLES)

        disc = discover.Discover(self.session, BASE_URL)
        raw_data = disc.raw_version_data()
        clean_data = disc.version_data()

        self.assertEqual(3, len(raw_data))

        for v in raw_data:
            self.assertEqual(v['status'], 'CURRENT')
            if v['id'] == 'v1.0':
                self.assertEqual(v['updated'], '2012-01-04T11:33:21Z')
            elif v['id'] == 'v2.0':
                self.assertEqual(v['updated'], '2012-11-21T11:33:21Z')
            elif v['id'] == 'v3.0':
                self.assertEqual(v['updated'], '2012-11-21T11:33:21Z')
            else:
                self.fail("Invalid version found")

        v1_url = "%sv1/" % BASE_URL
        v2_url = "%sv2/" % BASE_URL
        v3_url = "%sv3/" % BASE_URL

        self.assertEqual(clean_data, [
            {
                'collection': None,
                'max_microversion': None,
                'min_microversion': None,
                'next_min_version': None,
                'not_before': None,
                'version': (1, 0),
                'url': v1_url,
                'raw_status': 'CURRENT',
            },
            {
                'collection': None,
                'max_microversion': None,
                'min_microversion': None,
                'next_min_version': None,
                'not_before': None,
                'version': (2, 0),
                'url': v2_url,
                'raw_status': 'CURRENT',
            },
            {
                'collection': BASE_URL,
                'max_microversion': (3, 27),
                'min_microversion': (3, 0),
                'next_min_version': (3, 4),
                'not_before': u'2019-12-31',
                'version': (3, 0),
                'url': v3_url,
                'raw_status': 'CURRENT',
            },
        ])

        for version in (disc.data_for('v2.0'),
                        disc.versioned_data_for(min_version='v2.0',
                                                max_version='v2.latest')):
            self.assertEqual((2, 0), version['version'])
            self.assertEqual('CURRENT', version['raw_status'])
            self.assertEqual(v2_url, version['url'])

        for version in (disc.data_for(1),
                        disc.versioned_data_for(
                            min_version=(1, ),
                            max_version=(1, discover.LATEST))):
            self.assertEqual((1, 0), version['version'])
            self.assertEqual('CURRENT', version['raw_status'])
            self.assertEqual(v1_url, version['url'])

        self.assertIsNone(disc.url_for('v4'))
        self.assertIsNone(
            disc.versioned_url_for(min_version='v4', max_version='v4.latest'))
        self.assertEqual(v3_url, disc.url_for('v3'))
        self.assertEqual(
            v3_url,
            disc.versioned_url_for(min_version='v3', max_version='v3.latest'))
        self.assertEqual(v2_url, disc.url_for('v2'))
        self.assertEqual(
            v2_url,
            disc.versioned_url_for(min_version='v2', max_version='v2.latest'))
        self.assertEqual(v1_url, disc.url_for('v1'))
        self.assertEqual(
            v1_url,
            disc.versioned_url_for(min_version='v1', max_version='v1.latest'))

        self.assertTrue(mock.called_once)
Exemple #25
0
    def test_keystone_version_data(self):
        mock = self.requests_mock.get(BASE_URL,
                                      status_code=300,
                                      json=V3_VERSION_LIST)

        disc = discover.Discover(self.session, BASE_URL)
        raw_data = disc.raw_version_data()
        clean_data = disc.version_data()

        self.assertEqual(2, len(raw_data))
        self.assertEqual(2, len(clean_data))

        for v in raw_data:
            self.assertIn(v['id'], ('v2.0', 'v3.0'))
            self.assertEqual(v['updated'], UPDATED)
            self.assertEqual(v['status'], 'stable')

            if v['id'] == 'v3.0':
                self.assertEqual(v['media-types'], V3_MEDIA_TYPES)

        for v in clean_data:
            self.assertIn(v['version'], ((2, 0), (3, 0)))
            self.assertEqual(v['raw_status'], 'stable')

        valid_v3_versions = (disc.data_for('v3.0'), disc.data_for('3.latest'),
                             disc.data_for('latest'),
                             disc.versioned_data_for(min_version='v3.0',
                                                     max_version='v3.latest'),
                             disc.versioned_data_for(min_version='3'),
                             disc.versioned_data_for(min_version='3.latest'),
                             disc.versioned_data_for(min_version='latest'),
                             disc.versioned_data_for(min_version='3.latest',
                                                     max_version='latest'),
                             disc.versioned_data_for(min_version='latest',
                                                     max_version='latest'),
                             disc.versioned_data_for(min_version=2),
                             disc.versioned_data_for(min_version='2.latest'))
        for version in valid_v3_versions:
            self.assertEqual((3, 0), version['version'])
            self.assertEqual('stable', version['raw_status'])
            self.assertEqual(V3_URL, version['url'])

        valid_v2_versions = (disc.data_for(2), disc.data_for('2.latest'),
                             disc.versioned_data_for(
                                 min_version=2,
                                 max_version=(2, discover.LATEST)),
                             disc.versioned_data_for(min_version='2.latest',
                                                     max_version='2.latest'))
        for version in valid_v2_versions:
            self.assertEqual((2, 0), version['version'])
            self.assertEqual('stable', version['raw_status'])
            self.assertEqual(V2_URL, version['url'])

        self.assertIsNone(disc.url_for('v4'))
        self.assertIsNone(
            disc.versioned_url_for(min_version='v4', max_version='v4.latest'))
        self.assertEqual(V3_URL, disc.url_for('v3'))
        self.assertEqual(
            V3_URL,
            disc.versioned_url_for(min_version='v3', max_version='v3.latest'))
        self.assertEqual(V2_URL, disc.url_for('v2'))
        self.assertEqual(
            V2_URL,
            disc.versioned_url_for(min_version='v2', max_version='v2.latest'))

        self.assertTrue(mock.called_once)
Exemple #26
0
 def test_exc(versions_in):
     setup_mock(versions_in)
     # Ensure TypeError is raised
     self.assertRaises(
         TypeError,
         discover.Discover(self.session, V3_URL).version_data)