From 5df616de59d754b1610c21dde6389b31159af64c Mon Sep 17 00:00:00 2001 From: Eric Sakowski Date: Wed, 31 Jul 2013 20:36:06 +0000 Subject: [PATCH 1/5] Add ability to deploy code to subdirs of modules dir --- lib/librarian/puppet/simple/installer.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/librarian/puppet/simple/installer.rb b/lib/librarian/puppet/simple/installer.rb index 8506365..b54d02a 100644 --- a/lib/librarian/puppet/simple/installer.rb +++ b/lib/librarian/puppet/simple/installer.rb @@ -22,9 +22,12 @@ module Installer # iterator mixin def install! each_module do |repo| - print_verbose "\n##### processing module #{repo[:name]}..." - + module_path = module_path() + if repo[:subdir] + module_path = File.join(module_path, repo[:subdir]) + FileUtils.mkdir_p(module_path) unless File.exists?(module_path) + end module_dir = File.join(module_path, repo[:name]) unless File.exists?(module_dir) From 1aab3837842c8ecc84e7176f8f6c1c5611aead87 Mon Sep 17 00:00:00 2001 From: Eric Sakowski Date: Wed, 31 Jul 2013 16:47:58 -0400 Subject: [PATCH 2/5] Updated README.md w/ subdir param --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 868c74a..440063c 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,12 @@ mod "puppetlabs/ntp", mod "apache", :tarball => "https://forge.puppetlabs.com/puppetlabs/apache/0.6.0.tar.gz" -``` +#Deploy mysql module into modules/databases/mysql with the :subdir param +mod "mysql", + :git => "gitolite@myserver.com:mysql.git", + :subdir => "databases" +``` ## Setting up for development and running the specs Just clone the repo and run the following commands: ``` From a20b7b1a2a5177434d44d5be2a5fa268f2df2164 Mon Sep 17 00:00:00 2001 From: Henrik Date: Sun, 3 Nov 2013 12:37:20 +0100 Subject: [PATCH 3/5] passing tests again --- spec/functional/install_spec.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spec/functional/install_spec.rb b/spec/functional/install_spec.rb index 7437e94..68493f9 100644 --- a/spec/functional/install_spec.rb +++ b/spec/functional/install_spec.rb @@ -35,14 +35,14 @@ output, status = execute_captured("bin/librarian-puppet install --path=#{temp_directory} --puppetfile=spec/fixtures/Puppetfile") status.should == 0 - Dir.entries(temp_directory).should =~ ['.', '..', 'apache', 'ntp', 'trashfile'] + Dir.entries(temp_directory).should =~ %w|. .. apache ntp trashfile dnsclient testlps| end it "with --clean it cleans the directory before installing the modules in a temp directory" do output, status = execute_captured("bin/librarian-puppet install --clean --path=#{temp_directory} --puppetfile=spec/fixtures/Puppetfile") status.should == 0 - Dir.entries(temp_directory).should =~ ['.', '..', 'apache', 'ntp'] + Dir.entries(temp_directory).should =~ %w|. .. apache ntp dnsclient testlps| end it "with --verbose it outputs progress messages" do @@ -66,9 +66,8 @@ output, status = execute_captured("bin/librarian-puppet install --verbose --path=#{temp_directory} --puppetfile=spec/fixtures/Puppetfile") status.should == 0 output.should include('Module apache already installed') - Dir.entries(temp_directory).should =~ ['.', '..', 'apache', 'ntp'] + Dir.entries(temp_directory).should =~ %w|. .. apache ntp dnsclient testlps| end - end end From 49fbbad305bcc60454080f201321dc48e9911c0c Mon Sep 17 00:00:00 2001 From: Henrik Date: Sun, 3 Nov 2013 12:55:19 +0100 Subject: [PATCH 4/5] passing tests --- README.md | 2 +- spec/fixtures/Puppetfile | 5 +++++ spec/functional/install_spec.rb | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e0c08f8..b5c602f 100644 --- a/README.md +++ b/README.md @@ -70,4 +70,4 @@ Beware that the functional tests will download files from GitHub and PuppetForge See [LICENSE](/LICENSE) ## Credits -The untar and ungzip methods came from https://gist.github.com/sinisterchipmunk/1335041 \ No newline at end of file +The untar and ungzip methods came from https://gist.github.com/sinisterchipmunk/1335041 diff --git a/spec/fixtures/Puppetfile b/spec/fixtures/Puppetfile index 0da12a4..4b6a528 100644 --- a/spec/fixtures/Puppetfile +++ b/spec/fixtures/Puppetfile @@ -11,3 +11,8 @@ mod 'ghoneycutt/testlps', mod 'ghoneycutt/dnsclient', :git => 'git://github.com/ghoneycutt/puppet-module-dnsclient.git', :ref => 'v3.0.4' + +mod 'haf/empty-repository', + :git => 'git://github.com/haf/empty-repository.git', + :subdir => 'subdir-A' + diff --git a/spec/functional/install_spec.rb b/spec/functional/install_spec.rb index 68493f9..6816a03 100644 --- a/spec/functional/install_spec.rb +++ b/spec/functional/install_spec.rb @@ -35,14 +35,14 @@ output, status = execute_captured("bin/librarian-puppet install --path=#{temp_directory} --puppetfile=spec/fixtures/Puppetfile") status.should == 0 - Dir.entries(temp_directory).should =~ %w|. .. apache ntp trashfile dnsclient testlps| + Dir.entries(temp_directory).should =~ %w|. .. apache ntp trashfile dnsclient testlps subdir-A| end it "with --clean it cleans the directory before installing the modules in a temp directory" do output, status = execute_captured("bin/librarian-puppet install --clean --path=#{temp_directory} --puppetfile=spec/fixtures/Puppetfile") status.should == 0 - Dir.entries(temp_directory).should =~ %w|. .. apache ntp dnsclient testlps| + Dir.entries(temp_directory).should =~ %w|. .. apache ntp dnsclient testlps subdir-A| end it "with --verbose it outputs progress messages" do @@ -66,7 +66,7 @@ output, status = execute_captured("bin/librarian-puppet install --verbose --path=#{temp_directory} --puppetfile=spec/fixtures/Puppetfile") status.should == 0 output.should include('Module apache already installed') - Dir.entries(temp_directory).should =~ %w|. .. apache ntp dnsclient testlps| + Dir.entries(temp_directory).should =~ %w|. .. apache ntp dnsclient testlps subdir-A| end end end From d9bed8980643ae770fa9d98c1338b51bf1ded13e Mon Sep 17 00:00:00 2001 From: Henrik Date: Sun, 3 Nov 2013 19:19:02 +0100 Subject: [PATCH 5/5] test for subdir contents, properly this time --- lib/librarian/puppet/simple/installer.rb | 19 +++++++++---------- lib/librarian/puppet/simple/util.rb | 2 +- spec/functional/install_spec.rb | 19 +++++++++++-------- spec/spec_helper.rb | 9 +++++++-- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/lib/librarian/puppet/simple/installer.rb b/lib/librarian/puppet/simple/installer.rb index b54d02a..f699f5a 100644 --- a/lib/librarian/puppet/simple/installer.rb +++ b/lib/librarian/puppet/simple/installer.rb @@ -23,17 +23,14 @@ module Installer def install! each_module do |repo| print_verbose "\n##### processing module #{repo[:name]}..." + # module path is where ALL the modules go, not this particular one module_path = module_path() - if repo[:subdir] - module_path = File.join(module_path, repo[:subdir]) - FileUtils.mkdir_p(module_path) unless File.exists?(module_path) - end - module_dir = File.join(module_path, repo[:name]) + module_dir = File.join(module_path, repo[:subdir] || repo[:name]) unless File.exists?(module_dir) case when repo[:git] - install_git module_path, repo[:name], repo[:git], repo[:ref] + install_git module_path, repo[:name], repo[:git], repo[:ref], repo[:subdir] when repo[:tarball] install_tarball module_path, repo[:name], repo[:tarball] else @@ -48,15 +45,17 @@ def install! private # installs sources that are git repos - def install_git(module_path, module_name, repo, ref = nil) - module_dir = File.join(module_path, module_name) + def install_git(module_path, module_name, repo, ref = nil, subdir = nil) + folder_name = subdir || module_name + module_dir = File.join(module_path, folder_name) Dir.chdir(module_path) do print_verbose "cloning #{repo}" - system_cmd("git clone #{repo} #{module_name}") - Dir.chdir(module_dir) do + system_cmd("git clone #{repo} #{folder_name}") + Dir.chdir(folder_name) do system_cmd('git branch -r') system_cmd("git checkout #{ref}") if ref + system_cmd("git filter-branch --subdirectory-filter #{subdir}") if subdir end end end diff --git a/lib/librarian/puppet/simple/util.rb b/lib/librarian/puppet/simple/util.rb index d38cef7..5df1274 100644 --- a/lib/librarian/puppet/simple/util.rb +++ b/lib/librarian/puppet/simple/util.rb @@ -10,7 +10,7 @@ module Util def forge(repo) # this does nothing atm end - # figure out what directory we are working out og + # figure out what directory we are working out of def base_dir @base_dir ||= Dir.pwd end diff --git a/spec/functional/install_spec.rb b/spec/functional/install_spec.rb index 6816a03..c5b2795 100644 --- a/spec/functional/install_spec.rb +++ b/spec/functional/install_spec.rb @@ -22,30 +22,33 @@ before :each do temp_directory = Dir.mktmpdir - Dir.entries(temp_directory).should =~ ['.', '..'] + Dir.entries(temp_directory).should =~ %w|. ..| FileUtils.touch File.join(temp_directory, 'trashfile') - Dir.entries(temp_directory).should =~ ['.', '..', 'trashfile'] + Dir.entries(temp_directory).should =~ %w|. .. trashfile| end after :each do FileUtils.rm_rf temp_directory end - it "install the modules in a temp directory" do + it "install the modules in a temp directory", :type => 'integration' do output, status = execute_captured("bin/librarian-puppet install --path=#{temp_directory} --puppetfile=spec/fixtures/Puppetfile") status.should == 0 Dir.entries(temp_directory).should =~ %w|. .. apache ntp trashfile dnsclient testlps subdir-A| + Dir.entries(File.join(temp_directory, 'subdir-A')).should =~ %w|. .. .git Hello.txt| end - it "with --clean it cleans the directory before installing the modules in a temp directory" do + + + it "with --clean it cleans the directory before installing the modules in a temp directory", :type => 'integration' do output, status = execute_captured("bin/librarian-puppet install --clean --path=#{temp_directory} --puppetfile=spec/fixtures/Puppetfile") status.should == 0 Dir.entries(temp_directory).should =~ %w|. .. apache ntp dnsclient testlps subdir-A| end - it "with --verbose it outputs progress messages" do + it "with --verbose it outputs progress messages", :type => 'integration' do output, status = execute_captured("bin/librarian-puppet install --verbose --path=#{temp_directory} --puppetfile=spec/fixtures/Puppetfile") status.should == 0 @@ -57,12 +60,12 @@ before :each do temp_directory = Dir.mktmpdir - Dir.entries(temp_directory).should =~ ['.', '..'] + Dir.entries(temp_directory).should =~ %w|. ..| FileUtils.touch File.join(temp_directory, 'apache') - Dir.entries(temp_directory).should =~ ['.', '..', 'apache'] + Dir.entries(temp_directory).should =~ %w|. .. apache| end - it 'without clean it should only install ntp' do + it 'without clean it should only install ntp', :type => 'integration' do output, status = execute_captured("bin/librarian-puppet install --verbose --path=#{temp_directory} --puppetfile=spec/fixtures/Puppetfile") status.should == 0 output.should include('Module apache already installed') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 513073f..e1dc9ef 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,7 +9,12 @@ RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true config.run_all_when_everything_filtered = true - config.filter_run :focus + + # if ENV['INTEGRATION'] + # config.filter_run :type => 'integration' + # else + # config.filter_run_excluding :type => 'integration' + # end # Run specs in random order to surface order dependencies. If you find an # order dependency and want to debug it, you can fix the order by providing @@ -22,4 +27,4 @@ def execute_captured(command) condensed = stdout.readlines.join + stderr.readlines.join [condensed, $?.exitstatus] end -end \ No newline at end of file +end