Statistics
| Branch: | Tag: | Revision:

root / test / ganeti.bdev_unittest.py @ 5a672c30

History | View | Annotate | Download (7.6 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 5a672c30 Manuel Franceschini
  def testParser80(self):
66 5a672c30 Manuel Franceschini
    """Test drbdsetup show parser for disk and network version 8.0"""
67 5a672c30 Manuel Franceschini
    data = self._ReadTestData("bdev-drbd-8.0.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 5a672c30 Manuel Franceschini
  def testParser83(self):
77 5a672c30 Manuel Franceschini
    """Test drbdsetup show parser for disk and network version 8.3"""
78 5a672c30 Manuel Franceschini
    data = self._ReadTestData("bdev-drbd-8.3.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 5a672c30 Manuel Franceschini
                    "Wrong network info (8.0.x)")
86 3840729d Iustin Pop
87 5a672c30 Manuel Franceschini
  def testParserNetIP4(self):
88 5a672c30 Manuel Franceschini
    """Test drbdsetup show parser for IPv4 network"""
89 5a672c30 Manuel Franceschini
    data = self._ReadTestData("bdev-drbd-net-ip4.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 5a672c30 Manuel Franceschini
                    "Wrong network info (IPv4)")
98 5a672c30 Manuel Franceschini
99 5a672c30 Manuel Franceschini
  def testParserNetIP6(self):
100 5a672c30 Manuel Franceschini
    """Test drbdsetup show parser for IPv6 network"""
101 5a672c30 Manuel Franceschini
    data = self._ReadTestData("bdev-drbd-net-ip6.txt")
102 5a672c30 Manuel Franceschini
    result = bdev.DRBD8._GetDevInfo(data)
103 5a672c30 Manuel Franceschini
    self.failUnless(("local_dev" not in result and
104 5a672c30 Manuel Franceschini
                     "meta_dev" not in result and
105 5a672c30 Manuel Franceschini
                     "meta_index" not in result),
106 5a672c30 Manuel Franceschini
                    "Should not find local disk info")
107 5a672c30 Manuel Franceschini
    self.failUnless(self._has_net(result, ("2001:db8:65::1", 11048),
108 5a672c30 Manuel Franceschini
                                  ("2001:db8:66::1", 11048)),
109 5a672c30 Manuel Franceschini
                    "Wrong network info (IPv6)")
110 3840729d Iustin Pop
111 3840729d Iustin Pop
  def testParserDisk(self):
112 5a672c30 Manuel Franceschini
    """Test drbdsetup show parser for disk"""
113 5a672c30 Manuel Franceschini
    data = self._ReadTestData("bdev-drbd-disk.txt")
114 3840729d Iustin Pop
    result = bdev.DRBD8._GetDevInfo(data)
115 3840729d Iustin Pop
    self.failUnless(self._has_disk(result, "/dev/xenvg/test.data",
116 3840729d Iustin Pop
                                   "/dev/xenvg/test.meta"),
117 3840729d Iustin Pop
                    "Wrong local disk info")
118 3840729d Iustin Pop
    self.failUnless(("local_addr" not in result and
119 3840729d Iustin Pop
                     "remote_addr" not in result),
120 3840729d Iustin Pop
                    "Should not find network info")
121 3840729d Iustin Pop
122 6b90c22e Iustin Pop
123 149a5439 Iustin Pop
class TestDRBD8Status(testutils.GanetiTestCase):
124 6b90c22e Iustin Pop
  """Testing case for DRBD8 /proc status"""
125 6b90c22e Iustin Pop
126 6b90c22e Iustin Pop
  def setUp(self):
127 6b90c22e Iustin Pop
    """Read in txt data"""
128 51596eb2 Iustin Pop
    testutils.GanetiTestCase.setUp(self)
129 149a5439 Iustin Pop
    proc_data = self._TestDataFilename("proc_drbd8.txt")
130 67d101d4 Iustin Pop
    proc80e_data = self._TestDataFilename("proc_drbd80-emptyline.txt")
131 01e2ce3a Iustin Pop
    proc83_data = self._TestDataFilename("proc_drbd83.txt")
132 ae9da390 Iustin Pop
    self.proc_data = bdev.DRBD8._GetProcData(filename=proc_data)
133 67d101d4 Iustin Pop
    self.proc80e_data = bdev.DRBD8._GetProcData(filename=proc80e_data)
134 01e2ce3a Iustin Pop
    self.proc83_data = bdev.DRBD8._GetProcData(filename=proc83_data)
135 6b90c22e Iustin Pop
    self.mass_data = bdev.DRBD8._MassageProcData(self.proc_data)
136 67d101d4 Iustin Pop
    self.mass80e_data = bdev.DRBD8._MassageProcData(self.proc80e_data)
137 01e2ce3a Iustin Pop
    self.mass83_data = bdev.DRBD8._MassageProcData(self.proc83_data)
138 6b90c22e Iustin Pop
139 f6eaed12 Iustin Pop
  def testIOErrors(self):
140 f6eaed12 Iustin Pop
    """Test handling of errors while reading the proc file."""
141 f6eaed12 Iustin Pop
    temp_file = self._CreateTempFile()
142 f6eaed12 Iustin Pop
    os.unlink(temp_file)
143 f6eaed12 Iustin Pop
    self.failUnlessRaises(errors.BlockDeviceError,
144 f6eaed12 Iustin Pop
                          bdev.DRBD8._GetProcData, filename=temp_file)
145 f6eaed12 Iustin Pop
146 6b90c22e Iustin Pop
  def testMinorNotFound(self):
147 6b90c22e Iustin Pop
    """Test not-found-minor in /proc"""
148 6b90c22e Iustin Pop
    self.failUnless(9 not in self.mass_data)
149 01e2ce3a Iustin Pop
    self.failUnless(9 not in self.mass83_data)
150 67d101d4 Iustin Pop
    self.failUnless(3 not in self.mass80e_data)
151 6b90c22e Iustin Pop
152 6b90c22e Iustin Pop
  def testLineNotMatch(self):
153 6b90c22e Iustin Pop
    """Test wrong line passed to DRBD8Status"""
154 6b90c22e Iustin Pop
    self.assertRaises(errors.BlockDeviceError, bdev.DRBD8Status, "foo")
155 6b90c22e Iustin Pop
156 6b90c22e Iustin Pop
  def testMinor0(self):
157 6b90c22e Iustin Pop
    """Test connected, primary device"""
158 01e2ce3a Iustin Pop
    for data in [self.mass_data, self.mass83_data]:
159 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[0])
160 01e2ce3a Iustin Pop
      self.failUnless(stats.is_in_use)
161 01e2ce3a Iustin Pop
      self.failUnless(stats.is_connected and stats.is_primary and
162 01e2ce3a Iustin Pop
                      stats.peer_secondary and stats.is_disk_uptodate)
163 6b90c22e Iustin Pop
164 6b90c22e Iustin Pop
  def testMinor1(self):
165 6b90c22e Iustin Pop
    """Test connected, secondary device"""
166 01e2ce3a Iustin Pop
    for data in [self.mass_data, self.mass83_data]:
167 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[1])
168 01e2ce3a Iustin Pop
      self.failUnless(stats.is_in_use)
169 01e2ce3a Iustin Pop
      self.failUnless(stats.is_connected and stats.is_secondary and
170 01e2ce3a Iustin Pop
                      stats.peer_primary and stats.is_disk_uptodate)
171 6b90c22e Iustin Pop
172 767d52d3 Iustin Pop
  def testMinor2(self):
173 767d52d3 Iustin Pop
    """Test unconfigured device"""
174 67d101d4 Iustin Pop
    for data in [self.mass_data, self.mass83_data, self.mass80e_data]:
175 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[2])
176 01e2ce3a Iustin Pop
      self.failIf(stats.is_in_use)
177 767d52d3 Iustin Pop
178 6b90c22e Iustin Pop
  def testMinor4(self):
179 6b90c22e Iustin Pop
    """Test WFconn device"""
180 01e2ce3a Iustin Pop
    for data in [self.mass_data, self.mass83_data]:
181 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[4])
182 01e2ce3a Iustin Pop
      self.failUnless(stats.is_in_use)
183 01e2ce3a Iustin Pop
      self.failUnless(stats.is_wfconn and stats.is_primary and
184 01e2ce3a Iustin Pop
                      stats.rrole == 'Unknown' and
185 01e2ce3a Iustin Pop
                      stats.is_disk_uptodate)
186 6b90c22e Iustin Pop
187 6b90c22e Iustin Pop
  def testMinor6(self):
188 6b90c22e Iustin Pop
    """Test diskless device"""
189 01e2ce3a Iustin Pop
    for data in [self.mass_data, self.mass83_data]:
190 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[6])
191 01e2ce3a Iustin Pop
      self.failUnless(stats.is_in_use)
192 01e2ce3a Iustin Pop
      self.failUnless(stats.is_connected and stats.is_secondary and
193 01e2ce3a Iustin Pop
                      stats.peer_primary and stats.is_diskless)
194 6b90c22e Iustin Pop
195 6b90c22e Iustin Pop
  def testMinor8(self):
196 6b90c22e Iustin Pop
    """Test standalone device"""
197 01e2ce3a Iustin Pop
    for data in [self.mass_data, self.mass83_data]:
198 01e2ce3a Iustin Pop
      stats = bdev.DRBD8Status(data[8])
199 01e2ce3a Iustin Pop
      self.failUnless(stats.is_in_use)
200 01e2ce3a Iustin Pop
      self.failUnless(stats.is_standalone and
201 01e2ce3a Iustin Pop
                      stats.rrole == 'Unknown' and
202 01e2ce3a Iustin Pop
                      stats.is_disk_uptodate)
203 6b90c22e Iustin Pop
204 3840729d Iustin Pop
if __name__ == '__main__':
205 25231ec5 Michael Hanselmann
  testutils.GanetiTestProgram()