Statistics
| Branch: | Tag: | Revision:

root / test / ganeti.bdev_unittest.py @ 67d101d4

History | View | Annotate | Download (7 kB)

1 3840729d Iustin Pop
#!/usr/bin/python
2 3840729d Iustin Pop
#
3 3840729d Iustin Pop
4 3840729d Iustin Pop
# Copyright (C) 2006, 2007 Google Inc.
5 3840729d Iustin Pop
#
6 3840729d Iustin Pop
# This program is free software; you can redistribute it and/or modify
7 3840729d Iustin Pop
# it under the terms of the GNU General Public License as published by
8 3840729d Iustin Pop
# the Free Software Foundation; either version 2 of the License, or
9 3840729d Iustin Pop
# (at your option) any later version.
10 3840729d Iustin Pop
#
11 3840729d Iustin Pop
# This program is distributed in the hope that it will be useful, but
12 3840729d Iustin Pop
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 3840729d Iustin Pop
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 3840729d Iustin Pop
# General Public License for more details.
15 3840729d Iustin Pop
#
16 3840729d Iustin Pop
# You should have received a copy of the GNU General Public License
17 3840729d Iustin Pop
# along with this program; if not, write to the Free Software
18 3840729d Iustin Pop
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 3840729d Iustin Pop
# 02110-1301, USA.
20 3840729d Iustin Pop
21 3840729d Iustin Pop
22 3840729d Iustin Pop
"""Script for unittesting the bdev module"""
23 3840729d Iustin Pop
24 3840729d Iustin Pop
25 6634816b Iustin Pop
import os
26 3840729d Iustin Pop
import unittest
27 3840729d Iustin Pop
28 149a5439 Iustin Pop
import testutils
29 3840729d Iustin Pop
from ganeti import bdev
30 6b90c22e Iustin Pop
from ganeti import errors
31 3840729d Iustin Pop
32 3840729d Iustin Pop
33 149a5439 Iustin Pop
class TestDRBD8Runner(testutils.GanetiTestCase):
34 3840729d Iustin Pop
  """Testing case for DRBD8"""
35 3840729d Iustin Pop
36 3840729d Iustin Pop
  @staticmethod
37 3840729d Iustin Pop
  def _has_disk(data, dname, mname):
38 3840729d Iustin Pop
    """Check local disk corectness"""
39 3840729d Iustin Pop
    retval = (
40 3840729d Iustin Pop
      "local_dev" in data and
41 3840729d Iustin Pop
      data["local_dev"] == dname and
42 3840729d Iustin Pop
      "meta_dev" in data and
43 3840729d Iustin Pop
      data["meta_dev"] == mname and
44 3840729d Iustin Pop
      "meta_index" in data and
45 3840729d Iustin Pop
      data["meta_index"] == 0
46 3840729d Iustin Pop
      )
47 3840729d Iustin Pop
    return retval
48 3840729d Iustin Pop
49 3840729d Iustin Pop
  @staticmethod
50 3840729d Iustin Pop
  def _has_net(data, local, remote):
51 3840729d Iustin Pop
    """Check network connection parameters"""
52 3840729d Iustin Pop
    retval = (
53 3840729d Iustin Pop
      "local_addr" in data and
54 3840729d Iustin Pop
      data["local_addr"] == local and
55 3840729d Iustin Pop
      "remote_addr" in data and
56 3840729d Iustin Pop
      data["remote_addr"] == remote
57 3840729d Iustin Pop
      )
58 3840729d Iustin Pop
    return retval
59 3840729d Iustin Pop
60 3840729d Iustin Pop
  def testParserCreation(self):
61 3840729d Iustin Pop
    """Test drbdsetup show parser creation"""
62 3840729d Iustin Pop
    bdev.DRBD8._GetShowParser()
63 3840729d Iustin Pop
64 01e2ce3a Iustin Pop
  def testParserBoth80(self):
65 3840729d Iustin Pop
    """Test drbdsetup show parser for disk and network"""
66 149a5439 Iustin Pop
    data = self._ReadTestData("bdev-both.txt")
67 3840729d Iustin Pop
    result = bdev.DRBD8._GetDevInfo(data)
68 3840729d Iustin Pop
    self.failUnless(self._has_disk(result, "/dev/xenvg/test.data",
69 3840729d Iustin Pop
                                   "/dev/xenvg/test.meta"),
70 3840729d Iustin Pop
                    "Wrong local disk info")
71 3840729d Iustin Pop
    self.failUnless(self._has_net(result, ("192.168.1.1", 11000),
72 3840729d Iustin Pop
                                  ("192.168.1.2", 11000)),
73 01e2ce3a Iustin Pop
                    "Wrong network info (8.0.x)")
74 01e2ce3a Iustin Pop
75 01e2ce3a Iustin Pop
  def testParserBoth83(self):
76 01e2ce3a Iustin Pop
    """Test drbdsetup show parser for disk and network"""
77 01e2ce3a Iustin Pop
    data = self._ReadTestData("bdev-8.3-both.txt")
78 01e2ce3a Iustin Pop
    result = bdev.DRBD8._GetDevInfo(data)
79 01e2ce3a Iustin Pop
    self.failUnless(self._has_disk(result, "/dev/xenvg/test.data",
80 01e2ce3a Iustin Pop
                                   "/dev/xenvg/test.meta"),
81 01e2ce3a Iustin Pop
                    "Wrong local disk info")
82 01e2ce3a Iustin Pop
    self.failUnless(self._has_net(result, ("192.168.1.1", 11000),
83 01e2ce3a Iustin Pop
                                  ("192.168.1.2", 11000)),
84 01e2ce3a Iustin Pop
                    "Wrong network info (8.2.x)")
85 3840729d Iustin Pop
86 3840729d Iustin Pop
  def testParserNet(self):
87 3840729d Iustin Pop
    """Test drbdsetup show parser for disk and network"""
88 149a5439 Iustin Pop
    data = self._ReadTestData("bdev-net.txt")
89 3840729d Iustin Pop
    result = bdev.DRBD8._GetDevInfo(data)
90 3840729d Iustin Pop
    self.failUnless(("local_dev" not in result and
91 3840729d Iustin Pop
                     "meta_dev" not in result and
92 3840729d Iustin Pop
                     "meta_index" not in result),
93 3840729d Iustin Pop
                    "Should not find local disk info")
94 3840729d Iustin Pop
    self.failUnless(self._has_net(result, ("192.168.1.1", 11002),
95 3840729d Iustin Pop
                                  ("192.168.1.2", 11002)),
96 3840729d Iustin Pop
                    "Wrong network info")
97 3840729d Iustin Pop
98 3840729d Iustin Pop
  def testParserDisk(self):
99 3840729d Iustin Pop
    """Test drbdsetup show parser for disk and network"""
100 149a5439 Iustin Pop
    data = self._ReadTestData("bdev-disk.txt")
101 3840729d Iustin Pop
    result = bdev.DRBD8._GetDevInfo(data)
102 3840729d Iustin Pop
    self.failUnless(self._has_disk(result, "/dev/xenvg/test.data",
103 3840729d Iustin Pop
                                   "/dev/xenvg/test.meta"),
104 3840729d Iustin Pop
                    "Wrong local disk info")
105 3840729d Iustin Pop
    self.failUnless(("local_addr" not in result and
106 3840729d Iustin Pop
                     "remote_addr" not in result),
107 3840729d Iustin Pop
                    "Should not find network info")
108 3840729d Iustin Pop
109 6b90c22e Iustin Pop
110 149a5439 Iustin Pop
class TestDRBD8Status(testutils.GanetiTestCase):
111 6b90c22e Iustin Pop
  """Testing case for DRBD8 /proc status"""
112 6b90c22e Iustin Pop
113 6b90c22e Iustin Pop
  def setUp(self):
114 6b90c22e Iustin Pop
    """Read in txt data"""
115 51596eb2 Iustin Pop
    testutils.GanetiTestCase.setUp(self)
116 149a5439 Iustin Pop
    proc_data = self._TestDataFilename("proc_drbd8.txt")
117 67d101d4 Iustin Pop
    proc80e_data = self._TestDataFilename("proc_drbd80-emptyline.txt")
118 01e2ce3a Iustin Pop
    proc83_data = self._TestDataFilename("proc_drbd83.txt")
119 ae9da390 Iustin Pop
    self.proc_data = bdev.DRBD8._GetProcData(filename=proc_data)
120 67d101d4 Iustin Pop
    self.proc80e_data = bdev.DRBD8._GetProcData(filename=proc80e_data)
121 01e2ce3a Iustin Pop
    self.proc83_data = bdev.DRBD8._GetProcData(filename=proc83_data)
122 6b90c22e Iustin Pop
    self.mass_data = bdev.DRBD8._MassageProcData(self.proc_data)
123 67d101d4 Iustin Pop
    self.mass80e_data = bdev.DRBD8._MassageProcData(self.proc80e_data)
124 01e2ce3a Iustin Pop
    self.mass83_data = bdev.DRBD8._MassageProcData(self.proc83_data)
125 6b90c22e Iustin Pop
126 f6eaed12 Iustin Pop
  def testIOErrors(self):
127 f6eaed12 Iustin Pop
    """Test handling of errors while reading the proc file."""
128 f6eaed12 Iustin Pop
    temp_file = self._CreateTempFile()
129 f6eaed12 Iustin Pop
    os.unlink(temp_file)
130 f6eaed12 Iustin Pop
    self.failUnlessRaises(errors.BlockDeviceError,
131 f6eaed12 Iustin Pop
                          bdev.DRBD8._GetProcData, filename=temp_file)
132 f6eaed12 Iustin Pop
133 6b90c22e Iustin Pop
  def testMinorNotFound(self):
134 6b90c22e Iustin Pop
    """Test not-found-minor in /proc"""
135 6b90c22e Iustin Pop
    self.failUnless(9 not in self.mass_data)
136 01e2ce3a Iustin Pop
    self.failUnless(9 not in self.mass83_data)
137 67d101d4 Iustin Pop
    self.failUnless(3 not in self.mass80e_data)
138 6b90c22e Iustin Pop
139 6b90c22e Iustin Pop
  def testLineNotMatch(self):
140 6b90c22e Iustin Pop
    """Test wrong line passed to DRBD8Status"""
141 6b90c22e Iustin Pop
    self.assertRaises(errors.BlockDeviceError, bdev.DRBD8Status, "foo")
142 6b90c22e Iustin Pop
143 6b90c22e Iustin Pop
  def testMinor0(self):
144 6b90c22e Iustin Pop
    """Test connected, primary device"""
145 01e2ce3a Iustin Pop
    for data in [self.mass_data, self.mass83_data]:
146 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[0])
147 01e2ce3a Iustin Pop
      self.failUnless(stats.is_in_use)
148 01e2ce3a Iustin Pop
      self.failUnless(stats.is_connected and stats.is_primary and
149 01e2ce3a Iustin Pop
                      stats.peer_secondary and stats.is_disk_uptodate)
150 6b90c22e Iustin Pop
151 6b90c22e Iustin Pop
  def testMinor1(self):
152 6b90c22e Iustin Pop
    """Test connected, secondary device"""
153 01e2ce3a Iustin Pop
    for data in [self.mass_data, self.mass83_data]:
154 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[1])
155 01e2ce3a Iustin Pop
      self.failUnless(stats.is_in_use)
156 01e2ce3a Iustin Pop
      self.failUnless(stats.is_connected and stats.is_secondary and
157 01e2ce3a Iustin Pop
                      stats.peer_primary and stats.is_disk_uptodate)
158 6b90c22e Iustin Pop
159 767d52d3 Iustin Pop
  def testMinor2(self):
160 767d52d3 Iustin Pop
    """Test unconfigured device"""
161 67d101d4 Iustin Pop
    for data in [self.mass_data, self.mass83_data, self.mass80e_data]:
162 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[2])
163 01e2ce3a Iustin Pop
      self.failIf(stats.is_in_use)
164 767d52d3 Iustin Pop
165 6b90c22e Iustin Pop
  def testMinor4(self):
166 6b90c22e Iustin Pop
    """Test WFconn device"""
167 01e2ce3a Iustin Pop
    for data in [self.mass_data, self.mass83_data]:
168 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[4])
169 01e2ce3a Iustin Pop
      self.failUnless(stats.is_in_use)
170 01e2ce3a Iustin Pop
      self.failUnless(stats.is_wfconn and stats.is_primary and
171 01e2ce3a Iustin Pop
                      stats.rrole == 'Unknown' and
172 01e2ce3a Iustin Pop
                      stats.is_disk_uptodate)
173 6b90c22e Iustin Pop
174 6b90c22e Iustin Pop
  def testMinor6(self):
175 6b90c22e Iustin Pop
    """Test diskless device"""
176 01e2ce3a Iustin Pop
    for data in [self.mass_data, self.mass83_data]:
177 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[6])
178 01e2ce3a Iustin Pop
      self.failUnless(stats.is_in_use)
179 01e2ce3a Iustin Pop
      self.failUnless(stats.is_connected and stats.is_secondary and
180 01e2ce3a Iustin Pop
                      stats.peer_primary and stats.is_diskless)
181 6b90c22e Iustin Pop
182 6b90c22e Iustin Pop
  def testMinor8(self):
183 6b90c22e Iustin Pop
    """Test standalone device"""
184 01e2ce3a Iustin Pop
    for data in [self.mass_data, self.mass83_data]:
185 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[8])
186 01e2ce3a Iustin Pop
      self.failUnless(stats.is_in_use)
187 01e2ce3a Iustin Pop
      self.failUnless(stats.is_standalone and
188 01e2ce3a Iustin Pop
                      stats.rrole == 'Unknown' and
189 01e2ce3a Iustin Pop
                      stats.is_disk_uptodate)
190 6b90c22e Iustin Pop
191 3840729d Iustin Pop
if __name__ == '__main__':
192 3840729d Iustin Pop
  unittest.main()