puppet 0.25.0 → 0.25.1
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.
- data/CHANGELOG +4772 -19114
- data/README +1 -1
- data/Rakefile +7 -25
- data/{sbin → bin}/puppetca +0 -0
- data/{sbin → bin}/puppetd +0 -0
- data/{sbin → bin}/puppetmasterd +0 -0
- data/{sbin → bin}/puppetqd +0 -0
- data/{sbin → bin}/puppetrun +0 -0
- data/conf/osx/createpackage.sh +1 -1
- data/conf/redhat/client.init +6 -3
- data/conf/redhat/puppet.spec +26 -14
- data/conf/redhat/server.init +3 -2
- data/ext/vim/syntax/puppet.vim +4 -1
- data/install.rb +25 -7
- data/lib/puppet.rb +1 -1
- data/lib/puppet/agent.rb +2 -2
- data/lib/puppet/application/puppet.rb +3 -3
- data/lib/puppet/application/puppetd.rb +0 -7
- data/lib/puppet/application/puppetdoc.rb +1 -0
- data/lib/puppet/application/puppetmasterd.rb +2 -2
- data/lib/puppet/configurer.rb +6 -1
- data/lib/puppet/configurer/fact_handler.rb +2 -2
- data/lib/puppet/defaults.rb +2 -2
- data/lib/puppet/external/nagios/base.rb +4 -3
- data/lib/puppet/external/pson/common.rb +367 -0
- data/lib/puppet/external/pson/pure.rb +77 -0
- data/lib/puppet/external/pson/pure/generator.rb +429 -0
- data/lib/puppet/external/pson/pure/parser.rb +269 -0
- data/lib/puppet/external/pson/version.rb +8 -0
- data/lib/puppet/feature/pson.rb +6 -0
- data/lib/puppet/feature/rails.rb +1 -5
- data/lib/puppet/file_serving/configuration.rb +2 -2
- data/lib/puppet/indirector/certificate/rest.rb +6 -0
- data/lib/puppet/indirector/facts/facter.rb +1 -1
- data/lib/puppet/indirector/ldap.rb +1 -1
- data/lib/puppet/indirector/queue.rb +3 -3
- data/lib/puppet/indirector/rest.rb +1 -1
- data/lib/puppet/network/authstore.rb +34 -53
- data/lib/puppet/network/formats.rb +59 -9
- data/lib/puppet/network/http/mongrel/rest.rb +10 -9
- data/lib/puppet/network/http/webrick.rb +8 -1
- data/lib/puppet/network/http/webrick/rest.rb +2 -5
- data/lib/puppet/network/http_server/webrick.rb +1 -4
- data/lib/puppet/parser/ast/leaf.rb +1 -3
- data/lib/puppet/parser/collector.rb +14 -8
- data/lib/puppet/parser/compiler.rb +7 -0
- data/lib/puppet/parser/functions/fqdn_rand.rb +4 -10
- data/lib/puppet/parser/functions/regsubst.rb +44 -30
- data/lib/puppet/parser/functions/require.rb +18 -3
- data/lib/puppet/parser/functions/versioncmp.rb +1 -1
- data/lib/puppet/parser/interpreter.rb +1 -1
- data/lib/puppet/parser/lexer.rb +29 -31
- data/lib/puppet/parser/loaded_code.rb +4 -0
- data/lib/puppet/parser/parser_support.rb +5 -2
- data/lib/puppet/parser/resource.rb +31 -6
- data/lib/puppet/property.rb +3 -2
- data/lib/puppet/provider/macauthorization/macauthorization.rb +14 -14
- data/lib/puppet/provider/package/dpkg.rb +1 -1
- data/lib/puppet/provider/package/portage.rb +15 -5
- data/lib/puppet/provider/package/rug.rb +1 -1
- data/lib/puppet/provider/package/up2date.rb +1 -1
- data/lib/puppet/provider/package/urpmi.rb +1 -1
- data/lib/puppet/provider/service/daemontools.rb +7 -10
- data/lib/puppet/provider/service/runit.rb +7 -17
- data/lib/puppet/provider/ssh_authorized_key/parsed.rb +7 -47
- data/lib/puppet/provider/zone/solaris.rb +12 -3
- data/lib/puppet/relationship.rb +12 -12
- data/lib/puppet/reports/rrdgraph.rb +1 -1
- data/lib/puppet/reports/store.rb +2 -2
- data/lib/puppet/reports/tagmail.rb +5 -16
- data/lib/puppet/resource.rb +15 -20
- data/lib/puppet/resource/catalog.rb +40 -29
- data/lib/puppet/ssl/certificate_revocation_list.rb +0 -2
- data/lib/puppet/ssl/host.rb +2 -3
- data/lib/puppet/sslcertificates/ca.rb +0 -5
- data/lib/puppet/type/cron.rb +1 -1
- data/lib/puppet/type/file/owner.rb +7 -4
- data/lib/puppet/type/resources.rb +17 -17
- data/lib/puppet/type/yumrepo.rb +10 -3
- data/lib/puppet/util.rb +6 -11
- data/lib/puppet/util/inifile.rb +8 -0
- data/lib/puppet/util/log.rb +2 -2
- data/lib/puppet/util/monkey_patches.rb +0 -43
- data/lib/puppet/util/{json.rb → pson.rb} +6 -6
- data/lib/puppet/util/rdoc.rb +5 -3
- data/lib/puppet/util/selinux.rb +12 -6
- data/lib/puppet/util/settings.rb +25 -16
- data/lib/puppet/util/settings/file_setting.rb +4 -2
- data/spec/integration/application/puppet.rb +4 -4
- data/spec/integration/defaults.rb +2 -2
- data/spec/integration/indirector/catalog/queue.rb +5 -5
- data/spec/integration/indirector/certificate/rest.rb +3 -1
- data/spec/integration/network/formats.rb +36 -36
- data/spec/integration/parser/functions/require.rb +5 -3
- data/spec/integration/provider/mailalias/aliases.rb +4 -4
- data/spec/integration/resource/catalog.rb +4 -4
- data/spec/unit/application/puppet.rb +16 -15
- data/spec/unit/application/puppetd.rb +1 -1
- data/spec/unit/application/puppetdoc.rb +6 -0
- data/spec/unit/application/puppetmasterd.rb +6 -6
- data/spec/unit/configurer/fact_handler.rb +3 -3
- data/spec/unit/file_serving/configuration.rb +16 -2
- data/spec/unit/indirector/certificate/rest.rb +34 -0
- data/spec/unit/indirector/queue.rb +15 -15
- data/spec/unit/indirector/rest.rb +31 -9
- data/spec/unit/network/authstore.rb +105 -26
- data/spec/unit/network/formats.rb +124 -39
- data/spec/unit/parser/ast/leaf.rb +15 -0
- data/spec/unit/parser/collector.rb +20 -9
- data/spec/unit/parser/compiler.rb +19 -0
- data/spec/unit/parser/functions/fqdn_rand.rb +62 -0
- data/spec/unit/parser/functions/regsubst.rb +80 -0
- data/spec/unit/parser/functions/require.rb +19 -7
- data/spec/unit/parser/interpreter.rb +2 -2
- data/spec/unit/parser/lexer.rb +32 -7
- data/spec/unit/parser/loaded_code.rb +18 -1
- data/spec/unit/parser/parser.rb +10 -2
- data/spec/unit/parser/resource.rb +53 -2
- data/spec/unit/parser/scope.rb +1 -1
- data/spec/unit/property.rb +14 -4
- data/spec/unit/provider/package/dpkg.rb +7 -0
- data/spec/unit/provider/service/daemontools.rb +19 -2
- data/spec/unit/provider/service/redhat.rb +2 -0
- data/spec/unit/provider/service/runit.rb +15 -4
- data/spec/unit/provider/ssh_authorized_key/parsed.rb +32 -55
- data/spec/unit/relationship.rb +21 -46
- data/spec/unit/resource.rb +30 -39
- data/spec/unit/resource/catalog.rb +66 -51
- data/spec/unit/ssl/certificate_revocation_list.rb +0 -12
- data/spec/unit/type/cron.rb +33 -0
- data/spec/unit/type/file/owner.rb +10 -4
- data/spec/unit/util/json.rb +9 -9
- data/spec/unit/util/log.rb +36 -0
- data/spec/unit/util/settings.rb +6 -0
- data/test/data/providers/ssh_authorized_key/parsed/authorized_keys2 +1 -0
- data/test/lib/puppettest/support/utils.rb +8 -16
- metadata +36 -13
- data/lib/puppet/feature/json.rb +0 -2
data/lib/puppet/type/yumrepo.rb
CHANGED
@@ -178,9 +178,16 @@ module Puppet
|
|
178
178
|
|
179
179
|
# Store all modifications back to disk
|
180
180
|
def self.store
|
181
|
-
|
182
|
-
unless
|
183
|
-
|
181
|
+
inifile.store
|
182
|
+
unless Puppet[:noop]
|
183
|
+
target_mode = 0644 # FIXME: should be configurable
|
184
|
+
inifile.each_file do |file|
|
185
|
+
current_mode = File.stat(file).mode & 0777
|
186
|
+
unless current_mode == target_mode
|
187
|
+
Puppet::info "changing mode of #{file} from %03o to %03o" % [current_mode, target_mode]
|
188
|
+
File.chmod(target_mode, file)
|
189
|
+
end
|
190
|
+
end
|
184
191
|
end
|
185
192
|
end
|
186
193
|
|
data/lib/puppet/util.rb
CHANGED
@@ -185,19 +185,14 @@ module Util
|
|
185
185
|
|
186
186
|
def binary(bin)
|
187
187
|
if bin =~ /^\//
|
188
|
-
if FileTest.file? bin and FileTest.executable? bin
|
189
|
-
return bin
|
190
|
-
else
|
191
|
-
return nil
|
192
|
-
end
|
188
|
+
return bin if FileTest.file? bin and FileTest.executable? bin
|
193
189
|
else
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
return x
|
199
|
-
end
|
190
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |dir|
|
191
|
+
dest=File.join(dir, bin)
|
192
|
+
return dest if FileTest.file? dest and FileTest.executable? dest
|
193
|
+
end
|
200
194
|
end
|
195
|
+
return nil
|
201
196
|
end
|
202
197
|
module_function :binary
|
203
198
|
|
data/lib/puppet/util/inifile.rb
CHANGED
@@ -180,6 +180,14 @@ module Puppet::Util::IniConfig
|
|
180
180
|
end
|
181
181
|
end
|
182
182
|
|
183
|
+
# Execute BLOCK, passing each file constituting this inifile
|
184
|
+
# as an argument
|
185
|
+
def each_file(&block)
|
186
|
+
@files.keys.each do |file|
|
187
|
+
yield(file)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
183
191
|
# Return the Section with the given name or nil
|
184
192
|
def [](name)
|
185
193
|
name = name.to_s
|
data/lib/puppet/util/log.rb
CHANGED
@@ -282,9 +282,9 @@ class Puppet::Util::Log
|
|
282
282
|
|
283
283
|
def colorize(level, str)
|
284
284
|
case Puppet[:color]
|
285
|
-
when
|
286
|
-
when true, :ansi, "ansi"; console_color(level, str)
|
285
|
+
when true, :ansi, "ansi", :yes, "yes"; console_color(level, str)
|
287
286
|
when :html, "html"; html_color(level, str)
|
287
|
+
else str
|
288
288
|
end
|
289
289
|
end
|
290
290
|
|
@@ -1,43 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Monkey patches to ruby classes for compatibility
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# In earlier versions of ruby (e.g. 1.8.1) yaml serialized symbols with an explicit
|
6
|
-
# type designation. Later versions understand the explicit form in addition to the
|
7
|
-
# implicit "literal" form (e.g. :symbol) which they produce.
|
8
|
-
#
|
9
|
-
# This causes problems when the puppet master and the client are running on different
|
10
|
-
# versions of ruby; the newer version can produce yaml that it's older partner can't
|
11
|
-
# decypher.
|
12
|
-
#
|
13
|
-
# This patch causes newer versions to produce the older encoding for Symbols. It is
|
14
|
-
# only applied if the existing library does not already produce them. Thus it will
|
15
|
-
# not be applied on older rubys and it will not be applied more than once. It also
|
16
|
-
# checks that it has been applied to a version which support it and, if not reverts
|
17
|
-
# to the original.
|
18
|
-
#
|
19
|
-
require "yaml"
|
20
|
-
|
21
|
-
if :test.to_yaml !~ %r{!ruby/sym}
|
22
|
-
class Symbol
|
23
|
-
if !respond_to? :original_to_yaml
|
24
|
-
alias :original_to_yaml :to_yaml
|
25
|
-
def to_yaml(opts={})
|
26
|
-
YAML::quick_emit(nil,opts) { |out|
|
27
|
-
if out.respond_to? :scalar
|
28
|
-
# 1.8.5 through 1.8.8, possibly others
|
29
|
-
out.scalar("tag:ruby:sym", to_s,:to_yaml_style)
|
30
|
-
elsif out.respond_to? :<<
|
31
|
-
# 1.8.2, possibly others
|
32
|
-
out << "!ruby/sym "
|
33
|
-
self.id2name.to_yaml( :Emitter => out )
|
34
|
-
else
|
35
|
-
# go back to the base version if neither of the above work
|
36
|
-
alias :to_yaml :original_to_yaml
|
37
|
-
to_yaml(opts)
|
38
|
-
end
|
39
|
-
}
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
# A simple module to provide consistency between how we use
|
1
|
+
# A simple module to provide consistency between how we use PSON and how
|
2
2
|
# ruby expects it to be used. Basically, we don't want to require
|
3
3
|
# that the sender specify a class.
|
4
|
-
# Ruby wants everyone to provide a '
|
4
|
+
# Ruby wants everyone to provide a 'type' field, and the PSON support
|
5
5
|
# requires such a field to track the class down. Because we use our URL to
|
6
6
|
# figure out what class we're working on, we don't need that, and we don't want
|
7
7
|
# our consumers and producers to need to know anything about our internals.
|
8
|
-
module Puppet::Util::
|
9
|
-
def
|
10
|
-
raise ArgumentError, "No data provided in
|
11
|
-
|
8
|
+
module Puppet::Util::Pson
|
9
|
+
def pson_create(pson)
|
10
|
+
raise ArgumentError, "No data provided in pson data" unless pson['data']
|
11
|
+
from_pson(pson['data'])
|
12
12
|
end
|
13
13
|
end
|
data/lib/puppet/util/rdoc.rb
CHANGED
@@ -49,13 +49,15 @@ module Puppet::Util::RDoc
|
|
49
49
|
# of a manifest
|
50
50
|
def output(file, ast)
|
51
51
|
astobj = []
|
52
|
-
ast
|
52
|
+
ast.nodes.each do |name, k|
|
53
53
|
astobj << k if k.file == file
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
|
+
ast.hostclasses.each do |name,k|
|
56
57
|
astobj << k if k.file == file
|
57
58
|
end
|
58
|
-
|
59
|
+
|
60
|
+
ast.definitions.each do |name, k|
|
59
61
|
astobj << k if k.file == file
|
60
62
|
end
|
61
63
|
astobj.sort! {|a,b| a.line <=> b.line }.each do |k|
|
data/lib/puppet/util/selinux.rb
CHANGED
@@ -154,16 +154,22 @@ module Puppet::Util::SELinux
|
|
154
154
|
def read_mounts
|
155
155
|
mounts = ""
|
156
156
|
begin
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
mounts += mountfh.read_nonblock(1024)
|
157
|
+
if File.instance_methods.include? "read_nonblock"
|
158
|
+
# If possible we use read_nonblock() in a loop rather than read() to work-
|
159
|
+
# a linux kernel bug. See ticket #1963 for details.
|
160
|
+
mountfh = File.open("/proc/mounts")
|
161
|
+
mounts += mountfh.read_nonblock(1024) while true
|
162
|
+
else
|
163
|
+
# Otherwise we shell out and let cat do it for us
|
164
|
+
mountfh = IO.popen("/bin/cat /proc/mounts")
|
165
|
+
mounts = mountfh.read
|
162
166
|
end
|
163
167
|
rescue EOFError
|
164
|
-
|
168
|
+
# that's expected
|
165
169
|
rescue
|
166
170
|
return nil
|
171
|
+
ensure
|
172
|
+
mountfh.close
|
167
173
|
end
|
168
174
|
|
169
175
|
mntpoint = {}
|
data/lib/puppet/util/settings.rb
CHANGED
@@ -653,6 +653,30 @@ Generated on #{Time.now}.
|
|
653
653
|
@config.has_key?(param)
|
654
654
|
end
|
655
655
|
|
656
|
+
def uninterpolated_value(param, environment = nil)
|
657
|
+
param = param.to_sym
|
658
|
+
environment = environment.to_sym if environment
|
659
|
+
|
660
|
+
# See if we can find it within our searchable list of values
|
661
|
+
val = catch :foundval do
|
662
|
+
each_source(environment) do |source|
|
663
|
+
# Look for the value. We have to test the hash for whether
|
664
|
+
# it exists, because the value might be false.
|
665
|
+
@sync.synchronize do
|
666
|
+
if @values[source].include?(param)
|
667
|
+
throw :foundval, @values[source][param]
|
668
|
+
end
|
669
|
+
end
|
670
|
+
end
|
671
|
+
throw :foundval, nil
|
672
|
+
end
|
673
|
+
|
674
|
+
# If we didn't get a value, use the default
|
675
|
+
val = @config[param].default if val.nil?
|
676
|
+
|
677
|
+
return val
|
678
|
+
end
|
679
|
+
|
656
680
|
# Find the correct value using our search path. Optionally accept an environment
|
657
681
|
# in which to search before the other configuration sections.
|
658
682
|
def value(param, environment = nil)
|
@@ -672,22 +696,7 @@ Generated on #{Time.now}.
|
|
672
696
|
return cached
|
673
697
|
end
|
674
698
|
|
675
|
-
|
676
|
-
val = catch :foundval do
|
677
|
-
each_source(environment) do |source|
|
678
|
-
# Look for the value. We have to test the hash for whether
|
679
|
-
# it exists, because the value might be false.
|
680
|
-
@sync.synchronize do
|
681
|
-
if @values[source].include?(param)
|
682
|
-
throw :foundval, @values[source][param]
|
683
|
-
end
|
684
|
-
end
|
685
|
-
end
|
686
|
-
throw :foundval, nil
|
687
|
-
end
|
688
|
-
|
689
|
-
# If we didn't get a value, use the default
|
690
|
-
val = @config[param].default if val.nil?
|
699
|
+
val = uninterpolated_value(param, environment)
|
691
700
|
|
692
701
|
# Convert it if necessary
|
693
702
|
val = convert(val, environment)
|
@@ -16,7 +16,8 @@ class Puppet::Util::Settings::FileSetting < Puppet::Util::Settings::Setting
|
|
16
16
|
|
17
17
|
def group=(value)
|
18
18
|
unless AllowedGroups.include?(value)
|
19
|
-
|
19
|
+
identifying_fields = [desc,name,default].compact.join(': ')
|
20
|
+
raise SettingError, "Internal error: The :group setting for %s must be 'service', not '%s'" % [identifying_fields,value]
|
20
21
|
end
|
21
22
|
@group = value
|
22
23
|
end
|
@@ -28,7 +29,8 @@ class Puppet::Util::Settings::FileSetting < Puppet::Util::Settings::Setting
|
|
28
29
|
|
29
30
|
def owner=(value)
|
30
31
|
unless AllowedOwners.include?(value)
|
31
|
-
|
32
|
+
identifying_fields = [desc,name,default].compact.join(': ')
|
33
|
+
raise SettingError, "Internal error: The :owner setting for %s must be either 'root' or 'service', not '%s'" % [identifying_fields,value]
|
32
34
|
end
|
33
35
|
@owner = value
|
34
36
|
end
|
@@ -10,16 +10,16 @@ describe "Puppet" do
|
|
10
10
|
include PuppetSpec::Files
|
11
11
|
|
12
12
|
describe "when applying provided catalogs" do
|
13
|
-
confine "
|
14
|
-
it "should be able to apply catalogs provided in a file in
|
15
|
-
file_to_create = tmpfile("
|
13
|
+
confine "PSON library is missing; cannot test applying catalogs" => Puppet.features.pson?
|
14
|
+
it "should be able to apply catalogs provided in a file in pson" do
|
15
|
+
file_to_create = tmpfile("pson_catalog")
|
16
16
|
catalog = Puppet::Resource::Catalog.new
|
17
17
|
resource = Puppet::Resource.new(:file, file_to_create, :content => "my stuff")
|
18
18
|
catalog.add_resource resource
|
19
19
|
|
20
20
|
manifest = tmpfile("manifest")
|
21
21
|
|
22
|
-
File.open(manifest, "w") { |f| f.print catalog.
|
22
|
+
File.open(manifest, "w") { |f| f.print catalog.to_pson }
|
23
23
|
|
24
24
|
puppet = Puppet::Application[:puppet]
|
25
25
|
puppet.options[:catalog] = manifest
|
@@ -89,8 +89,8 @@ describe "Puppet defaults" do
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
it "should default to
|
93
|
-
Puppet.settings.value(:preferred_serialization_format).should == "
|
92
|
+
it "should default to pson for the preferred serialization format" do
|
93
|
+
Puppet.settings.value(:preferred_serialization_format).should == "pson"
|
94
94
|
end
|
95
95
|
|
96
96
|
describe "when enabling storeconfigs" do
|
@@ -6,7 +6,7 @@ require 'puppet/resource/catalog'
|
|
6
6
|
|
7
7
|
|
8
8
|
describe "Puppet::Resource::Catalog::Queue" do
|
9
|
-
confine "Missing
|
9
|
+
confine "Missing pson support; cannot test queue" => Puppet.features.pson?
|
10
10
|
|
11
11
|
before do
|
12
12
|
Puppet::Resource::Catalog.indirection.terminus(:queue)
|
@@ -23,13 +23,13 @@ describe "Puppet::Resource::Catalog::Queue" do
|
|
23
23
|
|
24
24
|
after { Puppet.settings.clear }
|
25
25
|
|
26
|
-
it "should render catalogs to
|
26
|
+
it "should render catalogs to pson and send them via the queue client when catalogs are saved" do
|
27
27
|
terminus = Puppet::Resource::Catalog.indirection.terminus(:queue)
|
28
28
|
|
29
29
|
client = mock 'client'
|
30
30
|
terminus.stubs(:client).returns client
|
31
31
|
|
32
|
-
client.expects(:send_message).with(:catalog, @catalog.
|
32
|
+
client.expects(:send_message).with(:catalog, @catalog.to_pson)
|
33
33
|
|
34
34
|
request = Puppet::Indirector::Request.new(:catalog, :save, "foo", :instance => @catalog)
|
35
35
|
|
@@ -40,9 +40,9 @@ describe "Puppet::Resource::Catalog::Queue" do
|
|
40
40
|
client = mock 'client'
|
41
41
|
Puppet::Resource::Catalog::Queue.stubs(:client).returns client
|
42
42
|
|
43
|
-
|
43
|
+
pson = @catalog.to_pson
|
44
44
|
|
45
|
-
client.expects(:subscribe).with(:catalog).yields(
|
45
|
+
client.expects(:subscribe).with(:catalog).yields(pson)
|
46
46
|
|
47
47
|
Puppet.expects(:err).never
|
48
48
|
|
@@ -64,6 +64,8 @@ describe "Certificate REST Terminus" do
|
|
64
64
|
|
65
65
|
# There's no good '==' method on certs.
|
66
66
|
result.content.to_s.should == @host.certificate.content.to_s
|
67
|
-
|
67
|
+
|
68
|
+
# also make sure it uses the provided name, rather than the internal one.
|
69
|
+
result.name.should == "bar"
|
68
70
|
end
|
69
71
|
end
|
@@ -4,13 +4,13 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|
4
4
|
|
5
5
|
require 'puppet/network/formats'
|
6
6
|
|
7
|
-
class
|
7
|
+
class PsonIntTest
|
8
8
|
attr_accessor :string
|
9
9
|
def ==(other)
|
10
10
|
other.class == self.class and string == other.string
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.
|
13
|
+
def self.from_pson(data)
|
14
14
|
new(data[0])
|
15
15
|
end
|
16
16
|
|
@@ -18,15 +18,15 @@ class JsonIntTest
|
|
18
18
|
@string = string
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
21
|
+
def to_pson(*args)
|
22
22
|
{
|
23
|
-
'
|
23
|
+
'type' => self.class.name,
|
24
24
|
'data' => [@string]
|
25
|
-
}.
|
25
|
+
}.to_pson(*args)
|
26
26
|
end
|
27
27
|
|
28
28
|
def self.canonical_order(s)
|
29
|
-
s.gsub(/\{"data":\[(.*?)\],"
|
29
|
+
s.gsub(/\{"data":\[(.*?)\],"type":"PsonIntTest"\}/,'{"type":"PsonIntTest","data":[\1]}')
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
@@ -45,65 +45,65 @@ describe Puppet::Network::FormatHandler.format(:s) do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
describe Puppet::Network::FormatHandler.format(:
|
49
|
-
describe "when
|
50
|
-
confine "'
|
48
|
+
describe Puppet::Network::FormatHandler.format(:pson) do
|
49
|
+
describe "when pson is absent" do
|
50
|
+
confine "'pson' library is present" => (! Puppet.features.pson?)
|
51
51
|
|
52
52
|
before do
|
53
|
-
@
|
53
|
+
@pson = Puppet::Network::FormatHandler.format(:pson)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should not be suitable" do
|
57
|
-
@
|
57
|
+
@pson.should_not be_suitable
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
describe "when
|
62
|
-
confine "Missing '
|
61
|
+
describe "when pson is available" do
|
62
|
+
confine "Missing 'pson' library" => Puppet.features.pson?
|
63
63
|
|
64
64
|
before do
|
65
|
-
@
|
65
|
+
@pson = Puppet::Network::FormatHandler.format(:pson)
|
66
66
|
end
|
67
67
|
|
68
|
-
it "should be able to render an instance to
|
69
|
-
instance =
|
70
|
-
|
68
|
+
it "should be able to render an instance to pson" do
|
69
|
+
instance = PsonIntTest.new("foo")
|
70
|
+
PsonIntTest.canonical_order(@pson.render(instance)).should == PsonIntTest.canonical_order('{"type":"PsonIntTest","data":["foo"]}' )
|
71
71
|
end
|
72
72
|
|
73
|
-
it "should be able to render arrays to
|
74
|
-
@
|
73
|
+
it "should be able to render arrays to pson" do
|
74
|
+
@pson.render([1,2]).should == '[1,2]'
|
75
75
|
end
|
76
76
|
|
77
|
-
it "should be able to render arrays containing hashes to
|
78
|
-
@
|
77
|
+
it "should be able to render arrays containing hashes to pson" do
|
78
|
+
@pson.render([{"one"=>1},{"two"=>2}]).should == '[{"one":1},{"two":2}]'
|
79
79
|
end
|
80
80
|
|
81
|
-
it "should be able to render multiple instances to
|
82
|
-
Puppet.features.add(:
|
81
|
+
it "should be able to render multiple instances to pson" do
|
82
|
+
Puppet.features.add(:pson, :libs => ["pson"])
|
83
83
|
|
84
|
-
one =
|
85
|
-
two =
|
84
|
+
one = PsonIntTest.new("one")
|
85
|
+
two = PsonIntTest.new("two")
|
86
86
|
|
87
|
-
|
87
|
+
PsonIntTest.canonical_order(@pson.render([one,two])).should == PsonIntTest.canonical_order('[{"type":"PsonIntTest","data":["one"]},{"type":"PsonIntTest","data":["two"]}]')
|
88
88
|
end
|
89
89
|
|
90
|
-
it "should be able to intern
|
91
|
-
@
|
90
|
+
it "should be able to intern pson into an instance" do
|
91
|
+
@pson.intern(PsonIntTest, '{"type":"PsonIntTest","data":["foo"]}').should == PsonIntTest.new("foo")
|
92
92
|
end
|
93
93
|
|
94
|
-
it "should be able to intern
|
95
|
-
@
|
94
|
+
it "should be able to intern pson with no class information into an instance" do
|
95
|
+
@pson.intern(PsonIntTest, '["foo"]').should == PsonIntTest.new("foo")
|
96
96
|
end
|
97
97
|
|
98
|
-
it "should be able to intern multiple instances from
|
99
|
-
@
|
100
|
-
|
98
|
+
it "should be able to intern multiple instances from pson" do
|
99
|
+
@pson.intern_multiple(PsonIntTest, '[{"type": "PsonIntTest", "data": ["one"]},{"type": "PsonIntTest", "data": ["two"]}]').should == [
|
100
|
+
PsonIntTest.new("one"), PsonIntTest.new("two")
|
101
101
|
]
|
102
102
|
end
|
103
103
|
|
104
|
-
it "should be able to intern multiple instances from
|
105
|
-
@
|
106
|
-
|
104
|
+
it "should be able to intern multiple instances from pson with no class information" do
|
105
|
+
@pson.intern_multiple(PsonIntTest, '[["one"],["two"]]').should == [
|
106
|
+
PsonIntTest.new("one"), PsonIntTest.new("two")
|
107
107
|
]
|
108
108
|
end
|
109
109
|
end
|