puppet 2.7.8 → 2.7.9

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (98) hide show
  1. data/CHANGELOG +6 -0
  2. data/README_DEVELOPER.md +63 -0
  3. data/conf/redhat/puppet.spec +4 -1
  4. data/ext/puppetstoredconfigclean.rb +39 -27
  5. data/lib/puppet.rb +1 -1
  6. data/lib/puppet/application/agent.rb +33 -25
  7. data/lib/puppet/application/apply.rb +15 -1
  8. data/lib/puppet/application/module.rb +3 -0
  9. data/lib/puppet/defaults.rb +4 -0
  10. data/lib/puppet/face/module.rb +12 -0
  11. data/lib/puppet/face/module/build.rb +31 -0
  12. data/lib/puppet/face/module/changes.rb +38 -0
  13. data/lib/puppet/face/module/clean.rb +30 -0
  14. data/lib/puppet/face/module/generate.rb +40 -0
  15. data/lib/puppet/face/module/install.rb +83 -0
  16. data/lib/puppet/face/module/search.rb +66 -0
  17. data/lib/puppet/indirector/exec.rb +1 -1
  18. data/lib/puppet/module_tool.rb +97 -0
  19. data/lib/puppet/module_tool/applications.rb +12 -0
  20. data/lib/puppet/module_tool/applications/application.rb +83 -0
  21. data/lib/puppet/module_tool/applications/builder.rb +91 -0
  22. data/lib/puppet/module_tool/applications/checksummer.rb +47 -0
  23. data/lib/puppet/module_tool/applications/cleaner.rb +16 -0
  24. data/lib/puppet/module_tool/applications/generator.rb +141 -0
  25. data/lib/puppet/module_tool/applications/installer.rb +89 -0
  26. data/lib/puppet/module_tool/applications/searcher.rb +40 -0
  27. data/lib/puppet/module_tool/applications/unpacker.rb +70 -0
  28. data/lib/puppet/module_tool/cache.rb +56 -0
  29. data/lib/puppet/module_tool/checksums.rb +52 -0
  30. data/lib/puppet/module_tool/contents_description.rb +82 -0
  31. data/lib/puppet/module_tool/dependency.rb +24 -0
  32. data/lib/puppet/module_tool/metadata.rb +141 -0
  33. data/lib/puppet/module_tool/modulefile.rb +75 -0
  34. data/lib/puppet/module_tool/repository.rb +79 -0
  35. data/lib/puppet/module_tool/skeleton.rb +34 -0
  36. data/lib/puppet/module_tool/skeleton/templates/generator/Modulefile.erb +11 -0
  37. data/lib/puppet/module_tool/skeleton/templates/generator/README.erb +16 -0
  38. data/lib/puppet/module_tool/skeleton/templates/generator/manifests/init.pp.erb +41 -0
  39. data/lib/puppet/module_tool/skeleton/templates/generator/metadata.json +12 -0
  40. data/lib/puppet/module_tool/skeleton/templates/generator/spec/spec_helper.rb +17 -0
  41. data/lib/puppet/module_tool/skeleton/templates/generator/tests/init.pp.erb +11 -0
  42. data/lib/puppet/module_tool/utils.rb +5 -0
  43. data/lib/puppet/module_tool/utils/interrogation.rb +25 -0
  44. data/lib/puppet/network/http/api/v1.rb +2 -1
  45. data/lib/puppet/parser/functions/create_resources.rb +19 -4
  46. data/lib/puppet/rails.rb +1 -1
  47. data/lib/puppet/rails/database/schema.rb +1 -1
  48. data/lib/puppet/ssl/host.rb +16 -8
  49. data/lib/puppet/transaction.rb +1 -1
  50. data/lib/puppet/type/file.rb +7 -2
  51. data/lib/puppet/type/file/ctime.rb +1 -1
  52. data/lib/puppet/type/file/mtime.rb +1 -1
  53. data/lib/puppet/type/file/type.rb +1 -1
  54. data/lib/puppet/util/queue/stomp.rb +19 -6
  55. data/lib/puppet/util/zaml.rb +39 -5
  56. data/spec/fixtures/releases/jamtur01-apache/Modulefile +2 -0
  57. data/spec/fixtures/releases/jamtur01-apache/files/httpd +24 -0
  58. data/spec/fixtures/releases/jamtur01-apache/files/test.vhost +18 -0
  59. data/spec/fixtures/releases/jamtur01-apache/lib/puppet/provider/a2mod/debian.rb +21 -0
  60. data/spec/fixtures/releases/jamtur01-apache/lib/puppet/type/a2mod.rb +12 -0
  61. data/spec/fixtures/releases/jamtur01-apache/manifests/dev.pp +5 -0
  62. data/spec/fixtures/releases/jamtur01-apache/manifests/init.pp +34 -0
  63. data/spec/fixtures/releases/jamtur01-apache/manifests/params.pp +17 -0
  64. data/spec/fixtures/releases/jamtur01-apache/manifests/php.pp +5 -0
  65. data/spec/fixtures/releases/jamtur01-apache/manifests/ssl.pp +15 -0
  66. data/spec/fixtures/releases/jamtur01-apache/manifests/vhost.pp +15 -0
  67. data/spec/fixtures/releases/jamtur01-apache/metadata.json +1 -0
  68. data/spec/fixtures/releases/jamtur01-apache/templates/vhost-default.conf.erb +20 -0
  69. data/spec/fixtures/releases/jamtur01-apache/tests/apache.pp +1 -0
  70. data/spec/fixtures/releases/jamtur01-apache/tests/dev.pp +1 -0
  71. data/spec/fixtures/releases/jamtur01-apache/tests/init.pp +1 -0
  72. data/spec/fixtures/releases/jamtur01-apache/tests/php.pp +1 -0
  73. data/spec/fixtures/releases/jamtur01-apache/tests/ssl.pp +1 -0
  74. data/spec/fixtures/releases/jamtur01-apache/tests/vhost.pp +2 -0
  75. data/spec/integration/module_tool_spec.rb +477 -0
  76. data/spec/integration/util/windows/security_spec.rb +1 -1
  77. data/spec/unit/application/agent_spec.rb +26 -0
  78. data/spec/unit/application/apply_spec.rb +12 -1
  79. data/spec/unit/face/module/build_spec.rb +30 -0
  80. data/spec/unit/face/module/changes_spec.rb +30 -0
  81. data/spec/unit/face/module/clean_spec.rb +30 -0
  82. data/spec/unit/face/module/generate_spec.rb +30 -0
  83. data/spec/unit/face/module/install_spec.rb +75 -0
  84. data/spec/unit/face/module/search_spec.rb +40 -0
  85. data/spec/unit/face/module_spec.rb +3 -0
  86. data/spec/unit/file_bucket/dipper_spec.rb +1 -1
  87. data/spec/unit/module_tool/application_spec.rb +29 -0
  88. data/spec/unit/module_tool/metadata_spec.rb +11 -0
  89. data/spec/unit/module_tool/repository_spec.rb +52 -0
  90. data/spec/unit/module_tool_spec.rb +38 -0
  91. data/spec/unit/network/http/api/v1_spec.rb +4 -0
  92. data/spec/unit/parser/functions/create_resources_spec.rb +21 -4
  93. data/spec/unit/rails_spec.rb +89 -158
  94. data/spec/unit/ssl/host_spec.rb +10 -33
  95. data/spec/unit/type/file_spec.rb +30 -0
  96. data/spec/unit/util/queue/stomp_spec.rb +9 -4
  97. data/spec/unit/util/zaml_spec.rb +37 -0
  98. metadata +77 -11
@@ -0,0 +1,2 @@
1
+ name 'jamtur01-apache'
2
+ version '0.0.1'
@@ -0,0 +1,24 @@
1
+ # Configuration file for the httpd service.
2
+
3
+ #
4
+ # The default processing model (MPM) is the process-based
5
+ # 'prefork' model. A thread-based model, 'worker', is also
6
+ # available, but does not work with some modules (such as PHP).
7
+ # The service must be stopped before changing this variable.
8
+ #
9
+ #HTTPD=/usr/sbin/httpd.worker
10
+
11
+ #
12
+ # To pass additional options (for instance, -D definitions) to the
13
+ # httpd binary at startup, set OPTIONS here.
14
+ #
15
+ #OPTIONS=
16
+ #OPTIONS=-DDOWN
17
+
18
+ #
19
+ # By default, the httpd process is started in the C locale; to
20
+ # change the locale in which the server runs, the HTTPD_LANG
21
+ # variable can be set.
22
+ #
23
+ #HTTPD_LANG=C
24
+ export SHORTHOST=`hostname -s`
@@ -0,0 +1,18 @@
1
+ #
2
+ # Test vhost
3
+ #
4
+ NameVirtualHost *:80
5
+ <VirtualHost *:80>
6
+ ServerName testvhost
7
+ DocumentRoot /tmp/testvhost
8
+ <Directory /tmp/testvhost>
9
+ Options Indexes FollowSymLinks MultiViews
10
+ AllowOverride None
11
+ Order allow,deny
12
+ allow from all
13
+ </Directory>
14
+ ErrorLog /var/log/apache2/error.log
15
+ LogLevel warn
16
+ CustomLog /var/log/apache2/access.log combined
17
+ ServerSignature On
18
+ </VirtualHost>
@@ -0,0 +1,21 @@
1
+ Puppet::Type.type(:a2mod).provide(:debian) do
2
+ desc "Manage Apache 2 modules on Debian-like OSes (e.g. Ubuntu)"
3
+
4
+ commands :encmd => "a2enmod"
5
+ commands :discmd => "a2dismod"
6
+
7
+ defaultfor :operatingsystem => [:debian, :ubuntu]
8
+
9
+ def create
10
+ encmd resource[:name]
11
+ end
12
+
13
+ def destroy
14
+ discmd resource[:name]
15
+ end
16
+
17
+ def exists?
18
+ mod= "/etc/apache2/mods-enabled/" + resource[:name] + ".load"
19
+ File.exists?(mod)
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ Puppet::Type.newtype(:a2mod) do
2
+ @doc = "Manage Apache 2 modules"
3
+
4
+ ensurable
5
+
6
+ newparam(:name) do
7
+ desc "The name of the module to be managed"
8
+
9
+ isnamevar
10
+
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ class apache::dev {
2
+ include apache::params
3
+
4
+ package{$apache::params::apache_dev: ensure => installed}
5
+ }
@@ -0,0 +1,34 @@
1
+ # ensure apache is installed
2
+ class apache {
3
+ include apache::params
4
+ package{'httpd':
5
+ name => $apache::params::apache_name,
6
+ ensure => present,
7
+ }
8
+ service { 'httpd':
9
+ name => $apache::params::apache_name,
10
+ ensure => running,
11
+ enable => true,
12
+ subscribe => Package['httpd'],
13
+ }
14
+ #
15
+ # May want to purge all none realize modules using the resources resource type.
16
+ # A2mod resource type is broken. Look into fixing it and moving it into apache.
17
+ #
18
+ A2mod { require => Package['httpd'], notify => Service['httpd']}
19
+ @a2mod {
20
+ 'rewrite' : ensure => present;
21
+ 'headers' : ensure => present;
22
+ 'expires' : ensure => present;
23
+ }
24
+ $vdir = $operatingsystem? {
25
+ 'ubuntu' => '/etc/apache2/sites-enabled/',
26
+ default => '/etc/httpd/conf.d',
27
+ }
28
+ file { $vdir:
29
+ ensure => directory,
30
+ recurse => true,
31
+ purge => true,
32
+ notify => Service['httpd'],
33
+ }
34
+ }
@@ -0,0 +1,17 @@
1
+ class apache::params{
2
+ $user = 'www-data'
3
+ $group = 'www-data'
4
+
5
+ case $operatingsystem {
6
+ "centos": {
7
+ $apache_name = httpd
8
+ $ssl_package = mod_ssl
9
+ $apache_dev = httpd-devel
10
+ }
11
+ "ubuntu": {
12
+ $apache_name = apache2
13
+ $ssl_package = apache-ssl
14
+ $apache_dev = [ libaprutil1-dev, libapr1-dev, apache2-prefork-dev ]
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,5 @@
1
+ class apache::php{
2
+ package{'libapache2-mod-php5':
3
+ ensure => present,
4
+ }
5
+ }
@@ -0,0 +1,15 @@
1
+ class apache::ssl {
2
+ include apache
3
+
4
+
5
+ case $operatingsystem {
6
+ "centos": {
7
+ package { $apache::params::ssl_package:
8
+ require => Package['httpd'],
9
+ }
10
+ }
11
+ "ubuntu": {
12
+ a2mod { "ssl": ensure => present, }
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ define apache::vhost( $port, $docroot, $ssl=true, $template='apache/vhost-default.conf.erb', $priority, $serveraliases = '' ) {
2
+ include apache
3
+ $vdir = $operatingsystem? {
4
+ 'ubuntu' => '/etc/apache2/sites-enabled/',
5
+ default => '/etc/httpd/conf.d',
6
+ }
7
+ file{"${vdir}/${priority}-${name}":
8
+ content => template($template),
9
+ owner => 'root',
10
+ group => 'root',
11
+ mode => '777',
12
+ require => Package['httpd'],
13
+ notify => Service['httpd'],
14
+ }
15
+ }
@@ -0,0 +1 @@
1
+ {"dependencies":[],"types":[{"providers":[{"name":"a2mod","doc":"Manage Apache 2 modules on Debian and Ubuntu Required binaries: ``a2enmod``, ``a2dismod``. Default for ``operatingsystem`` == ``debianubuntu``. "}],"parameters":[{"name":"name","doc":"The name of the module to be managed"}],"properties":[{"name":"ensure","doc":"The basic property that the resource should be in. Valid values are ``present``, ``absent``."}],"name":"a2mod","doc":"Manage Apache 2 modules on Debian and Ubuntu"}],"checksums":{"manifests/params.pp":"71734796921dbdbfd58f503622527616","tests/ssl.pp":"191912535199531fd631f911c6329e56","tests/vhost.pp":"1b91e03c8ef89a7ecb6793831ac18399","manifests/php.pp":"b78cc593f1c4cd800c906e0891c9b11f","files/httpd":"295f5e924afe6f752d29327e73fe6d0a","tests/php.pp":"ce7bb9eef69d32b42a32ce32d9653625","lib/puppet/provider/a2mod/a2mod.rb":"18c5bb180b75a2375e95e07f88a94257","files/test.vhost":"0602022c19a7b6b289f218c7b93c1aea","manifests/ssl.pp":"b4334a161a2ba5fa8a62cf7b38f352c8","manifests/dev.pp":"510813942246cc9a7786d8f2d8874a35","manifests/vhost.pp":"cbc4657b0cce5cd432057393d5f6b0c2","tests/init.pp":"4eac4a7ef68499854c54a78879e25535","lib/puppet/type/a2mod.rb":"0e1b4843431413a10320ac1f6a055d15","tests/apache.pp":"4eac4a7ef68499854c54a78879e25535","tests/dev.pp":"4cf15c1fecea3ca86009f182b402c7ab","templates/vhost-default.conf.erb":"9055aed946e1111c30ab81fedac2c8b0","manifests/init.pp":"dc503e26e8021351078813b541c4bd3d","Modulefile":"d43334b4072cd1744121b3b25cd9ed15"},"version":"0.0.1","name":"jamtur01-apache"}
@@ -0,0 +1,20 @@
1
+ NameVirtualHost *:<%= port %>
2
+ <VirtualHost *:<%= port %>>
3
+ ServerName <%= name %>
4
+ <%if serveraliases.is_a? Array -%>
5
+ <% serveraliases.each do |name| -%><%= " ServerAlias #{name}\n" %><% end -%>
6
+ <% elsif serveraliases != '' -%>
7
+ <%= " ServerAlias #{serveraliases}" -%>
8
+ <% end -%>
9
+ DocumentRoot <%= docroot %>
10
+ <Directory <%= docroot %>>
11
+ Options Indexes FollowSymLinks MultiViews
12
+ AllowOverride None
13
+ Order allow,deny
14
+ allow from all
15
+ </Directory>
16
+ ErrorLog /var/log/apache2/<%= name %>_error.log
17
+ LogLevel warn
18
+ CustomLog /var/log/apache2/<%= name %>_access.log combined
19
+ ServerSignature On
20
+ </VirtualHost>
@@ -0,0 +1 @@
1
+ include apache::dev
@@ -0,0 +1 @@
1
+ include apache::php
@@ -0,0 +1 @@
1
+ include apache::ssl
@@ -0,0 +1,2 @@
1
+ include apache
2
+ apache::vhost { 'test.vhost': source => 'puppet:///modules/apache/test.vhost' }
@@ -0,0 +1,477 @@
1
+ require 'spec_helper'
2
+ require 'tmpdir'
3
+ require 'fileutils'
4
+
5
+ # FIXME This are helper methods that could be used by other tests in the
6
+ # future, should we move these to a more central location
7
+ def stub_repository_read(code, body)
8
+ kind = Net::HTTPResponse.send(:response_class, code.to_s)
9
+ response = kind.new('1.0', code.to_s, 'HTTP MESSAGE')
10
+ response.stubs(:read_body).returns(body)
11
+ Puppet::Module::Tool::Repository.any_instance.stubs(:read_response).returns(response)
12
+ end
13
+
14
+ def stub_installer_read(body)
15
+ Puppet::Module::Tool::Applications::Installer.any_instance.stubs(:read_match).returns(body)
16
+ end
17
+
18
+ def stub_cache_read(body)
19
+ Puppet::Module::Tool::Cache.any_instance.stubs(:read_retrieve).returns(body)
20
+ end
21
+
22
+ # Return path to temparory directory for testing.
23
+ def testdir
24
+ return @testdir ||= tmpdir("module_tool_testdir")
25
+ end
26
+
27
+ # Create a temporary testing directory, change into it, and execute the
28
+ # +block+. When the block exists, remove the test directory and change back
29
+ # to the previous directory.
30
+ def mktestdircd(&block)
31
+ previousdir = Dir.pwd
32
+ rmtestdir
33
+ FileUtils.mkdir_p(testdir)
34
+ Dir.chdir(testdir)
35
+ block.call
36
+ ensure
37
+ rmtestdir
38
+ Dir.chdir previousdir
39
+ end
40
+
41
+ # Remove the temporary test directory.
42
+ def rmtestdir
43
+ FileUtils.rm_rf(testdir) if File.directory?(testdir)
44
+ end
45
+ # END helper methods
46
+
47
+
48
+ # Directory that contains sample releases.
49
+ RELEASE_FIXTURES_DIR = File.join(PuppetSpec::FIXTURE_DIR, "releases")
50
+
51
+ # Return the pathname string to the directory containing the release fixture called +name+.
52
+ def release_fixture(name)
53
+ return File.join(RELEASE_FIXTURES_DIR, name)
54
+ end
55
+
56
+ # Copy the release fixture called +name+ into the current working directory.
57
+ def install_release_fixture(name)
58
+ release_fixture(name)
59
+ FileUtils.cp_r(release_fixture(name), name)
60
+ end
61
+
62
+ describe "module_tool", :fails_on_windows => true do
63
+ include PuppetSpec::Files
64
+ before do
65
+ @tmp_confdir = Puppet[:confdir] = tmpdir("module_tool_test_confdir")
66
+ @tmp_vardir = Puppet[:vardir] = tmpdir("module_tool_test_vardir")
67
+ Puppet[:module_repository] = "http://forge.puppetlabs.com"
68
+ @mytmpdir = Pathname.new(tmpdir("module_tool_test"))
69
+ @options = {}
70
+ @options[:install_dir] = @mytmpdir
71
+ @options[:module_repository] = "http://forge.puppetlabs.com"
72
+ end
73
+
74
+ def build_and_install_module
75
+ Puppet::Module::Tool::Applications::Generator.run(@full_module_name)
76
+ Puppet::Module::Tool::Applications::Builder.run(@full_module_name)
77
+
78
+ FileUtils.mv("#{@full_module_name}/pkg/#{@release_name}.tar.gz", "#{@release_name}.tar.gz")
79
+ FileUtils.rm_rf(@full_module_name)
80
+
81
+ Puppet::Module::Tool::Applications::Installer.run("#{@release_name}.tar.gz", @options)
82
+ end
83
+
84
+ # Return STDOUT and STDERR output generated from +block+ as it's run within a temporary test directory.
85
+ def run(&block)
86
+ mktestdircd do
87
+ block.call
88
+ end
89
+ end
90
+
91
+ before :all do
92
+ @username = "myuser"
93
+ @module_name = "mymodule"
94
+ @full_module_name = "#{@username}-#{@module_name}"
95
+ @version = "0.0.1"
96
+ @release_name = "#{@full_module_name}-#{@version}"
97
+ end
98
+
99
+ before :each do
100
+ Puppet.settings.stubs(:parse)
101
+ Puppet::Module::Tool::Cache.clean
102
+ end
103
+
104
+ after :each do
105
+ Puppet::Module::Tool::Cache.clean
106
+ end
107
+
108
+ describe "generate" do
109
+ it "should generate a module if given a dashed name" do
110
+ run do
111
+ Puppet::Module::Tool::Applications::Generator.run(@full_module_name)
112
+
113
+ File.directory?(@full_module_name).should == true
114
+ modulefile = File.join(@full_module_name, "Modulefile")
115
+ File.file?(modulefile).should == true
116
+ metadata = Puppet::Module::Tool::Metadata.new
117
+ Puppet::Module::Tool::ModulefileReader.evaluate(metadata, modulefile)
118
+ metadata.full_module_name.should == @full_module_name
119
+ metadata.username.should == @username
120
+ metadata.name.should == @module_name
121
+ end
122
+ end
123
+
124
+ it "should fail if given an undashed name" do
125
+ run do
126
+ lambda { Puppet::Module::Tool::Applications::Generator.run("invalid") }.should raise_error(RuntimeError)
127
+ end
128
+ end
129
+
130
+ it "should fail if directory already exists" do
131
+ run do
132
+ Puppet::Module::Tool::Applications::Generator.run(@full_module_name)
133
+ lambda { Puppet::Module::Tool::Applications::Generator.run(@full_module_name) }.should raise_error(ArgumentError)
134
+ end
135
+ end
136
+
137
+ it "should return an array of Pathname objects representing paths of generated files" do
138
+ run do
139
+ return_value = Puppet::Module::Tool::Applications::Generator.run(@full_module_name)
140
+ return_value.each do |generated_file|
141
+ generated_file.should be_kind_of(Pathname)
142
+ end
143
+ return_value.should be_kind_of(Array)
144
+ end
145
+ end
146
+ end
147
+
148
+ describe "build" do
149
+ it "should build a module in a directory" do
150
+ run do
151
+ Puppet::Module::Tool::Applications::Generator.run(@full_module_name)
152
+ Puppet::Module::Tool::Applications::Builder.run(@full_module_name)
153
+
154
+ File.directory?(File.join(@full_module_name, "pkg", @release_name)).should == true
155
+ File.file?(File.join(@full_module_name, "pkg", @release_name + ".tar.gz")).should == true
156
+ metadata_file = File.join(@full_module_name, "pkg", @release_name, "metadata.json")
157
+ File.file?(metadata_file).should == true
158
+ metadata = PSON.parse(File.read(metadata_file))
159
+ metadata["name"].should == @full_module_name
160
+ metadata["version"].should == @version
161
+ metadata["checksums"].should be_a_kind_of(Hash)
162
+ metadata["dependencies"].should == []
163
+ metadata["types"].should == []
164
+ end
165
+ end
166
+
167
+ it "should build a module's checksums" do
168
+ run do
169
+ Puppet::Module::Tool::Applications::Generator.run(@full_module_name)
170
+ Puppet::Module::Tool::Applications::Builder.run(@full_module_name)
171
+
172
+ metadata_file = File.join(@full_module_name, "pkg", @release_name, "metadata.json")
173
+ metadata = PSON.parse(File.read(metadata_file))
174
+ metadata["checksums"].should be_a_kind_of(Hash)
175
+
176
+ modulefile_path = Pathname.new(File.join(@full_module_name, "Modulefile"))
177
+ metadata["checksums"]["Modulefile"].should == Digest::MD5.hexdigest(modulefile_path.read)
178
+ end
179
+ end
180
+
181
+ it "should build a module's types and providers" do
182
+ run do
183
+ name = "jamtur01-apache"
184
+ install_release_fixture name
185
+ Puppet::Module::Tool::Applications::Builder.run(name)
186
+
187
+ metadata_file = File.join(name, "pkg", "#{name}-0.0.1", "metadata.json")
188
+ metadata = PSON.parse(File.read(metadata_file))
189
+
190
+ metadata["types"].size.should == 1
191
+ type = metadata["types"].first
192
+ type["name"].should == "a2mod"
193
+ type["doc"].should == "Manage Apache 2 modules"
194
+
195
+
196
+ type["parameters"].size.should == 1
197
+ type["parameters"].first.tap do |o|
198
+ o["name"].should == "name"
199
+ o["doc"].should == "The name of the module to be managed"
200
+ end
201
+
202
+ type["properties"].size.should == 1
203
+ type["properties"].first.tap do |o|
204
+ o["name"].should == "ensure"
205
+ o["doc"].should =~ /present.+absent/
206
+ end
207
+
208
+ type["providers"].size.should == 1
209
+ type["providers"].first.tap do |o|
210
+ o["name"].should == "debian"
211
+ o["doc"].should =~ /Manage Apache 2 modules on Debian-like OSes/
212
+ end
213
+ end
214
+ end
215
+
216
+ it "should build a module's dependencies" do
217
+ run do
218
+ Puppet::Module::Tool::Applications::Generator.run(@full_module_name)
219
+ modulefile = File.join(@full_module_name, "Modulefile")
220
+
221
+ dependency1_name = "anotheruser-anothermodule"
222
+ dependency1_requirement = ">= 1.2.3"
223
+ dependency2_name = "someuser-somemodule"
224
+ dependency2_requirement = "4.2"
225
+ dependency2_repository = "http://some.repo"
226
+
227
+ File.open(modulefile, "a") do |handle|
228
+ handle.puts "dependency '#{dependency1_name}', '#{dependency1_requirement}'"
229
+ handle.puts "dependency '#{dependency2_name}', '#{dependency2_requirement}', '#{dependency2_repository}'"
230
+ end
231
+
232
+ Puppet::Module::Tool::Applications::Builder.run(@full_module_name)
233
+
234
+ metadata_file = File.join(@full_module_name, "pkg", "#{@full_module_name}-#{@version}", "metadata.json")
235
+ metadata = PSON.parse(File.read(metadata_file))
236
+
237
+ metadata['dependencies'].size.should == 2
238
+ metadata['dependencies'].sort_by{|t| t['name']}.tap do |dependencies|
239
+ dependencies[0].tap do |dependency1|
240
+ dependency1['name'].should == dependency1_name
241
+ dependency1['version_requirement'].should == dependency1_requirement
242
+ dependency1['repository'].should be_nil
243
+ end
244
+
245
+ dependencies[1].tap do |dependency2|
246
+ dependency2['name'].should == dependency2_name
247
+ dependency2['version_requirement'].should == dependency2_requirement
248
+ dependency2['repository'].should == dependency2_repository
249
+ end
250
+ end
251
+ end
252
+ end
253
+
254
+ it "should rebuild a module in a directory" do
255
+ run do
256
+ Puppet::Module::Tool::Applications::Generator.run(@full_module_name)
257
+ Puppet::Module::Tool::Applications::Builder.run(@full_module_name)
258
+ Puppet::Module::Tool::Applications::Builder.run(@full_module_name)
259
+ end
260
+ end
261
+
262
+ it "should build a module in the current directory" do
263
+ run do
264
+ Puppet::Module::Tool::Applications::Generator.run(@full_module_name)
265
+ Dir.chdir(@full_module_name)
266
+ Puppet::Module::Tool::Applications::Builder.run(Puppet::Module::Tool.find_module_root(nil))
267
+
268
+ File.file?(File.join("pkg", @release_name + ".tar.gz")).should == true
269
+ end
270
+ end
271
+
272
+ it "should fail to build a module without a Modulefile" do
273
+ run do
274
+ Puppet::Module::Tool::Applications::Generator.run(@full_module_name)
275
+ FileUtils.rm(File.join(@full_module_name, "Modulefile"))
276
+
277
+ lambda { Puppet::Module::Tool::Applications::Builder.run(Puppet::Module::Tool.find_module_root(@full_module_name)) }.should raise_error(ArgumentError)
278
+ end
279
+ end
280
+
281
+ it "should fail to build a module directory that doesn't exist" do
282
+ run do
283
+ lambda { Puppet::Module::Tool::Applications::Builder.run(Puppet::Module::Tool.find_module_root(@full_module_name)) }.should raise_error(ArgumentError)
284
+ end
285
+ end
286
+
287
+ it "should fail to build a module in the current directory that's not a module" do
288
+ run do
289
+ lambda { Puppet::Module::Tool::Applications::Builder.run(Puppet::Module::Tool.find_module_root(nil)) }.should raise_error(ArgumentError)
290
+ end
291
+ end
292
+
293
+ it "should return a Pathname object representing the path to the release archive." do
294
+ run do
295
+ Puppet::Module::Tool::Applications::Generator.run(@full_module_name)
296
+ Puppet::Module::Tool::Applications::Builder.run(@full_module_name).should be_kind_of(Pathname)
297
+ end
298
+ end
299
+ end
300
+
301
+ describe "search" do
302
+ it "should display matching modules" do
303
+ run do
304
+ stub_repository_read 200, <<-HERE
305
+ [
306
+ {"full_module_name": "cli", "version": "1.0"},
307
+ {"full_module_name": "web", "version": "2.0"}
308
+ ]
309
+ HERE
310
+ Puppet::Module::Tool::Applications::Searcher.run("mymodule", @options).size.should == 2
311
+ end
312
+ end
313
+
314
+ it "should display no matches" do
315
+ run do
316
+ stub_repository_read 200, "[]"
317
+ Puppet::Module::Tool::Applications::Searcher.run("mymodule", @options).should == []
318
+ end
319
+ end
320
+
321
+ it "should fail if can't get a connection" do
322
+ run do
323
+ stub_repository_read 500, "OH NOES!!1!"
324
+ lambda { Puppet::Module::Tool::Applications::Searcher.run("mymodule", @options) }.should raise_error(RuntimeError)
325
+ end
326
+ end
327
+
328
+ it "should return an array of module metadata hashes" do
329
+ run do
330
+ results = <<-HERE
331
+ [
332
+ {"full_module_name": "cli", "version": "1.0"},
333
+ {"full_module_name": "web", "version": "2.0"}
334
+ ]
335
+ HERE
336
+ expected = [
337
+ {"version"=>"1.0", "full_module_name"=>"cli"},
338
+ {"version"=>"2.0", "full_module_name"=>"web"}
339
+ ]
340
+ stub_repository_read 200, results
341
+ return_value = Puppet::Module::Tool::Applications::Searcher.run("mymodule", @options)
342
+ return_value.should == expected
343
+ return_value.should be_kind_of(Array)
344
+ end
345
+ end
346
+ end
347
+
348
+ describe "install" do
349
+ it "should install a module to the puppet modulepath by default" do
350
+ myothertmpdir = Pathname.new(tmpdir("module_tool_test_myothertmpdir"))
351
+ run do
352
+ @options[:install_dir] = myothertmpdir
353
+ Puppet::Module::Tool.unstub(:install_dir)
354
+
355
+ build_and_install_module
356
+
357
+ File.directory?(myothertmpdir + @module_name).should == true
358
+ File.file?(myothertmpdir + @module_name + 'metadata.json').should == true
359
+ end
360
+ end
361
+
362
+ it "should install a module from a filesystem path" do
363
+ run do
364
+ build_and_install_module
365
+
366
+ File.directory?(@mytmpdir + @module_name).should == true
367
+ File.file?(@mytmpdir + @module_name + 'metadata.json').should == true
368
+ end
369
+ end
370
+
371
+ it "should install a module from a webserver URL" do
372
+ run do
373
+ Puppet::Module::Tool::Applications::Generator.run(@full_module_name)
374
+ Puppet::Module::Tool::Applications::Builder.run(@full_module_name)
375
+
376
+ stub_cache_read File.read("#{@full_module_name}/pkg/#{@release_name}.tar.gz")
377
+ FileUtils.rm_rf(@full_module_name)
378
+
379
+ stub_installer_read <<-HERE
380
+ {"file": "/foo/bar/#{@release_name}.tar.gz", "version": "#{@version}"}
381
+ HERE
382
+
383
+ Puppet::Module::Tool::Applications::Installer.run(@full_module_name, @options)
384
+
385
+ File.directory?(@mytmpdir + @module_name).should == true
386
+ File.file?(@mytmpdir + @module_name + 'metadata.json').should == true
387
+ end
388
+ end
389
+
390
+ it "should install a module from a webserver URL using a version requirement" # TODO
391
+
392
+ it "should fail if module isn't a slashed name" do
393
+ run do
394
+ lambda { Puppet::Module::Tool::Applications::Installer.run("invalid") }.should raise_error(RuntimeError)
395
+ end
396
+ end
397
+
398
+ it "should fail if module doesn't exist on webserver" do
399
+ run do
400
+ stub_installer_read "{}"
401
+ lambda { Puppet::Module::Tool::Applications::Installer.run("not-found", @options) }.should raise_error(RuntimeError)
402
+ end
403
+ end
404
+
405
+ it "should fail gracefully when receiving invalid PSON" do
406
+ pending "Implement PSON error wrapper" # TODO
407
+ run do
408
+ stub_installer_read "1/0"
409
+ lambda { Puppet::Module::Tool::Applications::Installer.run("not-found") }.should raise_error(SystemExit)
410
+ end
411
+ end
412
+
413
+ it "should fail if installing a module that's already installed" do
414
+ run do
415
+ name = "myuser-mymodule"
416
+ Dir.mkdir name
417
+ lambda { Puppet::Module::Tool::Applications::Installer.run(name) }.should raise_error(ArgumentError)
418
+ end
419
+ end
420
+
421
+ it "should return a Pathname object representing the path to the installed module" do
422
+ run do
423
+ Puppet::Module::Tool::Applications::Generator.run(@full_module_name)
424
+ Puppet::Module::Tool::Applications::Builder.run(@full_module_name)
425
+
426
+ stub_cache_read File.read("#{@full_module_name}/pkg/#{@release_name}.tar.gz")
427
+ FileUtils.rm_rf(@full_module_name)
428
+
429
+ stub_installer_read <<-HERE
430
+ {"file": "/foo/bar/#{@release_name}.tar.gz", "version": "#{@version}"}
431
+ HERE
432
+
433
+ Puppet::Module::Tool::Applications::Installer.run(@full_module_name, @options).should be_kind_of(Pathname)
434
+ end
435
+ end
436
+
437
+ end
438
+
439
+ describe "clean" do
440
+ require 'puppet/module_tool'
441
+ it "should clean cache" do
442
+ run do
443
+ build_and_install_module
444
+ Puppet::Module::Tool::Cache.base_path.directory?.should == true
445
+ Puppet::Module::Tool::Applications::Cleaner.run
446
+ Puppet::Module::Tool::Cache.base_path.directory?.should == false
447
+ end
448
+ end
449
+
450
+ it "should return a status Hash" do
451
+ run do
452
+ build_and_install_module
453
+ return_value = Puppet::Module::Tool::Applications::Cleaner.run
454
+ return_value.should include(:msg)
455
+ return_value.should include(:status)
456
+ return_value.should be_kind_of(Hash)
457
+ end
458
+ end
459
+ end
460
+
461
+ describe "changes" do
462
+ it "should return an array of modified files" do
463
+ run do
464
+ Puppet::Module::Tool::Applications::Generator.run(@full_module_name)
465
+ Puppet::Module::Tool::Applications::Builder.run(@full_module_name)
466
+ Dir.chdir("#{@full_module_name}/pkg/#{@release_name}")
467
+ File.open("Modulefile", "a") do |handle|
468
+ handle.puts
469
+ handle.puts "# Added"
470
+ end
471
+ return_value = Puppet::Module::Tool::Applications::Checksummer.run(".")
472
+ return_value.should include("Modulefile")
473
+ return_value.should be_kind_of(Array)
474
+ end
475
+ end
476
+ end
477
+ end