Exemplo n.º 1
0
 def test_doesnt_call_load_regiond_commands_if_no_maasserver(self):
     self.patch(cli,
                "get_django_management").return_value = sentinel.management
     self.patch(cli, "is_maasserver_available").return_value = None
     mock_load_regiond_commands = self.patch(cli, "load_regiond_commands")
     parser = ArgumentParser()
     cli.register_cli_commands(parser)
     self.assertThat(mock_load_regiond_commands, MockNotCalled())
Exemplo n.º 2
0
 def test_load_init_command_snap(self):
     environ = {'SNAP': 'snap-path'}
     self.patch(os, 'environ', environ)
     parser = ArgumentParser()
     cli.register_cli_commands(parser)
     subparser = parser.subparsers.choices.get('init')
     self.assertIsInstance(subparser.get_default('execute'),
                           snappy.cmd_init)
Exemplo n.º 3
0
 def test_load_init_command_no_snap_no_maasserver(self):
     environ = {}
     self.patch(os, 'environ', environ)
     self.patch(cli, "is_maasserver_available").return_value = None
     parser = ArgumentParser()
     cli.register_cli_commands(parser)
     subparser = parser.subparsers.choices.get('init')
     self.assertIsNone(subparser)
Exemplo n.º 4
0
 def test_load_init_command_snap(self):
     environ = {"SNAP": "snap-path"}
     self.patch(os, "environ", environ)
     parser = ArgumentParser()
     cli.register_cli_commands(parser)
     subparser = parser.subparsers.choices.get("init")
     self.assertIsInstance(subparser.get_default("execute"),
                           snappy.cmd_init)
Exemplo n.º 5
0
 def test_hidden_commands(self):
     environ = {"SNAP": "snap-path", "SNAP_COMMON": "snap-common"}
     self.patch(os, "environ", environ)
     stdout = self.patch(sys, "stdout", StringIO())
     parser = ArgumentParser()
     cli.register_cli_commands(parser)
     error = self.assertRaises(SystemExit, parser.parse_args, ["--help"])
     self.assertEqual(error.code, 0)
     self.assertNotIn("reconfigure-supervisord", stdout.getvalue())
Exemplo n.º 6
0
def prepare_parser(argv):
    """Create and populate an arguments parser for the maascli command."""
    help_title, help_body = parse_docstring(api)
    parser = ArgumentParser(
        description=help_body, prog=argv[0],
        epilog="http://maas.ubuntu.com/")
    register_cli_commands(parser)
    api.register_api_commands(parser)
    return parser
Exemplo n.º 7
0
def prepare_parser(argv):
    """Create and populate an arguments parser for the maascli command."""
    help_title, help_body = parse_docstring(api)
    parser = ArgumentParser(description=help_body,
                            prog=argv[0],
                            epilog="http://maas.ubuntu.com/")
    register_cli_commands(parser)
    api.register_api_commands(parser)
    return parser
Exemplo n.º 8
0
 def test_loads_all_regiond_commands(self):
     parser = ArgumentParser()
     cli.register_cli_commands(parser)
     for name, app, help_text in cli.regiond_commands:
         subparser = parser.subparsers.choices.get(name)
         klass = management.load_command_class(app, name)
         if help_text is None:
             help_text = klass.help
         self.assertIsNotNone(subparser)
         self.assertEqual(help_text, subparser.description)
Exemplo n.º 9
0
 def test_calls_load_regiond_commands_when_management_and_maasserver(self):
     self.patch(cli,
                "get_django_management").return_value = sentinel.management
     self.patch(cli,
                "is_maasserver_available").return_value = sentinel.pkg_util
     mock_load_regiond_commands = self.patch(cli, "load_regiond_commands")
     parser = ArgumentParser()
     cli.register_cli_commands(parser)
     mock_load_regiond_commands.assert_called_once_with(
         sentinel.management, parser)
Exemplo n.º 10
0
def prepare_parser(argv):
    """Create and populate an arguments parser for the maascli command."""
    help_title, help_body = parse_docstring(api)
    parser = ArgumentParser(description=help_body,
                            prog=os.path.basename(argv[0]),
                            epilog="http://maas.io/")
    register_cli_commands(parser)
    api.register_api_commands(parser)
    parser.add_argument('--debug',
                        action='store_true',
                        default=False,
                        help=argparse.SUPPRESS)
    return parser
Exemplo n.º 11
0
    def test_load_init_command_snap(self):
        from provisioningserver import maas_certificates

        certificates_dir = self.useFixture(TempDirectory()).path
        maas_certificates.MAAS_PRIVATE_KEY = os.path.join(
            certificates_dir, "maas.key")
        maas_certificates.MAAS_PUBLIC_KEY = os.path.join(
            certificates_dir, "maas.pub")
        maas_certificates.MAAS_CERTIFICATE = os.path.join(
            certificates_dir, "maas.crt")
        environ = {"SNAP": "snap-path"}
        self.patch(os, "environ", environ)
        parser = ArgumentParser()
        cli.register_cli_commands(parser)
        subparser = parser.subparsers.choices.get("init")
        self.assertIsInstance(subparser.get_default("execute"),
                              snappy.cmd_init)
Exemplo n.º 12
0
 def test_registers_subparsers(self):
     parser = ArgumentParser()
     self.assertIsNone(parser._subparsers)
     cli.register_cli_commands(parser)
     self.assertIsNotNone(parser._subparsers)
Exemplo n.º 13
0
 def test_subparsers_have_appropriate_execute_defaults(self):
     parser = ArgumentParser()
     cli.register_cli_commands(parser)
     self.assertIsInstance(
         parser.subparsers.choices['login'].get_default('execute'),
         cli.cmd_login)
Exemplo n.º 14
0
 def test_registers_subparsers(self):
     parser = ArgumentParser()
     self.assertIsNone(parser._subparsers)
     cli.register_cli_commands(parser)
     self.assertIsNotNone(parser._subparsers)