Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument schema of function stateful_set_update_strategy_tests got type ObjectSchema but expected type StringSchema #380

Open
whentojump opened this issue Apr 4, 2024 · 0 comments

Comments

@whentojump
Copy link
Member

How to reproduce

python3 -m acto --config data/percona-server-mongodb-operator/config.json --learn

It will crash with this log message:

CRITICAL, MainThread, error_handler.py:55, An exception occured: <class 'TypeError'>: Argument `schema` of function <function stateful_set_update_strategy_tests at 0x7f553ed792d0> got type <class 'acto.schema.object.ObjectSchema'> but expected type <class 'acto.schema.string.StringSchema'>.

Causes

  1. For this operator, updateStrategy is a string (not an object like in the native schema).

  2. At this stage of Acto code:

    # sort by priority
    generator_candidates.sort(key=lambda x: x.priority, reverse=True)
    if len(generator_candidates) > 0:
    test_cases.append(
    (schema.path, generator_candidates[0].func(schema)),
    )

    generator_candidates in fact has two elements: one is the exact match for updateStrategy; the second is for type String. But Acto only uses the first candidate with the highest priority and fails type check later here.

Possible solutions

The quoted code snippet seems to have certain design that allows a few alternative generators (e.g. it sorts the whole candidate list instead of directly picking up the max or min) but ends up with trying only one. Maybe we can add some try-except statement there.

To work around it in my 523 homework, I used the following

        if len(generator_candidates) > 0:
            if (schema.path == ['spec', 'updateStrategy']):
                test_cases.append(
                    (schema.path, generator_candidates[1].func(schema)),
                )
            else:
                test_cases.append(
                    (schema.path, generator_candidates[0].func(schema)),
                )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant