Skip to content

Commit

Permalink
Merge branch 'tests-booth'
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmular committed Feb 1, 2018
2 parents 7b5994d + 7b7b90b commit 435a55f
Show file tree
Hide file tree
Showing 12 changed files with 994 additions and 315 deletions.
2 changes: 1 addition & 1 deletion pcs/lib/booth/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def set_keyfile_access(file_path):
except EnvironmentError as e:
raise report_keyfile_io_error(file_path, "chown", e)
try:
os.chmod(file_path, 0o600)
os.chmod(file_path, settings.pacemaker_authkey_file_mode)
except EnvironmentError as e:
raise report_keyfile_io_error(file_path, "chmod", e)

Expand Down
147 changes: 0 additions & 147 deletions pcs/lib/booth/test/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,104 +33,6 @@
def to_b64(string):
return base64.b64encode(string.encode("utf-8")).decode("utf-8")

@skip("TODO: rewrite for pcs.lib.communication.booth.BoothSendConfig")
class SetConfigOnNodeTest(TestCase):
def setUp(self):
self.mock_com = mock.MagicMock(spec_set=NodeCommunicator)
self.mock_rep = MockLibraryReportProcessor()
self.node = NodeAddresses("node")

def test_with_authfile(self):
lib._set_config_on_node(
self.mock_com,
self.mock_rep,
self.node,
"cfg_name",
"cfg",
authfile="/abs/path/my-key.key",
authfile_data="test key".encode("utf-8")
)
self.assertEqual(1, self.mock_com.call_node.call_count)
self.assertEqual(self.node, self.mock_com.call_node.call_args[0][0])
self.assertEqual(
"remote/booth_set_config", self.mock_com.call_node.call_args[0][1]
)
data = url_decode(self.mock_com.call_node.call_args[0][2])
self.assertTrue("data_json" in data)
self.assertEqual(
{
"config": {
"name": "cfg_name.conf",
"data": "cfg"
},
"authfile": {
"name": "my-key.key",
"data": to_b64("test key")
}
},
json.loads(data["data_json"][0])
)
assert_report_item_list_equal(
self.mock_rep.report_item_list,
[(
Severities.INFO,
report_codes.BOOTH_CONFIG_ACCEPTED_BY_NODE,
{
"node": self.node.label,
"name_list": ["cfg_name"]
}
)]
)

def _assert(self):
self.assertEqual(1, self.mock_com.call_node.call_count)
self.assertEqual(self.node, self.mock_com.call_node.call_args[0][0])
self.assertEqual(
"remote/booth_set_config", self.mock_com.call_node.call_args[0][1]
)
data = url_decode(self.mock_com.call_node.call_args[0][2])
self.assertTrue("data_json" in data)
self.assertEqual(
{
"config": {
"name": "cfg_name.conf",
"data": "cfg"
}
},
json.loads(data["data_json"][0])
)
assert_report_item_list_equal(
self.mock_rep.report_item_list,
[(
Severities.INFO,
report_codes.BOOTH_CONFIG_ACCEPTED_BY_NODE,
{
"node": self.node.label,
"name_list": ["cfg_name"]
}
)]
)

def test_authfile_data_None(self):
lib._set_config_on_node(
self.mock_com, self.mock_rep, self.node, "cfg_name", "cfg",
authfile="key.key"
)
self._assert()

def test_authfile_only_data(self):
lib._set_config_on_node(
self.mock_com, self.mock_rep, self.node, "cfg_name", "cfg",
authfile_data="key".encode("utf-8")
)
self._assert()

def test_without_authfile(self):
lib._set_config_on_node(
self.mock_com, self.mock_rep, self.node, "cfg_name", "cfg"
)
self._assert()

@skip("TODO: rewrite for pcs.lib.communication.booth.BoothSaveFiles")
@mock.patch("pcs.lib.booth.sync.parallel_nodes_communication_helper")
class SyncConfigInCluster(TestCase):
Expand Down Expand Up @@ -1046,52 +948,3 @@ def mock_parse_fn(config_data):
)
]
)

@skip("TODO: rewrite for pcs.lib.communication.booth.BoothGetConfig")
class PullConfigFromNodeTest(TestCase):
def setUp(self):
self.mock_communicator = mock.MagicMock(spec_set=NodeCommunicator)
self.node = NodeAddresses("node")

def test_success(self):
self.mock_communicator.call_node.return_value = "{}"
self.assertEqual(
{}, lib.pull_config_from_node(
self.mock_communicator, self.node, "booth"
)
)
self.mock_communicator.call_node.assert_called_once_with(
self.node, "remote/booth_get_config", "name=booth"
)

def test_not_json(self):
self.mock_communicator.call_node.return_value = "not json"
assert_raise_library_error(
lambda: lib.pull_config_from_node(
self.mock_communicator, self.node, "booth"
),
(
Severities.ERROR,
report_codes.INVALID_RESPONSE_FORMAT,
{"node": self.node.label}
)
)

def test_communication_failure(self):
self.mock_communicator.call_node.side_effect = NodeConnectionException(
self.node.label, "command", "reason"
)
assert_raise_library_error(
lambda: lib.pull_config_from_node(
self.mock_communicator, self.node, "booth"
),
(
Severities.ERROR,
report_codes.NODE_COMMUNICATION_ERROR_UNABLE_TO_CONNECT,
{
"node": self.node.label,
"command": "command",
"reason": "reason"
}
)
)
Loading

0 comments on commit 435a55f

Please sign in to comment.