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

salt.outputter.highstate: recursion for orch #46022

Merged
merged 3 commits into from
Apr 11, 2018

Conversation

mattp-
Copy link
Contributor

@mattp- mattp- commented Feb 14, 2018

What does this PR do?

orchestration / nested runners emitting to highstate were not rendered as
highstate like a normal state apply. With this change, recurse and indent
accordingly based on nested orchestrations.

Previous Behavior

nested orch / states were just rendered as raw data.

          ID: sleep 2
    Function: cmd.run
      Result: True
     Comment: Command "sleep 2" run
     Started: 15:33:47.059209
    Duration: 2022.743 ms
     Changes:
              ----------
              pid:
                  22643
              retcode:
                  0
              stderr:
              stdout:
----------
          ID: par2
    Function: salt.runner
        Name: state.orchestrate
      Result: True
     Comment: Runner function 'state.orchestrate' executed.
     Started: 15:33:49.084557
    Duration: 3026.912 ms
     Changes:
              ----------
              data:
                  ----------
                  saltlab-syndic02:
                      ----------
                      test_|-always-passes-with-any-kwarg_|-aaaa_|-nop:
                          ----------
                          __id__:
                              always-passes-with-any-kwarg
                          __run_num__:
                              0
                          __sls__:
                              orch.test.par2
                          changes:
                              ----------
                          comment:
                              Success!
                          duration:
                              0.881
                          name:
                              aaaa
                          result:
                              True
                          start_time:
                              15:33:52.090657
                      test_|-always-passes-with-changes_|-oinaosf_|-succeed_with_changes:
                          ----------
                          __id__:
                              always-passes-with-changes
                          __run_num__:
                              2
                          __sls__:
                              orch.test.par2
                          changes:
                              ----------
                              testing:
                                  ----------
                                  new:
                                      Something pretended to change
                                  old:
                                      Unchanged
                          comment:
                              Success!
                          duration:
                              0.853
                          name:
                              oinaosf
                          result:
                              True
                          start_time:
                              15:33:52.093029
                      test_|-always-passes_|-fasdfasddfasdfoo_|-succeed_without_changes:
                          ----------
                          __id__:
                              always-passes
                          __run_num__:
                              1
                          __sls__:
                              orch.test.par2
                          changes:
                              ----------
                          comment:
                              Success!
                          duration:
                              0.897
                          name:
                              fasdfasddfasdfoo
                          result:
                              True
                          start_time:
                              15:33:52.091850
              outputter:
                  highstate
              retcode:
                  0
----------
          ID: par4
    Function: salt.runner
        Name: test.arg
      Result: True
     Comment: Runner function 'test.arg' executed.
     Started: 15:33:52.111810
    Duration: 1444.039 ms
     Changes:
              ----------
              args:
                  - 1
                  - 2
              kwargs:
                  ----------

Summary for saltlab-syndic02
------------
Succeeded: 3 (changed=3)
Failed:    0
------------
Total states run:     3
Total run time:   6.494 s

New Behavior

orch/state output is now rendered as nested inner highstates:

local_master:
----------
          ID: sleep 2
    Function: cmd.run
      Result: True
     Comment: Command "sleep 2" run
     Started: 15:23:59.088329
    Duration: 5.811 ms
     Changes:
              ----------
              pid:
                  30087
              retcode:
                  0
              stderr:
              stdout:
 ----------
          ID: par2
    Function: salt.runner
        Name: state.orchestrate
      Result: True
     Comment: Runner function 'state.orchestrate' executed.
     Started: 15:24:01.115448
    Duration: 2.442 ms
     Changes:
              local_master:
              ----------
                        ID: always-passes-with-any-kwarg
                  Function: test.nop
                      Name: aaaa
                    Result: True
                   Comment: Success!
                   Started: 15:24:02.741617
                  Duration: 3.316 ms
                   Changes:
              ----------
                        ID: always-passes
                  Function: test.succeed_without_changes
                      Name: fasdfasddfasdfoo
                    Result: True
                   Comment: Success!
                   Started: 15:24:02.745295
                  Duration: 0.717 ms
                   Changes:
              ----------
                        ID: always-passes-with-changes
                  Function: test.succeed_with_changes
                      Name: oinaosf
                    Result: True
                   Comment: Success!
                   Started: 15:24:02.746166
                  Duration: 0.421 ms
                   Changes:
                            ----------
                            testing:
                                ----------
                                new:
                                    Something pretended to change
                                old:
                                    Unchanged

              Summary for local_master
              ------------
              Succeeded: 3 (changed=1)
              Failed:    0
              ------------
              Total states run:     3
              Total run time:   4.454 ms
----------
          ID: par4
    Function: salt.runner
        Name: test.arg
      Result: True
     Comment: Runner function 'test.arg' executed.
     Started: 15:24:01.118253
    Duration: 3.994 ms
     Changes:
              ----------
              return:
                  ----------
                  args:
                      - 1
                      - 2
                  kwargs:
                      ----------

Summary for local_master
------------
Succeeded: 3 (changed=3)
Failed:    0
------------
Total states run:     3
Total run time:  12.247 ms

Tests written?

No

Commits signed with GPG?

No

Please review Salt's Contributing Guide for best practices.

See GitHub's page on GPG signing for more information about signing commits with GPG.

@mattp- mattp- force-pushed the nested-orch-highstate branch from 6137184 to 3ed7b48 Compare February 14, 2018 19:28
@rallytime
Copy link
Contributor

@mattp- Thanks for submitting this! Offhand, there's a lint error here: https://jenkins.saltstack.com/job/PR/job/salt-pr-lint-n/19299/violations/file/salt/output/highstate.py/

Copy link
Contributor

@rallytime rallytime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests need to be written to make sure this change doesn't regress, too.

nchanges += 1 if schanged else 0
if ret.get('name') in ['state.orch', 'state.orchestrate', 'state.sls']:
nested = output(ret['changes']['return'], indent_level=indent_level+1)
ctext = re.sub('^',u' ' * 14 * indent_level, '\n'+nested, flags=re.MULTILINE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be using the u'' syntax here. That should be using salt.utils.stringutils.to_unicode instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah my bad, originally wrote this on a release branch pre Unicode change. Will update and add a regression test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattp- All good! Thank you :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The u is still there. Also, there need to be spaces after commas and between operators, or else the linter will complain.

I don't think we'll need to use salt.utils.stringutils.to_unicode() here, due to unicode_literals being imported. The nested variable should contain a unicode string because the output() function returns unicode strings.

@rallytime rallytime added the Needs-Testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases label Feb 15, 2018
@rallytime rallytime requested a review from a team February 15, 2018 19:36
Copy link
Contributor

@cachedout cachedout left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get tests written for this?

nchanges += 1 if schanged else 0
if ret.get('name') in ['state.orch', 'state.orchestrate', 'state.sls']:
nested = output(ret['changes']['return'], indent_level=indent_level+1)
ctext = re.sub('^',u' ' * 14 * indent_level, '\n'+nested, flags=re.MULTILINE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The u is still there. Also, there need to be spaces after commas and between operators, or else the linter will complain.

I don't think we'll need to use salt.utils.stringutils.to_unicode() here, due to unicode_literals being imported. The nested variable should contain a unicode string because the output() function returns unicode strings.

@mattp- mattp- force-pushed the nested-orch-highstate branch 4 times, most recently from d960c6a to 1556338 Compare March 26, 2018 13:36
@mattp-
Copy link
Contributor Author

mattp- commented Mar 26, 2018

@rallytime / @terminalmage I've added a regression test and updated to correct the lint errors. can you please take another gander? Thanks

Copy link
Contributor

@terminalmage terminalmage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is still a single lint issue that needs to be fixed. The ones in test_error.py are unrelated and already fixed upstream, if you rebase against the head of our develop branch after fixing the lint error I pointed out below, then it should get the lint check to pass.

'retcode': 0
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line needs to be removed to satisfy the linter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 186 in case the above comment is ambiguous.

@mattp- mattp- force-pushed the nested-orch-highstate branch 2 times, most recently from 1fec871 to 2928817 Compare March 29, 2018 17:03
@mattp-
Copy link
Contributor Author

mattp- commented Mar 30, 2018

Lint issues should now be resolved

@mattp- mattp- force-pushed the nested-orch-highstate branch 2 times, most recently from 8b4f76a to 6966347 Compare April 5, 2018 15:52
orchestration / nested runners emitting to highstate were not rendered as
highstate like a normal state apply. With this change, recurse and indent
accordingly based on nested orchestrations.
@mattp- mattp- force-pushed the nested-orch-highstate branch from 6966347 to 98cfa1f Compare April 5, 2018 15:55
@rallytime rallytime removed the Needs-Testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases label Apr 6, 2018
@cachedout cachedout merged commit 4e44fee into saltstack:develop Apr 11, 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.

4 participants