Statistics
| Branch: | Tag: | Revision:

root / test / py / mocks.py @ 14933c17

History | View | Annotate | Download (3.2 kB)

1
#
2
#
3

    
4
# Copyright (C) 2006, 2007, 2010, 2011 Google Inc.
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
# General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
# 02110-1301, USA.
20

    
21

    
22
"""Module implementing a fake ConfigWriter"""
23

    
24

    
25
import os
26

    
27
from ganeti import netutils
28

    
29

    
30
FAKE_CLUSTER_KEY = ("AAAAB3NzaC1yc2EAAAABIwAAAQEAsuGLw70et3eApJ/ZEJkAVZogIrm"
31
                    "EYPQJvb1ll52Ti0nr80Wztxibaa8bYGzY22rQIAloIlePeTGcJceAYK"
32
                    "PZgm0I/Mp2EUGg2NVsQZIzasz6cW0vYuiUbF9GkVlROmvOAykT58RfM"
33
                    "L8RhPrjrQxZc+NXgZtgDugYSZcXHDLUyWM1xKUoYy0MqYG6ZXCC/Zno"
34
                    "RThhmjOJgEmvwrMcTWQjmzH3NeJAxaBsEHR8tiVZ/Y23C/ULWLyNT6R"
35
                    "fB+DE7IovsMQaS+83AK1Teg7RWNyQczachatf/JT8VjUqFYjJepPjMb"
36
                    "vYdB2nQds7/+Bf40C/OpbvnAxna1kVtgFHAo18cQ==")
37

    
38

    
39
class FakeConfig(object):
40
  """Fake configuration object"""
41

    
42
  def IsCluster(self):
43
    return True
44

    
45
  def GetNodeList(self):
46
    return ["a", "b", "c"]
47

    
48
  def GetRsaHostKey(self):
49
    return FAKE_CLUSTER_KEY
50

    
51
  def GetDsaHostKey(self):
52
    return FAKE_CLUSTER_KEY
53

    
54
  def GetClusterName(self):
55
    return "test.cluster"
56

    
57
  def GetMasterNode(self):
58
    return "a"
59

    
60
  def GetMasterNodeName(self):
61
    return netutils.Hostname.GetSysName()
62

    
63
  def GetDefaultIAllocator(self):
64
    return "testallocator"
65

    
66
  def GetNodeName(self, node_uuid):
67
    if node_uuid in self.GetNodeList():
68
      return "node_%s.example.com" % (node_uuid,)
69
    else:
70
      return None
71

    
72
  def GetNodeNames(self, node_uuids):
73
    return map(self.GetNodeName, node_uuids)
74

    
75

    
76
class FakeProc(object):
77
  """Fake processor object"""
78

    
79
  def Log(self, msg, *args, **kwargs):
80
    pass
81

    
82
  def LogWarning(self, msg, *args, **kwargs):
83
    pass
84

    
85
  def LogInfo(self, msg, *args, **kwargs):
86
    pass
87

    
88
  def LogStep(self, current, total, message):
89
    pass
90

    
91

    
92
class FakeGLM(object):
93
  """Fake global lock manager object"""
94

    
95
  def list_owned(self, _):
96
    return set()
97

    
98

    
99
class FakeContext(object):
100
  """Fake context object"""
101

    
102
  def __init__(self):
103
    self.cfg = FakeConfig()
104
    self.glm = FakeGLM()
105

    
106

    
107
class FakeGetentResolver:
108
  """Fake runtime.GetentResolver"""
109

    
110
  def __init__(self):
111
    # As we nomally don't run under root we use our own uid/gid for all
112
    # fields. This way we don't run into permission denied problems.
113
    uid = os.getuid()
114
    gid = os.getgid()
115

    
116
    self.masterd_uid = uid
117
    self.masterd_gid = gid
118
    self.confd_uid = uid
119
    self.confd_gid = gid
120
    self.rapi_uid = uid
121
    self.rapi_gid = gid
122
    self.noded_uid = uid
123
    self.noded_gid = gid
124

    
125
    self.daemons_gid = gid
126
    self.admin_gid = gid
127

    
128
  def LookupUid(self, uid):
129
    return "user%s" % uid
130

    
131
  def LookupGid(self, gid):
132
    return "group%s" % gid