Statistics
| Branch: | Tag: | Revision:

root / test / ganeti.bdev_unittest.py @ 28f34048

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 3840729d Iustin Pop
from ganeti import bdev
29 6b90c22e Iustin Pop
from ganeti import errors
30 3840729d Iustin Pop
31 25231ec5 Michael Hanselmann
import testutils
32 25231ec5 Michael Hanselmann
33 3840729d Iustin Pop
34 149a5439 Iustin Pop
class TestDRBD8Runner(testutils.GanetiTestCase):
35 3840729d Iustin Pop
  """Testing case for DRBD8"""
36 3840729d Iustin Pop
37 3840729d Iustin Pop
  @staticmethod
38 3840729d Iustin Pop
  def _has_disk(data, dname, mname):
39 3840729d Iustin Pop
    """Check local disk corectness"""
40 3840729d Iustin Pop
    retval = (
41 3840729d Iustin Pop
      "local_dev" in data and
42 3840729d Iustin Pop
      data["local_dev"] == dname and
43 3840729d Iustin Pop
      "meta_dev" in data and
44 3840729d Iustin Pop
      data["meta_dev"] == mname and
45 3840729d Iustin Pop
      "meta_index" in data and
46 3840729d Iustin Pop
      data["meta_index"] == 0
47 3840729d Iustin Pop
      )
48 3840729d Iustin Pop
    return retval
49 3840729d Iustin Pop
50 3840729d Iustin Pop
  @staticmethod
51 3840729d Iustin Pop
  def _has_net(data, local, remote):
52 3840729d Iustin Pop
    """Check network connection parameters"""
53 3840729d Iustin Pop
    retval = (
54 3840729d Iustin Pop
      "local_addr" in data and
55 3840729d Iustin Pop
      data["local_addr"] == local and
56 3840729d Iustin Pop
      "remote_addr" in data and
57 3840729d Iustin Pop
      data["remote_addr"] == remote
58 3840729d Iustin Pop
      )
59 3840729d Iustin Pop
    return retval
60 3840729d Iustin Pop
61 3840729d Iustin Pop
  def testParserCreation(self):
62 3840729d Iustin Pop
    """Test drbdsetup show parser creation"""
63 3840729d Iustin Pop
    bdev.DRBD8._GetShowParser()
64 3840729d Iustin Pop
65 01e2ce3a Iustin Pop
  def testParserBoth80(self):
66 3840729d Iustin Pop
    """Test drbdsetup show parser for disk and network"""
67 149a5439 Iustin Pop
    data = self._ReadTestData("bdev-both.txt")
68 3840729d Iustin Pop
    result = bdev.DRBD8._GetDevInfo(data)
69 3840729d Iustin Pop
    self.failUnless(self._has_disk(result, "/dev/xenvg/test.data",
70 3840729d Iustin Pop
                                   "/dev/xenvg/test.meta"),
71 3840729d Iustin Pop
                    "Wrong local disk info")
72 3840729d Iustin Pop
    self.failUnless(self._has_net(result, ("192.168.1.1", 11000),
73 3840729d Iustin Pop
                                  ("192.168.1.2", 11000)),
74 01e2ce3a Iustin Pop
                    "Wrong network info (8.0.x)")
75 01e2ce3a Iustin Pop
76 01e2ce3a Iustin Pop
  def testParserBoth83(self):
77 01e2ce3a Iustin Pop
    """Test drbdsetup show parser for disk and network"""
78 01e2ce3a Iustin Pop
    data = self._ReadTestData("bdev-8.3-both.txt")
79 01e2ce3a Iustin Pop
    result = bdev.DRBD8._GetDevInfo(data)
80 01e2ce3a Iustin Pop
    self.failUnless(self._has_disk(result, "/dev/xenvg/test.data",
81 01e2ce3a Iustin Pop
                                   "/dev/xenvg/test.meta"),
82 01e2ce3a Iustin Pop
                    "Wrong local disk info")
83 01e2ce3a Iustin Pop
    self.failUnless(self._has_net(result, ("192.168.1.1", 11000),
84 01e2ce3a Iustin Pop
                                  ("192.168.1.2", 11000)),
85 01e2ce3a Iustin Pop
                    "Wrong network info (8.2.x)")
86 3840729d Iustin Pop
87 3840729d Iustin Pop
  def testParserNet(self):
88 3840729d Iustin Pop
    """Test drbdsetup show parser for disk and network"""
89 149a5439 Iustin Pop
    data = self._ReadTestData("bdev-net.txt")
90 3840729d Iustin Pop
    result = bdev.DRBD8._GetDevInfo(data)
91 3840729d Iustin Pop
    self.failUnless(("local_dev" not in result and
92 3840729d Iustin Pop
                     "meta_dev" not in result and
93 3840729d Iustin Pop
                     "meta_index" not in result),
94 3840729d Iustin Pop
                    "Should not find local disk info")
95 3840729d Iustin Pop
    self.failUnless(self._has_net(result, ("192.168.1.1", 11002),
96 3840729d Iustin Pop
                                  ("192.168.1.2", 11002)),
97 3840729d Iustin Pop
                    "Wrong network info")
98 3840729d Iustin Pop
99 3840729d Iustin Pop
  def testParserDisk(self):
100 3840729d Iustin Pop
    """Test drbdsetup show parser for disk and network"""
101 149a5439 Iustin Pop
    data = self._ReadTestData("bdev-disk.txt")
102 3840729d Iustin Pop
    result = bdev.DRBD8._GetDevInfo(data)
103 3840729d Iustin Pop
    self.failUnless(self._has_disk(result, "/dev/xenvg/test.data",
104 3840729d Iustin Pop
                                   "/dev/xenvg/test.meta"),
105 3840729d Iustin Pop
                    "Wrong local disk info")
106 3840729d Iustin Pop
    self.failUnless(("local_addr" not in result and
107 3840729d Iustin Pop
                     "remote_addr" not in result),
108 3840729d Iustin Pop
                    "Should not find network info")
109 3840729d Iustin Pop
110 6b90c22e Iustin Pop
111 149a5439 Iustin Pop
class TestDRBD8Status(testutils.GanetiTestCase):
112 6b90c22e Iustin Pop
  """Testing case for DRBD8 /proc status"""
113 6b90c22e Iustin Pop
114 6b90c22e Iustin Pop
  def setUp(self):
115 6b90c22e Iustin Pop
    """Read in txt data"""
116 51596eb2 Iustin Pop
    testutils.GanetiTestCase.setUp(self)
117 149a5439 Iustin Pop
    proc_data = self._TestDataFilename("proc_drbd8.txt")
118 67d101d4 Iustin Pop
    proc80e_data = self._TestDataFilename("proc_drbd80-emptyline.txt")
119 01e2ce3a Iustin Pop
    proc83_data = self._TestDataFilename("proc_drbd83.txt")
120 ae9da390 Iustin Pop
    self.proc_data = bdev.DRBD8._GetProcData(filename=proc_data)
121 67d101d4 Iustin Pop
    self.proc80e_data = bdev.DRBD8._GetProcData(filename=proc80e_data)
122 01e2ce3a Iustin Pop
    self.proc83_data = bdev.DRBD8._GetProcData(filename=proc83_data)
123 6b90c22e Iustin Pop
    self.mass_data = bdev.DRBD8._MassageProcData(self.proc_data)
124 67d101d4 Iustin Pop
    self.mass80e_data = bdev.DRBD8._MassageProcData(self.proc80e_data)
125 01e2ce3a Iustin Pop
    self.mass83_data = bdev.DRBD8._MassageProcData(self.proc83_data)
126 6b90c22e Iustin Pop
127 f6eaed12 Iustin Pop
  def testIOErrors(self):
128 f6eaed12 Iustin Pop
    """Test handling of errors while reading the proc file."""
129 f6eaed12 Iustin Pop
    temp_file = self._CreateTempFile()
130 f6eaed12 Iustin Pop
    os.unlink(temp_file)
131 f6eaed12 Iustin Pop
    self.failUnlessRaises(errors.BlockDeviceError,
132 f6eaed12 Iustin Pop
                          bdev.DRBD8._GetProcData, filename=temp_file)
133 f6eaed12 Iustin Pop
134 6b90c22e Iustin Pop
  def testMinorNotFound(self):
135 6b90c22e Iustin Pop
    """Test not-found-minor in /proc"""
136 6b90c22e Iustin Pop
    self.failUnless(9 not in self.mass_data)
137 01e2ce3a Iustin Pop
    self.failUnless(9 not in self.mass83_data)
138 67d101d4 Iustin Pop
    self.failUnless(3 not in self.mass80e_data)
139 6b90c22e Iustin Pop
140 6b90c22e Iustin Pop
  def testLineNotMatch(self):
141 6b90c22e Iustin Pop
    """Test wrong line passed to DRBD8Status"""
142 6b90c22e Iustin Pop
    self.assertRaises(errors.BlockDeviceError, bdev.DRBD8Status, "foo")
143 6b90c22e Iustin Pop
144 6b90c22e Iustin Pop
  def testMinor0(self):
145 6b90c22e Iustin Pop
    """Test connected, primary device"""
146 01e2ce3a Iustin Pop
    for data in [self.mass_data, self.mass83_data]:
147 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[0])
148 01e2ce3a Iustin Pop
      self.failUnless(stats.is_in_use)
149 01e2ce3a Iustin Pop
      self.failUnless(stats.is_connected and stats.is_primary and
150 01e2ce3a Iustin Pop
                      stats.peer_secondary and stats.is_disk_uptodate)
151 6b90c22e Iustin Pop
152 6b90c22e Iustin Pop
  def testMinor1(self):
153 6b90c22e Iustin Pop
    """Test connected, secondary device"""
154 01e2ce3a Iustin Pop
    for data in [self.mass_data, self.mass83_data]:
155 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[1])
156 01e2ce3a Iustin Pop
      self.failUnless(stats.is_in_use)
157 01e2ce3a Iustin Pop
      self.failUnless(stats.is_connected and stats.is_secondary and
158 01e2ce3a Iustin Pop
                      stats.peer_primary and stats.is_disk_uptodate)
159 6b90c22e Iustin Pop
160 767d52d3 Iustin Pop
  def testMinor2(self):
161 767d52d3 Iustin Pop
    """Test unconfigured device"""
162 67d101d4 Iustin Pop
    for data in [self.mass_data, self.mass83_data, self.mass80e_data]:
163 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[2])
164 01e2ce3a Iustin Pop
      self.failIf(stats.is_in_use)
165 767d52d3 Iustin Pop
166 6b90c22e Iustin Pop
  def testMinor4(self):
167 6b90c22e Iustin Pop
    """Test WFconn device"""
168 01e2ce3a Iustin Pop
    for data in [self.mass_data, self.mass83_data]:
169 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[4])
170 01e2ce3a Iustin Pop
      self.failUnless(stats.is_in_use)
171 01e2ce3a Iustin Pop
      self.failUnless(stats.is_wfconn and stats.is_primary and
172 01e2ce3a Iustin Pop
                      stats.rrole == 'Unknown' and
173 01e2ce3a Iustin Pop
                      stats.is_disk_uptodate)
174 6b90c22e Iustin Pop
175 6b90c22e Iustin Pop
  def testMinor6(self):
176 6b90c22e Iustin Pop
    """Test diskless device"""
177 01e2ce3a Iustin Pop
    for data in [self.mass_data, self.mass83_data]:
178 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[6])
179 01e2ce3a Iustin Pop
      self.failUnless(stats.is_in_use)
180 01e2ce3a Iustin Pop
      self.failUnless(stats.is_connected and stats.is_secondary and
181 01e2ce3a Iustin Pop
                      stats.peer_primary and stats.is_diskless)
182 6b90c22e Iustin Pop
183 6b90c22e Iustin Pop
  def testMinor8(self):
184 6b90c22e Iustin Pop
    """Test standalone device"""
185 01e2ce3a Iustin Pop
    for data in [self.mass_data, self.mass83_data]:
186 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[8])
187 01e2ce3a Iustin Pop
      self.failUnless(stats.is_in_use)
188 01e2ce3a Iustin Pop
      self.failUnless(stats.is_standalone and
189 01e2ce3a Iustin Pop
                      stats.rrole == 'Unknown' and
190 01e2ce3a Iustin Pop
                      stats.is_disk_uptodate)
191 6b90c22e Iustin Pop
192 3840729d Iustin Pop
if __name__ == '__main__':
193 25231ec5 Michael Hanselmann
  testutils.GanetiTestProgram()