Esempio n. 1
0
def test_list_vaults(cli_testing_service_client, runner, config_file, config_profile):
    if not cli_testing_service_client.is_api_enabled('key_management', 'ListVaults'):
        pytest.skip('OCI Testing Service has not been configured for this operation yet.')

    root_command_name = oci_cli.cli_util.override('kms_vault_root_group.command_name', 'kms-vault')
    resource_group_command_name = oci_cli.cli_util.override('vault_group.command_name', 'vault')
    request_containers = cli_testing_service_client.get_requests(service_name='key_management', api_name='ListVaults')
    for i in range(len(request_containers)):
        request = request_containers[i]['request'].copy()
        done = False
        params = []
        while not done:

            if 'opts' in request:
                for key in request['opts']:
                    request[key] = request['opts'][key]
                del request['opts']

            request, cleanup = generated_test_request_transformers.transform_generated_test_input('key_management', 'ListVaults', request)

            input_content = json.dumps(request)

            # for operations with polymorphic input types, attempt to find an operation for a specific subtype
            # if one does not exist, fallback to calling base operation
            if not params:
                params = util.get_command_list(
                    root_command_name,
                    resource_group_command_name,
                    oci_cli.cli_util.override('list_vaults.command_name', 'list'),
                    True
                )

            if not params:
                raise ValueError(
                    'Failed to find CLI command "oci {} {} {}" for given operation: key_management, ListVaults. '
                    'This usually happens because generated commands have been manually re-arranged in code for better user '
                    'experience. To allow this test to find the proper command, please add an entry to MOVED_COMMANDS in '
                    'services/<spec_name>/tests/extend_test_<your_service_name>.py to map ({}, {}, {}) to the syntax '
                    'for the new command. If the file does not exist for your service, please create one. You can refer the '
                    'MOVED_COMMANDS map in services/core/tests/extend_test_compute.py as an example.'
                    .format(
                        root_command_name, resource_group_command_name,
                        oci_cli.cli_util.override('list_vaults.command_name', 'list'),
                        root_command_name, resource_group_command_name,
                        oci_cli.cli_util.override('list_vaults.command_name', 'list')))

            params.extend(['--from-json', input_content])
            try:
                util.set_admin_pass_phrase()
                result = invoke(runner, config_file, 'ADMIN', params)

                message = cli_testing_service_client.validate_result(
                    'key_management',
                    'ListVaults',
                    request_containers[i]['containerId'],
                    request_containers[i]['request'],
                    result,
                    'items',
                    False
                )
            finally:
                if cleanup:
                    try:
                        next(cleanup)
                    except StopIteration:
                        pass

            if message != "CONT":
                assert len(message) == 0, message
                done = True
            else:
                request_containers = cli_testing_service_client.get_requests(service_name='key_management', api_name='ListVaults')
                request = request_containers[i]['request'].copy()
Esempio n. 2
0
def test_update_auto_scaling_policy(cli_testing_service_client, runner,
                                    config_file, config_profile):
    if not cli_testing_service_client.is_api_enabled(
            'autoscaling', 'UpdateAutoScalingPolicy'):
        pytest.skip(
            'OCI Testing Service has not been configured for this operation yet.'
        )

    root_command_name = oci_cli.cli_util.override(
        'autoscaling_root_group.command_name', 'autoscaling')
    resource_group_command_name = oci_cli.cli_util.override(
        'auto_scaling_policy_group.command_name', 'auto_scaling_policy')
    request_containers = cli_testing_service_client.get_requests(
        service_name='autoscaling', api_name='UpdateAutoScalingPolicy')
    for i in range(len(request_containers)):
        request = request_containers[i]['request'].copy()
        done = False
        params = []
        while not done:
            # force all details param names to have lower case first letter for consistency with Java models
            param_name = 'UpdateAutoScalingPolicyDetails'
            details = request.pop(param_name[0].lower() + param_name[1:])
            for key in details:
                request[key] = details[key]
                override = util.variable_name_override(key)
                if override:
                    request[override] = request.pop(key)

            if 'opts' in request:
                for key in request['opts']:
                    request[key] = request['opts'][key]
                del request['opts']

            if request.get('policyType') == 'threshold':
                params = util.get_command_list(
                    root_command_name, resource_group_command_name,
                    oci_cli.cli_util.override(
                        'update_auto_scaling_policy_update_threshold_policy_details.command_name',
                        'update-auto-scaling-policy-update-threshold-policy-details'
                    ))

                if params:
                    del request['policyType']

            request, cleanup = generated_test_request_transformers.transform_generated_test_input(
                'autoscaling', 'UpdateAutoScalingPolicy', request)

            input_content = json.dumps(request)

            # for operations with polymorphic input types, attempt to find an operation for a specific subtype
            # if one does not exist, fallback to calling base operation
            if not params:
                params = util.get_command_list(
                    root_command_name, resource_group_command_name,
                    oci_cli.cli_util.override(
                        'update_auto_scaling_policy.command_name', 'update'))

            if not params:
                raise ValueError(
                    'Failed to find CLI command "oci {} {} {}" for given operation: autoscaling, UpdateAutoScalingPolicy. '
                    'This usually happens because generated commands have been manually re-arranged in code for better user '
                    'experience. To allow this test to find the proper command, please add an entry to MOVED_COMMANDS in '
                    'services/<spec_name>/tests/extend_test_<your_service_name>.py to map ({}, {}, {}) to the syntax '
                    'for the new command. If the file does not exist for your service, please create one. You can refer the '
                    'MOVED_COMMANDS map in services/core/tests/extend_test_compute.py as an example.'
                    .format(
                        root_command_name, resource_group_command_name,
                        oci_cli.cli_util.override(
                            'update_auto_scaling_policy.command_name',
                            'update'), root_command_name,
                        resource_group_command_name,
                        oci_cli.cli_util.override(
                            'update_auto_scaling_policy.command_name',
                            'update')))

            params.append('--force')
            params.extend(['--from-json', input_content])
            try:
                util.set_admin_pass_phrase()
                result = invoke(runner, config_file, 'ADMIN', params)

                message = cli_testing_service_client.validate_result(
                    'autoscaling', 'UpdateAutoScalingPolicy',
                    request_containers[i]['containerId'],
                    request_containers[i]['request'], result,
                    'autoScalingPolicy', False)
            finally:
                if cleanup:
                    try:
                        next(cleanup)
                    except StopIteration:
                        pass

            if message != "CONT":
                assert len(message) == 0, message
                done = True
            else:
                request_containers = cli_testing_service_client.get_requests(
                    service_name='autoscaling',
                    api_name='UpdateAutoScalingPolicy')
                request = request_containers[i]['request'].copy()
Esempio n. 3
0
def test_list_work_requests(cli_testing_service_client, runner, config_file,
                            config_profile):
    if not cli_testing_service_client.is_api_enabled('work_requests',
                                                     'ListWorkRequests'):
        pytest.skip(
            'OCI Testing Service has not been configured for this operation yet.'
        )

    config_file = os.environ['OCI_CLI_CONFIG_FILE']
    if 'USE_TESTING_SERVICE_CONFIG' in os.environ:
        try:
            config_str = cli_testing_service_client.get_config(
                'work_requests', 'WorkRequest', 'ListWorkRequests')
            config = json.loads(config_str)
            key_file_content = config['keyFileContent']
            with open(
                    'tests/resources/keyfile_for_test_list_work_requests.pem',
                    'w') as f:
                f.write(key_file_content)
            with open('tests/resources/config_for_test_list_work_requests',
                      'w') as f:
                f.write('[ADMIN]\n')
                f.write('user = '******'userId'] + '\n')
                f.write('fingerprint = ' + config['fingerprint'] + '\n')
                f.write('tenancy = ' + config['tenantId'] + '\n')
                f.write('region = ' + config['region'] + '\n')
                f.write(
                    'key_file = tests/resources/keyfile_for_test_list_work_requests.pem\n'
                )
            runner.invoke(oci_cli.cli, [
                'setup', 'repair-file-permissions', '--file',
                'tests/resources/config_for_test_list_work_requests'
            ])
            runner.invoke(oci_cli.cli, [
                'setup', 'repair-file-permissions', '--file',
                'tests/resources/keyfile_for_test_list_work_requests.pem'
            ])
            config_file = 'tests/resources/config_for_test_list_work_requests'
        except vcr.errors.CannotOverwriteExistingCassetteException:
            pass
        except Exception as e:
            print(e)
            raise e

    root_command_name = oci_cli.cli_util.override(
        'work_requests_root_group.command_name', 'work-requests')
    resource_group_command_name = oci_cli.cli_util.override(
        'work_request_group.command_name', 'work_request')
    request_containers = cli_testing_service_client.get_requests(
        service_name='work_requests', api_name='ListWorkRequests')
    for i in range(len(request_containers)):
        request = request_containers[i]['request'].copy()
        done = False
        params = []
        while not done:

            if 'opts' in request:
                for key in request['opts']:
                    request[key] = request['opts'][key]
                del request['opts']

            request, cleanup = generated_test_request_transformers.transform_generated_test_input(
                'work_requests', 'ListWorkRequests', request)

            input_content = json.dumps(request)

            # for operations with polymorphic input types, attempt to find an operation for a specific subtype
            # if one does not exist, fallback to calling base operation
            if not params:
                params = util.get_command_list(
                    root_command_name, resource_group_command_name,
                    oci_cli.cli_util.override(
                        'list_work_requests.command_name', 'list'))

            if not params:
                raise ValueError(
                    'Failed to find CLI command "oci {} {} {}" for given operation: work_requests, ListWorkRequests. '
                    'This usually happens because generated commands have been manually re-arranged in code for better user '
                    'experience. To allow this test to find the proper command, please add an entry to MOVED_COMMANDS in '
                    'services/<spec_name>/tests/extend_test_<your_service_name>.py to map ({}, {}, {}) to the syntax '
                    'for the new command. If the file does not exist for your service, please create one. You can refer the '
                    'MOVED_COMMANDS map in services/core/tests/extend_test_compute.py as an example.'
                    .format(
                        root_command_name, resource_group_command_name,
                        oci_cli.cli_util.override(
                            'list_work_requests.command_name', 'list'),
                        root_command_name, resource_group_command_name,
                        oci_cli.cli_util.override(
                            'list_work_requests.command_name', 'list')))

            params.extend(['--from-json', input_content])
            try:
                util.set_admin_pass_phrase()
                result = invoke(runner, config_file, 'ADMIN', params)

                message = cli_testing_service_client.validate_result(
                    'work_requests', 'ListWorkRequests',
                    request_containers[i]['containerId'],
                    request_containers[i]['request'], result, 'items', False)
            finally:
                if os.path.exists(
                        'tests/resources/keyfile_for_test_list_work_requests.pem'
                ):
                    os.remove(
                        'tests/resources/keyfile_for_test_list_work_requests.pem'
                    )
                if os.path.exists(
                        'tests/resources/config_for_test_list_work_requests'):
                    os.remove(
                        'tests/resources/config_for_test_list_work_requests')
                if cleanup:
                    try:
                        next(cleanup)
                    except StopIteration:
                        pass

            if message != "CONT":
                assert len(message) == 0, message
                done = True
            else:
                request_containers = cli_testing_service_client.get_requests(
                    service_name='work_requests', api_name='ListWorkRequests')
                request = request_containers[i]['request'].copy()