r10k 1.1.4 → 1.2.0rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +8 -8
  2. data/.gitignore +1 -0
  3. data/.nodeset.yml +7 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +2 -1
  6. data/CHANGELOG +17 -12
  7. data/Gemfile +8 -0
  8. data/README.markdown +4 -2
  9. data/Rakefile +1 -0
  10. data/doc/dynamic-environments.markdown +206 -0
  11. data/doc/puppetfile.markdown +87 -0
  12. data/lib/r10k/cli.rb +1 -1
  13. data/lib/r10k/errors.rb +30 -3
  14. data/lib/r10k/execution.rb +5 -2
  15. data/lib/r10k/git/cache.rb +26 -42
  16. data/lib/r10k/git/commit.rb +22 -0
  17. data/lib/r10k/git/errors.rb +31 -22
  18. data/lib/r10k/git/head.rb +33 -0
  19. data/lib/r10k/git/ref.rb +63 -0
  20. data/lib/r10k/git/repository.rb +65 -36
  21. data/lib/r10k/git/tag.rb +26 -0
  22. data/lib/r10k/git/working_dir.rb +93 -83
  23. data/lib/r10k/git.rb +14 -0
  24. data/lib/r10k/module/forge.rb +129 -62
  25. data/lib/r10k/module/git.rb +72 -6
  26. data/lib/r10k/module/metadata.rb +47 -0
  27. data/lib/r10k/module/svn.rb +99 -0
  28. data/lib/r10k/module.rb +1 -0
  29. data/lib/r10k/module_repository/forge.rb +64 -0
  30. data/lib/r10k/module_repository.rb +8 -0
  31. data/lib/r10k/semver.rb +1 -1
  32. data/lib/r10k/svn/working_dir.rb +76 -0
  33. data/lib/r10k/task/deployment.rb +21 -28
  34. data/lib/r10k/util/subprocess/io.rb +12 -0
  35. data/lib/r10k/util/subprocess/result.rb +36 -0
  36. data/lib/r10k/util/subprocess/runner.rb +88 -0
  37. data/lib/r10k/util/subprocess.rb +107 -0
  38. data/lib/r10k/version.rb +1 -1
  39. data/r10k.gemspec +11 -1
  40. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/can_fetch_all_versions_of_a_given_module.yml +42 -0
  41. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/can_fetch_the_latest_version_of_a_given_module.yml +42 -0
  42. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_all_versions_of_a_given_module.yml +42 -0
  43. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_the_latest_version_of_a_given_module.yml +42 -0
  44. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions.yml +42 -0
  45. data/spec/fixtures/vcr/cassettes/R10K_Module_Forge/and_the_expected_version_is_latest/sets_the_expected_version_based_on_the_latest_forge_version.yml +42 -0
  46. data/spec/rspec-system-r10k/puppetfile.rb +24 -0
  47. data/spec/rspec-system-r10k/tmpdir.rb +32 -0
  48. data/spec/shared-examples/git-ref.rb +49 -0
  49. data/spec/spec_helper.rb +23 -0
  50. data/spec/system/module/forge/install_spec.rb +51 -0
  51. data/spec/system/module/git/install_spec.rb +117 -0
  52. data/spec/system/module/svn/install_spec.rb +51 -0
  53. data/spec/system/module/svn/update_spec.rb +38 -0
  54. data/spec/system/spec_helper.rb +60 -0
  55. data/spec/system/system-helpers.rb +4 -0
  56. data/spec/system/version_spec.rb +7 -0
  57. data/spec/system-provisioning/el.rb +38 -0
  58. data/spec/unit/deployment/source_spec.rb +1 -1
  59. data/spec/unit/git/cache_spec.rb +38 -0
  60. data/spec/unit/git/commit_spec.rb +33 -0
  61. data/spec/unit/git/head_spec.rb +27 -0
  62. data/spec/unit/git/ref_spec.rb +68 -0
  63. data/spec/unit/git/tag_spec.rb +31 -0
  64. data/spec/unit/module/forge_spec.rb +157 -37
  65. data/spec/unit/module/git_spec.rb +49 -0
  66. data/spec/unit/module/metadata_spec.rb +68 -0
  67. data/spec/unit/module/svn_spec.rb +146 -0
  68. data/spec/unit/module_repository/forge_spec.rb +32 -0
  69. metadata +151 -8
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://forge.puppetlabs.com/api/v1/releases.json?module=adrien%2Fboolean
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.8
12
+ response:
13
+ status:
14
+ code: 200
15
+ message:
16
+ headers:
17
+ server:
18
+ - nginx
19
+ date:
20
+ - Wed, 25 Dec 2013 23:40:52 GMT
21
+ content-type:
22
+ - application/json
23
+ content-length:
24
+ - '432'
25
+ connection:
26
+ - close
27
+ status:
28
+ - 200 OK
29
+ x-frame-options:
30
+ - sameorigin
31
+ x-xss-protection:
32
+ - 1; mode=block
33
+ x-node:
34
+ - forgeweb02
35
+ x-revision:
36
+ - b288c1e7e86f82eef7692085670c78693062c84d
37
+ body:
38
+ encoding: US-ASCII
39
+ string: ! '{"adrien/boolean":[{"file":"/system/releases/a/adrien/adrien-boolean-0.9.0-rc1.tar.gz","version":"0.9.0-rc1","dependencies":[]},{"file":"/system/releases/a/adrien/adrien-boolean-0.9.0.tar.gz","version":"0.9.0","dependencies":[]},{"file":"/system/releases/a/adrien/adrien-boolean-1.0.0.tar.gz","version":"1.0.0","dependencies":[]},{"file":"/system/releases/a/adrien/adrien-boolean-1.0.1.tar.gz","version":"1.0.1","dependencies":[]}]}'
40
+ http_version:
41
+ recorded_at: Wed, 25 Dec 2013 23:42:06 GMT
42
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://forge.puppetlabs.com/api/v1/releases.json?module=branan%2Feight_hundred
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.8
12
+ response:
13
+ status:
14
+ code: 200
15
+ message:
16
+ headers:
17
+ server:
18
+ - nginx
19
+ date:
20
+ - Thu, 26 Dec 2013 03:36:17 GMT
21
+ content-type:
22
+ - application/json
23
+ content-length:
24
+ - '133'
25
+ connection:
26
+ - close
27
+ status:
28
+ - 200 OK
29
+ x-frame-options:
30
+ - sameorigin
31
+ x-xss-protection:
32
+ - 1; mode=block
33
+ x-node:
34
+ - forgeweb01
35
+ x-revision:
36
+ - b288c1e7e86f82eef7692085670c78693062c84d
37
+ body:
38
+ encoding: US-ASCII
39
+ string: ! '{"branan/eight_hundred":[{"file":"/system/releases/b/branan/branan-eight_hundred-8.0.0.tar.gz","version":"8.0.0","dependencies":[]}]}'
40
+ http_version:
41
+ recorded_at: Thu, 26 Dec 2013 03:37:31 GMT
42
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,24 @@
1
+ require 'tempfile'
2
+
3
+ module RSpecSystem
4
+ module Puppetfile
5
+ def puppetfile_install(options = {})
6
+ expected_exit_code = options.fetch(:exit_code, 0)
7
+
8
+ shell %[r10k puppetfile install] do |results|
9
+ expect(results.exit_code).to eq expected_exit_code
10
+ end
11
+ end
12
+
13
+ def create_puppetfile(*mods)
14
+ tmp = Tempfile.new('rs-r10k-puppetfile')
15
+ tmp.write(mods.join("\n"))
16
+ tmp.flush
17
+ rcp :sp => tmp.path, :dp => "Puppetfile"
18
+ end
19
+ end
20
+ end
21
+
22
+ RSpec.configure do |config|
23
+ config.include RSpecSystem::Puppetfile
24
+ end
@@ -0,0 +1,32 @@
1
+ # Create and teardown a tmpdir around rspec example groups.
2
+
3
+ module RSpecSystem
4
+ module Tmpdir
5
+ def tmpdir
6
+ dir = RSpec.configuration.tmpdir_stack.last
7
+ if dir.nil?
8
+ raise ArgumentError, "No tmpdir currently defined"
9
+ else
10
+ dir
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ RSpec.configure do |config|
17
+
18
+ config.add_setting(:tmpdir_stack, :default => [])
19
+
20
+ config.include RSpecSystem::Tmpdir
21
+ config.extend RSpecSystem::Tmpdir
22
+
23
+ config.before(:all, :rs_tmpdir => true) do |example|
24
+ shell 'mktemp -p $PWD -d rs.XXXXXXXX' do |sh|
25
+ RSpec.configuration.tmpdir_stack.push sh.stdout.chomp
26
+ end
27
+ end
28
+
29
+ config.after(:all, :rs_tmpdir => true) do |example|
30
+ RSpec.configuration.tmpdir_stack.pop
31
+ end
32
+ end
@@ -0,0 +1,49 @@
1
+ shared_examples_for "a git ref" do
2
+
3
+ it "can be created with an optional repository" do
4
+ ref = described_class.new(ref, repo)
5
+ expect(ref.repository).to eq repo
6
+ end
7
+
8
+ describe "comparing to another object" do
9
+ let(:other) { double('equal') }
10
+
11
+ it "is true if the resolved SHA1s match" do
12
+ expect(other).to receive(:sha1).and_return 'fcf6140cf3e0b3738583167702176867833ec2a7'
13
+ expect(subject).to receive(:sha1).and_return 'fcf6140cf3e0b3738583167702176867833ec2a7'
14
+ expect(subject == other).to be_true
15
+ end
16
+
17
+ it "is false if the resolved SHA1s don't match" do
18
+ expect(other).to receive(:sha1).and_return '57d31c788610d7d6a1c139b4ffff0d60888ca742'
19
+ expect(subject).to receive(:sha1).and_return 'fcf6140cf3e0b3738583167702176867833ec2a7'
20
+ expect(subject == other).to be_false
21
+ end
22
+
23
+ it "is false if an argumenterror is raised while comparing the SHA1s" do
24
+ expect(other).to receive(:sha1).and_return 'fcf6140cf3e0b3738583167702176867833ec2a7'
25
+ expect(subject).to receive(:sha1).and_raise(ArgumentError, "Cannot resolve")
26
+ expect(subject == other).to be_false
27
+ end
28
+
29
+ it "is false if a nonexistenthasherror is raised while comparing the SHA1s" do
30
+ expect(other).to receive(:sha1).and_return 'fcf6140cf3e0b3738583167702176867833ec2a7'
31
+ expect(subject).to receive(:sha1).and_raise(R10K::Git::UnresolvableRefError, :ref => "hash")
32
+ expect(subject == other).to be_false
33
+ end
34
+ end
35
+ end
36
+
37
+ shared_examples_for "an immutable git ref" do
38
+ describe "determining if the ref needs to be fetched" do
39
+ it "is false when the ref can be resolved" do
40
+ expect(subject).to receive(:resolvable?).and_return true
41
+ expect(subject.fetch?).to be_false
42
+ end
43
+
44
+ it "is true when the ref cannot be resolved" do
45
+ expect(subject).to receive(:resolvable?).and_return false
46
+ expect(subject.fetch?).to be_true
47
+ end
48
+ end
49
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,33 @@
1
1
  require 'r10k'
2
2
 
3
+ require 'shared-examples/git-ref'
4
+
3
5
  PROJECT_ROOT = File.expand_path('..', File.dirname(__FILE__))
4
6
 
7
+ require 'vcr'
8
+ VCR.configure do |vcr|
9
+ vcr.cassette_library_dir = File.expand_path('spec/fixtures/vcr/cassettes', PROJECT_ROOT)
10
+ vcr.hook_into :faraday
11
+ vcr.configure_rspec_metadata!
12
+ end
13
+
5
14
  RSpec.configure do |config|
6
15
  # Filter out integration tests by default
7
16
  #
8
17
  # To run integration tests, run `rspec --tag integration`
9
18
  config.filter_run_excluding :integration => true
10
19
  end
20
+
21
+ shared_context 'stub logging' do
22
+ before do
23
+ log = double('stub logger').as_null_object
24
+ allow_any_instance_of(described_class).to receive(:logger).and_return log
25
+ end
26
+ end
27
+
28
+ shared_context 'fail on execution' do
29
+ before do
30
+ allow_any_instance_of(described_class).to receive(:execute).and_raise "Tests should never invoke system calls"
31
+ allow_any_instance_of(R10K::Util::Subprocess).to receive(:execute).and_raise "Tests should never invoke system calls"
32
+ end
33
+ end
@@ -0,0 +1,51 @@
1
+ require 'system/spec_helper'
2
+
3
+ describe 'installing modules from the forge' do
4
+
5
+ describe 'when no version is specified' do
6
+
7
+ include_context 'system module installation'
8
+
9
+ before(:all) do
10
+ shell %[echo 'mod "adrien/boolean"' > ./Puppetfile]
11
+ shell %[r10k puppetfile install]
12
+ end
13
+
14
+ describe file('modules/boolean/metadata.json') do
15
+ its(:content) { should match /adrien-boolean/ }
16
+ its(:content) { should match /version.*1\.0\.1/ }
17
+ end
18
+ end
19
+
20
+ describe 'when a specific version is specified' do
21
+
22
+ include_context 'system module installation'
23
+
24
+ before(:all) do
25
+ shell %[echo 'mod "adrien/boolean", "0.9.0"' > ./Puppetfile]
26
+ shell %[r10k puppetfile install]
27
+ end
28
+
29
+ describe file('modules/boolean/metadata.json') do
30
+ its(:content) { should match /adrien-boolean/ }
31
+ its(:content) { should match /version.*0\.9\.0/ }
32
+ end
33
+ end
34
+
35
+ describe 'when the latest version is requested' do
36
+
37
+ include_context 'system module installation'
38
+
39
+ before(:all) do
40
+ shell %[echo 'mod "adrien/boolean", "0.9.0"' > ./Puppetfile]
41
+ shell %[r10k puppetfile install]
42
+ shell %[echo 'mod "adrien/boolean", :latest' > ./Puppetfile]
43
+ end
44
+
45
+ it 'upgrades to the latest version' do
46
+ shell %[r10k puppetfile install]
47
+
48
+ expect(file('modules/boolean/metadata.json').content).to match /version.*1\.0\.1/
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,117 @@
1
+ require 'system/spec_helper'
2
+
3
+ describe 'installing modules from git' do
4
+
5
+ before(:all) { yum_install 'git' }
6
+ after(:all) { shell %[yum -y remove git] }
7
+
8
+ describe 'when no version is specified' do
9
+
10
+ include_context 'system module installation'
11
+
12
+ before(:all) do
13
+ create_puppetfile(
14
+ %[mod 'boolean', :git => 'git://github.com/adrienthebo/puppet-boolean']
15
+ )
16
+ end
17
+ it "defaults to 'master'" do
18
+ puppetfile_install
19
+
20
+ shell %[git --git-dir=modules/boolean/.git rev-parse HEAD] do |results|
21
+ expect(results.stdout).to match /157011a4eaa27f1202a9d94335ee4876b26d377e/
22
+ end
23
+ end
24
+ end
25
+
26
+ describe "with a ref" do
27
+
28
+ include_context 'system module installation'
29
+
30
+ before(:all) do
31
+ create_puppetfile(
32
+ %[mod 'boolean',
33
+ :git => 'git://github.com/adrienthebo/puppet-boolean',
34
+ :ref => '0.9.0'
35
+ ]
36
+ )
37
+ end
38
+
39
+ it "checks out the tag when the ref is a tag" do
40
+ puppetfile_install
41
+
42
+ shell %[git --git-dir=modules/boolean/.git rev-parse HEAD] do |results|
43
+ expect(results.stdout).to match /3084373e8d181cf2fea5b4ade2690ba22872bd67/
44
+ end
45
+ end
46
+
47
+ it "checks out the commit when the ref is a commit"
48
+ it "checks out the branch when the ref is a branch"
49
+ end
50
+
51
+ describe "with a tag" do
52
+
53
+ include_context 'system module installation'
54
+
55
+ before(:all) do
56
+ create_puppetfile(
57
+ %[mod 'boolean',
58
+ :git => 'git://github.com/adrienthebo/puppet-boolean',
59
+ :tag => '0.9.0'
60
+ ]
61
+ )
62
+ end
63
+
64
+ it "checks out the tag" do
65
+ puppetfile_install
66
+
67
+ shell %[git --git-dir=modules/boolean/.git rev-parse HEAD] do |results|
68
+ expect(results.stdout).to match /3084373e8d181cf2fea5b4ade2690ba22872bd67/
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "with a commit" do
74
+
75
+ include_context 'system module installation'
76
+
77
+ before(:all) do
78
+ create_puppetfile(
79
+ %[mod 'boolean',
80
+ :git => 'git://github.com/adrienthebo/puppet-boolean',
81
+ :commit => 'd98ba4af3b4fd632fc7f2d652c4f9e142186dbd1'
82
+ ]
83
+ )
84
+ end
85
+
86
+ it "checks out the commit" do
87
+ puppetfile_install
88
+
89
+ shell %[git --git-dir=modules/boolean/.git rev-parse HEAD] do |results|
90
+ expect(results.stdout).to match /d98ba4af3b4fd632fc7f2d652c4f9e142186dbd1/
91
+ end
92
+ end
93
+ end
94
+
95
+ describe "with a branch" do
96
+
97
+ include_context 'system module installation'
98
+
99
+ before(:all) do
100
+ create_puppetfile(
101
+ %[mod 'boolean',
102
+ :git => 'git://github.com/adrienthebo/puppet-boolean',
103
+ :branch => 'master'
104
+ ]
105
+ )
106
+ end
107
+
108
+ it "checks out the branch" do
109
+ puppetfile_install
110
+
111
+ shell %[git --git-dir=modules/boolean/.git rev-parse HEAD] do |results|
112
+ expect(results.stdout).to match /157011a4eaa27f1202a9d94335ee4876b26d377e/
113
+ end
114
+ end
115
+ end
116
+
117
+ end
@@ -0,0 +1,51 @@
1
+ require 'system/spec_helper'
2
+
3
+ describe 'installing modules from SVN' do
4
+
5
+ extend SystemProvisioning::EL
6
+
7
+ before(:all) { yum_install 'subversion' }
8
+ after(:all) { shell %[yum -y remove subversion] }
9
+
10
+ describe 'when no version is specified' do
11
+
12
+ include_context 'system module installation'
13
+
14
+ before(:all) do
15
+ shell %[echo "mod 'gitolite', :svn => 'https://github.com/nvalentine-puppetlabs/puppet-gitolite/trunk'" > ./Puppetfile]
16
+ end
17
+
18
+ it "installs the module successfully" do
19
+ shell %[r10k puppetfile install] do |sh|
20
+ expect(sh.exit_code).to eq 0
21
+ end
22
+ end
23
+
24
+ it "creates the svn module" do
25
+ expect(file('modules/gitolite/.svn')).to be_directory
26
+ end
27
+ end
28
+
29
+ describe 'when a revision is specified' do
30
+
31
+ include_context 'system module installation'
32
+
33
+ before(:all) do
34
+ shell %[echo "mod 'gitolite', :svn => 'https://github.com/nvalentine-puppetlabs/puppet-gitolite/trunk', :rev => '10'" > ./Puppetfile]
35
+ end
36
+
37
+ it "installs the module successfully" do
38
+ shell %[r10k puppetfile install] do |sh|
39
+ expect(sh.exit_code).to eq 0
40
+ end
41
+ end
42
+
43
+ it "creates the svn module" do
44
+ expect(file('modules/gitolite/.svn')).to be_directory
45
+ end
46
+
47
+ it "checks out the specific revision" do
48
+ expect(command('cd modules/gitolite; svn info')).to return_stdout /Revision: 10/
49
+ end
50
+ end
51
+ end