-
Notifications
You must be signed in to change notification settings - Fork 302
api: support cAPI.UnitState() for a single unit #1679
api: support cAPI.UnitState() for a single unit #1679
Conversation
e1b436b
to
0454b49
Compare
Fixed bugs.
My suggestion is to merge first #1673 and #1667. After that, we could take some time to review this PR for Anyway every functional test should now work as expected. :-) |
cfaf321
to
fc18d4e
Compare
Added necesssary unit tests too. |
0ba8e0f
to
94f2b69
Compare
@jonboulle Yes. |
94f2b69
to
4caeaf6
Compare
6d42b12
to
e541e1a
Compare
e541e1a
to
f674d6f
Compare
I managed to get this PR decoupled from #1673. Now it's working even without updating gRPC altogether. At the beginning it didn't work with old gRPC, because for some reason the new method It's ready for review. |
6d83f94
to
70510b3
Compare
Although it contains many lines of codes, I think its logic is relatively straightforward. |
apiStates, errU = cAPI.UnitStates() | ||
if errU != nil { | ||
return fmt.Errorf("Error retrieving list of units: %v", errU) | ||
if _, err := cAPI.UnitState(name); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm missing something, what is the point of the sleep + this call here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonboulle Yeah, I'd also like to remove them, but without calling the sleep and again UnitState, several functional tests like TestUnitStart seem to fail occasionally. I didn't have a chance to find out the reason.
Let me think how I can avoid such errors with calling UnitState just once.
if err != nil { | ||
return err | ||
return fmt.Errorf("Error retrieving list of units: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs an update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonboulle Will do.
A couple of questions about the fleetctl code, but overall this looks really great, thanks! |
HTTP client should be able to retrieve a unit state via URL like http://*/state/unitName. Support GET for stateResource just like unitResource.
Define Get method for UnitState in the schema, and regenerate both json and go.
Introduce UnitState() for API interface as well as HTTPClient struct.
Protobuf must also its own method GetUnitState().
UnitState() needs to be defined for etcdRegistry, RPCRegistry, and *RegistryMux*. Also inmemoryRegistry() needs to have UnitState().
Now fleetctl should be able to retrieve a unit state, using cAPI.UnitState(). Also get rid of getSingleUnitState() to simplify the logic.
We should add new unit tests like TestUnitState() as well as TestInMemoryUnitState(), to cover the new cases like EtcdRegistry.UnitState() or inmemoryRegistry.UnitState().
70510b3
to
08891bf
Compare
Rebased, and pushed 2 more commits, "fleetctl: periodically check for systemd states using waitForState" and "fleetctl: make use of waitForState also in assertUnitState()". |
08891bf
to
bb33268
Compare
// If it cannot get the expected states within the period, return error. | ||
func assertSystemdActiveState(unitName string) error { | ||
var errbuf error | ||
fetchSystemdActiveState := func() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just have this func() err
and propagate the error instead of using this buffer variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonboulle Done.
bb33268
to
2c014f0
Compare
case <-alarm: | ||
return timeout, fmt.Errorf("Failed to fetch systemd active states within %v", timeout) | ||
case <-ticker: | ||
isChecked, err := stateCheckFunc() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to keep nitting on this, but I might not have explained clearly: err
will always be nil
when isChecked
is true
, right? which means that you can just remove the bool
value and rely on the nil-ness of the error :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonboulle Yeah right. It's done.
The return type of waitForState was like that because of copy-and-paste from functional tests. So I'm now thinking, maybe it would make sense to convert the return type of waitForState also in functional tests: error instead of bool. TODO.
Although checkSystemdActiveState() doesn't have to depend on cAPI.UnitStates(), it's still impossible to remove additional sleep in case of error from assertSystemdActiveState(). That's actually a known issue. Sometimes it simply takes much time until fleetctl became able to get valid unit states. Adding additional sleeps or tuning the sleep time wouldn't be a good approach, as an optimal sleep interval could vary a lot case by case. To gracefully handle this case, let's do similar checking as done in functional tests. * Introduce a new helper waitForState(), just like util.WaitForState() from functional tests. * Squash assertFetchSystemdActiveState() into assertSystemdActiveState() to make it retry the assertion periodically up to defaultSleepTime. * Increase defaultSleepTime from 500 to 2000 msec. * Remove the additional sleep call as well as cAPI.UnitState() call.
b438a2c
to
9137746
Compare
waitForUnitState() has been making use of an additional sleep, in case assertUnitState() returned error. Now that a helper waitForState() is available for fleetctl, we don't need to sleep there. So remove the sleep calls, and instead make assertUnitState() a wrapper of waitForState() over fetchUnitState(). That way, assertUnitState() can periodically retry to get a unit, up to defaultSleepTime. This is also good for consistency in the entire code, as assertSystemdActiveState() already depends on waitForState().
I suppose everything was addressed. I'm merging it. |
GET
method forstateResource
Get
method forUnitState
UnitState()
for API interfaceGetUnitState()
for registryClient and registryServerUnitState()
foretcdRegistry
andRPCRegistry
cAPI.UnitStates()
with.UnitState()
GetUnitState()
and relevant oneswaitForState
waitForState
also inassertUnitState()
Fixes #1675