Merge ~pieq/bugit/+git/qabro:lp1892198-new-checkbox-session-dir into bugit:master

Proposed by Pierre Equoy
Status: Merged
Approved by: Pierre Equoy
Approved revision: fec44725c2ac3cf9cf172aee9995be2445c06a33
Merged at revision: 8bfc3b5d7a91d9878f324d6597abe8186452e779
Proposed branch: ~pieq/bugit/+git/qabro:lp1892198-new-checkbox-session-dir
Merge into: bugit:master
Diff against target: 106 lines (+36/-11)
3 files modified
CHANGELOG.md (+4/-1)
qabro/bug_assistant.py (+9/-7)
tests/test_bug_assistant.py (+23/-3)
Reviewer Review Type Date Requested Status
Maciej Kisielewski (community) Approve
Review via email: mp+390891@code.launchpad.net

Description of the change

qabro will now search for Checkbox sessions in /var/tmp/checkbox-ng/sessions (in addition to previous directories for retro-compatibility).

How to test
===========

Build a snap and install it:

$ snapcraft
(...)
$ sudo snap install qabro_0.14dev_amd64.snap --devmode

Make sure you have some sessions in /var/tmp/checkbox-ng/sessions:

$ ls /var/tmp/checkbox-ng/sessions
session_title-2020-09-17T07.53.45.session throwaway-2020-09-17T07.53.49.session

Launch qabro on staging LP and file a bug:

$ APPORT_LAUNCHPAD_INSTANCE=staging qabro

→ The created issue should have a checkbox-session.tgz attachment containing the latest session available on your testing device.

To post a comment you must log in.
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

Looks good! +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/CHANGELOG.md b/CHANGELOG.md
index eefb675..b476e42 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,9 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
8### Added8### Added
9- Unit tests (see Contributing Guidelines for more info)9- Unit tests (see Contributing Guidelines for more info)
1010
11### Changed
12- Look for Checkbox sessions in `/var/tmp/checkbox-ng/sessions` to comply with the new session path in place in checkbox-ng ([LP #1892198](https://bugs.launchpad.net/qabro/+bug/1892198)).
13
11### Fixed14### Fixed
12([LP #1891609](https://bugs.launchpad.net/qabro/+bug/1887903))15([LP #1891609](https://bugs.launchpad.net/qabro/+bug/1887903))
13- `JSONDecodeError` when launching qabro on some installations ([LP #1891609](https://bugs.launchpad.net/qabro/+bug/1887903))16- `JSONDecodeError` when launching qabro on some installations ([LP #1887903](https://bugs.launchpad.net/qabro/+bug/1887903))
14- Cannot upload attachments: 'title' error is shown ([LP #1891609](https://bugs.launchpad.net/qabro/+bug/1891609))17- Cannot upload attachments: 'title' error is shown ([LP #1891609](https://bugs.launchpad.net/qabro/+bug/1891609))
1518
1619
diff --git a/qabro/bug_assistant.py b/qabro/bug_assistant.py
index 6a720b0..f8630e4 100644
--- a/qabro/bug_assistant.py
+++ b/qabro/bug_assistant.py
@@ -267,20 +267,22 @@ class AttachmentAssistant:
267 snap.props.confinement.value_nick)267 snap.props.confinement.value_nick)
268 self.attachments["snap_list.log"] = out.encode()268 self.attachments["snap_list.log"] = out.encode()
269269
270 def _get_last_checkbox_session_path(self, usr_dir="/home/$USER", root_dir="/root"):270 def _get_last_checkbox_session_path(self, usr_home="/home/$USER", root_home="/root", root_dir="/"):
271 """Return path of the most recent Checkbox session directory."""271 """Return path of the most recent Checkbox session directory."""
272 rootpath = ''272 rootpath = ''
273 latest_session_dir = ''273 latest_session_dir = ''
274 # Determine if we use a classic install or a snap install274 generic_path = os.path.join(root_dir, "var/tmp/checkbox-ng/sessions")
275 classic_path = os.path.expandvars(os.path.join(usr_dir, ".cache/plainbox/sessions"))275 classic_path = os.path.expandvars(os.path.join(usr_home, ".cache/plainbox/sessions"))
276 if os.path.exists(classic_path):276 if os.path.exists(generic_path): # for any checkbox installs based on checkbox-ng >= 1.10
277 rootpath = generic_path
278 elif os.path.exists(classic_path): # for classic checkbox installs based on checkbox-ng <= 1.9
277 rootpath = classic_path279 rootpath = classic_path
278 else:280 else: # for snap checkbox installs based on checkbox-ng <= 1.9
279 snaps = qabro.utils.get_snaps()281 snaps = qabro.utils.get_snaps()
280 snap_list = [e.props.name for e in snaps if 'checkbox-' in e.props.name]282 snap_list = [e.props.name for e in snaps if 'checkbox-' in e.props.name]
281 for snap_name in snap_list:283 for snap_name in snap_list:
282 sp = [os.path.join(usr_dir, "snap/{}/current/.cache/plainbox/sessions"),284 sp = [os.path.join(usr_home, "snap/{}/current/.cache/plainbox/sessions"),
283 os.path.join(root_dir, "snap/{}/current/.cache/plainbox/sessions")]285 os.path.join(root_home, "snap/{}/current/.cache/plainbox/sessions")]
284 for p in sp:286 for p in sp:
285 snap_path = os.path.expandvars(p.format(snap_name))287 snap_path = os.path.expandvars(p.format(snap_name))
286 if os.path.exists(snap_path):288 if os.path.exists(snap_path):
diff --git a/tests/test_bug_assistant.py b/tests/test_bug_assistant.py
index 752db7d..7a6fe07 100644
--- a/tests/test_bug_assistant.py
+++ b/tests/test_bug_assistant.py
@@ -23,6 +23,23 @@ def get_snaps(session_mocker):
23 session_mocker.patch("qabro.utils.get_snaps", return_value=[test_snap, ])23 session_mocker.patch("qabro.utils.get_snaps", return_value=[test_snap, ])
2424
2525
26def test_get_last_checkbox_session_path_generic(get_snaps, tmp_path):
27 session_dir = "var/tmp/checkbox-ng/sessions"
28 for session in ["session1", "session2", "last_session"]:
29 s = tmp_path / session_dir / session
30 s.mkdir(parents=True)
31 last_session_path = tmp_path / session_dir / "last_session"
32 # Add 1 second to last session directory access/modify time to make sure
33 # it will be seen as the most recent session directory
34 last_session_time = os.stat(last_session_path).st_mtime + 1
35 os.utime(last_session_path, times=(last_session_time, last_session_time))
36 aa = AttachmentAssistant()
37 last_session = aa._get_last_checkbox_session_path(usr_home="/nothing/here",
38 root_home="/nothing/here",
39 root_dir=tmp_path)
40 assert last_session.endswith("last_session")
41
42
26@pytest.mark.parametrize("usr_dir",43@pytest.mark.parametrize("usr_dir",
27 [".cache/plainbox/sessions",44 [".cache/plainbox/sessions",
28 "snap/checkbox-snappy/current/.cache/plainbox/sessions"])45 "snap/checkbox-snappy/current/.cache/plainbox/sessions"])
@@ -36,7 +53,8 @@ def test_get_last_checkbox_session_path_ubuntu_classic(get_snaps, tmp_path, usr_
36 last_session_time = os.stat(last_session_path).st_mtime + 153 last_session_time = os.stat(last_session_path).st_mtime + 1
37 os.utime(last_session_path, times=(last_session_time, last_session_time))54 os.utime(last_session_path, times=(last_session_time, last_session_time))
38 aa = AttachmentAssistant()55 aa = AttachmentAssistant()
39 last_session = aa._get_last_checkbox_session_path(usr_dir=tmp_path, root_dir="/nothing/here")56 last_session = aa._get_last_checkbox_session_path(usr_home=tmp_path,
57 root_home="/nothing/here")
40 assert last_session.endswith("last_session")58 assert last_session.endswith("last_session")
4159
4260
@@ -51,13 +69,15 @@ def test_get_last_checkbox_session_path_ubuntu_core(get_snaps, tmp_path):
51 last_session_time = os.stat(last_session_path).st_mtime + 169 last_session_time = os.stat(last_session_path).st_mtime + 1
52 os.utime(last_session_path, times=(last_session_time, last_session_time))70 os.utime(last_session_path, times=(last_session_time, last_session_time))
53 aa = AttachmentAssistant()71 aa = AttachmentAssistant()
54 last_session = aa._get_last_checkbox_session_path(usr_dir="/nothing/here", root_dir=tmp_path)72 last_session = aa._get_last_checkbox_session_path(usr_home="/nothing/here",
73 root_home=tmp_path)
55 assert last_session.endswith("last_session")74 assert last_session.endswith("last_session")
5675
5776
58def test_get_last_checkbox_session_path_no_session(get_snaps, tmp_path):77def test_get_last_checkbox_session_path_no_session(get_snaps, tmp_path):
59 aa = AttachmentAssistant()78 aa = AttachmentAssistant()
60 last_session = aa._get_last_checkbox_session_path(usr_dir="/nothing/here", root_dir="/nothing/there")79 last_session = aa._get_last_checkbox_session_path(usr_home="/nothing/here",
80 root_home="/nothing/there")
61 assert last_session == ""81 assert last_session == ""
6282
6383

Subscribers

People subscribed via source and target branches

to all changes: