From 9afabcd78e1e848565af10965809d3abee198728 Mon Sep 17 00:00:00 2001 From: sriramvu Date: Thu, 5 Mar 2015 18:15:51 +0530 Subject: [PATCH 1/3] bug1680974 --- .../PSRecoveryServicesClient.cs | 22 +++++++++++++++---- .../Properties/Resources.Designer.cs | 9 ++++++++ .../Properties/Resources.resx | 3 +++ .../lib/Utilities.cs | 2 ++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesClient.cs b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesClient.cs index cba792731dec..cd6b441792c9 100644 --- a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesClient.cs +++ b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesClient.cs @@ -79,6 +79,8 @@ public RecoveryServicesManagementClient GetRecoveryServicesClient /// private RecoveryServicesManagementClient recoveryServicesClient; + private string currentSubscriptionId; + /// /// Initializes a new instance of the class with /// required current subscription. @@ -87,6 +89,7 @@ public RecoveryServicesManagementClient GetRecoveryServicesClient public PSRecoveryServicesClient(AzureProfile azureProfile, AzureSubscription azureSubscription) { this.Profile = azureProfile; + this.currentSubscriptionId = azureSubscription.Id.ToString(); this.recoveryServicesClient = AzureSession.ClientFactory.CreateClient(azureProfile, azureSubscription, AzureEnvironment.Endpoint.ServiceManagement); } @@ -154,6 +157,17 @@ public bool ValidateVaultSettings( return true; } + public bool ValidateVaultContext( + string subscriptionId) + { + if (0 == string.CompareOrdinal(this.currentSubscriptionId, subscriptionId)) + { + return true; + } + + return false; + } + /// /// Site Recovery requests that go to on-premise components (like the Provider installed /// in VMM) require an authentication token that is signed with the vault key to indicate @@ -213,10 +227,10 @@ public CustomRequestHeaders GetRequestHeaders(bool shouldSignRequest = true) private SiteRecoveryManagementClient GetSiteRecoveryClient() { CloudServiceListResponse services = this.recoveryServicesClient.CloudServices.List(); - this.ValidateVaultSettings( - asrVaultCreds.ResourceName, - asrVaultCreds.CloudServiceName, - services); + if (!this.ValidateVaultContext(asrVaultCreds.SubscriptionId)) + { + throw new ArgumentException(Properties.Resources.InvalidVaultContext); + } CloudService selectedCloudService = null; Vault selectedResource = null; diff --git a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.Designer.cs b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.Designer.cs index 82e9046ea72d..8f8c12734b79 100644 --- a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.Designer.cs +++ b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.Designer.cs @@ -182,6 +182,15 @@ internal static string InvalidResource { } } + /// + /// Looks up a localized string similar to Imported Vault is not associated with the Current Subscription.. + /// + internal static string InvalidVaultContext { + get { + return ResourceManager.GetString("InvalidVaultContext", resourceCulture); + } + } + /// /// Looks up a localized string similar to XML is malformed or file is empty, exception details: {0}. /// diff --git a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.resx b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.resx index 3d362f7f9f51..0b7f012a459a 100644 --- a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.resx +++ b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.resx @@ -256,4 +256,7 @@ Please provide a storage account with the same location as that of the vault. The Subscription or Storage account couldn’t be validated. For failovers to be successful, the Subscription should belong to your account, the Storage account to the Subscription and Storage account location must be the same as location of your Vault. + + Imported Vault is not associated with the Current Subscription. + \ No newline at end of file diff --git a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/lib/Utilities.cs b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/lib/Utilities.cs index 525ccb182ccc..7f9ce4b549b3 100644 --- a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/lib/Utilities.cs +++ b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/lib/Utilities.cs @@ -112,6 +112,8 @@ public static void UpdateVaultSettings(ASRVaultCreds asrVaultCreds) asrVaultCreds.CloudServiceName; PSRecoveryServicesClient.asrVaultCreds.ChannelIntegrityKey = asrVaultCreds.ChannelIntegrityKey; + PSRecoveryServicesClient.asrVaultCreds.SubscriptionId = + asrVaultCreds.SubscriptionId; } } From 3758cbabfe4f8163e7dc21d63c5e1ff22d9d8c40 Mon Sep 17 00:00:00 2001 From: sriramvu Date: Tue, 10 Mar 2015 12:25:00 +0530 Subject: [PATCH 2/3] fixing test issue wrt Storage & Network mapping --- .../ScenarioTests/RecoveryServicesTests.ps1 | 62 ++++++++++++------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices.Test/ScenarioTests/RecoveryServicesTests.ps1 b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices.Test/ScenarioTests/RecoveryServicesTests.ps1 index 7dcb3c0c6f52..4886a79b2b7f 100644 --- a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices.Test/ScenarioTests/RecoveryServicesTests.ps1 +++ b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices.Test/ScenarioTests/RecoveryServicesTests.ps1 @@ -247,7 +247,7 @@ function Test-StorageMapping # Enumerate Servers $servers = Get-AzureSiteRecoveryServer - Assert-True { $servers.Count -gt 0 } + Assert-True { $servers.Count -gt 1 } Assert-NotNull($servers) foreach($server in $servers) { @@ -256,25 +256,34 @@ function Test-StorageMapping } # Enumerate Storages - $storages = Get-AzureSiteRecoveryStorage -Server $servers[0] - Assert-NotNull($storages) - Assert-True { $storages.Count -gt 0 } - foreach($storage in $storages) + $storagesOnPrimary = Get-AzureSiteRecoveryStorage -Server $servers[0] + Assert-NotNull($storagesOnPrimary) + Assert-True { $storagesOnPrimary.Count -gt 0 } + foreach($storage in $storagesOnPrimary) + { + Assert-NotNull($storage.Name) + Assert-NotNull($storage.ID) + } + + $storagesOnRecovery = Get-AzureSiteRecoveryStorage -Server $servers[1] + Assert-NotNull($storagesOnRecovery) + Assert-True { $storagesOnRecovery.Count -gt 0 } + foreach($storage in $storagesOnRecovery) { Assert-NotNull($storage.Name) Assert-NotNull($storage.ID) } # Enumerate StorageMappings - $storageMappings = Get-AzureSiteRecoveryStorageMapping -PrimaryServer $servers[0] -RecoveryServer $servers[0] + $storageMappings = Get-AzureSiteRecoveryStorageMapping -PrimaryServer $servers[0] -RecoveryServer $servers[1] Assert-True { $storageMappings.Count -eq 0 } # Create StorageMapping - $job = New-AzureSiteRecoveryStorageMapping -PrimaryStorage $storages[0] -RecoveryStorage $storages[1] + $job = New-AzureSiteRecoveryStorageMapping -PrimaryStorage $storagesOnPrimary[0] -RecoveryStorage $storagesOnRecovery[0] WaitForJobCompletion -JobId $job.ID # Enumerate StorageMappings - $storageMappings = Get-AzureSiteRecoveryStorageMapping -PrimaryServer $servers[0] -RecoveryServer $servers[0] + $storageMappings = Get-AzureSiteRecoveryStorageMapping -PrimaryServer $servers[0] -RecoveryServer $servers[1] Assert-NotNull($storageMappings) Assert-True { $storageMappings.Count -eq 1 } Assert-NotNull($storageMappings[0].PrimaryServerId) @@ -296,7 +305,7 @@ function Test-StorageUnMapping # Enumerate Servers $servers = Get-AzureSiteRecoveryServer - Assert-True { $servers.Count -gt 0 } + Assert-True { $servers.Count -gt 1 } Assert-NotNull($servers) foreach($server in $servers) { @@ -305,7 +314,7 @@ function Test-StorageUnMapping } # Enumerate StorageMappings - $storageMappings = Get-AzureSiteRecoveryStorageMapping -PrimaryServer $servers[0] -RecoveryServer $servers[0] + $storageMappings = Get-AzureSiteRecoveryStorageMapping -PrimaryServer $servers[0] -RecoveryServer $servers[1] Assert-NotNull($storageMappings) Assert-True { $storageMappings.Count -eq 1 } Assert-NotNull($storageMappings[0].PrimaryServerId) @@ -318,7 +327,7 @@ function Test-StorageUnMapping WaitForJobCompletion -JobId $job.ID # Enumerate StorageMappings - $storageMappings = Get-AzureSiteRecoveryStorageMapping -PrimaryServer $servers[0] -RecoveryServer $servers[0] + $storageMappings = Get-AzureSiteRecoveryStorageMapping -PrimaryServer $servers[0] -RecoveryServer $servers[1] Assert-True { $storageMappings.Count -eq 0 } } @@ -335,7 +344,7 @@ function Test-NetworkMapping # Enumerate Servers $servers = Get-AzureSiteRecoveryServer - Assert-True { $servers.Count -gt 0 } + Assert-True { $servers.Count -gt 1 } Assert-NotNull($servers) foreach($server in $servers) { @@ -344,25 +353,34 @@ function Test-NetworkMapping } # Enumerate Networks - $networks = Get-AzureSiteRecoveryNetwork -Server $servers[0] - Assert-NotNull($networks) - Assert-True { $networks.Count -gt 0 } - foreach($network in $networks) + $networksOnPrimary = Get-AzureSiteRecoveryNetwork -Server $servers[0] + Assert-NotNull($networksOnPrimary) + Assert-True { $networksOnPrimary.Count -gt 0 } + foreach($network in $networksOnPrimary) + { + Assert-NotNull($network.Name) + Assert-NotNull($network.ID) + } + + $networksOnRecovery = Get-AzureSiteRecoveryNetwork -Server $servers[1] + Assert-NotNull($networksOnRecovery) + Assert-True { $networksOnRecovery.Count -gt 0 } + foreach($network in $networksOnRecovery) { Assert-NotNull($network.Name) Assert-NotNull($network.ID) } # Enumerate NetworkMappings - $networkMappings = Get-AzureSiteRecoveryNetworkMapping -PrimaryServer $servers[0] -RecoveryServer $servers[0] + $networkMappings = Get-AzureSiteRecoveryNetworkMapping -PrimaryServer $servers[0] -RecoveryServer $servers[1] Assert-True { $networkMappings.Count -eq 0 } # Create NetworkMapping - $job = New-AzureSiteRecoveryNetworkMapping -PrimaryNetwork $networks[0] -RecoveryNetwork $networks[1] + $job = New-AzureSiteRecoveryNetworkMapping -PrimaryNetwork $networksOnPrimary[0] -RecoveryNetwork $networksOnRecovery[0] WaitForJobCompletion -JobId $job.ID # Enumerate NetworkMappings - $networkMappings = Get-AzureSiteRecoveryNetworkMapping -PrimaryServer $servers[0] -RecoveryServer $servers[0] + $networkMappings = Get-AzureSiteRecoveryNetworkMapping -PrimaryServer $servers[0] -RecoveryServer $servers[1] Assert-NotNull($networkMappings) Assert-True { $networkMappings.Count -eq 1 } Assert-NotNull($networkMappings[0].PrimaryServerId) @@ -450,7 +468,7 @@ function Test-NetworkUnMapping # Enumerate Servers $servers = Get-AzureSiteRecoveryServer - Assert-True { $servers.Count -gt 0 } + Assert-True { $servers.Count -gt 1 } Assert-NotNull($servers) foreach($server in $servers) { @@ -459,7 +477,7 @@ function Test-NetworkUnMapping } # Enumerate NetworkMappings - $networkMappings = Get-AzureSiteRecoveryNetworkMapping -PrimaryServer $servers[0] -RecoveryServer $servers[0] + $networkMappings = Get-AzureSiteRecoveryNetworkMapping -PrimaryServer $servers[0] -RecoveryServer $servers[1] Assert-NotNull($networkMappings) Assert-True { $networkMappings.Count -eq 1 } Assert-NotNull($networkMappings[0].PrimaryServerId) @@ -474,7 +492,7 @@ function Test-NetworkUnMapping WaitForJobCompletion -JobId $job.ID # Enumerate NetworkMappings - $networkMappings = Get-AzureSiteRecoveryNetworkMapping -PrimaryServer $servers[0] -RecoveryServer $servers[0] + $networkMappings = Get-AzureSiteRecoveryNetworkMapping -PrimaryServer $servers[0] -RecoveryServer $servers[1] Assert-True { $networkMappings.Count -eq 0 } } From ce314adee67fee15e0c23c63a934ab5eac18a868 Mon Sep 17 00:00:00 2001 From: sriramvu Date: Wed, 11 Mar 2015 13:42:46 +0530 Subject: [PATCH 3/3] Revert "bug1680974" This reverts commit 9afabcd78e1e848565af10965809d3abee198728. --- .../PSRecoveryServicesClient.cs | 22 ++++--------------- .../Properties/Resources.Designer.cs | 9 -------- .../Properties/Resources.resx | 3 --- .../lib/Utilities.cs | 2 -- 4 files changed, 4 insertions(+), 32 deletions(-) diff --git a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesClient.cs b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesClient.cs index cd6b441792c9..cba792731dec 100644 --- a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesClient.cs +++ b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesClient.cs @@ -79,8 +79,6 @@ public RecoveryServicesManagementClient GetRecoveryServicesClient /// private RecoveryServicesManagementClient recoveryServicesClient; - private string currentSubscriptionId; - /// /// Initializes a new instance of the class with /// required current subscription. @@ -89,7 +87,6 @@ public RecoveryServicesManagementClient GetRecoveryServicesClient public PSRecoveryServicesClient(AzureProfile azureProfile, AzureSubscription azureSubscription) { this.Profile = azureProfile; - this.currentSubscriptionId = azureSubscription.Id.ToString(); this.recoveryServicesClient = AzureSession.ClientFactory.CreateClient(azureProfile, azureSubscription, AzureEnvironment.Endpoint.ServiceManagement); } @@ -157,17 +154,6 @@ public bool ValidateVaultSettings( return true; } - public bool ValidateVaultContext( - string subscriptionId) - { - if (0 == string.CompareOrdinal(this.currentSubscriptionId, subscriptionId)) - { - return true; - } - - return false; - } - /// /// Site Recovery requests that go to on-premise components (like the Provider installed /// in VMM) require an authentication token that is signed with the vault key to indicate @@ -227,10 +213,10 @@ public CustomRequestHeaders GetRequestHeaders(bool shouldSignRequest = true) private SiteRecoveryManagementClient GetSiteRecoveryClient() { CloudServiceListResponse services = this.recoveryServicesClient.CloudServices.List(); - if (!this.ValidateVaultContext(asrVaultCreds.SubscriptionId)) - { - throw new ArgumentException(Properties.Resources.InvalidVaultContext); - } + this.ValidateVaultSettings( + asrVaultCreds.ResourceName, + asrVaultCreds.CloudServiceName, + services); CloudService selectedCloudService = null; Vault selectedResource = null; diff --git a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.Designer.cs b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.Designer.cs index 8f8c12734b79..82e9046ea72d 100644 --- a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.Designer.cs +++ b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.Designer.cs @@ -182,15 +182,6 @@ internal static string InvalidResource { } } - /// - /// Looks up a localized string similar to Imported Vault is not associated with the Current Subscription.. - /// - internal static string InvalidVaultContext { - get { - return ResourceManager.GetString("InvalidVaultContext", resourceCulture); - } - } - /// /// Looks up a localized string similar to XML is malformed or file is empty, exception details: {0}. /// diff --git a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.resx b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.resx index 0b7f012a459a..3d362f7f9f51 100644 --- a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.resx +++ b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.resx @@ -256,7 +256,4 @@ Please provide a storage account with the same location as that of the vault. The Subscription or Storage account couldn’t be validated. For failovers to be successful, the Subscription should belong to your account, the Storage account to the Subscription and Storage account location must be the same as location of your Vault. - - Imported Vault is not associated with the Current Subscription. - \ No newline at end of file diff --git a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/lib/Utilities.cs b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/lib/Utilities.cs index 7f9ce4b549b3..525ccb182ccc 100644 --- a/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/lib/Utilities.cs +++ b/src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/lib/Utilities.cs @@ -112,8 +112,6 @@ public static void UpdateVaultSettings(ASRVaultCreds asrVaultCreds) asrVaultCreds.CloudServiceName; PSRecoveryServicesClient.asrVaultCreds.ChannelIntegrityKey = asrVaultCreds.ChannelIntegrityKey; - PSRecoveryServicesClient.asrVaultCreds.SubscriptionId = - asrVaultCreds.SubscriptionId; } }