Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce parameter sets for Get-RubrikManagedVolume - Issue 351 #423

Merged
merged 15 commits into from
Aug 12, 2019
19 changes: 14 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

* Now uses new private function instead of the custom code in the function

## 2019-08-08

### Changed [Get-RubrikManagedVolume]

* Changed behavior of `-Relic` switch, by default now retrieves both relic and non-relics. `-Relic` or `-Relic:$false` in addition to that
* Added additional unit test
* Created parameter sets and improved parameter validation [Issue 351](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/351)

## 2019-08-06

### Changed [Get-RubrikSnapshot]
* Added -Latest parameter to return latest snapshot data
* Added -Range to use with -Date. This specifies how many days away from the given date to search for the closest matching snapshot. Defaults to one day.
* Added -ExactMatch to use with -Date. This causes no results to be returned if a matching date isn't found. Otherwise, all snapshots are returned if no match is made.
* Added unit tests for Get-RubrikSnapshot
* Updated Test-DateDifference, a private function used by Get-RubrikSnapshot, to support the -Range parameter

* Added `-Latest` parameter to return latest snapshot data
* Added `-Range` to use with `-Date`. This specifies how many days away from the given date to search for the closest matching snapshot. Defaults to one day.
* Added `-ExactMatch` to use with `-Date`. This causes no results to be returned if a matching date isn't found. Otherwise, all snapshots are returned if no match is made.
* Added unit tests for `Get-RubrikSnapshot`
* Updated `Test-DateDifference`, a private function used by `Get-RubrikSnapshot`, to support the `-Range` parameter

## 2019-07-31

Expand Down
48 changes: 45 additions & 3 deletions Rubrik/Public/Get-RubrikManagedVolume.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ function Get-RubrikManagedVolume
.LINK
http://rubrikinc.github.io/rubrik-sdk-for-powershell/

.EXAMPLE
Get-RubrikManagedVolume

Retrieves all Rubrik Managed Volumes, active and relics

.EXAMPLE
Get-RubrikManagedVolume -Relic

Retrieves all Rubrik Managed Volumes that are relics

.EXAMPLE
Get-RubrikManagedVolume -Relic:$false

Retrieves all Rubrik Managed Volumes that are not relics

.EXAMPLE
Get-RubrikManagedVolume -name sqltest

Expand All @@ -34,23 +49,46 @@ function Get-RubrikManagedVolume
Get the managed volume named 'Bar'.
#>

[CmdletBinding()]
[CmdletBinding(DefaultParameterSetName = 'Name')]
Param(
# id of managed volume
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Parameter(
ParameterSetName='ID',
Mandatory = $true,
Position = 0,
ValueFromPipelineByPropertyName = $true
)]
[ValidateNotNullOrEmpty()]
[String]$id,
# Name of managed volume
[Parameter(
ParameterSetName='Name',
Position = 0,
ValueFromPipelineByPropertyName = $true
)]
[ValidateNotNullOrEmpty()]
[String]$Name,
# SLA name that the managed volume is protected under
[Parameter(ParameterSetName='Name')]
[Parameter(ParameterSetName='ID')]
[ValidateNotNullOrEmpty()]
[String]$SLA,
# SLA id that the managed volume is protected under
[Parameter(ParameterSetName='Name')]
[Parameter(ParameterSetName='ID')]
[Alias('effective_sla_domain_id')]
[ValidateNotNullOrEmpty()]
[String]$SLAID,
# Filter results to include only relic (removed) databases
[Parameter(ParameterSetName='Name')]
[Parameter(ParameterSetName='ID')]
[Alias('is_relic')]
[Switch]$Relic,
# Filter the summary information based on the primarycluster_id of the primary Rubrik cluster. Use **_local** as the primary_cluster_id of the Rubrik cluster that is hosting the current REST API session.
# Filter the summary information based on the primarycluster_id of the primary Rubrik cluster. Use local as the primary_cluster_id of the Rubrik cluster that is hosting the current REST API session.
[Alias('primary_cluster_id')]
[Parameter(ParameterSetName='Name')]
[Parameter(ParameterSetName='ID')]
[ValidateNotNullOrEmpty()]
[String]$PrimaryClusterID,
# Rubrik server IP or FQDN
[String]$Server = $global:RubrikConnection.server,
Expand All @@ -76,6 +114,10 @@ function Get-RubrikManagedVolume
Write-Verbose -Message "Load API data for $($resources.Function)"
Write-Verbose -Message "Description: $($resources.Description)"

# If the switch parameter was not explicitly specified remove from query params
if(-not $PSBoundParameters.ContainsKey('Relic')) {
$Resources.Query.Remove('is_relic')
}
}

Process {
Expand Down
35 changes: 25 additions & 10 deletions Tests/Get-RubrikManagedVolume.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Describe -Name 'Public/Get-RubrikManagedVolume' -Tag 'Public', 'Get-RubrikManage
Context -Name 'Results Filtering' {
Mock -CommandName Test-RubrikConnection -Verifiable -ModuleName 'Rubrik' -MockWith {}
Mock -CommandName Test-RubrikSLA -Verifiable -ModuleName 'Rubrik' -MockWith {
@{ 'slaid' = '12345678-1234-abcd-8910-1234567890ab' }
@{ 'slaid' = '12345678-1234-abcd-8910-1234567890cab' }
}
Mock -CommandName Submit-Request -Verifiable -ModuleName 'Rubrik' -MockWith {
@{
Expand All @@ -31,8 +31,8 @@ Describe -Name 'Public/Get-RubrikManagedVolume' -Tag 'Public', 'Get-RubrikManage
'primaryClusterId' = 'local'
'name' = 'OracleMV'
'isRelic' = 'False'
'effectiveSlaDomainId' = '12345678-1234-abcd-8910-1234567890ab'
'configuredSlaDomainId' = '12345678-1234-abcd-8910-1234567890ab'
'effectiveSlaDomainId' = '12345678-1234-abcd-8910-1234567890cab'
'configuredSlaDomainId' = '12345678-1234-abcd-8910-1234567890cab'
'effectiveSlaDomainName' = 'Gold'
'configuredSlaDomainName' = 'Gold'
},
Expand All @@ -46,33 +46,48 @@ Describe -Name 'Public/Get-RubrikManagedVolume' -Tag 'Public', 'Get-RubrikManage
'configuredSlaDomainId' = '12345678-1234-abcd-8910-1234567890abc'
'effectiveSlaDomainName' = 'Bronze'
'configuredSlaDomainName' = 'Bronze'
},
@{
'id' = 'ManagedVolume:::33333'
'isDeleted' = 'False'
'primaryClusterId' = 'local'
'name' = 'LinMV'
'isRelic' = 'True'
'effectiveSlaDomainId' = '12345678-1234-abcd-8910-1234567890bac'
'configuredSlaDomainId' = '12345678-1234-abcd-8910-1234567890bac'
'effectiveSlaDomainName' = 'Silver'
'configuredSlaDomainName' = 'Silver'
}
}

It -Name 'Should Return count of 2' -Test {
(Get-RubrikManagedVolume).Count |
Should -BeExactly 2
Should -BeExactly 3
}
It -Name 'Name filter non existant should return count of 0' -Test {
(Get-RubrikManagedVolume -Name 'nonexistant').Count |
Should -BeExactly 0
}
}
It -Name 'Name Filter - ID should be ManagedVolume:::22222' -Test {
(Get-RubrikManagedVolume -name 'SQLMV').id |
Should -BeExactly 'ManagedVolume:::22222'
}
}
It -Name 'SLA Filter should be count of 1' -Test {
(Get-RubrikManagedVolume -SLA "Bronze" | Measure-Object).Count |
Should -BeExactly 1
}
}
It -Name 'Missing ID Exception' -Test {
{ Get-RubrikManagedVolume -id } |
Should -Throw "Missing an argument for parameter 'id'. Specify a parameter of type 'System.String' and try again."
}
}
It -Name 'Null or empty ID Exception' -Test {
{ Get-RubrikManagedVolume -id '' } |
Should -Throw "Cannot validate argument on parameter 'id'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again."
}

Assert-VerifiableMock
Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Times 1
Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Times 1
Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 4
Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 4
}

}