Skip to content

Commit

Permalink
tests: sbd tests overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmular committed Jan 22, 2018
1 parent 87fb199 commit 735e68d
Show file tree
Hide file tree
Showing 14 changed files with 2,160 additions and 922 deletions.
22 changes: 12 additions & 10 deletions pcs/lib/commands/sbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
)


UNSUPPORTED_SBD_OPTION_LIST = [
"SBD_WATCHDOG_DEV", "SBD_OPTS", "SBD_PACEMAKER", "SBD_DEVICE"
]
ALLOWED_SBD_OPTION_LIST = [
"SBD_DELAY_START", "SBD_STARTMODE", "SBD_WATCHDOG_TIMEOUT"
]


def _validate_sbd_options(sbd_config, allow_unknown_opts=False):
"""
Validate user SBD configuration. Options 'SBD_WATCHDOG_DEV' and 'SBD_OPTS'
Expand All @@ -51,22 +59,16 @@ def _validate_sbd_options(sbd_config, allow_unknown_opts=False):
"""

report_item_list = []
unsupported_sbd_option_list = [
"SBD_WATCHDOG_DEV", "SBD_OPTS", "SBD_PACEMAKER", "SBD_DEVICE"
]
allowed_sbd_options = [
"SBD_DELAY_START", "SBD_STARTMODE", "SBD_WATCHDOG_TIMEOUT"
]
for sbd_opt in sbd_config:
if sbd_opt in unsupported_sbd_option_list:
if sbd_opt in UNSUPPORTED_SBD_OPTION_LIST:
report_item_list.append(reports.invalid_options(
[sbd_opt], allowed_sbd_options, None
[sbd_opt], ALLOWED_SBD_OPTION_LIST, None
))

elif sbd_opt not in allowed_sbd_options:
elif sbd_opt not in ALLOWED_SBD_OPTION_LIST:
report_item_list.append(reports.invalid_options(
[sbd_opt],
allowed_sbd_options,
ALLOWED_SBD_OPTION_LIST,
None,
severity=(
Severities.WARNING if allow_unknown_opts
Expand Down
257 changes: 227 additions & 30 deletions pcs/lib/commands/test/sbd/test_disable_sbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
print_function,
)

import json

from pcs.common import report_codes
from pcs.lib.commands.sbd import disable_sbd
from pcs.test.tools import fixture
Expand All @@ -16,42 +14,241 @@
class DisableSbd(TestCase):
def setUp(self):
self.env_assist, self.config = get_env_tools(self)
self.corosync_conf_name = "corosync-3nodes.conf"
self.node_list = ["rh7-1", "rh7-2", "rh7-3"]

def test_base(self):
(self.config
.runner.corosync.version()
.corosync_conf.load(
node_name_list=["node-1", "node-2"],
)
.http.add_communication(
"check_auth",
[
dict(
label="node-1",
output=json.dumps({"notauthorized": "true"}),
response_code=401,
),
dict(
label="node-2",
output=json.dumps({"success": "true"}),
response_code=200,
),
],
action="remote/check_auth",
param_list=[('check_auth_only', 1)]
)
def test_success(self):
self.config.runner.corosync.version()
self.config.corosync_conf.load(filename=self.corosync_conf_name)
self.config.http.host.check_auth(node_labels=self.node_list)
self.config.http.pcmk.set_stonith_watchdog_timeout_to_zero(
node_labels=self.node_list[:1]
)
self.config.http.sbd.disable_sbd(node_labels=self.node_list)
disable_sbd(self.env_assist.get_env())
self.env_assist.assert_reports(
[fixture.info(report_codes.SBD_DISABLING_STARTED)]
+
[
fixture.info(
report_codes.SERVICE_DISABLE_SUCCESS,
service="sbd",
node=node,
instance=None
) for node in self.node_list
]
+
[
fixture.warn(
report_codes.CLUSTER_RESTART_REQUIRED_TO_APPLY_CHANGES
)
]
)

def test_node_offline(self):
err_msg = "Failed connect to rh7-3:2224; No route to host"
self.config.runner.corosync.version()
self.config.corosync_conf.load(filename=self.corosync_conf_name)
self.config.http.host.check_auth(
communication_list=[
{"label": "rh7-1"},
{"label": "rh7-2"},
{
"label": "rh7-3",
"was_connected": False,
"errno": 7,
"error_msg": err_msg,
}
]
)
self.env_assist.assert_raise_library_error(
lambda: disable_sbd(self.env_assist.get_env()),
[],
expected_in_processor=False
)

self.env_assist.assert_reports([
fixture.error(
report_codes.NODE_COMMUNICATION_ERROR_NOT_AUTHORIZED,
node="node-1",
reason="HTTP error: 401",
command="remote/check_auth",
report_codes.NODE_COMMUNICATION_ERROR_UNABLE_TO_CONNECT,
force_code=report_codes.SKIP_OFFLINE_NODES,
node="rh7-3",
reason=err_msg,
command="remote/check_auth"
)
])

def test_success_node_offline_skip_offline(self):
err_msg = "Failed connect to rh7-3:2224; No route to host"
online_nodes_list = ["rh7-2", "rh7-3"]
self.config.runner.corosync.version()
self.config.corosync_conf.load(filename=self.corosync_conf_name)
self.config.http.host.check_auth(
communication_list=[
{
"label": "rh7-1",
"was_connected": False,
"errno": 7,
"error_msg": err_msg,
},
{"label": "rh7-2"},
{"label": "rh7-3"}
]
)
self.config.http.pcmk.set_stonith_watchdog_timeout_to_zero(
node_labels=online_nodes_list[:1]
)
self.config.http.sbd.disable_sbd(node_labels=online_nodes_list)
disable_sbd(self.env_assist.get_env(), ignore_offline_nodes=True)
self.env_assist.assert_reports(
[fixture.warn(report_codes.OMITTING_NODE, node="rh7-1")]
+
[fixture.info(report_codes.SBD_DISABLING_STARTED)]
+
[
fixture.info(
report_codes.SERVICE_DISABLE_SUCCESS,
service="sbd",
node=node,
instance=None
) for node in online_nodes_list
]
+
[
fixture.warn(
report_codes.CLUSTER_RESTART_REQUIRED_TO_APPLY_CHANGES
)
]
)

def test_set_stonith_watchdog_timeout_fails_on_some_nodes(self):
err_msg = "Error"
self.config.runner.corosync.version()
self.config.corosync_conf.load(filename=self.corosync_conf_name)
self.config.http.host.check_auth(node_labels=self.node_list)
self.config.http.pcmk.set_stonith_watchdog_timeout_to_zero(
communication_list=[
[{
"label": "rh7-1",
"was_connected": False,
"errno": 7,
"error_msg": err_msg,
}],
[{
"label": "rh7-2",
"response_code": 400,
"output": "FAILED",
}],
[{"label": "rh7-3"}]
]
)
self.config.http.sbd.disable_sbd(node_labels=self.node_list)
disable_sbd(self.env_assist.get_env())
self.env_assist.assert_reports(
[
fixture.warn(
report_codes.NODE_COMMUNICATION_ERROR_UNABLE_TO_CONNECT,
node="rh7-1",
reason=err_msg,
command="remote/set_stonith_watchdog_timeout_to_zero"
),
fixture.warn(
report_codes.NODE_COMMUNICATION_COMMAND_UNSUCCESSFUL,
node="rh7-2",
reason="FAILED",
command="remote/set_stonith_watchdog_timeout_to_zero"
)
]
+
[fixture.info(report_codes.SBD_DISABLING_STARTED)]
+
[
fixture.info(
report_codes.SERVICE_DISABLE_SUCCESS,
service="sbd",
node=node,
instance=None
) for node in self.node_list
]
+
[
fixture.warn(
report_codes.CLUSTER_RESTART_REQUIRED_TO_APPLY_CHANGES
)
]
)

def test_set_stonith_watchdog_timeout_fails_on_all_nodes(self):
err_msg = "Error"
self.config.runner.corosync.version()
self.config.corosync_conf.load(filename=self.corosync_conf_name)
self.config.http.host.check_auth(node_labels=self.node_list)
self.config.http.pcmk.set_stonith_watchdog_timeout_to_zero(
communication_list=[
[dict(label=node, response_code=400, output=err_msg)]
for node in self.node_list
]
)
self.env_assist.assert_raise_library_error(
lambda: disable_sbd(self.env_assist.get_env()),
[],
)
self.env_assist.assert_reports(
[
fixture.warn(
report_codes.NODE_COMMUNICATION_COMMAND_UNSUCCESSFUL,
node=node,
reason=err_msg,
command="remote/set_stonith_watchdog_timeout_to_zero"
) for node in self.node_list
]
+
[
fixture.error(
report_codes.UNABLE_TO_PERFORM_OPERATION_ON_ANY_NODE,
)
]
)

def test_disable_failed(self):
err_msg = "Error"
self.config.runner.corosync.version()
self.config.corosync_conf.load(filename=self.corosync_conf_name)
self.config.http.host.check_auth(node_labels=self.node_list)
self.config.http.pcmk.set_stonith_watchdog_timeout_to_zero(
node_labels=self.node_list[:1]
)
self.config.http.sbd.disable_sbd(
communication_list=[
{"label": "rh7-1"},
{"label": "rh7-2"},
{
"label": "rh7-3",
"response_code": 400,
"output": err_msg
}
]
)
self.env_assist.assert_raise_library_error(
lambda: disable_sbd(self.env_assist.get_env()),
[],
)
self.env_assist.assert_reports(
[fixture.info(report_codes.SBD_DISABLING_STARTED)]
+
[
fixture.info(
report_codes.SERVICE_DISABLE_SUCCESS,
service="sbd",
node=node,
instance=None
) for node in self.node_list[:2]
]
+
[
fixture.error(
report_codes.NODE_COMMUNICATION_COMMAND_UNSUCCESSFUL,
node="rh7-3",
reason=err_msg,
command="remote/sbd_disable"
)
]
)
Loading

0 comments on commit 735e68d

Please sign in to comment.