Skip to content

Fix output of show command for RunsOnClient#1217

Merged
joergsteffens merged 9 commits intomasterfrom
dev/joergs/master/show-runscript-fix
Aug 12, 2022
Merged

Fix output of show command for RunsOnClient#1217
joergsteffens merged 9 commits intomasterfrom
dev/joergs/master/show-runscript-fix

Conversation

@joergsteffens
Copy link
Member

@joergsteffens joergsteffens commented Aug 9, 2022

This change fixes the output of the show command for RunsOnClient.
Also implement show verbose for Runscripts
and execute Console Runscripts always on the Director, not the client.

OP#5211

Thank you for contributing to the Bareos Project!

Please check

  • Short description and the purpose of this PR is present above this paragraph
  • Your name is present in the AUTHORS file (optional)

If you have any questions or problems, please give a comment in the PR.

Helpful documentation and best practices

Checklist for the reviewer of the PR (will be processed by the Bareos team)

General
  • PR name is meaningful
  • Purpose of the PR is understood
  • Separate commit for this PR in the CHANGELOG.md, PR number referenced is same
  • Commit descriptions are understandable and well formatted
  • [ ] If backport: add original PR number and target branch at top of this file: Backport of PR#000 to bareos-2x
Source code quality
  • Source code changes are understandable
  • Variable and function names are meaningful
  • Code comments are correct (logically and spelling)
  • Required documentation changes are present and part of the PR
  • bareos-check-sources --since-merge does not report any problems
  • git status should not report modifications in the source tree after building and testing
Tests
  • Decision taken that a test is required (if not, then remove this paragraph)
  • The choice of the type of test (unit test or systemtest) is reasonable
  • Testname matches exactly what is being tested
  • On a fail, output of the test leads quickly to the origin of the fault

joergsteffens added a commit that referenced this pull request Aug 9, 2022
@joergsteffens joergsteffens marked this pull request as ready for review August 9, 2022 17:51
@bruno-at-bareos
Copy link
Contributor

Hello Joerg, I've made some additional tests and I would like to clear out the unclear state of where the job will be run in the following scenario.

If defined like

  # Update stats run them on server.
  RunScript {
    Console = "prune stats yes"
    Console = "update stats days=3"
    Console = ".bvfs_update"
    RunsWhen = After
    RunsOnClient = no
  }

With this PR It will output the following

  RunScript {
    Console = "prune stats yes"
    RunsWhen = "after"
    RunsOnClient = No
  }
  RunScript {
    Console = "update stats days=3"
    RunsWhen = "after"
    RunsOnClient = No
  }
  RunScript {
    Console = ".bvfs_update"
    RunsWhen = "after"
    RunsOnClient = No
  }

Which is what we decide is correct.

Now if we don't specify Where it run like

  # with no runsonclient
  RunScript {
    Console = "prune stats yes"
    Console = "update stats days=3"
    Console = ".bvfs_update"
    RunsWhen = After
  }

It shows

  RunScript {
    Console = "prune stats yes"
    RunsWhen = "after"
  }
  RunScript {
    Console = "update stats days=3"
    RunsWhen = "after"
  }
  RunScript {
    Console = ".bvfs_update"
    RunsWhen = "after"
  }

Which let undetermined if yes or no it will run on client, the operator can check the documentation and will find that by default RunOnClient = Yes.
If it is easy to agree that console command will never been run on client, it is more complicated to determine if a command will be yes or no RunOnClient = yes.
To explain a bit more the uncertain state we can use the following example with 1 Console and 1 Command:

  RunScript {
    Console = "prune stats yes"
    Command = "systemctl start tralala"
    RunsWhen = After
  }

The resulting show form look like:

  RunScript {
    Console = "update stats days=3"
    RunsWhen = "after"
  }
  RunScript {
    Command = "systemctl start tralala"
    RunsWhen = "after"
  }

Here we can eventually deduce that console will never be run on client.
But the last command is again undetermined and operator can't have an idea, without opening the text configuration file to see that the block is written in condensed form and maybe will not be executed on client.

@joergsteffens
Copy link
Member Author

The resulting show form look like:

  RunScript {
    Console = "update stats days=3"
    RunsWhen = "after"
  }
  RunScript {
    Command = "systemctl start tralala"
    RunsWhen = "after"
  }

Here we can eventually deduce that console will never be run on client. But the last command is again undetermined and operator can't have an idea, without opening the text configuration file to see that the block is written in condensed form and maybe will not be executed on client.

I even expect, that systemctl start tralala will be executed on the client, as the default of RunOnClient is yes.
Anyway, not printing the default value is the default behavior for all directives. It will be not consistent to only change this for the RunOnClient directive.
To let the show command also display the default value, there is the show verbose command. However, this is currently not working for Runscript sections. If you think, this is required, I can add that.

@bruno-at-bareos
Copy link
Contributor

bruno-at-bareos commented Aug 10, 2022

My concern is that for the moment any console or command if the RunOnClient = No is not specified are run on client and show verbose doesn't confirm that.

so yes we need to fix this. and maybe also fixing console to never be run on client (or there's a use case, that I'm not aware of?)

10-Aug 09:38 localhost-fd JobId 1: shell command: run ClientAfterJob "prune stats yes"
10-Aug 09:38 localhost-fd JobId 1: Error: Runscript: ClientAfterJob returned non-zero status=208. ERR=No such file or directory

log use shell command also for console command :-(

joergsteffens added a commit that referenced this pull request Aug 10, 2022
@joergsteffens joergsteffens force-pushed the dev/joergs/master/show-runscript-fix branch from 30caf30 to 5f13099 Compare August 10, 2022 14:24
@joergsteffens
Copy link
Member Author

@bruno-at-bareos I updated the PR to cover the problems you described.

Copy link
Contributor

@bruno-at-bareos bruno-at-bareos left a comment

Choose a reason for hiding this comment

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

Nice approach, I believe we cover all the case. There's just minor modification to still be included.

@joergsteffens
Copy link
Member Author

Now, it warns only once the misconfigured Runscript resource.

@bruno-at-bareos
Copy link
Contributor

bruno-at-bareos commented Aug 11, 2022

In my last manual testing I found that we emit a warning about console command without a RunOnClient=No.
As we change the behaviour (Console command will be always run on Dir) maybe we can disable this warning.
Here the configuration example to trigger the warning

  # Only Console command, no warning should be emitted
  RunScript {
    Console = "prune stats yes"
    Console = "update stats days=3"
    Console = ".bvfs_update"
    RunsWhen = After
  }

There are configuration warnings:

  • RunScripts with Console commands are not intended to run on clients. Setting 'RunOnClients' to 'no'. Please adapt the RunScript resource in config file /usr/local/etc/bareos/bareos-dir.d/job/BackupCatalog.conf ending in line 24.
  # Mixed command then the warning should be shown.
  RunScript {
    Console = "prune stats yes"
    Console = "update stats days=3"
    Command = "systemctl stop mysql"
    RunsWhen = After
  }

I'm asking for that because if operator now use the show command the RunOnClient = no is automatically added.

  RunScript {
    Console = "prune stats yes"
    RunsWhen = "after"
    RunsOnClient = No
  }
  RunScript {
    Console = "update stats days=3"
    RunsWhen = "after"
    RunsOnClient = No
  }
  RunScript {
    Console = ".bvfs_update"
    RunsWhen = "after"
    RunsOnClient = No
  }

What's your opinion on this ?

@joergsteffens
Copy link
Member Author

I intentionally added the warning, as the behavior is somehow changed now.
Before you could configure

RunScript {
    Console = "prune stats yes"
    RunsWhen = After
}

but as Bareos then tries to execute "prune stats yes" on the client as a shell script (this might work for some commands, that also exists in the OS or if you create /usr/local/bin/prune).
You had to configure it as

RunScript {
    Console = "prune stats yes"
    RunsWhen = After
    RunsOnClient = No
}

And this is still true, just that specifying a Console runscript implicietly sets RunsOnClient = No (even if you explicitly set it to Yes !).
This is not behavior we like to have, therefore we issue the Warning, so that the Administrator sets it to the correct value.

joergsteffens added a commit that referenced this pull request Aug 11, 2022
@joergsteffens joergsteffens force-pushed the dev/joergs/master/show-runscript-fix branch from fee2131 to 0173e48 Compare August 11, 2022 15:46
RunOnClient is only used for external commands,
not console commands.
Console commands are always executed on the Director.

Also some cleanup in the RunScript section.
@joergsteffens joergsteffens force-pushed the dev/joergs/master/show-runscript-fix branch from 0173e48 to 312312a Compare August 11, 2022 17:47
Copy link
Contributor

@bruno-at-bareos bruno-at-bareos left a comment

Choose a reason for hiding this comment

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

Nice revision and work. all the tests done look really great now.
I just let a comment about a "inherit" replacement if you want to fix it and maybe an enhancement for one test description.

Otherwise if build and tests are green, can be merged.

@joergsteffens joergsteffens merged commit 7b75861 into master Aug 12, 2022
@joergsteffens joergsteffens deleted the dev/joergs/master/show-runscript-fix branch August 12, 2022 06:13
bruno-at-bareos pushed a commit to bruno-at-bareos/bareos that referenced this pull request Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants