Пример #1
0
def pull_config(env, node_name, name):
    """
    Get config from specified node and save it on local system. It will
    rewrite existing files.

    env -- LibraryEnvironment
    node_name -- string, name of node from which config should be fetched
    name -- string, name of booth instance of which config should be fetched
    """
    env.report_processor.process(
        booth_reports.booth_fetching_config_from_node_started(node_name, name))
    output = sync.pull_config_from_node(env.node_communicator(),
                                        NodeAddresses(node_name), name)
    try:
        env.booth.create_config(output["config"]["data"], True)
        if (output["authfile"]["name"] is not None
                and output["authfile"]["data"]):
            env.booth.set_key_path(
                os.path.join(settings.booth_config_dir,
                             output["authfile"]["name"]))
            env.booth.create_key(
                base64.b64decode(output["authfile"]["data"].encode("utf-8")),
                True)
        env.report_processor.process(
            booth_reports.booth_config_accepted_by_node(name_list=[name]))
    except KeyError:
        raise LibraryError(reports.invalid_response_format(node_name))
Пример #2
0
def pull_config(env, node_name, name):
    """
    Get config from specified node and save it on local system. It will
    rewrite existing files.

    env -- LibraryEnvironment
    node_name -- string, name of node from which config should be fetched
    name -- string, name of booth instance of which config should be fetched
    """
    env.report_processor.process(
        booth_reports.booth_fetching_config_from_node_started(node_name, name)
    )
    output = sync.pull_config_from_node(
        env.node_communicator(), NodeAddresses(node_name), name
    )
    try:
        env.booth.create_config(output["config"]["data"], True)
        if (
            output["authfile"]["name"] is not None and
            output["authfile"]["data"]
        ):
            env.booth.set_key_path(os.path.join(
                settings.booth_config_dir, output["authfile"]["name"]
            ))
            env.booth.create_key(
                base64.b64decode(
                    output["authfile"]["data"].encode("utf-8")
                ),
                True
            )
        env.report_processor.process(
            booth_reports.booth_config_accepted_by_node(name_list=[name])
        )
    except KeyError:
        raise LibraryError(reports.invalid_response_format(node_name))
Пример #3
0
 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")
Пример #4
0
 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
         }))
Пример #5
0
 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"
     )
Пример #6
0
 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}
         )
     )
Пример #7
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"
          }))
Пример #8
0
def config_text(env, name, node_name=None):
    """
    get configuration in raw format
    string name -- name of booth instance whose config should be returned
    string node_name -- get the config from specified node or local host if None
    """
    if node_name is None:
        # TODO add name support
        return env.booth.get_config_content()

    remote_data = sync.pull_config_from_node(env.node_communicator(),
                                             NodeAddresses(node_name), name)
    try:
        return remote_data["config"]["data"]
    except KeyError:
        raise LibraryError(reports.invalid_response_format(node_name))
Пример #9
0
def config_text(env, name, node_name=None):
    """
    get configuration in raw format
    string name -- name of booth instance whose config should be returned
    string node_name -- get the config from specified node or local host if None
    """
    if node_name is None:
        # TODO add name support
        return env.booth.get_config_content()

    remote_data = sync.pull_config_from_node(
        env.node_communicator(), NodeAddresses(node_name), name
    )
    try:
        return remote_data["config"]["data"]
    except KeyError:
        raise LibraryError(reports.invalid_response_format(node_name))
Пример #10
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"
             }
         )
     )