Merge pull request #48 from ZertoPublic/75Update

Update to add token parameter to Add-ZertoPeerSite
This commit is contained in:
Wes Carroll
2019-10-04 17:01:37 -04:00
committed by GitHub
5 changed files with 123 additions and 40 deletions
+2 -10
View File
@@ -2,17 +2,9 @@
### Zerto Virtual Manager ### Zerto Virtual Manager
* Added two functions to aid in bulk updating of NIC information for protected VMs. ([Issue 38](https://github.com/ZertoPublic/ZertoApiWrapper/issues/38)) * [Zerto version 7.5 has been released.](https://s3.amazonaws.com/zertodownload_docs/Latest/Zerto%20Virtual%20Replication%20Release%20Notes.pdf) As part of this release Zerto has added API functionality that requires the following updates.
* [Export-ZertoVmNicSetting](https://github.com/ZertoPublic/ZertoApiWrapper/blob/Master/docs/Export-ZertoVmNicSettings.md) * A token is now required to pair two sites together. The need is discussed in [Issue 46](https://github.com/ZertoPublic/ZertoApiWrapper/issues/46). To implement this change a `-token` parameter has been added to the `Add-ZertoPeerSite` function.
* [Import-ZertoVmNicSetting](https://github.com/ZertoPublic/ZertoApiWrapper/blob/Master/docs/Import-ZertoVmNicSettings.md)
* Fixed an [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/43) where a VPG being created with a single VM member would not be parsed by the API correctly using PowerShell 5.1
### Zerto Analytics ### Zerto Analytics
* Fixed an [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/36) where the Zerto Analytics Rest Request function was not checking for the token before attempting a connection.
* Fixed an [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/40) where the `Get-ZAVpg` method would return a 404 error when a `-vpgIdentifier` parameter was specified.
### General Updates ### General Updates
* Updated the way that tests are invoked and parsed to ensure that both source and built module files are tested. This will ensure that what is being shipped passes all tests along with testing of the source files.
* Added additional parameter validation tests to several of the functions. On-going effort to complete stand alone unit testing of each function.
+50 -22
View File
@@ -9,34 +9,55 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' {
Context "$global:function::Parameter Unit Tests" { Context "$global:function::Parameter Unit Tests" {
It "Has a mandatory string parameter for the target host" { It "$global:function should have exactly 16 parameters defined" {
Get-Command $global:function | Should -HaveParameter TargetHost -Mandatory -Type String (Get-Command $global:function).Parameters.Count | Should -Be 16
} }
It "Will not take a non-ip address as a 'TargetHost'" { $ParameterTestCases = @(
{ Add-ZertoPeerSite -targetHost 'MyZVMHost' -targetPort '9081' } | Should -Throw @{ParameterName = 'targetHost'; Type = 'String'; Mandatory = $true; Validation = 'Script' }
{ Add-ZertoPeerSite -targetHost '192.168.1.266' -targetPort '9081' } | Should -Throw @{ParameterName = 'targetPort'; Type = 'Int32'; Mandatory = $false; Validation = 'Range' }
{ Add-ZertoPeerSite -targetHost '192.168.1' -targetPort '9081' } | Should -Throw @{ParameterName = 'token'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' }
{ Add-ZertoPeerSite -targetHost $null -targetPort '9081' } | Should -Throw )
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
param($ParameterName, $Type, $Mandatory, $Validation)
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
} }
It "Has a non-mandatory string parameter for the target port with default value of 9081" { It "<ParameterName> parameter has correct validation setting" -TestCases $ParameterTestCases {
Get-Command Add-ZertoPeerSite | Should -HaveParameter TargetPort -Not -Mandatory param($ParameterName, $Validation)
Get-Command Add-ZertoPeerSite | Should -HaveParameter TargetPort -Type Int32 Switch ($Validation) {
Get-Command Add-ZertoPeerSite | Should -HaveParameter TargetPort -DefaultValue 9081 'Script' {
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
$attrs.Where{ $_ -is [ValidateScript] }.Count | Should -Be 1
}
'Range' {
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
$attrs.Where{ $_ -is [ValidateRange] }.Count | Should -Be 1
}
'NotNullOrEmpty' {
$attrs = (Get-Command $global:function).Parameters[$ParameterName].Attributes
$attrs.Where{ $_ -is [ValidateNotNullOrEmpty] }.Count | Should -Be 1
}
default {
$true | Should be $false -Because "No Validation Selected. Review test cases"
}
}
} }
It "Will not take a non-int as a port" { It "targetPort Parameter should have a default value of 9081" {
{ Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 'string' } | Should -Throw Get-Command $global:function | Should -HaveParameter targetPort -DefaultValue 9081
{ Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort $true } | Should -Throw
{ Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort $null } | Should -Throw
} }
It "Will fail if the specified port is outside of the range 1024 - 65535" { It "targetPort Parameter should have a Min value of 1024" {
{ Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 1023 } | Should -Throw (Get-Command $global:function).Parameters['targetPort'].Attributes.Where{ $_ -is [ValidateRange] }.MinRange | Should Be 1024
{ Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 65536 } | Should -Throw }
{ Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 0 } | Should -Throw
{ Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort -1 } | Should -Throw It "targetPort Parameter should have a Max value of 65535" {
(Get-Command $global:function).Parameters['targetPort'].Attributes.Where{ $_ -is [ValidateRange] }.MaxRange | Should Be 65535
} }
It "Supports 'SupportsShouldProcess'" { It "Supports 'SupportsShouldProcess'" {
@@ -52,19 +73,26 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' {
return (Get-Content "$global:here\Mocks\TaskId.txt") return (Get-Content "$global:here\Mocks\TaskId.txt")
} }
It "Returns a string value" { It "Returns a string value when no Token Passed" {
$results = Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort '9081' $results = Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort '9081'
$results | Should -Not -BeNullOrEmpty $results | Should -Not -BeNullOrEmpty
$results | Should -BeOfType "String" $results | Should -BeOfType "String"
$results | Should -BeExactly "7e79035e-fb8c-47fe-815c-12ddd41708e6.3e4cdd0d-1064-4022-921f-6265ad6d335a" $results | Should -BeExactly "7e79035e-fb8c-47fe-815c-12ddd41708e6.3e4cdd0d-1064-4022-921f-6265ad6d335a"
} }
It "Returns a string value when a Token is passed" {
$results = Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort '9081' -token "NotARealTokenString"
$results | Should -Not -BeNullOrEmpty
$results | Should -BeOfType "String"
$results | Should -BeExactly "7e79035e-fb8c-47fe-815c-12ddd41708e6.3e4cdd0d-1064-4022-921f-6265ad6d335a"
}
It "Does not return a taskId if '-whatif' is used" { It "Does not return a taskId if '-whatif' is used" {
$results = Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort '9081' -WhatIf $results = Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort '9081' -WhatIf
$results | Should -BeNullOrEmpty $results | Should -BeNullOrEmpty
} }
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -Exactly 1 Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -Exactly 2
} }
} }
Remove-Variable -Name here -Scope Global Remove-Variable -Name here -Scope Global
+13 -4
View File
@@ -6,21 +6,30 @@ function Add-ZertoPeerSite {
Mandatory = $true, Mandatory = $true,
HelpMessage = "Target Hostname or IP address to pair the localsite to." HelpMessage = "Target Hostname or IP address to pair the localsite to."
)] )]
[ValidateScript( {$_ -match [IPAddress]$_ } )] [ValidateScript( { $_ -match [IPAddress]$_ } )]
[string]$targetHost, [string]$targetHost,
[Parameter( [Parameter(
HelpMessage = "Target communication port. Default is 9081" HelpMessage = "Target communication port. Default is 9081"
)] )]
[ValidateRange(1024, 65535)] [ValidateRange(1024, 65535)]
[int]$targetPort = 9081 [int]$targetPort = 9081,
[Parameter(
HelpMessage = "The generated token from the destination site. Note: This is only supported when both sites support pairing authentication. This was implemented to support ZVR 7.5 and later."
)]
[ValidateNotNullOrEmpty()]
[string]$token
) )
begin { begin {
$baseUri = "peersites"
$body = @{"HostName" = $targetHost; "Port" = $targetPort}
} }
process { process {
$baseUri = "peersites"
if ($PSBoundParameters.Keys.Contains("token")) {
$body = @{ "HostName" = $targetHost; "Port" = $targetPort; "Token" = $token }
} else {
$body = @{ "HostName" = $targetHost; "Port" = $targetPort }
}
if ($PSCmdlet.ShouldProcess("Pairing with Site $targetHost")) { if ($PSCmdlet.ShouldProcess("Pairing with Site $targetHost")) {
Invoke-ZertoRestRequest -uri $baseUri -body $($body | ConvertTo-Json) -method "POST" Invoke-ZertoRestRequest -uri $baseUri -body $($body | ConvertTo-Json) -method "POST"
} }
+26 -3
View File
@@ -13,7 +13,8 @@ Pairs the current Zerto Virtual Manager to the target Zerto Virtual Manager
## SYNTAX ## SYNTAX
``` ```
Add-ZertoPeerSite [-targetHost] <String> [[-targetPort] <Int32>] [-WhatIf] [-Confirm] [<CommonParameters>] Add-ZertoPeerSite [-targetHost] <String> [[-targetPort] <Int32>] [-token <String>] [-WhatIf] [-Confirm]
[<CommonParameters>]
``` ```
## DESCRIPTION ## DESCRIPTION
@@ -23,10 +24,17 @@ Pairs the current Zerto Virtual Manager to the target Zerto Virtual Manager by l
### Example 1 ### Example 1
```powershell ```powershell
PS C:\> Add-ZertoPeerSite -targetHost "192.168.2.100" -targetPort "9081" PS C:\> Add-ZertoPeerSite -targetHost "192.168.2.100"
``` ```
Pairs the current Zerto Virtual Manager to the Zerto Virtual Manager at IP address 192.168.2.100. Pairs the current Zerto Virtual Manager to the Zerto Virtual Manager at IP address 192.168.2.100. Use this method when pairing Zerto Virtual Managers that are prior to version 7.5
### Example 2
```powershell
PS C:\> Add-ZertoPeerSite -targetHost "192.168.2.100" -token "GeneratedFromTargetZVM"
```
Pairs the current Zerto Virtual Manager to the Zerto Virtual Manager at IP address 192.168.2.100. Use this method when pairing Zerto Virtual Managers that are version 7.5 or later.
## PARAMETERS ## PARAMETERS
@@ -61,6 +69,21 @@ Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
``` ```
### -token
The generated token from the destination site. Note: This is only supported when both sites support pairing authentication. This was implemented to support ZVR 7.5 and later.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Confirm ### -Confirm
Prompts you for confirmation before running the cmdlet. Prompts you for confirmation before running the cmdlet.
+32 -1
View File
@@ -13,7 +13,7 @@ Using a CSV file, will import updated Live and Test network settings for protect
## SYNTAX ## SYNTAX
``` ```
Import-ZertoVmNicSetting [-InputFile] <String> [<CommonParameters>] Import-ZertoVmNicSetting [-InputFile] <String> [-WhatIf] [-Confirm] [<CommonParameters>]
``` ```
## DESCRIPTION ## DESCRIPTION
@@ -47,6 +47,36 @@ Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
``` ```
### -Confirm
Prompts you for confirmation before running the cmdlet.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters ### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
@@ -57,4 +87,5 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
## NOTES ## NOTES
## RELATED LINKS ## RELATED LINKS
[Zerto Virtual Manager REST API VpgSettings end point documentation](http://s3.amazonaws.com/zertodownload_docs/Latest/Zerto%20Virtual%20Replication%20Zerto%20Virtual%20Manager%20%28ZVM%29%20-%20vSphere%20Online%20Help/index.html#page/RestfulAPIs%2FStatusAPIs.5.110.html%23) [Zerto Virtual Manager REST API VpgSettings end point documentation](http://s3.amazonaws.com/zertodownload_docs/Latest/Zerto%20Virtual%20Replication%20Zerto%20Virtual%20Manager%20%28ZVM%29%20-%20vSphere%20Online%20Help/index.html#page/RestfulAPIs%2FStatusAPIs.5.110.html%23)