← Back to team overview

cf-charmers team mailing list archive

[Merge] lp:~lomov-as/charm-helpers/cloud-foundry-fix into lp:~cf-charmers/charm-helpers/cloud-foundry

 

Alex Lomov has proposed merging lp:~lomov-as/charm-helpers/cloud-foundry-fix into lp:~cf-charmers/charm-helpers/cloud-foundry.

Requested reviews:
  Cloud Foundry Charmers (cf-charmers)

For more details, see:
https://code.launchpad.net/~lomov-as/charm-helpers/cloud-foundry-fix/+merge/220450

issue with interfaces with dashes in name

Names of interfaces in RelartionContext can contain dashes , but template variables are not allowed to have such names that's why I decided to replace dashes with underscores.
-- 
https://code.launchpad.net/~lomov-as/charm-helpers/cloud-foundry-fix/+merge/220450
Your team Cloud Foundry Charmers is requested to review the proposed merge of lp:~lomov-as/charm-helpers/cloud-foundry-fix into lp:~cf-charmers/charm-helpers/cloud-foundry.
=== modified file '.bzrignore'
--- .bzrignore	2014-05-09 02:08:58 +0000
+++ .bzrignore	2014-05-21 12:54:20 +0000
@@ -10,4 +10,5 @@
 .ropeproject/
 charmhelpers.egg-info/
 .DS_Store
-.tox/
\ No newline at end of file
+.tox/
+chdev/
\ No newline at end of file

=== modified file 'charmhelpers/core/templating.py'
--- charmhelpers/core/templating.py	2014-05-20 15:40:48 +0000
+++ charmhelpers/core/templating.py	2014-05-21 12:54:20 +0000
@@ -76,7 +76,7 @@
                 reldata = hookenv.relation_get(rid=rid, unit=unit)
                 required = set(self.required_keys)
                 if set(reldata.keys()).issuperset(required):
-                    ns = ctx.setdefault(self.interface, {})
+                    ns = ctx.setdefault(self.interface.replace('-', '_'), {})
                     for k, v in reldata.items():
                         ns[k] = v
                     return ctx

=== modified file 'tests/core/test_templating.py'
--- tests/core/test_templating.py	2014-05-16 21:48:06 +0000
+++ tests/core/test_templating.py	2014-05-21 12:54:20 +0000
@@ -184,12 +184,6 @@
         mhookenv.relation_ids.assert_called_once_with('http')
 
     @mock.patch.object(templating, 'hookenv')
-    def test_no_units(self, mhookenv):
-        mhookenv.relation_ids.return_value = ['nginx']
-        mhookenv.related_units.return_value = []
-        self.assertEqual(self.context_provider(), {})
-
-    @mock.patch.object(templating, 'hookenv')
     def test_incomplete(self, mhookenv):
         mhookenv.relation_ids.return_value = ['nginx', 'apache']
         mhookenv.related_units.side_effect = lambda i: [i+'/0']
@@ -211,3 +205,12 @@
             mock.call(rid='nginx', unit='nginx/0'),
             mock.call(rid='apache', unit='apache/0'),
         ])
+
+    @mock.patch.object(templating, 'hookenv')
+    def test_interface_name_with_dashes(self, mhookenv):
+        self.context_provider.interface = 'cf-mysql-service-broker'
+        mhookenv.relation_ids.return_value = ['cf-mysql-service-broker']
+        mhookenv.related_units.side_effect = lambda i: [i+'/0']
+        mhookenv.relation_get.side_effect = [{'foo': '1', 'bar': '2'}]
+        self.assertEqual(self.context_provider(), {'cf_mysql_service_broker': {'foo': '1', 'bar': '2'}})
+        # self.assertEqual(True, True)
\ No newline at end of file