diff options
-rwxr-xr-x | bin/filebucket | 5 | ||||
-rwxr-xr-x | bin/puppet | 5 | ||||
-rw-r--r-- | lib/puppet/resource.rb | 10 | ||||
-rw-r--r-- | lib/puppet/resource/catalog.rb | 2 | ||||
-rwxr-xr-x | spec/unit/resource.rb | 14 | ||||
-rwxr-xr-x | spec/unit/resource/catalog.rb | 5 | ||||
-rwxr-xr-x | test/network/client/client.rb | 127 | ||||
-rwxr-xr-x | test/network/server/webrick.rb | 33 | ||||
-rwxr-xr-x | test/other/puppet.rb | 30 | ||||
-rwxr-xr-x | test/other/report.rb | 7 | ||||
-rwxr-xr-x | test/util/settings.rb | 10 |
11 files changed, 46 insertions, 202 deletions
diff --git a/bin/filebucket b/bin/filebucket index 17e01ed64..ea75cb6de 100755 --- a/bin/filebucket +++ b/bin/filebucket @@ -152,7 +152,10 @@ Puppet::Log.newdestination(:console) client = nil server = nil -Puppet.settraps +trap(:INT) do + $stderr.puts "Cancelling" + exit(1) +end if options[:debug] Puppet::Log.level = :debug diff --git a/bin/puppet b/bin/puppet index c01d7392c..e3a9c4f37 100755 --- a/bin/puppet +++ b/bin/puppet @@ -166,7 +166,10 @@ end client = nil server = nil -Puppet.settraps +trap(:INT) do + $stderr.puts "Exiting" + exit(1) +end if options[:debug] Puppet::Util::Log.level = :debug diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb index b8347f8d7..add32b7cf 100644 --- a/lib/puppet/resource.rb +++ b/lib/puppet/resource.rb @@ -29,6 +29,16 @@ class Puppet::Resource @parameters[parameter_name(param)] end + # Compatibility method. + def builtin? + builtin_type? + end + + # Is this a builtin resource type? + def builtin_type? + @reference.builtin_type? + end + # Iterate over each param/value pair, as required for Enumerable. def each @parameters.each { |p,v| yield p, v } diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb index d50241d6c..78f6a6f79 100644 --- a/lib/puppet/resource/catalog.rb +++ b/lib/puppet/resource/catalog.rb @@ -469,6 +469,8 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph def to_catalog(convert) result = self.class.new(self.name) + result.version = self.version + map = {} vertices.each do |resource| next if resource.respond_to?(:virtual?) and resource.virtual? diff --git a/spec/unit/resource.rb b/spec/unit/resource.rb index f24ec0123..0fcf51b8b 100755 --- a/spec/unit/resource.rb +++ b/spec/unit/resource.rb @@ -56,6 +56,20 @@ describe Puppet::Resource do resource.title.should == "mytitle" end + it "should use its resource reference to determine whether it is builtin" do + ref = Puppet::Resource::Reference.new("file", "/f") + Puppet::Resource::Reference.expects(:new).returns ref + resource = Puppet::Resource.new("file", "/f") + ref.expects(:builtin_type?).returns "yep" + resource.builtin_type?.should == "yep" + end + + it "should call its builtin_type? method when 'builtin?' is called" do + resource = Puppet::Resource.new("file", "/f") + resource.expects(:builtin_type?).returns "foo" + resource.builtin?.should == "foo" + end + it "should use its resource reference to produce its canonical reference string" do ref = Puppet::Resource::Reference.new("file", "/f") Puppet::Resource::Reference.expects(:new).returns ref diff --git a/spec/unit/resource/catalog.rb b/spec/unit/resource/catalog.rb index bc526a70d..f72162b39 100755 --- a/spec/unit/resource/catalog.rb +++ b/spec/unit/resource/catalog.rb @@ -191,6 +191,11 @@ describe Puppet::Resource::Catalog, "when compiling" do @catalog = @original.to_resource end + it "should copy over the version" do + @original.version = "foo" + @original.to_resource.version.should == "foo" + end + it "should add all resources as Puppet::Resource instances" do @resources.each { |resource| @catalog.resource(resource.ref).should be_instance_of(Puppet::Resource) } end diff --git a/test/network/client/client.rb b/test/network/client/client.rb index 5f96cac11..0befef55a 100755 --- a/test/network/client/client.rb +++ b/test/network/client/client.rb @@ -15,131 +15,6 @@ class TestClient < Test::Unit::TestCase class FakeDriver end - # a single run through of connect, auth, etc. - def disabled_test_sslInitWithAutosigningLocalServer - # autosign everything, for simplicity - Puppet[:autosign] = true - - # create a server to which to connect - mkserver() - - # create our client - client = nil - assert_nothing_raised { - client = Puppet::Network::Client.master.new( - :Server => "localhost", - :Port => @@port - ) - } - - # get our certs - assert_nothing_raised { - client.initcerts - } - - # make sure all of our cert files exist - certfile = File.join(Puppet[:certdir], [client.fqdn, "pem"].join(".")) - keyfile = File.join(Puppet[:privatekeydir], [client.fqdn, "pem"].join(".")) - publickeyfile = File.join(Puppet[:publickeydir], [client.fqdn, "pem"].join(".")) - - assert(File.exists?(keyfile)) - assert(File.exists?(certfile)) - assert(File.exists?(publickeyfile)) - - # verify we can retrieve the catalog - assert_nothing_raised("Client could not retrieve catalog") { - client.getconfig - } - - # and apply it - assert_nothing_raised("Client could not apply catalog") { - client.apply - } - - # and verify that it did what it was supposed to - assert(FileTest.exists?(@createdfile), - "Applied file does not exist") - end - - - # here we create two servers; we - def disabled_test_failureWithUntrustedCerts - Puppet[:autosign] = true - - # create a pair of clients with no certs - nonemaster = nil - assert_nothing_raised { - nonemaster = Puppet::Network::Client.master.new( - :Server => "localhost", - :Port => @@port - ) - } - - nonebucket = nil - assert_nothing_raised { - nonebucket = Puppet::Network::Client.dipper.new( - :Server => "localhost", - :Port => @@port - ) - } - - # create a ca so we can create a set of certs - # make a new ssldir for it - ca = nil - assert_nothing_raised { - ca = Puppet::Network::Client.ca.new( - :CA => true, :Local => true - ) - ca.requestcert - } - - # initialize our clients with this set of certs - certmaster = nil - assert_nothing_raised { - certmaster = Puppet::Network::Client.master.new( - :Server => "localhost", - :Port => @@port - ) - } - - certbucket = nil - assert_nothing_raised { - certbucket = Puppet::Network::Client.dipper.new( - :Server => "localhost", - :Port => @@port - ) - } - - # Create a new ssl root. - confdir = tempfile() - Puppet[:ssldir] = confdir - Puppet.settings.mkdir(:ssldir) - Puppet.settings.clearused - Puppet.settings.use(:ssl, :ca) - - mkserver - - # now verify that our client cannot do non-cert operations - # because its certs are signed by a different CA - assert_raise(Puppet::Error, - "Client was allowed to call getconfig with no certs") { - nonemaster.getconfig - } - assert_raise(Puppet::Error, - "Client was allowed to call getconfig with untrusted certs") { - certmaster.getconfig - } - - assert_raise(Puppet::Network::XMLRPCClientError, - "Client was allowed to call backup with no certs") { - nonebucket.backup("/etc/passwd") - } - assert_raise(Puppet::Network::XMLRPCClientError, - "Client was allowed to call backup with untrusted certs") { - certbucket.backup("/etc/passwd") - } - end - def test_client_loading # Make sure we don't get a failure but that we also get nothing back assert_nothing_raised do @@ -181,7 +56,7 @@ class TestClient < Test::Unit::TestCase # Make sure we get a client class for each handler type. def test_loading_all_clients - %w{ca dipper file master report resource runner status}.each do |name| + %w{ca dipper file report resource runner status}.each do |name| client = nil assert_nothing_raised do client = Puppet::Network::Client.client(name) diff --git a/test/network/server/webrick.rb b/test/network/server/webrick.rb index 0cdade4ba..8b637c39f 100755 --- a/test/network/server/webrick.rb +++ b/test/network/server/webrick.rb @@ -65,39 +65,6 @@ class TestWebrickServer < Test::Unit::TestCase } assert_equal(1, retval) end - - # Test that a client whose cert has been revoked really can't connect - def test_xcertificate_revocation - Puppet[:autosign] = true - - serverpid, server = mk_status_server - - client = mk_status_client - - status = nil - assert_nothing_raised() { - status = client.status - } - assert_equal(1, status) - client.shutdown - - # Revoke the client's cert - ca = Puppet::SSLCertificates::CA.new() - ca.revoke(ca.getclientcert(Puppet[:certname])[0].serial) - - # Restart the server - @@port += 1 - Puppet[:autosign] = false - kill_and_wait(serverpid, server.pidfile) - serverpid, server = mk_status_server - - # This time the client should be denied. With keep-alive, - # the client starts its connection immediately, thus throwing - # the error. - assert_raise(OpenSSL::SSL::SSLError) { - Puppet::Network::HttpPool.http_instance("localhost", @@port).start - } - end def mk_status_client client = nil diff --git a/test/other/puppet.rb b/test/other/puppet.rb index 6527bed56..23aa6971b 100755 --- a/test/other/puppet.rb +++ b/test/other/puppet.rb @@ -41,36 +41,6 @@ class TestPuppetModule < Test::Unit::TestCase end end - # Make sure that services get correctly started and stopped - def test_servicehandling - file = tempfile() - testclass = mktestclass() - - obj = testclass.new(file) - - assert_nothing_raised { - Puppet.newservice(obj) - } - - assert_nothing_raised { - Puppet.start(false) - } - - # Give it a sec or so - sleep 0.3 - - assert(obj.started?, "Object was not started") - - assert_nothing_raised { - Puppet.shutdown(false) - } - # Give it a sec or so - sleep 0.3 - - assert(!obj.started?, "Object is still running") - - end - def test_path oldpath = ENV["PATH"] cleanup do diff --git a/test/other/report.rb b/test/other/report.rb index bfae0dab0..dd2f4c1ef 100755 --- a/test/other/report.rb +++ b/test/other/report.rb @@ -83,7 +83,7 @@ class TestReports < Test::Unit::TestCase # We have to reuse reporting here because of something going on in the # server/report.rb file - Puppet.settings.use(:main, :reporting) + Puppet.settings.use(:main, :puppetmasterd) 3.times { |i| log = Puppet.warning("Report test message %s" % i) @@ -97,10 +97,7 @@ class TestReports < Test::Unit::TestCase yaml = YAML.dump(report) - file = nil - assert_nothing_raised { - file = report.process - } + file = report.process assert(FileTest.exists?(file), "report file did not get created") assert_equal(yaml, File.read(file), "File did not get written") diff --git a/test/util/settings.rb b/test/util/settings.rb index c4096f0bc..edd8e3e2c 100755 --- a/test/util/settings.rb +++ b/test/util/settings.rb @@ -203,8 +203,6 @@ yay = /a/path file = tempfile() File.open(file, "w") { |f| f.puts text } - - @config.expects(:settimer) result = nil assert_nothing_raised { @@ -607,8 +605,6 @@ yay = /a/path end def test_correct_type_assumptions - config = mkconfig - file = Puppet::Util::Settings::CFile element = Puppet::Util::Settings::CElement bool = Puppet::Util::Settings::CBoolean @@ -624,11 +620,13 @@ yay = /a/path ["$server/yayness", file], ["$server/yayness.conf", file] ].each do |ary| + config = mkconfig value, type = ary + name = value.to_s + "_setting" assert_nothing_raised { - config.setdefaults(:yayness, value => { :default => value, :desc => name.to_s}) + config.setdefaults(:yayness, name => { :default => value, :desc => name.to_s}) } - elem = config.element(value) + elem = config.element(name) assert_instance_of(type, elem, "%s got created as wrong type" % value.inspect) |