From a3c944bb1860faeb4eb0e90534ace07c1e869ea1 Mon Sep 17 00:00:00 2001 From: Yong Sheng Gong Date: Tue, 3 Dec 2013 11:47:33 +0800 Subject: [PATCH] atomically setup ovs ports Change-Id: I7c4d4cac8150439f26b81d5727a5b7efb0a115f4 Closes-Bug: #1257014 --- neutron/agent/linux/ovs_lib.py | 30 ++++++------- .../tests/unit/openvswitch/test_ovs_lib.py | 44 +++++-------------- 2 files changed, 25 insertions(+), 49 deletions(-) diff --git a/neutron/agent/linux/ovs_lib.py b/neutron/agent/linux/ovs_lib.py index 6857e9fb8..876557e3a 100644 --- a/neutron/agent/linux/ovs_lib.py +++ b/neutron/agent/linux/ovs_lib.py @@ -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): diff --git a/neutron/tests/unit/openvswitch/test_ovs_lib.py b/neutron/tests/unit/openvswitch/test_ovs_lib.py index f313a12db..707e628c3 100644 --- a/neutron/tests/unit/openvswitch/test_ovs_lib.py +++ b/neutron/tests/unit/openvswitch/test_ovs_lib.py @@ -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"], -- 2.45.2