diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/CredentialHelper.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/CredentialHelper.cs index df9d65c4deb1..579a68ccb504 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/CredentialHelper.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/CredentialHelper.cs @@ -34,7 +34,6 @@ public static class CredentialHelper private static string DefaultStorageAccountVariable = "AZURERT_DEFAULT_STORAGE_ACCOUNT"; private static string DefaultLocationVariable = "AZURERT_DEFAULT_LOCATION"; private static string CredentialBlobUriFormat = "https://{0}.blob.core.windows.net"; - //private static string CredentialImportFormat = "Import-AzurePublishSettingsFile '{0}'"; private static string publishSettingsFile = null; private static string defaultSubscriptionName = null; @@ -42,6 +41,7 @@ public static class CredentialHelper private static string defaultStorageName = null; private static string currentTestEnvironment = null; private static CloudBlobContainer blobContainer; + private const string VhdFilesContainerName = "vhdfiles"; private static Dictionary environment = new Dictionary(); public static Dictionary PowerShellVariables { get; private set; } @@ -59,10 +59,15 @@ public static void GetCredentialInfo(string downloadDirectoryPath) Assert.IsTrue(environment.ContainsKey(StorageAccountKeyVariable), string.Format("You must define a storage account key for credential download using environment variable {0}", StorageAccountKeyVariable)); string storageAccountKey = environment[StorageAccountKeyVariable]; + DownloadTestCredentials(currentTestEnvironment, downloadDirectoryPath, string.Format(CredentialBlobUriFormat, storageAccount), storageAccount, storageAccountKey); + DownloadTestVhdsAndPackages(currentTestEnvironment, downloadDirectoryPath, + string.Format(CredentialBlobUriFormat, storageAccount), + storageAccount, storageAccountKey); + if (environment.ContainsKey(DefaultStorageAccountVariable)) { string.Format("Default storage account name define is {0}", DefaultStorageAccountVariable); @@ -96,6 +101,22 @@ private static void DownloadTestCredentials(string testEnvironment, string downl } } + private static void DownloadTestVhdsAndPackages(string testEnvironment, string downloadDirectoryPath, string blobUri, string storageAccount, string storageKey) + { + StorageCredentials credentials = new StorageCredentials(storageAccount, storageKey); + CloudBlobClient blobClient = new CloudBlobClient(new Uri(blobUri), credentials); + blobContainer = blobClient.GetContainerReference(VhdFilesContainerName); + foreach (IListBlobItem blobItem in blobContainer.ListBlobs()) + { + ICloudBlob blob = blobClient.GetBlobReferenceFromServer(blobItem.Uri); + Console.WriteLine("Downloading file {0} from blob Uri {1}", blob.Name, blob.Uri); + FileStream blobStream = new FileStream(Path.Combine(downloadDirectoryPath, blob.Name), FileMode.Create); + blob.DownloadToStream(blobStream); + blobStream.Flush(); + blobStream.Close(); + } + } + public static void GetTestSettings(string testSettings) { switch (testSettings) diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ScenarioTest.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ScenarioTest.cs index a3f0998cc7c5..f1ba137d59dd 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ScenarioTest.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ScenarioTest.cs @@ -225,8 +225,15 @@ public void ProvisionLinuxVM() try { - vmPowershellCmdlets.NewAzureQuickVM(OS.Linux, newAzureLinuxVMName, serviceName, linuxImageName, "user", - password, locationName); + Utilities.RetryActionUntilSuccess(() => + { + if (vmPowershellCmdlets.TestAzureServiceName(serviceName)) + { + var op = vmPowershellCmdlets.RemoveAzureService(serviceName); + } + + vmPowershellCmdlets.NewAzureQuickVM(OS.Linux, newAzureLinuxVMName, serviceName, linuxImageName, "user", password, locationName); + }, "Windows Azure is currently performing an operation on this hosted service that requires exclusive access.", 10, 30); // Verify PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureLinuxVMName, serviceName); diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementTest.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementTest.cs index a932994c8c42..ef084d8d9fac 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementTest.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementTest.cs @@ -69,13 +69,6 @@ public class ServiceManagementTest private TestContext testContextInstance; - private const string VhdFilesContainerName = "vhdfiles"; - private static readonly string[] VhdFiles = new[] - { - "dynamic_50.vhd", "dynamic_50_child01.vhd", "dynamic_50_child02.vhd", - "fixed_50.vhd", "fixed_50_child01.vhd", "fixed_50_child02.vhd" - }; - /// ///Gets or sets the test context which provides ///information about and functionality for the current test run. @@ -202,26 +195,6 @@ private static string GetDefaultStorage(string storageName, string locName) return null; } - private static string GetSubscriptionName(string publishSettingsFile) - { - try - { - XDocument psf = XDocument.Load(publishSettingsFile); - XElement pubData = psf.Descendants().FirstOrDefault(); - XElement pubProfile = pubData.Elements().ToList()[0]; - XElement sub = pubProfile.Elements().ToList()[0]; - string subName = sub.Attribute("Name").Value; - Console.WriteLine("Getting subscription: {0}", subName); - - return subName; - } - catch - { - Console.WriteLine("Error occurred during loading publish settings file..."); - return null; - } - } - private static string GetServiceManagementUrl(string publishSettingsFile) { try @@ -346,15 +319,6 @@ public static void SetTestSettings() Console.WriteLine("Error occurred during Get-AzureVMImageName... imageName is not set."); } - try - { - DownloadVhds(); - } - catch - { - Console.WriteLine("Error occurred during downloading vhds..."); - } - if (String.IsNullOrEmpty(imageName)) { Console.WriteLine("No image is selected!"); @@ -414,41 +378,6 @@ protected static void CleanupService(string svcName) Utilities.TryAndIgnore(() => vmPowershellCmdlets.RemoveAzureService(svcName, true), "does not exist"); } - protected static void DownloadVhds() - { - storageAccountKey = vmPowershellCmdlets.GetAzureStorageAccountKey(defaultAzureSubscription.CurrentStorageAccountName); - - foreach (var vhdFile in VhdFiles) - { - string vhdBlobLocation = string.Format("{0}{1}/{2}", blobUrlRoot, VhdFilesContainerName, vhdFile); - - var vhdLocalPath = new FileInfo(Directory.GetCurrentDirectory() + "\\" + vhdFile); - - if (!File.Exists(vhdLocalPath.FullName)) - { - // Set the source blob - BlobHandle blobHandle = Utilities.GetBlobHandle(vhdBlobLocation, storageAccountKey.Primary); - - SaveVhd(blobHandle, vhdLocalPath, storageAccountKey.Primary); - } - } - } - - protected static void SaveVhd(BlobHandle destination, FileInfo locFile, string storageKey, int? numThread = null, bool overwrite = false) - { - try - { - Console.WriteLine("Downloading a VHD from {0} to {1}...", destination.Blob.Uri.ToString(), locFile.FullName); - DateTime startTime = DateTime.Now; - vmPowershellCmdlets.SaveAzureVhd(destination.Blob.Uri, locFile, numThread, storageKey, overwrite); - Console.WriteLine("Downloading completed in {0} seconds.", (DateTime.Now - startTime).TotalSeconds); - } - catch (Exception e) - { - Assert.Fail(e.InnerException.ToString()); - } - } - protected void VerifyRDP(string serviceName, string rdpPath) { Utilities.GetDeploymentAndWaitForReady(serviceName, DeploymentSlotType.Production, 10, 600); diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/Model/DeploymentInfoContext.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/Model/DeploymentInfoContext.cs index c60093f3ac7d..3c051acbf4dc 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/Model/DeploymentInfoContext.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/Model/DeploymentInfoContext.cs @@ -255,7 +255,7 @@ public DeploymentInfoContext(DeploymentGetResponse deployment) this.RolesConfiguration = new Dictionary(); - var roles = doc.Root.Descendants(this.ns + "Role"); + var roles = doc.Root.Descendants(this.ns + "Role").Where(t => t.Parent == doc.Root); foreach (var role in roles) {