def load_command_table(self, args):  #pylint: disable=too-many-statements
        """Load all Service Fabric commands"""

        # Need an empty client for the select and upload operations
        with CommandSuperGroup(__name__, self,
                               'rcctl.custom_cluster#{}') as super_group:
            with super_group.group('cluster') as group:
                group.command('select', 'select')

        with CommandSuperGroup(__name__,
                               self,
                               'rcctl.custom_reliablecollections#{}',
                               client_factory=client_create) as super_group:
            with super_group.group('dictionary') as group:
                group.command('query', 'query_reliabledictionary')
                group.command('execute', 'execute_reliabledictionary')
                group.command('schema', 'get_reliabledictionary_schema')
                group.command('list', 'get_reliabledictionary_list')
                group.command('type-schema',
                              'get_reliabledictionary_type_schema')

        with ArgumentsContext(self, 'dictionary') as ac:
            ac.argument('application_name',
                        options_list=['--application-name', '-a'])
            ac.argument('service_name', options_list=['--service-name', '-s'])
            ac.argument('dictionary_name',
                        options_list=['--dictionary-name', '-d'])
            ac.argument('output_file', options_list=['--output-file', '-out'])
            ac.argument('input_file', options_list=['--input-file', '-in'])
            ac.argument('query_string', options_list=['--query-string', '-q'])
            ac.argument('type_name', options_list=['--type-name', '-t'])

        return OrderedDict(self.command_table)
    def load_command_table(self, args): #pylint: disable=too-many-statements
        """Load all Service Fabric commands"""

        with CommandSuperGroup(__name__, self, 'bkpctl.custom_backup_explorer#{}'
                               ) as super_group: 
            with super_group.group('query') as group:
                group.command('metadata', 'query_metadata')
                group.command('collection', 'query_collection')
            with super_group.group('get') as group:
                group.command('transactions', 'get_transactions')
            with super_group.group('update') as group:
                group.command('collection', 'add_transaction')
            with super_group.group('backup') as group:
                group.command('partition', 'trigger_backup')
            
        with ArgumentsContext(self, 'query') as ac:
            ac.argument('name', options_list=['--name', '-n'])
            
        with ArgumentsContext(self, 'update') as ac:
            ac.argument('collectiontype', options_list=['--collectiontype', '-ct'])
            ac.argument('operation', options_list=['--operation', '-op'])
            ac.argument('collection', options_list=['--collection', '-c'])
            ac.argument('partition_id', options_list=['--partitionId', '-p'])
            ac.argument('etag', options_list=['--etag', '-e'])
            ac.argument('key', options_list=['--key', '-k'])
            ac.argument('value', options_list=['--value', '-v'])

        with ArgumentsContext(self, 'backup') as ac:
            ac.argument('typeOfBackup', options_list=['--type', '-t'])
            ac.argument('path', options_list=['--path', '-p'])
            ac.argument('timeout', options_list=['--timeout', '-to'])
            ac.argument('cancellationInSecs', options_list=['--cancellationAfter', '-ca'])

        return OrderedDict(self.command_table)
Пример #3
0
    def test_register_command(self):
        cl = CLICommandsLoader(self.mock_ctx)
        command_name = 'test register sample-command'
        with CommandSuperGroup(__name__, cl, '{}#{{}}'.format(__name__)) as sg:
            with sg.group('test register') as g:
                g.command('sample-command', '{}.{}'.format(TestCommandRegistration.__name__,
                                                           TestCommandRegistration.sample_command_handler.__name__))

        self.assertEqual(len(cl.command_table), 1, 'We expect exactly one command in the command table')
        cl.load_arguments(command_name)
        command_metadata = cl.command_table[command_name]
        self.assertEqual(len(command_metadata.arguments), 4, 'We expected exactly 4 arguments')
        some_expected_arguments = {
            'group_name': CLIArgumentType(dest='group_name',
                                          required=True,
                                          help='The name of the group.'),
            'resource_name': CLIArgumentType(dest='resource_name',
                                             required=True,
                                             help='The name of the resource.'),
            'opt_param': CLIArgumentType(required=False,
                                         help='Used to verify reflection correctly identifies optional params.'),
            'expand': CLIArgumentType(required=False,
                                      help='The expand expression to apply on the operation.')
        }

        for probe in some_expected_arguments:
            existing = next(arg for arg in command_metadata.arguments if arg == probe)
            contains_subset = _dictContainsSubset(some_expected_arguments[existing].settings,
                                                  command_metadata.arguments[existing].options)
            self.assertTrue(contains_subset)
        self.assertEqual(command_metadata.arguments['resource_name'].options_list, ['--resource-name'])
Пример #4
0
 def test_register_cli_argument(self):
     cl = CLICommandsLoader(self.mock_ctx)
     command_name = 'test register sample-command'
     with CommandSuperGroup(__name__, cl, '{}#{{}}'.format(__name__)) as sg:
         with sg.group('test register') as g:
             g.command('sample-command', '{}.{}'.format(TestCommandRegistration.__name__,
                                                        TestCommandRegistration.sample_command_handler.__name__))
     with ArgumentsContext(cl, command_name) as ac:
         ac.argument('resource_name', CLIArgumentType(
         options_list=('--wonky-name', '-n'), metavar='RNAME', help='Completely WONKY name...',
         required=False
     ))
     cl.load_arguments(command_name)
     self.assertEqual(len(cl.command_table), 1, 'We expect exactly one command in the command table')
     command_metadata = cl.command_table[command_name]
     self.assertEqual(len(command_metadata.arguments), 4, 'We expected exactly 4 arguments')
     some_expected_arguments = {
         'group_name': CLIArgumentType(dest='group_name', required=True),
         'resource_name': CLIArgumentType(dest='resource_name', required=False),
     }
     for probe in some_expected_arguments:
         existing = next(arg for arg in command_metadata.arguments if arg == probe)
         contains_subset = _dictContainsSubset(some_expected_arguments[existing].settings,
                                               command_metadata.arguments[existing].options)
         self.assertTrue(contains_subset)
     self.assertEqual(command_metadata.arguments['resource_name'].options_list, ('--wonky-name', '-n'))
Пример #5
0
    def test_override_using_register_cli_argument(self):
        def sample_sdk_method(param_a):  # pylint: disable=unused-argument
            pass

        def test_validator_completer():
            pass

        cl = CLICommandsLoader(self.mock_ctx)
        command_name = 'override_using_register_cli_argument foo'
        setattr(sys.modules[__name__], sample_sdk_method.__name__, sample_sdk_method)
        with CommandSuperGroup(__name__, cl, '{}#{{}}'.format(__name__)) as sg:
            with sg.group('override_using_register_cli_argument') as g:
                g.command('foo', sample_sdk_method.__name__)
        with ArgumentsContext(cl, 'override_using_register_cli_argument') as ac:
            ac.argument('param_a',
                                 options_list=('--overridden', '-r'),
                                 validator=test_validator_completer,
                                 completer=test_validator_completer,
                                 required=False)
        cl.load_arguments(command_name)

        command_metadata = cl.command_table[command_name]
        self.assertEqual(len(command_metadata.arguments), 1, 'We expected exactly 1 arguments')

        actual_arg = command_metadata.arguments['param_a']
        self.assertEqual(actual_arg.options_list, ('--overridden', '-r'))
        self.assertEqual(actual_arg.validator, test_validator_completer)
        self.assertEqual(actual_arg.completer, test_validator_completer)
        self.assertFalse(actual_arg.options['required'])
Пример #6
0
 def test_register_cli_argument_with_overrides(self):
     cl = CLICommandsLoader(self.mock_ctx)
     global_vm_name_type = CLIArgumentType(
         options_list=('--foo', '-f'), metavar='FOO', help='foo help'
     )
     derived_vm_name_type = CLIArgumentType(base_type=global_vm_name_type,
                                            help='first modification')
     with CommandSuperGroup(__name__, cl, '{}#{{}}'.format(__name__)) as sg:
         with sg.group('test') as g:
             g.command('sample-get', '{}.{}'.format(TestCommandRegistration.__name__,
                                                        TestCommandRegistration.sample_command_handler.__name__))
             g.command('command sample-get-1', '{}.{}'.format(TestCommandRegistration.__name__,
                                                        TestCommandRegistration.sample_command_handler.__name__))
             g.command('command sample-get-2', '{}.{}'.format(TestCommandRegistration.__name__,
                                                        TestCommandRegistration.sample_command_handler.__name__))
     with ArgumentsContext(cl, 'test') as ac:
         ac.argument('resource_name', global_vm_name_type)
     with ArgumentsContext(cl, 'test command') as ac:
         ac.argument('resource_name', derived_vm_name_type)
     with ArgumentsContext(cl, 'test command sample-get-2') as ac:
         ac.argument('resource_name', derived_vm_name_type, help='second modification')
     cl.load_arguments('test sample-get')
     cl.load_arguments('test command sample-get-1')
     cl.load_arguments('test command sample-get-2')
     self.assertEqual(len(cl.command_table), 3, 'We expect exactly three commands in the command table')
     command1 = cl.command_table['test sample-get'].arguments['resource_name']
     command2 = cl.command_table['test command sample-get-1'].arguments['resource_name']
     command3 = cl.command_table['test command sample-get-2'].arguments['resource_name']
     self.assertTrue(command1.options['help'] == 'foo help')
     self.assertTrue(command2.options['help'] == 'first modification')
     self.assertTrue(command3.options['help'] == 'second modification')
Пример #7
0
def load_work_commands(cli_command_loader):
    with CommandSuperGroup(__name__, cli_command_loader,
                           'vsts.cli.work.common.custom#{}') as sg:
        with sg.group('work') as g:
            g.command('item show',
                      'show_work_item',
                      table_transformer=transform_work_item_table_output)
            g.command('item create',
                      'create_work_item',
                      table_transformer=transform_work_item_table_output)
            g.command(
                'item query',
                'query_work_items',
                table_transformer=transform_work_item_query_result_table_output
            )
            g.command('item update',
                      'update_work_item',
                      table_transformer=transform_work_item_table_output)
Пример #8
0
def load_build_commands(cli_command_loader):
    with CommandSuperGroup(__name__, cli_command_loader,
                           'vsts.cli.build.common.custom#{}') as sg:
        with sg.group('build') as g:
            # basic vsts_cli_build commands
            g.command('list',
                      'build_list',
                      table_transformer=transform_builds_table_output)
            g.command('queue',
                      'build_queue',
                      table_transformer=transform_build_table_output)
            g.command('show',
                      'build_show',
                      table_transformer=transform_build_table_output)

            # basic vsts_cli_build definition commands
            g.command('definition list',
                      'build_definition_list',
                      table_transformer=transform_definitions_table_output)
            g.command('definition show',
                      'build_definition_show',
                      table_transformer=transform_definition_table_output)
Пример #9
0
    def test_command_build_argument_help_text(self):
        def sample_sdk_method_with_weird_docstring(param_a, param_b, param_c):  # pylint: disable=unused-argument
            """
            An operation with nothing good.

            :param dict param_a:
            :param param_b: The name
            of
            nothing.
            :param param_c: The name
            of

            nothing2.
            """
            pass

        cl = CLICommandsLoader(self.mock_ctx)
        command_name = 'test command foo'
        setattr(sys.modules[__name__], sample_sdk_method_with_weird_docstring.__name__,
                sample_sdk_method_with_weird_docstring)
        with CommandSuperGroup(__name__, cl, '{}#{{}}'.format(__name__)) as sg:
            with sg.group('test command') as g:
                g.command('foo', sample_sdk_method_with_weird_docstring.__name__)
        cl.load_arguments(command_name)
        command_metadata = cl.command_table[command_name]
        self.assertEqual(len(command_metadata.arguments), 3, 'We expected exactly 3 arguments')
        some_expected_arguments = {
            'param_a': CLIArgumentType(dest='param_a', required=True, help=''),
            'param_b': CLIArgumentType(dest='param_b', required=True, help='The name of nothing.'),
            'param_c': CLIArgumentType(dest='param_c', required=True, help='The name of nothing2.')
        }

        for probe in some_expected_arguments:
            existing = next(arg for arg in command_metadata.arguments if arg == probe)
            contains_subset = _dictContainsSubset(some_expected_arguments[existing].settings,
                                                  command_metadata.arguments[existing].options)
            self.assertTrue(contains_subset)
Пример #10
0
    def test_register_extra_cli_argument(self):
        cl = CLICommandsLoader(self.mock_ctx)
        command_name = 'test register sample-command'
        with CommandSuperGroup(__name__, cl, '{}#{{}}'.format(__name__)) as sg:
            with sg.group('test register') as g:
                g.command('sample-command', '{}.{}'.format(TestCommandRegistration.__name__,
                                                           TestCommandRegistration.sample_command_handler.__name__))
        with ArgumentsContext(cl, command_name) as ac:
            ac.extra('added_param', options_list=('--added-param',),
                     metavar='ADDED', help='Just added this right now!', required=True)
        cl.load_arguments(command_name)
        self.assertEqual(len(cl.command_table), 1, 'We expect exactly one command in the command table')
        command_metadata = cl.command_table[command_name]
        self.assertEqual(len(command_metadata.arguments), 5, 'We expected exactly 5 arguments')

        some_expected_arguments = {
            'added_param': CLIArgumentType(dest='added_param', required=True)
        }

        for probe in some_expected_arguments:
            existing = next(arg for arg in command_metadata.arguments if arg == probe)
            contains_subset = _dictContainsSubset(some_expected_arguments[existing].settings,
                                                  command_metadata.arguments[existing].options)
            self.assertTrue(contains_subset)
Пример #11
0
    def load_command_table(self, args): #pylint: disable=too-many-statements
        """Load all Service Fabric commands"""

        client_func_path = 'azure.servicefabric#ServiceFabricClientAPIs.{}'
        with CommandSuperGroup(__name__, self, client_func_path,
                               client_factory=client_create) as super_group:

            with super_group.group('rpm') as group:
                group.command('delete', 'delete_repair_task')
                group.command('list', 'get_repair_task_list')
                group.command('approve-force', 'force_approve_repair_task')


            with super_group.group('sa-cluster') as group:
                group.command('config', 'get_cluster_configuration')
                group.command('upgrade-status',
                              'get_cluster_configuration_upgrade_status')

            with super_group.group('cluster') as group:
                group.command('health', 'get_cluster_health')
                group.command('manifest', 'get_cluster_manifest')
                group.command(
                    'code-versions',
                    'get_provisioned_fabric_code_version_info_list'
                )
                group.command(
                    'config-versions',
                    'get_provisioned_fabric_config_version_info_list'
                )
                group.command('upgrade-status', 'get_cluster_upgrade_progress')
                group.command('recover-system', 'recover_system_partitions')
                group.command('operation-list', 'get_fault_operation_list')
                group.command('operation-cancel', 'cancel_operation')
                group.command('provision', 'provision_cluster')
                group.command('unprovision', 'unprovision_cluster')
                group.command('upgrade-rollback', 'rollback_cluster_upgrade')
                group.command('upgrade-resume', 'resume_cluster_upgrade')

            with super_group.group('node') as group:
                group.command('list', 'get_node_info_list')
                group.command('info', 'get_node_info')
                group.command('health', 'get_node_health')
                group.command('load', 'get_node_load_info')
                group.command('disable', 'disable_node')
                group.command('enable', 'enable_node')
                group.command('remove-state', 'remove_node_state')
                group.command('restart', 'restart_node')
                group.command('transition', 'start_node_transition')
                group.command(
                    'transition-status',
                    'get_node_transition_progress'
                )

            with super_group.group('application') as group:
                group.command('type-list', 'get_application_type_info_list')
                group.command('type', 'get_application_type_info_list_by_name')
                group.command('unprovision', 'unprovision_application_type')
                group.command('delete', 'delete_application')
                group.command('list', 'get_application_info_list')
                group.command('info', 'get_application_info')
                group.command('health', 'get_application_health')
                group.command('upgrade-status', 'get_application_upgrade')
                group.command('upgrade-resume', 'resume_application_upgrade')
                group.command(
                    'upgrade-rollback',
                    'rollback_application_upgrade'
                )
                group.command(
                    'deployed-list',
                    'get_deployed_application_info_list'
                )
                group.command('deployed', 'get_deployed_application_info')
                group.command(
                    'deployed-health',
                    'get_deployed_application_health'
                )
                group.command('manifest', 'get_application_manifest')
                group.command('load', 'get_application_load_info')

            with super_group.group('service') as group:
                group.command('type-list', 'get_service_type_info_list')
                group.command('manifest', 'get_service_manifest')
                group.command(
                    'deployed-type-list',
                    'get_deployed_service_type_info_list'
                )
                group.command(
                    'deployed-type',
                    'get_deployed_service_type_info_by_name'
                )
                group.command('list', 'get_service_info_list')
                group.command('info', 'get_service_info')
                group.command('app-name', 'get_application_name_info')
                group.command('delete', 'delete_service')
                group.command('description', 'get_service_description')
                group.command('health', 'get_service_health')
                group.command('resolve', 'resolve_service')
                group.command('recover', 'recover_service_partitions')
                group.command(
                    'package-list',
                    'get_deployed_service_package_info_list'
                    )
                group.command(
                    'package-info',
                    'get_deployed_service_package_info_list_by_name'
                )
                group.command(
                    'package-health',
                    'get_deployed_service_package_health'
                )
                group.command(
                    'code-package-list',
                    'get_deployed_code_package_info_list'
                )

            with super_group.group('partition') as group:
                group.command('list', 'get_partition_info_list')
                group.command('info', 'get_partition_info')
                group.command('svc-name', 'get_service_name_info')
                group.command('health', 'get_partition_health')
                group.command('load', 'get_partition_load_information')
                group.command('load-reset', 'reset_partition_load')
                group.command('recover', 'recover_partition')
                group.command('recover-all', 'recover_all_partitions')
                group.command('data-loss', 'start_data_loss')
                group.command('data-loss-status', 'get_data_loss_progress')
                group.command('quorum-loss', 'start_quorum_loss')
                group.command('quorum-loss-status', 'get_quorum_loss_progress')
                group.command('restart', 'start_partition_restart')
                group.command(
                    'restart-status',
                    'get_partition_restart_progress'
                )

            with super_group.group('replica') as group:
                group.command('list', 'get_replica_info_list')
                group.command('info', 'get_replica_info')
                group.command('health', 'get_replica_health')
                group.command(
                    'deployed-list',
                    'get_deployed_service_replica_info_list'
                )
                group.command(
                    'deployed',
                    'get_deployed_service_replica_detail_info'
                )
                group.command('restart', 'restart_replica')
                group.command('remove', 'remove_replica')

            with super_group.group('compose') as group:
                group.command('status', 'get_compose_deployment_status')
                group.command('list', 'get_compose_deployment_status_list')
                group.command('remove', 'remove_compose_deployment')
                group.command('upgrade-status',
                              'get_compose_deployment_upgrade_progress')

            with super_group.group('chaos') as group:
                group.command('stop', 'stop_chaos')
                group.command('report', 'get_chaos_report')

            with super_group.group('store') as group:
                group.command('stat', 'get_image_store_content')
                group.command('delete', 'delete_image_store_content')
                group.command('root-info', 'get_image_store_root_content')

            with super_group.group('is') as group:
                group.command('command', 'invoke_infrastructure_command')
                group.command('query', 'invoke_infrastructure_query')

            with super_group.group('property') as group:
                group.command('put', 'put_property')
                group.command('list', 'get_property_info_list')
                group.command('get', 'get_property_info')
                group.command('delete', 'delete_property')

        # Custom commands

        with CommandSuperGroup(__name__, self,
                               'sfctl.custom_cluster_upgrade#{}',
                               client_factory=client_create) as super_group:
            with super_group.group('cluster') as group:
                group.command('upgrade', 'upgrade')
                group.command('upgrade-update', 'update_upgrade')
            with super_group.group('sa-cluster') as group:
                group.command('config-upgrade', 'sa_configuration_upgrade')

        with CommandSuperGroup(__name__, self, 'sfctl.custom_compose#{}',
                               client_factory=client_create) as super_group:
            with super_group.group('compose') as group:
                group.command('upgrade', 'upgrade')
                group.command('create', 'create')

        with CommandSuperGroup(__name__, self, 'sfctl.custom_app#{}',
                               client_factory=client_create) as super_group:
            with super_group.group('application') as group:
                group.command('create', 'create')
                group.command('upgrade', 'upgrade')

        # Need an empty client for the select and upload operations
        with CommandSuperGroup(__name__, self,
                               'sfctl.custom_cluster#{}') as super_group:
            with super_group.group('cluster') as group:
                group.command('select', 'select')
        with CommandSuperGroup(__name__, self,
                               'sfctl.custom_app#{}') as super_group:
            with super_group.group('application') as group:
                group.command('upload', 'upload')

        with CommandSuperGroup(__name__, self, 'sfctl.custom_chaos#{}',
                               client_factory=client_create) as super_group:
            with super_group.group('chaos') as group:
                group.command('start', 'start')

        with CommandSuperGroup(__name__, self, 'sfctl.custom_health#{}',
                               client_factory=client_create) as super_group:
            with super_group.group('application') as group:
                group.command('report-health', 'report_app_health')
            with super_group.group('service') as group:
                group.command('report-health', 'report_svc_health')
            with super_group.group('partition') as group:
                group.command('report-health', 'report_partition_health')
            with super_group.group('replica') as group:
                group.command('report-health', 'report_replica_health')
            with super_group.group('node') as group:
                group.command('report-health', 'report_node_health')
            with super_group.group('cluster') as group:
                group.command('report-health', 'report_cluster_health')

        with CommandSuperGroup(__name__, self, 'sfctl.custom_service#{}',
                               client_factory=client_create) as super_group:
            with super_group.group('service') as group:
                group.command('create', 'create')
                group.command('update', 'update')
                group.command('package-deploy', 'package_upload')

        # Only add when provision API correctly specified in SDK
        # with CommandSuperGroup(__name__, self, 'sfctl.custom_app_type#{}',
        #                        client_factory=client_create) as super_group:
        #     with super_group.group('application') as group:
        #         group.command('provision', 'provision_application_type')

        return OrderedDict(self.command_table)
Пример #12
0
def load_code_commands(cli_command_loader):
    with CommandSuperGroup(__name__, cli_command_loader,
                           'vsts.cli.code.common.{}') as sg:
        with sg.group('code') as g:
            # basic pr commands
            g.command('pr create',
                      'pull_request#create_pull_request',
                      table_transformer=transform_pull_request_table_output)
            g.command('pr update',
                      'pull_request#update_pull_request',
                      table_transformer=transform_pull_request_table_output)
            g.command('pr show',
                      'pull_request#show_pull_request',
                      table_transformer=transform_pull_request_table_output)
            g.command('pr list',
                      'pull_request#list_pull_requests',
                      table_transformer=transform_pull_requests_table_output)

            # pr status update commands
            g.command('pr complete',
                      'pull_request#complete_pull_request',
                      table_transformer=transform_pull_request_table_output)
            g.command('pr abandon',
                      'pull_request#abandon_pull_request',
                      table_transformer=transform_pull_request_table_output)
            g.command('pr reactivate',
                      'pull_request#reactivate_pull_request',
                      table_transformer=transform_pull_request_table_output)

            # pr reviewer commands
            g.command('pr reviewers add',
                      'pull_request#create_pull_request_reviewers',
                      table_transformer=transform_reviewers_table_output)
            g.command('pr reviewers list',
                      'pull_request#list_pull_request_reviewers',
                      table_transformer=transform_reviewers_table_output)
            g.command('pr reviewers remove',
                      'pull_request#delete_pull_request_reviewers',
                      table_transformer=transform_reviewers_table_output)

            # pr work item commands
            g.command('pr work-items add',
                      'pull_request#add_pull_request_work_items',
                      table_transformer=transform_work_items_table_output)
            g.command('pr work-items list',
                      'pull_request#list_pull_request_work_items',
                      table_transformer=transform_work_items_table_output)
            g.command('pr work-items remove',
                      'pull_request#remove_pull_request_work_items',
                      table_transformer=transform_work_items_table_output)

            # pr set-vote commands
            g.command('pr set-vote',
                      'pull_request#vote_pull_request',
                      table_transformer=transform_reviewer_table_output)

            # pr policy commands
            g.command('pr policies list',
                      'pull_request#list_pr_policies',
                      table_transformer=transform_policies_table_output)
            g.command('pr policies queue',
                      'pull_request#queue_pr_policy',
                      table_transformer=transform_policy_table_output)

            # repository commands
            g.command('repo create',
                      'repository#create_repo',
                      table_transformer=transform_repo_table_output)
            g.command('repo list',
                      'repository#list_repos',
                      table_transformer=transform_repos_table_output)
            g.command('repo show',
                      'repository#show_repo',
                      table_transformer=transform_repo_table_output)