コード例 #1
0
def test_pcluster3_config_converter(test_datadir, tmpdir, expected_input,
                                    expected_output, mocker, warn, error,
                                    force_convert, capsys, cluster_label):
    mocker.patch(
        "pcluster3_config_converter.pcluster3_config_converter.Pcluster3ConfigConverter.get_region",
        return_value="us-west-1",
    )
    mocker.patch(
        "pcluster3_config_converter.pcluster3_config_converter._get_account_id",
        return_value="1234567",
    )
    converter = Pcluster3ConfigConverter(test_datadir / expected_input,
                                         cluster_label, tmpdir / "output_yaml",
                                         False, force_convert)
    try:
        converter.validate()
        converter.convert_to_pcluster3_config()
        converter.write_configuration_file()
        _assert_files_are_equal(
            tmpdir / "output_yaml",
            test_datadir / expected_output,
        )

    except SystemExit as e:
        print(e)
        assert_that(e.args[0]).contains(error)
    if warn:
        readouterr = capsys.readouterr()
        for message in warn:
            assert_that(readouterr.out).contains(message)
コード例 #2
0
def test_convert_region(test_case):
    user_input, expected_output = test_case[0], test_case[1]
    expected_output_data = yaml.safe_load(expected_output)
    converter = Pcluster3ConfigConverter(config_file=user_input,
                                         cluster_template="default",
                                         output_file="dummy_output",
                                         input_as_string=True)
    converter.convert_region("Region")
    assert_that(
        converter.pcluster3_configuration).is_equal_to(expected_output_data)
コード例 #3
0
def test_convert_shared_storage(test_case):
    user_input, expected_output = test_case[0], test_case[1]
    expected_output_data = yaml.safe_load(expected_output)
    converter = Pcluster3ConfigConverter(config_file=user_input,
                                         cluster_template="default",
                                         output_file="dummy_output",
                                         input_as_string=True)
    converter.validate_cluster_section_name()
    converter.convert_shared_storage("SharedStorage")
    assert_that(
        converter.pcluster3_configuration).is_equal_to(expected_output_data)
コード例 #4
0
def test_convert_tags(test_case):
    user_input, expected_output, error_message = test_case[0], test_case[
        1], test_case[2]
    expected_output_data = yaml.safe_load(expected_output)
    converter = Pcluster3ConfigConverter(config_file=user_input,
                                         cluster_template="default",
                                         output_file="dummy_output",
                                         input_as_string=True)
    converter.validate_cluster_section_name()
    try:
        converter.convert_tags("Tags")
        assert_that(converter.pcluster3_configuration).is_equal_to(
            expected_output_data)
    except SystemExit as e:
        assert_that(e.args[0]).contains(error_message)
コード例 #5
0
def test_convert_single_field(test_datadir, tmpdir, pcluster2_field, value,
                              pcluster3_field, method, error_message, caplog,
                              capsys):
    converter = Pcluster3ConfigConverter(config_file="dummy_input",
                                         cluster_template="default",
                                         output_file="dummy_output")
    converter.config_parser.read_dict(
        {"dummy-section": {
            pcluster2_field: value
        }})
    pcluster3_model = {}
    try:
        converter.convert_single_field("dummy-section", pcluster2_field,
                                       pcluster3_model, pcluster3_field,
                                       method)
        assert_that(pcluster3_model).is_equal_to({pcluster3_field: value})
    except SystemExit as e:
        assert_that(e.args[0]).contains(error_message)
コード例 #6
0
def test_convert_iam(test_case, mocker):
    mocker.patch(
        "pcluster3_config_converter.pcluster3_config_converter.Pcluster3ConfigConverter.get_region",
        return_value="us-west-1",
    )
    mocker.patch(
        "pcluster3_config_converter.pcluster3_config_converter._get_account_id",
        return_value="1234567",
    )
    user_input, expected_output = test_case[0], test_case[1]
    expected_output_data = yaml.safe_load(expected_output)
    converter = Pcluster3ConfigConverter(config_file=user_input,
                                         cluster_template="default",
                                         output_file="dummy_output",
                                         input_as_string=True)
    converter.validate_cluster_section_name()
    converter.convert_iam("Iam")
    assert_that(
        converter.pcluster3_configuration).is_equal_to(expected_output_data)
コード例 #7
0
def test_convert_scheduling(test_case, mocker):
    mocker.patch(
        "pcluster3_config_converter.pcluster3_config_converter.Pcluster3ConfigConverter.get_region",
        return_value="us-west-1",
    )
    mocker.patch(
        "pcluster3_config_converter.pcluster3_config_converter._get_account_id",
        return_value="1234567",
    )
    user_input, expected_output, warn = test_case[0], test_case[1], test_case[
        2]
    expected_output_data = yaml.safe_load(expected_output)
    converter = Pcluster3ConfigConverter(config_file=user_input,
                                         cluster_template="default",
                                         output_file="dummy_output",
                                         input_as_string=True)
    converter.validate_cluster_section_name()
    converter.validate_vpc_settings()
    converter.convert_scheduling("Scheduling")
    assert_that(
        converter.pcluster3_configuration).is_equal_to(expected_output_data)
    if warn:
        assert_that(converter.comments).contains(warn)