From 9db3a73ffdba345842781596fe5a14b9347b9dfb Mon Sep 17 00:00:00 2001 From: David Chung Date: Wed, 11 Jan 2017 17:35:40 -0800 Subject: [PATCH 1/7] Schema change for executor / plugin starter config --- pkg/launch/monitor.go | 23 ++++++++++++++--------- pkg/launch/monitor_test.go | 6 ++++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/pkg/launch/monitor.go b/pkg/launch/monitor.go index 9de3ea1d0..8af849ae4 100644 --- a/pkg/launch/monitor.go +++ b/pkg/launch/monitor.go @@ -9,17 +9,22 @@ import ( var errNoConfig = errors.New("no-counfig") +// ExecRule encapsulates what's required to exec a plugin +type ExecRule struct { + // Exec is the name of the exec to use to start the plugin + Exec string + // Properties is the properties for the executor + Properties *Config +} + // Rule provides the instructions on starting the plugin type Rule struct { // Plugin is the name of the plugin Plugin string - // Exec is the name of the exec to use to start the plugin - Exec string - - // Launch is encoded form of the rule on how to start/exec the process - Launch *Config + // Launch is the rule for starting / launching the plugin. + Launch ExecRule } // Monitor runs continuously receiving requests to start a plugin. @@ -39,7 +44,7 @@ func NewMonitor(l Exec, rules []Rule) *Monitor { m := map[string]Rule{} // index by name of plugin for _, r := range rules { - if r.Exec == l.Name() { + if r.Launch.Exec == l.Name() { m[r.Plugin] = r } } @@ -95,13 +100,13 @@ func (m *Monitor) Start() (chan<- StartPlugin, error) { r, has := m.rules[req.Plugin] if !has { log.Warningln("no plugin:", req) - req.reportError(r.Launch, errNoConfig) + req.reportError(r.Launch.Properties, errNoConfig) continue loop } configCopy := &Config{} - if r.Launch != nil { - *configCopy = *r.Launch + if r.Launch.Properties != nil { + *configCopy = *r.Launch.Properties } block, err := m.exec.Exec(r.Plugin, configCopy) diff --git a/pkg/launch/monitor_test.go b/pkg/launch/monitor_test.go index 573662f9a..22971a2ab 100644 --- a/pkg/launch/monitor_test.go +++ b/pkg/launch/monitor_test.go @@ -73,8 +73,10 @@ func TestMonitorLoopValidRule(t *testing.T) { var receivedArgs *Config rule := Rule{ Plugin: "hello", - Exec: "test", - Launch: raw, + Launch: ExecRule{ + Exec: "test", + Properties: raw, + }, } monitor := NewMonitor(&testLauncher{ name: "test", From 703d0f7e95d703066e6eb68f2f17c12e6bfb40f3 Mon Sep 17 00:00:00 2001 From: David Chung Date: Wed, 11 Jan 2017 17:36:07 -0800 Subject: [PATCH 2/7] Update config JSON for e2e test Signed-off-by: David Chung --- scripts/tutorial-start-plugins.json | 42 ++++++++++++++++------------- scripts/tutorial-test2 | 13 ++++++--- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/scripts/tutorial-start-plugins.json b/scripts/tutorial-start-plugins.json index 4200f182b..1f954f112 100644 --- a/scripts/tutorial-start-plugins.json +++ b/scripts/tutorial-start-plugins.json @@ -1,28 +1,34 @@ [ { - "Plugin" : "group-default", - "Exec" : "os", - "Launch" : { - "Cmd" : "infrakit-group-default --poll-interval 500ms --name group-stateless --log 5 > {{env "LOG_DIR"}}/group-default-{{unixtime}}.log 2>&1 &", - "SamePgID" : true - } + "Plugin" : "group-default", + "Launch" : { + "Exec" : "os", + "Properties": { + "Cmd" : "infrakit-group-default --poll-interval 500ms --name group-stateless --log 5 > {{env "LOG_DIR"}}/group-default-{{unixtime}}.log 2>&1 &", + "SamePgID" : true + } + } } , { - "Plugin" : "instance-file", - "Exec" : "os", - "Launch" : { - "Cmd" : "infrakit-instance-file --dir {{env "TUTORIAL_DIR"}} --log 5 > {{env "LOG_DIR"}}/instance-file-{{unixtime}}.log 2>&1", - "SamePgID" : true - } + "Plugin" : "instance-file", + "Launch" : { + "Exec" : "os", + "Properties" : { + "Cmd" : "infrakit-instance-file --dir {{env "TUTORIAL_DIR"}} --log 5 > {{env "LOG_DIR"}}/instance-file-{{unixtime}}.log 2>&1", + "SamePgID" : true + } + } } , { - "Plugin" : "flavor-vanilla", - "Exec" : "os", - "Launch" : { - "Cmd" : "infrakit-flavor-vanilla --log 5 > {{env "LOG_DIR"}}/flavor-vanilla-{{unixtime}}.log 2>&1", - "SamePgID" : true - } + "Plugin" : "flavor-vanilla", + "Launch" : { + "Exec" : "os", + "Properties" : { + "Cmd" : "infrakit-flavor-vanilla --log 5 > {{env "LOG_DIR"}}/flavor-vanilla-{{unixtime}}.log 2>&1", + "SamePgID" : true + } + } } ] diff --git a/scripts/tutorial-test2 b/scripts/tutorial-test2 index 101b94ab9..d41c878c4 100755 --- a/scripts/tutorial-test2 +++ b/scripts/tutorial-test2 @@ -6,9 +6,14 @@ set -o nounset HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd "$HERE/.." +starterpid="" # pid of the cli plugin starter cleanup() { - kill $(jobs -p) - rm -rf tutorial + pgid=$(ps -o pgid= -p $starterpid) + echo "Stopping plugin starter utility - $starterpid , pgid=$pgid" + kill -TERM -$pgid + echo "Stopping other jobs" + kill $(jobs -p) + rm -rf tutorial } trap cleanup EXIT @@ -49,8 +54,8 @@ export TUTORIAL_DIR=$TUTORIAL_DIR # note -- on exit, this won't clean up the plugins started by the cli since they will be in a separate process group build/infrakit plugin start --wait --config-url file:///$PWD/scripts/tutorial-start-plugins.json --os group-default instance-file flavor-vanilla & -lastpid=$! -echo "plugin start pid=$lastpid" +starterpid=$! +echo "plugin start pid=$starterpid" sleep 5 From 8c962c4a379e35d2210fc5f42d6c7add554af38f Mon Sep 17 00:00:00 2001 From: David Chung Date: Wed, 11 Jan 2017 17:37:18 -0800 Subject: [PATCH 3/7] use new test in make ci Signed-off-by: David Chung --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index dc81c3cc0..0990232db 100644 --- a/Makefile +++ b/Makefile @@ -143,7 +143,7 @@ coverage: tutorial-test: binaries @echo "+ $@" - ./scripts/tutorial-test + ./scripts/tutorial-test2 test-full: @echo "+ $@" From becf2ca02b8004f678ace2090648fe5db17050c9 Mon Sep 17 00:00:00 2001 From: David Chung Date: Wed, 11 Jan 2017 18:14:30 -0800 Subject: [PATCH 4/7] Make sure infrakit binaries are in PATH Signed-off-by: David Chung --- scripts/tutorial-test2 | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/scripts/tutorial-test2 b/scripts/tutorial-test2 index d41c878c4..159cf4acf 100755 --- a/scripts/tutorial-test2 +++ b/scripts/tutorial-test2 @@ -6,6 +6,8 @@ set -o nounset HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd "$HERE/.." +export PATH=$PWD/build:$PATH + starterpid="" # pid of the cli plugin starter cleanup() { pgid=$(ps -o pgid= -p $starterpid) @@ -32,9 +34,9 @@ echo group > $leaderfile # start up multiple instances of manager -- typically we want multiple SETS of plugins and managers # but here for simplicity just start up with multiple managers and one set of plugins -build/infrakit-manager --name group --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore & -build/infrakit-manager --name group1 --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore & -build/infrakit-manager --name group2 --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore & +infrakit-manager --name group --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore & +infrakit-manager --name group1 --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore & +infrakit-manager --name group2 --proxy-for-group group-stateless os --leader-file $leaderfile --store-dir $configstore & sleep 5 # manager needs to detect leadership @@ -52,7 +54,7 @@ export LOG_DIR=$LOG_DIR export TUTORIAL_DIR=$TUTORIAL_DIR # note -- on exit, this won't clean up the plugins started by the cli since they will be in a separate process group -build/infrakit plugin start --wait --config-url file:///$PWD/scripts/tutorial-start-plugins.json --os group-default instance-file flavor-vanilla & +infrakit plugin start --wait --config-url file:///$PWD/scripts/tutorial-start-plugins.json --os group-default instance-file flavor-vanilla & starterpid=$! echo "plugin start pid=$starterpid" @@ -95,33 +97,33 @@ expect_output_lines() { fi } -expect_output_lines "6 plugins should be discoverable" "build/infrakit plugin ls -q" "6" -expect_output_lines "0 instances should exist" "build/infrakit instance describe -q --name instance-file" "0" +expect_output_lines "6 plugins should be discoverable" "infrakit plugin ls -q" "6" +expect_output_lines "0 instances should exist" "infrakit instance describe -q --name instance-file" "0" echo "Commiting" -build/infrakit group commit docs/cattle.json +infrakit group commit docs/cattle.json echo 'Waiting for group to be provisioned' sleep 2 -expect_output_lines "5 instances should exist in group" "build/infrakit group describe cattle -q" "5" -expect_output_lines "5 instances should exist" "build/infrakit instance describe -q --name instance-file" "5" +expect_output_lines "5 instances should exist in group" "infrakit group describe cattle -q" "5" +expect_output_lines "5 instances should exist" "infrakit instance describe -q --name instance-file" "5" -build/infrakit group free cattle -build/infrakit group commit docs/cattle.json +infrakit group free cattle +infrakit group commit docs/cattle.json -expect_exact_output "Should be watching one group" "build/infrakit group ls -q" "cattle" +expect_exact_output "Should be watching one group" "infrakit group ls -q" "cattle" expect_exact_output \ "Update should roll 5 and scale group to 10" \ - "build/infrakit group commit docs/cattle2.json --pretend" \ + "infrakit group commit docs/cattle2.json --pretend" \ "Committing cattle would involve: Performing a rolling update on 5 instances, then adding 5 instances to increase the group size to 10" -build/infrakit group commit docs/cattle2.json +infrakit group commit docs/cattle2.json sleep 5 -expect_output_lines "10 instances should exist in group" "build/infrakit group describe cattle -q" "10" +expect_output_lines "10 instances should exist in group" "infrakit group describe cattle -q" "10" # Terminate 3 instances. pushd $TUTORIAL_DIR @@ -130,9 +132,9 @@ popd sleep 5 -expect_output_lines "10 instances should exist in group" "build/infrakit group describe cattle -q" "10" +expect_output_lines "10 instances should exist in group" "infrakit group describe cattle -q" "10" -build/infrakit group destroy cattle -expect_output_lines "0 instances should exist" "build/infrakit instance describe -q --name instance-file" "0" +infrakit group destroy cattle +expect_output_lines "0 instances should exist" "infrakit instance describe -q --name instance-file" "0" echo 'ALL TESTS PASSED' From 0168a7ea5770ec0d95c63ca1f23bf1b0a941c9f1 Mon Sep 17 00:00:00 2001 From: David Chung Date: Wed, 11 Jan 2017 18:31:34 -0800 Subject: [PATCH 5/7] run the kill in another shell to avoid termination on circle ci Signed-off-by: David Chung --- scripts/tutorial-test2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tutorial-test2 b/scripts/tutorial-test2 index 159cf4acf..b4c5237ad 100755 --- a/scripts/tutorial-test2 +++ b/scripts/tutorial-test2 @@ -12,7 +12,7 @@ starterpid="" # pid of the cli plugin starter cleanup() { pgid=$(ps -o pgid= -p $starterpid) echo "Stopping plugin starter utility - $starterpid , pgid=$pgid" - kill -TERM -$pgid + $(kill -TERM -$pgid) echo "Stopping other jobs" kill $(jobs -p) rm -rf tutorial From fa4d8ca14914acd1dbb990feab9981c22a634460 Mon Sep 17 00:00:00 2001 From: David Chung Date: Wed, 11 Jan 2017 18:49:14 -0800 Subject: [PATCH 6/7] disable cleanup on circle Signed-off-by: David Chung --- scripts/tutorial-test2 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/tutorial-test2 b/scripts/tutorial-test2 index b4c5237ad..1f7bb4c64 100755 --- a/scripts/tutorial-test2 +++ b/scripts/tutorial-test2 @@ -12,12 +12,15 @@ starterpid="" # pid of the cli plugin starter cleanup() { pgid=$(ps -o pgid= -p $starterpid) echo "Stopping plugin starter utility - $starterpid , pgid=$pgid" - $(kill -TERM -$pgid) + kill -TERM -$pgid echo "Stopping other jobs" kill $(jobs -p) rm -rf tutorial } -trap cleanup EXIT + +if [ "DOCKER_RM" = "true" ]; then + trap cleanup EXIT +fi # infrakit directories plugins=~/.infrakit/plugins From 2f4b9ecbcd6e1424e39e9a8cde18f5373d9342c9 Mon Sep 17 00:00:00 2001 From: David Chung Date: Wed, 11 Jan 2017 19:00:29 -0800 Subject: [PATCH 7/7] hack - disable cleanup on circle Signed-off-by: David Chung --- circle.yml | 1 + scripts/tutorial-test2 | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 3fd0153b6..93b29cfb4 100644 --- a/circle.yml +++ b/circle.yml @@ -10,6 +10,7 @@ machine: GOPATH: "$HOME/.go_workspace" WORKDIR: "$GOPATH/src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME" DOCKER_RM: "false" + SKIP_CLEANUP: "true" dependencies: pre: diff --git a/scripts/tutorial-test2 b/scripts/tutorial-test2 index 1f7bb4c64..6c9d7d0aa 100755 --- a/scripts/tutorial-test2 +++ b/scripts/tutorial-test2 @@ -8,6 +8,8 @@ cd "$HERE/.." export PATH=$PWD/build:$PATH +SKIP_CLEANUP=${SKIP_CLEANUP:-false} + starterpid="" # pid of the cli plugin starter cleanup() { pgid=$(ps -o pgid= -p $starterpid) @@ -18,7 +20,7 @@ cleanup() { rm -rf tutorial } -if [ "DOCKER_RM" = "true" ]; then +if [ "$SKIP_CLEANUP" != "true" ]; then trap cleanup EXIT fi