Add sort_mount_point method
As this method can be introduced without any dependency, provide it on an independent change to simplify reviews. This is a partial refactor based on I592c0b1329409307197460cfa8fd69798013f1f8 Change-Id: Idaf3d2b3b3e23d0b9d6bc071d67b961a829ae422 Co-Authored-By: Andreas Florath <andreas@florath.net>
This commit is contained in:
parent
c3dda92b67
commit
59a1fc6546
@ -97,3 +97,23 @@ def exec_sudo(cmd):
|
||||
logger.error("Calling [%s] failed with [%s]" %
|
||||
(" ".join(sudo_cmd), rval))
|
||||
return rval
|
||||
|
||||
|
||||
def sort_mount_points(mount_points):
|
||||
logger.debug("sort_mount_points called [%s]" % mount_points)
|
||||
|
||||
def insert_sorted(mp, sorted_mount_points):
|
||||
if len(sorted_mount_points) == 0:
|
||||
sorted_mount_points.append(mp)
|
||||
return
|
||||
for idx in range(0, len(sorted_mount_points)):
|
||||
if sorted_mount_points[idx].startswith(mp):
|
||||
sorted_mount_points.insert(idx, mp)
|
||||
return
|
||||
sorted_mount_points.append(mp)
|
||||
|
||||
sorted_mount_points = []
|
||||
for mp in mount_points:
|
||||
insert_sorted(mp, sorted_mount_points)
|
||||
logger.debug("sort_mount_points result [%s]" % sorted_mount_points)
|
||||
return sorted_mount_points
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
from diskimage_builder.block_device.utils import parse_abs_size_spec
|
||||
from diskimage_builder.block_device.utils import parse_rel_size_spec
|
||||
from diskimage_builder.block_device.utils import sort_mount_points
|
||||
import testtools
|
||||
|
||||
|
||||
@ -47,3 +48,9 @@ class TestBlockDeviceUtils(testtools.TestCase):
|
||||
"""Call parse_abs_size_spec with a completely broken unit spec"""
|
||||
|
||||
self.assertRaises(RuntimeError, parse_abs_size_spec, "_+!HuHi+-=")
|
||||
|
||||
def test_sort_mount_points(self):
|
||||
"""Run sort_mount_points with a set of paths"""
|
||||
|
||||
smp = sort_mount_points(["/boot", "/", "/var/tmp", "/var"])
|
||||
self.assertEqual(['/', '/boot', '/var', '/var/tmp'], smp)
|
||||
|
Loading…
Reference in New Issue
Block a user