1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Copyright (C) 2016 Canonical Ltd.
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.
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.
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/>.
20
from ubuntu_system_tests.helpers.ubuntuuitoolkit import environment
22
logger = logging.getLogger(__name__)
25
class InitctlEnvironmentVariable(fixtures.Fixture):
26
"""Set the value of initctl environment variables."""
28
def __init__(self, global_=False, **kwargs):
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_
38
for variable, value in self.variables.items():
39
self._add_variable_cleanup(variable)
41
self.environment.unset_initctl_env_var(
42
variable, global_=self.global_)
44
self.environment.set_initctl_env_var(
45
variable, value, global_=self.global_)
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_)
53
self.environment.set_initctl_env_var,
59
self.environment.unset_initctl_env_var,