How to use oci - 10 common examples

To help you get started, we’ve selected a few oci examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oracle / oci-python-sdk / tests / unit / test_waiters.py View on Github external
response = virtual_network.create_vcn(request)
    vcn = response.data
    get_vcn_response = virtual_network.get_vcn(vcn.id)
    get_vcn_response.data.lifecycle_state = 'DUMMY'  # This will force at least one service call

    def fetch_func(response=None):
        counters['wait'] = counters['wait'] + 1
        return virtual_network.get_vcn(vcn.id)

    response = oci.wait_until(virtual_network, get_vcn_response, 'lifecycle_state', 'AVAILABLE', fetch_func=fetch_func)
    assert 'AVAILABLE' == response.data.lifecycle_state
    assert counters['wait'] > 0

    print('Deleting vcn')
    response = virtual_network.delete_vcn(vcn.id)
    result = oci.wait_until(virtual_network, get_vcn_response, 'lifecycle_state', 'TERMINATED', max_wait_seconds=180, succeed_on_not_found=True)
    assert result == oci.waiter.WAIT_RESOURCE_NOT_FOUND
github oracle / oci-ansible-modules / test / units / test_oci_load_balancer_certificate.py View on Github external
def test_delete_certificate(lb_client, delete_lb_resources_and_wait_patch):
    module = get_module(dict())
    certificate = get_certificate(dict())
    delete_lb_resources_and_wait_patch.return_value = dict(
        certificate=to_dict(certificate), changed=True
    )
    result = oci_load_balancer_certificate.delete_certificate(lb_client, module)
    assert result["changed"] is True
github oracle / oci-ansible-modules / test / units / test_oci_data_guard_association.py View on Github external
def test_create_data_guard_association(db_client, create_and_wait_patch):
    module = get_module(dict())
    data_guard_association = get_data_guard_association("PRIMARY", "STANDBY")
    create_and_wait_patch.return_value = {
        "data_guard_association": to_dict(data_guard_association),
        "changed": True,
    }
    result = oci_data_guard_association.create_data_guard_association(db_client, module)
    assert result["data_guard_association"]["role"] is data_guard_association.role
github oracle / oci-ansible-modules / test / units / test_oci_file_system.py View on Github external
def test_delete_file_system(file_storage_client, delete_and_wait_patch):
    module = get_module(dict(file_system_id="ocid1.mounttarget.aaa"))
    file_system = get_file_system()
    delete_and_wait_patch.return_value = {
        "file_system": to_dict(file_system),
        "changed": True,
    }
    result = oci_file_system.delete_file_system(file_storage_client, module)
    assert result["file_system"]["display_name"] is file_system.display_name
github oracle / oci-ansible-modules / test / units / test_oci_bucket.py View on Github external
def test_create_or_update_bucket_update_bucket_service_error(
    object_storage_client, get_existing_bucket_patch
):
    get_existing_bucket_patch.return_value = oci.object_storage.models.Bucket()
    error_message = "Namespace does not exist."
    object_storage_client.update_bucket.side_effect = ServiceError(
        400, "NoNameSpaceExists", dict(), error_message
    )
    object_storage_client.get_bucket.return_value = Bucket()
    module = get_module()
    try:
        oci_bucket.create_or_update_bucket(object_storage_client, module)
    except Exception as ex:
        assert error_message in ex.args[0]
github oracle / oci-ansible-modules / test / units / test_oci_user_facts.py View on Github external
def test_list_users_failure_service_error(identity_client, list_all_resources_patch):
    error_message = "Internal Server Error"
    list_all_resources_patch.side_effect = ServiceError(
        499, "InternalServerError", dict(), error_message
    )
    try:
        oci_user_facts.list_users(identity_client, get_module(dict()))
    except Exception as ex:
        assert error_message in ex.args[0]
github oracle / oci-ansible-modules / test / units / test_oci_db_node_facts.py View on Github external
def test_list_db_systems_service_error(db_client):
    error_message = "Internal Server Error"
    module = get_module(dict({"db_node_id": "ocid1.dbnode.aaaa"}))
    db_client.get_db_system.side_effect = ServiceError(
        499, "InternalServerError", dict(), error_message
    )
    try:
        oci_db_node_facts.list_db_nodes(db_client, module)
    except Exception as ex:
        assert error_message in ex.args[0]
github oracle / oci-ansible-modules / test / units / test_oci_db_system_facts.py View on Github external
def test_list_db_systems_service_error(db_client):
    error_message = "Internal Server Error"
    module = get_module(dict({"db_system_id": "ocid1.dbsystem.aaaa"}))
    db_client.get_db_system.side_effect = ServiceError(
        499, "InternalServerError", dict(), error_message
    )
    try:
        oci_db_system_facts.list_db_systems(db_client, module)
    except Exception as ex:
        assert error_message in ex.args[0]
github oracle / oci-python-sdk / tests / util.py View on Github external
def validate_service_error(error, status, code, message):
    assert isinstance(error, oci.exceptions.ServiceError)
    assert error.status == status
    assert error.code == code
    assert error.message.startswith(message)
    assert error.headers is not None
    assert error.request_id.strip()

    if error.headers.get('opc-request-id'):
        assert len(error.headers.get('opc-request-id')) == 98
    else:
        assert len(error.request_id) == 32

    # Check to string
    for info in [str(status), code, "opc-request-id", message]:
        assert info in str(error)
github oracle / oci-ansible-modules / test / units / test_oci_mount_target_facts.py View on Github external
def test_list_mount_targets_service_error(file_storage_client):
    error_message = "Internal Server Error"
    module = get_module(dict({"mount_target_id": "ocid1.mounttarget.aaaa"}))
    file_storage_client.get_mount_target.side_effect = ServiceError(
        499, "InternalServerError", dict(), error_message
    )
    try:
        oci_mount_target_facts.list_mount_targets(file_storage_client, module)
    except Exception as ex:
        assert error_message in ex.args[0]