diff --git a/.rubocop.yml b/.rubocop.yml index 569e352..9fe3e29 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,3 +9,6 @@ AllCops: Style/EmptyLinesAroundBlockBody: Enabled: false + +Style/StringLiterals: + Enabled: false \ No newline at end of file diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 92fc4ad..24be91b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,13 +1,65 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2016-03-25 19:11:49 +0100 using RuboCop version 0.38.0. +# on 2017-10-29 18:43:35 +1100 using RuboCop version 0.51.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: SupportedStyles, IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_braces +Layout/IndentHash: + EnforcedStyle: consistent + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: Width, IgnoredPatterns. +Layout/IndentationWidth: + Exclude: + - 'lib/vagrant-google/action/connect_google.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/LeadingCommentSpace: + Exclude: + - 'lib/vagrant-google/action/sync_folders.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/SpaceAfterComma: + Exclude: + - 'test/unit/common/config_test.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: SupportedStyles. +# SupportedStyles: space, no_space +Layout/SpaceAroundEqualsInParameterDefault: + EnforcedStyle: no_space + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, SupportedStylesForEmptyBraces. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceBeforeBlockBraces: + Exclude: + - 'lib/vagrant-google/action/sync_folders.rb' + - 'tasks/acceptance.rake' + # Offense count: 2 -Lint/LiteralInCondition: +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces, SpaceBeforeBlockParameters. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideBlockBraces: + Exclude: + - 'lib/vagrant-google/action/sync_folders.rb' + +# Offense count: 2 +Lint/LiteralAsCondition: Exclude: - 'lib/vagrant-google/action/run_instance.rb' - 'lib/vagrant-google/action/start_instance.rb' @@ -22,9 +74,14 @@ Lint/RescueException: Exclude: - 'lib/vagrant-google/action/read_state.rb' +# Offense count: 1 +Lint/RescueWithoutErrorClass: + Exclude: + - 'lib/vagrant-google/action/run_instance.rb' + # Offense count: 1 # Cop supports --auto-correct. -# Configuration parameters: IgnoreEmptyBlocks. +# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. Lint/UnusedBlockArgument: Exclude: - 'lib/vagrant-google/action/sync_folders.rb' @@ -40,16 +97,21 @@ Lint/UselessAssignment: Exclude: - 'lib/vagrant-google/plugin.rb' -# Offense count: 11 +# Offense count: 12 Metrics/AbcSize: - Max: 54 + Max: 59 + +# Offense count: 7 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/BlockLength: + Max: 224 # Offense count: 4 Metrics/CyclomaticComplexity: - Max: 16 + Max: 19 -# Offense count: 71 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes. +# Offense count: 84 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: Max: 131 @@ -57,18 +119,33 @@ Metrics/LineLength: # Offense count: 15 # Configuration parameters: CountComments. Metrics/MethodLength: - Max: 35 + Max: 43 # Offense count: 3 Metrics/PerceivedComplexity: - Max: 16 + Max: 19 # Offense count: 1 -Style/AccessorMethodName: +Naming/AccessorMethodName: Exclude: - 'test/unit/common/config_test.rb' -# Offense count: 8 +# Offense count: 2 +# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS +Naming/FileName: + Exclude: + - 'lib/vagrant-google.rb' + - 'vagrant-spec.config.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect. +Performance/HashEachMethods: + Exclude: + - 'lib/vagrant-google/action/sync_folders.rb' + +# Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: always, conditionals @@ -76,8 +153,23 @@ Style/AndOr: Exclude: - 'example_boxes/gce-test/Vagrantfile' - 'lib/vagrant-google/config.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: braces, no_braces, context_dependent +Style/BracesAroundHashParameters: + Exclude: - 'test/unit/common/config_test.rb' +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions. +# SupportedStyles: assign_to_condition, assign_inside_condition +Style/ConditionalAssignment: + Exclude: + - 'lib/vagrant-google/config.rb' + # Offense count: 18 Style/Documentation: Exclude: @@ -96,64 +188,36 @@ Style/Documentation: - 'lib/vagrant-google/provider.rb' - 'lib/vagrant-google/util/timer.rb' -# Offense count: 1 +# Offense count: 49 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: leading, trailing -Style/DotPosition: +# SupportedStyles: when_needed, always, never +Style/FrozenStringLiteralComment: Enabled: false -# Offense count: 9 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: empty_lines, no_empty_lines -Style/EmptyLinesAroundBlockBody: - Exclude: - - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: empty_lines, no_empty_lines -Style/EmptyLinesAroundClassBody: - Exclude: - - 'lib/vagrant-google/action/stop_instance.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: empty_lines, no_empty_lines -Style/EmptyLinesAroundModuleBody: - Exclude: - - 'lib/vagrant-google/action/stop_instance.rb' - -# Offense count: 2 -# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts. -Style/FileName: - Exclude: - - 'lib/vagrant-google.rb' - - 'vagrant-spec.config.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: consistent, special_for_inner_method_call, special_for_inner_method_call_in_parentheses -Style/FirstParameterIndentation: - Exclude: - - 'lib/vagrant-google/action/run_instance.rb' - -# Offense count: 1 +# Offense count: 4 # Configuration parameters: MinBodyLength. Style/GuardClause: Exclude: + - 'lib/vagrant-google/action/connect_google.rb' - 'lib/vagrant-google/action/run_instance.rb' + - 'lib/vagrant-google/plugin.rb' -# Offense count: 40 +# Offense count: 45 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues. -# SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets +# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. +# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys Style/HashSyntax: - Enabled: false + Exclude: + - 'lib/vagrant-google/action/connect_google.rb' + - 'lib/vagrant-google/action/read_ssh_info.rb' + - 'lib/vagrant-google/action/run_instance.rb' + - 'lib/vagrant-google/action/start_instance.rb' + - 'lib/vagrant-google/action/stop_instance.rb' + - 'lib/vagrant-google/action/sync_folders.rb' + - 'tasks/acceptance.rake' + - 'tasks/boxes.rake' + - 'test/unit/common/config_test.rb' # Offense count: 2 # Cop supports --auto-correct. @@ -164,9 +228,9 @@ Style/InfiniteLoop: # Offense count: 1 # Cop supports --auto-correct. -Style/LeadingCommentSpace: +Style/MultilineIfThen: Exclude: - - 'lib/vagrant-google/action/sync_folders.rb' + - 'lib/vagrant-google/action/read_ssh_info.rb' # Offense count: 1 # Cop supports --auto-correct. @@ -182,17 +246,25 @@ Style/NilComparison: Exclude: - 'test/unit/common/config_test.rb' +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Exclude: + - 'tasks/acceptance.rake' + # Offense count: 1 # Cop supports --auto-correct. Style/PerlBackrefs: Exclude: - 'lib/vagrant-google/action/sync_folders.rb' -# Offense count: 2 +# Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: AllowMultipleReturnValues. Style/RedundantReturn: Exclude: + - 'lib/vagrant-google/action/connect_google.rb' - 'lib/vagrant-google/action/read_ssh_info.rb' - 'lib/vagrant-google/action/read_state.rb' @@ -212,49 +284,34 @@ Style/RegexpLiteral: # Offense count: 2 # Cop supports --auto-correct. -# Configuration parameters: SupportedStyles. -# SupportedStyles: space, no_space -Style/SpaceAroundEqualsInParameterDefault: - EnforcedStyle: no_space - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: space, no_space -Style/SpaceBeforeBlockBraces: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -Style/SpaceBeforeComma: +# Configuration parameters: ConvertCodeThatCanStartToReturnNil. +Style/SafeNavigation: Exclude: - - 'Gemfile' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -Style/SpaceInsideBlockBraces: - Enabled: false - -# Offense count: 392 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiterals: - Enabled: false + - 'lib/vagrant-google/action/run_instance.rb' + - 'lib/vagrant-google/action/terminate_instance.rb' -# Offense count: 7 +# Offense count: 8 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: single_quotes, double_quotes Style/StringLiteralsInInterpolation: - Enabled: false + Exclude: + - 'lib/vagrant-google/action/run_instance.rb' + - 'lib/vagrant-google/action/start_instance.rb' + - 'lib/vagrant-google/config.rb' + - 'tasks/acceptance.rake' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: MinSize, SupportedStyles. +# SupportedStyles: percent, brackets +Style/SymbolArray: + EnforcedStyle: brackets # Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: IgnoredMethods. -# IgnoredMethods: respond_to +# IgnoredMethods: respond_to, define_method Style/SymbolProc: Exclude: - 'test/unit/common/config_test.rb' diff --git a/lib/vagrant-google/action/connect_google.rb b/lib/vagrant-google/action/connect_google.rb index eda080d..0623f8d 100644 --- a/lib/vagrant-google/action/connect_google.rb +++ b/lib/vagrant-google/action/connect_google.rb @@ -36,9 +36,9 @@ def call(env) :google_client_email => provider_config.google_client_email } if provider_config.google_json_key_location.nil? - fog_config[:google_key_location] = provider_config.google_key_location + fog_config[:google_key_location] = find_key(provider_config.google_key_location, env) else - fog_config[:google_json_key_location] = provider_config.google_json_key_location + fog_config[:google_json_key_location] = find_key(provider_config.google_json_key_location, env) end @logger.info("Connecting to Google...") @@ -47,6 +47,15 @@ def call(env) @app.call(env) @logger.info("...Connected!") end + + # If the key is not found, try expanding from root location (see #159) + def find_key(location, env) + if File.file?(location) + return location + else + return File.expand_path(location, env[:root_path]) + end + end end end end diff --git a/lib/vagrant-google/action/run_instance.rb b/lib/vagrant-google/action/run_instance.rb index 19fc27d..7a87ec8 100644 --- a/lib/vagrant-google/action/run_instance.rb +++ b/lib/vagrant-google/action/run_instance.rb @@ -103,11 +103,11 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize if disk_name.nil? # no disk_name... disk_name defaults to instance name disk = env[:google_compute].disks.create( - name: name, - size_gb: disk_size, - type: disk_type, - zone_name: zone, - source_image: image + name: name, + size_gb: disk_size, + type: disk_type, + zone_name: zone, + source_image: image ) disk_created_by_vagrant = true disk.wait_for { disk.ready? } @@ -116,11 +116,11 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize if disk.nil? # disk not found... create it with name disk = env[:google_compute].disks.create( - name: disk_name, - size_gb: disk_size, - type: disk_type, - zone_name: zone, - source_image: image + name: disk_name, + size_gb: disk_size, + type: disk_type, + zone_name: zone, + source_image: image ) disk.wait_for { disk.ready? } disk_created_by_vagrant = true diff --git a/lib/vagrant-google/action/stop_instance.rb b/lib/vagrant-google/action/stop_instance.rb index 5deef8c..5f4e2ac 100644 --- a/lib/vagrant-google/action/stop_instance.rb +++ b/lib/vagrant-google/action/stop_instance.rb @@ -18,10 +18,8 @@ module VagrantPlugins module Google module Action - # This stops the running instance. class StopInstance - include Vagrant::Util::Retryable def initialize(app, env) diff --git a/tasks/acceptance.rake b/tasks/acceptance.rake index 8c42ffe..5567c77 100644 --- a/tasks/acceptance.rake +++ b/tasks/acceptance.rake @@ -68,7 +68,7 @@ namespace :acceptance do provisioner/chef-solo ).map{ |s| "provider/google/#{s}" } - command = "bundle exec vagrant-spec test --components=#{components.join(" ")}" + command = "vagrant-spec test --components=#{components.join(" ")}" puts command puts exec(command) diff --git a/test/unit/common/config_test.rb b/test/unit/common/config_test.rb index 553e110..8bae071 100644 --- a/test/unit/common/config_test.rb +++ b/test/unit/common/config_test.rb @@ -162,8 +162,8 @@ def set_test_values(instance) end it "should raise an exception if not finalized" do - expect { instance.get_zone_config("us-central1-f") }. - to raise_error(RuntimeError,/Configuration must be finalized/) + expect { instance.get_zone_config("us-central1-f") } + .to raise_error(RuntimeError,/Configuration must be finalized/) end context "with no specific config set" do diff --git a/vagrant-google.gemspec b/vagrant-google.gemspec index 726007b..ac6d096 100644 --- a/vagrant-google.gemspec +++ b/vagrant-google.gemspec @@ -31,17 +31,16 @@ Gem::Specification.new do |s| s.add_runtime_dependency "fog-google", "~> 0.5.3" s.add_runtime_dependency "google-api-client", "< 0.9", "> 0.8.5" - s.add_development_dependency "pry" - s.add_development_dependency "pry-byebug" + # This is a restriction to avoid errors on `failure_message_for_should` + # TODO: revise after vagrant_spec goes past >0.0.1 (at master@e623a56) + s.add_development_dependency "rspec-legacy_formatters" - # This is a restriction to avoid an error "undefined method 'last_comment'" - # which is deprecated (see https://github.com/ruby/rake/issues/116) - # Remove it after update rspec-core to version greater than or equal to 3.4.4 - # s.add_development_dependency "rake", "< 11.0" s.add_development_dependency "rspec", ">= 3.5.0", "<= 3.6" s.add_development_dependency "rspec-its", "~> 1.2" s.add_development_dependency "rubocop", "~> 0.50" s.add_development_dependency "highline" + s.add_development_dependency "pry" + s.add_development_dependency "pry-byebug" # The following block of code determines the files that should be included # in the gem. It does this by reading all the files in the directory where