summaryrefslogtreecommitdiff
path: root/spec/unit/agent_spec.rb
AgeCommit message (Collapse)AuthorFilesLines
2014-02-27(PUP-1275) Never try to fork on WindowsJosh Cooper1-1/+8
In 3.0.2, in commit 4d1a2f83d9 for #17361 restored the ability for *nix agents to apply a catalog in a forked child process. But the change caused Windows agents to also try to fork if run without the `--onetime` flag. This regression means you can't run Windows agents with `--listen` and kick them. This commit adds a `can_fork?` method to ensure we only attempt to fork if we both can and should fork. There is no change in behavior for *nix agents.
2013-09-19Merge remote-tracking branch 'upstream/stable'Josh Cooper1-0/+2
* upstream/stable: (21 commits) (Maint) Fix typo in method name (#22608) Restore the ability for master to accept pson file backups (Maint) Remove spurious subproject commit line (Maint) Fixup whitespace (#22529) Update acceptance test for regex fix and solaris (#22535) Use a response header for version (maint) Convert from should to expect syntax (#22529) Acceptance test for puppet package resource behavior (#22529) Rpm provider does not parse 'package foo is not installed' as a package (#22529) Dpkg provider does not warn on package not found (#22535) Make a full status object the default in agent spec tests. (#22535) Fix support for agent's status endpoint (#22535) Fix an exception msg; cosmetic. (#22535) Add test for legacy yaml serialization of arrays in query string (#22535) Add tests for backward compatibility settings (#22535) Improve notice message for backward compatibility (#22535) Cleanup of desc/hook for new settings (#22535) Fix apply/etc by setting the status_terminus per application (#22535) Revert to yaml when a new agent talks to old master (#22535) Add puppet version to status indirector ...
2013-09-18(#22535) Use a response header for versionKylo Ginsberg1-19/+0
The initial fix for #22535 used a new field in the status endpoint hash to return the puppet master version. The status endpoint has been enabled in authconfig.rb since 2.6, so this seemed safe. However, acceptance tests are based on conf/auth.conf (as is the default PE auth.conf), which was never updated to enable the status endpoint. So the status endpoint is not a good choice for returning the puppet master's version. This patch adds a response header containing the puppet version and uses that to control yaml backward compatibility mode. This also required updating spec tests, including several that have a simple mock up of the http response object.
2013-09-17(#22535) Make a full status object the default in agent spec tests.Kylo Ginsberg1-2/+7
Prior to this patch, the default stubs for the find indirection returned a bare Puppet::Status object, i.e. without setting any version field in the hash, and the one test that needed a version field overrode that stub with one providing a status object with a version field. This is the opposite of what happens in the code, where by default one would expect Puppet::Status to include the current puppet version, and it's an unusual condition (older master) for it to omit the version field. So this patch reverses things so that the default stub of Puppet::Status includes a version field, and the two tests with specific expectations about the version field override the stub.
2013-09-17(#22535) Fix support for agent's status endpointKylo Ginsberg1-0/+16
Without this patch, if the agent's status endpoint were accessed, it would report the master's version. This would happen because the status indirection terminus was set to :rest for the duration of an agent's lifetime. This patch removes the puppet setting for status_terminus, and restores the default terminus of local. It also moves the check for master version out of Puppet::Configurer (where it was shared with, say, apply) and into Puppet::Agent. And in the agent, the check *temporarily* changes the endpoint to rest, queries the master's status endpoint, then restores the original setting for the endpoint. This patch also updates the corresponding spec tests, moving tests from configurer_spec.rb to agent_spec.rb, and adding a stub to local_spec.rb.
2013-08-20(#21201) Remove thread-safety codeAndrew Parker1-12/+0
Puppet does not support running in any threaded environments. The thread safety code that has been added has been, for the most part, haphazard and not a holistic solution to the threading problem. There are many areas that are not protected at all and others that were protected in incomplete ways. The extra code and logic only caused more complication in the codebase and is removed by this commit.
2012-11-07(#17361) Re-enable agent forking for catalog runPatrick Mooney1-3/+7
Commit 6812ee9fc51f327f3a74fc6a6c0eefd9758d0134 introduced agent forking as a means of controlling the persistent heap size of the Puppet daemon. This functionality was inadvertently disabled in the conflicting merge commit 23a1a17bebaadbb9b3a1611f34ae46d06b531136. This is a problem since the agent fails to utilize this memory-saving code path. This patch alters Puppet::Agent.initialize to include should_fork as an additional argument. Puppet::Application::Agent and Puppet::Run were also updated to reflect the new method signature. The agent is instantiated with should_fork enabled during normal operation. For --onetime runs and when instantiated via "puppet kick", should_fork disabled. In order to preserve the Puppet::Agent.initialize API for any external users, should_fork has a default value of true. Affected unit tests have been updated to reflect the expected forking behavior.
2012-09-26(Maint) Remove rspec from shebang lineJeff McCune1-1/+1
Without this patch Ruby 1.9 is still complaining loudly about trying to parse the spec files. The previous attempt to clean up this problem in edc3ddf works for Ruby 1.8 but not 1.9. I'd prefer to remove the shebang lines entirely, but doing so will cause encoding errors in Ruby 1.9. This patch strives for a happy middle ground of convincing Ruby it is actually working with Ruby while not confusing it to think it should exec() to rspec. This patch is the result of the following command run against the source tree: find spec -type f -print0 | \ xargs -0 perl -pl -i -e 's,^\#\!\s?/(.*)rspec,\#! /usr/bin/env ruby,'
2012-07-25(#15668) Use only one way of triggering pluginsyncAndrew Parker1-2/+2
Previously the Configurer took a parameter, :skip_plugin_download, which whould cause it to not trigger a pluginsync. At the same time the pluginsync code (Downloader) would look at Puppet[:pluginsync] to decide whether it should actually pluginsync or not. This changes it so that there is only Pupppet[:pluginsync] which is passed through to the Configurer as a :pluginsync parameter when the Configurer is called. Now all callers can be explicit about doing the pluginsync and the Configurer is less dependent on Puppet settings.
2012-07-23Reduce stubs and expectations on settingsPatrick Carlisle1-4/+4
Many tests set stubs or expectations on configuration values. This is unnecessary, as settings are reset before each test. Because creating a stub stubs out the entire value method on settings, stubbing any individual setting interferes with retrieving any other setting. This makes for weird errors and fragile tests. This commit changes most cases to just set each setting directly. Expectations on settings were often used to verify that a setting is used. This is not a good way of testing this, since it checks that the value is accessed but not that it is actually used correctly. Most expecations on settings are better expressed by changing the setting and then verifying a returned value.
2012-07-02(maint) Standardize on /usr/bin/env ruby -S rspecJeff McCune1-1/+1
Without this patch some spec files are using `ruby -S rspec` and others are using `rspec`. We should standardize on a single form of the interpreter used for spec files. `ruby -S rspec` is the best choice because it correctly informs editors such as Vim with Syntastic that the file is a Ruby file rather than an Rspec file.
2012-04-17(#3757) rename AnonymousFilelock to JsonFilelockChris Price1-10/+1
This commit simply renames AnonymousFilelock to JsonFilelock. The behavior hasn't changed at all yet, so this is a bit of a suspect commit but I wanted to make sure that the git history was as clear as possible as to what happened here.
2012-04-16(#3757) Remove 'anonymous' functionality from lockfilesChris Price1-2/+1
The agent lockfile mechanisms had a concept of "anonymous" built-in to them. This was necessary to help attempt to disambiguate the meaning of the lockfile when we were using it for two purposes (administrative-disabling vs. run-in-progress). Since we now have two separate lockfiles, this is no longer necessary... and it makes the code and API confusing. This commit removes it, and the resulting API feels much cleaner and more straightforward. The "AnonymousFilelock" class needs to be renamed, but I haven't done that yet. My next commit is going to transform it into a JSON-based lockfile class, so I'll rename it as part of that commit.
2012-04-16(#3757) separate settings for agent lockfile pathsChris Price1-5/+0
There are now two different lockfiles for agents; one for indicating that an agent is administratively disabled, and one that indicates that an agent run is already in progress. In previous revisions, the paths for these lockfiles was being built from a single puppet setting via naming convention. This commit does the following: 1. Creates two settings (:agent_running_lockfile and :agent_disabled_lockfile) instead of the previously existing one (:puppetdlock). 2. Removes the Configurer class from the chain of command when the Agent class is determining the lockfile path.
2012-04-16(#3757, #12934) Minor test improvement for agent disable messageChris Price1-1/+2
2012-04-16(#3757) re-introduce lockfile changesChris Price1-2/+8
This commit re-introduces the lockfile behavior changes that were originally merged in to 2.7.x via this pull request: https://github.com/puppetlabs/puppet/pull/216 It was reverted because of mcollective compatibility issues. For more info see: http://projects.puppetlabs.com/issues/12844 It is now being reintroduced for Telly, but with some minor modifications. See #3757, #12933 and #12934 for details on those.
2012-03-27Merge branch '2.7.x'cprice1-32/+0
Conflicts: lib/puppet/daemon.rb spec/unit/daemon_spec.rb spec/unit/parser/ast/leaf_spec.rb spec/unit/provider/package/dpkg_spec.rb spec/unit/util/settings_spec.rb
2012-03-16Merge remote-tracking branch ↵Patrick Carlisle1-32/+0
'daniel-pittman/refactor/2.7.x/4862-remove-the-event-loop-library' into 2.7.x * daniel-pittman/refactor/2.7.x/4862-remove-the-event-loop-library: (#4862) Finally remove the event-loop library. (#4862) define_method is not a public method in Ruby. (#4862) `returning` is not a standard Ruby method. (#4862) Stop using EventLoop in the Puppet daemon.
2012-03-05Merge branch '2.7.x'Patrick Carlisle1-11/+21
* 2.7.x: (#10722) Add spec to verify that an error is logged on bad http (#10722) Refactor http_spec to use expectations Updating CHANGELOG for 2.7.12rc2 (#7592) Remove redundant call to String#to_s (#11988) Work around Augeas reload bug when changing save modes (#11988) Don't overwrite symlinks in augeas provider (#8312) Fix zypper provider so ensure => 'latest' now works (#12844) Fix a unit test relating to lockfiles (#12914) Allow puppet to be interrupted while waiting for child (#12933) Better error message when agent is administratively disabled (#7592) Remove redundant call to String#to_s (#12844) Agent lockfiles: backwards compatibility with 2.7.10/2.7.11 (#10722) Display errors on HTTP report submission failures Revert "Merge remote-tracking branch 'masterzen/tickets/2.7.x/3757' into 2.7.x" Revert "(#12844) Backwards compatibility for 'puppet agent --enable'" (#11988) Work around Augeas reload bug when changing save modes (#11988) Don't overwrite symlinks in augeas provider (#12881) Fix cron type default name error on windows (#12844) Backwards compatibility for 'puppet agent --enable' (#8312) Fix zypper provider so ensure => 'latest' now works Conflicts: lib/puppet/provider/augeas/augeas.rb lib/puppet/reports/http.rb lib/puppet/util/pidlock.rb spec/unit/application/agent_spec.rb spec/unit/provider/augeas/augeas_spec.rb spec/unit/reports/http_spec.rb
2012-03-02(#12933) Better error message when agent is administratively disabledcprice1-3/+21
Detect the difference between the cases where an agent run is aborted due to another agent run already in progress vs. being aborted due to the agent being administratively disabled via '--disable', and print a more useful message for the latter case.
2012-03-01Revert "Merge remote-tracking branch 'masterzen/tickets/2.7.x/3757' into 2.7.x"cprice1-8/+0
This reverts commit 86a806f595f8b7bb280c8c445eef51dfd71bf39d, reversing changes made to ac81771a9cc70b5fb58f86439ebb0585ce92d4e8. See tickets #3757, #12844, #4836, #11057. These changes were deemed to be breaking public APIs, and thus are being reverted from 2.7.x. They'll be reintroduced in 3.x. (The changes in question were relating to how puppet agent creates / manages its lockfiles.) Conflicts: lib/puppet/util/pidlock.rb spec/unit/agent_spec.rb spec/unit/util/pidlock_spec.rb
2012-02-22(#4862) Stop using EventLoop in the Puppet daemon.Daniel Pittman1-32/+0
This eliminates the places in the code that use the EventLoop model directly: the two timers established to check configuration changes and run the agent, and the invocation of the main loop in daemon mode. Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-01-23Merge branch '2.7.x'Daniel Pittman1-0/+10
Conflicts: acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-01-21Run the agent in a child process during catalog applicationBrice Figureau1-0/+53
The idea is that during catalog application the puppet heap might grow quite large. And unfortunately in MRI the heap never decreases, so you're stuck with a large process doing nothing and not using the memory it allocated until the next run. The solution is to fork and do the puppet run in a child process. At the end of the catalog run, the process exits freeing memory to the OS until the next run. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
2012-01-21Refactor: configurer now returns report.exit_statusBrice Figureau1-0/+8
None of the configurer client was directly using the returned report, but only its exit_status. Since now the configurer might run in a child process, we can't return the report, only a status code. This commit changes the configurer and call site so that only the report exit code is returned. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
2012-01-18(#11057) Add spec, should notify why a run is skippedJeff McCune1-0/+10
Without this patch, there isn't any spec test coverage for this particular bug and the behavior change introduced in this change set. This patch fixes the problem by adding a spec test covering our expectation that Puppet informs the user why a run is skipped. The test makes the fundamental assumption this information is contained within Puppet::Application.run_status which we're mocking. The test validates the information contained in Puppet::Application.run_status is in fact shown to the user.
2011-12-28(#4836) - Agent --disable should allow to put a messageBrice Figureau1-0/+1
This way it is possible to let other users know why a puppet agent has been disabled. Usage: puppet agent --disable "because working on backup" When later on, the puppet agent run would abort with: "Run of Puppet configuration client is administratively disabled because working on backup; skipping" It's also possible to not set a message, in which case a default message is provided. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
2011-12-28(#3757) - Move enable/disable to its own lockBrice Figureau1-0/+7
This change also contains a refactor split of Pidlock into its anonymous counterpart. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
2011-08-18maint: remove inaccurate copyright and license statements.Daniel Pittman1-4/+0
For a while Luke, and other authors, injected a created tag, copyright statement, and "All rights reserved" into every new file they added to the Puppet project. This isn't really true, and we have a global license covering the code, so we have now stripped out all those old tags. Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2011-04-13maint: clean up the spec test headers in bulk.Daniel Pittman1-1/+1
We now use a shebang of: #!/usr/bin/env rspec This enables the direct execution of spec tests again, which was lost earlier during the transition to more directly using the rspec2 runtime environment.
2011-04-08maint: just require 'spec_helper', thanks rspec2Daniel Pittman1-1/+1
rspec2 automatically sets a bunch of load-path stuff we were by hand, so we can just stop. As a side-effect we can now avoid a whole pile of stupid things to try and include the spec_helper.rb file... ...and then we can stop protecting spec_helper from evaluating twice, since we now require it with a consistent name. Yay. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
2010-12-06maint: Use expand_path when requiring spec_helper or puppettestMatt Robinson1-1/+1
Doing a require to a relative path can cause files to be required more than once when they're required from different relative paths. If you expand the path fully, this won't happen. Ruby 1.9 also requires that you use expand_path when doing these requires. Paired-with: Jesse Wolfe
2010-07-09Code smell: Two space indentationMarkus Roberts1-215/+215
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
2010-07-09Code smell: Avoid needless decorationsMarkus Roberts1-1/+1
* Replaced 704 occurances of (.*)\b([a-z_]+)\(\) with \1\2 3 Examples: The code: ctx = OpenSSL::SSL::SSLContext.new() becomes: ctx = OpenSSL::SSL::SSLContext.new The code: skip() becomes: skip The code: path = tempfile() becomes: path = tempfile * Replaced 31 occurances of ^( *)end *#.* with \1end 3 Examples: The code: becomes: The code: end # Dir.foreach becomes: end The code: end # def becomes: end
2010-06-28[#3994-part 3] rename spec tests from *_spec_spec to *_spec.rbMarkus Roberts1-0/+281
Part 2 re-did the change on the spec files, which it shouldn't have.
2010-06-28[#3994-part 2] rename integration tests to *_spec.rbMarkus Roberts1-281/+0
Some spec files like active_record.rb had names that would confuse the load path and get loaded instead of the intended implentation when the spec was run from the same directory as the file. Author: Matt Robinson <matt@puppetlabs.com> Date: Fri Jun 11 15:29:33 2010 -0700
2010-06-23[#3994] rename the specs to have _spec.rb at the endMarkus Roberts1-0/+281
Some spec files like active_record.rb had names that would confuse the load path and get loaded instead of the intended implentation when the spec was run from the same directory as the file. Author: Matt Robinson <matt@puppetlabs.com> Date: Fri Jun 11 15:29:33 2010 -0700