Merge pull request #1 from bcwaldon/bump-go-systemd
bump github.com/coreos/go-systemd/dbus
This commit is contained in:
commit
282e4637cd
@ -128,10 +128,7 @@ func (c *Conn) ReloadOrTryRestartUnit(name string, mode string) (string, error)
|
|||||||
// unique. mode is the same as in StartUnit(), properties contains properties
|
// unique. mode is the same as in StartUnit(), properties contains properties
|
||||||
// of the unit.
|
// of the unit.
|
||||||
func (c *Conn) StartTransientUnit(name string, mode string, properties ...Property) (string, error) {
|
func (c *Conn) StartTransientUnit(name string, mode string, properties ...Property) (string, error) {
|
||||||
// the dbus interface for this method does not use the last argument and
|
return c.runJob("org.freedesktop.systemd1.Manager.StartTransientUnit", name, mode, properties, make([]PropertyCollection, 0))
|
||||||
// should simply be given an empty list. We use a concrete type here
|
|
||||||
// (instead of the more appropriate interface{}) to satisfy the dbus library.
|
|
||||||
return c.runJob("org.freedesktop.systemd1.Manager.StartTransientUnit", name, mode, properties, make([]string, 0))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// KillUnit takes the unit name and a UNIX signal number to send. All of the unit's
|
// KillUnit takes the unit name and a UNIX signal number to send. All of the unit's
|
||||||
|
@ -17,6 +17,8 @@ limitations under the License.
|
|||||||
package dbus
|
package dbus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@ -153,3 +155,59 @@ func TestGetUnitPropertiesRejectsInvalidName(t *testing.T) {
|
|||||||
t.Fatal("Expected an error, got nil")
|
t.Fatal("Expected an error, got nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure that basic transient unit starting and stopping works.
|
||||||
|
func TestStartStopTransientUnit(t *testing.T) {
|
||||||
|
conn := setupConn(t)
|
||||||
|
|
||||||
|
props := []Property{
|
||||||
|
PropExecStart([]string{"/bin/sleep", "400"}, false),
|
||||||
|
}
|
||||||
|
target := fmt.Sprintf("testing-transient-%d.service", rand.Int())
|
||||||
|
|
||||||
|
// Start the unit
|
||||||
|
job, err := conn.StartTransientUnit(target, "replace", props...)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if job != "done" {
|
||||||
|
t.Fatal("Job is not done, %v", job)
|
||||||
|
}
|
||||||
|
|
||||||
|
units, err := conn.ListUnits()
|
||||||
|
|
||||||
|
var unit *UnitStatus
|
||||||
|
for _, u := range units {
|
||||||
|
if u.Name == target {
|
||||||
|
unit = &u
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if unit == nil {
|
||||||
|
t.Fatalf("Test unit not found in list")
|
||||||
|
}
|
||||||
|
|
||||||
|
if unit.ActiveState != "active" {
|
||||||
|
t.Fatalf("Test unit not active")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Stop the unit
|
||||||
|
job, err = conn.StopUnit(target, "replace")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
units, err = conn.ListUnits()
|
||||||
|
|
||||||
|
unit = nil
|
||||||
|
for _, u := range units {
|
||||||
|
if u.Name == target {
|
||||||
|
unit = &u
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if unit != nil {
|
||||||
|
t.Fatalf("Test unit found in list, should be stopped")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -41,6 +41,11 @@ type Property struct {
|
|||||||
Value dbus.Variant
|
Value dbus.Variant
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PropertyCollection struct {
|
||||||
|
Name string
|
||||||
|
Properties []Property
|
||||||
|
}
|
||||||
|
|
||||||
type execStart struct {
|
type execStart struct {
|
||||||
Path string // the binary path to execute
|
Path string // the binary path to execute
|
||||||
Args []string // an array with all arguments to pass to the executed command, starting with argument 0
|
Args []string // an array with all arguments to pass to the executed command, starting with argument 0
|
||||||
|
Loading…
Reference in New Issue
Block a user