Merge lp:~evarlast/charms/trusty/apache2/trunk into lp:charms/trusty/apache2

Proposed by Jay R. Wren
Status: Merged
Merged at revision: 69
Proposed branch: lp:~evarlast/charms/trusty/apache2/trunk
Merge into: lp:charms/trusty/apache2
Diff against target: 192 lines (+69/-10)
5 files modified
Makefile (+14/-3)
config.yaml (+13/-0)
hooks/hooks.py (+28/-1)
hooks/tests/test_balancer_hook.py (+13/-6)
hooks/tests/test_config_changed.py (+1/-0)
To merge this branch: bzr merge lp:~evarlast/charms/trusty/apache2/trunk
Reviewer Review Type Date Requested Status
Kevin W Monroe Approve
Jay R. Wren (community) Needs Resubmitting
Andrew McLeod (community) Needs Fixing
Adam Israel (community) Needs Fixing
Review Queue (community) automated testing Needs Fixing
Review via email: mp+278220@code.launchpad.net

Description of the change

Add apt config options to allow apache2 to be installed from a PPA. This enabled use of http2 supporting apache.

To post a comment you must log in.
69. By Jay R. Wren

do not enable http2 by default

Revision history for this message
Review Queue (review-queue) wrote :

This item has failed automated testing! Results available here http://juju-ci.vapour.ws:8080/job/charm-bundle-test-lxc/1486/

review: Needs Fixing (automated testing)
Revision history for this message
Review Queue (review-queue) wrote :

This item has failed automated testing! Results available here http://juju-ci.vapour.ws:8080/job/charm-bundle-test-aws/1469/

review: Needs Fixing (automated testing)
Revision history for this message
Andrew McLeod (admcleod) wrote :

Hi Jay,

In order to confirm your changes are fully functional, I've attempted to run bundletester (bundletester -e $AWS -l DEBUG -vF) on this.

It appears that there are initial failures related to apt-source, but because of the 'F' I see that there are also older issues related to assert_called_once (see: https://bugs.launchpad.net/charms/+source/apache2/+bug/1511474)

Unfortunately because tests are failing (as noted by the automated testing also) I can't approve this - however, perhaps they're passing for you? If so can you tell me more about your environment so I can try to replicate it - I'm using trusty.

Thanks!
Andrew

review: Needs Fixing
Revision history for this message
Andrew McLeod (admcleod) wrote :

Jay,

I've just seen another RQ item from you where you've fixed some of those assert_called_once errors, but still failing on the following:

http://pastebin.ubuntu.com/13898257/

I've put this same pastebin in your other RQ item.

Andrew

review: Needs Fixing
Revision history for this message
Adam Israel (aisrael) wrote :

Hi Jay,

Just following up from our conversation on IRC yesterday. There are some failing tests here that are in the upstream, but new failing tests are introduced with this merge. Specifically:

======================================================================
ERROR: tests.test_balancer_hook.HooksTest.test_installs_hook
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "/tmp/bundletester-ylCDXc/apache2/.venv/local/lib/python2.7/site-packages/mock/mock.py", line 1305, in patched
    return func(*args, **keywargs)
  File "/tmp/bundletester-ylCDXc/apache2/hooks/tests/test_balancer_hook.py", line 512, in test_installs_hook
    result = hooks.install_hook()
  File "/tmp/bundletester-ylCDXc/apache2/hooks/hooks.py", line 294, in install_hook
    open('config.apt-source', 'w').write(apt_source)
TypeError: expected a character buffer object

======================================================================
ERROR: tests.test_config_changed.ConfigChangedTest.test_config_changed_ensure_empty_site_dir
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "/tmp/bundletester-ylCDXc/apache2/.venv/local/lib/python2.7/site-packages/mock/mock.py", line 1305, in patched
    return func(*args, **keywargs)
  File "/tmp/bundletester-ylCDXc/apache2/hooks/tests/test_config_changed.py", line 76, in test_config_changed_ensure_empty_site_dir
    hooks.config_changed()
  File "/tmp/bundletester-ylCDXc/apache2/hooks/hooks.py", line 602, in config_changed
    apt_source = config_data['apt-source']
KeyError: 'apt-source'

review: Needs Fixing
70. By Jay R. Wren

fix tests which I broke

Revision history for this message
Jay R. Wren (evarlast) wrote :

Thanks for this. I think I have fixed the required tests.

Please take another look.

Revision history for this message
Haw Loeung (hloeung) wrote :

These are pretty bad defaults. We're adding the http://ppa.launchpad.net/ondrej/apache2/ubuntu PPA and keys?

I think the defaults for apt-key-id and apt-source should be empty.

Revision history for this message
Jay R. Wren (evarlast) wrote :

Indeed! I intended them to be empty. Thank Haw.

71. By Jay R. Wren

default apt-key-id and apt-source to empty string

Revision history for this message
Andrew McLeod (admcleod) wrote :

Hi Jay,

There are still tests failing (http://pastebin.ubuntu.com/15017349/) and some of these are the ones Adam pasted further up in this thread. I'm trying to recall if we discussed similar failing tests in another thread. I ran these tests in a charmbox on AWS, perhaps this is unique to my environment?

review: Needs Fixing
Revision history for this message
Jay R. Wren (evarlast) wrote :

Maybe someone can help me out with what changes in this MR cause these
tests to fail?

On Thu, Feb 11, 2016 at 6:01 PM, Andrew McLeod
<email address hidden> wrote:
> Review: Needs Fixing
>
> Hi Jay,
>
> There are still tests failing (http://pastebin.ubuntu.com/15017349/) and some of these are the ones Adam pasted further up in this thread. I'm trying to recall if we discussed similar failing tests in another thread. I ran these tests in a charmbox on AWS, perhaps this is unique to my environment?
> --
> https://code.launchpad.net/~evarlast/charms/trusty/apache2/trunk/+merge/278220
> You are the owner of lp:~evarlast/charms/trusty/apache2/trunk.

Revision history for this message
Kevin W Monroe (kwmonroe) wrote :

Hey Jay - it's likely that nothing you did in this MP caused these failures. In fact, I'm quite certain that the 'assert_called_once' failures are happening because 'make test' is pulling in a newer version of mock (v1.3.0) that is more strict about mock'd methods [0].

That said, I agree with Andrew's desire to get tests passing before committing updates to a charm as important as apache2. If you have ideas on how to fix these test issues (even though you didn't introduce them), that would be much appreciated. If not, please at least hit the 'affects me too' on bug [0] to raise the heat.

Meanwhile, I'll try to poke on a test refactor to get around the assert_called_once errors, but we'll still need to dig into the other failures Andrew found in his latest pastebin.

[0] - https://bugs.launchpad.net/charms/+source/apache2/+bug/1511474

Revision history for this message
Kevin W Monroe (kwmonroe) wrote :

Hey Jay! I didn't realize when I pointed you at bug 1511474 that you already fixed it way back in November (which made it in with your add-logs-interface merge to apache2 today [0]).

That clears up all the apache2 errors that weren't your fault, but we're not out of the woods yet :) 'make test' with these changes merged into the new apache2 trunk branch yields:

======================================================================
ERROR: tests.test_config_changed.ConfigChangedTest.test_config_changed_ensure_empty_site_dir
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "/tmp/bundletester-0mKWLv/apache2/.venv/local/lib/python2.7/site-packages/mock/mock.py", line 1305, in patched
    return func(*args, **keywargs)
  File "/tmp/bundletester-0mKWLv/apache2/hooks/tests/test_config_changed.py", line 81, in test_config_changed_ensure_empty_site_dir
    hooks.config_changed()
  File "/tmp/bundletester-0mKWLv/apache2/hooks/hooks.py", line 604, in config_changed
    old_apt_source = open('config.apt-source', 'r').read()
IOError: [Errno 2] No such file or directory: 'config.apt-source'

This happens because install_hook() is the only place config.apt-source is written, and we're not invoking that in test_config_changed.py. You could mock a bunch of stuff out to handle that (like open and whatever subprocess stuff happens in config_changed), but but do you think it would be easier to alter your diff with a try/except during config_changed() in hooks.py?

...
     relationship_data = {}
     config_data = config_get()

+ apt_source = config_data['apt-source']
+ try:
+ old_apt_source = open('config.apt-source', 'r').read()
+ except IOError:
+ # File may not exist if install hook hasn't run (unlikely) or during
+ # ./hooks/tests/test-config-changed.py. Either way, it is safe to
+ # assume if this file DNE, our old apt source == current apt config.
+ old_apt_source = apt_source
...

In the same method, do you need to write the new repo config to the config.apt-source file? Altering your diff like:

+ if old_apt_source != apt_source:
+ subprocess.check_call(['add-apt-repository', '--yes', '-r',
+ old_apt_source])
+ add_source(apt_source, config_data['apt-key-id'])
+ open('config.apt-source', 'w+').write(apt_source)

Otherwise, I don't think your "old_apt_source != apt_source" test will be accurate after changing that config.

One last morsel of awesome, test_config_changed.py needs to close the hookenv.Config with a paren:

- }
+ "apt-source": "",
+ })

I know this MP has been a long time coming, and I *really* appreciate the fixes to apache2/trunk that you didn't cause. I think we're close with this one, but I want to get your input on these last few concerns of mine. Thanks!!

[0] - https://code.launchpad.net/~evarlast/charms/trusty/apache2/add-logs-interface/+merge/278222

Revision history for this message
Kevin W Monroe (kwmonroe) :
review: Needs Information
72. By Jay R. Wren

fix config changed handling of apt-source

Revision history for this message
Jay R. Wren (evarlast) wrote :

Great catch @kevin.

I've updated to include suggested fixes.

review: Needs Resubmitting
73. By Jay R. Wren

merge parent

74. By Jay R. Wren

i knew that was bug

Revision history for this message
Kevin W Monroe (kwmonroe) wrote :

Thanks for the updates Jay! Tests pass and I verified apt config settings are honored during both install and config-changed.

This has been merged into trusty/apache2. An updated charm should hit the store in about an hour. Thanks again for your patience during this review!

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 2015-11-23 19:12:12 +0000
3+++ Makefile 2016-02-25 16:17:14 +0000
4@@ -17,8 +17,16 @@
5 @(charm proof $(PWD) || [ $$? -eq 100 ]) && echo OK
6 @test `cat revision` = 0 && rm revision
7
8-.venv:
9- sudo apt-get install -y python-apt python-virtualenv python-jinja2 python-openssl
10+/usr/bin/apt:
11+ sudo apt-get install -y python-apt
12+
13+/usr/bin/virtualenv:
14+ sudo apt-get install -y python-virtualenv
15+
16+/usr/lib/python2.7/dist-packages/jinja2:
17+ sudo apt-get install -y python-jinja2
18+
19+.venv: /usr/bin/apt /usr/bin/virtualenv /usr/lib/python2.7/dist-packages/jinja2
20 virtualenv .venv --system-site-packages
21 .venv/bin/pip install -I nose testtools mock pyyaml
22
23@@ -42,4 +50,7 @@
24 -d hooks/charmhelpers
25 @echo Do not forget to commit the updated files if any.
26
27-.PHONY: revision proof .venv test lint sourcedeps charm-payload
28+clean:
29+ rm -rf .venv
30+
31+.PHONY: revision proof test lint sourcedeps charm-payload
32
33=== modified file 'config.yaml'
34--- config.yaml 2015-08-11 19:06:25 +0000
35+++ config.yaml 2016-02-25 16:17:14 +0000
36@@ -193,3 +193,16 @@
37 type: string
38 description: Comma seperated list of OpenID providers for authentication.
39 default: ""
40+ apt-key-id:
41+ type: string
42+ default: ""
43+ description: A PGP key id. This is used with PPA and the source
44+ option to import a PGP public key for verifying repository signatures.
45+ This value must match the PPA for apt-source.
46+ apt-source:
47+ type: string
48+ default: ""
49+ description: From where to install packages. This is the PPA source line.
50+ Note that due to a bug in software-properties add-apt-repository cannot
51+ add the ondrej/apache2 ppa, so the default value here is a full
52+ sources line.
53
54=== modified file 'hooks/hooks.py'
55--- hooks/hooks.py 2016-02-18 18:08:34 +0000
56+++ hooks/hooks.py 2016-02-25 16:17:14 +0000
57@@ -25,7 +25,7 @@
58 unit_get
59 )
60 from charmhelpers.contrib.charmsupport import nrpe
61-from charmhelpers.fetch import apt_update
62+from charmhelpers.fetch import apt_update, add_source
63
64 ###############################################################################
65 # Global variables
66@@ -289,6 +289,12 @@
67
68
69 def install_hook():
70+ apt_source = config_get('apt-source') or ''
71+ apt_key_id = config_get('apt-key-id') or False
72+ open('config.apt-source', 'w').write(apt_source)
73+ if apt_source and apt_key_id:
74+ print apt_source + " and " + apt_key_id
75+ add_source(apt_source, apt_key_id)
76 if not os.path.exists(default_apache2_service_config_dir):
77 os.mkdir(default_apache2_service_config_dir, 0600)
78 apt_update(fatal=True)
79@@ -301,6 +307,15 @@
80 ensure_package_status(service_affecting_packages,
81 config_get('package_status'))
82 ensure_extra_packages()
83+ # the apache2 deb does not yet have http2 module in mods-available. Add it.
84+ open('/etc/apache2/mods-available/http2.load', 'w').write(
85+ 'LoadModule http2_module /usr/lib/apache2/modules/mod_http2.so')
86+ open('/etc/apache2/mods-available/http2.conf', 'w').write(
87+ '''<IfModule http2_module>
88+ ProtocolsHonorOrder On
89+ Protocols h2 http/1.1
90+</IfModule>
91+''')
92 return install_status
93
94
95@@ -585,6 +600,18 @@
96 relationship_data = {}
97 config_data = config_get()
98
99+ apt_source = config_data['apt-source']
100+ old_apt_source = ''
101+ try:
102+ old_apt_source = open('config.apt-source', 'r').read()
103+ except:
104+ pass
105+ if old_apt_source != apt_source:
106+ subprocess.check_call(['add-apt-repository', '--yes', '-r',
107+ old_apt_source])
108+ add_source(apt_source, config_data['apt-key-id'])
109+ open('config.apt-source', 'w').write(apt_source)
110+
111 ensure_package_status(service_affecting_packages,
112 config_data['package_status'])
113 ensure_extra_packages()
114
115=== modified file 'hooks/tests/test_balancer_hook.py'
116--- hooks/tests/test_balancer_hook.py 2014-12-29 22:59:20 +0000
117+++ hooks/tests/test_balancer_hook.py 2016-02-25 16:17:14 +0000
118@@ -497,6 +497,7 @@
119 if os.path.exists(self.log_path):
120 os.remove(self.log_path)
121
122+ @patch('hooks.open')
123 @patch('hooks.config_get')
124 @patch('os.path.exists')
125 @patch('os.mkdir')
126@@ -504,7 +505,8 @@
127 @patch('hooks.log', MagicMock())
128 @patch('hooks.apt_update')
129 def test_installs_hook(
130- self, apt_update, apt_get_install, mkdir, exists, config_get):
131+ self, apt_update, apt_get_install, mkdir, exists, config_get,
132+ open):
133 exists.return_value = self.not_a_dir
134 config_get.return_value = None
135 apt_get_install.return_value = 'some result'
136@@ -523,19 +525,22 @@
137 call('apache2'),
138 ])
139
140- @patch('hooks.config_get')
141+ @patch('hooks.open')
142 @patch('os.path.exists')
143 @patch('os.mkdir')
144 @patch('hooks.apt_get_install')
145 @patch('hooks.log', MagicMock())
146 @patch('hooks.apt_update')
147 def test_install_hook_installs_extra_packages(
148- self, apt_update, apt_get_install, mkdir, exists, config_get):
149+ self, apt_update, apt_get_install, mkdir, exists,
150+ open):
151 exists.return_value = self.dir_exists
152- config_get.return_value = "extra"
153+ c = {'extra_packages': 'extra', 'apt-source': '', 'apt-key-id': ''}
154+ config_get = MagicMock(wraps=c.get)
155 apt_get_install.return_value = 'some result'
156
157- result = hooks.install_hook()
158+ with patch('hooks.config_get', config_get):
159+ result = hooks.install_hook()
160
161 self.assertEqual(result, 'some result')
162 apt_get_install.assert_has_calls([
163@@ -547,6 +552,7 @@
164 call('extra'),
165 ])
166
167+ @patch('hooks.open')
168 @patch('hooks.config_get')
169 @patch('os.path.exists')
170 @patch('os.mkdir')
171@@ -554,7 +560,8 @@
172 @patch('hooks.log', MagicMock())
173 @patch('hooks.apt_update')
174 def test_doesnt_create_dir_to_install_hooks_if_not_needed(
175- self, apt_update, apt_get_install, mkdir, exists, config_get):
176+ self, apt_update, apt_get_install, mkdir, exists, config_get,
177+ open):
178 exists.return_value = self.dir_exists
179 config_get.return_value = None
180 apt_get_install.return_value = 'some result'
181
182=== modified file 'hooks/tests/test_config_changed.py'
183--- hooks/tests/test_config_changed.py 2015-11-23 19:12:12 +0000
184+++ hooks/tests/test_config_changed.py 2016-02-25 16:17:14 +0000
185@@ -67,6 +67,7 @@
186 "servername": "foobar",
187 "vhost_http_template": "",
188 "vhost_https_template": "",
189+ "apt-source": "",
190 })
191 base = patch.object(hooks, 'default_apache_base_dir', self.dirname)
192 config22 = patch.object(hooks, 'default_apache22_config_dir',

Subscribers

People subscribed via source and target branches

to all changes: