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

Commands are not executed in the order they defined #455

Closed
Mad-ness opened this issue Jun 6, 2019 · 9 comments
Closed

Commands are not executed in the order they defined #455

Mad-ness opened this issue Jun 6, 2019 · 9 comments

Comments

@Mad-ness
Copy link

Mad-ness commented Jun 6, 2019

Hi,

I've two ideas.

  1. I'd like to define multiple commands in goss.yml and I expect they are being run in the same order as they go in the file. But they do not run in the same order, sometimes they do. It looks like they run randomly.
    Example of commands:
  • mount a NFS share
  • check permissions
  • unmount the share.

It would be great if it possible to define either order of execution (maybe add an option "priority") or just follow the order the commands are defined in goss.yml.

  1. I feel a big inconvenience in running multiple commands using "command" test. It would be awesome to have a test called script where I can specify a code of a multiline script. This might look like this:
script:
  myscript:
    body: |
      #!/bin/bash, #!/usr/bin/env python, #!/usr/bin/awk, #!/usr/bin/sed, etc
      as many as need shell/python/awk/etc commands or other script language instructions
      on many lines
   exit-status: 
   stdout: []
  ... etc ...

I know I can put needed scripts on a target host/image and execute it using command but the powerfull side of Goss is a simplicity. I wouldn't like to split a simple configuration into multiple pieces.

Thanks,
Dmitrii

@sshipway
Copy link
Contributor

This is related to my #485 feature request, to add before/after attributes to tests to enforce ordering

Normally all tests run in parallel...

@aelsabbahy
Copy link
Member

  1. Tests being independent allows for a lot of flexibility for execution order and in my opinion improves predictability. Ordering is not something I want to add to goss.

  2. The PR that @sshipway introduced a while back will allow some limited support for the simple use-case you want, example:

command:
  python_example:
    exec: |
      python3 << EOF
      import sys
      print('example output')
      for i in range(3):
        print(i)
      sys.exit(15)
      EOF
    stdout:
      - 'example'
      - '0'
      - '1'
      - '2'
    exit-status: 15
    timeout: 10000
goss v
..

Total Duration: 0.031s
Count: 2, Failed: 0, Skipped: 0

I know it's not the most ideal syntax, but.. putting code in yaml is less than ideal.

That said, in its current state it butchers the output when using more verbose formatters. I have a PR open #495 but will wait on @sshipway to understand the rationale behind the original change better.

@Mad-ness Does this meet your needs?

@sshipway
Copy link
Contributor

The original change moved the command from the Key to the exec attribute, leaving the Key to just be a symbol. For backwards compatibility, the Key would be used as the command if no exec attribute existed. The ide behind this was to make the yaml clearer, but mosty to allow a deep merge (such as if the config were managed by a tool like Puppet) to override just the command but leave the other items the same.

In order to keep the logs as similar as possible, the ID function was modified to output the exec attribute as well as the key, if it exists (otherwise it would be just the key which would conceal the command to run). However, I did not consider that someone could now put a whole script into the exec attribute, which would make the log display look wrong.

I like the idea of putting a script into the exec parameter, but if you're doing this, then for readability you would probably want to change the ID function (IE, the logging prefix) to output only the Key value, regardless of if an exec attribute exists or not.

@Mad-ness
Copy link
Author

  1. Tests being independent allows for a lot of flexibility for execution order and in my opinion improves predictability. Ordering is not something I want to add to goss.
  2. The PR that @sshipway introduced a while back will allow some limited support for the simple use-case you want, example:
command:
  python_example:
    exec: |
      python3 << EOF
      import sys
      print('example output')
      for i in range(3):
        print(i)
      sys.exit(15)
      EOF
    stdout:
      - 'example'
      - '0'
      - '1'
      - '2'
    exit-status: 15
    timeout: 10000
goss v
..

Total Duration: 0.031s
Count: 2, Failed: 0, Skipped: 0

I know it's not the most ideal syntax, but.. putting code in yaml is less than ideal.

That said, in its current state it butchers the output when using more verbose formatters. I have a PR open #495 but will wait on @sshipway to understand the rationale behind the original change better.

@Mad-ness Does this meet your needs?

'exec' with different 'key' values solves the issue with putting multiline commands in goss files. Of course, tens of lines of scripts in yaml files will not add readability but this is a prefect feature when you need to execute only a few commands.

Thank you

@aelsabbahy
Copy link
Member

Awesome, let me know if it's okay to close this issue.

The cleaner output has been merged in #495 and will be in the next Goss release

@milind69
Copy link

milind69 commented Nov 18, 2019 via email

@aelsabbahy
Copy link
Member

I'll have it out sometime this week assuming the open PRs don't cause any issues when merged

@aelsabbahy
Copy link
Member

Sorry schedule slipped a little bit on the release, should have the release out tomorrow.

Hoping to have the http header (request/response) support in this goss release.

@aelsabbahy
Copy link
Member

@milind69 Just released a new version with the command ID change

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

4 participants