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

Commit 9a16aaf

Browse files
author
David Chung
authored
Exec schema change and test script updates (#358)
Signed-off-by: David Chung <[email protected]>
1 parent d13d069 commit 9a16aaf

File tree

6 files changed

+79
-53
lines changed

6 files changed

+79
-53
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ coverage:
143143

144144
tutorial-test: binaries
145145
@echo "+ $@"
146-
./scripts/tutorial-test
146+
./scripts/tutorial-test2
147147

148148
test-full:
149149
@echo "+ $@"

circle.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ machine:
1010
GOPATH: "$HOME/.go_workspace"
1111
WORKDIR: "$GOPATH/src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME"
1212
DOCKER_RM: "false"
13+
SKIP_CLEANUP: "true"
1314

1415
dependencies:
1516
pre:

pkg/launch/monitor.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,22 @@ import (
99

1010
var errNoConfig = errors.New("no-counfig")
1111

12+
// ExecRule encapsulates what's required to exec a plugin
13+
type ExecRule struct {
14+
// Exec is the name of the exec to use to start the plugin
15+
Exec string
16+
// Properties is the properties for the executor
17+
Properties *Config
18+
}
19+
1220
// Rule provides the instructions on starting the plugin
1321
type Rule struct {
1422

1523
// Plugin is the name of the plugin
1624
Plugin string
1725

18-
// Exec is the name of the exec to use to start the plugin
19-
Exec string
20-
21-
// Launch is encoded form of the rule on how to start/exec the process
22-
Launch *Config
26+
// Launch is the rule for starting / launching the plugin.
27+
Launch ExecRule
2328
}
2429

2530
// Monitor runs continuously receiving requests to start a plugin.
@@ -39,7 +44,7 @@ func NewMonitor(l Exec, rules []Rule) *Monitor {
3944
m := map[string]Rule{}
4045
// index by name of plugin
4146
for _, r := range rules {
42-
if r.Exec == l.Name() {
47+
if r.Launch.Exec == l.Name() {
4348
m[r.Plugin] = r
4449
}
4550
}
@@ -95,13 +100,13 @@ func (m *Monitor) Start() (chan<- StartPlugin, error) {
95100
r, has := m.rules[req.Plugin]
96101
if !has {
97102
log.Warningln("no plugin:", req)
98-
req.reportError(r.Launch, errNoConfig)
103+
req.reportError(r.Launch.Properties, errNoConfig)
99104
continue loop
100105
}
101106

102107
configCopy := &Config{}
103-
if r.Launch != nil {
104-
*configCopy = *r.Launch
108+
if r.Launch.Properties != nil {
109+
*configCopy = *r.Launch.Properties
105110
}
106111

107112
block, err := m.exec.Exec(r.Plugin, configCopy)

pkg/launch/monitor_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ func TestMonitorLoopValidRule(t *testing.T) {
7373
var receivedArgs *Config
7474
rule := Rule{
7575
Plugin: "hello",
76-
Exec: "test",
77-
Launch: raw,
76+
Launch: ExecRule{
77+
Exec: "test",
78+
Properties: raw,
79+
},
7880
}
7981
monitor := NewMonitor(&testLauncher{
8082
name: "test",
Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
[
22
{
3-
"Plugin" : "group-default",
4-
"Exec" : "os",
5-
"Launch" : {
6-
"Cmd" : "infrakit-group-default --poll-interval 500ms --name group-stateless --log 5 > {{env "LOG_DIR"}}/group-default-{{unixtime}}.log 2>&1 &",
7-
"SamePgID" : true
8-
}
3+
"Plugin" : "group-default",
4+
"Launch" : {
5+
"Exec" : "os",
6+
"Properties": {
7+
"Cmd" : "infrakit-group-default --poll-interval 500ms --name group-stateless --log 5 > {{env "LOG_DIR"}}/group-default-{{unixtime}}.log 2>&1 &",
8+
"SamePgID" : true
9+
}
10+
}
911
}
1012
,
1113
{
12-
"Plugin" : "instance-file",
13-
"Exec" : "os",
14-
"Launch" : {
15-
"Cmd" : "infrakit-instance-file --dir {{env "TUTORIAL_DIR"}} --log 5 > {{env "LOG_DIR"}}/instance-file-{{unixtime}}.log 2>&1",
16-
"SamePgID" : true
17-
}
14+
"Plugin" : "instance-file",
15+
"Launch" : {
16+
"Exec" : "os",
17+
"Properties" : {
18+
"Cmd" : "infrakit-instance-file --dir {{env "TUTORIAL_DIR"}} --log 5 > {{env "LOG_DIR"}}/instance-file-{{unixtime}}.log 2>&1",
19+
"SamePgID" : true
20+
}
21+
}
1822
}
1923
,
2024
{
21-
"Plugin" : "flavor-vanilla",
22-
"Exec" : "os",
23-
"Launch" : {
24-
"Cmd" : "infrakit-flavor-vanilla --log 5 > {{env "LOG_DIR"}}/flavor-vanilla-{{unixtime}}.log 2>&1",
25-
"SamePgID" : true
26-
}
25+
"Plugin" : "flavor-vanilla",
26+
"Launch" : {
27+
"Exec" : "os",
28+
"Properties" : {
29+
"Cmd" : "infrakit-flavor-vanilla --log 5 > {{env "LOG_DIR"}}/flavor-vanilla-{{unixtime}}.log 2>&1",
30+
"SamePgID" : true
31+
}
32+
}
2733
}
2834
]

scripts/tutorial-test2

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,23 @@ set -o nounset
66
HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
77
cd "$HERE/.."
88

9+
export PATH=$PWD/build:$PATH
10+
11+
SKIP_CLEANUP=${SKIP_CLEANUP:-false}
12+
13+
starterpid="" # pid of the cli plugin starter
914
cleanup() {
10-
kill $(jobs -p)
11-
rm -rf tutorial
15+
pgid=$(ps -o pgid= -p $starterpid)
16+
echo "Stopping plugin starter utility - $starterpid , pgid=$pgid"
17+
kill -TERM -$pgid
18+
echo "Stopping other jobs"
19+
kill $(jobs -p)
20+
rm -rf tutorial
1221
}
13-
trap cleanup EXIT
22+
23+
if [ "$SKIP_CLEANUP" != "true" ]; then
24+
trap cleanup EXIT
25+
fi
1426

1527
# infrakit directories
1628
plugins=~/.infrakit/plugins
@@ -27,9 +39,9 @@ echo group > $leaderfile
2739

2840
# start up multiple instances of manager -- typically we want multiple SETS of plugins and managers
2941
# but here for simplicity just start up with multiple managers and one set of plugins
30-
build/infrakit-manager --name group --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore &
31-
build/infrakit-manager --name group1 --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore &
32-
build/infrakit-manager --name group2 --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore &
42+
infrakit-manager --name group --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore &
43+
infrakit-manager --name group1 --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore &
44+
infrakit-manager --name group2 --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore &
3345

3446
sleep 5 # manager needs to detect leadership
3547

@@ -47,10 +59,10 @@ export LOG_DIR=$LOG_DIR
4759
export TUTORIAL_DIR=$TUTORIAL_DIR
4860

4961
# note -- on exit, this won't clean up the plugins started by the cli since they will be in a separate process group
50-
build/infrakit plugin start --wait --config-url file:///$PWD/scripts/tutorial-start-plugins.json --os group-default instance-file flavor-vanilla &
62+
infrakit plugin start --wait --config-url file:///$PWD/scripts/tutorial-start-plugins.json --os group-default instance-file flavor-vanilla &
5163

52-
lastpid=$!
53-
echo "plugin start pid=$lastpid"
64+
starterpid=$!
65+
echo "plugin start pid=$starterpid"
5466

5567
sleep 5
5668

@@ -90,33 +102,33 @@ expect_output_lines() {
90102
fi
91103
}
92104

93-
expect_output_lines "6 plugins should be discoverable" "build/infrakit plugin ls -q" "6"
94-
expect_output_lines "0 instances should exist" "build/infrakit instance describe -q --name instance-file" "0"
105+
expect_output_lines "6 plugins should be discoverable" "infrakit plugin ls -q" "6"
106+
expect_output_lines "0 instances should exist" "infrakit instance describe -q --name instance-file" "0"
95107

96108
echo "Commiting"
97-
build/infrakit group commit docs/cattle.json
109+
infrakit group commit docs/cattle.json
98110

99111
echo 'Waiting for group to be provisioned'
100112
sleep 2
101113

102-
expect_output_lines "5 instances should exist in group" "build/infrakit group describe cattle -q" "5"
103-
expect_output_lines "5 instances should exist" "build/infrakit instance describe -q --name instance-file" "5"
114+
expect_output_lines "5 instances should exist in group" "infrakit group describe cattle -q" "5"
115+
expect_output_lines "5 instances should exist" "infrakit instance describe -q --name instance-file" "5"
104116

105-
build/infrakit group free cattle
106-
build/infrakit group commit docs/cattle.json
117+
infrakit group free cattle
118+
infrakit group commit docs/cattle.json
107119

108-
expect_exact_output "Should be watching one group" "build/infrakit group ls -q" "cattle"
120+
expect_exact_output "Should be watching one group" "infrakit group ls -q" "cattle"
109121

110122
expect_exact_output \
111123
"Update should roll 5 and scale group to 10" \
112-
"build/infrakit group commit docs/cattle2.json --pretend" \
124+
"infrakit group commit docs/cattle2.json --pretend" \
113125
"Committing cattle would involve: Performing a rolling update on 5 instances, then adding 5 instances to increase the group size to 10"
114126

115-
build/infrakit group commit docs/cattle2.json
127+
infrakit group commit docs/cattle2.json
116128

117129
sleep 5
118130

119-
expect_output_lines "10 instances should exist in group" "build/infrakit group describe cattle -q" "10"
131+
expect_output_lines "10 instances should exist in group" "infrakit group describe cattle -q" "10"
120132

121133
# Terminate 3 instances.
122134
pushd $TUTORIAL_DIR
@@ -125,9 +137,9 @@ popd
125137

126138
sleep 5
127139

128-
expect_output_lines "10 instances should exist in group" "build/infrakit group describe cattle -q" "10"
140+
expect_output_lines "10 instances should exist in group" "infrakit group describe cattle -q" "10"
129141

130-
build/infrakit group destroy cattle
131-
expect_output_lines "0 instances should exist" "build/infrakit instance describe -q --name instance-file" "0"
142+
infrakit group destroy cattle
143+
expect_output_lines "0 instances should exist" "infrakit instance describe -q --name instance-file" "0"
132144

133145
echo 'ALL TESTS PASSED'

0 commit comments

Comments
 (0)