-
Notifications
You must be signed in to change notification settings - Fork 1
/
load
76 lines (60 loc) · 1.72 KB
/
load
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
size := len(c.engines)
done := make(chan bool, size)
pipeWriters := []*io.PipeWriter{}
pipeReaders := []*io.PipeReader{}
for _, n := range c.engines {
pipeReader, pipeWriter := io.Pipe()
pipeReaders = append(pipeReaders, pipeReader)
pipeWriters = append(pipeWriters, pipeWriter)
go func(reader *io.PipeReader, nn *cluster.Engine) {
// call engine load image
err := nn.Load(reader)
if callback != nil {
if err != nil {
callback(nn.Name, err.Error())
}
}
// clean up
defer reader.Close()
done <- true
}(pipeReader, n)
}
// create multi-writer
listWriter := []io.Writer{}
for _, pipeW := range pipeWriters {
listWriter = append(listWriter, pipeW)
}
mutiWriter := io.MultiWriter(listWriter...)
// copy image-reader to muti-writer
written, err := io.Copy(mutiWriter, imageReader)
if err != nil {
log.Error(err)
}
// close pipe writers
for _, pipeW := range pipeWriters {
pipeW.Close()
}
// wait all host done
for i := 0; i < size; i++ {
<-done
}
#!/usr/bin/env bats
load helpers
# temp file for image
IMAGE_FILE=$(mktemp)
function teardown() {
stop_manager
stop_docker
rm -f $IMAGE_FILE
}
@test "docker load should return success,every node should load the image" {
# create a tar file
docker pull busybox:latest
docker save -o $IMAGE_FILE busybox:latest
start_docker 1
start_manager
run docker_swarm -i $IMAGE_FILE
[ "$status" -eq 0 ]
run docker -H ${HOSTS[0]} images
[ "${#lines[@]}" -eq 2 ]
}