X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/3fb4f7404062b0e6212c380ed77e34345d6c4a3e..9475189d3cba70537155ba00783ed75baf3ae2b8:/test/mocks.py diff --git a/test/mocks.py b/test/mocks.py index 58e68c3..61eafbc 100644 --- a/test/mocks.py +++ b/test/mocks.py @@ -1,7 +1,7 @@ # # -# Copyright (C) 2006, 2007 Google Inc. +# Copyright (C) 2006, 2007, 2010, 2011 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,7 +21,11 @@ """Module implementing a fake ConfigWriter""" + +import os + from ganeti import utils +from ganeti import netutils FAKE_CLUSTER_KEY = ("AAAAB3NzaC1yc2EAAAABIwAAAQEAsuGLw70et3eApJ/ZEJkAVZogIrm" @@ -34,37 +38,74 @@ FAKE_CLUSTER_KEY = ("AAAAB3NzaC1yc2EAAAABIwAAAQEAsuGLw70et3eApJ/ZEJkAVZogIrm" class FakeConfig: - """Fake configuration object""" + """Fake configuration object""" - def IsCluster(self): - return True + def IsCluster(self): + return True - def GetNodeList(self): - return ["a", "b", "c"] + def GetNodeList(self): + return ["a", "b", "c"] - def GetHostKey(self): - return FAKE_CLUSTER_KEY + def GetHostKey(self): + return FAKE_CLUSTER_KEY - def GetClusterName(self): - return "test.cluster" + def GetClusterName(self): + return "test.cluster" - def GetMasterNode(self): - return utils.HostInfo().name + def GetMasterNode(self): + return netutils.Hostname.GetSysName() + + def GetDefaultIAllocator(Self): + return "testallocator" class FakeProc: - """Fake processor object""" + """Fake processor object""" + + def Log(self, msg, *args, **kwargs): + pass + + def LogWarning(self, msg, *args, **kwargs): + pass + + def LogInfo(self, msg, *args, **kwargs): + pass + + def LogStep(self, current, total, message): + pass - def LogWarning(self, msg, *args, **kwargs): - pass - def LogInfo(self, msg, *args, **kwargs): - pass +class FakeGLM: + """Fake global lock manager object""" + + def list_owned(self, level): + return set() + class FakeContext: - """Fake context object""" + """Fake context object""" + + def __init__(self): + self.cfg = FakeConfig() + self.glm = FakeGLM() + + +class FakeGetentResolver: + """Fake runtime.GetentResolver""" + + def __init__(self): + # As we nomally don't run under root we use our own uid/gid for all + # fields. This way we don't run into permission denied problems. + uid = os.getuid() + gid = os.getgid() + + self.masterd_uid = uid + self.masterd_gid = gid + self.confd_uid = uid + self.confd_gid = gid + self.rapi_uid = uid + self.rapi_gid = gid + self.noded_uid = uid - def __init__(self): - self.cfg = FakeConfig() - # TODO: decide what features a mock Ganeti Lock Manager must have - self.GLM = None + self.daemons_gid = gid + self.admin_gid = gid