Ask Your Question
0

Managing multiple module's tests

asked 2016-04-29 08:19:12 -0500

DarylW gravatar image

Hello,

We currently have a monolithic repository with all of our puppet modules in it. It is part of our entire system's code, and we want to run the rake tasks as a part of our overall build.

I know that the short/best answer is 'make everything it's own repo, and run the tests per repo on checkin' but due to process/politics, that is not an option.

Being only a newbie with ruby/rake/rspec, is there a way that I can create specific rake tests per module, and then have a higher level rake task that will have multiple tasks that it would apply to all of the modules? I know that if I niavly move my Rakefile and my spec helper up to the top level, it will recursively search for all _spec.rb files and try to run them, but then the relative paths for the fixtures directories would be incorrect.

Is there a way to create tests that will migrate properly to a one module per repo path in the future, but still allow me to have a top-level rake test that will 'find' all the rakefiles, and run each of the tests locally from their directory? If there is already a solution/pattern out there, I don't want to reinvent the wheel. Otherwise I'll probably just script out what I mentioned above. ( find all Rakefile, foreach rake file, CD to it's parent and run a set of tasks, roll up success/failure).

One extra wrinkle in this is that we do have modules from the forge that aren't housed in our mono repo. (right now we sync our mono repo out to our puppet master into an environment, and we have all of our repo modules just extracted in /etc/puppet/modules/ ). I can setup the .fixtures.yml file with symlink options that would point to a 'vendor' folder where we could put all the forge modules, or I could check them into their own mono repo and use the repository option in the fixtures file.

Another wrinkle is that the rest of our build is done using ant. We hope to migrate to gradle in the not to distant future, but either way the wrapping build environment is not Rake. Being able to translate dependencies would be a plus, but rerunning all tests is not that big of a deal. (thanks CI server!)

TL:DR; Is there a good way to create a high level Rake task that could run individual targets of all the puppet modules under it? (separate task for lint, spec, beaker)

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-04-29 21:56:08 -0500

updated 2016-04-30 06:50:05 -0500

If I am understanding:

Set up Rspec and a Rakefile for each module as if they were in separate repositories, because one day you will become a Great Politician and win a general election with a mandate to split up the monolithic repo.

I therefore assume you can run:

cd site/modules/mymodule && bundle install && bundle exec rake spec

Now for the temporary hack in the monolithic repo's Rakefile (which will one day be your control repo's Rakefile):

desc 'Run module spec tasks' do
task :run_all_specs do
  Dir.glob('site/modules/*').each do |dir|
    system("cd #{dir} && bundle install && bundle exec rake spec")
  end
end

Update, as far as having task C call task A & B and then do other stuff:

task :A do
  # do A
end

task :B do
  # do B
end

task :C => [:A, :B] do
  # do A & B
  # then do C
end
edit flag offensive delete link more

Comments

is it possible to have a task that passes that same task to all the other tests? i.e. can I reference the 'task' and use that to specify the next task, or do I just have to manually hand-jam it. aka, rake lint will run cd #{dir} && bundle install && bundle exec rake lint ?

DarylW gravatar imageDarylW ( 2016-04-30 00:29:47 -0500 )edit

Updated, hope I got your meaning.

Alex Harvey gravatar imageAlex Harvey ( 2016-04-30 06:50:23 -0500 )edit

The important point is I think I would treat the top level of your monolithic repo as your future control repo, and expect that each of the embedded modules will one day be moved into their own module repos. Therefore, have roles & profiles tested at the level of the control repo, and tests for...

Alex Harvey gravatar imageAlex Harvey ( 2016-04-30 06:54:57 -0500 )edit

...the others in the site/module/<mymodule> directory.

Alex Harvey gravatar imageAlex Harvey ( 2016-04-30 06:55:39 -0500 )edit

so.. Control repo with .fixtures.yml for testing, and the actual metadata.json for r10k on the actual master. is there a way to do a 'pull' with the r10k gem instead to use a single file for dependencies?

DarylW gravatar imageDarylW ( 2016-04-30 11:14:59 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-04-29 08:19:12 -0500

Seen: 125 times

Last updated: Apr 30 '16