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
|
#
# 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
#
import mock
from testrunner import PluginsTestCase as TestCaseBase
from plugins import check_quorum_status
from glusternagios import utils
class TestCheckQuorumStatus(TestCaseBase):
# Method to test quorum status when quorum not set
@mock.patch('glusternagios.glustercli.volumeInfo')
def test_checkStatusNoQuorum(self, mock_volumeInfo):
mock_volumeInfo.return_value = _getVolumes('none')
exitStatusCode, exitStatusMsg = (check_quorum_status
.getClusterQuorumStatus())
print exitStatusMsg
assert exitStatusMsg == "Server quorum not turned on for any volume"
assert exitStatusCode == utils.PluginStatusCode.UNKNOWN
mock_volumeInfo.return_value = _getEmptyVolume()
exitStatusCode, exitStatusMsg = (check_quorum_status
.getClusterQuorumStatus())
assert exitStatusMsg == "Server quorum not turned on for any volume"
assert exitStatusCode == utils.PluginStatusCode.UNKNOWN
# Method to test quorum status when options are turned on
@mock.patch('glusternagios.glustercli.volumeInfo')
def test_checkStatusWithQuorum(self, mock_volumeInfo):
mock_volumeInfo.return_value = _getVolumes('server')
exitStatusCode, exitStatusMsg = (check_quorum_status
.getClusterQuorumStatus())
assert exitStatusCode == utils.PluginStatusCode.OK
assert exitStatusMsg == "Server quorum turned on " \
"for test-vol,test-vol2"
def _getVolumes(quorumVal):
vol = {'test-vol': {'brickCount': 2,
'bricks': ['server1:/path1', 'server2:/path2'],
'options': {'cluster.quorum-type': 'none',
'cluster.server-quorum-type': quorumVal,
'changelog.changelog': 'on'},
'transportType': ['tcp'],
'uuid': '0000-0000-0000-1111',
'volumeName': 'test-vol',
'volumeStatus': 'ONLINE',
'volumeType': 'DISTRIBUTED'},
'test-vol2': {'brickCount': 2,
'bricks': ['server1:/path1', 'server2:/path2'],
'options': {'cluster.quorum-type': 'none',
'cluster.server-quorum-type': quorumVal,
'changelog.changelog': 'on'},
'transportType': ['tcp'],
'uuid': '0000-0000-0000-1111',
'volumeName': 'test-vol',
'volumeStatus': 'ONLINE',
'volumeType': 'DISTRIBUTED'}}
return vol
def _getEmptyVolume():
return {}
|