When ryu starts up, related openstack components (keystone and neutron)
might not be running. They might be during start up process.
In that case, quantum_adapter results in exception as follows.
So in order to avoid ordering of starting up, lazily initialize neutoron
api.

> hub: uncaught exception: Traceback (most recent call last):
>   File "/ryu/lib/hub.py", line 48, in _launch
>     func(*args, **kwargs)
>   File "/ryu/base/app_manager.py", line 173, in _event_loop
>     handler(ev)
>   File "/ryu/app/quantum_adapter.py", line 398, in dp_handler
>     ovs_switch = self._get_ovs_switch(dpid)
>   File "/ryu/app/quantum_adapter.py", line 381, in _get_ovs_switch
>     ovs_switch = OVSSwitch(dpid, self.nw, self.ifaces, self.logger)
>   File "/ryu/app/quantum_adapter.py", line 167, in __init__
>     token = _get_auth_token(logger)
>   File "/ryu/app/quantum_adapter.py", line 90, in _get_auth_token
>     httpclient.authenticate()
>   File "/neutronclient/client.py", line 211, in authenticate
>     content_type="application/json")
>   File "/neutronclient/client.py", line 141, in _cs_request
>     raise exceptions.ConnectionFailed(reason=e)
> ConnectionFailed: Connection to neutron failed: [Errno 111] ECONNREFUSED

Signed-off-by: Isaku Yamahata <[email protected]>
---
 ryu/app/quantum_adapter.py |   16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/ryu/app/quantum_adapter.py b/ryu/app/quantum_adapter.py
index b6ea8b8..f6b267d 100644
--- a/ryu/app/quantum_adapter.py
+++ b/ryu/app/quantum_adapter.py
@@ -132,16 +132,11 @@ class OVSPort(object):
 class OVSSwitch(object):
     def __init__(self, dpid, nw, ifaces, logger):
         # TODO: clean up
-        token = None
-        if CONF.neutron_auth_strategy:
-            token = _get_auth_token(logger)
-        q_api = _get_quantum_client(token)
-
         self.dpid = dpid
         self.network_api = nw
         self.ifaces = ifaces
         self.logger = logger
-        self.q_api = q_api
+        self._q_api = None      # lazy initialization
         self.ctrl_addr = CONF.neutron_controller_addr
         if not self.ctrl_addr:
             raise ValueError('option neutron_controler_addr must be speicfied')
@@ -154,6 +149,15 @@ class OVSSwitch(object):
 
         super(OVSSwitch, self).__init__()
 
+    @property
+    def q_api(self):
+        if self._q_api is None:
+            token = None
+            if CONF.neutron_auth_strategy:
+                token = _get_auth_token(self.logger)
+            self._q_api = _get_quantum_client(token)
+        return self._q_api
+
     def set_ovsdb_addr(self, dpid, ovsdb_addr):
         # easy check if the address format valid
         self.logger.debug('set_ovsdb_addr dpid %s ovsdb_addr %s',
-- 
1.7.10.4


------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to