Skip to content

Commit

Permalink
Ensure that l3 agent creates client session if necessary
Browse files Browse the repository at this point in the history
Fixes bug 1157090

Change-Id: I2ead0ef949d272bd512c913b3be992f66ee99437
  • Loading branch information
Gary Kotton committed Mar 19, 2013
1 parent 913586b commit a109f7e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 16 additions & 8 deletions quantum/agent/l3_agent.py
Expand Up @@ -117,14 +117,7 @@ def __init__(self, conf):

self.polling_interval = conf.polling_interval

self.qclient = client.Client(
username=self.conf.admin_user,
password=self.conf.admin_password,
tenant_name=self.conf.admin_tenant_name,
auth_url=self.conf.auth_url,
auth_strategy=self.conf.auth_strategy,
region_name=self.conf.auth_region
)
self.qclient = None

if self.conf.use_namespaces:
self._destroy_router_namespaces(self.conf.router_id)
Expand Down Expand Up @@ -168,16 +161,31 @@ def _create_router_namespace(self, ri):
ip_wrapper = ip_wrapper_root.ensure_namespace(ri.ns_name())
ip_wrapper.netns.execute(['sysctl', '-w', 'net.ipv4.ip_forward=1'])

def client_create(self):
self.qclient = client.Client(
username=self.conf.admin_user,
password=self.conf.admin_password,
tenant_name=self.conf.admin_tenant_name,
auth_url=self.conf.auth_url,
auth_strategy=self.conf.auth_strategy,
region_name=self.conf.auth_region
)
LOG.debug(_("Client session established!"))

def daemon_loop(self):
#TODO(danwent): this simple diff logic does not handle if
# details of a router port (e.g., IP, mac) are changed behind
# our back. Will fix this properly with update notifications.

while True:
if not self.qclient:
self.client_create()

try:
self.do_single_loop()
except:
LOG.exception("Error running l3_nat daemon_loop")
self.qclient = None

time.sleep(self.polling_interval)

Expand Down
2 changes: 2 additions & 0 deletions quantum/tests/unit/test_l3_agent.py
Expand Up @@ -179,6 +179,7 @@ def testAgentRemoveFloatingIP(self):
def testProcessRouter(self):

agent = l3_agent.L3NATAgent(self.conf)
agent.client_create()
router_id = _uuid()
ri = l3_agent.RouterInfo(router_id, self.conf.root_helper,
self.conf.use_namespaces)
Expand Down Expand Up @@ -231,6 +232,7 @@ def fake_list_ports1(**kwargs):

def testSingleLoopRouterRemoval(self):
agent = l3_agent.L3NATAgent(self.conf)
agent.client_create()

self.client_inst.list_ports.return_value = {'ports': []}

Expand Down

0 comments on commit a109f7e

Please sign in to comment.