public
Rubygem
Description: James Turnbull's Puppet remote
Homepage: http://reductivelabs.com/trac/puppet
Clone URL: git://github.com/jamtur01/puppet.git
You can now select the encoding format when transferring the catalog,
with 'yaml' still being the default but 'marshal' being an option.
This is because testing has shown drastic performance differences
between the two, with up to 70% of compile time being spent
in YAML code.  Use the 'catalog_format' setting to choose your format,
and the setting must be set on the client.

Signed-off-by: Luke Kanies <luke@madstop.com>
lak (author)
Thu Jul 17 22:54:59 -0700 2008
jamtur01 (committer)
Thu Jul 17 23:41:54 -0700 2008
commit  d8937acb8c9b108e61330cbac703a17b2eaba9b3
tree    2e962357a87a10cd7eb76dadf752dd2b57e0c340
parent  a0fa09f6ee562dd1b61fe56dd4b914419d641986
...
1
 
 
 
 
 
 
 
2
3
4
...
1
2
3
4
5
6
7
8
9
10
11
0
@@ -1,4 +1,11 @@
0
 0.24.5
0
+ You can now select the encoding format when transferring the catalog,
0
+ with 'yaml' still being the default but 'marshal' being an option.
0
+ This is because testing has shown drastic performance differences
0
+ between the two, with up to 70% of compile time being spent
0
+ in YAML code. Use the 'catalog_format' setting to choose your format,
0
+ and the setting must be set on the client.
0
+
0
     Fixed #1431 - Provider confines must now specify similar tests in one call.
0
     I.e., you can't do confine :operatingsystem => %w{a b} and then
0
     confine :operatingsystem => %w{b c}; you'd need to do them in one command.
...
416
417
418
419
 
 
 
 
420
421
422
...
416
417
418
 
419
420
421
422
423
424
425
0
@@ -416,7 +416,10 @@ module Puppet
0
         :ca_server => ["$server", "The server to use for certificate
0
             authority requests. It's a separate server because it cannot
0
             and does not need to horizontally scale."],
0
- :ca_port => ["$masterport", "The port to use for the certificate authority."]
0
+ :ca_port => ["$masterport", "The port to use for the certificate authority."],
0
+ :catalog_format => ["yaml", "What format to use to dump the catalog. Only supports
0
+ 'marshal' and 'yaml'. Only matters on the client, since it asks the server
0
+ for a specific format."]
0
     )
0
         
0
     self.setdefaults(:filebucket,
...
143
144
145
146
 
147
148
149
150
151
152
 
 
 
 
 
 
153
154
 
155
156
157
...
175
176
177
178
 
179
180
181
...
442
443
444
445
 
446
447
448
...
143
144
145
 
146
147
148
149
150
151
 
152
153
154
155
156
157
158
 
159
160
161
162
...
180
181
182
 
183
184
185
186
...
447
448
449
 
450
451
452
453
0
@@ -143,15 +143,20 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
0
 
0
         # If we can't retrieve the catalog, just return, which will either
0
         # fail, or use the in-memory catalog.
0
- unless yaml_objects = get_actual_config(facts)
0
+ unless marshalled_objects = get_actual_config(facts)
0
             use_cached_config(true)
0
             return
0
         end
0
 
0
         begin
0
- objects = YAML.load(yaml_objects)
0
+ case Puppet[:catalog_format]
0
+ when "marshal": objects = Marshal.load(marshalled_objects)
0
+ when "yaml": objects = YAML.load(marshalled_objects)
0
+ else
0
+ raise "Invalid catalog format '%s'" % Puppet[:catalog_format]
0
+ end
0
         rescue => detail
0
- msg = "Configuration could not be translated from yaml"
0
+ msg = "Configuration could not be translated from %s" % Puppet[:catalog_format]
0
             msg += "; using cached catalog" if use_cached_config(true)
0
             Puppet.warning msg
0
             return
0
@@ -175,7 +180,7 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
0
         end
0
 
0
         if ! @catalog.from_cache
0
- self.cache(yaml_objects)
0
+ self.cache(marshalled_objects)
0
         end
0
 
0
         # Keep the state database up to date.
0
@@ -442,7 +447,7 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
0
         benchmark(:debug, "Retrieved catalog") do
0
             # error handling for this is done in the network client
0
             begin
0
- textobjects = @driver.getconfig(textfacts, "yaml")
0
+ textobjects = @driver.getconfig(textfacts, Puppet[:catalog_format])
0
                 begin
0
                     textobjects = CGI.unescape(textobjects)
0
                 rescue => detail
...
64
65
66
67
 
 
 
 
 
 
 
 
68
69
70
...
90
91
92
93
94
95
96
97
98
99
100
...
64
65
66
 
67
68
69
70
71
72
73
74
75
76
77
...
97
98
99
 
 
 
 
 
100
101
102
0
@@ -64,7 +64,14 @@ class Puppet::Network::Handler
0
 
0
             catalog = Puppet::Node::Catalog.find(client)
0
 
0
- return translate(catalog.extract)
0
+ case format
0
+ when "yaml":
0
+ return CGI.escape(catalog.extract.to_yaml(:UseBlock => true))
0
+ when "marshal":
0
+ return CGI.escape(Marshal.dump(catalog.extract))
0
+ else
0
+ raise "Invalid markup format '%s'" % format
0
+ end
0
         end
0
 
0
         #
0
@@ -90,11 +97,6 @@ class Puppet::Network::Handler
0
 
0
         # Translate our configuration appropriately for sending back to a client.
0
         def translate(config)
0
- if local?
0
- config
0
- else
0
- CGI.escape(config.to_yaml(:UseBlock => true))
0
- end
0
         end
0
     end
0
 end
...
40
41
42
 
 
 
 
43
...
40
41
42
43
44
45
46
47
0
@@ -40,4 +40,8 @@ describe "Puppet defaults" do
0
         Puppet.settings.element(:rundir).owner.should be_nil
0
         Puppet.settings.element(:rundir).group.should be_nil
0
     end
0
+
0
+ it "should default to yaml as the catalog format" do
0
+ Puppet.settings[:catalog_format].should == "yaml"
0
+ end
0
 end
...
59
60
61
62
63
64
65
 
 
 
 
 
 
 
 
66
67
68
 
 
 
 
69
70
 
 
71
72
73
74
75
 
 
 
 
76
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
79
80
81
82
83
 
 
 
 
 
 
 
 
84
85
 
 
 
 
86
87
 
 
88
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
91
92
...
59
60
61
 
 
 
 
62
63
64
65
66
67
68
69
70
 
 
71
72
73
74
75
 
76
77
78
 
 
 
 
79
80
81
82
83
 
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
 
 
 
 
110
111
112
113
114
115
116
117
118
 
119
120
121
122
123
 
124
125
126
 
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
0
@@ -59,34 +59,92 @@ describe Puppet::Network::Client::Master, " when retrieving the catalog" do
0
         @client.getconfig
0
     end
0
 
0
- it "should load the retrieved catalog using YAML" do
0
- @client.stubs(:dostorage)
0
- @client.class.stubs(:facts).returns(@facts)
0
- @master.stubs(:getconfig).returns("myconfig")
0
+ describe "when the catalog format is set to yaml" do
0
+ before do
0
+ Puppet.settings.stubs(:value).returns "foo"
0
+ Puppet.settings.stubs(:value).with(:pluginsync).returns false
0
+ Puppet.settings.stubs(:value).with(:configtimeout).returns 10
0
+ Puppet.settings.stubs(:value).with(:factsync).returns false
0
+ Puppet.settings.stubs(:value).with(:catalog_format).returns "yaml"
0
+ end
0
 
0
- config = mock 'config'
0
- YAML.expects(:load).with("myconfig").returns(config)
0
+ it "should request a yaml-encoded catalog" do
0
+ @client.stubs(:dostorage)
0
+ @client.class.stubs(:facts).returns(@facts)
0
+ @master.expects(:getconfig).with { |*args| args[1] == "yaml" }
0
 
0
- @client.stubs(:setclasses)
0
+ @client.getconfig
0
+ end
0
 
0
- config.stubs(:classes)
0
- config.stubs(:to_catalog).returns(config)
0
- config.stubs(:host_config=)
0
- config.stubs(:from_cache).returns(true)
0
+ it "should load the retrieved catalog using YAML" do
0
+ @client.stubs(:dostorage)
0
+ @client.class.stubs(:facts).returns(@facts)
0
+ @master.stubs(:getconfig).returns("myconfig")
0
 
0
- @client.getconfig
0
+ config = mock 'config'
0
+ YAML.expects(:load).with("myconfig").returns(config)
0
+
0
+ @client.stubs(:setclasses)
0
+
0
+ config.stubs(:classes)
0
+ config.stubs(:to_catalog).returns(config)
0
+ config.stubs(:host_config=)
0
+ config.stubs(:from_cache).returns(true)
0
+
0
+ @client.getconfig
0
+ end
0
+
0
+ it "should use the cached catalog if the retrieved catalog cannot be converted from YAML" do
0
+ @client.stubs(:dostorage)
0
+ @client.class.stubs(:facts).returns(@facts)
0
+ @master.stubs(:getconfig).returns("myconfig")
0
+
0
+ YAML.expects(:load).with("myconfig").raises(ArgumentError)
0
+
0
+ @client.expects(:use_cached_config).with(true)
0
+
0
+ @client.getconfig
0
+ end
0
     end
0
 
0
- it "should use the cached catalog if the retrieved catalog cannot be converted from YAML" do
0
- @client.stubs(:dostorage)
0
- @client.class.stubs(:facts).returns(@facts)
0
- @master.stubs(:getconfig).returns("myconfig")
0
+ describe "from Marshal" do
0
+ before do
0
+ Puppet.settings.stubs(:value).returns "foo"
0
+ Puppet.settings.stubs(:value).with(:pluginsync).returns false
0
+ Puppet.settings.stubs(:value).with(:configtimeout).returns 10
0
+ Puppet.settings.stubs(:value).with(:factsync).returns false
0
+ Puppet.settings.stubs(:value).with(:catalog_format).returns "marshal"
0
+ end
0
 
0
- YAML.expects(:load).with("myconfig").raises(ArgumentError)
0
+ it "should load the retrieved catalog using Marshal" do
0
+ @client.stubs(:dostorage)
0
+ @client.class.stubs(:facts).returns(@facts)
0
+ @master.stubs(:getconfig).returns("myconfig")
0
 
0
- @client.expects(:use_cached_config).with(true)
0
+ config = mock 'config'
0
+ Marshal.expects(:load).with("myconfig").returns(config)
0
 
0
- @client.getconfig
0
+ @client.stubs(:setclasses)
0
+
0
+ config.stubs(:classes)
0
+ config.stubs(:to_catalog).returns(config)
0
+ config.stubs(:host_config=)
0
+ config.stubs(:from_cache).returns(true)
0
+
0
+ @client.getconfig
0
+ end
0
+
0
+ it "should use the cached catalog if the retrieved catalog cannot be converted from Marshal" do
0
+ @client.stubs(:dostorage)
0
+ @client.class.stubs(:facts).returns(@facts)
0
+ @master.stubs(:getconfig).returns("myconfig")
0
+
0
+ Marshal.expects(:load).with("myconfig").raises(ArgumentError)
0
+
0
+ @client.expects(:use_cached_config).with(true)
0
+
0
+ @client.getconfig
0
+ end
0
     end
0
 
0
     it "should set the classes.txt file with the classes listed in the retrieved catalog" do
...
56
57
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
0
@@ -56,3 +56,37 @@ class TestMaster < Test::Unit::TestCase
0
         @master.getconfig("facts", "yaml", "foo.com")
0
     end
0
 end
0
+
0
+class TestMasterFormats < Test::Unit::TestCase
0
+ def setup
0
+ @facts = stub('facts', :save => nil)
0
+ Puppet::Node::Facts.stubs(:new).returns(@facts)
0
+
0
+ @master = Puppet::Network::Handler.master.new(:Code => "")
0
+ @master.stubs(:decode_facts)
0
+
0
+ @catalog = stub 'catalog', :extract => ""
0
+ Puppet::Node::Catalog.stubs(:find).returns(@catalog)
0
+ end
0
+
0
+ def test_marshal_can_be_used
0
+ @catalog.expects(:extract).returns "myextract"
0
+
0
+ Marshal.expects(:dump).with("myextract").returns "eh"
0
+
0
+ @master.getconfig("facts", "marshal", "foo.com")
0
+ end
0
+
0
+ def test_yaml_can_be_used
0
+ extract = mock 'extract'
0
+ @catalog.expects(:extract).returns extract
0
+
0
+ extract.expects(:to_yaml).returns "myaml"
0
+
0
+ @master.getconfig("facts", "yaml", "foo.com")
0
+ end
0
+
0
+ def test_failure_when_non_yaml_or_marshal_is_used
0
+ assert_raise(RuntimeError) { @master.getconfig("facts", "blah", "foo.com") }
0
+ end
0
+end

Comments

    No one has commented yet.