Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Update composer via cron, not exec. #48

Closed
wants to merge 0 commits into from

Conversation

hensema
Copy link

@hensema hensema commented Apr 16, 2018

Overview

This PR changes the exec resource to self-update composer to a cron resource. This prevents the node from being active all the time.

For now, the hour is hardcoded to 0 and the minute is generated randomly based on fqdn_rand().

@willdurand willdurand requested a review from Ma27 April 16, 2018 13:47
@Ma27 Ma27 added the in review label Apr 16, 2018
@Ma27
Copy link
Collaborator

Ma27 commented Apr 16, 2018

thanks a lot for your patch!
Before we can merge this, there are two things that need to be fixed:

  • the current build fails (according to the logs because of a styling issue)
  • it would be helpful to alter the testsuite accordingly (IIRC we currently ensure that in case of auto_update => true the exec will be evaluated, this needs to be changed)

@Ma27
Copy link
Collaborator

Ma27 commented Apr 18, 2018

@hensema can I help you with fixing the build? The change itself is perfectly fine to me :)

@hensema
Copy link
Author

hensema commented Apr 19, 2018

@Ma27 Sure, but due to personal circumstances I won't have time to do so quickly. Hopefully tomorrow or early next week.

@Ma27
Copy link
Collaborator

Ma27 commented Apr 19, 2018

@hensema no hurry, that's absolutely fine, thank you! :)

@hensema
Copy link
Author

hensema commented Apr 26, 2018

Unfortunately as I'm not a Ruby programmer I don't know how to run the unit tests, let alone adapt them to the new manifest.

When following the docs on https://puppet.com/blog/unit-testing-rspec-puppet-for-beginners I get:

hensema@puppet-foreman:~/erik/modules/composer/spec$ rspec classes/composer_spec.rb
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require': cannot load such file -- spec_helper (LoadError) from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require'
from /etc/puppetlabs/code/environments/erik/modules/composer/spec/classes/composer_spec.rb:1:in <top (required)>' from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:1361:in load'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:1361:in block in load_spec_files' from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:1359:in each'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:1359:in load_spec_files' from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:106:in setup'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:92:in run' from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:78:in run'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:45:in invoke' from /usr/bin/rspec:4:in

'

Any clue on how to proceed?

@Ma27
Copy link
Collaborator

Ma27 commented Apr 26, 2018

I'd use the configured rake scripts rather than the rspec CLI interface:

bundle install
bundle exec rake test

@hensema
Copy link
Author

hensema commented Apr 26, 2018

-nevermind-

@hensema
Copy link
Author

hensema commented Apr 26, 2018

I assume I should run "bundle exec rake spec". This seems to run the unit tests. However, almost all tests fail (28 failures out of 30).

Are there any other prerequisites for running the unit tests?

Output:

WARN: Unresolved specs during Gem::Specification.reset:
      diff-lcs (< 2.0, >= 1.2.0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
Cloning into 'spec/fixtures/modules/stdlib'...
remote: Counting objects: 622, done.
remote: Compressing objects: 100% (539/539), done.
remote: Total 622 (delta 183), reused 167 (delta 62), pack-reused 0
Receiving objects: 100% (622/622), 305.56 KiB | 0 bytes/s, done.
Resolving deltas: 100% (183/183), done.
Checking connectivity... done.
I, [2018-04-26T10:05:06.043140 #25127]  INFO -- : Creating symlink from spec/fixtures/modules/composer to /etc/puppetlabs/code/environments/erik/modules/composer
/usr/bin/ruby2.3 -I/var/lib/gems/2.3.0/gems/rspec-support-3.7.1/lib:/var/lib/gems/2.3.0/gems/rspec-core-3.7.1/lib /var/lib/gems/2.3.0/gems/rspec-core-3.7.1/exe/rspec --pattern spec/\{aliases,classes,defines,unit,functions,hosts,integration,plans,type_aliases,types\}/\*\*/\*_spec.rb --color
WARN: Unresolved specs during Gem::Specification.reset:
      rake (>= 0)
      diff-lcs (< 2.0, >= 1.2.0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
FFFFFFFFFFFFFFFFFFFFFFFFFFFF..

Failures:

  1) composer should contain Exec[composer-install] with command => "/usr/bin/wget --no-check-certificate -O /usr/local/bin/composer https://getcomposer.org/composer.phar", user => "root" and unless => "/usr/bin/test -f /usr/local/bin/composer"
     Failure/Error:
       it { should contain_exec('composer-install') \
         .with_command('/usr/bin/wget --no-check-certificate -O /usr/local/bin/composer https://getcomposer.org/composer.phar') \
         .with_user('root') \
         .with_unless('/usr/bin/test -f /usr/local/bin/composer')
       }
     
     Puppet::PreformattedError:
       Evaluation Error: Unknown variable: 'composer_target_dir'. at /etc/puppetlabs/code/environments/erik/modules/composer/spec/fixtures/modules/composer/manifests/init.pp:92:41 on node puppet-foreman.hostingxs.nl
     # /var/lib/gems/2.3.0/gems/puppet-4.9.4/lib/puppet/pops/evaluator/runtime3_support.rb:39:in `optionally_fail'
     # /var/lib/gems/2.3.0/gems/puppet-4.9.4/lib/puppet/pops/evaluator/runtime3_support.rb:99:in `get_variable_value'
     # /var/lib/gems/2.3.0/gems/puppet-4.9.4/lib/puppet/pops/evaluator/evaluator_impl.rb:1041:in `eval_VariableExpression'

[...]

@Ma27
Copy link
Collaborator

Ma27 commented Apr 26, 2018

First of all, can you please wrap the CLI output with ``` to make it easier to read? (https://guides.github.com/features/mastering-markdown/)

The issue is caused by your change, the variables composer_target_dir and composer_command_name simply don't exist. In case you're struggling with the tests way too much, just tell me since I could also do the job of fixing that %)

@hensema
Copy link
Author

hensema commented Apr 26, 2018

It would certainly be the quickest solution if you could update the tests 😀
I do plan on getting unit tests for our puppet modules running somewhere in the future, but as I said Ruby is completely alien to me so it's a struggle.

@Ma27
Copy link
Collaborator

Ma27 commented Apr 26, 2018

Dammit, screwed up the merge, pushed locally, sorry ...

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

Successfully merging this pull request may close these issues.

2 participants