root / test / py / mocks.py @ 8e8cf324
History | View | Annotate | Download (3.2 kB)
1 | 2f31098c | Iustin Pop | #
|
---|---|---|---|
2 | a8083063 | Iustin Pop | #
|
3 | a8083063 | Iustin Pop | |
4 | e8906f7d | Iustin Pop | # Copyright (C) 2006, 2007, 2010, 2011 Google Inc.
|
5 | a8083063 | Iustin Pop | #
|
6 | a8083063 | Iustin Pop | # This program is free software; you can redistribute it and/or modify
|
7 | a8083063 | Iustin Pop | # it under the terms of the GNU General Public License as published by
|
8 | a8083063 | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or
|
9 | a8083063 | Iustin Pop | # (at your option) any later version.
|
10 | a8083063 | Iustin Pop | #
|
11 | a8083063 | Iustin Pop | # This program is distributed in the hope that it will be useful, but
|
12 | a8083063 | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | a8083063 | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | a8083063 | Iustin Pop | # General Public License for more details.
|
15 | a8083063 | Iustin Pop | #
|
16 | a8083063 | Iustin Pop | # You should have received a copy of the GNU General Public License
|
17 | a8083063 | Iustin Pop | # along with this program; if not, write to the Free Software
|
18 | a8083063 | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | a8083063 | Iustin Pop | # 02110-1301, USA.
|
20 | a8083063 | Iustin Pop | |
21 | a8083063 | Iustin Pop | |
22 | a8083063 | Iustin Pop | """Module implementing a fake ConfigWriter"""
|
23 | a8083063 | Iustin Pop | |
24 | e60c73a1 | René Nussbaumer | |
25 | e60c73a1 | René Nussbaumer | import os |
26 | e60c73a1 | René Nussbaumer | |
27 | a744b676 | Manuel Franceschini | from ganeti import netutils |
28 | a8083063 | Iustin Pop | |
29 | 75a5f456 | Michael Hanselmann | |
30 | 75a5f456 | Michael Hanselmann | FAKE_CLUSTER_KEY = ("AAAAB3NzaC1yc2EAAAABIwAAAQEAsuGLw70et3eApJ/ZEJkAVZogIrm"
|
31 | 75a5f456 | Michael Hanselmann | "EYPQJvb1ll52Ti0nr80Wztxibaa8bYGzY22rQIAloIlePeTGcJceAYK"
|
32 | 75a5f456 | Michael Hanselmann | "PZgm0I/Mp2EUGg2NVsQZIzasz6cW0vYuiUbF9GkVlROmvOAykT58RfM"
|
33 | 75a5f456 | Michael Hanselmann | "L8RhPrjrQxZc+NXgZtgDugYSZcXHDLUyWM1xKUoYy0MqYG6ZXCC/Zno"
|
34 | 75a5f456 | Michael Hanselmann | "RThhmjOJgEmvwrMcTWQjmzH3NeJAxaBsEHR8tiVZ/Y23C/ULWLyNT6R"
|
35 | 75a5f456 | Michael Hanselmann | "fB+DE7IovsMQaS+83AK1Teg7RWNyQczachatf/JT8VjUqFYjJepPjMb"
|
36 | 75a5f456 | Michael Hanselmann | "vYdB2nQds7/+Bf40C/OpbvnAxna1kVtgFHAo18cQ==")
|
37 | 75a5f456 | Michael Hanselmann | |
38 | 75a5f456 | Michael Hanselmann | |
39 | bd39b6bb | Thomas Thrainer | class FakeConfig(object): |
40 | 2d91e6ae | Michael Hanselmann | """Fake configuration object"""
|
41 | a8083063 | Iustin Pop | |
42 | 2d91e6ae | Michael Hanselmann | def IsCluster(self): |
43 | 2d91e6ae | Michael Hanselmann | return True |
44 | a8083063 | Iustin Pop | |
45 | 2d91e6ae | Michael Hanselmann | def GetNodeList(self): |
46 | 2d91e6ae | Michael Hanselmann | return ["a", "b", "c"] |
47 | a8083063 | Iustin Pop | |
48 | a9542a4f | Thomas Thrainer | def GetRsaHostKey(self): |
49 | a9542a4f | Thomas Thrainer | return FAKE_CLUSTER_KEY
|
50 | a9542a4f | Thomas Thrainer | |
51 | a9542a4f | Thomas Thrainer | def GetDsaHostKey(self): |
52 | 2d91e6ae | Michael Hanselmann | return FAKE_CLUSTER_KEY
|
53 | 75a5f456 | Michael Hanselmann | |
54 | 2d91e6ae | Michael Hanselmann | def GetClusterName(self): |
55 | 2d91e6ae | Michael Hanselmann | return "test.cluster" |
56 | 437138c9 | Michael Hanselmann | |
57 | 2d91e6ae | Michael Hanselmann | def GetMasterNode(self): |
58 | 1c3231aa | Thomas Thrainer | return "a" |
59 | 1c3231aa | Thomas Thrainer | |
60 | 1c3231aa | Thomas Thrainer | def GetMasterNodeName(self): |
61 | 2d91e6ae | Michael Hanselmann | return netutils.Hostname.GetSysName()
|
62 | 437138c9 | Michael Hanselmann | |
63 | bd39b6bb | Thomas Thrainer | def GetDefaultIAllocator(self): |
64 | 2d91e6ae | Michael Hanselmann | return "testallocator" |
65 | bd5f214b | Apollon Oikonomopoulos | |
66 | 1c3231aa | Thomas Thrainer | def GetNodeName(self, node_uuid): |
67 | 1c3231aa | Thomas Thrainer | if node_uuid in self.GetNodeList(): |
68 | 1c3231aa | Thomas Thrainer | return "node_%s.example.com" % (node_uuid,) |
69 | 1c3231aa | Thomas Thrainer | else:
|
70 | 1c3231aa | Thomas Thrainer | return None |
71 | 1c3231aa | Thomas Thrainer | |
72 | 1c3231aa | Thomas Thrainer | def GetNodeNames(self, node_uuids): |
73 | 1c3231aa | Thomas Thrainer | return map(self.GetNodeName, node_uuids) |
74 | 1c3231aa | Thomas Thrainer | |
75 | 880478f8 | Iustin Pop | |
76 | bd39b6bb | Thomas Thrainer | class FakeProc(object): |
77 | 2d91e6ae | Michael Hanselmann | """Fake processor object"""
|
78 | 2395c322 | Iustin Pop | |
79 | 2d91e6ae | Michael Hanselmann | def Log(self, msg, *args, **kwargs): |
80 | 2d91e6ae | Michael Hanselmann | pass
|
81 | 7b4c1cb9 | Michael Hanselmann | |
82 | 2d91e6ae | Michael Hanselmann | def LogWarning(self, msg, *args, **kwargs): |
83 | 2d91e6ae | Michael Hanselmann | pass
|
84 | 2395c322 | Iustin Pop | |
85 | 2d91e6ae | Michael Hanselmann | def LogInfo(self, msg, *args, **kwargs): |
86 | 2d91e6ae | Michael Hanselmann | pass
|
87 | f4555db2 | Guido Trotter | |
88 | 2d91e6ae | Michael Hanselmann | def LogStep(self, current, total, message): |
89 | 2d91e6ae | Michael Hanselmann | pass
|
90 | c071c5b3 | Michael Hanselmann | |
91 | c071c5b3 | Michael Hanselmann | |
92 | bd39b6bb | Thomas Thrainer | class FakeGLM(object): |
93 | e8906f7d | Iustin Pop | """Fake global lock manager object"""
|
94 | e8906f7d | Iustin Pop | |
95 | bd39b6bb | Thomas Thrainer | def list_owned(self, _): |
96 | e8906f7d | Iustin Pop | return set() |
97 | e8906f7d | Iustin Pop | |
98 | e8906f7d | Iustin Pop | |
99 | bd39b6bb | Thomas Thrainer | class FakeContext(object): |
100 | 2d91e6ae | Michael Hanselmann | """Fake context object"""
|
101 | f4555db2 | Guido Trotter | |
102 | 2d91e6ae | Michael Hanselmann | def __init__(self): |
103 | 2d91e6ae | Michael Hanselmann | self.cfg = FakeConfig()
|
104 | e8906f7d | Iustin Pop | self.glm = FakeGLM()
|
105 | e60c73a1 | René Nussbaumer | |
106 | e60c73a1 | René Nussbaumer | |
107 | e60c73a1 | René Nussbaumer | class FakeGetentResolver: |
108 | 2d91e6ae | Michael Hanselmann | """Fake runtime.GetentResolver"""
|
109 | 2d91e6ae | Michael Hanselmann | |
110 | 2d91e6ae | Michael Hanselmann | def __init__(self): |
111 | 2d91e6ae | Michael Hanselmann | # As we nomally don't run under root we use our own uid/gid for all
|
112 | 2d91e6ae | Michael Hanselmann | # fields. This way we don't run into permission denied problems.
|
113 | 2d91e6ae | Michael Hanselmann | uid = os.getuid() |
114 | 2d91e6ae | Michael Hanselmann | gid = os.getgid() |
115 | 2d91e6ae | Michael Hanselmann | |
116 | 2d91e6ae | Michael Hanselmann | self.masterd_uid = uid
|
117 | 2d91e6ae | Michael Hanselmann | self.masterd_gid = gid
|
118 | 2d91e6ae | Michael Hanselmann | self.confd_uid = uid
|
119 | 2d91e6ae | Michael Hanselmann | self.confd_gid = gid
|
120 | 2d91e6ae | Michael Hanselmann | self.rapi_uid = uid
|
121 | 2d91e6ae | Michael Hanselmann | self.rapi_gid = gid
|
122 | 2d91e6ae | Michael Hanselmann | self.noded_uid = uid
|
123 | 23b9930c | Michael Hanselmann | self.noded_gid = gid
|
124 | 2d91e6ae | Michael Hanselmann | |
125 | 2d91e6ae | Michael Hanselmann | self.daemons_gid = gid
|
126 | 2d91e6ae | Michael Hanselmann | self.admin_gid = gid
|
127 | 601dfcbb | Michael Hanselmann | |
128 | 601dfcbb | Michael Hanselmann | def LookupUid(self, uid): |
129 | 601dfcbb | Michael Hanselmann | return "user%s" % uid |
130 | 601dfcbb | Michael Hanselmann | |
131 | 601dfcbb | Michael Hanselmann | def LookupGid(self, gid): |
132 | 601dfcbb | Michael Hanselmann | return "group%s" % gid |