def setUp(self):

        super(NvpApiRequestEventletTest, self).setUp()
        self.client = nace.NvpApiClientEventlet([("127.0.0.1", 4401, True)],
                                                "admin", "admin")
        self.url = "/ws.v1/_debug"
        self.req = nare.NvpApiRequestEventlet(self.client, self.url)
Пример #2
0
 def _redirect_params(self, conn, headers):
     url = None
     for name, value in headers:
         if name.lower() == "location":
             url = value
             break
     if not url:
         LOG.warn("Received redirect status without location header field")
         return (conn, None)
     # Accept location with the following format:
     # 1. /path, redirect to same node
     # 2. scheme://hostname:[port]/path where scheme is https or http
     # Reject others
     # 3. e.g. relative paths, unsupported scheme, unspecified host
     result = urlparse.urlparse(url)
     if not result.scheme and not result.hostname and result.path:
         if result.path[0] == "/":
             if result.query:
                 url = "%s?%s" % (result.path, result.query)
             else:
                 url = result.path
             return (conn, url)  # case 1
         else:
             LOG.warn("Received invalid redirect location: %s" % url)
             return (conn, None)  # case 3
     elif result.scheme not in ["http", "https"] or not result.hostname:
         LOG.warn("Received malformed redirect location: %s" % url)
         return (conn, None)  # case 3
     # case 2, redirect location includes a scheme
     # so setup a new connection and authenticate
     use_https = result.scheme == "https"
     api_providers = [(result.hostname, result.port, use_https)]
     client_eventlet = (quantum.plugins.nicira.nicira_nvp_plugin.api_client.
                        client_eventlet)
     api_client = client_eventlet.NvpApiClientEventlet(
         api_providers,
         self._api_client.user,
         self._api_client.password,
         use_https=use_https)
     api_client.wait_for_login()
     if api_client.auth_cookie:
         self._headers["Cookie"] = api_client.auth_cookie
     else:
         self._headers["Cookie"] = ""
     conn = api_client.acquire_connection()
     if result.query:
         url = "%s?%s" % (result.path, result.query)
     else:
         url = result.path
     return (conn, url)