Skip to content

Commit

Permalink
Sd card not tested (BugFix) (#1485)
Browse files Browse the repository at this point in the history
* Fixed storage test for mediacard+usb combo

* Updated mediacard jobs to use the mediacard_combo storage test
  • Loading branch information
fernando79513 authored Sep 25, 2024
1 parent aacb28b commit da70aef
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 9 deletions.
56 changes: 54 additions & 2 deletions checkbox-support/checkbox_support/scripts/run_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,48 @@ def _parse_journal_line(self, line_str):
self.action = "removal"


class MediacardComboStorage(StorageWatcher):
"""
MediacardComboStorage handles the insertion and removal of sd, sdhc, mmc
etc., for devices that combine mediacard and usb storage.
"""

def __init__(self, *args):
super().__init__(*args)
self.mounted_partition = None
self.action = None
self.device = None
self.address = None
self.number = None
self.driver = None

def _validate_insertion(self):
if self.mounted_partition and self.action == "insertion":
logger.info("usable partition: {}".format(self.mounted_partition))
logger.info("Device: {}".format(self.device))
if self.address:
logger.info("Address: {}".format(self.address))
if self.driver:
logger.info("Controller: {}".format(self.driver))
if self.number:
logger.info("Number: {}".format(self.number))
logger.info("Mediacard insertion test passed.")
self.test_passed = True

def _validate_removal(self):
if self.action == "removal":
logger.info("Mediacard removal test passed.")
self.test_passed = True

def _parse_journal_line(self, line_str):
"""
Gets one of the lines from the journal and updates values by calling
the parsers of MediacardStorage and USBStorage.
"""
MediacardStorage._parse_journal_line(self, line_str)
USBStorage._parse_journal_line(self, line_str)


class ThunderboltStorage(StorageWatcher):
"""
ThunderboltStorage handles the insertion and removal of thunderbolt
Expand Down Expand Up @@ -368,8 +410,14 @@ def parse_args():
)
parser.add_argument(
"storage_type",
choices=["usb2", "usb3", "mediacard", "thunderbolt"],
help=("usb2, usb3, mediacard or thunderbolt"),
choices=[
"usb2",
"usb3",
"mediacard",
"mediacard_combo",
"thunderbolt",
],
help=("usb2, usb3, mediacard, mediacard_combo or thunderbolt"),
)
parser.add_argument(
"--zapper-usb-address",
Expand All @@ -389,6 +437,10 @@ def main():
)
elif args.storage_type == "mediacard":
watcher = MediacardStorage(args.storage_type, args.zapper_usb_address)
elif args.storage_type == "mediacard_combo":
watcher = MediacardComboStorage(
args.storage_type, args.zapper_usb_address
)
else:
watcher = USBStorage(args.storage_type, args.zapper_usb_address)

Expand Down
104 changes: 104 additions & 0 deletions checkbox-support/checkbox_support/tests/test_run_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
StorageWatcher,
USBStorage,
MediacardStorage,
MediacardComboStorage,
ThunderboltStorage,
parse_args,
main,
Expand Down Expand Up @@ -428,6 +429,91 @@ def test_mediacard_storage_parse_journal_line(self):
MediacardStorage._parse_journal_line(mock_mediacard_storage, line_str)
self.assertEqual(mock_mediacard_storage.action, None)

def test_mediacard_combo_storage_init(self):
mediacard_combo_storage = MediacardComboStorage(
"mediacard", "zapper_addr"
)
self.assertEqual(mediacard_combo_storage.storage_type, "mediacard")
self.assertEqual(
mediacard_combo_storage.zapper_usb_address, "zapper_addr"
)
self.assertIsNone(mediacard_combo_storage.mounted_partition)

def test_mediacard_combo_storage_validate_insertion(self):
mock_mediacard_combo_storage = MagicMock()
mock_mediacard_combo_storage.mounted_partition = "mmcblk0p1"
mock_mediacard_combo_storage.action = "insertion"
mock_mediacard_combo_storage.device = "SD"
mock_mediacard_combo_storage.address = "123456"
mock_mediacard_combo_storage.driver = None
mock_mediacard_combo_storage.number = None

MediacardComboStorage._validate_insertion(mock_mediacard_combo_storage)
self.assertEqual(mock_mediacard_combo_storage.test_passed, True)

mock_mediacard_combo_storage = MagicMock()
mock_mediacard_combo_storage.mounted_partition = "sda1"
mock_mediacard_combo_storage.action = "insertion"
mock_mediacard_combo_storage.device = "SD"
mock_mediacard_combo_storage.driver = "xhci_hcd"
mock_mediacard_combo_storage.number = 1
mock_mediacard_combo_storage.address = None

MediacardComboStorage._validate_insertion(mock_mediacard_combo_storage)
self.assertEqual(mock_mediacard_combo_storage.test_passed, True)

def test_mediacard_combo_storage_validate_removal(self):
mock_mediacard_combo_storage = MagicMock()
mock_mediacard_combo_storage.action = "removal"

MediacardComboStorage._validate_removal(mock_mediacard_combo_storage)
self.assertEqual(mock_mediacard_combo_storage.test_passed, True)

def test_mediacard_combo_storage_no_insertion(self):
mock_mediacard_combo_storage = MagicMock()
mock_mediacard_combo_storage.mounted_partition = None
mock_mediacard_combo_storage.action = ""
MediacardComboStorage._validate_insertion(mock_mediacard_combo_storage)

def test_mediacard_combo_storage_no_removal(self):
mock_mediacard_combo_storage = MagicMock()
mock_mediacard_combo_storage.action = ""
MediacardComboStorage._validate_removal(mock_mediacard_combo_storage)

def test_mediacard_combo_storage_parse_journal_line(self):
line_str = "mmcblk0: p1"
mock_mediacard_combo_storage = MagicMock()
MediacardComboStorage._parse_journal_line(
mock_mediacard_combo_storage, line_str
)
self.assertEqual(
mock_mediacard_combo_storage.mounted_partition, "mmcblk0p1"
)

line_str = "new SD card at address 123456"
mock_mediacard_combo_storage = MagicMock()
MediacardComboStorage._parse_journal_line(
mock_mediacard_combo_storage, line_str
)
self.assertEqual(mock_mediacard_combo_storage.action, "insertion")
self.assertEqual(mock_mediacard_combo_storage.device, "SD")
self.assertEqual(mock_mediacard_combo_storage.address, "123456")

line_str = "card 123456 removed"
mock_mediacard_combo_storage = MagicMock()
MediacardComboStorage._parse_journal_line(
mock_mediacard_combo_storage, line_str
)
self.assertEqual(mock_mediacard_combo_storage.action, "removal")

line_str = "Invalid line"
mock_mediacard_combo_storage = MagicMock()
mock_mediacard_combo_storage.action = None
MediacardComboStorage._parse_journal_line(
mock_mediacard_combo_storage, line_str
)
self.assertEqual(mock_mediacard_combo_storage.action, None)

def test_thunderbolt_storage_init(self):
thunderbolt_storage = ThunderboltStorage("thunderbolt", "zapper_addr")
self.assertEqual(thunderbolt_storage.storage_type, "thunderbolt")
Expand Down Expand Up @@ -559,6 +645,24 @@ def test_main_mediacard(self, mock_parse_args, mock_mediacard):
# check that the watcher is an MediacardStorage object
self.assertIsInstance(watcher, MediacardStorage)

@patch(
"checkbox_support.scripts.run_watcher.MediacardComboStorage",
spec=MediacardComboStorage,
)
@patch("checkbox_support.scripts.run_watcher.parse_args")
def test_main_mediacard_combo(self, mock_parse_args, mock_mediacard):
mock_parse_args.return_value = argparse.Namespace(
testcase="insertion",
storage_type="mediacard_combo",
zapper_usb_address=None,
)
main()
self.assertEqual(mock_mediacard.call_count, 1)
# get the watcher object from main
watcher = mock_mediacard.return_value
# check that the watcher is an MediacardComboStorage object
self.assertIsInstance(watcher, MediacardComboStorage)

@patch(
"checkbox_support.scripts.run_watcher.ThunderboltStorage",
spec=ThunderboltStorage,
Expand Down
14 changes: 7 additions & 7 deletions providers/base/units/mediacard/jobs.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ category_id: com.canonical.plainbox::mediacard
id: mediacard/mmc-storage-manual
estimated_duration: 120
command:
checkbox-support-run_watcher storage mediacard
checkbox-support-run_watcher storage mediacard_combo
imports: from com.canonical.plainbox import manifest
requires:
manifest.has_card_reader == 'True'
Expand Down Expand Up @@ -36,7 +36,7 @@ id: mediacard/sdhc-storage-manual
flags: also-after-suspend
estimated_duration: 30.0
command:
checkbox-support-run_watcher storage mediacard
checkbox-support-run_watcher storage mediacard_combo
imports: from com.canonical.plainbox import manifest
requires:
manifest.has_card_reader == 'True'
Expand Down Expand Up @@ -67,7 +67,7 @@ category_id: com.canonical.plainbox::mediacard
id: mediacard/cf-storage-manual
estimated_duration: 120
command:
checkbox-support-run_watcher storage mediacard
checkbox-support-run_watcher storage mediacard_combo
imports: from com.canonical.plainbox import manifest
requires:
manifest.has_card_reader == 'True'
Expand Down Expand Up @@ -97,7 +97,7 @@ category_id: com.canonical.plainbox::mediacard
id: mediacard/sdxc-storage-manual
estimated_duration: 120
command:
checkbox-support-run_watcher storage mediacard
checkbox-support-run_watcher storage mediacard_combo
imports: from com.canonical.plainbox import manifest
requires:
manifest.has_card_reader == 'True'
Expand Down Expand Up @@ -127,7 +127,7 @@ category_id: com.canonical.plainbox::mediacard
id: mediacard/ms-storage-manual
estimated_duration: 120
command:
checkbox-support-run_watcher storage mediacard
checkbox-support-run_watcher storage mediacard_combo
imports: from com.canonical.plainbox import manifest
requires:
manifest.has_card_reader == 'True'
Expand Down Expand Up @@ -158,7 +158,7 @@ category_id: com.canonical.plainbox::mediacard
id: mediacard/msp-storage-manual
estimated_duration: 120
command:
checkbox-support-run_watcher storage mediacard
checkbox-support-run_watcher storage mediacard_combo
user: root
imports: from com.canonical.plainbox import manifest
requires:
Expand Down Expand Up @@ -190,7 +190,7 @@ category_id: com.canonical.plainbox::mediacard
id: mediacard/xd-storage-manual
estimated_duration: 120
command:
checkbox-support-run_watcher storage mediacard
checkbox-support-run_watcher storage mediacard_combo
imports: from com.canonical.plainbox import manifest
requires:
manifest.has_card_reader == 'True'
Expand Down

0 comments on commit da70aef

Please sign in to comment.