PageRenderTime 4ms CodeModel.GetById 4ms app.highlight 55ms RepoModel.GetById 1ms app.codeStats 1ms

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

https://github.com/IrisClasson/azure-sdk-tools
C# | 1508 lines | 1107 code | 277 blank | 124 comment | 55 complexity | 97562440cf961ae994e5546beabe2f4f MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1// ----------------------------------------------------------------------------------
  2//
  3// Copyright Microsoft Corporation
  4// Licensed under the Apache License, Version 2.0 (the "License");
  5// you may not use this file except in compliance with the License.
  6// You may obtain a copy of the License at
  7// http://www.apache.org/licenses/LICENSE-2.0
  8// Unless required by applicable law or agreed to in writing, software
  9// distributed under the License is distributed on an "AS IS" BASIS,
 10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11// See the License for the specific language governing permissions and
 12// limitations under the License.
 13// ----------------------------------------------------------------------------------
 14
 15
 16namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests
 17{
 18    using ConfigDataInfo;
 19    using Extensions;
 20    using Model;
 21    using Properties;
 22    using Service.Gateway;
 23    using System;
 24    using System.Collections.Generic;
 25    using System.Collections.ObjectModel;
 26    using System.IO;
 27    using System.Management.Automation;
 28    using System.Net;
 29    using System.Net.Cache;
 30    using System.Reflection;
 31    using System.Text;
 32    using System.Threading;
 33    using System.Xml;
 34    using System.Xml.Linq;
 35    using VisualStudio.TestTools.UnitTesting;
 36    using WindowsAzure.ServiceManagement;
 37    
 38    using System.Security.Cryptography.X509Certificates;
 39    using System.Linq;
 40    using Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.PersistentVMs;
 41
 42
 43
 44
 45    [TestClass]
 46    public class ScenarioTest : ServiceManagementTest
 47    {
 48        private const string ReadyState = "ReadyRole";
 49        private string serviceName;
 50
 51        string perfFile;
 52
 53        [TestInitialize]
 54        public void Initialize()
 55        {
 56            serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
 57
 58            pass = false;
 59            testStartTime = DateTime.Now;
 60        }
 61
 62        /// <summary>
 63        /// </summary>
 64        [TestMethod(), TestCategory("Scenario"), TestCategory("BVT"), TestProperty("Feature", "IaaS"), Priority(1), Owner("priya"), Description("Test the cmdlets (New-AzureQuickVM,Get-AzureVMImage,Get-AzureVM,Get-AzureLocation,Import-AzurePublishSettingsFile,Get-AzureSubscription,Set-AzureSubscription)")]
 65        public void NewWindowsAzureQuickVM()
 66        {
 67            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
 68            string newAzureQuickVMName1 = Utilities.GetUniqueShortName(vmNamePrefix);
 69            string newAzureQuickVMName2 = Utilities.GetUniqueShortName(vmNamePrefix);
 70
 71            try
 72            {
 73                if (string.IsNullOrEmpty(imageName))
 74                    imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
 75
 76                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName1, serviceName, imageName, username, password, locationName);
 77                // Verify
 78                Assert.AreEqual(newAzureQuickVMName1, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName1, serviceName).Name, true);
 79
 80                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName2, serviceName, imageName, username, password);
 81                // Verify
 82                Assert.AreEqual(newAzureQuickVMName2, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName2, serviceName).Name, true);
 83
 84                try
 85                {
 86                    vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName1 + "wrongVMName", serviceName);
 87                    Assert.Fail("Should Fail!!");
 88                }
 89                catch (Exception e)
 90                {
 91                    Console.WriteLine("Fail as expected: {0}", e.ToString());
 92                }
 93
 94
 95
 96                // Cleanup 
 97                vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName1, serviceName);
 98                Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName1, serviceName));
 99                Assert.AreEqual(newAzureQuickVMName2, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName2, serviceName).Name, true);
100                vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName2, serviceName);
101                Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName2, serviceName));
102
103                //Remove the service after removing the VM above
104                vmPowershellCmdlets.RemoveAzureService(serviceName);
105
106                //DisableWinRMHttps Test Case
107
108                try
109                {
110                    vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName2, serviceName, imageName, username, password, locationName, null, "");                    
111                    pass = true;
112
113                }
114                catch (Exception e)
115                {
116                    pass = false;
117                    if (e is AssertFailedException)
118                    {
119                        throw;
120                    }
121
122                }
123                finally
124                {
125                    if (pass == true) pass = true;
126                    vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName2, serviceName);
127                    Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName2, serviceName));
128                }
129
130                //End DisableWinRMHttps Test Case
131
132                // Negative Test Case--It should Fail
133
134                try
135                {
136                    vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName1, serviceName, imageName, username, password, locationName);
137                    Assert.Fail("Should have failed, but succeeded!!");
138                    pass = true;
139                }
140                catch (Exception e)
141                {
142                    if (e is AssertFailedException)
143                    {
144                        throw;
145                    }
146                    Console.WriteLine("This exception is expected.");
147                    pass = true;
148                }
149                // End of Negative Test Case -- It should Fail]
150
151
152            }
153            catch (Exception e)
154            {
155                Console.WriteLine(e);
156                throw;
157            }
158        }
159
160        /// <summary>
161        /// Get-AzureWinRMUri
162        /// </summary>
163        [TestMethod(), TestCategory("Scenario"), TestCategory("BVT"), TestProperty("Feature", "IaaS"), Priority(1), Owner("v-rakonj"), Description("Test the cmdlets (Get-AzureWinRMUri)")]
164        public void GetAzureWinRMUri()
165        {
166            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
167            try
168            {
169                string newAzureQuickVMName = Utilities.GetUniqueShortName(vmNamePrefix);
170                if (string.IsNullOrEmpty(imageName))
171                    imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
172
173                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName);
174
175                // Verify the VM
176                var vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName);
177                Assert.AreEqual(newAzureQuickVMName, vmRoleCtxt.Name, true, "VM names are not matched!");
178
179                // Get the WinRM Uri
180                var resultUri = vmPowershellCmdlets.GetAzureWinRMUri(serviceName, vmRoleCtxt.Name);
181
182                // starting the test.
183                InputEndpointContext winRMEndpoint = null;
184
185                foreach (InputEndpointContext inputEndpointCtxt in vmPowershellCmdlets.GetAzureEndPoint(vmRoleCtxt))
186                {
187                    if (inputEndpointCtxt.Name.Equals("WinRmHTTPs"))
188                    {
189                        winRMEndpoint = inputEndpointCtxt;
190                    }
191                }
192
193                Assert.IsNotNull(winRMEndpoint, "There is no WinRM endpoint!");
194                Assert.IsNotNull(resultUri, "No WinRM Uri!");
195
196                Console.WriteLine("InputEndpointContext Name: {0}", winRMEndpoint.Name);
197                Console.WriteLine("InputEndpointContext port: {0}", winRMEndpoint.Port);
198                Console.WriteLine("InputEndpointContext protocol: {0}", winRMEndpoint.Protocol);
199
200                Console.WriteLine("WinRM Uri: {0}", resultUri.AbsoluteUri);
201                Console.WriteLine("WinRM Port: {0}", resultUri.Port);
202                Console.WriteLine("WinRM Scheme: {0}", resultUri.Scheme);
203
204                Assert.AreEqual(winRMEndpoint.Port, resultUri.Port, "Port numbers are not matched!");
205
206                pass = true;
207            }
208            catch (Exception e)
209            {
210                Console.WriteLine(e);
211                throw;
212            }
213        }
214
215
216        /// <summary>
217        /// Basic Provisioning a Virtual Machine
218        /// </summary>
219        [TestMethod(), TestCategory("Scenario"), TestCategory("BVT"), TestProperty("Feature", "IaaS"), Priority(1), Owner("priya"), Description("Test the cmdlets (Get-AzureLocation,Test-AzureName ,Get-AzureVMImage,New-AzureQuickVM,Get-AzureVM ,Restart-AzureVM,Stop-AzureVM , Start-AzureVM)")]
220        public void ProvisionLinuxVM()
221        {
222            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
223
224            string newAzureLinuxVMName = Utilities.GetUniqueShortName("PSLinuxVM");
225            string linuxImageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Linux" }, false);
226
227            try
228            {
229                vmPowershellCmdlets.NewAzureQuickVM(OS.Linux, newAzureLinuxVMName, serviceName, linuxImageName, "user",
230                                                    password, locationName);
231
232                // Verify
233                PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureLinuxVMName, serviceName);
234                Assert.AreEqual(newAzureLinuxVMName, vmRoleCtxt.Name, true);
235                try
236                {
237                    vmPowershellCmdlets.RemoveAzureVM(newAzureLinuxVMName + "wrongVMName", serviceName);
238                    Assert.Fail("Should Fail!!");
239                }
240                catch (Exception e)
241                {
242                    if (e is AssertFailedException)
243                    {
244                        throw;
245                    }
246                    Console.WriteLine("Fail as expected: {0}", e);
247                }
248
249                // Cleanup
250                vmPowershellCmdlets.RemoveAzureVM(newAzureLinuxVMName, serviceName);
251                Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureLinuxVMName, serviceName));
252                pass = true;
253            }
254            catch (Exception e)
255            {
256                Console.WriteLine(e.ToString());
257                throw;
258            }
259        }
260
261        /// <summary>
262        /// Verify Advanced Provisioning for the Dev/Test Scenario
263        /// Make an Service
264        /// Make a VM
265        /// Add 4 additonal endpoints
266        /// Makes a storage account
267        /// </summary>
268        [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("msampson"), Description("Test the cmdlets (Get-AzureDeployment, New-AzureVMConfig, Add-AzureProvisioningConfig, Add-AzureEndpoint, New-AzureVM, New-AzureStorageAccount)")]
269        public void DevTestProvisioning()
270        {
271            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
272
273            string newAzureVM1Name = Utilities.GetUniqueShortName(vmNamePrefix);
274            //Find a Windows VM Image
275            imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
276            
277            //Specify a small Windows image, with username and pw
278            AzureVMConfigInfo azureVMConfigInfo1 = new AzureVMConfigInfo(newAzureVM1Name, InstanceSize.ExtraSmall.ToString(), imageName);
279            AzureProvisioningConfigInfo azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password);
280            AzureEndPointConfigInfo azureEndPointConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.NoLB, ProtocolInfo.tcp, 80, 80, "Http");
281
282            PersistentVMConfigInfo persistentVMConfigInfo1 = new PersistentVMConfigInfo(azureVMConfigInfo1, azureProvisioningConfig, null, azureEndPointConfigInfo);
283            PersistentVM persistentVM1 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo1);
284
285            //Add all the endpoints that are added by the Dev Test feature in Azure Tools
286            azureEndPointConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.NoLB, ProtocolInfo.tcp, 443, 443, "Https");
287            azureEndPointConfigInfo.Vm = persistentVM1;
288            persistentVM1 = vmPowershellCmdlets.AddAzureEndPoint(azureEndPointConfigInfo);
289            azureEndPointConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.NoLB, ProtocolInfo.tcp, 1433, 1433, "MSSQL");
290            azureEndPointConfigInfo.Vm = persistentVM1;
291            persistentVM1 = vmPowershellCmdlets.AddAzureEndPoint(azureEndPointConfigInfo);
292            azureEndPointConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.NoLB, ProtocolInfo.tcp, 8172, 8172, "WebDeploy");
293            azureEndPointConfigInfo.Vm = persistentVM1;
294            persistentVM1 = vmPowershellCmdlets.AddAzureEndPoint(azureEndPointConfigInfo);
295
296            // Make a storage account named "devtestNNNNN"
297            string storageAcctName = "devtest" + new Random().Next(10000, 99999);
298            vmPowershellCmdlets.NewAzureStorageAccount(storageAcctName, locationName);
299
300            // When making a new azure VM, you can't specify a location if you want to use the existing service
301            PersistentVM[] VMs = { persistentVM1 };
302            vmPowershellCmdlets.NewAzureVM(serviceName, VMs, locationName);
303
304            var svcDeployment = vmPowershellCmdlets.GetAzureDeployment(serviceName);
305            Assert.AreEqual(svcDeployment.ServiceName, serviceName);
306            var vmDeployment = vmPowershellCmdlets.GetAzureVM(newAzureVM1Name, serviceName);
307            Assert.AreEqual(vmDeployment.InstanceName, newAzureVM1Name);
308
309            // Cleanup
310            vmPowershellCmdlets.RemoveAzureVM(newAzureVM1Name, serviceName);
311            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM1Name, serviceName));
312            Utilities.RetryActionUntilSuccess(() => vmPowershellCmdlets.RemoveAzureStorageAccount(storageAcctName), "in use", 10, 30);
313            pass = true;
314        }
315
316        /// <summary>
317        /// Verify Advanced Provisioning
318        /// </summary>
319        [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("priya"), Description("Test the cmdlets (New-AzureService,New-AzureVMConfig,Add-AzureProvisioningConfig ,Add-AzureDataDisk ,Add-AzureEndpoint,New-AzureVM)")]
320        public void AdvancedProvisioning()
321        {
322            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
323
324            string newAzureVM1Name = Utilities.GetUniqueShortName(vmNamePrefix);
325            string newAzureVM2Name = Utilities.GetUniqueShortName(vmNamePrefix);
326            if (string.IsNullOrEmpty(imageName))
327            {
328                imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
329            }
330
331            vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
332
333            var azureVMConfigInfo1 = new AzureVMConfigInfo(newAzureVM1Name, InstanceSize.ExtraSmall.ToString(), imageName);
334            var azureVMConfigInfo2 = new AzureVMConfigInfo(newAzureVM2Name, InstanceSize.ExtraSmall.ToString(), imageName);
335            var azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password);
336            var azureDataDiskConfigInfo = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk1", 0);
337            var azureEndPointConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.CustomProbe, ProtocolInfo.tcp, 80, 80, "web", "lbweb", 80, ProtocolInfo.http, @"/", null, null);
338
339            var persistentVMConfigInfo1 = new PersistentVMConfigInfo(azureVMConfigInfo1, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo);
340            var persistentVMConfigInfo2 = new PersistentVMConfigInfo(azureVMConfigInfo2, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo);
341
342            PersistentVM persistentVM1 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo1);
343            PersistentVM persistentVM2 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo2);
344
345            PersistentVM[] VMs = { persistentVM1, persistentVM2 };
346            vmPowershellCmdlets.NewAzureVM(serviceName, VMs);
347
348            // Cleanup
349            vmPowershellCmdlets.RemoveAzureVM(newAzureVM1Name, serviceName);
350            vmPowershellCmdlets.RemoveAzureVM(newAzureVM2Name, serviceName);
351
352            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM1Name, serviceName));
353            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM2Name, serviceName));
354            pass = true;
355        }
356
357        /// <summary>
358        /// Modifying Existing Virtual Machines
359        /// </summary>
360        [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("priya"), Description("Test the cmdlets (New-AzureVMConfig,Add-AzureProvisioningConfig ,Add-AzureDataDisk ,Add-AzureEndpoint,New-AzureVM)")]
361        public void ModifyingVM()
362        {
363            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
364
365            string newAzureQuickVMName = Utilities.GetUniqueShortName(vmNamePrefix);
366            if (string.IsNullOrEmpty(imageName))
367                imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
368
369            vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName);
370
371            AddAzureDataDiskConfig azureDataDiskConfigInfo1 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk1", 0);
372            AddAzureDataDiskConfig azureDataDiskConfigInfo2 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk2", 1);
373            AzureEndPointConfigInfo azureEndPointConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.NoLB, ProtocolInfo.tcp, 1433, 2000, "sql");
374            AddAzureDataDiskConfig[] dataDiskConfig = { azureDataDiskConfigInfo1, azureDataDiskConfigInfo2 };
375            vmPowershellCmdlets.AddVMDataDisksAndEndPoint(newAzureQuickVMName, serviceName, dataDiskConfig, azureEndPointConfigInfo);
376
377            SetAzureDataDiskConfig setAzureDataDiskConfig1 = new SetAzureDataDiskConfig(HostCaching.ReadWrite, 0);
378            SetAzureDataDiskConfig setAzureDataDiskConfig2 = new SetAzureDataDiskConfig(HostCaching.ReadWrite, 0);
379            SetAzureDataDiskConfig[] diskConfig = { setAzureDataDiskConfig1, setAzureDataDiskConfig2 };
380            vmPowershellCmdlets.SetVMDataDisks(newAzureQuickVMName, serviceName, diskConfig);
381
382            vmPowershellCmdlets.GetAzureDataDisk(newAzureQuickVMName, serviceName);
383
384            // Cleanup
385            vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName);
386
387            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));
388            pass = true;
389        }
390
391        /// <summary>
392        /// Changes that Require a Reboot
393        /// </summary>
394        [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("priya"), Description("Test the cmdlets (Get-AzureVM,Set-AzureDataDisk ,Update-AzureVM,Set-AzureVMSize)")]
395        public void UpdateAndReboot()
396        {
397            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
398
399            string newAzureQuickVMName = Utilities.GetUniqueShortName("PSTestVM");
400            if (string.IsNullOrEmpty(imageName))
401                imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
402
403            vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName);
404
405            var azureDataDiskConfigInfo1 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk1", 0);
406            var azureDataDiskConfigInfo2 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk2", 1);
407            AddAzureDataDiskConfig[] dataDiskConfig = { azureDataDiskConfigInfo1, azureDataDiskConfigInfo2 };
408            vmPowershellCmdlets.AddVMDataDisks(newAzureQuickVMName, serviceName, dataDiskConfig);
409
410            var setAzureDataDiskConfig1 = new SetAzureDataDiskConfig(HostCaching.ReadOnly, 0);
411            var setAzureDataDiskConfig2 = new SetAzureDataDiskConfig(HostCaching.ReadOnly, 0);
412            SetAzureDataDiskConfig[] diskConfig = { setAzureDataDiskConfig1, setAzureDataDiskConfig2 };
413            vmPowershellCmdlets.SetVMDataDisks(newAzureQuickVMName, serviceName, diskConfig);
414
415            var vmSizeConfig = new SetAzureVMSizeConfig(InstanceSize.Medium.ToString());
416            vmPowershellCmdlets.SetVMSize(newAzureQuickVMName, serviceName, vmSizeConfig);
417
418            // Cleanup
419            vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName);
420            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));
421            pass = true;
422        }
423
424        /// <summary>
425        /// </summary>
426        [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("hylee"), Description("Test the cmdlets (Get-AzureDisk,Remove-AzureVM,Remove-AzureDisk,Get-AzureVMImage)")]
427        public void ManagingDiskImages()
428        {
429            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
430
431            // Create a unique VM name and Service Name
432            string newAzureQuickVMName = Utilities.GetUniqueShortName(vmNamePrefix);
433            if (string.IsNullOrEmpty(imageName))
434            {
435                imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
436            }
437
438            vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName); // New-AzureQuickVM
439            Console.WriteLine("VM is created successfully: -Name {0} -ServiceName {1}", newAzureQuickVMName, serviceName);
440
441            // starting the test.
442            Collection<DiskContext> vmDisks = vmPowershellCmdlets.GetAzureDiskAttachedToRoleName(new[] { newAzureQuickVMName });  // Get-AzureDisk | Where {$_.AttachedTo.RoleName -eq $vmname }
443
444            foreach (var disk in vmDisks)
445                Console.WriteLine("The disk, {0}, is created", disk.DiskName);
446
447            vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName);  // Remove-AzureVM
448            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));
449            Console.WriteLine("The VM, {0}, is successfully removed.", newAzureQuickVMName);
450
451            foreach (var disk in vmDisks)
452            {
453                for (int i = 0; i < 3; i++)
454                {
455                    try
456                    {
457                        vmPowershellCmdlets.RemoveAzureDisk(disk.DiskName, false); // Remove-AzureDisk
458                        break;
459                    }
460                    catch (Exception e)
461                    {
462                        if (e.ToString().ToLowerInvariant().Contains("currently in use") && i != 2)
463                        {
464                            Console.WriteLine("The vhd, {0}, is still in the state of being used by the deleted VM", disk.DiskName);
465                            Thread.Sleep(120000);
466                            continue;
467                        }
468                        else
469                        {
470                            Assert.Fail("error during Remove-AzureDisk: {0}", e.ToString());
471                        }
472                    }
473                }
474
475                try
476                {
477                    vmPowershellCmdlets.GetAzureDisk(disk.DiskName); // Get-AzureDisk -DiskName (try to get the removed disk.)
478                    Console.WriteLine("Disk is not removed: {0}", disk.DiskName);
479                    pass = false;
480                }
481                catch (Exception e)
482                {
483                    if (e.ToString().ToLowerInvariant().Contains("does not exist"))
484                    {
485                        Console.WriteLine("The disk, {0}, is successfully removed.", disk.DiskName);
486                        continue;
487                    }
488                    else
489                    {
490                        Assert.Fail("Exception: {0}", e.ToString());
491                    }
492                }
493            }
494            pass = true;
495        }
496
497        /// <summary>
498        /// </summary>
499        [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("hylee"), Description("Test the cmdlets (New-AzureVMConfig,Add-AzureProvisioningConfig,New-AzureVM,Save-AzureVMImage)")]
500        public void CaptureImagingExportingImportingVMConfig()
501        {
502            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
503
504            // Create a unique VM name
505            string newAzureVMName = Utilities.GetUniqueShortName("PSTestVM");
506            Console.WriteLine("VM Name: {0}", newAzureVMName);
507
508            // Create a unique Service Name
509            vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
510            Console.WriteLine("Service Name: {0}", serviceName);
511            if (string.IsNullOrEmpty(imageName))
512                imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
513
514            // starting the test.
515            var azureVMConfigInfo = new AzureVMConfigInfo(newAzureVMName, InstanceSize.Small.ToString(), imageName); // parameters for New-AzureVMConfig (-Name -InstanceSize -ImageName)
516            var azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password); // parameters for Add-AzureProvisioningConfig (-Windows -Password)
517            var persistentVMConfigInfo = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null);
518            PersistentVM persistentVM = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo); // New-AzureVMConfig & Add-AzureProvisioningConfig
519
520            PersistentVM[] VMs = { persistentVM };
521            vmPowershellCmdlets.NewAzureVM(serviceName, VMs); // New-AzureVM
522            Console.WriteLine("The VM is successfully created: {0}", persistentVM.RoleName);
523            PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(persistentVM.RoleName, serviceName);
524            Assert.AreEqual(vmRoleCtxt.Name, persistentVM.RoleName, true);
525
526
527            vmPowershellCmdlets.StopAzureVM(newAzureVMName, serviceName, true); // Stop-AzureVM
528            for (int i = 0; i < 3; i++)
529            {
530                vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(persistentVM.RoleName, serviceName);
531                if (vmRoleCtxt.InstanceStatus == "StoppedVM")
532                {
533                    break;
534                }
535                Console.WriteLine("The status of the VM {0} : {1}", persistentVM.RoleName, vmRoleCtxt.InstanceStatus);
536                Thread.Sleep(120000);
537            }
538            Assert.AreEqual(vmRoleCtxt.InstanceStatus, "StoppedVM", true);
539
540            // Save-AzureVMImage
541            vmPowershellCmdlets.SaveAzureVMImage(serviceName, newAzureVMName, newAzureVMName);
542
543            // Verify VM image.
544            var image = vmPowershellCmdlets.GetAzureVMImage(newAzureVMName)[0];
545
546            Assert.AreEqual("Windows", image.OS, "OS is not matching!");
547            Assert.AreEqual(newAzureVMName, image.ImageName, "Names are not matching!");
548
549            // Verify that the VM is removed
550            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(persistentVM.RoleName, serviceName));
551
552            // Cleanup the registered image
553            vmPowershellCmdlets.RemoveAzureVMImage(newAzureVMName, true);
554
555            pass = true;
556        }
557
558        /// <summary>
559        /// </summary>
560        [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("hylee"), Description("Test the cmdlets (Export-AzureVM,Remove-AzureVM,Import-AzureVM,New-AzureVM)")]
561        public void ExportingImportingVMConfigAsTemplateforRepeatableUsage()
562        {
563            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
564
565            // Create a new Azure quick VM
566            string newAzureQuickVMName = Utilities.GetUniqueShortName("PSTestVM");
567            if (string.IsNullOrEmpty(imageName))
568                imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
569            vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName); // New-AzureQuickVM
570            Console.WriteLine("VM is created successfully: -Name {0} -ServiceName {1}", newAzureQuickVMName, serviceName);
571
572            // starting the test.
573            string path = ".\\mytestvmconfig1.xml";
574            PersistentVMRoleContext vmRole = vmPowershellCmdlets.ExportAzureVM(newAzureQuickVMName, serviceName, path); // Export-AzureVM
575            Console.WriteLine("Exporting VM is successfully done: path - {0}  Name - {1}", path, vmRole.Name);
576
577            vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName); // Remove-AzureVM
578            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));
579            Console.WriteLine("The VM is successfully removed: {0}", newAzureQuickVMName);
580
581            List<PersistentVM> VMs = new List<PersistentVM>();
582            foreach (var pervm in vmPowershellCmdlets.ImportAzureVM(path)) // Import-AzureVM
583            {
584                VMs.Add(pervm);
585                Console.WriteLine("The VM, {0}, is imported.", pervm.RoleName);
586            }
587
588
589            for (int i = 0; i < 3; i++)
590            {
591                try
592                {
593                    vmPowershellCmdlets.NewAzureVM(serviceName, VMs.ToArray()); // New-AzureVM
594                    Console.WriteLine("All VMs are successfully created.");
595                    foreach (var vm in VMs)
596                    {
597                        Console.WriteLine("created VM: {0}", vm.RoleName);
598                    }
599                    break;
600                }
601                catch (Exception e)
602                {
603                    if (e.ToString().ToLowerInvariant().Contains("currently in use") && i != 2)
604                    {
605                        Console.WriteLine("The removed VM is still using the vhd");
606                        Thread.Sleep(120000);
607                        continue;
608                    }
609                    else
610                    {
611                        Assert.Fail("error during New-AzureVM: {0}", e.ToString());
612                    }
613                }
614            }
615
616            // Verify
617            PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName);
618            Assert.AreEqual(newAzureQuickVMName, vmRoleCtxt.Name, true);
619
620            // Cleanup
621            vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName);
622            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));
623
624            pass = true;
625        }
626
627        /// <summary>
628        /// </summary>
629        [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IaaS"), Priority(1), Owner("hylee"), Description("Test the cmdlets (Get-AzureVM,Get-AzureEndpoint,Get-AzureRemoteDesktopFile)")]
630        public void ManagingRDPSSHConnectivity()
631        {
632            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
633
634            // Create a new Azure quick VM
635            string newAzureQuickVMName = Utilities.GetUniqueShortName("PSTestVM");
636            if (string.IsNullOrEmpty(imageName))
637                imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
638            vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName); // New-AzureQuickVM
639            Console.WriteLine("VM is created successfully: -Name {0} -ServiceName {1}", newAzureQuickVMName, serviceName);
640
641            // starting the test.
642            PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName); // Get-AzureVM
643            InputEndpointContext inputEndpointCtxt = vmPowershellCmdlets.GetAzureEndPoint(vmRoleCtxt)[0]; // Get-AzureEndpoint
644            Console.WriteLine("InputEndpointContext Name: {0}", inputEndpointCtxt.Name);
645            Console.WriteLine("InputEndpointContext port: {0}", inputEndpointCtxt.Port);
646            Console.WriteLine("InputEndpointContext protocol: {0}", inputEndpointCtxt.Protocol);
647            Assert.AreEqual(inputEndpointCtxt.Name, "RemoteDesktop", true);
648
649            string path = ".\\myvmconnection.rdp";
650            vmPowershellCmdlets.GetAzureRemoteDesktopFile(newAzureQuickVMName, serviceName, path, false); // Get-AzureRemoteDesktopFile
651            Console.WriteLine("RDP file is successfully created at: {0}", path);
652
653            // ToDo: Automate RDP.
654            //vmPowershellCmdlets.GetAzureRemoteDesktopFile(newAzureQuickVMName, newAzureQuickVMSvcName, path, true); // Get-AzureRemoteDesktopFile -Launch
655
656            Console.WriteLine("Test passed");
657
658            // Cleanup
659            vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName);
660            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));
661
662            pass = true;
663        }
664
665        /// <summary>
666        /// Basic Provisioning a Virtual Machine
667        /// </summary>
668        [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "PAAS"), Priority(1), Owner("hylee"), Description("Test the cmdlet ((New,Get,Set,Remove,Move)-AzureDeployment)")]
669        [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\Resources\\packageScenario.csv", "packageScenario#csv", DataAccessMethod.Sequential)]
670        public void DeploymentUpgrade()
671        {
672
673            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
674            perfFile = @"..\deploymentUpgradeResult.csv";
675
676            // Choose the package and config files from local machine
677            string path = Convert.ToString(TestContext.DataRow["path"]);
678            string packageName = Convert.ToString(TestContext.DataRow["packageName"]);
679            string configName = Convert.ToString(TestContext.DataRow["configName"]);
680            string upgradePackageName = Convert.ToString(TestContext.DataRow["upgradePackage"]);
681            string upgradeConfigName = Convert.ToString(TestContext.DataRow["upgradeConfig"]);
682            string upgradeConfigName2 = Convert.ToString(TestContext.DataRow["upgradeConfig2"]);
683
684            var packagePath1 = new FileInfo(@path + packageName); // package with two roles
685            var packagePath2 = new FileInfo(@path + upgradePackageName); // package with one role
686            var configPath1 = new FileInfo(@path + configName); // config with 2 roles, 4 instances each
687            var configPath2 = new FileInfo(@path + upgradeConfigName); // config with 1 role, 2 instances
688            var configPath3 = new FileInfo(@path + upgradeConfigName2); // config with 1 role, 4 instances
689
690            Assert.IsTrue(File.Exists(packagePath1.FullName), "VHD file not exist={0}", packagePath1);
691            Assert.IsTrue(File.Exists(configPath1.FullName), "VHD file not exist={0}", configPath1);
692
693            string deploymentName = "deployment1";
694            string deploymentLabel = "label1";
695            DeploymentInfoContext result;
696
697            try
698            {
699                vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
700                Console.WriteLine("service, {0}, is created.", serviceName);
701
702                // New deployment to Production
703                DateTime start = DateTime.Now;
704                vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath1.FullName, configPath1.FullName, DeploymentSlotType.Production, deploymentLabel, deploymentName, false, false);
705
706                TimeSpan duration = DateTime.Now - start;
707
708                Uri site = Utilities.GetDeploymentAndWaitForReady(serviceName, DeploymentSlotType.Production, 10, 1000);
709
710                System.IO.File.AppendAllLines(perfFile, new string[] { String.Format("Deployment, {0}, {1}", duration, DateTime.Now - start) });
711
712                Console.WriteLine("site: {0}", site.ToString());
713                Console.WriteLine("Time for all instances to become in ready state: {0}", DateTime.Now - start);
714
715                // Auto-Upgrade the deployment
716                start = DateTime.Now;
717                vmPowershellCmdlets.SetAzureDeploymentUpgrade(serviceName, DeploymentSlotType.Production, UpgradeType.Auto, packagePath1.FullName, configPath1.FullName);
718                duration = DateTime.Now - start;
719                Console.WriteLine("Auto upgrade took {0}.", duration);
720
721                result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
722                Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, serviceName, DeploymentSlotType.Production, null, 8);
723                Console.WriteLine("successfully updated the deployment");
724
725                site = Utilities.GetDeploymentAndWaitForReady(serviceName, DeploymentSlotType.Production, 10, 600);
726                System.IO.File.AppendAllLines(perfFile, new string[] { String.Format("Auto Upgrade, {0}, {1}", duration, DateTime.Now - start) });
727
728                // Manual-Upgrade the deployment
729                start = DateTime.Now;
730                vmPowershellCmdlets.SetAzureDeploymentUpgrade(serviceName, DeploymentSlotType.Production, UpgradeType.Manual, packagePath1.FullName, configPath1.FullName);
731                vmPowershellCmdlets.SetAzureWalkUpgradeDomain(serviceName, DeploymentSlotType.Production, 0);
732                vmPowershellCmdlets.SetAzureWalkUpgradeDomain(serviceName, DeploymentSlotType.Production, 1);
733                vmPowershellCmdlets.SetAzureWalkUpgradeDomain(serviceName, DeploymentSlotType.Production, 2);
734                vmPowershellCmdlets.SetAzureWalkUpgradeDomain(serviceName, DeploymentSlotType.Production, 3);
735                vmPowershellCmdlets.SetAzureWalkUpgradeDomain(serviceName, DeploymentSlotType.Production, 4);
736                duration = DateTime.Now - start;
737                Console.WriteLine("Manual upgrade took {0}.", duration);
738
739                result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
740                Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, serviceName, DeploymentSlotType.Production, null, 8);
741                Console.WriteLine("successfully updated the deployment");
742
743                site = Utilities.GetDeploymentAndWaitForReady(serviceName, DeploymentSlotType.Production, 10, 600);
744                System.IO.File.AppendAllLines(perfFile, new string[] { String.Format("Manual Upgrade, {0}, {1}", duration, DateTime.Now - start) });
745
746                // Simulatenous-Upgrade the deployment
747                start = DateTime.Now;
748                vmPowershellCmdlets.SetAzureDeploymentUpgrade(serviceName, DeploymentSlotType.Production, UpgradeType.Simultaneous, packagePath1.FullName, configPath1.FullName);
749                duration = DateTime.Now - start;
750                Console.WriteLine("Simulatenous upgrade took {0}.", duration);
751
752                result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
753                Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, serviceName, DeploymentSlotType.Production, null, 8);
754                Console.WriteLine("successfully updated the deployment");
755
756                site = Utilities.GetDeploymentAndWaitForReady(serviceName, DeploymentSlotType.Production, 10, 600);
757                System.IO.File.AppendAllLines(perfFile, new string[] { String.Format("Simulatenous Upgrade, {0}, {1}", duration, DateTime.Now - start) });
758
759                vmPowershellCmdlets.RemoveAzureDeployment(serviceName, DeploymentSlotType.Production, true);
760                pass = Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, serviceName);
761            }
762            catch (Exception e)
763            {
764                pass = false;
765                Assert.Fail("Exception occurred: {0}", e.ToString());
766            }
767        }
768
769
770        /// <summary>
771        /// AzureVNetGatewayTest()
772        /// </summary>
773        /// Note: Create a VNet, a LocalNet from the portal without creating a gateway.
774        [TestMethod(), TestCategory("Scenario"), TestProperty("Feature", "IAAS"), Priority(1), Owner("hylee"),
775        Description("Test the cmdlet ((Set,Remove)-AzureVNetConfig, Get-AzureVNetSite, (New,Get,Set,Remove)-AzureVNetGateway, Get-AzureVNetConnection)")]
776        public void VNetTest()
777        {
778            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
779
780            string newAzureQuickVMName = Utilities.GetUniqueShortName(vmNamePrefix);
781            if (string.IsNullOrEmpty(imageName))
782                imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
783
784            // Read the vnetconfig file and get the names of local networks, virtual networks and affinity groups.
785            XDocument vnetconfigxml = XDocument.Load(vnetConfigFilePath);
786            List<string> localNets = new List<string>();
787            List<string> virtualNets = new List<string>();
788            HashSet<string> affinityGroups = new HashSet<string>();
789            Dictionary<string,string> dns = new Dictionary<string,string>();
790            List<LocalNetworkSite> localNetworkSites = new List<LocalNetworkSite>();
791            AddressPrefixList prefixlist = null;
792
793            foreach (XElement el in vnetconfigxml.Descendants())
794            {
795                switch (el.Name.LocalName)
796                {
797                    case "LocalNetworkSite":
798                        {
799                            localNets.Add(el.FirstAttribute.Value);
800                            List<XElement> elements = el.Elements().ToList<XElement>();
801                            prefixlist = new AddressPrefixList();
802                            prefixlist.Add(elements[0].Elements().First().Value);
803                            localNetworkSites.Add(new LocalNetworkSite()
804                                {
805                                    VpnGatewayAddress = elements[1].Value,
806                                    AddressSpace = new AddressSpace() { AddressPrefixes = prefixlist }
807                                }
808                            );
809                        }
810                        break;
811                    case "VirtualNetworkSite":
812                        virtualNets.Add(el.Attribute("name").Value);
813                        affinityGroups.Add(el.Attribute("AffinityGroup").Value);
814                        break;
815                    case "DnsServer":
816                        {
817                            dns.Add(el.Attribute("name").Value, el.Attribute("IPAddress").Value);
818                            break;
819                        }
820                    default:
821                        break;
822                }
823            }
824
825            foreach (string aff in affinityGroups)
826            {
827                if (Utilities.CheckRemove(vmPowershellCmdlets.GetAzureAffinityGroup, aff))
828                {
829
830                    vmPowershellCmdlets.NewAzureAffinityGroup(aff, locationName, null, null);
831                }
832            }
833
834            string vnet1 = virtualNets[0];
835            string lnet1 = localNets[0];
836
837            try
838            {
839                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName); // New-AzureQuickVM
840                Console.WriteLine("VM is created successfully: -Name {0} -ServiceName {1}", newAzureQuickVMName, serviceName);
841
842                vmPowershellCmdlets.SetAzureVNetConfig(vnetConfigFilePath);
843
844                foreach (VirtualNetworkSiteContext site in vmPowershellCmdlets.GetAzureVNetSite(null))
845                {
846                    Console.WriteLine("Name: {0}, AffinityGroup: {1}", site.Name, site.AffinityGroup);
847                }
848
849                foreach (string vnet in virtualNets)
850                {
851                    VirtualNetworkSiteContext vnetsite = vmPowershellCmdlets.GetAzureVNetSite(vnet)[0];
852                    Assert.AreEqual(vnet, vnetsite.Name);
853                    //Verify DNS and IPAddress
854                    Assert.AreEqual(1, vnetsite.DnsServers.Count());
855                    Assert.IsTrue(dns.ContainsKey(vnetsite.DnsServers.First().Name));
856                    Assert.AreEqual(dns[vnetsite.DnsServers.First().Name], vnetsite.DnsServers.First().Address);
857
858                    //Verify the Gateway sites
859                    Assert.AreEqual(1,vnetsite.GatewaySites.Count);
860                    Assert.AreEqual(localNetworkSites[0].VpnGatewayAddress, vnetsite.GatewaySites[0].VpnGatewayAddress);
861                    Assert.IsTrue(localNetworkSites[0].AddressSpace.AddressPrefixes.All(c => vnetsite.GatewaySites[0].AddressSpace.AddressPrefixes.Contains(c)));
862
863                    Assert.AreEqual(ProvisioningState.NotProvisioned, vmPowershellCmdlets.GetAzureVNetGateway(vnet)[0].State);
864                }
865
866                vmPowershellCmdlets.NewAzureVNetGateway(vnet1);
867
868                Assert.IsTrue(GetVNetState(vnet1, ProvisioningState.Provisioned, 12, 60));
869
870                // Set-AzureVNetGateway -Connect Test
871                vmPowershellCmdlets.SetAzureVNetGateway("connect", vnet1, lnet1);
872
873                foreach (GatewayConnectionContext connection in vmPowershellCmdlets.GetAzureVNetConnection(vnet1))
874                {
875                    Console.WriteLine("Connectivity: {0}, LocalNetwork: {1}", connection.ConnectivityState, connection.LocalNetworkSiteName);
876                    Assert.IsFalse(connection.ConnectivityState.ToLowerInvariant().Contains("notconnected"));
877                }
878
879                // Get-AzureVNetGatewayKey
880                SharedKeyContext result = vmPowershellCmdlets.GetAzureVNetGatewayKey(vnet1,
881                    vmPowershellCmdlets.GetAzureVNetConnection(vnet1)[0].LocalNetworkSiteName);
882                Console.WriteLine("Gateway Key: {0}", result.Value);
883
884
885                // Set-AzureVNetGateway -Disconnect
886                vmPowershellCmdlets.SetAzureVNetGateway("disconnect", vnet1, lnet1);
887
888                foreach (GatewayConnectionContext connection in vmPowershellCmdlets.GetAzureVNetConnection(vnet1))
889                {
890                    Console.WriteLine("Connectivity: {0}, LocalNetwork: {1}", connection.ConnectivityState, connection.LocalNetworkSiteName);
891                }
892
893                // Remove-AzureVnetGateway
894                vmPowershellCmdlets.RemoveAzureVNetGateway(vnet1);
895
896                foreach (string vnet in virtualNets)
897                {
898                    VirtualNetworkGatewayContext gateway = vmPowershellCmdlets.GetAzureVNetGateway(vnet)[0];
899
900                    Console.WriteLine("State: {0}, VIP: {1}", gateway.State.ToString(), gateway.VIPAddress);
901                    if (vnet.Equals(vnet1))
902                    {
903                        if (gateway.State != ProvisioningState.Deprovisioning &&
904                            gateway.State != ProvisioningState.NotProvisioned)
905                        {
906                            Assert.Fail("The state of the gateway is neither Deprovisioning nor NotProvisioned!");
907                        }
908                    }
909                    else
910                    {
911                        Assert.AreEqual(ProvisioningState.NotProvisioned, gateway.State);
912                    }
913
914                }
915
916                //Utilities.RetryFunctionUntilSuccess<ManagementOperationContext>(vmPowershellCmdlets.RemoveAzureVNetConfig, "in use", 10, 30);
917                Utilities.RetryActionUntilSuccess(() => vmPowershellCmdlets.RemoveAzureVNetConfig(), "in use", 10, 30);
918
919                pass = true;
920
921            }
922            catch (Exception e)
923            {
924                pass = false;
925                if (cleanupIfFailed)
926                {
927                    try
928                    {
929                        vmPowershellCmdlets.RemoveAzureVNetGateway(vnet1);
930                    }
931                    catch { }
932                    Utilities.RetryActionUntilSuccess(() => vmPowershellCmdlets.Remov

Large files files are truncated, but you can click here to view the full file