]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
atomically setup ovs ports
authorYong Sheng Gong <gongysh@unitedstack.com>
Tue, 3 Dec 2013 03:47:33 +0000 (11:47 +0800)
committerYong Sheng Gong <gongysh@unitedstack.com>
Tue, 3 Dec 2013 06:50:13 +0000 (14:50 +0800)
Change-Id: I7c4d4cac8150439f26b81d5727a5b7efb0a115f4
Closes-Bug: #1257014

neutron/agent/linux/ovs_lib.py
neutron/tests/unit/openvswitch/test_ovs_lib.py

index 6857e9fb89ce6334422df8d69eda5a62d7f898cd..876557e3a008d2b8e4bf53c1bcfe21216d6b1512 100644 (file)
@@ -247,29 +247,25 @@ class OVSBridge(BaseOVS):
     def add_tunnel_port(self, port_name, remote_ip, local_ip,
                         tunnel_type=constants.TYPE_GRE,
                         vxlan_udp_port=constants.VXLAN_UDP_PORT):
-        self.run_vsctl(["--", "--may-exist", "add-port", self.br_name,
-                       port_name])
-        self.set_db_attribute("Interface", port_name, "type", tunnel_type)
+        vsctl_command = ["--", "--may-exist", "add-port", self.br_name,
+                         port_name]
+        vsctl_command.extend(["--", "set", "Interface", port_name,
+                              "type=%s" % tunnel_type])
         if tunnel_type == constants.TYPE_VXLAN:
             # Only set the VXLAN UDP port if it's not the default
             if vxlan_udp_port != constants.VXLAN_UDP_PORT:
-                self.set_db_attribute("Interface", port_name,
-                                      "options:dst_port",
-                                      vxlan_udp_port)
-        self.set_db_attribute("Interface", port_name, "options:remote_ip",
-                              remote_ip)
-        self.set_db_attribute("Interface", port_name, "options:local_ip",
-                              local_ip)
-        self.set_db_attribute("Interface", port_name, "options:in_key", "flow")
-        self.set_db_attribute("Interface", port_name, "options:out_key",
-                              "flow")
+                vsctl_command.append("options:dst_port=%s" % vxlan_udp_port)
+        vsctl_command.extend(["options:remote_ip=%s" % remote_ip,
+                              "options:local_ip=%s" % local_ip,
+                              "options:in_key=flow",
+                              "options:out_key=flow"])
+        self.run_vsctl(vsctl_command)
         return self.get_port_ofport(port_name)
 
     def add_patch_port(self, local_name, remote_name):
-        self.run_vsctl(["add-port", self.br_name, local_name])
-        self.set_db_attribute("Interface", local_name, "type", "patch")
-        self.set_db_attribute("Interface", local_name, "options:peer",
-                              remote_name)
+        self.run_vsctl(["add-port", self.br_name, local_name,
+                        "--", "set", "Interface", local_name,
+                        "type=patch", "options:peer=%s" % remote_name])
         return self.get_port_ofport(local_name)
 
     def db_get_map(self, table, record, column):
index f313a12db333dbb1948c905bfbf57ce69b34ea17..707e628c315ba6b5f61265a3f04532888e591b74 100644 (file)
@@ -293,31 +293,16 @@ class OVS_Lib_Test(base.BaseTestCase):
         local_ip = "1.1.1.1"
         remote_ip = "9.9.9.9"
         ofport = "6"
-
+        command = ["ovs-vsctl", self.TO, '--', "--may-exist", "add-port",
+                   self.BR_NAME, pname]
+        command.extend(["--", "set", "Interface", pname])
+        command.extend(["type=gre", "options:remote_ip=" + remote_ip,
+                        "options:local_ip=" + local_ip,
+                        "options:in_key=flow",
+                        "options:out_key=flow"])
         # Each element is a tuple of (expected mock call, return_value)
         expected_calls_and_values = [
-            (mock.call(["ovs-vsctl", self.TO, '--', "--may-exist", "add-port",
-                        self.BR_NAME, pname], root_helper=self.root_helper),
-             None),
-            (mock.call(["ovs-vsctl", self.TO, "set", "Interface",
-                        pname, "type=gre"], root_helper=self.root_helper),
-             None),
-            (mock.call(["ovs-vsctl", self.TO, "set", "Interface",
-                        pname, "options:remote_ip=" + remote_ip],
-                       root_helper=self.root_helper),
-             None),
-            (mock.call(["ovs-vsctl", self.TO, "set", "Interface",
-                        pname, "options:local_ip=" + local_ip],
-                       root_helper=self.root_helper),
-             None),
-            (mock.call(["ovs-vsctl", self.TO, "set", "Interface",
-                        pname, "options:in_key=flow"],
-                       root_helper=self.root_helper),
-             None),
-            (mock.call(["ovs-vsctl", self.TO, "set", "Interface",
-                        pname, "options:out_key=flow"],
-                       root_helper=self.root_helper),
-             None),
+            (mock.call(command, root_helper=self.root_helper), None),
             (mock.call(["ovs-vsctl", self.TO, "get",
                         "Interface", pname, "ofport"],
                        root_helper=self.root_helper),
@@ -337,16 +322,11 @@ class OVS_Lib_Test(base.BaseTestCase):
         ofport = "6"
 
         # Each element is a tuple of (expected mock call, return_value)
+        command = ["ovs-vsctl", self.TO, "add-port", self.BR_NAME, pname]
+        command.extend(["--", "set", "Interface", pname])
+        command.extend(["type=patch", "options:peer=" + peer])
         expected_calls_and_values = [
-            (mock.call(["ovs-vsctl", self.TO, "add-port",
-                        self.BR_NAME, pname], root_helper=self.root_helper),
-             None),
-            (mock.call(["ovs-vsctl", self.TO, "set", "Interface",
-                        pname, "type=patch"], root_helper=self.root_helper),
-             None),
-            (mock.call(["ovs-vsctl", self.TO, "set",
-                        "Interface", pname, "options:peer=" + peer],
-                       root_helper=self.root_helper),
+            (mock.call(command, root_helper=self.root_helper),
              None),
             (mock.call(["ovs-vsctl", self.TO, "get",
                         "Interface", pname, "ofport"],