MCPcopy
hub / github.com/purpleidea/mgmt / SimpleDeployLang

Method SimpleDeployLang

integration/patterns.go:98–147  ·  view source on GitHub ↗

SimpleDeployLang is a helper method that takes a struct representing a cluster and runs a sequence of methods on it. This particular helper starts up a series of instances linearly, deploys some code, and then shuts down. Both after initially starting up, after peering each instance, and after deplo

(code string)

Source from the content-addressed store, hash-verified

96// Both after initially starting up, after peering each instance, and after
97// deploy, it waits for the instance to converge before running the next step.
98func (obj *Cluster) SimpleDeployLang(code string) error {
99 if err := obj.Init(); err != nil {
100 return errwrap.Wrapf(err, "could not init instance")
101 }
102 defer obj.Close() // clean up working directories
103
104 // start the cluster
105 if err := obj.RunLinear(); err != nil {
106 return errwrap.Wrapf(err, "mgmt could not start")
107 }
108 defer obj.Kill() // do a kill -9
109
110 // wait for an internal converge signal as a baseline
111 // FIXME: add this wait if we remove it from RunLinear
112 //{
113 // ctx, cancel := context.WithTimeout(context.Background(), time.Duration(longTimeout*len(obj.Hostnames))*time.Second)
114 // defer cancel()
115 // if err := obj.Wait(ctx); err != nil { // wait to get a converged signal
116 // return errwrap.Wrapf(err, "mgmt initial wait failed") // timeout expired
117 // }
118 //}
119
120 // push a deploy
121 if err := obj.DeployLang(code); err != nil {
122 return errwrap.Wrapf(err, "mgmt could not deploy")
123 }
124
125 // wait for an internal converge signal
126 {
127 ctx, cancel := context.WithTimeout(context.Background(), time.Duration(longTimeout*len(obj.Hostnames))*time.Second)
128 defer cancel()
129 if err := obj.WaitForConvergedAfterActivity(ctx); err != nil { // wait to get a converged signal
130 return errwrap.Wrapf(err, "mgmt post-deploy wait failed") // timeout expired
131 }
132 }
133
134 // press ^C
135 {
136 ctx, cancel := context.WithTimeout(context.Background(), time.Duration(longTimeout*len(obj.Hostnames))*time.Second)
137 defer cancel()
138 if err := obj.Quit(ctx); err != nil {
139 if err == context.DeadlineExceeded {
140 return errwrap.Wrapf(err, "mgmt blocked on exit")
141 }
142 return errwrap.Wrapf(err, "mgmt exited with error")
143 }
144 }
145
146 return nil
147}

Callers 1

TestCluster1Function · 0.95

Calls 9

InitMethod · 0.95
CloseMethod · 0.95
RunLinearMethod · 0.95
KillMethod · 0.95
DeployLangMethod · 0.95
QuitMethod · 0.95
WrapfFunction · 0.92
BackgroundMethod · 0.65

Tested by 1

TestCluster1Function · 0.76