Exemplo n.º 1
0
 def test_get_version_list(self):
     req = webob.Request.blank('/', base_url='http://127.0.0.1:9292/')
     req.accept = 'application/json'
     self.config(bind_host='127.0.0.1', bind_port=9292)
     res = versions.Controller().index(req)
     self.assertEqual(res.status_int, 300)
     self.assertEqual(res.content_type, 'application/json')
     results = json.loads(res.body)['versions']
     expected = [
         {
             'id': 'v2.0',
             'status': 'CURRENT',
             'links': [{
                 'rel': 'self',
                 'href': 'http://127.0.0.1:9292/v2/'
             }],
         },
         {
             'id': 'v1.1',
             'status': 'CURRENT',
             'links': [{
                 'rel': 'self',
                 'href': 'http://127.0.0.1:9292/v1/'
             }],
         },
         {
             'id': 'v1.0',
             'status': 'SUPPORTED',
             'links': [{
                 'rel': 'self',
                 'href': 'http://127.0.0.1:9292/v1/'
             }],
         },
     ]
     self.assertEqual(results, expected)
Exemplo n.º 2
0
    def test_get_version_list_for_external_app(self):
        url = 'http://customhost:9292/app/api'
        req = webob.Request.blank('/', base_url=url)
        self.config(bind_host='127.0.0.1', bind_port=9292)
        res = versions.Controller().index(req)
        self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
        self.assertEqual('application/json', res.content_type)
        results = jsonutils.loads(res.body)['versions']
        expected = get_versions_list(url)
        self.assertEqual(expected, results)

        self.config(enabled_backends='slow:one,fast:two')
        res = versions.Controller().index(req)
        results = jsonutils.loads(res.body)['versions']
        expected = get_versions_list(url, enabled_backends=True)
        self.assertEqual(expected, results)
Exemplo n.º 3
0
 def test_get_version_list(self):
     req = webob.Request.blank('/', base_url='http://0.0.0.0:9292/')
     req.accept = 'application/json'
     config_opts = {'bind_host': '0.0.0.0', 'bind_port': 9292}
     conf = utils.TestConfigOpts(config_opts)
     res = versions.Controller(conf).index(req)
     self.assertEqual(res.status_int, 300)
     self.assertEqual(res.content_type, 'application/json')
     results = json.loads(res.body)['versions']
     expected = [
         {
             'id': 'v2',
             'status': 'EXPERIMENTAL',
             'links': [{'rel': 'self', 'href': 'http://0.0.0.0:9292/v2/'}],
         },
         {
             'id': 'v1.1',
             'status': 'CURRENT',
             'links': [{'rel': 'self', 'href': 'http://0.0.0.0:9292/v1/'}],
         },
         {
             'id': 'v1.0',
             'status': 'SUPPORTED',
             'links': [{'rel': 'self', 'href': 'http://0.0.0.0:9292/v1/'}],
         },
     ]
     self.assertEqual(results, expected)
Exemplo n.º 4
0
 def test_get_version_list_secure_proxy_ssl_header_https(self):
     self.config(secure_proxy_ssl_header='HTTP_X_FORWARDED_PROTO')
     environ = webob.request.environ_from_url('http://localhost:9292')
     environ['HTTP_X_FORWARDED_PROTO'] = "https"
     req = WsgiRequest(environ)
     res = versions.Controller().index(req)
     self.assertEqual(300, res.status_int)
     self.assertEqual('application/json', res.content_type)
     results = jsonutils.loads(res.body)['versions']
     expected = [
         {
             'id': 'v2.3',
             'status': 'CURRENT',
             'links': [{
                 'rel': 'self',
                 'href': 'https://localhost:9292/v2/'
             }],
         },
         {
             'id': 'v2.2',
             'status': 'SUPPORTED',
             'links': [{
                 'rel': 'self',
                 'href': 'https://localhost:9292/v2/'
             }],
         },
         {
             'id': 'v2.1',
             'status': 'SUPPORTED',
             'links': [{
                 'rel': 'self',
                 'href': 'https://localhost:9292/v2/'
             }],
         },
         {
             'id': 'v2.0',
             'status': 'SUPPORTED',
             'links': [{
                 'rel': 'self',
                 'href': 'https://localhost:9292/v2/'
             }],
         },
         {
             'id': 'v1.1',
             'status': 'DEPRECATED',
             'links': [{
                 'rel': 'self',
                 'href': 'https://localhost:9292/v1/'
             }],
         },
         {
             'id': 'v1.0',
             'status': 'DEPRECATED',
             'links': [{
                 'rel': 'self',
                 'href': 'https://localhost:9292/v1/'
             }],
         },
     ]
     self.assertEqual(expected, results)
Exemplo n.º 5
0
 def test_get_version_list(self):
     req = webob.Request.blank('/')
     req.accept = "application/json"
     conf = utils.TestConfigOpts({
         'bind_host': '0.0.0.0',
         'bind_port': 9292
     })
     res = req.get_response(versions.Controller(conf))
     self.assertEqual(res.status_int, 300)
     self.assertEqual(res.content_type, "application/json")
     results = json.loads(res.body)["versions"]
     expected = [{
         "id":
         "v1.1",
         "status":
         "CURRENT",
         "links": [{
             "rel": "self",
             "href": "http://0.0.0.0:9292/v1/"
         }]
     }, {
         "id":
         "v1.0",
         "status":
         "SUPPORTED",
         "links": [{
             "rel": "self",
             "href": "http://0.0.0.0:9292/v1/"
         }]
     }]
     self.assertEqual(results, expected)
Exemplo n.º 6
0
 def _get_list_of_version_ids(self, status):
     request = webob.Request.blank('/')
     request.accept = 'application/json'
     # TODO(rosmaita): remove in Queens when option is removed
     self.config(enable_image_import=True)
     response = versions.Controller().index(request)
     v_list = jsonutils.loads(response.body)['versions']
     return [v['id'] for v in v_list if v['status'] == status]
Exemplo n.º 7
0
    def test_get_version_list_secure_proxy_ssl_header(self):
        self.config(secure_proxy_ssl_header='HTTP_X_FORWARDED_PROTO')
        url = 'http://localhost:9292'
        environ = webob.request.environ_from_url(url)
        req = WsgiRequest(environ)
        res = versions.Controller().index(req)
        self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
        self.assertEqual('application/json', res.content_type)
        results = jsonutils.loads(res.body)['versions']
        expected = get_versions_list(url)
        self.assertEqual(expected, results)

        self.config(enabled_backends='slow:one,fast:two')
        res = versions.Controller().index(req)
        results = jsonutils.loads(res.body)['versions']
        expected = get_versions_list(url, enabled_backends=True)
        self.assertEqual(expected, results)
Exemplo n.º 8
0
    def test_get_version_list_public_endpoint(self):
        req = webob.Request.blank('/', base_url='http://127.0.0.1:9292/')
        req.accept = 'application/json'
        self.config(bind_host='127.0.0.1', bind_port=9292,
                    public_endpoint='https://example.com:9292')
        res = versions.Controller().index(req)
        self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
        self.assertEqual('application/json', res.content_type)
        results = jsonutils.loads(res.body)['versions']
        expected = get_versions_list('https://example.com:9292')
        self.assertEqual(expected, results)

        self.config(enabled_backends='slow:one,fast:two')
        res = versions.Controller().index(req)
        results = jsonutils.loads(res.body)['versions']
        expected = get_versions_list('https://example.com:9292',
                                     enabled_backends=True)
        self.assertEqual(expected, results)
Exemplo n.º 9
0
 def test_get_version_list(self):
     req = webob.Request.blank('/', base_url='http://127.0.0.1:9292/')
     req.accept = 'application/json'
     self.config(bind_host='127.0.0.1', bind_port=9292)
     res = versions.Controller().index(req)
     self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
     self.assertEqual('application/json', res.content_type)
     results = jsonutils.loads(res.body)['versions']
     expected = self._get_versions_list('http://127.0.0.1:9292')
     self.assertEqual(expected, results)
Exemplo n.º 10
0
 def test_get_version_list_public_endpoint(self):
     req = webob.Request.blank('/', base_url='http://127.0.0.1:9292/')
     req.accept = 'application/json'
     self.config(bind_host='127.0.0.1', bind_port=9292,
                 public_endpoint='https://example.com:9292')
     res = versions.Controller().index(req)
     self.assertEqual(300, res.status_int)
     self.assertEqual('application/json', res.content_type)
     results = jsonutils.loads(res.body)['versions']
     expected = [
         {
             'status': 'EXPERIMENTAL',
             'id': 'v3.0',
             'links': [{'href': 'https://example.com:9292/v3/',
                        'rel': 'self'}],
         },
         {
             'id': 'v2.3',
             'status': 'CURRENT',
             'links': [{'rel': 'self',
                        'href': 'https://example.com:9292/v2/'}],
         },
         {
             'id': 'v2.2',
             'status': 'SUPPORTED',
             'links': [{'rel': 'self',
                        'href': 'https://example.com:9292/v2/'}],
         },
         {
             'id': 'v2.1',
             'status': 'SUPPORTED',
             'links': [{'rel': 'self',
                        'href': 'https://example.com:9292/v2/'}],
         },
         {
             'id': 'v2.0',
             'status': 'SUPPORTED',
             'links': [{'rel': 'self',
                        'href': 'https://example.com:9292/v2/'}],
         },
         {
             'id': 'v1.1',
             'status': 'SUPPORTED',
             'links': [{'rel': 'self',
                        'href': 'https://example.com:9292/v1/'}],
         },
         {
             'id': 'v1.0',
             'status': 'SUPPORTED',
             'links': [{'rel': 'self',
                        'href': 'https://example.com:9292/v1/'}],
         },
     ]
     self.assertEqual(expected, results)
Exemplo n.º 11
0
 def test_get_version_list_secure_proxy_ssl_header_EXPERIMENTAL(self):
     self.config(secure_proxy_ssl_header='HTTP_X_FORWARDED_PROTO',
                 enable_image_import=True)
     url = 'http://localhost:9292'
     environ = webob.request.environ_from_url(url)
     req = WsgiRequest(environ)
     res = versions.Controller().index(req)
     self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
     self.assertEqual('application/json', res.content_type)
     results = jsonutils.loads(res.body)['versions']
     expected = self._get_versions_list_experimental(url)
     self.assertEqual(expected, results)
Exemplo n.º 12
0
 def __init__(self, app):
     self.versions_app = versions.Controller()
     super(VersionNegotiationFilter, self).__init__(app)
Exemplo n.º 13
0
 def __init__(self, app):
     self.versions_app = versions.Controller()
     self.allowed_versions = None
     self.vnd_mime_type = 'application/vnd.openstack.images-'
     super(VersionNegotiationFilter, self).__init__(app)
Exemplo n.º 14
0
 def __init__(self, app, conf, **local_conf):
     self.versions_app = versions.Controller(conf)
     self.version_uri_regex = re.compile(r"^v(\d+)\.?(\d+)?")
     self.conf = conf
     super(VersionNegotiationFilter, self).__init__(app)
Exemplo n.º 15
0
 def __init__(self, app, conf, **local_conf):
     self.versions_app = versions.Controller(conf)
     self.conf = conf
     super(VersionNegotiationFilter, self).__init__(app)
Exemplo n.º 16
0
 def test_get_version_list(self):
     req = webob.Request.blank('/', base_url='http://127.0.0.1:9292/')
     req.accept = 'application/json'
     self.config(bind_host='127.0.0.1', bind_port=9292)
     res = versions.Controller().index(req)
     self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
     self.assertEqual('application/json', res.content_type)
     results = jsonutils.loads(res.body)['versions']
     expected = [
         {
             'id': 'v2.6',
             'status': 'EXPERIMENTAL',
             'links': [{
                 'rel': 'self',
                 'href': 'http://127.0.0.1:9292/v2/'
             }],
         },
         {
             'id': 'v2.5',
             'status': 'CURRENT',
             'links': [{
                 'rel': 'self',
                 'href': 'http://127.0.0.1:9292/v2/'
             }],
         },
         {
             'id': 'v2.4',
             'status': 'SUPPORTED',
             'links': [{
                 'rel': 'self',
                 'href': 'http://127.0.0.1:9292/v2/'
             }],
         },
         {
             'id': 'v2.3',
             'status': 'SUPPORTED',
             'links': [{
                 'rel': 'self',
                 'href': 'http://127.0.0.1:9292/v2/'
             }],
         },
         {
             'id': 'v2.2',
             'status': 'SUPPORTED',
             'links': [{
                 'rel': 'self',
                 'href': 'http://127.0.0.1:9292/v2/'
             }],
         },
         {
             'id': 'v2.1',
             'status': 'SUPPORTED',
             'links': [{
                 'rel': 'self',
                 'href': 'http://127.0.0.1:9292/v2/'
             }],
         },
         {
             'id': 'v2.0',
             'status': 'SUPPORTED',
             'links': [{
                 'rel': 'self',
                 'href': 'http://127.0.0.1:9292/v2/'
             }],
         },
         {
             'id': 'v1.1',
             'status': 'DEPRECATED',
             'links': [{
                 'rel': 'self',
                 'href': 'http://127.0.0.1:9292/v1/'
             }],
         },
         {
             'id': 'v1.0',
             'status': 'DEPRECATED',
             'links': [{
                 'rel': 'self',
                 'href': 'http://127.0.0.1:9292/v1/'
             }],
         },
     ]
     self.assertEqual(expected, results)
Exemplo n.º 17
0
 def _get_list_of_version_ids(self, status):
     request = webob.Request.blank('/')
     request.accept = 'application/json'
     response = versions.Controller().index(request)
     v_list = jsonutils.loads(response.body)['versions']
     return [v['id'] for v in v_list if v['status'] == status]
Exemplo n.º 18
0
 def __init__(self, app, options):
     self.versions_app = versions.Controller(options)
     self.version_uri_regex = re.compile(r"^v(\d+)\.?(\d+)?")
     self.options = options
     super(VersionNegotiationFilter, self).__init__(app)