~lutostag/ubuntu/trusty/maas/1.5.2+packagefix

« back to all changes in this revision

Viewing changes to src/maasserver/rpc/testing/doubles.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2014-03-28 10:43:53 UTC
  • mto: This revision was merged to the branch mainline in revision 57.
  • Revision ID: package-import@ubuntu.com-20140328104353-ekpolg0pm5xnvq2s
Tags: upstream-1.5+bzr2204
ImportĀ upstreamĀ versionĀ 1.5+bzr2204

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
"""Test doubles for the region's RPC implementation."""
 
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
    "IdentifyingRegionServer",
 
17
]
 
18
 
 
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
 
23
 
 
24
 
 
25
class IdentifyingRegionServer(RegionServer):
 
26
    """A :class:`RegionServer` derivative that stubs ident of the cluster.
 
27
 
 
28
    This intercepts remote calls to `cluster.Identify` and returns a
 
29
    canned answer.
 
30
 
 
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.
 
34
    """
 
35
 
 
36
    cluster_uuid = None
 
37
 
 
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})
 
43
        else:
 
44
            return super(IdentifyingRegionServer, self).callRemote(
 
45
                commandType, *args, **kwargs)