Ejemplo n.º 1
0
def test_get_source_details_from_module_ignores_image_id_top_level_module_parameter_when_source_details_exists(
    create_instance_source_via_image_patch, ):
    module = get_module(set_top_level_image_id=True)
    create_instance_source_via_image_patch.return_value = InstanceSourceViaImageDetails(
        image_id=module.params["image_id"])
    source_details = oci_instance.get_source_details_from_module(module)
    assert source_details.image_id == module.params["image_id"]
    create_instance_source_via_image_patch.assert_called_once_with(
        module.params["image_id"], boot_volume_size_in_gbs=None)
Ejemplo n.º 2
0
def test_get_source_details_from_module_use_image_id_top_level_module_parameter_when_source_details_does_not_exist(
    create_instance_source_via_image_patch, ):
    module = get_module(set_top_level_image_id=True)
    del module.params["source_details"]
    create_instance_source_via_image_patch.return_value = InstanceSourceViaImageDetails(
        image_id=module.params["image_id"])
    source_details = oci_instance.get_source_details_from_module(module)
    assert source_details.image_id == module.params["image_id"]
    create_instance_source_via_image_patch.assert_called_once_with(
        module.params["image_id"])
Ejemplo n.º 3
0
def test_get_source_details_from_module_when_image_id_is_passed_as_source_details(
    create_instance_source_via_image_patch, ):
    module = get_module()
    create_instance_source_via_image_patch.return_value = InstanceSourceViaImageDetails(
        image_id=module.params["source_details"]["image_id"])
    source_details = oci_instance.get_source_details_from_module(module)
    assert source_details.image_id == module.params["source_details"][
        "image_id"]
    create_instance_source_via_image_patch.assert_called_once_with(
        module.params["source_details"]["image_id"],
        boot_volume_size_in_gbs=None)
Ejemplo n.º 4
0
def test_get_launch_instance_details_calls_get_source_details_from_module(
    get_source_details_from_module_patch, ):
    custom_boot_volume_size_in_gbs = 100
    module = get_module(
        custom_boot_volume_size_in_gbs=custom_boot_volume_size_in_gbs)
    get_source_details_from_module_patch.return_value = InstanceSourceViaImageDetails(
        image_id=module.params["source_details"]["image_id"],
        boot_volume_size_in_gbs=module.params["source_details"]
        ["boot_volume_size_in_gbs"],
    )
    launch_instance_details = oci_instance.get_launch_instance_details(module)
    assert (launch_instance_details.source_details.image_id ==
            module.params["source_details"]["image_id"])
    assert (launch_instance_details.source_details.boot_volume_size_in_gbs ==
            module.params["source_details"]["boot_volume_size_in_gbs"])
    get_source_details_from_module_patch.assert_called_once_with(module)
def test_get_source_details_from_module_when_image_id_is_passed_as_source_details_with_boot_volume_size(
        create_instance_source_via_image_patch):
    custom_boot_volume_size_in_gbs = 100
    module = get_module(
        custom_boot_volume_size_in_gbs=custom_boot_volume_size_in_gbs)
    create_instance_source_via_image_patch.return_value = InstanceSourceViaImageDetails(
        image_id=module.params["source_details"]["image_id"],
        boot_volume_size_in_gbs=module.params["source_details"]
        ["boot_volume_size_in_gbs"],
    )
    source_details = oci_instance.get_source_details_from_module(module)
    assert source_details.image_id == module.params["source_details"][
        "image_id"]
    assert (source_details.boot_volume_size_in_gbs ==
            module.params["source_details"]["boot_volume_size_in_gbs"])
    create_instance_source_via_image_patch.assert_called_once_with(
        module.params["source_details"]["image_id"],
        boot_volume_size_in_gbs=100)
Ejemplo n.º 6
0
def _prepare_source_details(available_images, **kwargs):
    selected_image = None
    for image in available_images:
        if (image.operating_system == kwargs["operating_system"]
                and image.operating_system_version
                == kwargs["operating_system_version"]):
            selected_image = image
            break

    if not selected_image:
        raise RuntimeError("Failed to find the specified image")

    source_image_kwargs = {
        k: v
        for k, v in kwargs.items() if hasattr(InstanceSourceViaImageDetails, k)
    }
    source_image_details = InstanceSourceViaImageDetails(
        image_id=selected_image.id, **source_image_kwargs)
    return source_image_details