/usr/lib/python3/dist-packages/provisioningserver/utils/testing.py is in python3-maas-provisioningserver 2.4.0~beta2-6865-gec43e47e6-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | # Copyright 2014-2016 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Testing helpers for provisioningserver.utils."""
__all__ = [
"callWithServiceRunning",
"MAASIDFixture",
"RegistryFixture",
]
from fixtures import Fixture
from provisioningserver.utils import env
from provisioningserver.utils.registry import _registry
from provisioningserver.utils.twisted import (
call,
callOut,
)
from twisted.internet import defer
class RegistryFixture(Fixture):
"""Clears the global registry on entry, restores on exit."""
def setUp(self):
super(RegistryFixture, self).setUp()
self.addCleanup(_registry.update, _registry.copy())
self.addCleanup(_registry.clear)
_registry.clear()
class MAASIDFixture(Fixture):
"""Populate the `maas_id` file."""
def __init__(self, system_id):
super(MAASIDFixture, self).__init__()
self.system_id = system_id
def _setUp(self):
super(MAASIDFixture, self)._setUp()
self.addCleanup(env.set_maas_id, env.get_maas_id())
env.set_maas_id(self.system_id)
def callWithServiceRunning(service, f, *args, **kwargs):
"""Call `f` with `service` running.
The given service is a Twisted service. It is started, the given function
called with the given arguments, then the service is stopped.
Returns a `Deferred`, firing with the result of the call to `f`.
"""
d = defer.maybeDeferred(service.startService)
d.addCallback(call, f, *args, **kwargs)
d.addBoth(callOut, service.stopService)
return d
|