Revision 69b139f6

b/Makefile.am
1589 1589
	test/py/cmdlib/testsupport/rpc_runner_mock.py \
1590 1590
	test/py/cmdlib/testsupport/ssh_mock.py \
1591 1591
	test/py/cmdlib/testsupport/utils_mock.py \
1592
	test/py/cmdlib/testsupport/util.py
1592
	test/py/cmdlib/testsupport/util.py \
1593
	test/py/cmdlib/testsupport/wconfd_mock.py
1593 1594

  
1594 1595
haskell_tests = test/hs/htest
1595 1596

  
b/test/py/cmdlib/testsupport/__init__.py
35 35
from cmdlib.testsupport.rpc_runner_mock import CreateRpcRunnerMock, \
36 36
  RpcResultsBuilder
37 37
from cmdlib.testsupport.ssh_mock import patchSsh
38
from cmdlib.testsupport.wconfd_mock import WConfdMock
38 39

  
39 40
__all__ = ["CmdlibTestCase",
40 41
           "withLockedLU",
......
49 50
           "ProcessorMock",
50 51
           "RpcResultsBuilder",
51 52
           "LiveLockMock",
53
           "WConfdMock",
52 54
           ]
b/test/py/cmdlib/testsupport/wconfd_mock.py
1
#
2
#
3

  
4
# Copyright (C) 2014 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
"""Support for mocking the wconfd calls"""
23

  
24

  
25
class MockClient(object):
26
  """Mock client calls to wconfd.
27

  
28
  """
29
  def __init__(self, wconfdmock):
30
    self.wconfdmock = wconfdmock
31

  
32
  def TryUpdateLocks(self, _jid, _lockfile, req):
33
    for lockrq in req:
34
      if lockrq[1] == "release":
35
        if lockrq[0] in self.wconfdmock.mylocks:
36
          del self.wconfdmock.mylocks[lockrq[0]]
37
      else:
38
        self.wconfdmock.mylocks[lockrq[0]] = lockrq[1]
39
    return []
40

  
41
  def ListLocks(self, *_):
42
    result = []
43
    for lock in self.wconfdmock.mylocks:
44
      result.append([lock, self.wconfdmock.mylocks[lock]])
45
    return result
46

  
47
  def FreeLocksLevel(self, _jid, _lockfile, level):
48
    locks = self.wconfdmock.mylocks.keys()
49
    for lock in locks:
50
      if lock.startswith(level + "/"):
51
        del self.wconfdmock.mylocks[lock]
52

  
53
  def OpportunisticLockUnion(self, _jid, _lockfile, req):
54
    for lockrq in req:
55
      self.wconfdmock.mylocks[lockrq[0]] = lockrq[1]
56
    return [lockrq[0] for lockrq in req]
57

  
58

  
59
class WConfdMock(object):
60
  """Mock calls to WConfD.
61

  
62
  As at various points, LUs are tested in an integration-test
63
  fashion, calling it through mcpu, which, in turn, calls wconfd,
64
  this mock must be able to live under these circumstances. In particular,
65
  it needs to keep track of locks requested and released, as both,
66
  mcpu and the individual LUs do consistency checks on the locks they
67
  own.
68

  
69
  """
70
  def __init__(self):
71
    self.mylocks = {}
72

  
73
  def Client(self):
74
    return MockClient(self)

Also available in: Unified diff