Skip to contentSkip to conversation

test: Include /sbin to the PATH when creating ext4 disk image

PATCH New Andy Shevchenko 2 participants 5 messages Feb 3, 2021 – Feb 5, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test: Include /sbin to the PATH when creating ext4 disk image

On some distributions the mkfs.ext4 is under /sbin and /sbin is not set for mere users. Include /sbin to the PATH when creating ext4 disk image, so that users won't get a scary traceback from Python.

---
 test/py/tests/test_env.py | 3 +++
 1 file changed, 3 insertions(+)
test/py/tests/test_env.py +3 -0
index 940279651da0..536467320e06 100644
@@ -414,6 +414,9 @@ def mk_env_ext4(state_test_env):
     if os.path.exists(persistent):
         c.log.action('Disk image file ' + persistent + ' already exists')
     else:
+        root_path = os.path.abspath('.').split(os.path.sep)[0] + os.path.sep
+        sbin_path = os.path.join(root_path, 'sbin')
+        os.environ["PATH"] += os.pathsep + sbin_path
         try:
             u_boot_utils.run_and_log(c, 'dd if=/dev/zero of=%s bs=1M count=16' % persistent)
             u_boot_utils.run_and_log(c, 'mkfs.ext4 %s' % persistent)
Signature · 1 line
2.30.0
#1 lore raw

PATCH 1/1 test: Include /sbin to the PATH when creating ext4 disk image

Hi Andy,

Quoted 15 lines · Andy Shevchenko

On some distributions the mkfs.ext4 is under /sbin and /sbin is not set for mere users. Include /sbin to the PATH when creating ext4 disk image, so that users won't get a scary traceback from Python.

---
 test/py/tests/test_env.py | 3 +++
 1 file changed, 3 insertions(+)
test/py/tests/test_env.py +0 -0
index 940279651da0..536467320e06 100644

test/py/tests/test_env.py def mk_env_ext4(state_test_env): · line 417

Quoted 4 lines
test/py/tests/test_env.py +1 -0
@@ -414,6 +414,9 @@ def mk_env_ext4(state_test_env):
     if os.path.exists(persistent):
         c.log.action('Disk image file ' + persistent + ' already exists')
     else:
+        root_path = os.path.abspath('.').split(os.path.sep)[0] + os.path.sep

Is it not enough to do os.path.abspath('.') ? I think it would be good to have a comment as to what we need this gymnastics.

Quoted 8 lines
test/py/tests/test_env.py +2 -1
+        sbin_path = os.path.join(root_path, 'sbin')
+        os.environ["PATH"] += os.pathsep + sbin_path
         try:
             u_boot_utils.run_and_log(c, 'dd if=/dev/zero of=%s bs=1M count=16' % persistent)
             u_boot_utils.run_and_log(c, 'mkfs.ext4 %s' % persistent)
--

2.30.0

Regards,
Simon

#2 lore raw

PATCH 1/1 test: Include /sbin to the PATH when creating ext4 disk image

Quoted 2 lines · Simon Glass

On Wed, 3 Feb 2021 at 08:32, Andy Shevchenko
<[email protected]> wrote:

...

Quoted 7 lines
Quoted 4 lines

if os.path.exists(persistent):
c.log.action('Disk image file ' + persistent + ' already exists')
else:
+ root_path = os.path.abspath('.').split(os.path.sep)[0] + os.path.sep

Is it not enough to do os.path.abspath('.') ? I think it would be good to have a comment as to what we need this gymnastics.

It's just a portable code. Of course we can simple use abspath() on *nix OSes. My preference is to have portable code, though. What's yours?

Quoted 5 lines
Quoted 5 lines
test/py/tests/test_env.py +2 -0
+        sbin_path = os.path.join(root_path, 'sbin')
+        os.environ["PATH"] += os.pathsep + sbin_path
         try:
             u_boot_utils.run_and_log(c, 'dd if=/dev/zero of=%s bs=1M count=16' % persistent)
             u_boot_utils.run_and_log(c, 'mkfs.ext4 %s' % persistent)
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

PATCH 1/1 test: Include /sbin to the PATH when creating ext4 disk image

Quoted 11 lines · Andy Shevchenko
Quoted 2 lines · Simon Glass

On Wed, 3 Feb 2021 at 08:32, Andy Shevchenko
<[email protected]> wrote:

...

Quoted 5 lines
Quoted 4 lines

if os.path.exists(persistent):
c.log.action('Disk image file ' + persistent + ' already exists')
else:
+ root_path = os.path.abspath('.').split(os.path.sep)[0] + os.path.sep

Quoted 11 lines
Quoted 2 lines

Is it not enough to do os.path.abspath('.') ? I think it would be good to have a comment as to what we need this gymnastics.

It's just a portable code. Of course we can simple use abspath() on *nix OSes. My preference is to have portable code, though. What's yours?

Quoted 5 lines
Quoted 5 lines
test/py/tests/test_env.py +2 -0
+        sbin_path = os.path.join(root_path, 'sbin')
+        os.environ["PATH"] += os.pathsep + sbin_path
         try:
             u_boot_utils.run_and_log(c, 'dd if=/dev/zero of=%s bs=1M count=16' % persistent)
             u_boot_utils.run_and_log(c, 'mkfs.ext4 %s' % persistent)

Since below we have /dev/zero explicitly I will replace the above to simple '/sbin'.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

PATCH 1/1 test: Include /sbin to the PATH when creating ext4 disk image

Hi Andy,

Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
Quoted 2 lines · Simon Glass

On Wed, 3 Feb 2021 at 08:32, Andy Shevchenko
<[email protected]> wrote:

...

Quoted 5 lines
Quoted 4 lines

if os.path.exists(persistent):
c.log.action('Disk image file ' + persistent + ' already exists')
else:
+ root_path = os.path.abspath('.').split(os.path.sep)[0] + os.path.sep

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

Is it not enough to do os.path.abspath('.') ? I think it would be good to have a comment as to what we need this gymnastics.

It's just a portable code. Of course we can simple use abspath() on *nix OSes. My preference is to have portable code, though. What's yours?

Portable to what? Can you add a comment as to what it is for?

Quoted 9 lines
Quoted 6 lines
Quoted 6 lines

test/py/tests/test_env.py def mk_env_ext4(state_test_env): · line 422

Quoted 6 lines
test/py/tests/test_env.py +2 -0
+        sbin_path = os.path.join(root_path, 'sbin')
+        os.environ["PATH"] += os.pathsep + sbin_path
         try:
             u_boot_utils.run_and_log(c, 'dd if=/dev/zero of=%s bs=1M count=16' % persistent)
             u_boot_utils.run_and_log(c, 'mkfs.ext4 %s' % persistent)

Since below we have /dev/zero explicitly I will replace the above to simple '/sbin'.

OK

Regards,
Simon