Esempio n. 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))
Esempio n. 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))
Esempio n. 3
0
 def test_another_name(self):
     self.assert_message_from_report(
         "Fetching booth config 'another' from node 'node1'...",
         reports.booth_fetching_config_from_node_started(
             "node1", config="another"
         )
     )
Esempio n. 4
0
def pull_config(env, node_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 = env.booth.name
    env.report_processor.process(
        booth_reports.booth_fetching_config_from_node_started(node_name, name))
    com_cmd = BoothGetConfig(env.report_processor, name)
    com_cmd.set_targets(
        [env.get_node_target_factory().get_target_from_hostname(node_name)])
    # pylint: disable=unsubscriptable-object
    # In general, pylint is right. And it cannot know in this case code is OK.
    # It is covered by tests.
    output = run_and_raise(env.get_node_communicator(), com_cmd)[0][1]
    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))
Esempio n. 5
0
def pull_config(env, node_name, instance_name=None):
    """
    Get config from specified node and save it on local system. It will
    rewrite existing files.

    LibraryEnvironment env
    string node_name -- name of the node from which the config should be fetched
    string instance_name -- booth instance name
    """
    report_processor = SimpleReportProcessor(env.report_processor)
    booth_env = env.get_booth_env(instance_name)
    instance_name = booth_env.instance_name
    _ensure_live_env(env, booth_env)

    env.report_processor.process(
        booth_reports.booth_fetching_config_from_node_started(
            node_name, instance_name))
    com_cmd = BoothGetConfig(env.report_processor, instance_name)
    com_cmd.set_targets(
        [env.get_node_target_factory().get_target_from_hostname(node_name)])
    # pylint: disable=unsubscriptable-object
    # In general, pylint is right. And it cannot know in this case code is OK.
    # It is covered by tests.
    output = run_and_raise(env.get_node_communicator(), com_cmd)[0][1]
    try:
        # TODO adapt to new file transfer framework once it is written
        if (output["authfile"]["name"] is not None
                and output["authfile"]["data"]):
            authfile_name = output["authfile"]["name"]
            report_list = config_validators.check_instance_name(authfile_name)
            if report_list:
                raise LibraryError(*report_list)
            booth_key = FileInstance.for_booth_key(authfile_name)
            booth_key.write_raw(base64.b64decode(
                output["authfile"]["data"].encode("utf-8")),
                                can_overwrite=True)
        booth_env.config.write_raw(output["config"]["data"].encode("utf-8"),
                                   can_overwrite=True)
        env.report_processor.process(
            booth_reports.booth_config_accepted_by_node(
                name_list=[instance_name]))
    except RawFileError as e:
        report_processor.report(raw_file_error_report(e))
    except KeyError:
        raise LibraryError(reports.invalid_response_format(node_name))
    if report_processor.has_errors:
        raise LibraryError()
Esempio n. 6
0
def pull_config(env, node_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 = env.booth.name
    env.report_processor.process(
        booth_reports.booth_fetching_config_from_node_started(node_name, name)
    )
    com_cmd = BoothGetConfig(env.report_processor, name)
    com_cmd.set_targets([
        env.get_node_target_factory().get_target_from_hostname(node_name)
    ])
    # pylint: disable=unsubscriptable-object
    # In general, pylint is right. And it cannot know in this case code is OK.
    # It is covered by tests.
    output = run_and_raise(env.get_node_communicator(), com_cmd)[0][1]
    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))
Esempio n. 7
0
 def test_another_name(self):
     self.assert_message_from_report(
         "Fetching booth config 'another' from node 'node1'...",
         reports.booth_fetching_config_from_node_started("node1",
                                                         config="another"))
Esempio n. 8
0
 def test_empty_name(self):
     self.assert_message_from_report(
         "Fetching booth config from node 'node1'...",
         reports.booth_fetching_config_from_node_started("node1"))
Esempio n. 9
0
 def test_empty_name(self):
     self.assert_message_from_report(
         "Fetching booth config from node 'node1'...",
         reports.booth_fetching_config_from_node_started("node1")
     )