From 0f16a0fbee3ac939ae7adb202ef2c8772c5c3d09 Mon Sep 17 00:00:00 2001 From: Veiko Aasa Date: Wed, 29 Jan 2020 18:19:40 +0200 Subject: [PATCH] storage: Show disks if FreedomBox is running in an unprivileged container - Get disks info from df command and add info from udisks, if available. Before, it was other way round. - Add a functional test that asserts root disk is available - Remove unused key file_system_type from disks info Closes #1765 Signed-off-by: Veiko Aasa Reviewed-by: James Valleroy --- functional_tests/features/storage.feature | 27 +++++++++++++++++++ .../step_definitions/interface.py | 5 ++++ functional_tests/step_definitions/system.py | 5 ++++ functional_tests/support/interface.py | 4 +-- functional_tests/support/system.py | 5 ++++ plinth/modules/samba/tests/test_views.py | 1 - plinth/modules/storage/__init__.py | 18 +++++++------ 7 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 functional_tests/features/storage.feature diff --git a/functional_tests/features/storage.feature b/functional_tests/features/storage.feature new file mode 100644 index 000000000..9a715437a --- /dev/null +++ b/functional_tests/features/storage.feature @@ -0,0 +1,27 @@ +# +# This file is part of FreedomBox. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# + +@system @storage @essential +Feature: Storage + Show information about the disks. + +Background: + Given I'm a logged in user + +Scenario: List disks + Given I'm on the storage page + Then the root disk should be shown diff --git a/functional_tests/step_definitions/interface.py b/functional_tests/step_definitions/interface.py index 28e12634b..376e5c30d 100644 --- a/functional_tests/step_definitions/interface.py +++ b/functional_tests/step_definitions/interface.py @@ -98,3 +98,8 @@ def help_go_to_status_logs(session_browser): @then('status logs should be shown') def help_status_logs_are_shown(session_browser): assert interface.are_status_logs_shown(session_browser) + + +@given(parsers.parse("I'm on the {name:w} page")) +def go_to_module(session_browser, name): + interface.nav_to_module(session_browser, name) diff --git a/functional_tests/step_definitions/system.py b/functional_tests/step_definitions/system.py index de04ce5d6..5d4aaf6da 100644 --- a/functional_tests/step_definitions/system.py +++ b/functional_tests/step_definitions/system.py @@ -356,3 +356,8 @@ def main_page_is_shown(session_browser): @given(parsers.parse('the network device is in the {zone:w} firewall zone')) def networks_set_firewall_zone(session_browser, zone): system.networks_set_firewall_zone(session_browser, zone) + + +@then('the root disk should be shown') +def storage_root_disk_is_shown(session_browser): + assert system.storage_is_root_disk_shown(session_browser) diff --git a/functional_tests/support/interface.py b/functional_tests/support/interface.py index 8c4ebcf03..4b35885f0 100644 --- a/functional_tests/support/interface.py +++ b/functional_tests/support/interface.py @@ -28,8 +28,8 @@ from .service import wait_for_page_update sys_modules = [ 'avahi', 'backups', 'bind', 'cockpit', 'config', 'datetime', 'diagnostics', 'dynamicdns', 'firewall', 'letsencrypt', 'monkeysphere', 'names', - 'networks', 'pagekite', 'power', 'security', 'snapshot', 'ssh', 'upgrades', - 'users' + 'networks', 'pagekite', 'power', 'security', 'snapshot', 'ssh', 'storage', + 'upgrades','users' ] default_url = config['DEFAULT']['url'] diff --git a/functional_tests/support/system.py b/functional_tests/support/system.py index 5fc3b541b..e579ca532 100644 --- a/functional_tests/support/system.py +++ b/functional_tests/support/system.py @@ -427,3 +427,8 @@ def networks_set_firewall_zone(browser, zone): browser.find_link_by_href(edit_url).first.click() browser.select('zone', zone) browser.find_by_tag("form").first.find_by_tag('input')[-1].click() + + +def storage_is_root_disk_shown(browser): + table_cells = browser.find_by_tag('td') + return any(cell.text == '/' for cell in table_cells) diff --git a/plinth/modules/samba/tests/test_views.py b/plinth/modules/samba/tests/test_views.py index cf83e09a8..54316d6c9 100644 --- a/plinth/modules/samba/tests/test_views.py +++ b/plinth/modules/samba/tests/test_views.py @@ -39,7 +39,6 @@ DISKS = [{ 'label': '', 'filesystem_type': 'ext4', 'mount_point': '/', - 'file_system_type': 'ext4', 'percent_used': 63, 'size_str': '9.5 GiB', 'used_str': '5.7 GiB' diff --git a/plinth/modules/storage/__init__.py b/plinth/modules/storage/__init__.py index adbc66971..cf94d1218 100644 --- a/plinth/modules/storage/__init__.py +++ b/plinth/modules/storage/__init__.py @@ -81,15 +81,15 @@ def init(): def get_disks(): - """Returns list of disks by combining information from df and lsblk.""" - disks = _get_disks_from_udisks() - disks_from_df = _get_disks_from_df() + """Returns list of disks by combining information from df and udisks.""" + disks = _get_disks_from_df() + disks_from_udisks = _get_disks_from_udisks() - # Add size info from df to the disks from udisks based on mount point. - for disk_from_udisks in disks: - for disk_from_df in disks_from_df: + # Add info from udisks to the disks from df based on mount point. + for disk_from_df in disks: + for disk_from_udisks in disks_from_udisks: if disk_from_udisks['mount_point'] == disk_from_df['mount_point']: - disk_from_udisks.update(disk_from_df) + disk_from_df.update(disk_from_udisks) return sorted(disks, key=lambda disk: disk['device']) @@ -138,7 +138,7 @@ def _get_disks_from_df(): disks = [] for line in output.splitlines()[1:]: parts = line.split(maxsplit=6) - keys = ('device', 'file_system_type', 'size', 'used', 'free', + keys = ('device', 'filesystem_type', 'size', 'used', 'free', 'percent_used', 'mount_point') disk = dict(zip(keys, parts)) disk['percent_used'] = int(disk['percent_used'].rstrip('%')) @@ -148,6 +148,8 @@ def _get_disks_from_df(): disk['size_str'] = format_bytes(disk['size']) disk['used_str'] = format_bytes(disk['used']) disk['free_str'] = format_bytes(disk['free']) + disk['label'] = None + disk['is_removable'] = None disks.append(disk) return disks