Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

fleetctl: {load|unload|start|stop} and get unit code cleanups #1433

Merged
merged 8 commits into from
Mar 8, 2016

Conversation

tixxdz
Copy link
Contributor

@tixxdz tixxdz commented Feb 16, 2016

This patches set aims to make the code more consistent and robust. It does not change the current behaviour just improves the code, consolidate it, more debug logs and code comments.

The main goal is to let stop, start, load and unload to share the same code base and probably avoid any corner case or bug that may related to one of these commands.

@@ -482,6 +482,36 @@ func getChecker() *ssh.HostKeyChecker {
return ssh.NewHostKeyChecker(keyFile)
}

func getUnit(file string) (*unit.UnitFile, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

getUnitFile

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@tixxdz tixxdz force-pushed the tixxdz/fleet-code-cleaning-v1+1 branch from c181aad to de05a8d Compare February 17, 2016 11:59
@tixxdz
Copy link
Contributor Author

tixxdz commented Feb 17, 2016

PR updated, thanks

// returned then try up to that value
func getBlockAttempts() int {
// By default we wait forever
var attempts int = -1
Copy link
Contributor

Choose a reason for hiding this comment

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

Where do you do anything with this being set to -1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I set it to negative value to not set it to zero, this way I can return immediately here endocode@75b6088#diff-197bb752bf0f52567eb6b0023ea65e40R782

And lalso to allow us to continue with the previous logic inside "waitForUnitStates()" 0 or any negative value. I didn't touch "waitForUnitStates()" since it's used in some other parts of the code, so I only converted new calls keeping the same semantics from a user experience. Yes the problem is we have two values inside the code blockattempts and noblock that interfere which other that's why I think we should convert this into one value that allows us to be more consistent in each part of the code. Perhaps later other parts can be converted too, but now I only changed fleetctl commands.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was just a bit confused about the inconsistency between BlockAttempts=0 on the command line referring to waiting forever, but getBlockAttempts() returning -1 to indicate the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

i.e. implicitly relying on https://github.com/coreos/fleet/pull/1433/files#diff-197bb752bf0f52567eb6b0023ea65e40R861 catching both cases. Maybe instead we could standardise on blockattempts=-1 == non blocking and change the check aat https://github.com/coreos/fleet/pull/1433/files#diff-197bb752bf0f52567eb6b0023ea65e40R817

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes exactly relying on that one: https://github.com/coreos/fleet/pull/1433/files#diff-197bb752bf0f52567eb6b0023ea65e40R861 to catch both of them.

For your comment "Maybe instead we could standardise on blockattempts=-1 == non blocking and change the check aat https://github.com/coreos/fleet/pull/1433/files#diff-197bb752bf0f52567eb6b0023ea65e40R817" yes I don't have a strong opinion here, I'm just used to negative values meaning retry or block forever for polling functions. Ok will do that change then, thanks!

@tixxdz
Copy link
Contributor Author

tixxdz commented Feb 19, 2016

The functional tests pass. Thanks!

if uni == nil {
return nil, fmt.Errorf("error extracting information from unit name %s", name)
} else if !uni.IsInstance() {
return nil, fmt.Errorf("unable to find Unit(%s) in Registry or on filesystem", name)
Copy link
Contributor

Choose a reason for hiding this comment

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

this error (and that on line 559) are actually bleeding into parent scope - this function is only checking for templates but the error is referencing filesystem looks (which just implicitly happen to have happened and failed before we're called in this scope). Need to clean this up somehow, not sure off the top of my head

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, ok so I got you a bit on this one, but yeh not sure what to do, certainly removing errors was not an option for me, so ?!

Copy link
Contributor

Choose a reason for hiding this comment

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

It's less than ideal, but you could create some typed errors like errNoTemplateFoundInRegistry , and return them from this function, then do a switch on the error from the outer scope, and assemble the error message there as appropriate.

@tixxdz tixxdz force-pushed the tixxdz/fleet-code-cleaning-v1+1 branch from 75dcaa0 to e8a80b5 Compare February 25, 2016 12:59
@tixxdz tixxdz added this to the v0.12.0 milestone Feb 26, 2016
func TestGetBlockAttempts(t *testing.T) {
oldNoBlock := sharedFlags.NoBlock
oldBlockAttempts := sharedFlags.BlockAttempts
sharedFlags.NoBlock = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Please turn this into a test table.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@tixxdz
Copy link
Contributor Author

tixxdz commented Mar 7, 2016

@jonboulle Investigating why semaphore fails, all comments were handled for this one and all functional tests pass here.... but semaphore fails for another error I guess...

@tixxdz tixxdz force-pushed the tixxdz/fleet-code-cleaning-v1+1 branch 2 times, most recently from e74ccba to 2b3951d Compare March 7, 2016 13:37
Djalal Harouni added 8 commits March 7, 2016 17:18
* tryWaitForUnitStates() tries to wait for units to reach the desired state.
* getBlockAttempts() gets the correct value of how many attempts to try
		     before giving up on an operation.

These helpers will be used to make the code more consistent and clean.
We do not intended to change any behaviour here.
Improve code comments about getUnitFileFromTemplate() and kill some
other useless code comments.
@tixxdz tixxdz force-pushed the tixxdz/fleet-code-cleaning-v1+1 branch from 9581bb6 to ae4b987 Compare March 7, 2016 16:37
jonboulle added a commit that referenced this pull request Mar 8, 2016
fleetctl: {load|unload|start|stop} and get unit code cleanups
@jonboulle jonboulle merged commit 980c15c into coreos:master Mar 8, 2016
@tixxdz tixxdz deleted the tixxdz/fleet-code-cleaning-v1+1 branch March 30, 2016 08:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants