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

Add conditional execution (similar to jsonpatch test) #17

Open
gberche-orange opened this issue Aug 1, 2018 · 2 comments
Open

Add conditional execution (similar to jsonpatch test) #17

gberche-orange opened this issue Aug 1, 2018 · 2 comments

Comments

@gberche-orange
Copy link

It is sometimes useful to conditionally execute bosh operators (in addition to the ? refer to hash keys that may or may not exist) depending on the presence of key/value in the manifest.

This issue suggests to implement a support similar to the json patch test syntax

{ "op": "test", "path": "/best_biscuit/name", "value": "Choco Leibniz" }
Tests that the specified value is set in the document. If the test fails, then the patch as a whole should not apply.

This would enable bosh operators to check their prereqs explicitly, and be ignored if preqs are not met.

/CC @voelzmo

Here is a related specific use-case (for a bosh-based on demand service broker similar to cppforlife/bosh-generic-sb-release): orange-cloudfoundry/cf-ops-automation-broker#30

@voelzmo
Copy link

voelzmo commented Jan 11, 2019

@gberche-orange is this what you were asking for? https://github.com/cppforlife/go-patch/blob/master/patch/integration_test.go#L50-L74

seems like @cppforlife added this recently without telling anyone ;)

@gberche-orange
Copy link
Author

gberche-orange commented Jan 11, 2019

yes this seems close to what I had in mind :-) thanks @voelzmo @cppforlife

It seems to support precondition and post conditions and fail if not met with a default error message:

Expects a specific value for a path. Fails otherwise with default error message.

- type: test
  path: /instance_groups/name=uaa/instances
  value: 0

Expects no value for a path. Fails otherwise with default error message

- type: test
  path: /instance_groups/name=uaa/instances-not
  absent: true

A possible extension would be something like the following to support skipping the current ops file (an any previously applied mutations) when a test fail, and proceed to other ops files specific to the bosh cli.

Expects a specific value for a path. Skip current ops file with a warning when unmet

- type: test
  path: /instance_groups/name=uaa/instances
  value: 0
  on_violations: skip_ops_file
  message: "my custom message: prereq X not met, skipping feature Y" 

Expects a specific value for a path. When unmet, fail the whole bosh int command and display a custom message

- type: test
  path: /instance_groups/name=uaa/instances
  value: 0
  on_violations: fail
  message: "my custom message: prereq X not met, please fix config" 

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

2 participants