Exemplo n.º 1
0
def config_setup(
    env: LibraryEnvironment,
    site_list,
    arbitrator_list,
    instance_name=None,
    overwrite_existing=False,
):
    """
    create booth configuration

    env
    list site_list -- site adresses of multisite
    list arbitrator_list -- arbitrator adresses of multisite
    string instance_name -- booth instance name
    bool overwrite_existing -- allow overwriting existing files
    """
    instance_name = instance_name or constants.DEFAULT_INSTANCE_NAME
    report_processor = env.report_processor

    report_processor.report_list(
        config_validators.check_instance_name(instance_name)
    )
    report_processor.report_list(
        config_validators.create(site_list, arbitrator_list)
    )
    if report_processor.has_errors:
        raise LibraryError()

    booth_env = env.get_booth_env(instance_name)

    booth_conf = booth_env.create_facade(site_list, arbitrator_list)
    booth_conf.set_authfile(booth_env.key_path)

    try:
        booth_env.key.write_raw(
            tools.generate_binary_key(
                random_bytes_count=settings.booth_authkey_bytes
            ),
            can_overwrite=overwrite_existing,
        )
        booth_env.config.write_facade(
            booth_conf, can_overwrite=overwrite_existing
        )
    except FileAlreadyExists as e:
        report_processor.report(
            ReportItem(
                severity=reports.item.get_severity(
                    reports.codes.FORCE,
                    overwrite_existing,
                ),
                message=reports.messages.FileAlreadyExists(
                    e.metadata.file_type_code,
                    e.metadata.path,
                ),
            )
        )
    except RawFileError as e:
        report_processor.report(raw_file_error_report(e))
    if report_processor.has_errors:
        raise LibraryError()
Exemplo n.º 2
0
 def test_no_reports_on_correct_args(self):
     assert_report_item_list_equal(
         config_validators.create(
             ["1.1.1.1", "2.2.2.2"],
             ["3.3.3.3"]
         ),
         []
     )
Exemplo n.º 3
0
 def test_refuse_even_number_peers(self):
     assert_report_item_list_equal(
         config_validators.create(["1.1.1.1", "2.2.2.2"], []),
         [
             fixture.error(
                 report_codes.BOOTH_EVEN_PEERS_NUM,
                 number=2,
             ),
         ],
     )
Exemplo n.º 4
0
 def test_refuse_less_than_2_sites(self):
     assert_report_item_list_equal(
         config_validators.create(["1.1.1.1"], ["3.3.3.3", "4.4.4.4"]),
         [
             fixture.error(
                 report_codes.BOOTH_LACK_OF_SITES,
                 sites=["1.1.1.1"],
             ),
         ],
     )
Exemplo n.º 5
0
 def test_refuse_address_duplication(self):
     assert_report_item_list_equal(
         config_validators.create(["1.1.1.1", "1.1.1.1", "1.1.1.1"],
                                  ["3.3.3.3", "4.4.4.4"]),
         [
             fixture.error(
                 report_codes.BOOTH_ADDRESS_DUPLICATION,
                 duplicate_addresses=["1.1.1.1"],
             ),
         ],
     )
Exemplo n.º 6
0
 def test_refuse_problem_combination(self):
     assert_report_item_list_equal(
         config_validators.create(["1.1.1.1"], ["1.1.1.1"]),
         [
             fixture.error(
                 report_codes.BOOTH_LACK_OF_SITES,
                 sites=["1.1.1.1"],
             ),
             fixture.error(
                 report_codes.BOOTH_EVEN_PEERS_NUM,
                 number=2,
             ),
             fixture.error(
                 report_codes.BOOTH_ADDRESS_DUPLICATION,
                 duplicate_addresses=["1.1.1.1"],
             ),
         ],
     )