~canonical-platform-qa/ubuntu-system-tests/qemu-build-snap

« back to all changes in this revision

Viewing changes to ubuntu_system_tests/helpers/ubuntuuitoolkit/environment.py

  • Committer: Tarmac
  • Author(s): Sergio Cazzolato, Santiago Baldassin, Heber Parrucci
  • Date: 2016-11-24 17:40:34 UTC
  • mfrom: (471.1.32 systemd-support)
  • Revision ID: tarmac-20161124174034-4isut3l7bveaenxc
Adding changes to support systemd in the target device.

Approved by Sergio Cazzolato, Richard Huddie, platform-qa-bot, Heber Parrucci.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
 
#
3
 
# Copyright (C) 2016 Canonical Ltd.
4
 
#
5
 
# This program is free software; you can redistribute it and/or modify
6
 
# it under the terms of the GNU Lesser General Public License as published by
7
 
# the Free Software Foundation; version 3.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
 
# GNU Lesser General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU Lesser General Public License
15
 
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
 
 
17
 
import logging
18
 
import subprocess
19
 
 
20
 
from autopilot import logging as autopilot_logging
21
 
 
22
 
 
23
 
logger = logging.getLogger(__name__)
24
 
 
25
 
 
26
 
def is_initctl_env_var_set(variable, global_=False):
27
 
    """Check True if an initctl environment variable is set.
28
 
 
29
 
    :param variable: The name of the variable to check.
30
 
    :param global: if True, the method will operate on the global environment
31
 
        table. Default is False.
32
 
    :return: True if the variable is set. False otherwise.
33
 
 
34
 
    """
35
 
    try:
36
 
        get_initctl_env_var(variable, global_)
37
 
        return True
38
 
    except subprocess.CalledProcessError:
39
 
        return False
40
 
 
41
 
 
42
 
def get_initctl_env_var(variable, global_=False):
43
 
    """Return the value of an initctl environment variable."""
44
 
    command = ['/sbin/initctl', 'get-env', variable]
45
 
    if global_:
46
 
        command += ['--global']
47
 
    output = subprocess.check_output(
48
 
        command, stderr=subprocess.STDOUT, universal_newlines=True)
49
 
    return output.rstrip()
50
 
 
51
 
 
52
 
@autopilot_logging.log_action(logger.info)
53
 
def set_initctl_env_var(variable, value, global_=False):
54
 
    """Set the value of an initctl environment variable."""
55
 
    command = ['/sbin/initctl', 'set-env', '%s=%s' % (variable, value)]
56
 
    if global_:
57
 
        command += ['--global']
58
 
    subprocess.call(command, stderr=subprocess.STDOUT, universal_newlines=True)
59
 
 
60
 
 
61
 
@autopilot_logging.log_action(logger.info)
62
 
def unset_initctl_env_var(variable, global_=False):
63
 
    """Remove an initctl environment variable."""
64
 
    command = ['/sbin/initctl', 'unset-env', variable]
65
 
    if global_:
66
 
        command += ['--global']
67
 
    subprocess.call(
68
 
        command, stderr=subprocess.STDOUT, universal_newlines=True)