From 30a79867cf7a02f6a656dc2bbc6289f3e3c99a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tino=20V=C3=A1zquez?= Date: Tue, 10 Jan 2023 13:13:46 +0100 Subject: [PATCH] L #-: Remove unneeded exceptions (cherry picked from commit 46cca6d6cd7c3b5e85ad6f4fb3adbfc7362d0fd7) --- src/oneprovision/lib/provision/ansible.rb | 16 +- .../models/OpenNebula2FA/sunstone_optp.rb | 2 - src/vmm_mad/remotes/az/az_driver.rb | 2 - .../remotes/lib/vcenter_driver/datacenter.rb | 42 +++-- .../remotes/lib/vcenter_driver/rest_client.rb | 32 ++-- .../remotes/lib/vcenter_driver/vi_client.rb | 144 +++++++++--------- src/vnm_mad/remotes/lib/vlan.rb | 2 - 7 files changed, 106 insertions(+), 134 deletions(-) diff --git a/src/oneprovision/lib/provision/ansible.rb b/src/oneprovision/lib/provision/ansible.rb index cb07b6af29..168a849c8b 100644 --- a/src/oneprovision/lib/provision/ansible.rb +++ b/src/oneprovision/lib/provision/ansible.rb @@ -185,8 +185,6 @@ module OneProvision end [0, @facts] - rescue StandardError => e - raise e end # Checks ssh connection @@ -281,17 +279,13 @@ module OneProvision when /^fatal: \[([^\]]+)\]: .* => ({.*})$/i host = Regexp.last_match(1) - begin - match = JSON.parse(Regexp.last_match(2)) + match = JSON.parse(Regexp.last_match(2)) - msg = match['msg'] - msg = match['reason'] if msg.nil? + msg = match['msg'] + msg = match['reason'] if msg.nil? - text = msg.strip.tr("\n", ' ') - text = "- #{text}" - rescue StandardError => e - raise e - end + text = msg.strip.tr("\n", ' ') + text = "- #{text}" when /^fatal: \[([^\]]+)\]: .* =>/i host = Regexp.last_match(1) end diff --git a/src/sunstone/models/OpenNebula2FA/sunstone_optp.rb b/src/sunstone/models/OpenNebula2FA/sunstone_optp.rb index e4744da914..270fc5d68d 100644 --- a/src/sunstone/models/OpenNebula2FA/sunstone_optp.rb +++ b/src/sunstone/models/OpenNebula2FA/sunstone_optp.rb @@ -33,8 +33,6 @@ class SunstoneOPTP @totp.verify(token, :drift_ahead => @five_minutes, :drift_behind => @five_minutes) - rescue StandardError => e - raise e end def provisioning_uri(account_name) diff --git a/src/vmm_mad/remotes/az/az_driver.rb b/src/vmm_mad/remotes/az/az_driver.rb index 239e8b004e..d97eb32c59 100755 --- a/src/vmm_mad/remotes/az/az_driver.rb +++ b/src/vmm_mad/remotes/az/az_driver.rb @@ -374,8 +374,6 @@ class AzureDriver end rescue ThreadError nil - rescue StandardError - raise end end end diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/datacenter.rb b/src/vmm_mad/remotes/lib/vcenter_driver/datacenter.rb index 8cc0e1a682..fcab2d3fff 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/datacenter.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/datacenter.rb @@ -929,30 +929,26 @@ module VCenterDriver spec.configSpec.maxMtu = mtu # The DVS must be created in the networkFolder of the datacenter - begin - dvs_creation_task = @item - .networkFolder - .CreateDVS_Task( - :spec => spec - ) - dvs_creation_task.wait_for_completion + dvs_creation_task = @item + .networkFolder + .CreateDVS_Task( + :spec => spec + ) + dvs_creation_task.wait_for_completion - # If task finished successfuly we rename the uplink portgroup - dvs = nil - if dvs_creation_task.info.state == 'success' - dvs = dvs_creation_task.info.result - dvs - .config - .uplinkPortgroup[0] - .Rename_Task( - :newName => "#{switch_name}-uplink-pg" - ).wait_for_completion - else - raise "The Distributed vSwitch #{switch_name} \ - could not be created. " - end - rescue StandardError => e - raise e + # If task finished successfuly we rename the uplink portgroup + dvs = nil + if dvs_creation_task.info.state == 'success' + dvs = dvs_creation_task.info.result + dvs + .config + .uplinkPortgroup[0] + .Rename_Task( + :newName => "#{switch_name}-uplink-pg" + ).wait_for_completion + else + raise "The Distributed vSwitch #{switch_name} \ + could not be created. " end @net_rollback << { diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/rest_client.rb b/src/vmm_mad/remotes/lib/vcenter_driver/rest_client.rb index 859b3e0483..b261618c96 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/rest_client.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/rest_client.rb @@ -69,25 +69,21 @@ module VCenterDriver end def self.new_from_host(host_id) - begin - client = OpenNebula::Client.new - host = OpenNebula::Host.new_with_id(host_id, client) - rc = host.info(true) - if OpenNebula.is_error?(rc) - raise "Could not get host info for ID: \ - #{host_id} - #{rc.message}" - end - - connection = { - :hostname => host['TEMPLATE/VCENTER_HOST'], - :username => host['TEMPLATE/VCENTER_USER'], - :password => host['TEMPLATE/VCENTER_PASSWORD'] - } - - new(connection) - rescue StandardError => e - raise e + client = OpenNebula::Client.new + host = OpenNebula::Host.new_with_id(host_id, client) + rc = host.info(true) + if OpenNebula.is_error?(rc) + raise "Could not get host info for ID: \ + #{host_id} - #{rc.message}" end + + connection = { + :hostname => host['TEMPLATE/VCENTER_HOST'], + :username => host['TEMPLATE/VCENTER_USER'], + :password => host['TEMPLATE/VCENTER_PASSWORD'] + } + + new(connection) end def get_or_create_tag( diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/vi_client.rb b/src/vmm_mad/remotes/lib/vcenter_driver/vi_client.rb index e213d504ee..0446d9a1ca 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/vi_client.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/vi_client.rb @@ -140,90 +140,82 @@ module VCenterDriver end def self.new_from_host(host_id, client = nil) - begin - client = OpenNebula::Client.new if client.nil? - host = OpenNebula::Host.new_with_id(host_id, client) - rc = host.info(true) - if OpenNebula.is_error?(rc) - raise "Could not get host info for \ - ID: #{host_id} - #{rc.message}" - end - - connection = { - :host => host['TEMPLATE/VCENTER_HOST'], - :user => host['TEMPLATE/VCENTER_USER'], - :rp => host['TEMPLATE/VCENTER_RESOURCE_POOL'], - :ccr => host['TEMPLATE/VCENTER_CCR_REF'], - :password => host['TEMPLATE/VCENTER_PASSWORD'] - } - - vc_port = host['TEMPLATE/VCENTER_PORT'] - connection[:port] = vc_port unless vc_port.nil? - - new(connection, host_id) - rescue StandardError => e - raise e + client = OpenNebula::Client.new if client.nil? + host = OpenNebula::Host.new_with_id(host_id, client) + rc = host.info(true) + if OpenNebula.is_error?(rc) + raise "Could not get host info for \ + ID: #{host_id} - #{rc.message}" end + + connection = { + :host => host['TEMPLATE/VCENTER_HOST'], + :user => host['TEMPLATE/VCENTER_USER'], + :rp => host['TEMPLATE/VCENTER_RESOURCE_POOL'], + :ccr => host['TEMPLATE/VCENTER_CCR_REF'], + :password => host['TEMPLATE/VCENTER_PASSWORD'] + } + + vc_port = host['TEMPLATE/VCENTER_PORT'] + connection[:port] = vc_port unless vc_port.nil? + + new(connection, host_id) end def self.new_from_datastore(datastore_id) - begin - client = OpenNebula::Client.new - datastore = - OpenNebula::Datastore + client = OpenNebula::Client.new + datastore = + OpenNebula::Datastore + .new_with_id( + datastore_id, + client + ) + rc = datastore.info + if OpenNebula.is_error?(rc) + raise "Could not get datastore info \ + for ID: #{datastore_id} - #{rc.message}" + end + + vcenter_id = datastore['TEMPLATE/VCENTER_INSTANCE_ID'] + + host_pool = OpenNebula::HostPool.new(client) + rc = host_pool.info + if OpenNebula.is_error?(rc) + raise "Could not get hosts information - #{rc.message}" + end + + user = '' + password = '' + port = 0 + host_pool.each do |host| + vc_instance_id = host['TEMPLATE/VCENTER_INSTANCE_ID'] + next unless vc_instance_id == vcenter_id + + host_decrypted = + OpenNebula::Host .new_with_id( - datastore_id, + host['ID'], client ) - rc = datastore.info - if OpenNebula.is_error?(rc) - raise "Could not get datastore info \ - for ID: #{datastore_id} - #{rc.message}" - end - - vcenter_id = datastore['TEMPLATE/VCENTER_INSTANCE_ID'] - - host_pool = OpenNebula::HostPool.new(client) - rc = host_pool.info - if OpenNebula.is_error?(rc) - raise "Could not get hosts information - #{rc.message}" - end - - user = '' - password = '' - port = 0 - host_pool.each do |host| - vc_instance_id = host['TEMPLATE/VCENTER_INSTANCE_ID'] - next unless vc_instance_id == vcenter_id - - host_decrypted = - OpenNebula::Host - .new_with_id( - host['ID'], - client - ) - host_decrypted.info(true) - user = host_decrypted['TEMPLATE/VCENTER_USER'] - password = host_decrypted['TEMPLATE/VCENTER_PASSWORD'] - port = host_decrypted['TEMPLATE/VCENTER_PORT'] - end - if password.empty? || user.empty? - raise "Error getting \ - credentials for datastore #{datastore_id}" - end - - connection = { - :host => datastore['TEMPLATE/VCENTER_HOST'], - :user => user, - :password => password - } - - connection[:port] = port unless port.nil? - - new(connection) - rescue StandardError => e - raise e + host_decrypted.info(true) + user = host_decrypted['TEMPLATE/VCENTER_USER'] + password = host_decrypted['TEMPLATE/VCENTER_PASSWORD'] + port = host_decrypted['TEMPLATE/VCENTER_PORT'] end + if password.empty? || user.empty? + raise "Error getting \ + credentials for datastore #{datastore_id}" + end + + connection = { + :host => datastore['TEMPLATE/VCENTER_HOST'], + :user => user, + :password => password + } + + connection[:port] = port unless port.nil? + + new(connection) end def self.decrypt(msg, token) diff --git a/src/vnm_mad/remotes/lib/vlan.rb b/src/vnm_mad/remotes/lib/vlan.rb index 87eab9ca7d..0da8a08e75 100644 --- a/src/vnm_mad/remotes/lib/vlan.rb +++ b/src/vnm_mad/remotes/lib/vlan.rb @@ -199,8 +199,6 @@ module VNMMAD return end end - rescue StandardError => e - raise e ensure unlock end