]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fixes i18n messages in nvp plugin
authorAaron Rosen <arosen@nicira.com>
Fri, 4 Jan 2013 20:53:32 +0000 (12:53 -0800)
committerAaron Rosen <arosen@nicira.com>
Fri, 11 Jan 2013 02:15:41 +0000 (18:15 -0800)
Fixes bug 1096205
Change-Id: Icb34b567a8630bb7247b2bb2d6efaf53269bf84b

quantum/plugins/nicira/nicira_nvp_plugin/NvpApiClient.py
quantum/plugins/nicira/nicira_nvp_plugin/QuantumPlugin.py
quantum/plugins/nicira/nicira_nvp_plugin/api_client/client.py
quantum/plugins/nicira/nicira_nvp_plugin/api_client/request.py
quantum/plugins/nicira/nicira_nvp_plugin/api_client/request_eventlet.py
quantum/plugins/nicira/nicira_nvp_plugin/nvplib.py

index b83648a9e3a90ed4cc8351ccb8a9052c527e1fad..ae511e580fa009e750cb2847718738832d20f66a 100644 (file)
@@ -169,7 +169,7 @@ class NvpApiException(Exception):
     with the keyword arguments provided to the constructor.
 
     '''
-    message = "An unknown exception occurred."
+    message = _("An unknown exception occurred.")
 
     def __init__(self, **kwargs):
         try:
@@ -184,26 +184,27 @@ class NvpApiException(Exception):
 
 
 class UnAuthorizedRequest(NvpApiException):
-    message = "Server denied session's authentication credentials."
+    message = _("Server denied session's authentication credentials.")
 
 
 class ResourceNotFound(NvpApiException):
-    message = "An entity referenced in the request was not found."
+    message = _("An entity referenced in the request was not found.")
 
 
 class Conflict(NvpApiException):
-    message = "Request conflicts with configuration on a different entity."
+    message = _("Request conflicts with configuration on a different "
+                "entity.")
 
 
 class ServiceUnavailable(NvpApiException):
-    message = ("Request could not completed because the associated "
-               "resource could not be reached.")
+    message = _("Request could not completed because the associated "
+                "resource could not be reached.")
 
 
 class Forbidden(NvpApiException):
-    message = ("The request is forbidden from accessing the "
-               "referenced resource.")
+    message = _("The request is forbidden from accessing the "
+                "referenced resource.")
 
 
 class RequestTimeout(NvpApiException):
-    message = "The request has timed out."
+    message = _("The request has timed out.")
index 11c7b2ca3d91d3a62744fd869b7c5b269f17c81a..afd06a2cda7117f70f0e895dc0fdcc5ffd225278 100644 (file)
@@ -167,8 +167,8 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
                            "Using first cluster:%s"), first_cluster_name)
             elif not def_cluster_name in self.clusters:
                 LOG.warning(_("Default cluster name %(def_cluster_name)s. "
-                              "Using first cluster:%(first_cluster_name)s")
-                            locals())
+                              "Using first cluster:%(first_cluster_name)s"),
+                            locals())
             # otherwise set 1st cluster as default
             self.default_cluster = self.clusters[first_cluster_name]
 
@@ -192,14 +192,14 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
     def _novazone_to_cluster(self, novazone_id):
         if novazone_id in self.novazone_cluster_map:
             return self.novazone_cluster_map[novazone_id]
-        LOG.debug(_("Looking for nova zone: %s") % novazone_id)
+        LOG.debug(_("Looking for nova zone: %s"), novazone_id)
         for x in self.clusters:
             LOG.debug(_("Looking for nova zone %(novazone_id)s in "
-                        "cluster: %(x)s") % locals())
+                        "cluster: %(x)s"), locals())
             if x.zone == str(novazone_id):
                 self.novazone_cluster_map[x.zone] = x
                 return x
-        LOG.error(_("Unable to find cluster config entry for nova zone: %s") %
+        LOG.error(_("Unable to find cluster config entry for nova zone: %s"),
                   novazone_id)
         raise nvp_exc.NvpInvalidNovaZone(nova_zone=novazone_id)
 
@@ -296,7 +296,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
                         ['lport_count'] < max_ports)].pop(0)
         except IndexError:
             # Too bad, no switch available
-            LOG.debug(_("No switch has available ports (%d checked)") %
+            LOG.debug(_("No switch has available ports (%d checked)"),
                       len(lswitches))
         if allow_extra_lswitches:
             main_ls = [ls for ls in lswitches if ls['uuid'] == network.id]
@@ -318,7 +318,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
             return selected_lswitch
         else:
             LOG.error(_("Maximum number of logical ports reached for "
-                        "logical network %s") % network.id)
+                        "logical network %s"), network.id)
             raise nvp_exc.NvpNoMorePortsException(network=network.id)
 
     def setup_rpc(self):
@@ -368,7 +368,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
         if net_data['admin_state_up'] is False:
             LOG.warning(_("Network with admin_state_up=False are not yet "
                           "supported by this plugin. Ignoring setting for "
-                          "network %s") % net_data.get('name', '<unknown>'))
+                          "network %s"), net_data.get('name', '<unknown>'))
         tenant_id = self._get_tenant_id_for_create(context, net_data)
         target_cluster = self._find_target_cluster(net_data)
         lswitch = nvplib.create_lswitch(target_cluster,
@@ -473,8 +473,8 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
                     net_op_status = constants.NET_STATUS_DOWN
                     break
             LOG.debug(_("Current network status:%(net_op_status)s; "
-                        "Status in Quantum DB:%(quantum_status)s")
-                      locals())
+                        "Status in Quantum DB:%(quantum_status)s"),
+                      locals())
             if net_op_status != network.status:
                 # update the network status
                 with context.session.begin(subtransactions=True):
@@ -822,7 +822,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
             raise nvp_exc.NvpPluginException(err_desc=err_msg)
 
         LOG.debug(_("create_port completed on NVP for tenant %(tenant_id)s: "
-                    "(%(id)s)") % port_data)
+                    "(%(id)s)"), port_data)
 
         # update port on Quantum DB with admin_state_up True
         port_update = {"port": {"admin_state_up": True}}
index 391112d0cd20bd553e90c25cbeccffb30c5d0e59..226a82a645b7bab53bd266d8a289130b4bf3875c 100644 (file)
@@ -120,16 +120,18 @@ class NvpApiClient(object):
         priority, conn = self._conn_pool.get()
         now = time.time()
         if getattr(conn, 'last_used', now) < now - self.CONN_IDLE_TIMEOUT:
-            LOG.info(_("[%d] Connection %s idle for %0.2f seconds; "
-                       "reconnecting."),
-                     rid, _conn_str(conn), now - conn.last_used)
+            LOG.info(_("[%(rid)d] Connection %(conn)s idle for %(sec)0.2f "
+                       "seconds; reconnecting."),
+                     {'rid': rid, 'conn': _conn_str(conn),
+                      'sec': now - conn.last_used})
             conn = self._create_connection(*self._conn_params(conn))
 
         conn.last_used = now
         conn.priority = priority  # stash current priority for release
         qsize = self._conn_pool.qsize()
-        LOG.debug(_("[%d] Acquired connection %s. %d connection(s) "
-                    "available."), rid, _conn_str(conn), qsize)
+        LOG.debug(_("[%(rid)d] Acquired connection %(conn)s. %(qsize)d "
+                    "connection(s) available."),
+                  {'rid': rid, 'conn': _conn_str(conn), 'qsize': qsize})
         if auto_login and self.auth_cookie(conn) is None:
             self._wait_for_login(conn, headers)
         return conn
@@ -147,16 +149,18 @@ class NvpApiClient(object):
         '''
         conn_params = self._conn_params(http_conn)
         if self._conn_params(http_conn) not in self._api_providers:
-            LOG.debug(_("[%d] Released connection '%s' is not an API provider "
-                        "for the cluster"), rid, _conn_str(http_conn))
+            LOG.debug(_("[%(rid)d] Released connection %(conn)s is not an "
+                        "API provider for the cluster"),
+                      {'rid': rid, 'conn': _conn_str(http_conn)})
             return
         elif hasattr(http_conn, "no_release"):
             return
 
         if bad_state:
             # Reconnect to provider.
-            LOG.warn(_("[%d] Connection returned in bad state, reconnecting "
-                       "to %s"), rid, _conn_str(http_conn))
+            LOG.warn(_("[%(rid)d] Connection returned in bad state, "
+                       "reconnecting to %(conn)s"),
+                     {'rid': rid, 'conn': _conn_str(http_conn)})
             http_conn = self._create_connection(*self._conn_params(http_conn))
             priority = self._next_conn_priority
             self._next_conn_priority += 1
@@ -179,9 +183,10 @@ class NvpApiClient(object):
             priority = http_conn.priority
 
         self._conn_pool.put((priority, http_conn))
-        LOG.debug(_("[%d] Released connection %s. %d connection(s) "
-                    "available."),
-                  rid, _conn_str(http_conn), self._conn_pool.qsize())
+        LOG.debug(_("[%(rid)d] Released connection %(conn)s. %(qsize)d "
+                    "connection(s) available."),
+                  {'rid': rid, 'conn': _conn_str(http_conn),
+                   'qsize': self._conn_pool.qsize()})
 
     def _wait_for_login(self, conn, headers=None):
         '''Block until a login has occurred for the current API provider.'''
index de8ad38218d622d2f4ee24267a371d24ee534dee..86e4f9e17e96df0acbbc5fefdd66231e7bb6134c 100644 (file)
@@ -87,13 +87,13 @@ class NvpApiRequest(object):
                                                     copy.copy(self._headers),
                                                     rid=self._rid()))
         if conn is None:
-            error = Exception("No API connections available")
+            error = Exception(_("No API connections available"))
             self._request_error = error
             return error
 
         url = self._url
-        LOG.debug(_("[%d] Issuing - request '%s'"),
-                  self._rid(), self._request_str(conn, url))
+        LOG.debug(_("[%(rid)d] Issuing - request %(conn)s"),
+                  {'rid': self._rid(), 'conn': self._request_str(conn, url)})
         issued_time = time.time()
         is_conn_error = False
         is_conn_service_unavail = False
@@ -117,26 +117,29 @@ class NvpApiRequest(object):
                 gen = self._api_client.nvp_config_gen
                 if gen:
                     headers["X-Nvp-Wait-For-Config-Generation"] = gen
-                    LOG.debug(_("Setting %s request header: '%s'"),
-                              'X-Nvp-Wait-For-Config-Generation', gen)
+                    LOG.debug(_("Setting X-Nvp-Wait-For-Config-Generation "
+                                "request header: '%s'"), gen)
                 try:
                     conn.request(self._method, url, self._body, headers)
                 except Exception as e:
-                    LOG.warn(_("[%d] Exception issuing request: '%s'"),
-                             self._rid(), e)
+                    LOG.warn(_("[%(rid)d] Exception issuing request: %(e)s"),
+                             {'rid': self._rid(), 'e': e})
                     raise e
 
                 response = conn.getresponse()
                 response.body = response.read()
                 response.headers = response.getheaders()
-                LOG.debug(_("[%d] Completed request '%s': %s (%0.2f seconds)"),
-                          self._rid(), self._request_str(conn, url),
-                          response.status, time.time() - issued_time)
+                LOG.debug(_("[%(rid)d] Completed request '%(conn)s': "
+                            "%(status)s (%(sec)0.2f seconds)"),
+                          {'rid': self._rid(),
+                           'conn': self._request_str(conn, url),
+                           'status': response.status,
+                           'sec': time.time() - issued_time})
 
                 new_gen = response.getheader('X-Nvp-Config-Generation', None)
                 if new_gen:
-                    LOG.debug(_("Reading '%s' response header: '%s'"),
-                              'X-Nvp-config-Generation', new_gen)
+                    LOG.debug(_("Reading X-Nvp-config-Generation response "
+                                "header: '%s'"), new_gen)
                     if (self._api_client.nvp_config_gen is None or
                         self._api_client.nvp_config_gen < int(new_gen)):
                         self._api_client.nvp_config_gen = int(new_gen)
@@ -174,8 +177,9 @@ class NvpApiRequest(object):
                 if url is None:
                     response.status = httplib.INTERNAL_SERVER_ERROR
                     break
-                LOG.info(_("[%d] Redirecting request to: '%s'"),
-                         self._rid(), self._request_str(conn, url))
+                LOG.info(_("[%(rid)d] Redirecting request to: %(conn)s"),
+                         {'rid': self._rid(),
+                          'conn': self._request_str(conn, url)})
 
             # If we receive any of these responses, then
             # our server did not process our request and may be in an
@@ -184,20 +188,21 @@ class NvpApiRequest(object):
             # which puts the conn on the back of the client's priority
             # queue.
             if response.status >= 500:
-                LOG.warn(_("[%d] Request '%s %s' received: %s"),
-                         self._rid(), self._method, self._url,
-                         response.status)
-                raise Exception('Server error return: %s' %
-                                response.status)
+                LOG.warn(_("[%(rid)d] Request '%(method) %(url)s' "
+                           "received: %(status)s"),
+                         {'rid': self._rid(), 'method': self._method,
+                          'url': self._url, 'status': response.status})
+                raise Exception(_('Server error return: %s'), response.status)
             return response
         except Exception as e:
             if isinstance(e, httplib.BadStatusLine):
-                msg = "Invalid server response"
+                msg = (_("Invalid server response"))
             else:
                 msg = unicode(e)
-            LOG.warn(_("[%d] Failed request '%s': '%s' (%0.2f seconds)"),
-                     self._rid(), self._request_str(conn, url), msg,
-                     time.time() - issued_time)
+            LOG.warn(_("[%(rid)d] Failed request '%(conn)s': '%(msg)s' "
+                       "(%(sec)0.2f seconds)"),
+                     {'rid': self._rid(), 'conn': self._request_str(conn, url),
+                      'msg': msg, 'sec': time.time() - issued_time})
             self._request_error = e
             is_conn_error = True
             return e
@@ -245,12 +250,12 @@ class NvpApiRequest(object):
                     url = result.path
                 return (conn, url)      # case 1
             else:
-                LOG.warn(_("[%d] Received invalid redirect location: '%s'"),
-                         self._rid(), url)
+                LOG.warn(_("[%(rid)d] Received invalid redirect location: "
+                           "'%(url)s'"), {'rid': self._rid(), 'url': url})
                 return (conn, None)     # case 3
         elif result.scheme not in ["http", "https"] or not result.hostname:
-            LOG.warn(_("[%d] Received malformed redirect location: %s"),
-                     self._rid(), url)
+            LOG.warn(_("[%(rid)d] Received malformed redirect "
+                       "location: %(url)s"), {'rid': self._rid(), 'url': url})
             return (conn, None)         # case 3
         # case 2, redirect location includes a scheme
         # so setup a new connection and authenticate
index 398dce4daafeae2b2805d7acf75692ea3845774d..30995caf7c196bb2648c21b799624ad0f1e9ae6d 100644 (file)
@@ -29,7 +29,7 @@ from quantum.plugins.nicira.nicira_nvp_plugin.api_client import request
 eventlet.monkey_patch()
 logging.basicConfig(level=logging.INFO)
 LOG = logging.getLogger(__name__)
-USER_AGENT = "NVP eventlet client/1.0"
+USER_AGENT = "NVP Quantum eventlet client/2.0"
 
 
 class NvpApiRequestEventlet(request.NvpApiRequest):
index 1a2b67bbfd129d19c51b520abbe8620606361d4b..df4a825ec04c87198fb0f981737ad9d9d94fe306 100644 (file)
@@ -253,7 +253,7 @@ def create_lswitch(cluster, tenant_id, display_name,
     except NvpApiClient.NvpApiException:
         raise exception.QuantumException()
     lswitch = json.loads(lswitch_res)
-    LOG.debug(_("Created logical switch: %s") % lswitch['uuid'])
+    LOG.debug(_("Created logical switch: %s"), lswitch['uuid'])
     return lswitch
 
 
@@ -471,12 +471,12 @@ def create_lport(cluster, lswitch_uuid, tenant_id, quantum_port_id,
                                      json.dumps(lport_obj),
                                      cluster=cluster)
     except NvpApiClient.ResourceNotFound as e:
-        LOG.error("Logical switch not found, Error: %s" % str(e))
+        LOG.error(_("Logical switch not found, Error: %s"), str(e))
         raise
 
     result = json.loads(resp_obj)
-    LOG.debug("Created logical port %s on logical swtich %s"
-              % (result['uuid'], lswitch_uuid))
+    LOG.debug(_("Created logical port %(result)s on logical swtich %(uuid)s"),
+              {'result': result['uuid'], 'uuid': lswitch_uuid})
     return result