1
# Copyright 2014 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Test doubles for the region's RPC implementation."""
6
from __future__ import (
16
"IdentifyingRegionServer",
19
from maasserver.rpc.regionservice import RegionServer
20
from maastesting.factory import factory
21
from provisioningserver.rpc import cluster
22
from twisted.internet.defer import succeed
25
class IdentifyingRegionServer(RegionServer):
26
"""A :class:`RegionServer` derivative that stubs ident of the cluster.
28
This intercepts remote calls to `cluster.Identify` and returns a
31
:ivar cluster_uuid: When `cluster.Identify` is called for the first
32
time, this is populated with a random UUID. That UUID is also
33
returned in the stub-response.
38
def callRemote(self, commandType, *args, **kwargs):
39
if commandType is cluster.Identify:
40
if self.cluster_uuid is None:
41
self.cluster_uuid = factory.getRandomUUID()
42
return succeed({b"ident": self.cluster_uuid})
44
return super(IdentifyingRegionServer, self).callRemote(
45
commandType, *args, **kwargs)