Merge lp:~michael.nelson/juju-core/1205466-remove-charm-on-destroy-service into lp:~go-bot/juju-core/trunk

Proposed by Michael Nelson
Status: Work in progress
Proposed branch: lp:~michael.nelson/juju-core/1205466-remove-charm-on-destroy-service
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 87 lines (+40/-0)
4 files modified
state/charm.go (+18/-0)
state/conn_test.go (+4/-0)
state/service.go (+2/-0)
state/service_test.go (+16/-0)
To merge this branch: bzr merge lp:~michael.nelson/juju-core/1205466-remove-charm-on-destroy-service
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+179010@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

1610. By Michael Nelson

GREEN: charms are deleted from state with destroy service.

1609. By Michael Nelson

RED: charms are deleted from state with destroy service.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'state/charm.go'
2--- state/charm.go 2013-07-09 10:32:23 +0000
3+++ state/charm.go 2013-08-07 16:06:31 +0000
4@@ -6,6 +6,8 @@
5 import (
6 "net/url"
7
8+ "labix.org/v2/mgo/txn"
9+
10 "launchpad.net/juju-core/charm"
11 )
12
13@@ -64,3 +66,19 @@
14 func (c *Charm) BundleSha256() string {
15 return c.doc.BundleSha256
16 }
17+
18+// removeCharmsOps returns the operations require to remove all versions
19+// of charms with the given name.
20+func removeCharmsOps(st *State, name string) []txn.Op {
21+ ops := []txn.Op{}
22+ var cdoc charmDoc
23+ iter := st.charms.Find(D{{"meta.name", name}}).Iter()
24+ for iter.Next(&cdoc) {
25+ ops = append(ops, txn.Op{
26+ C: st.charms.Name,
27+ Id: cdoc.URL.String(),
28+ Remove: true,
29+ })
30+ }
31+ return ops
32+}
33
34=== modified file 'state/conn_test.go'
35--- state/conn_test.go 2013-07-09 10:32:23 +0000
36+++ state/conn_test.go 2013-08-07 16:06:31 +0000
37@@ -64,6 +64,10 @@
38 return state.AddTestingCharm(c, s.State, name)
39 }
40
41+func (s *ConnSuite) AddTestingCharmRev(c *C, name string, rev int) *state.Charm {
42+ return state.AddCustomCharm(c, s.State, name, "", "", "series", rev)
43+}
44+
45 func (s *ConnSuite) AddSeriesCharm(c *C, name, series string) *state.Charm {
46 return state.AddCustomCharm(c, s.State, name, "", "", series, -1)
47 }
48
49=== modified file 'state/service.go'
50--- state/service.go 2013-07-30 14:00:53 +0000
51+++ state/service.go 2013-08-07 16:06:31 +0000
52@@ -223,6 +223,8 @@
53 Id: s.settingsKey(),
54 Remove: true,
55 }}
56+
57+ ops = append(ops, removeCharmsOps(s.st, s.doc.Name)...)
58 ops = append(ops, removeConstraintsOp(s.st, s.globalKey()))
59 return append(ops, annotationRemoveOp(s.st, s.globalKey()))
60 }
61
62=== modified file 'state/service_test.go'
63--- state/service_test.go 2013-07-18 16:46:59 +0000
64+++ state/service_test.go 2013-08-07 16:06:31 +0000
65@@ -905,6 +905,22 @@
66 c.Assert(err, checkers.Satisfies, errors.IsNotFoundError)
67 }
68
69+func (s *ServiceSuite) TestDestroyRemovesCharms(c *C) {
70+ s.charm = s.AddTestingCharmRev(c, "mysql", 2)
71+ // XXX: It'd be nicer to test with a third charm here
72+ // ensuring that it's not deleted. But including the
73+ // following line results in: http://paste.ubuntu.com/5958918/
74+ // s.charm = s.AddTestingCharm(c, "other")
75+ count, err := s.charms.Find(D{{}}).Count()
76+ c.Assert(count, Equals, 2)
77+
78+ err = s.mysql.Destroy()
79+ c.Assert(err, IsNil)
80+
81+ count, err = s.charms.Find(D{{}}).Count()
82+ c.Assert(count, Equals, 0)
83+}
84+
85 func (s *ServiceSuite) TestDestroyStillHasUnits(c *C) {
86 unit, err := s.mysql.AddUnit()
87 c.Assert(err, IsNil)

Subscribers

People subscribed via source and target branches

to status/vote changes: