~martin-nowack/ubuntu/utopic/maas/bug-1425837

« back to all changes in this revision

Viewing changes to src/provisioningserver/utils/env.py

  • Committer: Package Import Robot
  • Author(s): Julian Edwards, Julian Edwards, Andres Rodriguez
  • Date: 2014-08-21 18:38:27 UTC
  • mfrom: (1.2.34)
  • Revision ID: package-import@ubuntu.com-20140821183827-9xyb5u2o4l8g3zxj
Tags: 1.6.1+bzr2550-0ubuntu1
* New upstream bugfix release:
  - Auto-link node MACs to Networks (LP: #1341619)

[ Julian Edwards ]
* debian/maas-region-controller.postinst: Don't restart RabbitMQ on
  upgrades, just ensure it's running.  Should prevent a race with the
  cluster celery restarting.
* debian/rules: Pull upstream branch from the right place.

[ Andres Rodriguez ]
* debian/maas-region-controller.postinst: Ensure cluster celery is
  started if it also runs on the region.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2014 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Environment-related utilities."""
 
5
 
 
6
from __future__ import (
 
7
    absolute_import,
 
8
    print_function,
 
9
    unicode_literals,
 
10
    )
 
11
 
 
12
str = None
 
13
 
 
14
__metaclass__ = type
 
15
__all__ = [
 
16
    'environment_variables',
 
17
    ]
 
18
 
 
19
from contextlib import contextmanager
 
20
import os
 
21
 
 
22
 
 
23
@contextmanager
 
24
def environment_variables(variables):
 
25
    """Context manager: temporarily set the given environment variables.
 
26
 
 
27
    The variables are reset to their original settings afterwards.
 
28
 
 
29
    :param variables: A dict mapping environment variables to their temporary
 
30
        values.
 
31
    """
 
32
    prior_environ = os.environ.copy()
 
33
    os.environ.update(variables)
 
34
    try:
 
35
        yield
 
36
    finally:
 
37
        os.environ.clear()
 
38
        os.environ.update(prior_environ)