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
1diff --git a/CHANGELOG.md b/CHANGELOG.md
2index eefb675..b476e42 100644
3--- a/CHANGELOG.md
4+++ b/CHANGELOG.md
5@@ -8,9 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6 ### Added
7 - Unit tests (see Contributing Guidelines for more info)
8
9+### Changed
10+- 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)).
11+
12 ### Fixed
13 ([LP #1891609](https://bugs.launchpad.net/qabro/+bug/1887903))
14-- `JSONDecodeError` when launching qabro on some installations ([LP #1891609](https://bugs.launchpad.net/qabro/+bug/1887903))
15+- `JSONDecodeError` when launching qabro on some installations ([LP #1887903](https://bugs.launchpad.net/qabro/+bug/1887903))
16 - Cannot upload attachments: 'title' error is shown ([LP #1891609](https://bugs.launchpad.net/qabro/+bug/1891609))
17
18
19diff --git a/qabro/bug_assistant.py b/qabro/bug_assistant.py
20index 6a720b0..f8630e4 100644
21--- a/qabro/bug_assistant.py
22+++ b/qabro/bug_assistant.py
23@@ -267,20 +267,22 @@ class AttachmentAssistant:
24 snap.props.confinement.value_nick)
25 self.attachments["snap_list.log"] = out.encode()
26
27- def _get_last_checkbox_session_path(self, usr_dir="/home/$USER", root_dir="/root"):
28+ def _get_last_checkbox_session_path(self, usr_home="/home/$USER", root_home="/root", root_dir="/"):
29 """Return path of the most recent Checkbox session directory."""
30 rootpath = ''
31 latest_session_dir = ''
32- # Determine if we use a classic install or a snap install
33- classic_path = os.path.expandvars(os.path.join(usr_dir, ".cache/plainbox/sessions"))
34- if os.path.exists(classic_path):
35+ generic_path = os.path.join(root_dir, "var/tmp/checkbox-ng/sessions")
36+ classic_path = os.path.expandvars(os.path.join(usr_home, ".cache/plainbox/sessions"))
37+ if os.path.exists(generic_path): # for any checkbox installs based on checkbox-ng >= 1.10
38+ rootpath = generic_path
39+ elif os.path.exists(classic_path): # for classic checkbox installs based on checkbox-ng <= 1.9
40 rootpath = classic_path
41- else:
42+ else: # for snap checkbox installs based on checkbox-ng <= 1.9
43 snaps = qabro.utils.get_snaps()
44 snap_list = [e.props.name for e in snaps if 'checkbox-' in e.props.name]
45 for snap_name in snap_list:
46- sp = [os.path.join(usr_dir, "snap/{}/current/.cache/plainbox/sessions"),
47- os.path.join(root_dir, "snap/{}/current/.cache/plainbox/sessions")]
48+ sp = [os.path.join(usr_home, "snap/{}/current/.cache/plainbox/sessions"),
49+ os.path.join(root_home, "snap/{}/current/.cache/plainbox/sessions")]
50 for p in sp:
51 snap_path = os.path.expandvars(p.format(snap_name))
52 if os.path.exists(snap_path):
53diff --git a/tests/test_bug_assistant.py b/tests/test_bug_assistant.py
54index 752db7d..7a6fe07 100644
55--- a/tests/test_bug_assistant.py
56+++ b/tests/test_bug_assistant.py
57@@ -23,6 +23,23 @@ def get_snaps(session_mocker):
58 session_mocker.patch("qabro.utils.get_snaps", return_value=[test_snap, ])
59
60
61+def test_get_last_checkbox_session_path_generic(get_snaps, tmp_path):
62+ session_dir = "var/tmp/checkbox-ng/sessions"
63+ for session in ["session1", "session2", "last_session"]:
64+ s = tmp_path / session_dir / session
65+ s.mkdir(parents=True)
66+ last_session_path = tmp_path / session_dir / "last_session"
67+ # Add 1 second to last session directory access/modify time to make sure
68+ # it will be seen as the most recent session directory
69+ last_session_time = os.stat(last_session_path).st_mtime + 1
70+ os.utime(last_session_path, times=(last_session_time, last_session_time))
71+ aa = AttachmentAssistant()
72+ last_session = aa._get_last_checkbox_session_path(usr_home="/nothing/here",
73+ root_home="/nothing/here",
74+ root_dir=tmp_path)
75+ assert last_session.endswith("last_session")
76+
77+
78 @pytest.mark.parametrize("usr_dir",
79 [".cache/plainbox/sessions",
80 "snap/checkbox-snappy/current/.cache/plainbox/sessions"])
81@@ -36,7 +53,8 @@ def test_get_last_checkbox_session_path_ubuntu_classic(get_snaps, tmp_path, usr_
82 last_session_time = os.stat(last_session_path).st_mtime + 1
83 os.utime(last_session_path, times=(last_session_time, last_session_time))
84 aa = AttachmentAssistant()
85- last_session = aa._get_last_checkbox_session_path(usr_dir=tmp_path, root_dir="/nothing/here")
86+ last_session = aa._get_last_checkbox_session_path(usr_home=tmp_path,
87+ root_home="/nothing/here")
88 assert last_session.endswith("last_session")
89
90
91@@ -51,13 +69,15 @@ def test_get_last_checkbox_session_path_ubuntu_core(get_snaps, tmp_path):
92 last_session_time = os.stat(last_session_path).st_mtime + 1
93 os.utime(last_session_path, times=(last_session_time, last_session_time))
94 aa = AttachmentAssistant()
95- last_session = aa._get_last_checkbox_session_path(usr_dir="/nothing/here", root_dir=tmp_path)
96+ last_session = aa._get_last_checkbox_session_path(usr_home="/nothing/here",
97+ root_home=tmp_path)
98 assert last_session.endswith("last_session")
99
100
101 def test_get_last_checkbox_session_path_no_session(get_snaps, tmp_path):
102 aa = AttachmentAssistant()
103- last_session = aa._get_last_checkbox_session_path(usr_dir="/nothing/here", root_dir="/nothing/there")
104+ last_session = aa._get_last_checkbox_session_path(usr_home="/nothing/here",
105+ root_home="/nothing/there")
106 assert last_session == ""
107
108

Subscribers

People subscribed via source and target branches

to all changes: