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

Commit 42e5f99

Browse files
author
Dongsu Park
committed
functional: run etcdctl inside nspawn containers
WIP
1 parent 173dd62 commit 42e5f99

3 files changed

Lines changed: 21 additions & 10 deletions

File tree

functional/platform/cluster.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ type Cluster interface {
3535
// client operations
3636
Fleetctl(m Member, args ...string) (string, string, error)
3737
FleetctlWithInput(m Member, input string, args ...string) (string, string, error)
38+
Etcdctl(m Member, args ...string) (string, string, error)
39+
EtcdctlWithInput(m Member, input string, args ...string) (string, string, error)
3840
WaitForNActiveUnits(Member, int) (map[string][]util.UnitState, error)
3941
WaitForNMachines(Member, int) ([]string, error)
4042
}

functional/platform/nspawn.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ func (nc *nspawnCluster) FleetctlWithInput(m Member, input string, args ...strin
104104
return util.RunFleetctlWithInput(input, args...)
105105
}
106106

107+
func (nc *nspawnCluster) Etcdctl(m Member, args ...string) (string, string, error) {
108+
args = append([]string{"--no-sync"}, args...)
109+
return util.RunEtcdctl(args...)
110+
}
111+
112+
func (nc *nspawnCluster) EtcdctlWithInput(m Member, input string, args ...string) (string, string, error) {
113+
args = append([]string{"--no-sync"}, args...)
114+
return util.RunEtcdctlWithInput(input, args...)
115+
}
116+
107117
func (nc *nspawnCluster) WaitForNActiveUnits(m Member, count int) (map[string][]util.UnitState, error) {
108118
var nactive int
109119
states := make(map[string][]util.UnitState)

functional/unit_action_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"testing"
2323

2424
"github.com/coreos/fleet/functional/platform"
25-
"github.com/coreos/fleet/functional/util"
2625
"github.com/coreos/fleet/unit"
2726
)
2827

@@ -270,12 +269,12 @@ func TestUnitDestroyFromRegistry(t *testing.T) {
270269
unitBody := stdout
271270

272271
var hashUnit string
273-
if hashUnit, err = retrieveJobObjectHash("hello.service"); err != nil {
272+
if hashUnit, err = retrieveJobObjectHash(cluster, m, "hello.service"); err != nil {
274273
t.Fatalf("Failed to retrieve hash of job object hello.service: %v", err)
275274
}
276275

277276
var regBody string
278-
if regBody, err = retrieveUnitBody(hashUnit); err != nil {
277+
if regBody, err = retrieveUnitBody(cluster, m, hashUnit); err != nil {
279278
t.Fatalf("Failed to retrieve unit body for hello.service: %v", err)
280279
}
281280

@@ -302,7 +301,7 @@ func TestUnitDestroyFromRegistry(t *testing.T) {
302301
// check for the unit being destroyed from the etcd registry
303302
etcdUnitPrefix := "/_coreos.com/fleet/unit/"
304303
etcdUnitPath := path.Join(etcdUnitPrefix, hashUnit)
305-
if stdout, _, err = util.RunEtcdctl("ls", etcdUnitPath); err != nil {
304+
if stdout, _, err = cluster.Etcdctl(m, "ls", etcdUnitPath); err != nil {
306305
t.Fatalf("Failed to list a unit from the registry: %v", err)
307306
}
308307
units = strings.Split(strings.TrimSpace(stdout), "\n")
@@ -313,20 +312,20 @@ func TestUnitDestroyFromRegistry(t *testing.T) {
313312

314313
// retrieveJobObjectHash fetches the job hash value from
315314
// /_coreos.com/fleet/job/<jobName>/object in the etcd registry.
316-
func retrieveJobObjectHash(jobName string) (hash string, err error) {
315+
func retrieveJobObjectHash(cluster platform.Cluster, m platform.Member, jobName string) (hash string, err error) {
317316
etcdJobPrefix := "/_coreos.com/fleet/job/"
318317
etcdJobPath := path.Join(etcdJobPrefix, jobName, "object")
319318

320319
var stdout string
321-
if stdout, _, err = util.RunEtcdctl("ls", etcdJobPath); err != nil {
320+
if stdout, _, err = cluster.Etcdctl(m, "ls", etcdJobPath); err != nil {
322321
return "", fmt.Errorf("Failed to list a unit from the registry: %v", err)
323322
}
324323
units := strings.Split(strings.TrimSpace(stdout), "\n")
325324
if len(stdout) == 0 || len(units) == 0 {
326325
return "", fmt.Errorf("No such unit in the registry: %v", err)
327326
}
328327

329-
stdout, _, err = util.RunEtcdctl("get", etcdJobPath)
328+
stdout, _, err = cluster.Etcdctl(m, "get", etcdJobPath)
330329
stdout = strings.TrimSpace(stdout)
331330
objectBody := strings.Split(stdout, "\n")
332331
if err != nil || len(stdout) == 0 || len(objectBody) == 0 {
@@ -347,20 +346,20 @@ func retrieveJobObjectHash(jobName string) (hash string, err error) {
347346

348347
// retrieveUnitBody fetches unit body from /_coreos.com/fleet/unit/<hash>
349348
// in the etcd registry.
350-
func retrieveUnitBody(hashUnit string) (regBody string, err error) {
349+
func retrieveUnitBody(cluster platform.Cluster, m platform.Member, hashUnit string) (regBody string, err error) {
351350
etcdUnitPrefix := "/_coreos.com/fleet/unit/"
352351
etcdUnitPath := path.Join(etcdUnitPrefix, hashUnit)
353352

354353
var stdout string
355-
if stdout, _, err = util.RunEtcdctl("ls", etcdUnitPath); err != nil {
354+
if stdout, _, err = cluster.Etcdctl(m, "ls", etcdUnitPath); err != nil {
356355
return "", fmt.Errorf("Failed to list a unit from the registry: %v", err)
357356
}
358357

359358
units := strings.Split(strings.TrimSpace(stdout), "\n")
360359
if len(stdout) == 0 || len(units) == 0 {
361360
return "", fmt.Errorf("No such unit in the registry: %v", err)
362361
}
363-
stdout, _, err = util.RunEtcdctl("get", etcdUnitPath)
362+
stdout, _, err = cluster.Etcdctl(m, "get", etcdUnitPath)
364363
stdout = strings.TrimSpace(stdout)
365364
unitBody := strings.Split(stdout, "\n")
366365
if err != nil || len(stdout) == 0 || len(unitBody) == 0 {

0 commit comments

Comments
 (0)