Merge ~addyess/charm-thruk-agent:bug/1887602 into charm-thruk-agent:master

Proposed by Adam Dyess
Status: Merged
Approved by: Chris Sanders
Approved revision: 3b77816c53b0c353acb955ce761ce03f2b17cfed
Merged at revision: 3b77816c53b0c353acb955ce761ce03f2b17cfed
Proposed branch: ~addyess/charm-thruk-agent:bug/1887602
Merge into: charm-thruk-agent:master
Diff against target: 101 lines (+27/-21)
6 files modified
hooks/actions.py (+1/-0)
hooks/setup.py (+1/-2)
hooks/upgrade-charm (+1/-1)
hooks/upgrade_charm.py (+14/-0)
tests/unit/conftest.py (+5/-0)
tests/unit/test_actions.py (+5/-18)
Reviewer Review Type Date Requested Status
Chris Sanders (community) Approve
Review via email: mp+387409@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Adam Dyess (addyess) wrote :
Revision history for this message
Chris Sanders (chris.sanders) wrote :

one comment inline

review: Needs Fixing
Revision history for this message
Chris Sanders (chris.sanders) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/hooks/actions.py b/hooks/actions.py
2index 00f8eb5..f5f728b 100644
3--- a/hooks/actions.py
4+++ b/hooks/actions.py
5@@ -6,6 +6,7 @@ import stat
6 import subprocess
7 import sys
8
9+
10 from charmhelpers.core import hookenv
11 from charmhelpers.fetch import (
12 add_source, apt_install, apt_update,
13diff --git a/hooks/setup.py b/hooks/setup.py
14index a222cb3..433e5b5 100644
15--- a/hooks/setup.py
16+++ b/hooks/setup.py
17@@ -9,8 +9,7 @@ def install_charmhelpers():
18 import enum # noqa
19 except ImportError:
20 import subprocess
21- subprocess.check_call(['apt-get', 'install', '-y', 'python-pip'])
22- subprocess.check_call(['pip', 'install', 'enum34'])
23+ subprocess.check_call(['apt-get', 'install', '-y', 'python-enum34'])
24
25 try:
26 import charmhelpers # noqa
27diff --git a/hooks/upgrade-charm b/hooks/upgrade-charm
28index 9416ca6..d378ed9 120000
29--- a/hooks/upgrade-charm
30+++ b/hooks/upgrade-charm
31@@ -1 +1 @@
32-hooks.py
33\ No newline at end of file
34+upgrade_charm.py
35\ No newline at end of file
36diff --git a/hooks/upgrade_charm.py b/hooks/upgrade_charm.py
37new file mode 100755
38index 0000000..195e5ec
39--- /dev/null
40+++ b/hooks/upgrade_charm.py
41@@ -0,0 +1,14 @@
42+#!/usr/bin/python
43+
44+import sys
45+
46+import setup
47+setup.pre_install()
48+
49+from hooks import hookenv, hooks # noqa: E402, I100
50+
51+if __name__ == '__main__':
52+ try:
53+ hooks.execute(sys.argv)
54+ except hookenv.UnregisteredHookError as e:
55+ hookenv.log('Unknown hook {} - skipping.'.format(e))
56diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py
57new file mode 100644
58index 0000000..0f063b7
59--- /dev/null
60+++ b/tests/unit/conftest.py
61@@ -0,0 +1,5 @@
62+import sys
63+from pkg_resources import resource_filename
64+
65+# allow importing actions from the hooks directory
66+sys.path.append(resource_filename(__name__, '../../hooks'))
67diff --git a/tests/unit/test_actions.py b/tests/unit/test_actions.py
68index 52ba4cd..5f5f3f3 100755
69--- a/tests/unit/test_actions.py
70+++ b/tests/unit/test_actions.py
71@@ -1,25 +1,12 @@
72 #!/usr/bin/env python
73
74-import sys
75 import unittest
76 import unittest.mock as mock
77-
78-from pkg_resources import resource_filename
79-
80-# allow importing actions from the hooks directory
81-sys.path.append(resource_filename(__name__, '../../hooks'))
82 import actions # noqa
83
84
85-class TestActions(unittest.TestCase):
86- """Tests for charm actions."""
87-
88- @mock.patch('charmhelpers.core.hookenv.log')
89- def test_log_start(self, log):
90- """Test the log-start action."""
91- actions.log_start('test-service')
92- log.assert_called_once_with('thruk-agent starting')
93-
94-
95-if __name__ == '__main__':
96- unittest.main()
97+@mock.patch('charmhelpers.core.hookenv.log')
98+def test_log_start(log):
99+ """Test the log-start action."""
100+ actions.log_start('test-service')
101+ log.assert_called_once_with('thruk-agent starting')

Subscribers

People subscribed via source and target branches

to all changes: