Merge ~rodsmith/checkbox-support:fix-disk-support-stack-trace into checkbox-support:master

Proposed by Rod Smith
Status: Merged
Approved by: Maciej Kisielewski
Approved revision: ecbdd9e3abfa773564d5e7c5d349ce786575ac9d
Merged at revision: 5e79d6a1a9418992656c7da28de51884da4ffa9d
Proposed branch: ~rodsmith/checkbox-support:fix-disk-support-stack-trace
Merge into: checkbox-support:master
Diff against target: 45 lines (+8/-9)
1 file modified
checkbox_support/disk_support.py (+8/-9)
Reviewer Review Type Date Requested Status
Maciej Kisielewski Approve
Review via email: mp+390027@code.launchpad.net

Commit message

Fix bug if device file does not exist in disk_support.py

Description of the change

The get_partition_data(file) function in disk_support.py could result in a stack trace if the specified file variable pointed to a non-existent file, as seems to happen on some system configurations (per bug #1889533). This MR fixes that problem, and also addresses some minor stylistic issues identified by kissiel in https://code.launchpad.net/~rodsmith/checkbox-support/+git/checkbox-support/+merge/385587.

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

Great stuff. Thanks for the quick fix!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/checkbox_support/disk_support.py b/checkbox_support/disk_support.py
2index 2915b10..09d8525 100644
3--- a/checkbox_support/disk_support.py
4+++ b/checkbox_support/disk_support.py
5@@ -1,7 +1,3 @@
6-#!/usr/bin/env python3
7-
8-# Disk information/support features
9-#
10 # Copyright (C) 2020 Canonical Ltd.
11 #
12 # Authors:
13@@ -25,14 +21,14 @@ Support functions related to disk devices for Checkbox.
14
15
16 from subprocess import (
17- check_output,
18- PIPE,
19- STDOUT,
20+ CalledProcessError,
21+ check_output
22 )
23 import logging
24 import os
25 import shlex
26 import stat
27+import sys
28 import uuid
29
30
31@@ -50,9 +46,12 @@ def get_partition_data(file):
32 # Get filesystem type....
33 part_data['fs_type'] = ""
34 command = "blkid /dev/{} -o export".format(file)
35- local_results = check_output(shlex.split(command)).split()
36+ try:
37+ local_results = check_output(shlex.split(command)).split()
38+ except CalledProcessError:
39+ local_results = []
40 for result in local_results:
41- result_str = result.decode(encoding="utf-8", errors="ignore")
42+ result_str = result.decode(sys.stdout.encoding, errors="ignore")
43 if "TYPE" in result_str:
44 part_data['fs_type'] = result_str.split("=")[1]
45 return part_data

Subscribers

People subscribed via source and target branches