Skip to content

Commit

Permalink
Enable frozen string across project (vagrant-libvirt#1319)
Browse files Browse the repository at this point in the history
Turn on frozen string support in all files by using a comment to avoid
enabling across dependencies where it may not work.

Fixes: vagrant-libvirt#1177
  • Loading branch information
electrofelix authored Jun 30, 2021
1 parent 6dac9c9 commit 18ebb9d
Show file tree
Hide file tree
Showing 91 changed files with 220 additions and 46 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in vagrant-libvirt.gemspec
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#require 'rubygems'
#require 'bundler/setup'
require 'bundler/gem_tasks'
Expand Down
2 changes: 2 additions & 0 deletions example_box/Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# -*- mode: ruby -*-
# vi: set ft=ruby :

Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'pathname'

module VagrantPlugins
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'vagrant/action/builder'
require 'log4r'

Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/clean_machine_folder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'

module VagrantPlugins
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/create_domain.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'

module VagrantPlugins
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/create_domain_volume.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'

module VagrantPlugins
Expand Down
6 changes: 4 additions & 2 deletions lib/vagrant-libvirt/action/create_network_interfaces.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'
require 'vagrant/util/network_ip'
require 'vagrant/util/scoped_hash_override'
Expand Down Expand Up @@ -128,10 +130,10 @@ def call(env)
end

message = "Creating network interface eth#{@iface_number}"
message << " connected to network #{@network_name}."
message += " connected to network #{@network_name}."
if @mac
@mac = @mac.scan(/(\h{2})/).join(':')
message << " Using MAC address: #{@mac}"
message += " Using MAC address: #{@mac}"
end
@logger.info(message)

Expand Down
12 changes: 6 additions & 6 deletions lib/vagrant-libvirt/action/create_networks.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'
require 'vagrant/util/network_ip'
require 'vagrant/util/scoped_hash_override'
Expand Down Expand Up @@ -312,8 +314,7 @@ def create_private_network(env)

if @options[:dhcp_enabled]
# Find out DHCP addresses pool range.
network_address = "#{@interface_network[:network_address]}/"
network_address << (@interface_network[:netmask]).to_s
network_address = "#{@interface_network[:network_address]}/#{(@interface_network[:netmask]).to_s}"
net = @interface_network[:network_address] ? IPAddr.new(network_address) : nil

# First is address of network, second is gateway (by default).
Expand Down Expand Up @@ -345,10 +346,9 @@ def create_private_network(env)

created_networks_file = env[:machine].data_dir + 'created_networks'

message = 'Saving information about created network '
message << "#{@interface_network[:name]}, "
message << "UUID=#{@interface_network[:libvirt_network].uuid} "
message << "to file #{created_networks_file}."
message = 'Saving information about created network ' \
"#{@interface_network[:name]}, UUID=#{@interface_network[:libvirt_network].uuid} " \
"to file #{created_networks_file}."
@logger.info(message)

File.open(created_networks_file, 'a') do |file|
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/destroy_domain.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'

module VagrantPlugins
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/destroy_networks.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'
require 'nokogiri'

Expand Down
12 changes: 7 additions & 5 deletions lib/vagrant-libvirt/action/forward_ports.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module VagrantPlugins
module ProviderLibvirt
module Action
Expand Down Expand Up @@ -104,7 +106,7 @@ def redirect_port(env, machine, host_ip, host_port, guest_ip, guest_port,
IdentitiesOnly=#{ssh_info[:keys_only] ? 'yes' : 'no'}
) + ssh_info[:private_key_path].map do |pk|
"IdentityFile='\"#{pk}\"'"
end).map { |s| s.prepend('-o ') }.join(' ')
end).map { |s| "-o #{s}" }.join(' ')

options += " -o ProxyCommand=\"#{ssh_info[:proxy_command]}\"" if machine.provider_config.proxy_command

Expand All @@ -116,12 +118,12 @@ def redirect_port(env, machine, host_ip, host_port, guest_ip, guest_port,
env[:ui].info 'Requesting sudo for host port(s) <= 1024'
r = system('sudo -v')
if r
ssh_cmd << 'sudo ' # add sudo prefix
ssh_cmd += 'sudo ' # add sudo prefix
end
end
end

ssh_cmd << "ssh -n #{options} #{params}"
ssh_cmd += "ssh -n #{options} #{params}"

@logger.debug "Forwarding port with `#{ssh_cmd}`"
log_file = ssh_forward_log_file(
Expand Down Expand Up @@ -180,10 +182,10 @@ def call(env)
kill_cmd = ''

if tag[:port] <= 1024
kill_cmd << 'sudo ' # add sudo prefix
kill_cmd += 'sudo ' # add sudo prefix
end

kill_cmd << "kill #{tag[:pid]}"
kill_cmd += "kill #{tag[:pid]}"
@@lock.synchronize do
system(kill_cmd)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/halt_domain.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'

module VagrantPlugins
Expand Down
5 changes: 3 additions & 2 deletions lib/vagrant-libvirt/action/handle_box_image.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'
require 'open3'
require 'json'
Expand Down Expand Up @@ -179,8 +181,7 @@ def send_box_image(env, config, box_image_file, box_volume)
raise Vagrant::Errors::BoxNotFound, name: env[:machine].box.name
end
box_image_size = File.size(box_image_file) # B
message = "Creating volume #{box_volume[:name]}"
message << " in storage pool #{config.storage_pool_name}."
message = "Creating volume #{box_volume[:name]} in storage pool #{config.storage_pool_name}."
@logger.info(message)
begin
fog_volume = env[:machine].provider.driver.connection.volumes.create(
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/handle_storage_pool.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'

module VagrantPlugins
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/is_created.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module VagrantPlugins
module ProviderLibvirt
module Action
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/is_running.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module VagrantPlugins
module ProviderLibvirt
module Action
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/is_suspended.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module VagrantPlugins
module ProviderLibvirt
module Action
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/message_already_created.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module VagrantPlugins
module ProviderLibvirt
module Action
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/message_not_created.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module VagrantPlugins
module ProviderLibvirt
module Action
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/message_not_running.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module VagrantPlugins
module ProviderLibvirt
module Action
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/message_not_suspended.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module VagrantPlugins
module ProviderLibvirt
module Action
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/message_will_not_destroy.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module VagrantPlugins
module ProviderLibvirt
module Action
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/package_domain.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'fileutils'
require 'log4r'

Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/prepare_nfs_settings.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'nokogiri'
require 'socket'
require 'timeout'
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module VagrantPlugins
module ProviderLibvirt
module Action
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/prune_nfs_exports.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'vagrant-libvirt/util/nfs'
require 'yaml'

Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/read_mac_addresses.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'

module VagrantPlugins
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/remove_libvirt_image.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'

module VagrantPlugins
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/remove_stale_volume.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'
# require 'log4r/yamlconfigurator'

Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/resume_domain.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'

module VagrantPlugins
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/set_boot_order.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'
require 'nokogiri'

Expand Down
4 changes: 3 additions & 1 deletion lib/vagrant-libvirt/action/set_name_of_domain.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'securerandom'
module VagrantPlugins
module ProviderLibvirt
Expand Down Expand Up @@ -46,7 +48,7 @@ def build_domain_name(env)
env[:root_path].basename.to_s.dup.concat('_')
elsif config.default_prefix.empty?
# don't have any prefix, not even "_"
''
String.new
else
config.default_prefix.to_s.dup
end
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/share_folders.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'pathname'

require 'log4r'
Expand Down
16 changes: 9 additions & 7 deletions lib/vagrant-libvirt/action/start_domain.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'
require 'rexml/document'

Expand Down Expand Up @@ -165,7 +167,7 @@ def call(env)

# clock timers - because timers can be added/removed, just rebuild and then compare
if !config.clock_timers.empty? || clock.has_elements?
oldclock = ''
oldclock = String.new
formatter.write(REXML::XPath.first(xml_descr, '/domain/clock'), oldclock)
clock.delete_element('//timer')
config.clock_timers.each do |clock_timer|
Expand All @@ -175,7 +177,7 @@ def call(env)
end
end

newclock = ''
newclock = String.new
formatter.write(clock, newclock)
unless newclock.eql? oldclock
@logger.debug "clock timers config changed"
Expand Down Expand Up @@ -337,22 +339,22 @@ def call(env)
if descr_changed
begin
libvirt_domain.undefine
new_descr = ''
new_descr = String.new
xml_descr.write new_descr
server = env[:machine].provider.driver.connection.servers.create(xml: new_descr)
env[:machine].provider.driver.connection.servers.create(xml: new_descr)
rescue Fog::Errors::Error => e
server = env[:machine].provider.driver.connection.servers.create(xml: descr)
env[:machine].provider.driver.connection.servers.create(xml: descr)
raise Errors::FogCreateServerError, error_message: e.message
end
end
rescue => e
rescue Errors::VagrantLibvirtError => e
env[:ui].error("Error when updating domain settings: #{e.message}")
end
# Autostart with host if enabled in Vagrantfile
libvirt_domain.autostart = config.autostart
# Actually start the domain
domain.start
rescue => e
rescue Fog::Errors::Error, Errors::VagrantLibvirtError => e
raise Errors::FogError, message: e.message
end

Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/suspend_domain.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'

module VagrantPlugins
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/action/wait_till_up.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'
require 'vagrant-libvirt/errors'
require 'vagrant-libvirt/util/timer'
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/cap/mount_9p.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'digest/md5'
require 'vagrant/util/retryable'

Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/cap/mount_virtiofs.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'digest/md5'
require 'vagrant/util/retryable'

Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/cap/nic_mac_addresses.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module VagrantPlugins
module ProviderLibvirt
module Cap
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/cap/public_address.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module VagrantPlugins
module ProviderLibvirt
module Cap
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-libvirt/cap/synced_folder_9p.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'log4r'
require 'ostruct'
require 'nokogiri'
Expand Down
Loading

0 comments on commit 18ebb9d

Please sign in to comment.