1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
#
# Copyright 2014 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Refer to the README and COPYING files for full details of the license
#
from testrunner import PluginsTestCase as TestCaseBase
from plugins import discover_volumes
import json
class TestDiscoverVolumes(TestCaseBase):
def _getVolumeInfo(self):
result = {}
result['V1'] = {"bricksInfo": [{"name": "172.16.53.1:/bricks/v1-1",
"hostUuid": "0000-1111"}],
"volumeType": "DISTRIBUTE", "volumeName": "V1"}
result['V2'] = {"bricksInfo": [{"name": "172.16.53.2:/bricks/v2-1",
"hostUuid": "0000-1112"}],
"volumeType": "DISTRIBUTE", "volumeName": "V2"}
return result
def _mockGetVolumeInfo(self, volumeName):
volumes = self._getVolumeInfo()
if volumeName:
return {volumeName: volumes.get(volumeName)}
else:
return volumes
def _getBrickByHostAndPath(self, bricksList, hostUuid, path):
for brick in bricksList:
if brick.get('hostUuid') == hostUuid and \
brick.get('brickpath') == path:
return brick
return None
def _verifyVolumeList(self, volDict):
expectedVolumes = self._getVolumeInfo()
self.assertEqual(len(expectedVolumes), len(volDict))
for volName, volumeExpected in expectedVolumes.iteritems():
vol = volDict[volName]
self.assertEqual(volumeExpected['volumeType'], vol['type'])
self.assertEqual(volumeExpected['volumeName'], vol['name'])
self.assertEqual(vol.get('bricks'), None)
def _verifyVolumeInfo(self, volDict, volName):
expectedVolumes = self._mockGetVolumeInfo(volName)
self.assertEqual(len(expectedVolumes), len(volDict))
for volName, volumeExpected in expectedVolumes.iteritems():
vol = volDict[volName]
self.assertEqual(volumeExpected['volumeType'], vol['type'])
self.assertEqual(volumeExpected['volumeName'], vol['name'])
self.assertEqual(len(volumeExpected.get('bricksInfo')),
len(vol.get('bricks')))
for brickExpected in volumeExpected.get('bricksInfo'):
brick = self._getBrickByHostAndPath(
vol.get('bricks'), brickExpected['hostUuid'],
brickExpected['name'].split(":")[1])
self.assertEqual(brick.get('hostUuid'),
brickExpected.get('hostUuid'))
def testDiscoverVolumesList(self):
discover_volumes.glustercli.volumeInfo = self._mockGetVolumeInfo
volumesList = json.loads(discover_volumes.discoverVolumes(None, True))
self._verifyVolumeList(volumesList)
def testDiscoverVolumesInfo(self):
discover_volumes.glustercli.volumeInfo = self._mockGetVolumeInfo
volumesList = json.loads(discover_volumes.discoverVolumes("V1", False))
self._verifyVolumeInfo(volumesList, "V1")
def testAruguments(self):
argParser = discover_volumes.get_arg_parser()
args = argParser.parse_args(["-l", "-v", "V1"])
self.assertEqual(args.list, True)
self.assertEqual(args.volume, "V1")
args = argParser.parse_args(["--list", "--volume", "V1"])
self.assertEqual(args.list, True)
self.assertEqual(args.volume, "V1")
args = argParser.parse_args(["--v", "V1"])
self.assertEqual(args.volume, "V1")
self.assertEqual(args.list, False)
args = argParser.parse_args(["-l"])
self.assertEqual(args.list, True)
self.assertEqual(args.volume, None)
|