Merge lp:~michael.nelson/charm-helpers/ensure_etc_salt_exists into lp:charm-helpers

Proposed by Michael Nelson
Status: Merged
Merged at revision: 58
Proposed branch: lp:~michael.nelson/charm-helpers/ensure_etc_salt_exists
Merge into: lp:charm-helpers
Diff against target: 95 lines (+24/-4)
5 files modified
Makefile (+4/-0)
charmhelpers/contrib/saltstack/__init__.py (+5/-0)
tests/contrib/jujugui/test_utils.py (+2/-0)
tests/contrib/saltstack/test_saltstates.py (+5/-4)
tests/core/test_hookenv.py (+8/-0)
To merge this branch: bzr merge lp:~michael.nelson/charm-helpers/ensure_etc_salt_exists
Reviewer Review Type Date Requested Status
Matthew Wedgwood (community) Approve
Review via email: mp+170546@code.launchpad.net

Description of the change

When installing only the salt-common lib, the /etc/salt directory is not created (at least with the version I'm using from lamont).

This branch was just going to ensure that the dir exists before it writes out the grains for use in templates...

...but, while QAing this branch on my charm, I came across some changed behaviour in hookenv.relation_get(). When run in the context of no relation, it used to return None, now it returns Serializable(None).

What I was seeing was this http://paste.ubuntu.com/5783035/

So I added a test to demo the issue and fixed it. Just in terms of consistency, I'm not sure whether it's intended that hookenv.unit_get always returns a dict (result of json.loads) rather than a Serializable (when the result isn't None, that is).

Finally, I got sick of waiting for one specific test to finish when doing `make test`, so added `make ftest` for use while developing.

To post a comment you must log in.
Revision history for this message
Matthew Wedgwood (mew) wrote :

Hi, Michael,

Looks like stub's submitted an MP that removes the automatic decoration of those values with Serializable. I think that's a sensible solution and I think it should simplify things for you. That MP needs a bit of work before it can be merged.

If stub doesn't have the time to fix up the tests, I can probably get to that early next week.

Revision history for this message
Matthew Wedgwood (mew) wrote :

Because of r42, this needs rebasing to trunk.

review: Needs Fixing
37. By Michael Nelson

Merged trunk and resolved conflict.

38. By Michael Nelson

Removed an unnecessary change left from the merge.

39. By Michael Nelson

Remove no-longer-relevant test comment.

Revision history for this message
Michael Nelson (michael.nelson) wrote :

Thanks Matthew - just getting back from a week off. I've merged trunk and resolved the conflicts. Diff should look better now with r39.

I've left the new test in there that I added for hook_env, as I don't see another one there for relation_get returning None.

Revision history for this message
Michael Nelson (michael.nelson) wrote :

Ping? :)

Revision history for this message
Matthew Wedgwood (mew) wrote :

Thanks for the re-merge, Michael, and sorry for the delay. Looks good now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2013-06-27 15:59:39 +0000
3+++ Makefile 2013-07-09 10:04:27 +0000
4@@ -35,6 +35,10 @@
5 @echo Starting tests...
6 @$(PYTHON) /usr/bin/nosetests --nologcapture tests/
7
8+ftest:
9+ @echo Starting fast tests...
10+ @$(PYTHON) /usr/bin/nosetests --attr '!slow' --nologcapture tests/
11+
12 lint:
13 @echo Checking for Python syntax...
14 @flake8 --ignore=E123,E501 $(PROJECT) $(TESTS) && echo OK
15
16=== modified file 'charmhelpers/contrib/saltstack/__init__.py'
17--- charmhelpers/contrib/saltstack/__init__.py 2013-06-19 09:54:19 +0000
18+++ charmhelpers/contrib/saltstack/__init__.py 2013-07-09 10:04:27 +0000
19@@ -122,5 +122,10 @@
20 yaml.add_representer(unicode, lambda dumper,
21 value: dumper.represent_scalar(
22 u'tag:yaml.org,2002:str', value))
23+
24+ grains_dir = os.path.dirname(salt_grains_path)
25+ if not os.path.exists(grains_dir):
26+ os.makedirs(grains_dir)
27+
28 with open(salt_grains_path, "w+") as fp:
29 fp.write(config.yaml())
30
31=== modified file 'tests/contrib/jujugui/test_utils.py'
32--- tests/contrib/jujugui/test_utils.py 2013-05-19 18:17:25 +0000
33+++ tests/contrib/jujugui/test_utils.py 2013-07-09 10:04:27 +0000
34@@ -1,6 +1,7 @@
35 #!/usr/bin/env python2
36
37 from contextlib import contextmanager
38+import nose.plugins.attrib
39 import os
40 import shutil
41 from simplejson import dumps
42@@ -445,6 +446,7 @@
43 self.cert_file = os.path.join(self.cert_path, 'juju.crt')
44 self.key_file = os.path.join(self.cert_path, 'juju.key')
45
46+ @nose.plugins.attrib.attr('slow')
47 def test_generation(self):
48 # Ensure certificates are correctly generated.
49 save_or_create_certificates(
50
51=== modified file 'tests/contrib/saltstack/test_saltstates.py'
52--- tests/contrib/saltstack/test_saltstates.py 2013-06-19 19:09:31 +0000
53+++ tests/contrib/saltstack/test_saltstates.py 2013-07-09 10:04:27 +0000
54@@ -3,6 +3,8 @@
55 # Authors:
56 # Charm Helpers Developers <juju@lists.ubuntu.com>
57 import mock
58+import os
59+import shutil
60 import tempfile
61 import unittest
62 import yaml
63@@ -99,10 +101,9 @@
64 self.addCleanup(patcher.stop)
65
66 # patches specific to this test class.
67- grain_file = tempfile.NamedTemporaryFile()
68- self.grain_path = grain_file.name
69- self.addCleanup(grain_file.close)
70-
71+ etc_dir = tempfile.mkdtemp()
72+ self.addCleanup(shutil.rmtree, etc_dir)
73+ self.grain_path = os.path.join(etc_dir, 'salt', 'grains')
74 patcher = mock.patch.object(charmhelpers.contrib.saltstack,
75 'salt_grains_path', self.grain_path)
76 patcher.start()
77
78=== modified file 'tests/core/test_hookenv.py'
79--- tests/core/test_hookenv.py 2013-07-05 18:43:41 +0000
80+++ tests/core/test_hookenv.py 2013-07-09 10:04:27 +0000
81@@ -549,6 +549,14 @@
82 self.assertEqual(result['foo'], 'BAR')
83 check_output.assert_called_with(['relation-get', '--format=json', '-'])
84
85+ @patch('charmhelpers.core.hookenv.subprocess')
86+ def test_relation_get_none(self, mock_subprocess):
87+ mock_subprocess.check_output.return_value = 'null'
88+
89+ result = hookenv.relation_get()
90+
91+ self.assertIsNone(result)
92+
93 @patch('subprocess.check_output')
94 def test_gets_relation_with_scope(self, check_output):
95 check_output.return_value = json.dumps('bar')

Subscribers

People subscribed via source and target branches