Enable frozen string across project (#1319)

Turn on frozen string support in all files by using a comment to avoid
enabling across dependencies where it may not work.

Fixes: #1177
This commit is contained in:
Darragh Bailey 2021-06-30 13:27:03 +01:00 committed by GitHub
parent 6dac9c9054
commit 18ebb9d9ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
91 changed files with 220 additions and 46 deletions

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
source 'https://rubygems.org'
# Specify your gem's dependencies in vagrant-libvirt.gemspec

View File

@ -1,3 +1,4 @@
# frozen_string_literal: true
#require 'rubygems'
#require 'bundler/setup'
require 'bundler/gem_tasks'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# -*- mode: ruby -*-
# vi: set ft=ruby :

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'pathname'
module VagrantPlugins

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'vagrant/action/builder'
require 'log4r'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
module VagrantPlugins

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
module VagrantPlugins

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
module VagrantPlugins

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
require 'vagrant/util/network_ip'
require 'vagrant/util/scoped_hash_override'
@ -128,10 +130,10 @@ module VagrantPlugins
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)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
require 'vagrant/util/network_ip'
require 'vagrant/util/scoped_hash_override'
@ -312,8 +314,7 @@ module VagrantPlugins
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).
@ -345,10 +346,9 @@ module VagrantPlugins
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|

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
module VagrantPlugins

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
require 'nokogiri'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt
module Action
@ -104,7 +106,7 @@ module VagrantPlugins
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
@ -116,12 +118,12 @@ module VagrantPlugins
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(
@ -180,10 +182,10 @@ module VagrantPlugins
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

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
module VagrantPlugins

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
require 'open3'
require 'json'
@ -179,8 +181,7 @@ module VagrantPlugins
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(

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
module VagrantPlugins

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt
module Action

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt
module Action

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt
module Action

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt
module Action

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt
module Action

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt
module Action

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt
module Action

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt
module Action

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'fileutils'
require 'log4r'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'nokogiri'
require 'socket'
require 'timeout'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt
module Action

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'vagrant-libvirt/util/nfs'
require 'yaml'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
module VagrantPlugins

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
module VagrantPlugins

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
# require 'log4r/yamlconfigurator'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
module VagrantPlugins

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
require 'nokogiri'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'securerandom'
module VagrantPlugins
module ProviderLibvirt
@ -46,7 +48,7 @@ module VagrantPlugins
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

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'pathname'
require 'log4r'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
require 'rexml/document'
@ -165,7 +167,7 @@ module VagrantPlugins
# 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|
@ -175,7 +177,7 @@ module VagrantPlugins
end
end
newclock = ''
newclock = String.new
formatter.write(clock, newclock)
unless newclock.eql? oldclock
@logger.debug "clock timers config changed"
@ -337,22 +339,22 @@ module VagrantPlugins
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

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
module VagrantPlugins

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
require 'vagrant-libvirt/errors'
require 'vagrant-libvirt/util/timer'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'digest/md5'
require 'vagrant/util/retryable'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'digest/md5'
require 'vagrant/util/retryable'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt
module Cap

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt
module Cap

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
require 'ostruct'
require 'nokogiri'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'log4r'
require 'ostruct'
require 'nokogiri'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'cgi'
require 'vagrant'
@ -5,10 +7,10 @@ require 'vagrant'
class Numeric
Alphabet = ('a'..'z').to_a
def vdev
s = ''
s = String.new
q = self
(q, r = (q - 1).divmod(26)) && s.prepend(Alphabet[r]) until q.zero?
'vd' + s
"vd#{s}"
end
end
@ -352,7 +354,7 @@ module VagrantPlugins
# hda - hdc
curr = 'a'.ord
while curr <= 'd'.ord
dev = 'hd' + curr.chr
dev = "hd#{curr.chr}"
if exist[dev]
curr += 1
next
@ -745,24 +747,24 @@ module VagrantPlugins
if @connect_via_ssh == true
finalize_id_ssh_key_file
uri << '+ssh://'
uri << @username + '@' if @username && @username != UNSET_VALUE
uri += '+ssh://'
uri += "#{@username}@" if @username && @username != UNSET_VALUE
uri << ( @host && @host != UNSET_VALUE ? @host : 'localhost' )
uri += (@host && @host != UNSET_VALUE ? @host : 'localhost')
params['no_verify'] = '1'
params['keyfile'] = @id_ssh_key_file if @id_ssh_key_file
else
uri << '://'
uri << @host if @host && @host != UNSET_VALUE
uri += '://'
uri += @host if @host && @host != UNSET_VALUE
end
uri << virt_path
uri += virt_path
# set path to Libvirt socket
params['socket'] = @socket if @socket
uri << "?" + params.map{|pair| pair.join('=')}.join('&') if !params.empty?
uri += '?' + params.map { |pair| pair.join('=') }.join('&') unless params.empty?
uri
end
@ -955,11 +957,10 @@ module VagrantPlugins
machine.config.vm.networks.each do |_type, opts|
if opts[:mac]
opts[:mac].downcase!
if opts[:mac] =~ /\A([0-9a-f]{12})\z/
if opts[:mac] =~ /\A([0-9a-fA-F]{12})\z/
opts[:mac] = opts[:mac].scan(/../).join(':')
end
unless opts[:mac] =~ /\A([0-9a-f]{2}:){5}([0-9a-f]{2})\z/
unless opts[:mac] =~ /\A([0-9a-fA-F]{2}:){5}([0-9a-fA-F]{2})\z/
errors << "Configured NIC MAC '#{opts[:mac]}' is not in 'xx:xx:xx:xx:xx:xx' or 'xxxxxxxxxxxx' format"
end
end
@ -1032,7 +1033,7 @@ module VagrantPlugins
def resolve_ssh_key_file(key_file)
# set ssh key for access to Libvirt host
# if no slash, prepend $HOME/.ssh/
key_file.prepend("#{ENV['HOME']}/.ssh/") if key_file && key_file !~ /\A\//
key_file = "#{ENV['HOME']}/.ssh/#{key_file}" if key_file && key_file !~ /\A\//
key_file
end
@ -1061,17 +1062,17 @@ module VagrantPlugins
if @connect_via_ssh
if @proxy_command == UNSET_VALUE
proxy_command = "ssh '#{@host}' "
proxy_command << "-p #{@port} " if @port
proxy_command << "-l '#{@username}' " if @username
proxy_command << "-i '#{@id_ssh_key_file}' " if @id_ssh_key_file
proxy_command << '-W %h:%p'
proxy_command += "-p #{@port} " if @port
proxy_command += "-l '#{@username}' " if @username
proxy_command += "-i '#{@id_ssh_key_file}' " if @id_ssh_key_file
proxy_command += '-W %h:%p'
else
inputs = { host: @host }
inputs << { port: @port } if @port
inputs[:username] = @username if @username
inputs[:id_ssh_key_file] = @id_ssh_key_file if @id_ssh_key_file
proxy_command = @proxy_command
proxy_command = String.new(@proxy_command)
# avoid needing to escape '%' symbols
inputs.each do |key, value|
proxy_command.gsub!("{#{key}}", value)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'fog/libvirt'
require 'libvirt'
require 'log4r'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'vagrant'
module VagrantPlugins

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
begin
require 'vagrant'
rescue LoadError

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'vagrant'
module VagrantPlugins

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt
module Util

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt
module Util

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt
module Util

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Ripped from http://libvirt.org/html/libvirt-virterror.html#virErrorNumber.
module VagrantPlugins
module ProviderLibvirt

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'ipaddr'
require 'nokogiri'
require 'vagrant/util/network_ip'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt
module Util

View File

@ -1,3 +1,4 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt
module Util

View File

@ -1,3 +1,4 @@
# frozen_string_literal: true
module VagrantPlugins
module ProviderLibvirt

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'open3'
require 'tmpdir'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'simplecov'
require 'simplecov-lcov'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
##
# A simple extension of the Proc class that supports setting a custom binding
# and evaluates everything in the Proc using the new binding.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'ostruct'
require 'pathname'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'fog/libvirt'
shared_context 'libvirt' do

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "rspec/expectations/version"
#
# Taken from https://github.com/cucumber/aruba/blob/main/lib/aruba/matchers/file/have_file_content.rb

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'spec_helper'
shared_context 'unit' do

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
shared_context 'temporary_dir' do
around do |example|
Dir.mktmpdir("rspec-") do |dir|

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'spec_helper'
require 'support/sharedcontext'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'spec_helper'
require 'support/sharedcontext'
require 'support/libvirt_context'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'spec_helper'
require 'support/sharedcontext'
require 'support/libvirt_context'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'spec_helper'
require 'support/sharedcontext'
require 'support/libvirt_context'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'spec_helper'
require 'support/sharedcontext'
require 'support/libvirt_context'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'spec_helper'
require 'support/sharedcontext'
require 'support/libvirt_context'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'spec_helper'
require 'json'
require 'support/sharedcontext'
@ -77,7 +79,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::HandleBoxImage do
]
}
allow(env[:machine]).to receive_message_chain("box.directory.join") do |arg|
'/test/'.concat(arg.to_s)
'/test/' + arg.to_s
end
end
@ -197,7 +199,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::HandleBoxImage do
],
]}
allow(env[:machine]).to receive_message_chain("box.directory.join") do |arg|
'/test/'.concat(arg.to_s)
'/test/' + arg.to_s
end
allow(status).to receive(:success?).and_return(true)
allow(Open3).to receive(:capture3).with('qemu-img', 'info', '--output=json', '/test/box.img').and_return([
@ -334,7 +336,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::HandleBoxImage do
]
}
allow(env[:machine]).to receive_message_chain("box.directory.join") do |arg|
'/test/'.concat(arg.to_s)
'/test/' + arg.to_s
end
end
@ -354,7 +356,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::HandleBoxImage do
allow(env[:machine]).to receive_message_chain("box.version") { '1.1.1' }
allow(env[:machine]).to receive_message_chain("box.metadata") { box_metadata }
allow(env[:machine]).to receive_message_chain("box.directory.join") do |arg|
'/test/'.concat(arg.to_s)
'/test/' + arg.to_s
end
allow(status).to receive(:success?).and_return(true)
allow(Open3).to receive(:capture3).with('qemu-img', 'info', "--output=json", '/test/box.img').and_return([

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'spec_helper'
require 'support/sharedcontext'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'spec_helper'
describe VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain do

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'spec_helper'
require 'support/sharedcontext'
require 'support/libvirt_context'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'vagrant-libvirt/action/wait_till_up'
require 'vagrant-libvirt/errors'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'support/binding_proc'
require 'spec_helper'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'support/sharedcontext'
require 'vagrant-libvirt/config'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'spec_helper'
require 'vagrant-libvirt/util/byte_number'

View File

@ -1,5 +1,7 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# frozen_string_literal: true
Vagrant.configure("2") do |config|
config.vm.box = "infernix/tinycore"

View File

@ -1,5 +1,7 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# frozen_string_literal: true
Vagrant.configure("2") do |config|
config.vm.box = "infernix/tinycore"

View File

@ -1,5 +1,7 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# frozen_string_literal: true
Vagrant.configure("2") do |config|
config.vm.box = "infernix/tinycore"

View File

@ -1,5 +1,7 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# frozen_string_literal: true
Vagrant.configure("2") do |config|
config.vm.box = "generic/debian10"

View File

@ -1,5 +1,7 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# frozen_string_literal: true
Vagrant.configure("2") do |config|
config.vm.box = "infernix/tinycore"

View File

@ -1,5 +1,7 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# frozen_string_literal: true
Vagrant.configure("2") do |config|
# private network doesnt work with tinycore, use

View File

@ -1,5 +1,7 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# frozen_string_literal: true
Vagrant.configure("2") do |config|
config.vm.box = "infernix/tinycore"

View File

@ -1,5 +1,7 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# frozen_string_literal: true
Vagrant.configure("2") do |config|
config.vm.box = "infernix/tinycore"

View File

@ -1,5 +1,7 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# frozen_string_literal: true
Vagrant.configure("2") do |config|
config.vm.box = "infernix/tinycore"

View File

@ -1,5 +1,7 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# frozen_string_literal: true
Vagrant.configure("2") do |config|
config.vm.box = "infernix/tinycore-two-disks"

View File

@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: true
require File.expand_path('../lib/vagrant-libvirt/version', __FILE__)
Gem::Specification.new do |s|