Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ 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;
private static string location = null;
private static string defaultStorageName = null;
private static string currentTestEnvironment = null;
private static CloudBlobContainer blobContainer;
private const string VhdFilesContainerName = "vhdfiles";

private static Dictionary<string, string> environment = new Dictionary<string, string>();
public static Dictionary<string, string> PowerShellVariables { get; private set; }
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
};

/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!");
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public DeploymentInfoContext(DeploymentGetResponse deployment)

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

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)
{
Expand Down