Statistics
| Branch: | Tag: | Revision:

root / test / ganeti.bdev_unittest.py @ 3840729d

History | View | Annotate | Download (3.2 kB)

1
#!/usr/bin/python
2
#
3

    
4
# Copyright (C) 2006, 2007 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
"""Script for unittesting the bdev module"""
23

    
24

    
25
import unittest
26

    
27
from ganeti import bdev
28

    
29

    
30
class TestDRBD8Runner(unittest.TestCase):
31
  """Testing case for DRBD8"""
32

    
33
  @staticmethod
34
  def _has_disk(data, dname, mname):
35
    """Check local disk corectness"""
36
    retval = (
37
      "local_dev" in data and
38
      data["local_dev"] == dname and
39
      "meta_dev" in data and
40
      data["meta_dev"] == mname and
41
      "meta_index" in data and
42
      data["meta_index"] == 0
43
      )
44
    return retval
45

    
46
  @staticmethod
47
  def _has_net(data, local, remote):
48
    """Check network connection parameters"""
49
    retval = (
50
      "local_addr" in data and
51
      data["local_addr"] == local and
52
      "remote_addr" in data and
53
      data["remote_addr"] == remote
54
      )
55
    return retval
56

    
57
  def testParserCreation(self):
58
    """Test drbdsetup show parser creation"""
59
    bdev.DRBD8._GetShowParser()
60

    
61
  def testParserBoth(self):
62
    """Test drbdsetup show parser for disk and network"""
63
    data = open("data/bdev-both.txt").read()
64
    result = bdev.DRBD8._GetDevInfo(data)
65
    self.failUnless(self._has_disk(result, "/dev/xenvg/test.data",
66
                                   "/dev/xenvg/test.meta"),
67
                    "Wrong local disk info")
68
    self.failUnless(self._has_net(result, ("192.168.1.1", 11000),
69
                                  ("192.168.1.2", 11000)),
70
                    "Wrong network info")
71

    
72
  def testParserNet(self):
73
    """Test drbdsetup show parser for disk and network"""
74
    data = open("data/bdev-net.txt").read()
75
    result = bdev.DRBD8._GetDevInfo(data)
76
    self.failUnless(("local_dev" not in result and
77
                     "meta_dev" not in result and
78
                     "meta_index" not in result),
79
                    "Should not find local disk info")
80
    self.failUnless(self._has_net(result, ("192.168.1.1", 11002),
81
                                  ("192.168.1.2", 11002)),
82
                    "Wrong network info")
83

    
84
  def testParserDisk(self):
85
    """Test drbdsetup show parser for disk and network"""
86
    data = open("data/bdev-disk.txt").read()
87
    result = bdev.DRBD8._GetDevInfo(data)
88
    self.failUnless(self._has_disk(result, "/dev/xenvg/test.data",
89
                                   "/dev/xenvg/test.meta"),
90
                    "Wrong local disk info")
91
    self.failUnless(("local_addr" not in result and
92
                     "remote_addr" not in result),
93
                    "Should not find network info")
94

    
95
if __name__ == '__main__':
96
  unittest.main()