def test_update_db_systems_client_error_no_db_system(
        db_client, get_existing_resource_patch):
    error_message = 'No DB System'
    module = get_module(dict())
    get_existing_resource_patch.return_value = None
    try:
        oci_db_system.update_db_system(db_client, module,
                                       'ocid1.dbsystem.aaaa')
    except Exception as ex:
        assert error_message in str(ex.args)
def test_update_db_systems_freeform_tags(db_client,
                                         get_existing_resource_patch,
                                         update_and_wait_patch):
    db_system = get_db_system()
    get_existing_resource_patch.return_value = db_system
    module = get_module(dict(freeform_tags=dict(system_type='oracledb')))
    update_and_wait_patch.return_value = {
        'db_system': to_dict(db_system),
        'changed': True
    }
    result = oci_db_system.update_db_system(db_client, module,
                                            'ocid.dbsystem.ocid1')
    assert result['changed'] is True
def test_update_db_systems_defined_tags(db_client, get_existing_resource_patch,
                                        update_and_wait_patch):
    db_system = get_db_system()
    get_existing_resource_patch.return_value = db_system
    module = get_module(
        dict(defined_tags=dict(system_strength=dict(shape='medium'))))
    update_and_wait_patch.return_value = {
        'db_system': to_dict(db_system),
        'changed': True
    }
    result = oci_db_system.update_db_system(db_client, module,
                                            'ocid.dbsystem.ocid1')
    assert result['changed'] is True
def test_update_db_systems_defined_tags(db_client, get_existing_resource_patch,
                                        update_and_wait_patch):
    db_system = get_db_system()
    get_existing_resource_patch.return_value = db_system
    module = get_module(
        dict(defined_tags=dict(system_strength=dict(shape="medium"))))
    update_and_wait_patch.return_value = {
        "db_system": to_dict(db_system),
        "changed": True,
    }
    result = oci_db_system.update_db_system(db_client, module,
                                            "ocid.dbsystem.ocid1")
    assert result["changed"] is True
def test_update_db_systems_freeform_tags(db_client,
                                         get_existing_resource_patch,
                                         update_and_wait_patch):
    db_system = get_db_system()
    get_existing_resource_patch.return_value = db_system
    module = get_module(dict(freeform_tags=dict(system_type="oracledb")))
    update_and_wait_patch.return_value = {
        "db_system": to_dict(db_system),
        "changed": True,
    }
    result = oci_db_system.update_db_system(db_client, module,
                                            "ocid.dbsystem.ocid1")
    assert result["changed"] is True
def test_update_db_systems_with_cpu_core_count(db_client,
                                               get_existing_resource_patch,
                                               update_and_wait_patch):
    db_system = get_db_system()
    db_system.cpu_core_count = 4
    get_existing_resource_patch.return_value = db_system
    module = get_module(dict())
    update_and_wait_patch.return_value = {
        'db_system': to_dict(db_system),
        'changed': True
    }
    result = oci_db_system.update_db_system(db_client, module,
                                            'ocid.dbsystem.ocid1')
    assert result['changed'] is True
def test_update_db_systems_ssh_public_keys_changed_no_purge(db_client):
    db_system = get_db_system()
    existing_ssh_public_keys = get_ssh_public_keys(1)
    input_ssh_public_keys = get_ssh_public_keys(1)
    db_system.ssh_public_keys = existing_ssh_public_keys
    module = get_module(
        dict({
            'ssh_public_keys': input_ssh_public_keys,
            'purge_ssh_public_keys': False
        }))
    update_and_wait_patch.return_value = {
        'db_system': to_dict(db_system),
        'changed': True
    }
    result = oci_db_system.update_db_system(db_client, module,
                                            'ocid.dbsystem.ocid1')
    delete_ssh_public_keys(input_ssh_public_keys)
    delete_ssh_public_keys(existing_ssh_public_keys)
    assert result['changed'] is True
def test_update_db_systems_ssh_public_keys_changed_no_purge(db_client):
    db_system = get_db_system()
    existing_ssh_public_keys = get_ssh_public_keys(1)
    input_ssh_public_keys = get_ssh_public_keys(1)
    db_system.ssh_public_keys = existing_ssh_public_keys
    module = get_module(
        dict({
            "ssh_public_keys": input_ssh_public_keys,
            "purge_ssh_public_keys": False
        }))
    update_and_wait_patch.return_value = {
        "db_system": to_dict(db_system),
        "changed": True,
    }
    result = oci_db_system.update_db_system(db_client, module,
                                            "ocid.dbsystem.ocid1")
    delete_ssh_public_keys(input_ssh_public_keys)
    delete_ssh_public_keys(existing_ssh_public_keys)
    assert result["changed"] is True