rubrikinc / rubrik-sdk-for-powershell

Rubrik Module for PowerShell
https://build.rubrik.com/sdks/powershell/
MIT License
102 stars 87 forks source link

Set-RubrikSLA Incorrectly modifies archive settings even when no archival changes are requested. #775

Open marcus9467 opened 3 years ago

marcus9467 commented 3 years ago

Current Behavior:

Set-RubrikSLA incorrectly updates the archivalSpecs, during a PATCH call even when no archive related aspects are being updated. This can cause the archive tiering policy to be lost upon update.

Pre-PATCH call:
(Get-RubrikSLA -id "318a5b63-6c26-4846-86d0-8cb5d3490a90").archivalSpecs
locationId             : c518ee19-6a09-495b-9684-d9d32ed9683b
locationName           : Azure:cas
archivalThreshold      : 49680000
archivalTieringSpec    : @{isInstantTieringEnabled=True}
isPassthroughSupported : True

PATCH call:
$options = @{
    DailyRetentionType      =   "Weekly"
    MonthlyRetentionType    =   "Monthly"
    AdvancedConfig          =   $true
}
Get-RubrikSLA -id "318a5b63-6c26-4846-86d0-8cb5d3490a90" | Set-RubrikSLA @options -Verbose
VERBOSE: Validate the Rubrik token exists
VERBOSE: Found a Rubrik token for authentication
VERBOSE: Gather API Data for Set-RubrikSLA
VERBOSE: Selected 5.0 API Data for Set-RubrikSLA
VERBOSE: Load API data for Set-RubrikSLA
VERBOSE: Description: Update an existing SLA Domain on a Rubrik cluster by specifying Domain Rules and policies
VERBOSE: Build the URI                                                                                                                                                  VERBOSE: URI = https://rtplab.rubrik.com/api/v2/sla_domain/318a5b63-6c26-4846-86d0-8cb5d3490a90                                                                        VERBOSE: Build the query parameters for <null>                                                                                                                          VERBOSE: URI = https://rtplab.rubrik.com/api/v2/sla_domain/318a5b63-6c26-4846-86d0-8cb5d3490a90
VERBOSE: Build the body
VERBOSE: Setting ParamValidation flag to $false to check if user set any params
VERBOSE: Checking for the $ParamValidation flag
VERBOSE: Header = {"Authorization":","User-Agent":"RubrikPowerShellSDK-5.3.0--7.1.3--platform--Unix--platform_version--Darwin 19.6.0 Darwin Kernel Version 19.6.0. Thu May  6 00.48.39 "}
VERBOSE: Body = {
  "firstFullAllowedBackupWindows": [],
  "showAdvancedUi": true,
  "frequencies": {
    "daily": {
      "frequency": 1,
      "retention": 4
    },
    "yearly": {
      "yearStartMonth": "January",
      "dayOfYear": "LastDay",
      "retention": 10,
      "frequency": 1
    },
    "monthly": {
      "retention": 7,
      "dayOfMonth": "LastDay",
      "frequency": 1
    }
  },
  "allowedBackupWindows": [],
  "replicationSpecs": [],
  "name": "AdvancedRetentionTest",
  "localRetentionLimit": 49680000,
  "advancedUiConfig": [
    {
      "retentionType": "Weekly",
      "timeUnit": "Daily"
    },
    {
      "retentionType": "Monthly",
      "timeUnit": "Monthly"
    },
    {
      "retentionType": "Yearly",
      "timeUnit": "Yearly"
    }
  ],
  "archivalSpecs": [
    {
      "locationId": "c518ee19-6a09-495b-9684-d9d32ed9683b",
      "archivalThreshold": 49680000
    }
  ]
}
VERBOSE: Submitting the request
VERBOSE: Invoking request with a custom timeout of 1500 seconds
VERBOSE: PATCH https://rtplab.rubrik.com/api/v2/sla_domain/318a5b63-6c26-4846-86d0-8cb5d3490a90 with 893-byte payload
VERBOSE: received 913-byte response of content type application/json
VERBOSE: Received HTTP Status 200                                                                                                                                      VERBOSE: Formatting return value                                                                                                                                       VERBOSE: Filter the results                                                                                                                                             VERBOSE: Getting SLA Domain frequency summary
VERBOSE: Advanced config found, using this
VERBOSE: Applying Rubrik.SLADomain TypeName to results

Post-PATCH Call:
(Get-RubrikSLA -id "318a5b63-6c26-4846-86d0-8cb5d3490a90").archivalSpecs

locationId             : c518ee19-6a09-495b-9684-d9d32ed9683b
locationName           : Azure:cas
archivalThreshold      : 49680000
isPassthroughSupported : True

Expected Behavior: We should only modify the options supplied as part of the PATCH request. It looks like we have a few default things that are built into the PATCH call that get called regardless.

Steps to Reproduce:

Please provide detailed steps for reproducing the issue.

  1. Create an SLA with an archive and instant tiering policy in place
  2. Attempt to modify the SLA using Set-RubrikSLA, but do not make any changes to the archive in the PATCH call
  3. Review the archivalSpecs after the PATCH call.

Context: This is a relatively important thing to fix in the near term as at best it breaks all UPLOAD jobs for objects assigned to this SLA because the incremental upload is looking for references that currently only exist in the archive tier. At best it will result in a new chain being started in the access tier (often a good deal more expensive than the expected pricing for the archive tier)

Failure Logs

N/A

marcus9467 commented 3 years ago

It may also be worth noting that this cmdlet uses API v2 PATCH /sla_domain, and as of 5.2.X this API is deprecated in favor of using v3.