def main(self, argv): # these need to be available for the help, which gets parsed super # early self.load_ceph_conf_path() self.load_log_path() self.enable_plugins() main_args, subcommand_args = self._get_split_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(argv) <= 1: print(self.help(warning=True)) return parser = argparse.ArgumentParser( prog='ceph-volume', formatter_class=argparse.RawDescriptionHelpFormatter, description=self.help(), ) parser.add_argument( '--cluster', default='ceph', help='Cluster name (defaults to "ceph")', ) parser.add_argument( '--log-level', default='debug', help='Change the file log level (defaults to debug)', ) parser.add_argument( '--log-path', default='/var/log/ceph/', help='Change the log path (defaults to /var/log/ceph)', ) args = parser.parse_args(main_args) conf.log_path = args.log_path if os.path.isdir(conf.log_path): conf.log_path = os.path.join(args.log_path, 'ceph-volume.log') log.setup() logger = logging.getLogger(__name__) logger.info("Running command: ceph-volume %s %s", " ".join(main_args), " ".join(subcommand_args)) # set all variables from args and load everything needed according to # them self.load_ceph_conf_path(cluster_name=args.cluster) try: conf.ceph = configuration.load(conf.path) except exceptions.ConfigurationError as error: is_help = "-h" in subcommand_args or "--help" in subcommand_args if " ".join(subcommand_args[:2]) in IGNORE_CEPH_CONFIG_COMMANDS or is_help: # we warn only here, because it is possible that the configuration # file is not needed, or that it will be loaded by some other means # (like reading from lvm tags) logger.exception('ignoring inability to load ceph.conf') terminal.red(error) else: terminal.red(error) raise # dispatch to sub-commands terminal.dispatch(self.mapper, subcommand_args)
def main(self): terminal.dispatch(self.mapper, self.argv) parser = argparse.ArgumentParser( prog='ceph-volume lvm', formatter_class=argparse.RawDescriptionHelpFormatter, description=self.print_help(terminal.subhelp(self.mapper)), ) parser.parse_args(self.argv) if len(self.argv) <= 1: return parser.print_help()
def main(self, argv): self.load_ceph_conf_path() # these need to be available for the help, which gets parsed super # early self.load_ceph_conf_path() self.load_log_path() main_args, subcommand_args = self._get_split_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(argv) <= 1: print(self.help(warning=True)) return parser = argparse.ArgumentParser( prog='ceph-volume-zfs', formatter_class=argparse.RawDescriptionHelpFormatter, description=self.help(), ) parser.add_argument( '--cluster', default='ceph', help='Cluster name (defaults to "ceph")', ) parser.add_argument( '--log-level', default='debug', help='Change the file log level (defaults to debug)', ) parser.add_argument( '--log-path', default='/var/log/ceph/', help='Change the log path (defaults to /var/log/ceph)', ) args = parser.parse_args(main_args) conf.log_path = args.log_path if os.path.isdir(conf.log_path): conf.log_path = os.path.join(args.log_path, 'ceph-volume-zfs.log') log.setup() logger = logging.getLogger(__name__) logger.info("Running command: ceph-volume-zfs %s %s", " ".join(main_args), " ".join(subcommand_args)) # set all variables from args and load everything needed according to # them self.load_ceph_conf_path(cluster_name=args.cluster) try: conf.ceph = configuration.load(conf.path) except exceptions.ConfigurationError as error: # we warn only here, because it is possible that the configuration # file is not needed, or that it will be loaded by some other means # (like reading from zfs tags) logger.exception('ignoring inability to load ceph.conf') terminal.red(error) # dispatch to sub-commands terminal.dispatch(self.mapper, subcommand_args)
def test_no_main_found(self): class NoMain(object): def __init__(self, argv): pass result = terminal.dispatch({'sub': NoMain}, argv=['sub']) assert result is None
def main(self, argv): # these need to be available for the help, which gets parsed super # early self.load_ceph_conf_path() self.load_log_path() self.enable_plugins() main_args, subcommand_args = self._get_split_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(argv) <= 1: print(self.help(warning=True)) return parser = argparse.ArgumentParser( prog='ceph-volume', formatter_class=argparse.RawDescriptionHelpFormatter, description=self.help(), ) parser.add_argument( '--cluster', default='ceph', help='Cluster name (defaults to "ceph")', ) parser.add_argument( '--log-level', default='debug', help='Change the file log level (defaults to debug)', ) parser.add_argument( '--log-path', default='/var/log/ceph/', help='Change the log path (defaults to /var/log/ceph)', ) args = parser.parse_args(main_args) conf.log_path = args.log_path if os.path.isdir(conf.log_path): conf.log_path = os.path.join(args.log_path, 'ceph-volume.log') log.setup() # set all variables from args and load everything needed according to # them self.load_ceph_conf_path(cluster_name=args.cluster) conf.ceph = configuration.load(conf.path) # dispatch to sub-commands terminal.dispatch(self.mapper, subcommand_args)
def test_subcommand_found_and_dispatched_with_errors(self): with pytest.raises(SystemExit) as error: terminal.dispatch({'sub': BadSubCommand}, argv=['sub']) assert str(error.value) == '100'
def test_no_subcommand_found(self): result = terminal.dispatch({'sub': SubCommand}, argv=[]) assert result is None