Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(592)

Side by Side Diff: worker/uniter/uniter_test.go

Issue 8322043: state: add environment persistency with UUID (Closed)
Patch Set: state: add environment persistency with UUID Created 11 years, 12 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « worker/uniter/uniter.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package uniter_test 1 package uniter_test
2 2
3 import ( 3 import (
4 "bytes" 4 "bytes"
5 "crypto/sha256" 5 "crypto/sha256"
6 "encoding/hex" 6 "encoding/hex"
7 "fmt" 7 "fmt"
8 "io" 8 "io"
9 "io/ioutil" 9 "io/ioutil"
10 . "launchpad.net/gocheck" 10 . "launchpad.net/gocheck"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 102
103 func ut(summary string, steps ...stepper) uniterTest { 103 func ut(summary string, steps ...stepper) uniterTest {
104 return uniterTest{summary, steps} 104 return uniterTest{summary, steps}
105 } 105 }
106 106
107 type stepper interface { 107 type stepper interface {
108 step(c *C, ctx *context) 108 step(c *C, ctx *context)
109 } 109 }
110 110
111 type context struct { 111 type context struct {
112 » id int 112 » uuid string
113 path string 113 path string
114 dataDir string 114 dataDir string
115 s *UniterSuite 115 s *UniterSuite
116 st *state.State 116 st *state.State
117 charms coretesting.ResponseMap 117 charms coretesting.ResponseMap
118 hooks []string 118 hooks []string
119 sch *state.Charm 119 sch *state.Charm
120 svc *state.Service 120 svc *state.Service
121 unit *state.Unit 121 unit *state.Unit
122 uniter *uniter.Uniter 122 uniter *uniter.Uniter
(...skipping 11 matching lines...) Expand all
134 } 134 }
135 }() 135 }()
136 for i, s := range steps { 136 for i, s := range steps {
137 c.Logf("step %d", i) 137 c.Logf("step %d", i)
138 step(c, ctx, s) 138 step(c, ctx, s)
139 } 139 }
140 } 140 }
141 141
142 var goodHook = ` 142 var goodHook = `
143 #!/bin/bash 143 #!/bin/bash
144 juju-log UniterSuite-%d %s $JUJU_REMOTE_UNIT 144 juju-log $JUJU_ENV_UUID %s $JUJU_REMOTE_UNIT
145 `[1:] 145 `[1:]
146 146
147 var badHook = ` 147 var badHook = `
148 #!/bin/bash 148 #!/bin/bash
149 juju-log UniterSuite-%d fail-%s $JUJU_REMOTE_UNIT 149 juju-log $JUJU_ENV_UUID fail-%s $JUJU_REMOTE_UNIT
150 exit 1 150 exit 1
151 `[1:] 151 `[1:]
152 152
153 func (ctx *context) writeHook(c *C, path string, good bool) { 153 func (ctx *context) writeHook(c *C, path string, good bool) {
154 hook := badHook 154 hook := badHook
155 if good { 155 if good {
156 hook = goodHook 156 hook = goodHook
157 } 157 }
158 » content := fmt.Sprintf(hook, ctx.id, filepath.Base(path)) 158 » content := fmt.Sprintf(hook, filepath.Base(path))
159 err := ioutil.WriteFile(path, []byte(content), 0755) 159 err := ioutil.WriteFile(path, []byte(content), 0755)
160 c.Assert(err, IsNil) 160 c.Assert(err, IsNil)
161 } 161 }
162 162
163 func (ctx *context) matchLogHooks(c *C) (match bool, overshoot bool) { 163 func (ctx *context) matchLogHooks(c *C) (match bool, overshoot bool) {
164 // hookPattern matches juju-log calls as generated by writeHook. 164 // hookPattern matches juju-log calls as generated by writeHook.
165 hookPattern := fmt.Sprintf(`^.* INFO `+ 165 hookPattern := fmt.Sprintf(`^.* INFO `+
166 `u/0(| [a-z0-9-]+:[0-9]+)`+ // juju-log badge; group matches rel ation id 166 `u/0(| [a-z0-9-]+:[0-9]+)`+ // juju-log badge; group matches rel ation id
167 » » `: UniterSuite-%d`+ // test badge; prevents cross-pollution 167 » » `: %s`+ // JUJU_ENV_UUID (context badge; prevents cross-test pol lution)
168 ` ([0-9a-z-/ ]+)$`, // foo-relation-joined bar/123 168 ` ([0-9a-z-/ ]+)$`, // foo-relation-joined bar/123
169 » » ctx.id, 169 » » ctx.uuid,
170 ) 170 )
171 // donePattern matches uniter logging that indicates a hook has run. 171 // donePattern matches uniter logging that indicates a hook has run.
172 donePattern := `^.* (INFO|ERROR) worker/uniter: (ran "[a-z0-9-]+" hook|h ook failed)` 172 donePattern := `^.* (INFO|ERROR) worker/uniter: (ran "[a-z0-9-]+" hook|h ook failed)`
173 hookRegexp := regexp.MustCompile(hookPattern) 173 hookRegexp := regexp.MustCompile(hookPattern)
174 doneRegexp := regexp.MustCompile(donePattern) 174 doneRegexp := regexp.MustCompile(donePattern)
175 175
176 // pending is empty while we scan for a new hook, and holds a value whil e 176 // pending is empty while we scan for a new hook, and holds a value whil e
177 // we scan for output indicating that hook execution has finished; at wh ich 177 // we scan for output indicating that hook execution has finished; at wh ich
178 // point, we add it to... 178 // point, we add it to...
179 pending := "" 179 pending := ""
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 827
828 func (s *UniterSuite) TestUniterSubordinates(c *C) { 828 func (s *UniterSuite) TestUniterSubordinates(c *C) {
829 s.runUniterTests(c, subordinatesTests) 829 s.runUniterTests(c, subordinatesTests)
830 } 830 }
831 831
832 func (s *UniterSuite) runUniterTests(c *C, uniterTests []uniterTest) { 832 func (s *UniterSuite) runUniterTests(c *C, uniterTests []uniterTest) {
833 for i, t := range uniterTests { 833 for i, t := range uniterTests {
834 c.Logf("\ntest %d: %s\n", i, t.summary) 834 c.Logf("\ntest %d: %s\n", i, t.summary)
835 func() { 835 func() {
836 defer s.Reset(c) 836 defer s.Reset(c)
837 env, err := s.State.Environment()
838 c.Assert(err, IsNil)
837 ctx := &context{ 839 ctx := &context{
838 s: s, 840 s: s,
839 st: s.State, 841 st: s.State,
840 » » » » id: i, 842 » » » » uuid: env.UUID(),
841 path: s.unitDir, 843 path: s.unitDir,
842 dataDir: s.dataDir, 844 dataDir: s.dataDir,
843 charms: coretesting.ResponseMap{}, 845 charms: coretesting.ResponseMap{},
844 } 846 }
845 ctx.run(c, t.steps) 847 ctx.run(c, t.steps)
846 }() 848 }()
847 } 849 }
848 } 850 }
849 851
850 func (s *UniterSuite) TestSubordinateDying(c *C) { 852 func (s *UniterSuite) TestSubordinateDying(c *C) {
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 newmeta, err := goyaml.Marshal(meta) 1630 newmeta, err := goyaml.Marshal(meta)
1629 c.Assert(err, IsNil) 1631 c.Assert(err, IsNil)
1630 ioutil.WriteFile(path, newmeta, 0644) 1632 ioutil.WriteFile(path, newmeta, 0644)
1631 1633
1632 f, err = os.Open(path) 1634 f, err = os.Open(path)
1633 c.Assert(err, IsNil) 1635 c.Assert(err, IsNil)
1634 defer f.Close() 1636 defer f.Close()
1635 meta, err = charm.ReadMeta(f) 1637 meta, err = charm.ReadMeta(f)
1636 c.Assert(err, IsNil) 1638 c.Assert(err, IsNil)
1637 } 1639 }
OLDNEW
« no previous file with comments | « worker/uniter/uniter.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b