Skip to content

Commit 4b95a0c

Browse files
author
begoldsm
committed
Fix for broken remove-datasource cmdlet
This fixes the broken remove data source cmdlet, which had inverted conditional logic that made it impossible to remove either type of data source. In addition to this fix, this change includes test cases specific to testing adding and removing data sources, to ensure this doesn't happen again. Finally, all tests were run against production for both DataLake* cmdlet services so that we have production recordings.
1 parent 563d135 commit 4b95a0c

File tree

20 files changed

+5065
-1443
lines changed

20 files changed

+5065
-1443
lines changed

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/Commands.ScenarioTests.ResourceManager.Common.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@
5757
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.18.7-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
5858
</Reference>
5959
<Reference Include="Microsoft.Azure.Test.Framework">
60-
<HintPath>..\..\..\packages\Microsoft.Azure.Test.Framework.1.0.5772.15967-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>
60+
<HintPath>..\..\..\packages\Microsoft.Azure.Test.Framework.1.0.5785.18045-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>
6161
</Reference>
6262
<Reference Include="Microsoft.Azure.Test.HttpRecorder">
63-
<HintPath>..\..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.0.5772.15967-prerelease\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
63+
<HintPath>..\..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.0.5785.18045-prerelease\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
6464
</Reference>
6565
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory">
6666
<SpecificVersion>False</SpecificVersion>

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/packages.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<package id="Microsoft.Azure.Common.Authentication" version="1.3.5-preview" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
77
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
8-
<package id="Microsoft.Azure.Test.Framework" version="1.0.5772.15967-prerelease" targetFramework="net45" />
9-
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.0.5772.15967-prerelease" targetFramework="net45" />
8+
<package id="Microsoft.Azure.Test.Framework" version="1.0.5785.18045-prerelease" targetFramework="net45" />
9+
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.0.5785.18045-prerelease" targetFramework="net45" />
1010
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
1111
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
1212
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />

src/ResourceManager/DataLakeAnalytics/Commands.DataLakeAnalytics.Test/Commands.DataLakeAnalytics.Test.csproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,21 @@
7373
<SpecificVersion>False</SpecificVersion>
7474
<HintPath>..\..\..\packages\Microsoft.Azure.Management.DataLake.Store.0.9.1-preview\lib\net40\Microsoft.Azure.Management.DataLake.Store.dll</HintPath>
7575
</Reference>
76+
<Reference Include="Microsoft.Azure.Management.Storage">
77+
<SpecificVersion>False</SpecificVersion>
78+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Storage.3.0.0\lib\net40\Microsoft.Azure.Management.Storage.dll</HintPath>
79+
</Reference>
7680
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7781
<SpecificVersion>False</SpecificVersion>
7882
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.18.0-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
7983
</Reference>
80-
<Reference Include="Microsoft.Azure.Test.Framework, Version=1.0.5772.15967, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
84+
<Reference Include="Microsoft.Azure.Test.Framework">
8185
<SpecificVersion>False</SpecificVersion>
82-
<HintPath>..\..\..\packages\Microsoft.Azure.Test.Framework.1.0.5772.15967-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>
86+
<HintPath>..\..\..\packages\Microsoft.Azure.Test.Framework.1.0.5785.18045-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>
8387
</Reference>
84-
<Reference Include="Microsoft.Azure.Test.HttpRecorder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
88+
<Reference Include="Microsoft.Azure.Test.HttpRecorder">
8589
<SpecificVersion>False</SpecificVersion>
86-
<HintPath>..\..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.0.5772.15967-prerelease\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
90+
<HintPath>..\..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.0.5785.18045-prerelease\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
8791
</Reference>
8892
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.18.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
8993
<SpecificVersion>False</SpecificVersion>

src/ResourceManager/DataLakeAnalytics/Commands.DataLakeAnalytics.Test/ScenarioTests/DataLakeAnalyticsTests.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,33 @@ public class DataLakeAnalyticsTests : DataLakeAnalyticsTestsBase
2424
[Trait(Category.AcceptanceType, Category.CheckIn)]
2525
public void TestDataLakeAnalyticsAccount()
2626
{
27-
RunPowerShellTest(string.Format("Test-DataLakeAnalyticsAccount -resourceGroupName {0} -accountName {1} -dataLakeAccountName {2} -location '{3}'", this.resourceGroupName, this.dataLakeAnalyticsAccountName, this.dataLakeAccountName, DataLakeAnalyticsTestsBase.resourceGroupLocation));
27+
RunPowerShellTest(
28+
string.Format(
29+
"Test-DataLakeAnalyticsAccount -resourceGroupName {0} -accountName {1} -dataLakeAccountName {2} -secondDataLakeAccountName {3} -blobAccountName {4} -blobAccountKey {5} -location '{6}'",
30+
this.resourceGroupName, this.dataLakeAnalyticsAccountName, this.dataLakeStoreAccountName,
31+
this.secondDataLakeStoreAccountName, this.azureBlobStoreName, this.azureBlobStoreAccessKey,
32+
DataLakeAnalyticsTestsBase.resourceGroupLocation));
2833
}
2934

3035
[Fact]
3136
[Trait(Category.AcceptanceType, Category.CheckIn)]
3237
public void TestDataLakeAnalyticsJob()
3338
{
34-
RunPowerShellTest(string.Format("Test-DataLakeAnalyticsJob -resourceGroupName {0} -accountName {1} -dataLakeAccountName {2} -location '{3}'", this.resourceGroupName, this.dataLakeAnalyticsAccountName, this.dataLakeAccountName, DataLakeAnalyticsTestsBase.resourceGroupLocation));
39+
RunPowerShellTest(string.Format("Test-DataLakeAnalyticsJob -resourceGroupName {0} -accountName {1} -dataLakeAccountName {2} -location '{3}'", this.resourceGroupName, this.dataLakeAnalyticsAccountName, this.dataLakeStoreAccountName, DataLakeAnalyticsTestsBase.resourceGroupLocation));
3540
}
3641

3742
[Fact]
3843
[Trait(Category.AcceptanceType, Category.CheckIn)]
3944
public void TestNegativeDataLakeAnalyticsAccount()
4045
{
41-
RunPowerShellTest(string.Format("Test-NegativeDataLakeAnalyticsAccount -resourceGroupName {0} -accountName {1} -dataLakeAccountName {2} -location '{3}'", this.resourceGroupName, this.dataLakeAnalyticsAccountName, this.dataLakeAccountName, DataLakeAnalyticsTestsBase.resourceGroupLocation));
46+
RunPowerShellTest(string.Format("Test-NegativeDataLakeAnalyticsAccount -resourceGroupName {0} -accountName {1} -dataLakeAccountName {2} -location '{3}'", this.resourceGroupName, this.dataLakeAnalyticsAccountName, this.dataLakeStoreAccountName, DataLakeAnalyticsTestsBase.resourceGroupLocation));
4247
}
4348

4449
[Fact]
4550
[Trait(Category.AcceptanceType, Category.CheckIn)]
4651
public void TestNegativeDataLakeAnalyticsJob()
4752
{
48-
RunPowerShellTest(string.Format("Test-NegativeDataLakeAnalyticsJob -resourceGroupName {0} -accountName {1} -dataLakeAccountName {2} -location '{3}'", this.resourceGroupName, this.dataLakeAnalyticsAccountName, this.dataLakeAccountName, DataLakeAnalyticsTestsBase.resourceGroupLocation));
53+
RunPowerShellTest(string.Format("Test-NegativeDataLakeAnalyticsJob -resourceGroupName {0} -accountName {1} -dataLakeAccountName {2} -location '{3}'", this.resourceGroupName, this.dataLakeAnalyticsAccountName, this.dataLakeStoreAccountName, DataLakeAnalyticsTestsBase.resourceGroupLocation));
4954
}
5055
}
5156
}

src/ResourceManager/DataLakeAnalytics/Commands.DataLakeAnalytics.Test/ScenarioTests/DataLakeAnalyticsTests.ps1

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ function Test-DataLakeAnalyticsAccount
99
$resourceGroupName,
1010
$accountName,
1111
$dataLakeAccountName,
12-
$location = "West US"
12+
$secondDataLakeAccountName,
13+
$blobAccountName,
14+
$blobAccountKey,
15+
$location = "East US 2"
1316
)
1417

1518
# Creating Account
@@ -87,6 +90,34 @@ function Test-DataLakeAnalyticsAccount
8790
}
8891
Assert-True {$found -eq 1} "Account created earlier is not found when listing all in subscription."
8992

93+
# add a data lake store account to the analytics account
94+
Add-AzureRmDataLakeAnalyticsDataSource -Account $accountName -DataLakeStore $secondDataLakeAccountName
95+
96+
# get the account and ensure that it contains two data lake stores
97+
$testStoreAdd = Get-AzureRmDataLakeAnalyticsAccount -Name $accountName
98+
Assert-AreEqual 2 $testStoreAdd.Properties.DataLakeStoreAccounts.Count
99+
100+
# remove the Data lake storage account
101+
Assert-True {Remove-AzureRmDataLakeAnalyticsDataSource -Account $accountName -DataLakeStore $secondDataLakeAccountName -Force -PassThru} "Remove Data Lake Store account failed."
102+
103+
# get the account and ensure that it contains one data lake store
104+
$testStoreAdd = Get-AzureRmDataLakeAnalyticsAccount -Name $accountName
105+
Assert-AreEqual 1 $testStoreAdd.Properties.DataLakeStoreAccounts.Count
106+
107+
# add a blob account to the analytics account
108+
Add-AzureRmDataLakeAnalyticsDataSource -Account $accountName -Blob $blobAccountName -AccessKey $blobAccountKey
109+
110+
# get the account and ensure that it contains one blob account
111+
$testStoreAdd = Get-AzureRmDataLakeAnalyticsAccount -Name $accountName
112+
Assert-AreEqual 1 $testStoreAdd.Properties.StorageAccounts.Count
113+
114+
# remove the blob storage account
115+
Assert-True {Remove-AzureRmDataLakeAnalyticsDataSource -Account $accountName -Blob $blobAccountName -Force -PassThru} "Remove blob Storage account failed."
116+
117+
# get the account and ensure that it contains no azure storage accounts
118+
$testStoreAdd = Get-AzureRmDataLakeAnalyticsAccount -Name $accountName
119+
Assert-True {$testStoreAdd.Properties.StorageAccounts -eq $null -or $testStoreAdd.Properties.StorageAccounts.Count -eq 0} "Remove blob storage reported success but failed to remove the account."
120+
90121
# Delete dataLakeAnalytics account
91122
Assert-True {Remove-AzureRmDataLakeAnalyticsAccount -ResourceGroupName $resourceGroupName -Name $accountName -Force -PassThru} "Remove Account failed."
92123

src/ResourceManager/DataLakeAnalytics/Commands.DataLakeAnalytics.Test/ScenarioTests/DataLakeAnalyticsTestsBase.cs

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace Microsoft.Azure.Commands.DataLakeAnalytics.Test.ScenarioTests
2121
using Microsoft.Azure.Common.Authentication;
2222
using Microsoft.Azure.Management.DataLake.Store;
2323
using Microsoft.Azure.Management.DataLake.Store.Models;
24+
using Microsoft.Azure.Management.Storage;
25+
using Microsoft.Azure.Management.Storage.Models;
2426
using Microsoft.Azure.Management.DataLake.Analytics;
2527
using Microsoft.Azure.Management.Resources;
2628
using Microsoft.Azure.Management.Resources.Models;
@@ -34,9 +36,11 @@ public abstract class DataLakeAnalyticsTestsBase : TestBase, IDisposable
3436
{
3537
internal string resourceGroupName { get; set; }
3638
internal string dataLakeAnalyticsAccountName { get; set; }
37-
internal string dataLakeAccountName { get; set; }
38-
39-
internal const string resourceGroupLocation = "West US";
39+
internal string dataLakeStoreAccountName { get; set; }
40+
internal string secondDataLakeStoreAccountName { get; set; }
41+
internal string azureBlobStoreName { get; set; }
42+
internal string azureBlobStoreAccessKey { get; set; }
43+
internal const string resourceGroupLocation = "East US 2";
4044

4145
private EnvironmentSetupHelper helper;
4246

@@ -45,6 +49,7 @@ public abstract class DataLakeAnalyticsTestsBase : TestBase, IDisposable
4549
private DataLakeAnalyticsCatalogManagementClient dataLakeAnalyticsCatalogManagementClient;
4650
private DataLakeStoreManagementClient dataLakeStoreManagementClient;
4751
private ResourceManagementClient resourceManagementClient;
52+
private StorageManagementClient storageManagementClient;
4853

4954
protected DataLakeAnalyticsTestsBase()
5055
{
@@ -54,16 +59,19 @@ protected DataLakeAnalyticsTestsBase()
5459
dataLakeAnalyticsCatalogManagementClient = GetDataLakeAnalyticsCatalogManagementClient();
5560
resourceManagementClient = GetResourceManagementClient();
5661
dataLakeStoreManagementClient = GetDataLakeStoreManagementClient();
62+
storageManagementClient = GetStorageManagementClient();
5763
this.resourceGroupName = TestUtilities.GenerateName("abarg1");
5864
this.dataLakeAnalyticsAccountName = TestUtilities.GenerateName("testaba1");
59-
this.dataLakeAccountName = TestUtilities.GenerateName("datalake01");
65+
this.dataLakeStoreAccountName = TestUtilities.GenerateName("datalake01");
66+
this.secondDataLakeStoreAccountName = TestUtilities.GenerateName("datalake02");
67+
this.azureBlobStoreName = TestUtilities.GenerateName("azureblob01");
6068
}
6169

6270
protected void SetupManagementClients()
6371
{
6472
helper.SetupManagementClients(dataLakeAnalyticsManagementClient, dataLakeAnalyticsJobManagementClient,
6573
dataLakeAnalyticsCatalogManagementClient,
66-
resourceManagementClient, dataLakeStoreManagementClient);
74+
resourceManagementClient, dataLakeStoreManagementClient, storageManagementClient);
6775
}
6876

6977
protected void RunPowerShellTest(params string[] scripts)
@@ -76,11 +84,26 @@ protected void RunPowerShellTest(params string[] scripts)
7684
// Create the resource group
7785
this.TryRegisterSubscriptionForResource();
7886
this.TryCreateResourceGroup(this.resourceGroupName, resourceGroupLocation);
79-
this.TryCreateDataLakeStoreAccount(this.resourceGroupName, this.dataLakeAccountName, resourceGroupLocation);
87+
this.TryCreateDataLakeStoreAccount(this.resourceGroupName, this.dataLakeStoreAccountName, resourceGroupLocation);
88+
this.TryCreateDataLakeStoreAccount(this.resourceGroupName, this.secondDataLakeStoreAccountName, resourceGroupLocation);
89+
string storageSuffix;
90+
this.azureBlobStoreAccessKey = this.TryCreateStorageAccount(this.resourceGroupName, this.azureBlobStoreName,
91+
"DataLakeAnalyticsTestStorage", "DataLakeAnalyticsTestStorageDescription", resourceGroupLocation,
92+
out storageSuffix);
8093
helper.SetupEnvironment(AzureModule.AzureResourceManager);
8194
helper.SetupModules(AzureModule.AzureResourceManager, "ScenarioTests\\" + this.GetType().Name + ".ps1",
8295
helper.RMProfileModule, helper.GetRMModulePath(@"AzureRM.DataLakeAnalytics.psd1"));
8396

97+
// inject the access key into the script if necessary.
98+
for (int i =0; i < scripts.Length; i++)
99+
{
100+
if (scripts[i].Contains("-blobAccountKey"))
101+
{
102+
scripts[i] = scripts[i].Replace("-blobAccountKey",
103+
string.Format("-blobAccountKey '{0}'", this.azureBlobStoreAccessKey));
104+
}
105+
}
106+
84107
helper.RunPowerShellTest(scripts);
85108
}
86109
}
@@ -106,6 +129,11 @@ protected DataLakeStoreManagementClient GetDataLakeStoreManagementClient()
106129
return TestBase.GetServiceClient<DataLakeStoreManagementClient>(new CSMTestEnvironmentFactory());
107130
}
108131

132+
protected StorageManagementClient GetStorageManagementClient()
133+
{
134+
return TestBase.GetServiceClient<StorageManagementClient>(new CSMTestEnvironmentFactory());
135+
}
136+
109137
protected ResourceManagementClient GetResourceManagementClient()
110138
{
111139
return TestBase.GetServiceClient<ResourceManagementClient>(new CSMTestEnvironmentFactory());
@@ -185,6 +213,31 @@ private string TryCreateDataLakeStoreAccount(string resourceGroupName, string da
185213

186214
}
187215

216+
public string TryCreateStorageAccount(string resourceGroupName, string storageAccountName, string label, string description, string location, out string storageAccountSuffix)
217+
{
218+
var stoInput = new StorageAccountCreateParameters
219+
{
220+
Location = location,
221+
AccountType = AccountType.StandardGRS
222+
};
223+
224+
225+
// retrieve the storage account
226+
storageManagementClient.StorageAccounts.Create(resourceGroupName, storageAccountName, stoInput);
227+
228+
// retrieve the storage account primary access key
229+
var accessKey = storageManagementClient.StorageAccounts.ListKeys(resourceGroupName, storageAccountName).StorageAccountKeys.Key1;
230+
ThrowIfTrue(string.IsNullOrEmpty(accessKey), "storageManagementClient.StorageAccounts.ListKeys returned null.");
231+
232+
// set the storage account suffix
233+
var getResponse = storageManagementClient.StorageAccounts.GetProperties(resourceGroupName, storageAccountName);
234+
storageAccountSuffix = getResponse.StorageAccount.PrimaryEndpoints.Blob.ToString();
235+
storageAccountSuffix = storageAccountSuffix.Replace("https://", "").TrimEnd('/');
236+
storageAccountSuffix = storageAccountSuffix.Replace(storageAccountName, "").TrimStart('.');
237+
238+
return accessKey;
239+
}
240+
188241
private void ThrowIfTrue(bool condition, string message)
189242
{
190243
if (condition)

0 commit comments

Comments
 (0)