def test_add_global_identity_args(self):
        parser = mock.Mock()

        cliargs.add_global_identity_args(parser)
        expected = [
            '--os-auth-plugin',
            '--os-auth-url',
            '--os-project-id',
            '--os-project-name',
            '--os-tenant-id',
            '--os-tenant-name',
            '--os-domain-id',
            '--os-domain-name',
            '--os-project-domain-id',
            '--os-project-domain-name',
            '--os-user-domain-id',
            '--os-user-domain-name',
            '--os-username',
            '--os-user-id',
            '--os-password',
            '--os-trust-id',
            '--os-token',
            '--os-access-info',
            '--os-api-name',
            '--os-api-region',
            '--os-api-version',
            '--os-api-interface'
        ]

        options = [arg[0][0] for arg in parser.add_argument.call_args_list]
        self.assertEqual(expected, options)

        parser.add_mutually_exclusive_group.assert_called_once_with()
        group = parser.add_mutually_exclusive_group.return_value

        verify_opts = [arg[0][0] for arg in group.add_argument.call_args_list]
        verify_args = [
            '--os-cacert',
            '--verify',
            '--insecure'
        ]
        self.assertEqual(verify_args, verify_opts)
    def main(self, argv):
        # Parse args once to find version
        parser = argparse.ArgumentParser(
            prog='senlin',
            description=__doc__.strip(),
            epilog=_('Type "senlin help <COMMAND>" for help on a specific '
                     'command.'),
            add_help=False,
            formatter_class=HelpFormatter,
        )

        cliargs.add_global_args(parser, version=senlinclient.__version__)
        cliargs.add_global_identity_args(parser)
        self.add_profiler_args(parser)
        base_parser = parser

        (options, args) = base_parser.parse_known_args(argv)

        self._setup_logging(options.debug)
        self._setup_verbose(options.verbose)

        # build available subcommands based on version
        api_ver = options.senlin_api_version
        LOG.info(api_ver)
        subcommand_parser = self.get_subcommand_parser(base_parser, api_ver)
        self.parser = subcommand_parser

        # Handle top-level --help/-h before attempting to parse
        # a command off the command line
        if not args and options.help or not argv:
            self.do_help(options)
            return 0

        # Parse args again and call whatever callback was selected
        args = subcommand_parser.parse_args(argv)

        # Short-circuit and deal with help command right away.
        if args.func == self.do_help:
            self.do_help(args)
            return 0
        elif args.func == self.do_bash_completion:
            self.do_bash_completion(args)
            return 0

        # Check if identity information are sufficient
        self._check_identity_arguments(args)

        # Setup Senlin client connection
        sc = self._setup_senlin_client(api_ver, args)

        profile = osprofiler_profiler and options.profile
        if profile:
            osprofiler_profiler.init(options.profile)

        args.func(sc.service, args)

        if profile:
            trace_id = osprofiler_profiler.get().get_base_id()
            print(_("Trace ID: %s") % trace_id)
            print(_("To display trace use next command:\n"
                  "osprofiler trace show --html %s ") % trace_id)