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
=== modified file 'Makefile'
--- Makefile 2015-11-23 19:12:12 +0000
+++ Makefile 2016-02-25 16:17:14 +0000
@@ -17,8 +17,16 @@
17 @(charm proof $(PWD) || [ $$? -eq 100 ]) && echo OK17 @(charm proof $(PWD) || [ $$? -eq 100 ]) && echo OK
18 @test `cat revision` = 0 && rm revision18 @test `cat revision` = 0 && rm revision
1919
20.venv:20/usr/bin/apt:
21 sudo apt-get install -y python-apt python-virtualenv python-jinja2 python-openssl21 sudo apt-get install -y python-apt
22
23/usr/bin/virtualenv:
24 sudo apt-get install -y python-virtualenv
25
26/usr/lib/python2.7/dist-packages/jinja2:
27 sudo apt-get install -y python-jinja2
28
29.venv: /usr/bin/apt /usr/bin/virtualenv /usr/lib/python2.7/dist-packages/jinja2
22 virtualenv .venv --system-site-packages30 virtualenv .venv --system-site-packages
23 .venv/bin/pip install -I nose testtools mock pyyaml31 .venv/bin/pip install -I nose testtools mock pyyaml
2432
@@ -42,4 +50,7 @@
42 -d hooks/charmhelpers50 -d hooks/charmhelpers
43 @echo Do not forget to commit the updated files if any.51 @echo Do not forget to commit the updated files if any.
4452
45.PHONY: revision proof .venv test lint sourcedeps charm-payload53clean:
54 rm -rf .venv
55
56.PHONY: revision proof test lint sourcedeps charm-payload
4657
=== modified file 'config.yaml'
--- config.yaml 2015-08-11 19:06:25 +0000
+++ config.yaml 2016-02-25 16:17:14 +0000
@@ -193,3 +193,16 @@
193 type: string193 type: string
194 description: Comma seperated list of OpenID providers for authentication.194 description: Comma seperated list of OpenID providers for authentication.
195 default: ""195 default: ""
196 apt-key-id:
197 type: string
198 default: ""
199 description: A PGP key id. This is used with PPA and the source
200 option to import a PGP public key for verifying repository signatures.
201 This value must match the PPA for apt-source.
202 apt-source:
203 type: string
204 default: ""
205 description: From where to install packages. This is the PPA source line.
206 Note that due to a bug in software-properties add-apt-repository cannot
207 add the ondrej/apache2 ppa, so the default value here is a full
208 sources line.
196209
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2016-02-18 18:08:34 +0000
+++ hooks/hooks.py 2016-02-25 16:17:14 +0000
@@ -25,7 +25,7 @@
25 unit_get25 unit_get
26)26)
27from charmhelpers.contrib.charmsupport import nrpe27from charmhelpers.contrib.charmsupport import nrpe
28from charmhelpers.fetch import apt_update28from charmhelpers.fetch import apt_update, add_source
2929
30###############################################################################30###############################################################################
31# Global variables31# Global variables
@@ -289,6 +289,12 @@
289289
290290
291def install_hook():291def install_hook():
292 apt_source = config_get('apt-source') or ''
293 apt_key_id = config_get('apt-key-id') or False
294 open('config.apt-source', 'w').write(apt_source)
295 if apt_source and apt_key_id:
296 print apt_source + " and " + apt_key_id
297 add_source(apt_source, apt_key_id)
292 if not os.path.exists(default_apache2_service_config_dir):298 if not os.path.exists(default_apache2_service_config_dir):
293 os.mkdir(default_apache2_service_config_dir, 0600)299 os.mkdir(default_apache2_service_config_dir, 0600)
294 apt_update(fatal=True)300 apt_update(fatal=True)
@@ -301,6 +307,15 @@
301 ensure_package_status(service_affecting_packages,307 ensure_package_status(service_affecting_packages,
302 config_get('package_status'))308 config_get('package_status'))
303 ensure_extra_packages()309 ensure_extra_packages()
310 # the apache2 deb does not yet have http2 module in mods-available. Add it.
311 open('/etc/apache2/mods-available/http2.load', 'w').write(
312 'LoadModule http2_module /usr/lib/apache2/modules/mod_http2.so')
313 open('/etc/apache2/mods-available/http2.conf', 'w').write(
314 '''<IfModule http2_module>
315 ProtocolsHonorOrder On
316 Protocols h2 http/1.1
317</IfModule>
318''')
304 return install_status319 return install_status
305320
306321
@@ -585,6 +600,18 @@
585 relationship_data = {}600 relationship_data = {}
586 config_data = config_get()601 config_data = config_get()
587602
603 apt_source = config_data['apt-source']
604 old_apt_source = ''
605 try:
606 old_apt_source = open('config.apt-source', 'r').read()
607 except:
608 pass
609 if old_apt_source != apt_source:
610 subprocess.check_call(['add-apt-repository', '--yes', '-r',
611 old_apt_source])
612 add_source(apt_source, config_data['apt-key-id'])
613 open('config.apt-source', 'w').write(apt_source)
614
588 ensure_package_status(service_affecting_packages,615 ensure_package_status(service_affecting_packages,
589 config_data['package_status'])616 config_data['package_status'])
590 ensure_extra_packages()617 ensure_extra_packages()
591618
=== modified file 'hooks/tests/test_balancer_hook.py'
--- hooks/tests/test_balancer_hook.py 2014-12-29 22:59:20 +0000
+++ hooks/tests/test_balancer_hook.py 2016-02-25 16:17:14 +0000
@@ -497,6 +497,7 @@
497 if os.path.exists(self.log_path):497 if os.path.exists(self.log_path):
498 os.remove(self.log_path)498 os.remove(self.log_path)
499499
500 @patch('hooks.open')
500 @patch('hooks.config_get')501 @patch('hooks.config_get')
501 @patch('os.path.exists')502 @patch('os.path.exists')
502 @patch('os.mkdir')503 @patch('os.mkdir')
@@ -504,7 +505,8 @@
504 @patch('hooks.log', MagicMock())505 @patch('hooks.log', MagicMock())
505 @patch('hooks.apt_update')506 @patch('hooks.apt_update')
506 def test_installs_hook(507 def test_installs_hook(
507 self, apt_update, apt_get_install, mkdir, exists, config_get):508 self, apt_update, apt_get_install, mkdir, exists, config_get,
509 open):
508 exists.return_value = self.not_a_dir510 exists.return_value = self.not_a_dir
509 config_get.return_value = None511 config_get.return_value = None
510 apt_get_install.return_value = 'some result'512 apt_get_install.return_value = 'some result'
@@ -523,19 +525,22 @@
523 call('apache2'),525 call('apache2'),
524 ])526 ])
525527
526 @patch('hooks.config_get')528 @patch('hooks.open')
527 @patch('os.path.exists')529 @patch('os.path.exists')
528 @patch('os.mkdir')530 @patch('os.mkdir')
529 @patch('hooks.apt_get_install')531 @patch('hooks.apt_get_install')
530 @patch('hooks.log', MagicMock())532 @patch('hooks.log', MagicMock())
531 @patch('hooks.apt_update')533 @patch('hooks.apt_update')
532 def test_install_hook_installs_extra_packages(534 def test_install_hook_installs_extra_packages(
533 self, apt_update, apt_get_install, mkdir, exists, config_get):535 self, apt_update, apt_get_install, mkdir, exists,
536 open):
534 exists.return_value = self.dir_exists537 exists.return_value = self.dir_exists
535 config_get.return_value = "extra"538 c = {'extra_packages': 'extra', 'apt-source': '', 'apt-key-id': ''}
539 config_get = MagicMock(wraps=c.get)
536 apt_get_install.return_value = 'some result'540 apt_get_install.return_value = 'some result'
537541
538 result = hooks.install_hook()542 with patch('hooks.config_get', config_get):
543 result = hooks.install_hook()
539544
540 self.assertEqual(result, 'some result')545 self.assertEqual(result, 'some result')
541 apt_get_install.assert_has_calls([546 apt_get_install.assert_has_calls([
@@ -547,6 +552,7 @@
547 call('extra'),552 call('extra'),
548 ])553 ])
549554
555 @patch('hooks.open')
550 @patch('hooks.config_get')556 @patch('hooks.config_get')
551 @patch('os.path.exists')557 @patch('os.path.exists')
552 @patch('os.mkdir')558 @patch('os.mkdir')
@@ -554,7 +560,8 @@
554 @patch('hooks.log', MagicMock())560 @patch('hooks.log', MagicMock())
555 @patch('hooks.apt_update')561 @patch('hooks.apt_update')
556 def test_doesnt_create_dir_to_install_hooks_if_not_needed(562 def test_doesnt_create_dir_to_install_hooks_if_not_needed(
557 self, apt_update, apt_get_install, mkdir, exists, config_get):563 self, apt_update, apt_get_install, mkdir, exists, config_get,
564 open):
558 exists.return_value = self.dir_exists565 exists.return_value = self.dir_exists
559 config_get.return_value = None566 config_get.return_value = None
560 apt_get_install.return_value = 'some result'567 apt_get_install.return_value = 'some result'
561568
=== modified file 'hooks/tests/test_config_changed.py'
--- hooks/tests/test_config_changed.py 2015-11-23 19:12:12 +0000
+++ hooks/tests/test_config_changed.py 2016-02-25 16:17:14 +0000
@@ -67,6 +67,7 @@
67 "servername": "foobar",67 "servername": "foobar",
68 "vhost_http_template": "",68 "vhost_http_template": "",
69 "vhost_https_template": "",69 "vhost_https_template": "",
70 "apt-source": "",
70 })71 })
71 base = patch.object(hooks, 'default_apache_base_dir', self.dirname)72 base = patch.object(hooks, 'default_apache_base_dir', self.dirname)
72 config22 = patch.object(hooks, 'default_apache22_config_dir',73 config22 = patch.object(hooks, 'default_apache22_config_dir',

Subscribers

People subscribed via source and target branches

to all changes: