]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Exit rpc_loop when SIGTERM is recieved in ovs-agent
authorJakub Libosvar <libosvar@redhat.com>
Wed, 25 Jun 2014 13:06:13 +0000 (15:06 +0200)
committerJakub Libosvar <libosvar@redhat.com>
Thu, 26 Jun 2014 08:20:57 +0000 (10:20 +0200)
Previously ovs-agent exited with exit code 1 after SIGTERM was received.
SIGTERM should shutdown agent gracefully and exit code should be 0.

Closes-Bug: #1334264
Change-Id: I23e81cee5ae9e9fdabbe1377420b0902f47be8a7

neutron/plugins/openvswitch/agent/ovs_neutron_agent.py

index ccc5ff246ac0fd3c1536a653605b7127de0ea450..58527fadac8917509a6d319e142dc3a1c5cd8d54 100644 (file)
@@ -213,6 +213,7 @@ class OVSNeutronAgent(n_rpc.RpcCallback,
                                               root_helper)
         # Initialize iteration counter
         self.iter_num = 0
+        self.run_daemon_loop = True
 
     def _check_arp_responder_support(self):
         '''Check if OVS supports to modify ARP headers.
@@ -1313,7 +1314,7 @@ class OVSNeutronAgent(n_rpc.RpcCallback,
         ancillary_ports = set()
         tunnel_sync = True
         ovs_restarted = False
-        while True:
+        while self.run_daemon_loop:
             start = time.time()
             port_stats = {'regular': {'added': 0,
                                       'updated': 0,
@@ -1439,9 +1440,9 @@ class OVSNeutronAgent(n_rpc.RpcCallback,
 
             self.rpc_loop(polling_manager=pm)
 
-
-def handle_sigterm(signum, frame):
-    sys.exit(1)
+    def _handle_sigterm(self, signum, frame):
+        LOG.debug("Agent caught SIGTERM, quitting daemon loop.")
+        self.run_daemon_loop = False
 
 
 def create_agent_config_map(config):
@@ -1504,12 +1505,11 @@ def main():
         cfg.CONF.set_default('ip_lib_force_root', True)
 
     agent = OVSNeutronAgent(**agent_config)
-    signal.signal(signal.SIGTERM, handle_sigterm)
+    signal.signal(signal.SIGTERM, agent._handle_sigterm)
 
     # Start everything.
     LOG.info(_("Agent initialized successfully, now running... "))
     agent.daemon_loop()
-    sys.exit(0)
 
 
 if __name__ == "__main__":