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

« back to all changes in this revision

Viewing changes to ubuntu_system_tests/helpers/ubuntuuitoolkit/fixture_setup.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
 
 
19
 
import fixtures
20
 
from ubuntu_system_tests.helpers.ubuntuuitoolkit import environment
21
 
 
22
 
logger = logging.getLogger(__name__)
23
 
 
24
 
 
25
 
class InitctlEnvironmentVariable(fixtures.Fixture):
26
 
    """Set the value of initctl environment variables."""
27
 
 
28
 
    def __init__(self, global_=False, **kwargs):
29
 
        super().__init__()
30
 
        # Added one level of indirection to be able to spy the calls to
31
 
        # environment during tests.
32
 
        self.environment = environment
33
 
        self.variables = kwargs
34
 
        self.global_ = global_
35
 
 
36
 
    def setUp(self):
37
 
        super().setUp()
38
 
        for variable, value in self.variables.items():
39
 
            self._add_variable_cleanup(variable)
40
 
            if value is None:
41
 
                self.environment.unset_initctl_env_var(
42
 
                    variable, global_=self.global_)
43
 
            else:
44
 
                self.environment.set_initctl_env_var(
45
 
                    variable, value, global_=self.global_)
46
 
 
47
 
    def _add_variable_cleanup(self, variable):
48
 
        if self.environment.is_initctl_env_var_set(
49
 
                variable, global_=self.global_):
50
 
            original_value = self.environment.get_initctl_env_var(
51
 
                variable, global_=self.global_)
52
 
            self.addCleanup(
53
 
                self.environment.set_initctl_env_var,
54
 
                variable,
55
 
                original_value,
56
 
                global_=self.global_)
57
 
        else:
58
 
            self.addCleanup(
59
 
                self.environment.unset_initctl_env_var,
60
 
                variable,
61
 
                global_=self.global_)