components/openstack/neutron/files/neutron-l3-agent
branchs11-update
changeset 3323 b4b74d363c31
parent 3196 4c06db2d9388
child 3998 5bd484384122
--- a/components/openstack/neutron/files/neutron-l3-agent	Tue Sep 23 10:06:56 2014 -0700
+++ b/components/openstack/neutron/files/neutron-l3-agent	Tue Sep 23 10:12:34 2014 -0700
@@ -81,7 +81,8 @@
         if not prog.search(ipf):
             continue
         # capture the IP pool name
-        ippool_names.append(ipf.split('pool/')[1])
+        if 'pool/' in ipf:
+            ippool_names.append(ipf.split('pool/')[1])
 
         try:
             # remove the IP Filter rule
@@ -112,32 +113,9 @@
     except CalledProcessError as err:
         print "failed to kill the SMF contract: %s" % (err)
         return smf_include.SMF_EXIT_ERR_FATAL
-    # remove VNICs associated with L3 agent
-    cmd = ["/usr/sbin/ipadm", "show-if", "-p", "-o", "ifname"]
-    p = Popen(cmd, stdout=PIPE, stderr=PIPE)
-    output, error = p.communicate()
-    if p.returncode != 0:
-        print "failed to retrieve IP interface names"
-        return smf_include.SMF_EXIT_ERR_CONFIG
 
-    ifnames = output.splitlines()
-    # L3 agent datalinks are always 15 characters in length. They start
-    # with either 'l3i' or 'l3e', end with '_0', and in between they are
-    # hexadecimal digits.
-    prog = re.compile('l3[ie][0-9A-Fa-f\_]{10}_0')
-    for ifname in ifnames:
-        if not prog.search(ifname):
-            continue
-        try:
-            # first remove the IP
-            check_call(["/usr/bin/pfexec", "/usr/sbin/ipadm", "delete-ip",
-                        ifname])
-            # next remove the VNIC
-            check_call(["/usr/bin/pfexec", "/usr/sbin/dladm", "delete-vnic",
-                        ifname])
-        except CalledProcessError as err:
-            print "failed to remove datalinks used by L3 agent: %s" % (err)
-            return smf_include.SMF_EXIT_ERR_FATAL
+    # We need to first remove the IP filter rules and then remove
+    # the IP interfaces on which the rules were applied.
 
     # remove IPv4 Filter rules added by neutron-l3-agent
     rv = remove_ipfilter_rules(4)
@@ -173,6 +151,33 @@
             print "failed to remove IP NAT rule %s: %s" % (ipnat_rule, err)
             return smf_include.SMF_EXIT_ERR_FATAL
 
+    # remove VNICs associated with L3 agent
+    cmd = ["/usr/sbin/ipadm", "show-if", "-p", "-o", "ifname"]
+    p = Popen(cmd, stdout=PIPE, stderr=PIPE)
+    output, error = p.communicate()
+    if p.returncode != 0:
+        print "failed to retrieve IP interface names"
+        return smf_include.SMF_EXIT_ERR_CONFIG
+
+    ifnames = output.splitlines()
+    # L3 agent datalinks are always 15 characters in length. They start
+    # with either 'l3i' or 'l3e', end with '_0', and in between they are
+    # hexadecimal digits.
+    prog = re.compile('l3[ie][0-9A-Fa-f\_]{10}_0')
+    for ifname in ifnames:
+        if not prog.search(ifname):
+            continue
+        try:
+            # first remove the IP
+            check_call(["/usr/bin/pfexec", "/usr/sbin/ipadm", "delete-ip",
+                        ifname])
+            # next remove the VNIC
+            check_call(["/usr/bin/pfexec", "/usr/sbin/dladm", "delete-vnic",
+                        ifname])
+        except CalledProcessError as err:
+            print "failed to remove datalinks used by L3 agent: %s" % (err)
+            return smf_include.SMF_EXIT_ERR_FATAL
+
     return smf_include.SMF_EXIT_OK
 
 if __name__ == "__main__":