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
1=== modified file 'autopilot/application/_launcher.py'
2--- autopilot/application/_launcher.py 2015-12-08 21:42:14 +0000
3+++ autopilot/application/_launcher.py 2017-03-01 23:12:03 +0000
4@@ -1,7 +1,7 @@
5 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
6 #
7 # Autopilot Functional Test Tool
8-# Copyright (C) 2013 Canonical
9+# Copyright (C) 2013,2017 Canonical
10 #
11 # This program is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13@@ -20,21 +20,20 @@
14 """Base module for application launchers."""
15
16 import fixtures
17-from gi.repository import GLib
18+from gi import require_version
19 try:
20- from gi import require_version
21+ require_version('UbuntuAppLaunch', '3')
22+except ValueError:
23 require_version('UbuntuAppLaunch', '2')
24- from gi.repository import UbuntuAppLaunch
25-except ImportError:
26- # Note: the renamed package is not in Trusty.
27- from gi.repository import UpstartAppLaunch as UbuntuAppLaunch
28+from gi.repository import GLib, UbuntuAppLaunch
29+
30 import json
31 import logging
32 import os
33 import psutil
34 import subprocess
35 import signal
36-from testtools.content import content_from_file
37+from systemd import journal
38 from autopilot.utilities import safe_text_content
39
40 from autopilot._timeout import Timeout
41@@ -186,13 +185,20 @@
42 self.addCleanup(self._stop_application, app_id)
43 self.addCleanup(self._attach_application_log, app_id)
44
45+ @staticmethod
46+ def _get_user_unit_match(app_id):
47+ return 'ubuntu-app-launch-*-%s-*.service' % app_id
48+
49 def _attach_application_log(self, app_id):
50- log_path = UbuntuAppLaunch.application_log_path(app_id)
51- if log_path and os.path.exists(log_path):
52- self.caseAddDetail(
53- "Application Log (%s)" % app_id,
54- content_from_file(log_path)
55- )
56+ j = journal.Reader()
57+ j.log_level(journal.LOG_INFO)
58+ j.add_match(_SYSTEMD_USER_UNIT=self._get_user_unit_match(app_id))
59+ log_data = ''
60+ for i in j:
61+ log_data += str(i) + '\n'
62+ if len(log_data) > 0:
63+ self.caseAddDetail('Application Log (%s)' % app_id,
64+ safe_text_content(log_data))
65
66 def _stop_application(self, app_id):
67 state = {}
68
69=== modified file 'autopilot/tests/unit/test_application_launcher.py'
70--- autopilot/tests/unit/test_application_launcher.py 2014-07-22 02:30:19 +0000
71+++ autopilot/tests/unit/test_application_launcher.py 2017-03-01 23:12:03 +0000
72@@ -1,7 +1,7 @@
73 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
74 #
75 # Autopilot Functional Test Tool
76-# Copyright (C) 2013 Canonical
77+# Copyright (C) 2013,2017 Canonical
78 #
79 # This program is free software: you can redistribute it and/or modify
80 # it under the terms of the GNU General Public License as published by
81@@ -33,8 +33,7 @@
82 raises,
83 )
84 from testtools.content import text_content
85-import tempfile
86-from unittest.mock import Mock, patch
87+from unittest.mock import MagicMock, Mock, patch
88
89 from autopilot.application import (
90 ClickApplicationLauncher,
91@@ -782,32 +781,30 @@
92 app_id = self.getUniqueString()
93 case_addDetail = Mock()
94 launcher = UpstartApplicationLauncher(case_addDetail)
95- with patch.object(_l.UbuntuAppLaunch, 'application_log_path') as p:
96- p.return_value = None
97+ j = MagicMock(spec=_l.journal.Reader)
98+ with patch.object(_l.journal, 'Reader', return_value=j):
99 launcher._attach_application_log(app_id)
100-
101- p.assert_called_once_with(app_id)
102+ expected = launcher._get_user_unit_match(app_id)
103+ j.add_match.assert_called_once_with(_SYSTEMD_USER_UNIT=expected)
104 self.assertEqual(0, case_addDetail.call_count)
105
106- def test_attach_application_log_attaches_log_file(self):
107+ def test_attach_application_log_attaches_log(self):
108 token = self.getUniqueString()
109 case_addDetail = Mock()
110 launcher = UpstartApplicationLauncher(case_addDetail)
111 app_id = self.getUniqueString()
112- with tempfile.NamedTemporaryFile(mode='w') as f:
113- f.write(token)
114- f.flush()
115- with patch.object(_l.UbuntuAppLaunch, 'application_log_path',
116- return_value=f.name):
117- launcher._attach_application_log(app_id)
118+ j = MagicMock(spec=_l.journal.Reader)
119+ j.__iter__ = lambda x: iter([token])
120+ with patch.object(_l.journal, 'Reader', return_value=j):
121+ launcher._attach_application_log(app_id)
122
123- self.assertEqual(1, case_addDetail.call_count)
124- content_name, content_obj = case_addDetail.call_args[0]
125- self.assertEqual(
126- "Application Log (%s)" % app_id,
127- content_name
128- )
129- self.assertThat(content_obj.as_text(), Contains(token))
130+ self.assertEqual(1, case_addDetail.call_count)
131+ content_name, content_obj = case_addDetail.call_args[0]
132+ self.assertEqual(
133+ "Application Log (%s)" % app_id,
134+ content_name
135+ )
136+ self.assertThat(content_obj.as_text(), Contains(token))
137
138 def test_stop_adds_app_stopped_observer(self):
139 mock_add_detail = Mock()
140
141=== modified file 'debian/control'
142--- debian/control 2017-03-01 21:54:53 +0000
143+++ debian/control 2017-03-01 23:12:03 +0000
144@@ -8,7 +8,7 @@
145 dvipng,
146 gir1.2-gtk-3.0,
147 gir1.2-ibus-1.0,
148- gir1.2-ubuntu-app-launch-2 | gir1.2-upstart-app-launch-2,
149+ gir1.2-ubuntu-app-launch-3 | gir1.2-ubuntu-app-launch-2,
150 graphviz,
151 libjs-jquery,
152 libjs-underscore,
153@@ -27,6 +27,7 @@
154 python3-setuptools,
155 python3-sphinx,
156 python3-subunit,
157+ python3-systemd,
158 python3-testscenarios,
159 python3-testtools,
160 python3-tz,
161@@ -43,7 +44,7 @@
162
163 Package: python3-autopilot
164 Architecture: all
165-Depends: gir1.2-ubuntu-app-launch-2 | gir1.2-upstart-app-launch-2,
166+Depends: gir1.2-ubuntu-app-launch-3 | gir1.2-ubuntu-app-launch-2,
167 libjs-jquery,
168 libjs-underscore,
169 mir-utils,
170@@ -57,6 +58,7 @@
171 python3-pil,
172 python3-psutil,
173 python3-subunit,
174+ python3-systemd,
175 python3-testscenarios,
176 python3-testtools,
177 python3-tz,

Subscribers

People subscribed via source and target branches