Skip to contentSkip to conversation

test: Have test_fs work with non-functional guestmount tools

PATCH New Tom Rini 2 participants 4 messages Jul 7, 2020

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 test: Have test_fs work with non-functional guestmount tools

Since 2011 Ubuntu has intentionally broken support for guestmount[1] by default and requires sysadmin intervention to re-enable support. This in turn exposed that in our tests if guestmount is available but fails we do not fall back to trying to use sudo. Restructure our code to try sudo if guestmount fails rather than only when it is not in our path. Further, only note that we are using fuse on success of the call.

[1]: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/759725

Cc Heinrich Schuchardt <[email protected]>
Cc Simon Glass <[email protected]>
Cc Stephen Warren <[email protected]>

---
This, I suspect, will also fix the cases where in CI we attempt to run the FS tests but do not as guestmount fails. I'm not going to remove guestmount from the Docker containers as it's a useful reference for "what is required for a minimal environment for U-Boot builds" and perhaps we will switch to Debian instead at some point.

---
 test/py/tests/test_fs/conftest.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
test/py/tests/test_fs/conftest.py +5 -4
index ee82169c2a37..d8ce1876ffca 100644
@@ -206,10 +206,11 @@ def mount_fs(fs_type, device, mount_point):
     fuse_mounted = False
     try:
         if tool_is_in_path('guestmount'):
-            fuse_mounted = True
             check_call('guestmount -a %s -m /dev/sda %s'
                 % (device, mount_point), shell=True)
-        else:
+            fuse_mounted = True
+    except CalledProcessError:
+        try:
             mount_opt = 'loop,rw'
             if re.match('fat', fs_type):
                 mount_opt += ',umask=0000'
@@ -219,8 +220,8 @@ def mount_fs(fs_type, device, mount_point):
 
             # may not be effective for some file systems
             check_call('sudo chmod a+rw %s' % mount_point, shell=True)
-    except CalledProcessError:
-        raise
+        except CalledProcessError:
+            raise
 
 def umount_fs(mount_point):
     """Unmount a volume.
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 test: Have test_fs work with non-functional guestmount tools

Quoted 8 lines · Tom Rini

Since 2011 Ubuntu has intentionally broken support for guestmount[1] by default and requires sysadmin intervention to re-enable support. This in turn exposed that in our tests if guestmount is available but fails we do not fall back to trying to use sudo. Restructure our code to try sudo if guestmount fails rather than only when it is not in our path. Further, only note that we are using fuse on success of the call.

[1]: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/759725

That is ... an interesting bug!

This change looks conceptually fine.

Quoted 1 line
test/py/tests/test_fs/conftest.py +0 -0

...

test/py/tests/test_fs/conftest.py def mount_fs(fs_type, device, mount_point):

Quoted 1 line
test/py/tests/test_fs/conftest.py +0 -0
@@ -206,10 +206,11 @@ def mount_fs(fs_type, device, mount_point):

...> + try:

Quoted 3 lines
test/py/tests/test_fs/conftest.py +0 -0
             mount_opt = 'loop,rw'
             if re.match('fat', fs_type):
                 mount_opt += ',umask=0000'

...

test/py/tests/test_fs/conftest.py def mount_fs(fs_type, device, mount_point): · line 224

Quoted 5 lines
 
             # may not be effective for some file systems
             check_call('sudo chmod a+rw %s' % mount_point, shell=True)
test/py/tests/test_fs/conftest.py +2 -0
+        except CalledProcessError:
+            raise

That last/inner try...except/raise clause doesn't seem useful. Perhaps just remote try...except and keep the body?

author
#2 lore raw

PATCH 1/1 test: Have test_fs work with non-functional guestmount tools

Quoted 23 lines · Stephen Warren
Quoted 8 lines · Tom Rini

Since 2011 Ubuntu has intentionally broken support for guestmount[1] by default and requires sysadmin intervention to re-enable support. This in turn exposed that in our tests if guestmount is available but fails we do not fall back to trying to use sudo. Restructure our code to try sudo if guestmount fails rather than only when it is not in our path. Further, only note that we are using fuse on success of the call.

[1]: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/759725

That is ... an interesting bug!

This change looks conceptually fine.

Quoted 1 line
test/py/tests/test_fs/conftest.py +0 -0

...

test/py/tests/test_fs/conftest.py def mount_fs(fs_type, device, mount_point):

Quoted 1 line
test/py/tests/test_fs/conftest.py +0 -0
@@ -206,10 +206,11 @@ def mount_fs(fs_type, device, mount_point):

...> + try:

Quoted 3 lines
test/py/tests/test_fs/conftest.py +0 -0
             mount_opt = 'loop,rw'
             if re.match('fat', fs_type):
                 mount_opt += ',umask=0000'

...

Quoted 1 line
Quoted 7 lines

test/py/tests/test_fs/conftest.py def mount_fs(fs_type, device, mount_point): · line 224

Quoted 4 lines
             # may not be effective for some file systems
             check_call('sudo chmod a+rw %s' % mount_point, shell=True)
test/py/tests/test_fs/conftest.py +2 -0
+        except CalledProcessError:
+            raise

That last/inner try...except/raise clause doesn't seem useful. Perhaps just remote try...except and keep the body?

I don't quite follow, sorry. What we have today is if/else on guestmount, but since check_call() throws CalledProcessError when it fails to run we never try sudo'ing. That's why I put the inner try/except/raise in.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200707/0fda2c9d/attachment.sig>
#3 lore raw

PATCH 1/1 test: Have test_fs work with non-functional guestmount tools

Quoted 30 lines · Tom Rini
Quoted 10 lines · Stephen Warren
Quoted 8 lines · Tom Rini

Since 2011 Ubuntu has intentionally broken support for guestmount[1] by default and requires sysadmin intervention to re-enable support. This in turn exposed that in our tests if guestmount is available but fails we do not fall back to trying to use sudo. Restructure our code to try sudo if guestmount fails rather than only when it is not in our path. Further, only note that we are using fuse on success of the call.

[1]: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/759725

Quoted 8 lines

That is ... an interesting bug!

This change looks conceptually fine.

Quoted 1 line
test/py/tests/test_fs/conftest.py +0 -0

...

Quoted 1 line
test/py/tests/test_fs/conftest.py +0 -0
@@ -206,10 +206,11 @@ def mount_fs(fs_type, device, mount_point):

...

+ try:

Quoted 10 lines
Quoted 3 lines
             mount_opt = 'loop,rw'
             if re.match('fat', fs_type):
                 mount_opt += ',umask=0000'

...

Quoted 5 lines
 
             # may not be effective for some file systems
             check_call('sudo chmod a+rw %s' % mount_point, shell=True)
test/py/tests/test_fs/conftest.py +2 -0
+        except CalledProcessError:
+            raise
Quoted 7 lines
Quoted 2 lines

That last/inner try...except/raise clause doesn't seem useful. Perhaps just remote try...except and keep the body?

I don't quite follow, sorry. What we have today is if/else on guestmount, but since check_call() throws CalledProcessError when it fails to run we never try sudo'ing. That's why I put the inner try/except/raise in.

It's the outer try/except that switches between the two options, not the inner one.

It makes sense to have one try/except to catch errors running guestmount and switch to sudo mount. However, the second try/except block that solely wraps the sudo mount call doesn't do anything; it simply catches an exception and then immediately re-raises it. This same issue is actually present in the original code, except that there is applies to a larger region of code.

So, wherever the code does this:

try:
something
except CalledProcessError:
raise

Just replace that with this:

something

So...

fuse_mounted = False
try:
if tool_is_in_path('guestmount'):
check_call('guestmount -a %s -m /dev/sda %s'
% (device, mount_point), shell=True)
fuse_mounted = True
except CalledProcessError:
# TODO: Remove the try here
# TODO: Remove 1 indent level from the rest of this code
mount_opt = 'loop,rw'
if re.match('fat', fs_type):
mount_opt += ',umask=0000'
@@ -219,8 +220,8 @@ def mount_fs(fs_type, device, mount_point):

             # may not be effective for some file systems
             check_call('sudo chmod a+rw %s' % mount_point, shell=True)
        # TODO: Remove the except/raise here