|
| 1 | +// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. |
| 2 | +// Licensed under the Mozilla Public License v2.0 |
| 3 | + |
| 4 | +package integrationtest |
| 5 | + |
| 6 | +import ( |
| 7 | + "fmt" |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 11 | + "github.com/oracle/terraform-provider-oci/httpreplay" |
| 12 | + "github.com/oracle/terraform-provider-oci/internal/acctest" |
| 13 | + |
| 14 | + "github.com/oracle/terraform-provider-oci/internal/utils" |
| 15 | +) |
| 16 | + |
| 17 | +// issue-routing-tag: bds/default |
| 18 | +func TestBdsBdsInstanceOSPatchActionResource(t *testing.T) { |
| 19 | + //t.Skip("Run manual with an older cluster with patch available") |
| 20 | + httpreplay.SetScenario("TestBdsBdsInstanceOSPatchActionResource") |
| 21 | + defer httpreplay.SaveScenario() |
| 22 | + |
| 23 | + config := acctest.ProviderTestConfig() |
| 24 | + |
| 25 | + compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid") |
| 26 | + compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId) |
| 27 | + |
| 28 | + subnetId := utils.GetEnvSettingWithBlankDefault("subnet_ocid") |
| 29 | + subnetIdVariableStr := fmt.Sprintf("variable \"subnet_id\" { default = \"%s\" }\n", subnetId) |
| 30 | + |
| 31 | + // Pass cluster ocid as variable to directly apply OS patch to existing cluster |
| 32 | + //bdsinstanceId := utils.GetEnvSettingWithBlankDefault("bdsinstance_ocid") |
| 33 | + //bdsinstanceIdVariableStr := fmt.Sprintf("variable \"bdsinstance_id\" { default = \"%s\" }\n", bdsinstanceId) |
| 34 | + |
| 35 | + // Passing patching configs strategy & parameters in this representation |
| 36 | + BdsBdsInstanceOSPatchConfigRepresentation := map[string]interface{}{ |
| 37 | + "patching_config_strategy": acctest.Representation{RepType: acctest.Required, Create: "PATCHING_BASED"}, |
| 38 | + "batch_size": acctest.Representation{RepType: acctest.Required, Create: "3"}, |
| 39 | + "wait_time_between_batch_in_seconds": acctest.Representation{RepType: acctest.Required, Create: "60"}, |
| 40 | + "tolerance_threshold_per_batch": acctest.Representation{RepType: acctest.Required, Create: "0"}, |
| 41 | + } |
| 42 | + |
| 43 | + // Passing timeout representation since OS patching may take more time then default values |
| 44 | + PatchTimeoutsRepresentation := map[string]interface{}{ |
| 45 | + "create": acctest.Representation{RepType: acctest.Required, Create: `4h`}, |
| 46 | + "update": acctest.Representation{RepType: acctest.Required, Create: `4h`}, |
| 47 | + "delete": acctest.Representation{RepType: acctest.Required, Create: `4h`}, |
| 48 | + } |
| 49 | + |
| 50 | + // To use default patching strategy (nodes will be patched and rebooted AD/FD by AD/FD), comment patching_configs & above config representation |
| 51 | + var ( |
| 52 | + BdsBdsInstanceOSPatchActionRepresentation = map[string]interface{}{ |
| 53 | + "bds_instance_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_bds_bds_instance.test_bds_instance.id}`}, |
| 54 | + "cluster_admin_password": acctest.Representation{RepType: acctest.Required, Create: `T3JhY2xlVGVhbVVTQSExMjM=`}, |
| 55 | + "os_patch_version": acctest.Representation{RepType: acctest.Required, Create: "ol7.9-x86_64-1.28.0.619-0.0"}, |
| 56 | + "patching_configs": acctest.RepresentationGroup{RepType: acctest.Required, Group: BdsBdsInstanceOSPatchConfigRepresentation}, |
| 57 | + "timeouts": acctest.RepresentationGroup{RepType: acctest.Required, Group: PatchTimeoutsRepresentation}, |
| 58 | + } |
| 59 | + |
| 60 | + BdsBdsInstanceOSPatchActionResourceDependencies = acctest.GenerateResourceFromRepresentationMap("oci_bds_bds_instance", "test_bds_instance", acctest.Required, acctest.Create, bdsInstanceOdhRepresentation) + |
| 61 | + acctest.GenerateResourceFromRepresentationMap("oci_core_subnet", "test_subnet", acctest.Required, acctest.Create, CoreSubnetRepresentation) + |
| 62 | + acctest.GenerateResourceFromRepresentationMap("oci_core_vcn", "test_vcn", acctest.Required, acctest.Create, CoreVcnRepresentation) |
| 63 | + ) |
| 64 | + |
| 65 | + resourceName := "oci_bds_bds_instance_os_patch_action.test_bds_instance_os_patch_action" |
| 66 | + |
| 67 | + // Save TF content to Create resource with only required properties. This has to be exactly the same as the config part in the create step in the test. |
| 68 | + acctest.SaveConfigContent(config+compartmentIdVariableStr+subnetIdVariableStr+BdsBdsInstanceOSPatchActionResourceDependencies+ |
| 69 | + acctest.GenerateResourceFromRepresentationMap("oci_bds_bds_instance_os_patch_action", "test_bds_instance_os_patch_action", acctest.Required, acctest.Create, BdsBdsInstanceOSPatchActionRepresentation), "bds", "bdsInstanceOSPatchAction", t) |
| 70 | + |
| 71 | + acctest.ResourceTest(t, nil, []resource.TestStep{ |
| 72 | + // verify Create |
| 73 | + { |
| 74 | + Config: config + compartmentIdVariableStr + subnetIdVariableStr + BdsBdsInstanceOSPatchActionResourceDependencies + |
| 75 | + acctest.GenerateResourceFromRepresentationMap("oci_bds_bds_instance_os_patch_action", "test_bds_instance_os_patch_action", acctest.Required, acctest.Create, BdsBdsInstanceOSPatchActionRepresentation), |
| 76 | + Check: acctest.ComposeAggregateTestCheckFuncWrapper( |
| 77 | + resource.TestCheckResourceAttrSet(resourceName, "bds_instance_id"), |
| 78 | + resource.TestCheckResourceAttr(resourceName, "cluster_admin_password", "T3JhY2xlVGVhbVVTQSExMjM="), |
| 79 | + resource.TestCheckResourceAttrSet(resourceName, "state"), |
| 80 | + ), |
| 81 | + }, |
| 82 | + }) |
| 83 | + |
| 84 | +} |
0 commit comments