Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change recieving options in Itamae::Resource::Base at initialize time #144

Closed

Conversation

ganmacs
Copy link
Contributor

@ganmacs ganmacs commented Jul 12, 2015

ref #136

When dry_run mode, raise an error in edit action against a file resource if the target file does not exist.
So, I skip the method that raise an error to use dry_run options.

this is recipe.rb

file "./sample_file" do
  action :edit
end

Before apply this patch

ganmacs@ganmacs~% bundle exec bin/itamae ssh --vagrant recipe.rb --dry-run
 INFO : Starting Itamae...
 INFO : Recipe: /Users/ganmacs/src/github.com/ganmacs/itamae/recipe.rb
/Users/ganmacs/src/github.com/ganmacs/itamae/vendor/bundle/ruby/2.2.0/gems/net-scp-1.2.1/lib/net/scp.rb:365:in `block (3 levels) in start_command': SCP did not finish successfully (1): scp: ./sample_file: No such file or directory (Net::SCP::Error)
    from /Users/ganmacs/src/github.com/ganmacs/itamae/vendor/bundle/ruby/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/connection/channel.rb:591:in `call'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/vendor/bundle/ruby/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/connection/channel.rb:591:in `do_close'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/vendor/bundle/ruby/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:587:in `channel_close'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/vendor/bundle/ruby/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:466:in `dispatch_incoming_packets'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/vendor/bundle/ruby/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:222:in `preprocess'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/vendor/bundle/ruby/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:206:in `process'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/vendor/bundle/ruby/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:170:in `block in loop'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/vendor/bundle/ruby/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:170:in `loop'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/vendor/bundle/ruby/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:170:in `loop'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/vendor/bundle/ruby/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/connection/channel.rb:269:in `wait'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/vendor/bundle/ruby/2.2.0/gems/net-scp-1.2.1/lib/net/scp.rb:321:in `download!'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/ext/specinfra.rb:34:in `scp_download!'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/ext/specinfra.rb:23:in `receive_file'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/backend.rb:93:in `receive_file'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/resource/file.rb:23:in `pre_action'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/resource/base.rb:179:in `block in run_action'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/logger.rb:40:in `call'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/logger.rb:40:in `with_indent_if'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/resource/base.rb:177:in `run_action'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/resource/base.rb:135:in `block (2 levels) in run'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/resource/base.rb:134:in `each'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/resource/base.rb:134:in `block in run'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/logger.rb:40:in `call'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/logger.rb:40:in `with_indent_if'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/resource/base.rb:125:in `run'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/recipe_children.rb:60:in `block in run'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/recipe_children.rb:57:in `each'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/recipe_children.rb:57:in `run'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/recipe.rb:48:in `block in run'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/logger.rb:31:in `with_indent'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/recipe.rb:47:in `run'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/recipe_children.rb:62:in `block in run'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/recipe_children.rb:57:in `each'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/recipe_children.rb:57:in `run'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/runner.rb:53:in `run'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/runner.rb:23:in `run'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/lib/itamae/cli.rb:53:in `ssh'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/vendor/bundle/ruby/2.2.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/vendor/bundle/ruby/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/vendor/bundle/ruby/2.2.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
    from /Users/ganmacs/src/github.com/ganmacs/itamae/vendor/bundle/ruby/2.2.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from bin/itamae:4:in `<main>'
bundle exec bin/itamae ssh --vagrant recipe.rb --dry-run  5.10s user 0.95s system 92% cpu 6.558 total

After apply this patch

anmacs@ganmacs~% bundle exec bin/itamae ssh --vagrant recipe.rb --dry-run
 INFO : Starting Itamae...
 INFO : Recipe: /Users/ganmacs/src/github.com/ganmacs/itamae/recipe.rb
 INFO :   file[./sample_file] exist will change from 'false' to 'true'
bundle exec bin/itamae ssh --vagrant recipe.rb --dry-run  5.08s user 0.94s system 89% cpu 6.738 total

As above, after Apply this patch, if the target file does not exist, we can't detect an error In dry_run

end

send_tempfile
unless options[:dry_run]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create action in dry-run mode shows difference between tempfile and current file. This break the ability.

@ryotarai
Copy link
Member

Changing pre_action to accept an arg introduces plugin incompatibility because some plugin resources override pre_action method. I prefer:

# base.rb
if method(:pre_action).arity == 1
  pre_action(options)
else
  Logger.warn "DEPRECATION WARNING: #{resource_type} resource does not accept `options` arg."
  pre_action
end

# resource
# option arg is not optional
def pre_action(options)
  # ...
end

@ganmacs ganmacs force-pushed the add-option-to-pre-action branch from fae8160 to 21940e3 Compare July 13, 2015 10:18
@ganmacs
Copy link
Contributor Author

ganmacs commented Jul 13, 2015

Thanks for a detail explanation.
I had not noticed that my changing make plugins incompatible.

I think receiving options as arguments in Itamae::Resource::Base at initialize time can solve #136 and have compatible other plugins.
So I changed my patch drastically. and changed my PR title.

@ganmacs ganmacs changed the title Change pre_action to use command line options Change recieving options in Itamae::Resource::Base at initialize time Jul 13, 2015
In `Itame::Recipe` and `Itamae::Resource::Base`
@ganmacs ganmacs force-pushed the add-option-to-pre-action branch from 21940e3 to 5d30ac9 Compare July 13, 2015 11:13
@ryotarai
Copy link
Member

Sorry for late reply. I'll check this PR later.

ryotarai pushed a commit that referenced this pull request Nov 9, 2015
@ryotarai
Copy link
Member

ryotarai commented Nov 9, 2015

Sorry for late reaction. Your commits are merged:

Thank you for your contribution!

@ryotarai ryotarai closed this Nov 9, 2015
@ganmacs ganmacs deleted the add-option-to-pre-action branch November 12, 2019 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants