diff --git a/e2etest/GuestProxyAgentTest/GuestProxyAgentTest.csproj b/e2etest/GuestProxyAgentTest/GuestProxyAgentTest.csproj index f611178d..1e27c879 100644 --- a/e2etest/GuestProxyAgentTest/GuestProxyAgentTest.csproj +++ b/e2etest/GuestProxyAgentTest/GuestProxyAgentTest.csproj @@ -19,7 +19,6 @@ - diff --git a/e2etest/GuestProxyAgentTest/Utilities/ResourceNamer.cs b/e2etest/GuestProxyAgentTest/Utilities/ResourceNamer.cs new file mode 100644 index 00000000..3f086630 --- /dev/null +++ b/e2etest/GuestProxyAgentTest/Utilities/ResourceNamer.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation +// SPDX-License-Identifier: MIT +namespace GuestProxyAgentTest.Utilities +{ + public class ResourceNamer + { + private readonly string randName; + + private static string[] formats = new string[1] { "M/d/yyyy h:mm:ss tt" }; + + private static Random random = new Random(); + + public ResourceNamer(string name) + { + lock (random) + { + randName = name.ToLower() + Guid.NewGuid().ToString("N").Substring(0, 3) + .ToLower(); + } + } + + public virtual string RandomName(string prefix, int maxLen) + { + lock (random) + { + prefix = prefix.ToLower(); + int num = 5; + string text = random.Next(0, 100000).ToString("D5"); + if (maxLen < prefix.Length + randName.Length + num) + { + string text2 = prefix + text; + return text2 + RandomString((maxLen - text2.Length) / 2); + } + + string text3 = prefix + randName + text; + return text3 + RandomString((maxLen - text3.Length) / 2); + } + } + + private string RandomString(int length) + { + string text = ""; + while (text.Length < length) + { + text += Guid.NewGuid().ToString("N").Substring(0, Math.Min(32, length)) + .ToLower(); + } + + return text; + } + + public string RandomGuid() + { + return Guid.NewGuid().ToString(); + } + } +} diff --git a/e2etest/GuestProxyAgentTest/Utilities/VMBuilder.cs b/e2etest/GuestProxyAgentTest/Utilities/VMBuilder.cs index f8328367..727c5d85 100644 --- a/e2etest/GuestProxyAgentTest/Utilities/VMBuilder.cs +++ b/e2etest/GuestProxyAgentTest/Utilities/VMBuilder.cs @@ -8,7 +8,6 @@ using Azure.ResourceManager.Network; using Azure.ResourceManager.Resources; using GuestProxyAgentTest.Settings; -using Microsoft.Azure.Management.ResourceManager.Fluent; namespace GuestProxyAgentTest.Utilities { @@ -24,7 +23,7 @@ class VMBuilder private string pubIpName = ""; private string rgName = ""; private string adminUsername = "testuser"; - private string adminPassword = SdkContext.RandomResourceName("pP@1", 15); + private string adminPassword = new ResourceNamer("").RandomName("pP@1", 15); // In order to use the plan, we need to accept the terms first. // https://learn.microsoft.com/en-us/cli/azure/vm/image/terms?view=azure-cli-latest#az-vm-image-terms-accept