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

updated_by_last_action? of resource in LWRP always returns false #3748

Closed
metmajer opened this Issue Aug 3, 2015 · 4 comments

Comments

Projects
None yet
3 participants
@metmajer

metmajer commented Aug 3, 2015

Version:

Chef: 12.4.1 (not tested in other versions)

Environment:

I am using a Dockerized Debian 7.4 to test our custom Dynatrace Cookbook via Test Kitchen.

Scenario:

I wrote an LWRP to configure and deploy a set of init scripts (templates) for each of our system services. What I would like to achieve is that our services should only get restarted if a template has changed in a Chef run:

# recipes/wsagent_package.rb

dynatrace_configure_init_scripts "#{name}" do
  ...
  notifies :restart, "service[#{name}]"
end

service "#{name}" do
  service_name service
  ...
  action [:enable]
end
# providers/configure_init_scripts.rb

action :run do
  new_resource.scripts.each do |script|
    t = template "Configure and copy the #{new_resource.name}'s '#{script}' init script" do
      source "init.d/#{script}.erb"
      path   "#{new_resource.installer_prefix_dir}/dynatrace/init.d/#{script}"
      ...
      action :create
    end
    new_resource.updated_by_last_action(true) if t.updated_by_last_action?
end

The problem here is that t.updated_by_last_action is always false, even if:

  • the file at path did not exist
  • the file contents changed

Steps to Reproduce:

Please find a temporary branch here: https://github.com/dynaTrace/Dynatrace-Chef/tree/bugfix/restartIfRequired.

In order to reproduce:

  1. git clone https://github.com/dynaTrace/Dynatrace-Chef.git -b bugfix/restartIfRequired
  2. Download the installer artifact from http://bit.ly/1hfKlte and place the file as dynatrace-wsagent.tar in the Cookbook's files directory
  3. bundle install && kitchen converge wsagent-package-debian
@coderanger

This comment has been minimized.

Show comment
Hide comment
@coderanger

coderanger Aug 3, 2015

Contributor

Yes, that pattern never worked. Use use_inline_resources or similar if you want this kind of behavior.

Contributor

coderanger commented Aug 3, 2015

Yes, that pattern never worked. Use use_inline_resources or similar if you want this kind of behavior.

@coderanger coderanger closed this Aug 3, 2015

@metmajer

This comment has been minimized.

Show comment
Hide comment
@metmajer

metmajer Aug 3, 2015

Using use_inline_resources in providers/configure_init_scripts.rb, such as:

# providers/configure_init_scripts.rb

use_inline_resources

action :run do
...

does not solve the problem. @coderanger can you be more specific? Thanks.

metmajer commented Aug 3, 2015

Using use_inline_resources in providers/configure_init_scripts.rb, such as:

# providers/configure_init_scripts.rb

use_inline_resources

action :run do
...

does not solve the problem. @coderanger can you be more specific? Thanks.

@coderanger

This comment has been minimized.

Show comment
Hide comment
@coderanger

coderanger Aug 3, 2015

Contributor

use_inline_resources automatically sets the updated flag on the LWResource if any resource used in the action method is updated.

Contributor

coderanger commented Aug 3, 2015

use_inline_resources automatically sets the updated flag on the LWResource if any resource used in the action method is updated.

@stevendanna

This comment has been minimized.

Show comment
Hide comment
@stevendanna

stevendanna Aug 3, 2015

Member

Specifically, using use_inline_resources, the following should correctly set the updated flag on the resource if any of your script resource executed.

use_inline_resources 

action :run do
  new_resource.scripts.each do |script|
    template "Configure and copy the #{new_resource.name}'s '#{script}' init script" do
      source "init.d/#{script}.erb"
      path   "#{new_resource.installer_prefix_dir}/dynatrace/init.d/#{script}"
      ...
      action :create
    end
  end
end
Member

stevendanna commented Aug 3, 2015

Specifically, using use_inline_resources, the following should correctly set the updated flag on the resource if any of your script resource executed.

use_inline_resources 

action :run do
  new_resource.scripts.each do |script|
    template "Configure and copy the #{new_resource.name}'s '#{script}' init script" do
      source "init.d/#{script}.erb"
      path   "#{new_resource.installer_prefix_dir}/dynatrace/init.d/#{script}"
      ...
      action :create
    end
  end
end

@chef chef locked and limited conversation to collaborators Nov 16, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.