From: Alfredo Deza Date: Mon, 16 Apr 2018 18:42:22 +0000 (-0400) Subject: ceph-volume util.prepare preserve order on incoming mount flags X-Git-Tag: v12.2.5~8^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fd48bd4392c34538451892e77a645c422929225f;p=ceph.git ceph-volume util.prepare preserve order on incoming mount flags Signed-off-by: Alfredo Deza (cherry picked from commit 89f8f82402f9eda7cf76ebe860e50dd8e1047d76) --- diff --git a/src/ceph-volume/ceph_volume/util/prepare.py b/src/ceph-volume/ceph_volume/util/prepare.py index b8e9d3183647..d02c570fec82 100644 --- a/src/ceph-volume/ceph_volume/util/prepare.py +++ b/src/ceph-volume/ceph_volume/util/prepare.py @@ -162,13 +162,21 @@ def _normalize_mount_flags(flags, extras=None): :param extras: Extra set of mount flags, useful when custom devices like VDO need ad-hoc mount configurations """ + # Instead of using set(), we append to this new list here, because set() + # will create an arbitrary order on the items that is made worst when + # testing with tools like tox that includes a randomizer seed. By + # controlling the order, it is easier to correctly assert the expectation + unique_flags = [] if isinstance(flags, list): if extras: flags.extend(extras) + # ensure that spaces and commas are removed so that they can join # correctly, remove duplicates - flags = set([f.strip().strip(',') for f in flags if f]) - return ','.join(flags) + for f in flags: + if f and f not in unique_flags: + unique_flags.append(f.strip().strip(',')) + return ','.join(unique_flags) # split them, clean them, and join them back again flags = flags.strip().split(' ') @@ -176,7 +184,10 @@ def _normalize_mount_flags(flags, extras=None): flags.extend(extras) # remove possible duplicates - flags = ','.join([f.strip().strip(',') for f in flags if f]) + for f in flags: + if f and f not in unique_flags: + unique_flags.append(f.strip().strip(',')) + flags = ','.join(unique_flags) # Before returning, split them again, since strings can be mashed up # together, preventing removal of duplicate entries return ','.join(set(flags.split(',')))