-
Notifications
You must be signed in to change notification settings - Fork 328
dbus: add support for new ListUnits* methods #150
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
Conversation
dbus/methods.go
Outdated
| // and hence there might be more unit names loaded than actual units behind them. | ||
| func (c *Conn) ListUnitsFiltered(states []string, patterns []string) ([]UnitStatus, error) { | ||
| result := make([][]interface{}, 0) | ||
| err := c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitsFiltered", 0, states, patterns).Store(&result) |
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.
is this documented somewhere? seems they've stopped updating the API page :-( https://www.freedesktop.org/wiki/Software/systemd/dbus/
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.
No, it is not, see systemd/systemd#1042
Also this ListUnitsFiltered implementation is customized. I'm working on systemd patch as I mentioned in PR description.
ff35f30 to
74acfae
Compare
|
@jonboulle updated this PR according to systemd/systemd#3142 |
|
@jonboulle Updated this PR according to systemd/systemd#3182 |
5f70197 to
c280fd6
Compare
|
@jonboulle both new methods were merged in systemd. |
dbus/methods.go
Outdated
| // units. Input array should contain exact unit names, but not patterns. | ||
| func (c *Conn) ListUnitsByNames(units []string) ([]UnitStatus, error) { | ||
| result := make([][]interface{}, 0) | ||
| err := c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitsByNames", 0, units).Store(&result) |
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 function is 99% the same as ListUnits, so can you split out the common code, something like
type storeFunc func(retvalues ...interface{}) error
func (c *Conn) listUnitsInternal(f storeFunc) ([]UnitStatus, error) {
result := make([][]interface{}, 0)
err := f(&result)
if err != nil {
... // rest of current func here
return status, nil
}
func (c *Conn) ListUnitsByNames(units []string) ([]UnitStatus, error) {
return c.listUnitsInternal(
c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitsByNames", 0, units).Store
)
}
func (c *Conn) ListUnitsByPatterns(states []string, patterns []string) ([]UnitStatus, error) {
return c.listUnitsInternal(
c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitsByPatterns", 0, states, patterns).Store
)
}
func (c *Conn) ListUnits(units []string) ([]UnitStatus, error) {
return c.listUnitsInternal(
c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnits", 0).Store
)
}
|
LGTM in principle, but:
|
ac30e13 to
4207225
Compare
|
@jonboulle fixed PR following your suggestions. I'll provide benchmark results inside fleet PR: coreos/fleet#1564 |
80168f1 to
6c718b3
Compare
|
Regarding previous review, code has been refactored but it is still not covered by any tests (is fleet blocked by this? Can you add them here or later?). Nothing else to add from my side. |
|
@lucab does switching from |
|
@kayrus I'm not sure if it is doable, but I would try to pick some well-known unit name/pattern (ie. existing on most systems) and try to test if the filtered listing succeeds and the result is a subset of the full set you get via |
e523618 to
d3fb628
Compare
1107669 to
b9d28d2
Compare
|
@lucab done |
implemented new dbus methods: * ListUnitsFiltered * ListUnitsByPatterns * ListUnitsByNames * ListUnitFilesByPatterns refactored legacy ListUnits and ListUnitFiles functions
b9d28d2 to
124d391
Compare
| } | ||
| } | ||
|
|
||
| if unit == 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.
Why should it be found in the list? this is counterintuitive the way it's written
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 take a look on this comment https://github.com/coreos/go-systemd/pull/150/files#diff-b5b8384be79564335a3b50bcfed63e91R293
systemd should return unit states for non-existing units.
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.
Oh... confusing
On Tue, May 31, 2016 at 5:34 PM, kayrus [email protected] wrote:
In dbus/methods_test.go
#150 (comment):
t.Fatalf("%s unit not found in list", target1)- }
- if unit.ActiveState != "active" {
t.Fatalf("%s unit should be active but it is %s", target1, unit.ActiveState)- }
- unit = nil
- for _, u := range units {
if u.Name == target2 {unit = &ubreak}- }
- if unit == nil {
@jonboulle https://github.com/jonboulle take a look on this comment
https://github.com/coreos/go-systemd/pull/150/files#diff-b5b8384be79564335a3b50bcfed63e91R293
systemd should return unit states for non-existing units.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/coreos/go-systemd/pull/150/files/124d391a9338d39c19cd55de93b70a4e7ed649f4#r65206518,
or mute the thread
https://github.com/notifications/unsubscribe/ACewNzMPezWMqZoW3zMavEVcKRxk5tcbks5qHFUSgaJpZM4IMyF5
.
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 yep I confirm it's a bit confusing, but that's how systemd works actually please check this comment systemd/systemd#3182 (comment) so basically the implementation doesn't bother it's just gives you back what you have requested setting up the right state of course.
Now this test can be updated to be more readable:
just create a target1 and target2 object which has {unit_name, activestate, a bolean found or not} , do the whole check inside the same loop, and check after the loop if the units have been found or not. The doc of ListUnitsByNames() clearly states that it may return results for even non-existent units which is good.
|
@lucab ping |
| break | ||
| } | ||
| } | ||
|
|
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.
same thing with previous test ? have one loop maybe ?
Not sure if it covers what you have in mind, but that change at systemd level was covered inside systemctl by a fallback to the old method if the new provided method is not available. I think @kayrus did the right thing the check also fallbacks in fleet here: However to not have test failures in go-systemd, so inside newly added tests of go-systemd when you call the new methods, check the error code and if the method is not available do not fatal ? warning or something ? not sure if this make sense, it depends on how often go-systemd is updated, in all case systemd was released with these new changes. Thanks! |
|
lgtm overall, just small code cleanups, thanks! |
* Added getUnitStatus and getUnitFile functions for test * Added t.Skip for methods which are not available * Increased verbosity to show skipped tests
|
@lucab @jonboulle done |
|
LGTM |
|
@lucab will you make some kind of tag? |
|
@kayrus yes, v9 is pending due to a regression in sdjournal. |
|
@lucab please ping me when you'l fix that. |
…d support)
is a part of this change: endocode/systemd@5b4452a
and this pull request: coreos/fleet#1564