Exemplo n.º 1
0
def test_filter_violate_with_invalid_filter():
    instance_0 = vmss_provider.provide_instance_real_sample()
    instance_1 = vmss_provider.provide_instance_real_sample()
    instance_1['instance_id'] = '1'

    instances = [instance_0, instance_1]
    input_filter = "sam 1"

    with pytest.raises(jmespath.exceptions.ParseError):
        kustolight.filter_resources(instances, input_filter)
Exemplo n.º 2
0
def test_filter_successful_one_instance():
    instance_0 = vmss_provider.provide_instance_real_sample()
    instance_1 = vmss_provider.provide_instance_real_sample()
    instance_1['instance_id'] = '1'

    instances = [instance_0, instance_1]
    input_filter = "where instance_id=='0'"

    result = kustolight.filter_resources(instances, input_filter)

    assert len(result) == 1
Exemplo n.º 3
0
def test_filter_successful_one_instance_with_where_clause_and_sample_operator(
):
    instance_0 = vmss_provider.provide_instance_real_sample()
    instance_1 = vmss_provider.provide_instance_real_sample()
    instance_1['instance_id'] = '1'

    instances = [instance_0, instance_1]
    input_filter = "where instance_id=='0' or instance_id=='1' | sample 1"

    result = kustolight.filter_resources(instances, input_filter)

    assert len(result) == 1
Exemplo n.º 4
0
def fetch_instances(vmss, instance_filter: str,
                    client: ComputeManagementClient) -> List[Dict[str, Any]]:
    if not instance_filter:
        instance_filter = "sample 1"

    try:
        instances = fetch_all_vmss_instances(vmss, client)
        result = kustolight.filter_resources(instances, instance_filter)
    except jmespath.exceptions.ParseError:
        raise InterruptExecution(
            "'{}' is an invalid query. Please have a look at the documentation."
            .format(instance_filter))

    return result