Merge "atomically setup ovs ports"

This commit is contained in:
Jenkins 2013-12-05 09:52:40 +00:00 committed by Gerrit Code Review
commit 22a311bd8d
2 changed files with 25 additions and 49 deletions

View File

@ -247,29 +247,25 @@ class OVSBridge(BaseOVS):
def add_tunnel_port(self, port_name, remote_ip, local_ip, def add_tunnel_port(self, port_name, remote_ip, local_ip,
tunnel_type=constants.TYPE_GRE, tunnel_type=constants.TYPE_GRE,
vxlan_udp_port=constants.VXLAN_UDP_PORT): vxlan_udp_port=constants.VXLAN_UDP_PORT):
self.run_vsctl(["--", "--may-exist", "add-port", self.br_name, vsctl_command = ["--", "--may-exist", "add-port", self.br_name,
port_name]) port_name]
self.set_db_attribute("Interface", port_name, "type", tunnel_type) vsctl_command.extend(["--", "set", "Interface", port_name,
"type=%s" % tunnel_type])
if tunnel_type == constants.TYPE_VXLAN: if tunnel_type == constants.TYPE_VXLAN:
# Only set the VXLAN UDP port if it's not the default # Only set the VXLAN UDP port if it's not the default
if vxlan_udp_port != constants.VXLAN_UDP_PORT: if vxlan_udp_port != constants.VXLAN_UDP_PORT:
self.set_db_attribute("Interface", port_name, vsctl_command.append("options:dst_port=%s" % vxlan_udp_port)
"options:dst_port", vsctl_command.extend(["options:remote_ip=%s" % remote_ip,
vxlan_udp_port) "options:local_ip=%s" % local_ip,
self.set_db_attribute("Interface", port_name, "options:remote_ip", "options:in_key=flow",
remote_ip) "options:out_key=flow"])
self.set_db_attribute("Interface", port_name, "options:local_ip", self.run_vsctl(vsctl_command)
local_ip)
self.set_db_attribute("Interface", port_name, "options:in_key", "flow")
self.set_db_attribute("Interface", port_name, "options:out_key",
"flow")
return self.get_port_ofport(port_name) return self.get_port_ofport(port_name)
def add_patch_port(self, local_name, remote_name): def add_patch_port(self, local_name, remote_name):
self.run_vsctl(["add-port", self.br_name, local_name]) self.run_vsctl(["add-port", self.br_name, local_name,
self.set_db_attribute("Interface", local_name, "type", "patch") "--", "set", "Interface", local_name,
self.set_db_attribute("Interface", local_name, "options:peer", "type=patch", "options:peer=%s" % remote_name])
remote_name)
return self.get_port_ofport(local_name) return self.get_port_ofport(local_name)
def db_get_map(self, table, record, column): def db_get_map(self, table, record, column):

View File

@ -293,31 +293,16 @@ class OVS_Lib_Test(base.BaseTestCase):
local_ip = "1.1.1.1" local_ip = "1.1.1.1"
remote_ip = "9.9.9.9" remote_ip = "9.9.9.9"
ofport = "6" 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) # Each element is a tuple of (expected mock call, return_value)
expected_calls_and_values = [ expected_calls_and_values = [
(mock.call(["ovs-vsctl", self.TO, '--', "--may-exist", "add-port", (mock.call(command, root_helper=self.root_helper), None),
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(["ovs-vsctl", self.TO, "get", (mock.call(["ovs-vsctl", self.TO, "get",
"Interface", pname, "ofport"], "Interface", pname, "ofport"],
root_helper=self.root_helper), root_helper=self.root_helper),
@ -337,16 +322,11 @@ class OVS_Lib_Test(base.BaseTestCase):
ofport = "6" ofport = "6"
# Each element is a tuple of (expected mock call, return_value) # 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 = [ expected_calls_and_values = [
(mock.call(["ovs-vsctl", self.TO, "add-port", (mock.call(command, root_helper=self.root_helper),
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),
None), None),
(mock.call(["ovs-vsctl", self.TO, "get", (mock.call(["ovs-vsctl", self.TO, "get",
"Interface", pname, "ofport"], "Interface", pname, "ofport"],