From 3ed4ede17d8ab1da9b74e623523fbe3e7b2f38e8 Mon Sep 17 00:00:00 2001 From: Jan Orel Date: Fri, 18 Jan 2019 15:44:44 +0100 Subject: [PATCH] B #2629 Prevent race-condition when spawning multiple VMs --- src/mad/ruby/scripts_common.rb | 4 ++-- src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb | 2 +- src/vnm_mad/remotes/vxlan/vxlan.rb | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/mad/ruby/scripts_common.rb b/src/mad/ruby/scripts_common.rb index 29642ffd25..4381299a9b 100644 --- a/src/mad/ruby/scripts_common.rb +++ b/src/mad/ruby/scripts_common.rb @@ -75,11 +75,11 @@ module OpenNebula # Executes a command, if it fails returns error message and exits # If a second parameter is present it is used as the error message when # the command fails - def self.exec_and_log(command, message=nil) + def self.exec_and_log(command, message=nil, allowed_return_code=0) output=`#{command} 2>&1 1>/dev/null` code=$?.exitstatus - if code!=0 + if code!=0 && code!=allowed_return_code log_error "Command \"#{command}\" failed." log_error output if !message diff --git a/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb b/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb index 33ed662ff3..1bd32f253e 100644 --- a/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb +++ b/src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb @@ -391,7 +391,7 @@ private def create_bridge return if @bridges.keys.include? @nic[:bridge] - OpenNebula.exec_and_log("#{command(:ovs_vsctl)} add-br #{@nic[:bridge]}") + OpenNebula.exec_and_log("#{command(:ovs_vsctl)} --may-exist add-br #{@nic[:bridge]}") set_bridge_options diff --git a/src/vnm_mad/remotes/vxlan/vxlan.rb b/src/vnm_mad/remotes/vxlan/vxlan.rb index a74f026d6c..1c67d467e4 100644 --- a/src/vnm_mad/remotes/vxlan/vxlan.rb +++ b/src/vnm_mad/remotes/vxlan/vxlan.rb @@ -65,9 +65,11 @@ module VXLAN ip_link_conf << "#{option} #{value} " end + # `ip link add ...` returns 2 when vxlan device already exists + # allow it to prevent race conditions OpenNebula.exec_and_log("#{command(:ip)} link add #{@nic[@attr_vlan_dev]}"\ " #{mtu} type vxlan id #{@nic[@attr_vlan_id]} #{group} #{ttl}"\ - " #{tep} #{ip_link_conf}") + " #{tep} #{ip_link_conf}", nil, 2) OpenNebula.exec_and_log("#{command(:ip)} link set #{@nic[@attr_vlan_dev]} up") end