storage: tests: functional: Fix tests always getting skipped

- The method to check if we are running inside a container is not being called.
Call it.

- Also fix the assumption that tests and freedombox service run on the same
machine. Be conservative and assume running in container if we can't determine
the accurate state.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>

Reviewed-by: Fioddor Superconcentrado <fioddor@gmail.com>
This commit is contained in:
Sunil Mohan Adapa 2021-10-05 20:10:43 -07:00 committed by Fioddor Superconcentrado
parent 2b525a1930
commit 4b708214e4
2 changed files with 12 additions and 3 deletions

View File

@ -3,6 +3,7 @@
Functional, browser based tests for storage app.
"""
import pytest
from plinth.tests import functional
pytestmark = [pytest.mark.system, pytest.mark.essential, pytest.mark.storage]
@ -16,7 +17,7 @@ def fixture_background(session_browser):
def test_list_disks(session_browser):
"""Test that root disk is shown on storage page."""
if functional.running_inside_container:
if functional.running_inside_container():
pytest.skip('Storage doesn\'t work inside a container')
else:
functional.nav_to_module(session_browser, 'storage')

View File

@ -439,9 +439,17 @@ def service_is_not_running(browser, app_name):
def running_inside_container():
"""Check if freedombox is running inside a container"""
# If the URL to connect to was overridden then assume that we are running
# tests on a different machine than the machine running freedombox. Assume
# running inside container to be conservative about tests.
if config['DEFAULT']['url'] != 'https://localhost':
return True
# If URL is not overridden then testing code and freedombox are running on
# the same machine. Proceed with a proper test.
result = subprocess.run(['systemd-detect-virt', '--container'],
stdout=subprocess.PIPE)
return bool(result.stdout.decode('utf-8').lower() != "none\n")
stdout=subprocess.PIPE, check=False)
return result.stdout.decode('utf-8').strip().lower() != 'none'
##############################