Exemplo n.º 1
0
 def subtest_config_get(self):
     util.set_admin_pass_phrase()
     result = util.invoke_command_as_admin(['audit', 'config', 'get', '--compartment-id', util.TENANT_ID])
     util.unset_admin_pass_phrase()
     util.validate_response(result)
     response = json.loads(result.output)
     assert response["data"]["retention-period-days"] is not None
Exemplo 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()
Exemplo n.º 3
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()
Exemplo n.º 4
0
# coding: utf-8
# Copyright (c) 2016, 2021, Oracle and/or its affiliates.  All rights reserved.
# This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.

import json
import oci_cli
import pytest
from tests import util
from tests import test_config_container

CASSETTE_LIBRARY_DIR = 'services/email/tests/cassettes'

util.set_admin_pass_phrase()


@pytest.fixture(autouse=True, scope='function')
def vcr_fixture(request):
    with test_config_container.create_vcr(
            cassette_library_dir=CASSETTE_LIBRARY_DIR).use_cassette(
                'email_{name}.yml'.format(name=request.function.__name__)):
        yield


def test_sender_crud(runner, config_file, config_profile):
    sender_id = None
    try:
        params = [
            'email', 'sender', 'create', '--email-address',
            util.random_name('clisender', insert_underscore=False) +
            '@oracle.com', '--compartment-id', util.COMPARTMENT_ID
        ]
Exemplo n.º 5
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()
Exemplo n.º 6
0
 def setUp(self):
     util.set_admin_pass_phrase()