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

skipped failed hosts #2

Open
dbarrosop opened this issue Jun 3, 2019 · 4 comments
Open

skipped failed hosts #2

dbarrosop opened this issue Jun 3, 2019 · 4 comments
Labels
core documentation Improvements or additions to documentation

Comments

@dbarrosop
Copy link
Contributor

dbarrosop commented Jun 3, 2019

runners should skip failed hosts unless stated otherwise

@dbarrosop dbarrosop changed the title Feature parity with nornir skipped failed hosts Jun 3, 2019
@nleiva
Copy link
Collaborator

nleiva commented Jun 3, 2019

What is a failed host?. One that you couldn't connect to?

I can add a timeout to:

if err := session.Run(r.Command); err != nil {
	result.SetErr(errors.Wrap(err, "failed to execute command"))
	jobResult <- result
	return
}

@dbarrosop
Copy link
Contributor Author

dbarrosop commented Jun 4, 2019

A failed host is basically whatever the host determines that was a failure. Some things are obvious like a connection failed to establish or something like that but you could do your own thing, for instance:

var AssertionFailed error = errors.New("assertion failed")

type VerifyPreconditionsTask struct {
}

func (t *VerifyPreconditionsTask) Run(...) {
   // here we could do some asserts against a device or something
   if preConditionFailed {
       result.SetErr(AssertionFailed)  // SetErr will also store the error in the host
       jobResult <- result
   }
}

Now, as a user in your main code you could do:

gr.RunS(
   "let's test our devices meet preconditions",
   &VerifyPreconditionsTask{},
)

// Now we could filter out the devices
func okHosts(host *Host, gr *Gornir) bool {
   return host.Err() == nil
}
gr.RunS.Filter(okHosts).RunS(
  "do more stuff",
   ...
)

// Or maybe we want to do something on the hosts that failed the precondition
func hostsThatPassedPrecondition(host *Host, gr *Gornir) bool {
   return host.Err() == AssertionFailed
}
gr.RunS.Filter(hostsThatPassedPrecondition).RunS(
  "we need to do something on the hosts that failed the assertions",
   ...
)

Actually, I think this is a good enough interface without any attached magic so maybe there is nothing to do here. Maybe just write a working example.

Does this make sense?

@nleiva
Copy link
Collaborator

nleiva commented Jun 4, 2019

It does. I can envision running a pre-check to check the operating system version of a host, or a given capability, before sending the task. Thanks.

@dbarrosop
Copy link
Contributor Author

Awesome, I am going to keep it open to remind us to add an example. Eventually I'd like to also use a "golden file pattern" for testing the examples.

@dbarrosop dbarrosop added core documentation Improvements or additions to documentation labels Jun 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants