blob: d7cf0c941565f9e636c27421720e261479ab639d [file] [log] [blame]
Sean Kaud2a20432017-07-05 16:55:19 -07001# Copyright 2017 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5from autotest_lib.client.common_lib import error
6from autotest_lib.client.common_lib import utils as sys_utils
7from autotest_lib.client.cros import upstart
8"""Provides utility methods for CUPS."""
9
10
11def has_cups_upstart():
12 """Returns True if cups is installed under upstart."""
13 return upstart.has_service('cupsd')
14
15
16def has_cups_systemd():
17 """Returns True if cups is running under systemd.
18
19 Attempts to start cups if it is not already running.
20 """
21 return sys_utils.has_systemd() and (
22 (sys_utils.get_service_pid('cups') != 0) or
23 (sys_utils.start_service('cups', ignore_status=True) == 0))
24
25
26def has_cups_or_die():
27 """Checks if the cups dameon is installed. Raises TestNAError if it is not.
28
29 TestNA skips the test.
30 """
31 if not (has_cups_upstart() or has_cups_systemd()):
32 raise error.TestNAError('No cupsd service found')