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

pass arguments as JSON array to process probe #34

Merged
merged 4 commits into from
Feb 19, 2018

Conversation

twuyts
Copy link
Contributor

@twuyts twuyts commented Feb 14, 2018

This PR allows for more freedom in passing arguments to a process probe.
For example: when running a docker container, it is possible to pass in environment variables through
the -e cmdline option. If you need to add more than one option, you just add multiple -e arguments. I have a few simple docker containers that implement a probe, but configuring multiple -e arguments in the experiment JSON to the container is not possible in a JSON object.

By also allowing the arguments object in the probe configuration to be an array, you can pass any argument you like, without being confined to the option:value structure. See ProcEchoArrayProbe in tests/probes.py for an example.

@Lawouach
Copy link
Contributor

Awesome idea and work @twuyts!

While I review it, would you be kind enough to sign your commit so the DCO check is happy? :)

Signed-off-by: Tim Wuyts <tim.wuyts@gmail.com>
Signed-off-by: Tim Wuyts <tim.wuyts@gmail.com>
Signed-off-by: Tim Wuyts <tim.wuyts@gmail.com>
@twuyts
Copy link
Contributor Author

twuyts commented Feb 14, 2018

DCO and whitespace stuff is fixed, but I seem to have a failed test in Python 3.5. I've only tested in 3.6. I'll have a quick look.

@twuyts
Copy link
Contributor Author

twuyts commented Feb 14, 2018

It's a problem with the way Python handles dicts. Apparently it has changed from 3.5 -> 3.6
see this post on StackOverflow

The official description of the change is mentioned here

This means that my test that checks if the arguments were passed correctly will fail most of the times when using a JSON object (vs array). Passing them as an array will pass the arguments in the given order, though.

I will remove the failing test, as I don't see a way to do this correctly.

Signed-off-by: Tim Wuyts <tim.wuyts@gmail.com>
@Lawouach
Copy link
Contributor

Dict are ordered (insertion that is) ordered now indeed. Could we use an OrderedDict when using python 3.5-?

@twuyts
Copy link
Contributor Author

twuyts commented Feb 14, 2018

I assume we could.

def load_experiment(path: str) -> Experiment:
    """
    Parse the given experiment from `path` and return it.
    """
    with io.open(path) as f:
        if (sys.version_info >= (3,6)):
            return json.load(f)
        else:
            return json.load(f, object_pairs_hook=OrderedDict)

That would make an OrderedDict of the complete experiment object.
I'm not too confident about this: there doesn't seem to be a single test that actually loads an experiment from a file, so I'm not sure if there aren't any unintended side-effects.

What do you propose?

@Lawouach
Copy link
Contributor

That's actually an interesting idea, I didn't know the json interface allowed for this kind of possibility. I will toy around (and indeed write a test would be a good idea).

How urgent is this for you to be merged? I might need until Friday to get that done, is that okay?

@twuyts
Copy link
Contributor Author

twuyts commented Feb 14, 2018

That's fine, thanks!

@Lawouach
Copy link
Contributor

I have worked on this PR yesterday but couldn't find the right way to make that test pass either yet. I think it should be the case so I'll continue on that next week :)

@Lawouach
Copy link
Contributor

While trying to find a way to make it work, I realised we shouldn't actually assume order at all when using a dict-based arguments sequence.

Basically, we should document that if the ordering of arguments is mandatory, then the list approach must be used. When ordering is meaningless, either ones should be used (in fact, we could even deprecate the dict approach).

what do you think?

@twuyts
Copy link
Contributor Author

twuyts commented Feb 19, 2018 via email

@Lawouach
Copy link
Contributor

Sounds appropriate yeah. I think I can merge your PR as-is and I will add the deprecation warning for the dict approach afterwards.

@Lawouach Lawouach merged commit 65ec0a9 into chaostoolkit:master Feb 19, 2018
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

Successfully merging this pull request may close these issues.

2 participants