mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-06-03 10:50:20 +00:00
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 <veiko17@disroot.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
a0415bc110
commit
0f16a0fbee
27
functional_tests/features/storage.feature
Normal file
27
functional_tests/features/storage.feature
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
@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
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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']
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user