Skip to content

Commit eb5c64b

Browse files
committed
fix(transient): pass good aux arg to StartTransientUnit
1 parent 8abd78f commit eb5c64b

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

dbus/methods.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ func (c *Conn) ReloadOrTryRestartUnit(name string, mode string) (string, error)
128128
// unique. mode is the same as in StartUnit(), properties contains properties
129129
// of the unit.
130130
func (c *Conn) StartTransientUnit(name string, mode string, properties ...Property) (string, error) {
131-
// the dbus interface for this method does not use the last argument and
132-
// should simply be given an empty list. We use a concrete type here
133-
// (instead of the more appropriate interface{}) to satisfy the dbus library.
134-
return c.runJob("org.freedesktop.systemd1.Manager.StartTransientUnit", name, mode, properties, make([]string, 0))
131+
return c.runJob("org.freedesktop.systemd1.Manager.StartTransientUnit", name, mode, properties, make([]PropertyCollection, 0))
135132
}
136133

137134
// KillUnit takes the unit name and a UNIX signal number to send. All of the unit's

dbus/methods_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package dbus
1818

1919
import (
20+
"fmt"
21+
"math/rand"
2022
"os"
2123
"path/filepath"
2224
"testing"
@@ -153,3 +155,59 @@ func TestGetUnitPropertiesRejectsInvalidName(t *testing.T) {
153155
t.Fatal("Expected an error, got nil")
154156
}
155157
}
158+
159+
// Ensure that basic transient unit starting and stopping works.
160+
func TestStartStopTransientUnit(t *testing.T) {
161+
conn := setupConn(t)
162+
163+
props := []Property{
164+
PropExecStart([]string{"/bin/sleep", "400"}, false),
165+
}
166+
target := fmt.Sprintf("testing-transient-%d.service", rand.Int())
167+
168+
// Start the unit
169+
job, err := conn.StartTransientUnit(target, "replace", props...)
170+
if err != nil {
171+
t.Fatal(err)
172+
}
173+
174+
if job != "done" {
175+
t.Fatal("Job is not done, %v", job)
176+
}
177+
178+
units, err := conn.ListUnits()
179+
180+
var unit *UnitStatus
181+
for _, u := range units {
182+
if u.Name == target {
183+
unit = &u
184+
}
185+
}
186+
187+
if unit == nil {
188+
t.Fatalf("Test unit not found in list")
189+
}
190+
191+
if unit.ActiveState != "active" {
192+
t.Fatalf("Test unit not active")
193+
}
194+
195+
// 3. Stop the unit
196+
job, err = conn.StopUnit(target, "replace")
197+
if err != nil {
198+
t.Fatal(err)
199+
}
200+
201+
units, err = conn.ListUnits()
202+
203+
unit = nil
204+
for _, u := range units {
205+
if u.Name == target {
206+
unit = &u
207+
}
208+
}
209+
210+
if unit != nil {
211+
t.Fatalf("Test unit found in list, should be stopped")
212+
}
213+
}

dbus/properties.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ type Property struct {
4141
Value dbus.Variant
4242
}
4343

44+
type PropertyCollection struct {
45+
Name string
46+
Properties []Property
47+
}
48+
4449
type execStart struct {
4550
Path string // the binary path to execute
4651
Args []string // an array with all arguments to pass to the executed command, starting with argument 0

0 commit comments

Comments
 (0)