Skip to content

Commit

Permalink
Silence queue enumeration "normal" errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tequeter committed Feb 25, 2020
1 parent 142499b commit e41be13
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,9 @@ Installs, configures, and manages the CUPS service.
* `papersize`: Sets the system's default `/etc/papersize`. See `man papersize` for supported values.

* `purge_unmanaged_queues`: Setting `true` will remove all queues from the node
which do not match a `cups_queue` resource in the current catalog. Defaults to `false`.
which do not match a `cups_queue` resource in the current catalog. Silently
ignored if the Cups server is not reachable when Puppet starts. Defaults to
`false`.

* `resources`: This attribute is intended for use with Hiera or any other ENC (see the [example above](#using-hiera)).

Expand Down
4 changes: 3 additions & 1 deletion README.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,9 @@ Installs, configures, and manages the CUPS service.
* `papersize`: Sets the system's default `/etc/papersize`. See `man papersize` for supported values.

* `purge_unmanaged_queues`: Setting `true` will remove all queues from the node
which do not match a `cups_queue` resource in the current catalog. Defaults to `false`.
which do not match a `cups_queue` resource in the current catalog. Silently
ignored if the Cups server is not reachable when Puppet starts. Defaults to
`false`.

* `resources`: This attribute is intended for use with Hiera or any other ENC (see the [example above](#using-hiera)).

Expand Down
26 changes: 24 additions & 2 deletions lib/puppet/provider/cups_queue/cups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,34 @@
### Static provider methods

def self.instances
discover_class_instances + discover_printer_instances
rescue PuppetX::Cups::Ipp::QueryError => e
# Connecting to Cups may fail because it is not running yet. As Puppet
# tries to enumerate instances before applying the catalog, no amount of
# resource ordering will allow to start the service before we try to
# connect to it.
#
# Furthermore, the desired state might be to stop the service or to not
# manage it at all.
#
# Therefore, purge_unmanaged_queues => true may fail for reasons we can't
# fix, and scare the users with a big red error message (or worse, lead to
# ignore-the-errors mindset). We thus prefer to silence the error here.
# It's still in the debug log if one cares.
debug("Cups queues enumeration failed (this is normal if the cups service isn't running yet):\n" + e.message)
[]
end

def self.discover_class_instances
providers = []
# Discover class instances
PuppetX::Cups::Instances.class_members.each do |class_name, member_names|
providers << new(name: class_name, ensure: :class, members: member_names)
end
# Discover printer instances
providers
end

def self.discover_printer_instances
providers = []
PuppetX::Cups::Instances.printers.each do |printer_name|
providers << new(name: printer_name, ensure: :printer)
end
Expand Down
3 changes: 2 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
# @param page_log_format Sets the `PageLogFormat` directive of the CUPS server.
# @param papersize Sets the system's default `/etc/papersize`. See `man papersize` for supported values.
# @param purge_unmanaged_queues Setting `true` will remove all queues from the node
# which do not match a `cups_queue` resource in the current catalog.
# which do not match a `cups_queue` resource in the current catalog. Silently
# ignored if the Cups server is not reachable when Puppet starts.
# @param resources This attribute is intended for use with Hiera or any other ENC.
# @param server_alias Sets the `ServerAlias` directive of the CUPS server.
# @param server_name Sets the `ServerName` directive of the CUPS server.
Expand Down
15 changes: 15 additions & 0 deletions spec/acceptance/classes/cups_purge_unmanaged_queues_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,19 @@
end
end
end

context 'when the Cups service is running' do
before(:all) do
ensure_cups_is_running
purge_all_queues
add_printers('Office')
end

let(:manifest) { 'class { "cups": purge_unmanaged_queues => true }' }

it 'purges unmanaged queues' do
apply_manifest(manifest, expect_changes: true)
shell('lpstat -p Office', acceptable_exit_codes: [1])
end
end
end

0 comments on commit e41be13

Please sign in to comment.