Exemple #1
0
 def raiser(_, node):
     if node == self.node_list[1]:
         raise NodeConnectionException(self.node_list[1], "command",
                                       "reason")
     elif node == self.node_list[4]:
         raise NodeCommunicationException(self.node_list[4], "command",
                                          "reason")
Exemple #2
0
 def report_item_generator(i):
     if i == 1:
         raise NodeConnectionException("node", "command", "reason")
     elif i == 2:
         raise LibraryError(
             ReportItem.error(report_codes.COMMON_ERROR, ),
             ReportItem.info(report_codes.COMMON_INFO, ))
Exemple #3
0
 def test_communication_failure(self, mock_read_authfile, mock_read_configs,
                                mock_parse, mock_authfile):
     mock_parse.side_effect = self.mock_parse_fn
     mock_authfile.side_effect = self.mock_authfile_fn
     mock_read_authfile.side_effect = self.mock_read_authfile_fn
     mock_read_configs.return_value = {
         "name1.conf": "config1",
         "name2.conf": "config2"
     }
     self.mock_communicator.call_node.side_effect = NodeConnectionException(
         self.node.label, "command", "reason")
     assert_raise_library_error(
         lambda: lib.send_all_config_to_node(self.mock_communicator, self.
                                             mock_reporter, self.node),
         (Severities.ERROR,
          report_codes.NODE_COMMUNICATION_ERROR_UNABLE_TO_CONNECT, {
              "node": self.node.label,
              "command": "command",
              "reason": "reason"
          }))
     self.assertEqual(2, mock_parse.call_count)
     mock_parse.assert_has_calls(
         [mock.call("config1"), mock.call("config2")])
     self.assertEqual(2, mock_authfile.call_count)
     mock_authfile.assert_has_calls(
         [mock.call("config1"), mock.call("config2")])
     self.assertEqual(2, mock_read_authfile.call_count)
     mock_read_authfile.assert_has_calls([
         mock.call(self.mock_reporter, "/path/to/file1.key"),
         mock.call(self.mock_reporter, "/path/to/file2.key")
     ])
     mock_read_configs.assert_called_once_with(self.mock_reporter, False)
     self.assertEqual(1, self.mock_communicator.call_node.call_count)
     self.assertEqual(self.node,
                      self.mock_communicator.call_node.call_args[0][0])
     self.assertEqual("remote/booth_save_files",
                      self.mock_communicator.call_node.call_args[0][1])
     data = url_decode(self.mock_communicator.call_node.call_args[0][2])
     self.assertFalse("rewrite_existing" in data)
     self.assertTrue("data_json" in data)
     self.assertEqual([{
         "name": "name1.conf",
         "data": "config1",
         "is_authfile": False
     }, {
         "name": "file1.key",
         "data": to_b64("some key"),
         "is_authfile": True
     }, {
         "name": "name2.conf",
         "data": "config2",
         "is_authfile": False
     }, {
         "name": "file2.key",
         "data": to_b64("another key"),
         "is_authfile": True
     }], json.loads(data["data_json"][0]))
Exemple #4
0
 def test_unable_to_connect(self, mock_check_sbd):
     mock_check_sbd.side_effect = NodeConnectionException(
         self.node.label, "command", "reason")
     self.assertRaises(
         NodeCommunicationException, lambda: lib_sbd.check_sbd_on_node(
             self.mock_rep, self.mock_com, self.node, "watchdog"))
     mock_check_sbd.assert_called_once_with(self.mock_com, self.node,
                                            "watchdog")
     self.assertEqual(0, len(self.mock_rep.report_item_list))
Exemple #5
0
 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"
          }))
        def ret_val(communicator, node):
            self.assertEqual(communicator, self.mock_com)
            if node.label == "node0":
                return """\
            # comment
            SBD_TEST=true
            ANOTHER_OPT=1
            """
            elif node.label == "node1":
                return """\
invalid value

            """
            elif node.label == "node2":
                raise NodeConnectionException(node.label, "command", "reason")
            else:
                raise AssertionError(
                    "Unexpected call: node={node}, node.label={label}".format(
                        node=str(node), label=node.label))
 def ret_val(communicator, node, empty_str):
     self.assertEqual(communicator, self.mock_com)
     self.assertEqual(empty_str, "")
     if node.label == "node0":
         return """{
             "not_sbd": {
                 "installed": true,
                 "enabled": true,
                 "running": false
             }
         }"""
     elif node.label == "node1":
         raise NodeConnectionException(node.label, "command", "reason")
     elif node.label == "node2":
         return "invalid_json"
     else:
         raise AssertionError(
             "Unexpected call: node={node}, node.label={label}".format(
                 node=str(node), label=node.label))