From 09aa3cf2953bc22fc82ced215bc220fbf2a993c7 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Wed, 12 Jul 2017 16:39:58 -0400 Subject: [PATCH] ceph-volume: main: changes to sys.argv handling for better testing Signed-off-by: Alfredo Deza --- src/ceph-volume/ceph_volume/main.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ceph-volume/ceph_volume/main.py b/src/ceph-volume/ceph_volume/main.py index 0a269ebd7ac56..ca819bbe23649 100644 --- a/src/ceph-volume/ceph_volume/main.py +++ b/src/ceph-volume/ceph_volume/main.py @@ -29,9 +29,11 @@ Ceph Conf: {ceph_path} self.mapper = {'lvm': devices.lvm.LVM} self.plugin_help = "No plugins found/loaded" if argv is None: - argv = sys.argv + self.argv = sys.argv + else: + self.argv = argv if parse: - self.main(argv) + self.main(self.argv) def help(self, warning=False): warning = 'See "ceph-volume --help" for full list of options.' if warning else '' @@ -87,13 +89,13 @@ Ceph Conf: {ceph_path} def _get_sanitized_args(self): subcommands = self.mapper.keys() - slice_on_index = len(sys.argv) + 1 - pruned_args = sys.argv[1:] + slice_on_index = len(self.argv) + 1 + pruned_args = self.argv[1:] for count, arg in enumerate(pruned_args): if arg in subcommands: slice_on_index = count break - return sys.argv[:slice_on_index] + return self.argv[:slice_on_index] @catches() def main(self, argv): @@ -105,7 +107,7 @@ Ceph Conf: {ceph_path} sanitized_args = self._get_sanitized_args() # no flags where passed in, return the help menu instead of waiting for # argparse which will end up complaning that there are no args - if len(sys.argv) <= 1: + if len(argv) <= 1: print self.help(warning=True) return parser = argparse.ArgumentParser( -- 2.39.5