Ejemplo n.º 1
0
def test_get_config_file():
    c = get_config_file(None)
    assert c is None
    c = get_config_file(os.path.join(os.path.dirname(os.path.realpath(__file__)), "configs/good.config"))
    assert c is not None
    assert c.legacy_config is not None

    with pytest.raises(configparser.Error):
        get_config_file(os.path.join(os.path.dirname(os.path.realpath(__file__)), "configs/bad.config"))
Ejemplo n.º 2
0
def test_client_secret_location():
    cfg = get_config_file(
        os.path.join(os.path.dirname(os.path.realpath(__file__)),
                     "configs/sample.yaml"))
    secret_location = Credentials.CLIENT_CREDENTIALS_SECRET_LOCATION.read(cfg)
    assert secret_location is None

    cfg = get_config_file(
        os.path.join(os.path.dirname(os.path.realpath(__file__)),
                     "configs/creds_secret_location.yaml"))
    secret_location = Credentials.CLIENT_CREDENTIALS_SECRET_LOCATION.read(cfg)
    assert secret_location == "../tests/flytekit/unit/configuration/configs/fake_secret"
Ejemplo n.º 3
0
def test_command_2(mocked):
    mocked.environ.get.return_value = "a,b,c"
    cfg = get_config_file(
        os.path.join(os.path.dirname(os.path.realpath(__file__)),
                     "configs/good.config"))
    res = Credentials.COMMAND.read(cfg)
    assert res == ["a", "b", "c"]
Ejemplo n.º 4
0
def test_some_int(mocked):
    mocked.environ.get.side_effect = "5"
    cfg = get_config_file(
        os.path.join(os.path.dirname(os.path.realpath(__file__)),
                     "configs/good.config"))
    res = AWS.RETRIES.read(cfg)
    assert type(res) is int
    assert res == 5
Ejemplo n.º 5
0
def test_config_entry_file():
    # Pytest feature
    c = ConfigEntry(LegacyConfigEntry("platform", "url", str))
    assert c.read() is None

    cfg = get_config_file(os.path.join(os.path.dirname(os.path.realpath(__file__)), "configs/good.config"))
    assert c.read(cfg) == "fakeflyte.com"

    c = ConfigEntry(LegacyConfigEntry("platform", "url2", str))  # Does not exist
    assert c.read(cfg) is None
Ejemplo n.º 6
0
def test_config_entry_precedence():
    # Pytest feature
    c = ConfigEntry(LegacyConfigEntry("platform", "url", str))
    assert c.read() is None

    old_environ = dict(os.environ)
    os.environ["FLYTE_PLATFORM_URL"] = "xyz"
    cfg = get_config_file(os.path.join(os.path.dirname(os.path.realpath(__file__)), "configs/good.config"))
    assert c.read(cfg) == "xyz"
    # reset
    os.environ = old_environ
Ejemplo n.º 7
0
def test_config_entry_file():
    c = ConfigEntry(LegacyConfigEntry("platform", "url", str),
                    YamlConfigEntry("admin.endpoint"),
                    lambda x: x.replace("dns:///", ""))
    assert c.read() is None

    cfg = get_config_file(
        os.path.join(os.path.dirname(os.path.realpath(__file__)),
                     "configs/sample.yaml"))
    assert c.read(cfg) == "flyte.mycorp.io"

    c = ConfigEntry(LegacyConfigEntry("platform", "url2",
                                      str))  # Does not exist
    assert c.read(cfg) is None
Ejemplo n.º 8
0
def test_config_entry_file_2(mock_get):
    # Test reading of the environment variable that flytectl asks users to set.
    # Can take both extensions
    sample_yaml_file_name = os.path.join(
        os.path.dirname(os.path.realpath(__file__)), "configs/sample.yml")

    mock_get.return_value = sample_yaml_file_name

    c = ConfigEntry(LegacyConfigEntry("platform", "url", str),
                    YamlConfigEntry("admin.endpoint"),
                    lambda x: x.replace("dns:///", ""))
    assert c.read() is None

    cfg = get_config_file(sample_yaml_file_name)
    assert c.read(cfg) == "flyte.mycorp.io"

    c = ConfigEntry(LegacyConfigEntry("platform", "url2",
                                      str))  # Does not exist
    assert c.read(cfg) is None
Ejemplo n.º 9
0
def test_config_entry_types():
    cfg = get_config_file(os.path.join(os.path.dirname(os.path.realpath(__file__)), "configs/good.config"))

    l = ConfigEntry(LegacyConfigEntry("sdk", "workflow_packages", list))
    assert l.read(cfg) == ["this.module", "that.module"]

    s = ConfigEntry(LegacyConfigEntry("madeup", "string_value"))
    assert s.read(cfg) == "abc"

    i = ConfigEntry(LegacyConfigEntry("madeup", "int_value", int))
    assert i.read(cfg) == 3

    b = ConfigEntry(LegacyConfigEntry("madeup", "bool_value", bool))
    assert b.read(cfg) is False

    t = ConfigEntry(
        LegacyConfigEntry("madeup", "timedelta_value", datetime.timedelta),
        transform=lambda x: datetime.timedelta(seconds=timeparse(x)),
    )
    assert t.read(cfg) == datetime.timedelta(hours=20)
Ejemplo n.º 10
0
def test_real_config():
    config_file = get_config_file(
        os.path.join(os.path.dirname(os.path.realpath(__file__)),
                     "configs/sample.yaml"))
    res = Platform.INSECURE.read(config_file)
    assert res

    res = Platform.URL.read(config_file)
    assert res == "flyte.mycorp.io"

    res = AWS.S3_ACCESS_KEY_ID.read(config_file)
    assert res == "minio"

    res = AWS.S3_ENDPOINT.read(config_file)
    assert res == "http://localhost:30084"

    res = AWS.S3_SECRET_ACCESS_KEY.read(config_file)
    assert res == "miniostorage"

    res = Credentials.SCOPES.read(config_file)
    assert res == ["all"]
Ejemplo n.º 11
0
def test_load_images():
    cfg = get_config_file(
        os.path.join(os.path.dirname(os.path.realpath(__file__)),
                     "configs/images.config"))
    imgs = Images.get_specified_images(cfg)
    assert imgs == {"abc": "docker.io/abc", "xyz": "docker.io/xyz:latest"}
Ejemplo n.º 12
0
def test_command():
    cfg = get_config_file(
        os.path.join(os.path.dirname(os.path.realpath(__file__)),
                     "configs/good.config"))
    res = Credentials.COMMAND.read(cfg)
    assert res == ["aws", "sso", "get-token"]
Ejemplo n.º 13
0
def test_no_images():
    cfg = get_config_file(
        os.path.join(os.path.dirname(os.path.realpath(__file__)),
                     "configs/good.config"))
    imgs = Images.get_specified_images(cfg)
    assert imgs == {}