Statistics
| Branch: | Tag: | Revision:

root / test / mocks.py @ 601dfcbb

History | View | Annotate | Download (2.8 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 utils
28
from ganeti import netutils
29

    
30

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

    
39

    
40
class FakeConfig:
41
  """Fake configuration object"""
42

    
43
  def IsCluster(self):
44
    return True
45

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

    
49
  def GetHostKey(self):
50
    return FAKE_CLUSTER_KEY
51

    
52
  def GetClusterName(self):
53
    return "test.cluster"
54

    
55
  def GetMasterNode(self):
56
    return netutils.Hostname.GetSysName()
57

    
58
  def GetDefaultIAllocator(Self):
59
    return "testallocator"
60

    
61

    
62
class FakeProc:
63
  """Fake processor object"""
64

    
65
  def Log(self, msg, *args, **kwargs):
66
    pass
67

    
68
  def LogWarning(self, msg, *args, **kwargs):
69
    pass
70

    
71
  def LogInfo(self, msg, *args, **kwargs):
72
    pass
73

    
74
  def LogStep(self, current, total, message):
75
    pass
76

    
77

    
78
class FakeGLM:
79
  """Fake global lock manager object"""
80

    
81
  def list_owned(self, level):
82
    return set()
83

    
84

    
85
class FakeContext:
86
  """Fake context object"""
87

    
88
  def __init__(self):
89
    self.cfg = FakeConfig()
90
    self.glm = FakeGLM()
91

    
92

    
93
class FakeGetentResolver:
94
  """Fake runtime.GetentResolver"""
95

    
96
  def __init__(self):
97
    # As we nomally don't run under root we use our own uid/gid for all
98
    # fields. This way we don't run into permission denied problems.
99
    uid = os.getuid()
100
    gid = os.getgid()
101

    
102
    self.masterd_uid = uid
103
    self.masterd_gid = gid
104
    self.confd_uid = uid
105
    self.confd_gid = gid
106
    self.rapi_uid = uid
107
    self.rapi_gid = gid
108
    self.noded_uid = uid
109

    
110
    self.daemons_gid = gid
111
    self.admin_gid = gid
112

    
113
  def LookupUid(self, uid):
114
    return "user%s" % uid
115

    
116
  def LookupGid(self, gid):
117
    return "group%s" % gid