/usr/lib/python3/dist-packages/provisioningserver/rackdservices/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 | # Copyright 2016 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Testing resources for `provisioningserver.rackdservices`."""
__all__ = [
"prepareRegionForGetControllerType",
]
from maastesting.factory import factory
from maastesting.twisted import always_succeed_with
from provisioningserver import services
from provisioningserver.rpc import region
from provisioningserver.rpc.testing import MockLiveClusterToRegionRPCFixture
def prepareRegionForGetControllerType(test, is_region=False, is_rack=True):
"""Set up a mock region controller that responds to `GetControllerType`.
In addition it sets the MAAS ID to a new random value. It arranges for
tear-down at the end of the test.
:return: The running RPC service, and the protocol instance.
"""
fixture = test.useFixture(MockLiveClusterToRegionRPCFixture())
protocol, connecting = fixture.makeEventLoop(region.GetControllerType)
protocol.RegisterRackController.side_effect = always_succeed_with(
{"system_id": factory.make_name("maas-id")})
protocol.GetControllerType.side_effect = always_succeed_with({
"is_region": is_region, "is_rack": is_rack})
def connected(teardown):
test.addCleanup(teardown)
return services.getServiceNamed("rpc"), protocol
return connecting.addCallback(connected)
|