Merge lp:~benji/charmworld/1263120-allow-self-referential-relations-in-bundles into lp:charmworld

Proposed by Benji York
Status: Merged
Approved by: Benji York
Approved revision: 478
Merged at revision: 479
Proposed branch: lp:~benji/charmworld/1263120-allow-self-referential-relations-in-bundles
Merge into: lp:charmworld
Diff against target: 122 lines (+70/-6)
3 files modified
charmworld/lib/proof.py (+3/-0)
charmworld/lib/tests/test_proof.py (+30/-4)
charmworld/views/tests/test_proof.py (+37/-2)
To merge this branch: bzr merge lp:~benji/charmworld/1263120-allow-self-referential-relations-in-bundles
Reviewer Review Type Date Requested Status
Kapil Thangavelu (community) Disapprove
Juju Gui Bot continuous-integration Approve
Review via email: mp+202373@code.launchpad.net

Commit message

Add a very useful hint about relation ordering.

Description of the change

Add a very useful hint about relation ordering.

https://codereview.appspot.com/54560044/

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :
Download full text (4.4 KiB)

Reviewers: mp+202373_code.launchpad.net,

Message:
Please take a look.

Description:
Add a very useful hint about relation ordering.

https://code.launchpad.net/~benji/charmworld/1263120-allow-self-referential-relations-in-bundles/+merge/202373

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/54560044/

Affected files (+44, -7 lines):
   A [revision details]
   M charmworld/lib/proof.py
   M charmworld/lib/tests/test_proof.py
   M charmworld/views/tests/test_proof.py

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-20140117153416-xbkyontzme0m6h82
+New revision: <email address hidden>

Index: charmworld/lib/proof.py
=== modified file 'charmworld/lib/proof.py'
--- charmworld/lib/proof.py 2014-01-13 18:31:15 +0000
+++ charmworld/lib/proof.py 2014-01-20 20:33:00 +0000
@@ -91,7 +91,8 @@
      if not exist or not same_type:
          # Then this definition is invalid.
          msg = ('The requested relation %s to %s is incompatible between '
- 'services.')
+ 'services. Hint: if order of the relation were reversed
it '
+ 'would be valid.')
          raise ProofError(
              [('Endpoints are the same type on both services? ' +
                str(same_type)), ],

Index: charmworld/lib/tests/test_proof.py
=== modified file 'charmworld/lib/tests/test_proof.py'
--- charmworld/lib/tests/test_proof.py 2014-01-13 18:31:15 +0000
+++ charmworld/lib/tests/test_proof.py 2014-01-20 20:45:50 +0000
@@ -308,10 +308,9 @@
                  requires,
                  provides)

- msg = ('The requested relation db to cache is incompatible
between '
- 'services.')
- self.assertEqual(
- msg,
+ self.assertIn(
+ 'The requested relation db to cache is incompatible between '
+ 'services.',
              exc.exception.msg
          )
          self.assertEqual(

Index: charmworld/views/tests/test_proof.py
=== modified file 'charmworld/views/tests/test_proof.py'
--- charmworld/views/tests/test_proof.py 2014-01-14 19:24:49 +0000
+++ charmworld/views/tests/test_proof.py 2014-01-20 20:33:00 +0000
@@ -12,8 +12,8 @@
      """Verify that a bundle can be proofed in charmworld."""

      def setup_relatable_charms(self, second_requires, second_provides):
- # The default charm provides website:https and requires
- # database:mongodb
+ # Unless otherwise specified, the generated charm provides
+ # website:https and requires database:mongodb.
          _id, charm_one = factory.makeCharm(
              self.db,
              description='',
@@ -278,6 +278,41 @@
              'wiki: The requested relation db to proxy is incompatible',
              response.json_body['error_messages'][0])

+ def test_reverse_relation_order(self):
+ # Relations must be provided in (provides, requires) order. If a
+ # reverse relation would have worked, a nice error message tells
you
+ # so.
+ ...

Read more...

Revision history for this message
Richard Harding (rharding) wrote :

LGTM with the one question on the assumption in the hint.

https://codereview.appspot.com/54560044/diff/1/charmworld/lib/proof.py
File charmworld/lib/proof.py (right):

https://codereview.appspot.com/54560044/diff/1/charmworld/lib/proof.py#newcode96
charmworld/lib/proof.py:96: raise ProofError(
Doesn't this hint need to account for the case of non matching types?

https://codereview.appspot.com/54560044/

Revision history for this message
Benji York (benji) wrote :
Revision history for this message
Benji York (benji) wrote :

Fixed bug found in review.

https://codereview.appspot.com/54560044/diff/1/charmworld/lib/proof.py
File charmworld/lib/proof.py (right):

https://codereview.appspot.com/54560044/diff/1/charmworld/lib/proof.py#newcode96
charmworld/lib/proof.py:96: raise ProofError(
On 2014/01/20 20:53:31, rick.harding wrote:
> Doesn't this hint need to account for the case of non matching types?

Indeed! I've fixed this and added a test.

https://codereview.appspot.com/54560044/

Revision history for this message
Juju Gui Bot (juju-gui-bot) wrote :

FAILED: Autolanding.
No commit message was specified in the merge proposal. Hit 'Add commit message' on the merge proposal web page or follow the link below. You can approve the merge proposal yourself to rerun.
https://code.launchpad.net/~benji/charmworld/1263120-allow-self-referential-relations-in-bundles/+merge/202373/+edit-commit-message

review: Needs Fixing (continuous-integration)
Revision history for this message
Juju Gui Bot (juju-gui-bot) :
review: Approve (continuous-integration)
Revision history for this message
Kapil Thangavelu (hazmat) wrote :

order within a relation doesn't matter.

review: Disapprove
Revision history for this message
Benji York (benji) wrote :

Changing proof's behavior would be fine, but this branch doesn't introduce the behavior in question (requiring a particular order for relations) it only reports it to the user better.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmworld/lib/proof.py'
2--- charmworld/lib/proof.py 2014-01-13 18:31:15 +0000
3+++ charmworld/lib/proof.py 2014-01-21 13:47:04 +0000
4@@ -92,6 +92,9 @@
5 # Then this definition is invalid.
6 msg = ('The requested relation %s to %s is incompatible between '
7 'services.')
8+ if reversed:
9+ msg += ('Hint: if order of the relation were reversed it '
10+ 'would be valid.')
11 raise ProofError(
12 [('Endpoints are the same type on both services? ' +
13 str(same_type)), ],
14
15=== modified file 'charmworld/lib/tests/test_proof.py'
16--- charmworld/lib/tests/test_proof.py 2014-01-13 18:31:15 +0000
17+++ charmworld/lib/tests/test_proof.py 2014-01-21 13:47:04 +0000
18@@ -308,10 +308,9 @@
19 requires,
20 provides)
21
22- msg = ('The requested relation db to cache is incompatible between '
23- 'services.')
24- self.assertEqual(
25- msg,
26+ self.assertIn(
27+ 'The requested relation db to cache is incompatible between '
28+ 'services.',
29 exc.exception.msg
30 )
31 self.assertEqual(
32@@ -319,6 +318,33 @@
33 exc.exception.debug_info[0]
34 )
35
36+ def test_including_hint_when_relation_direction_is_reversed(self):
37+ # If the relation is not valid, but would have been if the direction
38+ # of the relation had been reversed, then a helpful hint is included
39+ # in the exception.
40+
41+ # If these two were reversed, the relation would have been valid.
42+ check_requires = 'cache'
43+ check_provides = 'website'
44+
45+ requires = {'website': {'interface': 'http'}}
46+ provides = {'cache': {'interface': 'http'}}
47+
48+ with self.assertRaises(ProofError) as exc:
49+ verify_points_exist_and_same_type(
50+ check_requires, check_provides, requires, provides)
51+
52+ # Since the relations are reversed, a hint is given.
53+ self.assertIn(
54+ 'Hint: if order of the relation were reversed it would be valid.',
55+ exc.exception.msg
56+ )
57+ # The normal incompatability message is included too.
58+ self.assertIn(
59+ 'The requested relation cache to website is incompatible',
60+ exc.exception.msg
61+ )
62+
63 def test_valid_fully_qualified_endpoints(self):
64 # relation = ['wiki:website', 'haproxy:cache']
65 check_requires = 'website'
66
67=== modified file 'charmworld/views/tests/test_proof.py'
68--- charmworld/views/tests/test_proof.py 2014-01-14 19:24:49 +0000
69+++ charmworld/views/tests/test_proof.py 2014-01-21 13:47:04 +0000
70@@ -12,8 +12,8 @@
71 """Verify that a bundle can be proofed in charmworld."""
72
73 def setup_relatable_charms(self, second_requires, second_provides):
74- # The default charm provides website:https and requires
75- # database:mongodb
76+ # Unless otherwise specified, the generated charm provides
77+ # website:https and requires database:mongodb.
78 _id, charm_one = factory.makeCharm(
79 self.db,
80 description='',
81@@ -278,6 +278,41 @@
82 'wiki: The requested relation db to proxy is incompatible',
83 response.json_body['error_messages'][0])
84
85+ def test_reverse_relation_order(self):
86+ # Relations must be provided in (provides, requires) order. If a
87+ # reverse relation would have worked, a nice error message tells you
88+ # so.
89+ one_store_url, two_store_url = self.setup_relatable_charms(
90+ {}, {'db': {'interface': 'mongodb'}})
91+
92+ bundle_base = dedent("""\
93+ wiki:
94+ series: precise
95+ promulgated: True
96+ services:
97+ wiki:
98+ charm: {}
99+ db:
100+ charm: {}
101+ relations:
102+ - ["db:db", "wiki:database"]
103+ """.format(one_store_url, two_store_url))
104+
105+ request = self.make_request('bundle', remainder='/proof')
106+ request.params = {
107+ 'deployer_file': bundle_base
108+ }
109+ response = self.api_class(request)()
110+ self.assertEqual(200, response.status_code)
111+ error_messages = response.json_body['error_messages']
112+ self.assertEqual(1, len(error_messages))
113+ self.assertIn(
114+ 'wiki: The requested relation db to database is incompatible',
115+ error_messages[0])
116+ self.assertIn(
117+ 'Hint: if order of the relation were reversed it would be valid.',
118+ error_messages[0])
119+
120 def test_bundle_proof_passes_with_valid_relations(self):
121 one_store_url, two_store_url = self.setup_relatable_charms(
122 {

Subscribers

People subscribed via source and target branches

to all changes: