Skip to content

Commit dbaa515

Browse files
author
Hovsep
committed
Merge pull request #22 from AzureRT/dev
AzureRT PR S42 #1 - Fix a potential error in Get-AzureDeployment
2 parents 60b964d + a277131 commit dbaa515

File tree

4 files changed

+32
-75
lines changed

4 files changed

+32
-75
lines changed

src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/CredentialHelper.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ public static class CredentialHelper
3434
private static string DefaultStorageAccountVariable = "AZURERT_DEFAULT_STORAGE_ACCOUNT";
3535
private static string DefaultLocationVariable = "AZURERT_DEFAULT_LOCATION";
3636
private static string CredentialBlobUriFormat = "https://{0}.blob.core.windows.net";
37-
//private static string CredentialImportFormat = "Import-AzurePublishSettingsFile '{0}'";
3837

3938
private static string publishSettingsFile = null;
4039
private static string defaultSubscriptionName = null;
4140
private static string location = null;
4241
private static string defaultStorageName = null;
4342
private static string currentTestEnvironment = null;
4443
private static CloudBlobContainer blobContainer;
44+
private const string VhdFilesContainerName = "vhdfiles";
4545

4646
private static Dictionary<string, string> environment = new Dictionary<string, string>();
4747
public static Dictionary<string, string> PowerShellVariables { get; private set; }
@@ -59,10 +59,15 @@ public static void GetCredentialInfo(string downloadDirectoryPath)
5959
Assert.IsTrue(environment.ContainsKey(StorageAccountKeyVariable),
6060
string.Format("You must define a storage account key for credential download using environment variable {0}", StorageAccountKeyVariable));
6161
string storageAccountKey = environment[StorageAccountKeyVariable];
62+
6263
DownloadTestCredentials(currentTestEnvironment, downloadDirectoryPath,
6364
string.Format(CredentialBlobUriFormat, storageAccount),
6465
storageAccount, storageAccountKey);
6566

67+
DownloadTestVhdsAndPackages(currentTestEnvironment, downloadDirectoryPath,
68+
string.Format(CredentialBlobUriFormat, storageAccount),
69+
storageAccount, storageAccountKey);
70+
6671
if (environment.ContainsKey(DefaultStorageAccountVariable))
6772
{
6873
string.Format("Default storage account name define is {0}", DefaultStorageAccountVariable);
@@ -96,6 +101,22 @@ private static void DownloadTestCredentials(string testEnvironment, string downl
96101
}
97102
}
98103

104+
private static void DownloadTestVhdsAndPackages(string testEnvironment, string downloadDirectoryPath, string blobUri, string storageAccount, string storageKey)
105+
{
106+
StorageCredentials credentials = new StorageCredentials(storageAccount, storageKey);
107+
CloudBlobClient blobClient = new CloudBlobClient(new Uri(blobUri), credentials);
108+
blobContainer = blobClient.GetContainerReference(VhdFilesContainerName);
109+
foreach (IListBlobItem blobItem in blobContainer.ListBlobs())
110+
{
111+
ICloudBlob blob = blobClient.GetBlobReferenceFromServer(blobItem.Uri);
112+
Console.WriteLine("Downloading file {0} from blob Uri {1}", blob.Name, blob.Uri);
113+
FileStream blobStream = new FileStream(Path.Combine(downloadDirectoryPath, blob.Name), FileMode.Create);
114+
blob.DownloadToStream(blobStream);
115+
blobStream.Flush();
116+
blobStream.Close();
117+
}
118+
}
119+
99120
public static void GetTestSettings(string testSettings)
100121
{
101122
switch (testSettings)

src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ScenarioTest.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,15 @@ public void ProvisionLinuxVM()
225225

226226
try
227227
{
228-
vmPowershellCmdlets.NewAzureQuickVM(OS.Linux, newAzureLinuxVMName, serviceName, linuxImageName, "user",
229-
password, locationName);
228+
Utilities.RetryActionUntilSuccess(() =>
229+
{
230+
if (vmPowershellCmdlets.TestAzureServiceName(serviceName))
231+
{
232+
var op = vmPowershellCmdlets.RemoveAzureService(serviceName);
233+
}
234+
235+
vmPowershellCmdlets.NewAzureQuickVM(OS.Linux, newAzureLinuxVMName, serviceName, linuxImageName, "user", password, locationName);
236+
}, "Windows Azure is currently performing an operation on this hosted service that requires exclusive access.", 10, 30);
230237

231238
// Verify
232239
PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureLinuxVMName, serviceName);

src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementTest.cs

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ public class ServiceManagementTest
6969

7070
private TestContext testContextInstance;
7171

72-
private const string VhdFilesContainerName = "vhdfiles";
73-
private static readonly string[] VhdFiles = new[]
74-
{
75-
"dynamic_50.vhd", "dynamic_50_child01.vhd", "dynamic_50_child02.vhd",
76-
"fixed_50.vhd", "fixed_50_child01.vhd", "fixed_50_child02.vhd"
77-
};
78-
7972
/// <summary>
8073
///Gets or sets the test context which provides
8174
///information about and functionality for the current test run.
@@ -202,26 +195,6 @@ private static string GetDefaultStorage(string storageName, string locName)
202195
return null;
203196
}
204197

205-
private static string GetSubscriptionName(string publishSettingsFile)
206-
{
207-
try
208-
{
209-
XDocument psf = XDocument.Load(publishSettingsFile);
210-
XElement pubData = psf.Descendants().FirstOrDefault();
211-
XElement pubProfile = pubData.Elements().ToList()[0];
212-
XElement sub = pubProfile.Elements().ToList()[0];
213-
string subName = sub.Attribute("Name").Value;
214-
Console.WriteLine("Getting subscription: {0}", subName);
215-
216-
return subName;
217-
}
218-
catch
219-
{
220-
Console.WriteLine("Error occurred during loading publish settings file...");
221-
return null;
222-
}
223-
}
224-
225198
private static string GetServiceManagementUrl(string publishSettingsFile)
226199
{
227200
try
@@ -346,15 +319,6 @@ public static void SetTestSettings()
346319
Console.WriteLine("Error occurred during Get-AzureVMImageName... imageName is not set.");
347320
}
348321

349-
try
350-
{
351-
DownloadVhds();
352-
}
353-
catch
354-
{
355-
Console.WriteLine("Error occurred during downloading vhds...");
356-
}
357-
358322
if (String.IsNullOrEmpty(imageName))
359323
{
360324
Console.WriteLine("No image is selected!");
@@ -414,41 +378,6 @@ protected static void CleanupService(string svcName)
414378
Utilities.TryAndIgnore(() => vmPowershellCmdlets.RemoveAzureService(svcName, true), "does not exist");
415379
}
416380

417-
protected static void DownloadVhds()
418-
{
419-
storageAccountKey = vmPowershellCmdlets.GetAzureStorageAccountKey(defaultAzureSubscription.CurrentStorageAccountName);
420-
421-
foreach (var vhdFile in VhdFiles)
422-
{
423-
string vhdBlobLocation = string.Format("{0}{1}/{2}", blobUrlRoot, VhdFilesContainerName, vhdFile);
424-
425-
var vhdLocalPath = new FileInfo(Directory.GetCurrentDirectory() + "\\" + vhdFile);
426-
427-
if (!File.Exists(vhdLocalPath.FullName))
428-
{
429-
// Set the source blob
430-
BlobHandle blobHandle = Utilities.GetBlobHandle(vhdBlobLocation, storageAccountKey.Primary);
431-
432-
SaveVhd(blobHandle, vhdLocalPath, storageAccountKey.Primary);
433-
}
434-
}
435-
}
436-
437-
protected static void SaveVhd(BlobHandle destination, FileInfo locFile, string storageKey, int? numThread = null, bool overwrite = false)
438-
{
439-
try
440-
{
441-
Console.WriteLine("Downloading a VHD from {0} to {1}...", destination.Blob.Uri.ToString(), locFile.FullName);
442-
DateTime startTime = DateTime.Now;
443-
vmPowershellCmdlets.SaveAzureVhd(destination.Blob.Uri, locFile, numThread, storageKey, overwrite);
444-
Console.WriteLine("Downloading completed in {0} seconds.", (DateTime.Now - startTime).TotalSeconds);
445-
}
446-
catch (Exception e)
447-
{
448-
Assert.Fail(e.InnerException.ToString());
449-
}
450-
}
451-
452381
protected void VerifyRDP(string serviceName, string rdpPath)
453382
{
454383
Utilities.GetDeploymentAndWaitForReady(serviceName, DeploymentSlotType.Production, 10, 600);

src/ServiceManagement/Compute/Commands.ServiceManagement/Model/DeploymentInfoContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public DeploymentInfoContext(DeploymentGetResponse deployment)
255255

256256
this.RolesConfiguration = new Dictionary<string, RoleConfiguration>();
257257

258-
var roles = doc.Root.Descendants(this.ns + "Role");
258+
var roles = doc.Root.Descendants(this.ns + "Role").Where(t => t.Parent == doc.Root);
259259

260260
foreach (var role in roles)
261261
{

0 commit comments

Comments
 (0)