root / test / py / ganeti.storage_unittest.py @ 90066780
History | View | Annotate | Download (4.4 kB)
1 |
#!/usr/bin/python
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2012 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 testing ganeti.storage"""
|
23 |
|
24 |
import re |
25 |
import unittest |
26 |
import random |
27 |
|
28 |
from ganeti import constants |
29 |
from ganeti import utils |
30 |
from ganeti import compat |
31 |
from ganeti import errors |
32 |
from ganeti import storage |
33 |
|
34 |
import testutils |
35 |
|
36 |
|
37 |
class TestVGReduce(testutils.GanetiTestCase): |
38 |
VGNAME = "xenvg"
|
39 |
LIST_CMD = storage.LvmVgStorage.LIST_COMMAND |
40 |
VGREDUCE_CMD = storage.LvmVgStorage.VGREDUCE_COMMAND |
41 |
|
42 |
def _runCmd(self, cmd, **kwargs): |
43 |
if not self.run_history: |
44 |
self.fail("Empty run results") |
45 |
exp_cmd, result = self.run_history.pop(0) |
46 |
self.assertEqual(cmd, exp_cmd)
|
47 |
return result
|
48 |
|
49 |
def testOldVersion(self): |
50 |
lvmvg = storage.LvmVgStorage() |
51 |
stdout = self._ReadTestData("vgreduce-removemissing-2.02.02.txt") |
52 |
vgs_fail = self._ReadTestData("vgs-missing-pvs-2.02.02.txt") |
53 |
self.run_history = [
|
54 |
([self.VGREDUCE_CMD, "--removemissing", self.VGNAME], |
55 |
utils.RunResult(0, None, stdout, "", "", None, None)), |
56 |
([self.LIST_CMD, "--noheadings", "--nosuffix", self.VGNAME], |
57 |
utils.RunResult(0, None, "", "", "", None, None)), |
58 |
] |
59 |
lvmvg._RemoveMissing(self.VGNAME, _runcmd_fn=self._runCmd) |
60 |
self.assertEqual(self.run_history, []) |
61 |
for ecode, out in [(1, ""), (0, vgs_fail)]: |
62 |
self.run_history = [
|
63 |
([self.VGREDUCE_CMD, "--removemissing", self.VGNAME], |
64 |
utils.RunResult(0, None, stdout, "", "", None, None)), |
65 |
([self.LIST_CMD, "--noheadings", "--nosuffix", self.VGNAME], |
66 |
utils.RunResult(ecode, None, out, "", "", None, None)), |
67 |
] |
68 |
self.assertRaises(errors.StorageError, lvmvg._RemoveMissing, self.VGNAME, |
69 |
_runcmd_fn=self._runCmd)
|
70 |
self.assertEqual(self.run_history, []) |
71 |
|
72 |
def testNewVersion(self): |
73 |
lvmvg = storage.LvmVgStorage() |
74 |
stdout1 = self._ReadTestData("vgreduce-removemissing-2.02.66-fail.txt") |
75 |
stdout2 = self._ReadTestData("vgreduce-removemissing-2.02.66-ok.txt") |
76 |
vgs_fail = self._ReadTestData("vgs-missing-pvs-2.02.66.txt") |
77 |
# first: require --fail, check that it's used
|
78 |
self.run_history = [
|
79 |
([self.VGREDUCE_CMD, "--removemissing", self.VGNAME], |
80 |
utils.RunResult(0, None, stdout1, "", "", None, None)), |
81 |
([self.VGREDUCE_CMD, "--removemissing", "--force", self.VGNAME], |
82 |
utils.RunResult(0, None, stdout2, "", "", None, None)), |
83 |
([self.LIST_CMD, "--noheadings", "--nosuffix", self.VGNAME], |
84 |
utils.RunResult(0, None, "", "", "", None, None)), |
85 |
] |
86 |
lvmvg._RemoveMissing(self.VGNAME, _runcmd_fn=self._runCmd) |
87 |
self.assertEqual(self.run_history, []) |
88 |
# second: make sure --fail is not used if not needed
|
89 |
self.run_history = [
|
90 |
([self.VGREDUCE_CMD, "--removemissing", self.VGNAME], |
91 |
utils.RunResult(0, None, stdout2, "", "", None, None)), |
92 |
([self.LIST_CMD, "--noheadings", "--nosuffix", self.VGNAME], |
93 |
utils.RunResult(0, None, "", "", "", None, None)), |
94 |
] |
95 |
lvmvg._RemoveMissing(self.VGNAME, _runcmd_fn=self._runCmd) |
96 |
self.assertEqual(self.run_history, []) |
97 |
# third: make sure we error out if vgs doesn't find the volume
|
98 |
for ecode, out in [(1, ""), (0, vgs_fail)]: |
99 |
self.run_history = [
|
100 |
([self.VGREDUCE_CMD, "--removemissing", self.VGNAME], |
101 |
utils.RunResult(0, None, stdout1, "", "", None, None)), |
102 |
([self.VGREDUCE_CMD, "--removemissing", "--force", self.VGNAME], |
103 |
utils.RunResult(0, None, stdout2, "", "", None, None)), |
104 |
([self.LIST_CMD, "--noheadings", "--nosuffix", self.VGNAME], |
105 |
utils.RunResult(ecode, None, out, "", "", None, None)), |
106 |
] |
107 |
self.assertRaises(errors.StorageError, lvmvg._RemoveMissing, self.VGNAME, |
108 |
_runcmd_fn=self._runCmd)
|
109 |
self.assertEqual(self.run_history, []) |
110 |
|
111 |
|
112 |
if __name__ == "__main__": |
113 |
testutils.GanetiTestProgram() |