Fix the bug that prevent assign 2 Cluster to one controller

In some cases Ruby uses pointer instead of copying something for
optimization. But it allows to side effects. It was cause of that bug.
After cloning one variable by var.dup the problem was fixed.

Change-Id: Ide58c184f4cb9b655e11a13afb8c05bfc5149ab9
Closes-bug: #1625092
This commit is contained in:
Igor Gajsin 2016-09-20 15:35:08 +03:00
parent 337e8b8b6f
commit b19b88653d
1 changed files with 9 additions and 12 deletions

View File

@ -13,9 +13,11 @@
controllersp = args[4].any? {|role| role.include?("controller")} controllersp = args[4].any? {|role| role.include?("controller")}
primaryp = args[4].any? {|role| role.include?("primary")} primaryp = args[4].any? {|role| role.include?("primary")}
agents = [] agents = []
vcenter.each {|vc| vcenter.each {|vc|
if (vc["target_node"] == "controllers" and controllersp) or current_node == vc["target_node"] if (vc["target_node"] == "controllers" and controllersp) or current_node == vc["target_node"]
agent = {} agent = {}
ns = netmaps.dup
agent["host"] = vc["availability_zone_name"] + "-" + vc["service_name"] agent["host"] = vc["availability_zone_name"] + "-" + vc["service_name"]
agent["vsphere_hostname"] = vc["vc_host"] agent["vsphere_hostname"] = vc["vc_host"]
agent["vsphere_login"] = vc["vc_user"] agent["vsphere_login"] = vc["vc_user"]
@ -23,18 +25,13 @@
agent["vsphere_insecure"] = vc["vc_insecure"] agent["vsphere_insecure"] = vc["vc_insecure"]
agent["vsphere_ca_file"] = vc["vc_ca_file"] agent["vsphere_ca_file"] = vc["vc_ca_file"]
cluster = vc["vc_cluster"] cluster = vc["vc_cluster"]
netmaps = netmaps.keep_if {|s| s =~ /^#{cluster}/}.first.split(":") ns = ns.keep_if {|s| s =~ /^#{cluster}/}.first.split(":")
if netmaps.length == 4 vds = ns[1]
vds = netmaps[1] uplinks = false
uplinks = netmaps[2] + ":" + netmaps[3] if ns.length == 4
elsif netmaps.length == 3 uplinks = ns[2] + ":" + ns[3]
vds = netmaps[1] elsif ns.length == 3
uplinks = netmaps[2] uplinks = ns[2]
elsif netmaps.length == 2
vds = netmaps[1]
uplinks = false
else
raise 'Wrong vmware_dvs_net_maps'
end end
agent["network_maps"] = physnet + ":" + vds agent["network_maps"] = physnet + ":" + vds
agent["uplink_maps"] = physnet + ":" + uplinks if uplinks agent["uplink_maps"] = physnet + ":" + uplinks if uplinks