Merge lp:~dobey/autopilot/ual-break into lp:autopilot

Proposed by dobey
Status: Merged
Approved by: Omer Akram
Approved revision: 598
Merged at revision: 592
Proposed branch: lp:~dobey/autopilot/ual-break
Merge into: lp:autopilot
Diff against target: 177 lines (+42/-37)
3 files modified
autopilot/application/_launcher.py (+20/-14)
autopilot/tests/unit/test_application_launcher.py (+18/-21)
debian/control (+4/-2)
To merge this branch: bzr merge lp:~dobey/autopilot/ual-break
Reviewer Review Type Date Requested Status
Omer Akram (community) Approve
Santiago Baldassin (community) Approve
platform-qa-bot continuous-integration Approve
Review via email: mp+318667@code.launchpad.net

Commit message

Update dependency for ubuntu-app-launch API break.
Get logs directly from systemd journal now, for ual launched apps.

To post a comment you must log in.
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)
lp:~dobey/autopilot/ual-break updated
592. By dobey

Use systemd to get the log content, as ual dropped log path API.

593. By dobey

Update copyright year here too.

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)
lp:~dobey/autopilot/ual-break updated
594. By dobey

Must convert the dicts to a string.

595. By dobey

Fix flake8 complaints.

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)
lp:~dobey/autopilot/ual-break updated
596. By dobey

Fix syntax error.

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)
lp:~dobey/autopilot/ual-break updated
597. By dobey

Fix the tests.

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)
lp:~dobey/autopilot/ual-break updated
598. By dobey

Fix flake8 issue.

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Santiago Baldassin (sbaldassin) wrote :

Code looks good to me

review: Approve
Revision history for this message
Omer Akram (om26er) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'autopilot/application/_launcher.py'
--- autopilot/application/_launcher.py 2015-12-08 21:42:14 +0000
+++ autopilot/application/_launcher.py 2017-03-01 23:12:03 +0000
@@ -1,7 +1,7 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#2#
3# Autopilot Functional Test Tool3# Autopilot Functional Test Tool
4# Copyright (C) 2013 Canonical4# Copyright (C) 2013,2017 Canonical
5#5#
6# This program is free software: you can redistribute it and/or modify6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by7# it under the terms of the GNU General Public License as published by
@@ -20,21 +20,20 @@
20"""Base module for application launchers."""20"""Base module for application launchers."""
2121
22import fixtures22import fixtures
23from gi.repository import GLib23from gi import require_version
24try:24try:
25 from gi import require_version25 require_version('UbuntuAppLaunch', '3')
26except ValueError:
26 require_version('UbuntuAppLaunch', '2')27 require_version('UbuntuAppLaunch', '2')
27 from gi.repository import UbuntuAppLaunch28from gi.repository import GLib, UbuntuAppLaunch
28except ImportError:29
29 # Note: the renamed package is not in Trusty.
30 from gi.repository import UpstartAppLaunch as UbuntuAppLaunch
31import json30import json
32import logging31import logging
33import os32import os
34import psutil33import psutil
35import subprocess34import subprocess
36import signal35import signal
37from testtools.content import content_from_file36from systemd import journal
38from autopilot.utilities import safe_text_content37from autopilot.utilities import safe_text_content
3938
40from autopilot._timeout import Timeout39from autopilot._timeout import Timeout
@@ -186,13 +185,20 @@
186 self.addCleanup(self._stop_application, app_id)185 self.addCleanup(self._stop_application, app_id)
187 self.addCleanup(self._attach_application_log, app_id)186 self.addCleanup(self._attach_application_log, app_id)
188187
188 @staticmethod
189 def _get_user_unit_match(app_id):
190 return 'ubuntu-app-launch-*-%s-*.service' % app_id
191
189 def _attach_application_log(self, app_id):192 def _attach_application_log(self, app_id):
190 log_path = UbuntuAppLaunch.application_log_path(app_id)193 j = journal.Reader()
191 if log_path and os.path.exists(log_path):194 j.log_level(journal.LOG_INFO)
192 self.caseAddDetail(195 j.add_match(_SYSTEMD_USER_UNIT=self._get_user_unit_match(app_id))
193 "Application Log (%s)" % app_id,196 log_data = ''
194 content_from_file(log_path)197 for i in j:
195 )198 log_data += str(i) + '\n'
199 if len(log_data) > 0:
200 self.caseAddDetail('Application Log (%s)' % app_id,
201 safe_text_content(log_data))
196202
197 def _stop_application(self, app_id):203 def _stop_application(self, app_id):
198 state = {}204 state = {}
199205
=== modified file 'autopilot/tests/unit/test_application_launcher.py'
--- autopilot/tests/unit/test_application_launcher.py 2014-07-22 02:30:19 +0000
+++ autopilot/tests/unit/test_application_launcher.py 2017-03-01 23:12:03 +0000
@@ -1,7 +1,7 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#2#
3# Autopilot Functional Test Tool3# Autopilot Functional Test Tool
4# Copyright (C) 2013 Canonical4# Copyright (C) 2013,2017 Canonical
5#5#
6# This program is free software: you can redistribute it and/or modify6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by7# it under the terms of the GNU General Public License as published by
@@ -33,8 +33,7 @@
33 raises,33 raises,
34)34)
35from testtools.content import text_content35from testtools.content import text_content
36import tempfile36from unittest.mock import MagicMock, Mock, patch
37from unittest.mock import Mock, patch
3837
39from autopilot.application import (38from autopilot.application import (
40 ClickApplicationLauncher,39 ClickApplicationLauncher,
@@ -782,32 +781,30 @@
782 app_id = self.getUniqueString()781 app_id = self.getUniqueString()
783 case_addDetail = Mock()782 case_addDetail = Mock()
784 launcher = UpstartApplicationLauncher(case_addDetail)783 launcher = UpstartApplicationLauncher(case_addDetail)
785 with patch.object(_l.UbuntuAppLaunch, 'application_log_path') as p:784 j = MagicMock(spec=_l.journal.Reader)
786 p.return_value = None785 with patch.object(_l.journal, 'Reader', return_value=j):
787 launcher._attach_application_log(app_id)786 launcher._attach_application_log(app_id)
788787 expected = launcher._get_user_unit_match(app_id)
789 p.assert_called_once_with(app_id)788 j.add_match.assert_called_once_with(_SYSTEMD_USER_UNIT=expected)
790 self.assertEqual(0, case_addDetail.call_count)789 self.assertEqual(0, case_addDetail.call_count)
791790
792 def test_attach_application_log_attaches_log_file(self):791 def test_attach_application_log_attaches_log(self):
793 token = self.getUniqueString()792 token = self.getUniqueString()
794 case_addDetail = Mock()793 case_addDetail = Mock()
795 launcher = UpstartApplicationLauncher(case_addDetail)794 launcher = UpstartApplicationLauncher(case_addDetail)
796 app_id = self.getUniqueString()795 app_id = self.getUniqueString()
797 with tempfile.NamedTemporaryFile(mode='w') as f:796 j = MagicMock(spec=_l.journal.Reader)
798 f.write(token)797 j.__iter__ = lambda x: iter([token])
799 f.flush()798 with patch.object(_l.journal, 'Reader', return_value=j):
800 with patch.object(_l.UbuntuAppLaunch, 'application_log_path',799 launcher._attach_application_log(app_id)
801 return_value=f.name):
802 launcher._attach_application_log(app_id)
803800
804 self.assertEqual(1, case_addDetail.call_count)801 self.assertEqual(1, case_addDetail.call_count)
805 content_name, content_obj = case_addDetail.call_args[0]802 content_name, content_obj = case_addDetail.call_args[0]
806 self.assertEqual(803 self.assertEqual(
807 "Application Log (%s)" % app_id,804 "Application Log (%s)" % app_id,
808 content_name805 content_name
809 )806 )
810 self.assertThat(content_obj.as_text(), Contains(token))807 self.assertThat(content_obj.as_text(), Contains(token))
811808
812 def test_stop_adds_app_stopped_observer(self):809 def test_stop_adds_app_stopped_observer(self):
813 mock_add_detail = Mock()810 mock_add_detail = Mock()
814811
=== modified file 'debian/control'
--- debian/control 2017-03-01 21:54:53 +0000
+++ debian/control 2017-03-01 23:12:03 +0000
@@ -8,7 +8,7 @@
8 dvipng,8 dvipng,
9 gir1.2-gtk-3.0,9 gir1.2-gtk-3.0,
10 gir1.2-ibus-1.0,10 gir1.2-ibus-1.0,
11 gir1.2-ubuntu-app-launch-2 | gir1.2-upstart-app-launch-2,11 gir1.2-ubuntu-app-launch-3 | gir1.2-ubuntu-app-launch-2,
12 graphviz,12 graphviz,
13 libjs-jquery,13 libjs-jquery,
14 libjs-underscore,14 libjs-underscore,
@@ -27,6 +27,7 @@
27 python3-setuptools,27 python3-setuptools,
28 python3-sphinx,28 python3-sphinx,
29 python3-subunit,29 python3-subunit,
30 python3-systemd,
30 python3-testscenarios,31 python3-testscenarios,
31 python3-testtools,32 python3-testtools,
32 python3-tz,33 python3-tz,
@@ -43,7 +44,7 @@
4344
44Package: python3-autopilot45Package: python3-autopilot
45Architecture: all46Architecture: all
46Depends: gir1.2-ubuntu-app-launch-2 | gir1.2-upstart-app-launch-2,47Depends: gir1.2-ubuntu-app-launch-3 | gir1.2-ubuntu-app-launch-2,
47 libjs-jquery,48 libjs-jquery,
48 libjs-underscore,49 libjs-underscore,
49 mir-utils,50 mir-utils,
@@ -57,6 +58,7 @@
57 python3-pil,58 python3-pil,
58 python3-psutil,59 python3-psutil,
59 python3-subunit,60 python3-subunit,
61 python3-systemd,
60 python3-testscenarios,62 python3-testscenarios,
61 python3-testtools,63 python3-testtools,
62 python3-tz,64 python3-tz,

Subscribers

People subscribed via source and target branches