protected void ValidateVMScaleSetVM(VirtualMachineScaleSetVM vmScaleSetVM, string skuName, VirtualMachineScaleSetVM vmScaleSetVMOut, bool hasManagedDisks = false)
        {
            Assert.True(!string.IsNullOrEmpty(vmScaleSetVMOut.ProvisioningState));

            Assert.True(skuName
                        == vmScaleSetVMOut.Sku.Name);

            Assert.NotNull(vmScaleSetVMOut.StorageProfile.OsDisk);

            if (hasManagedDisks)
            {
                Assert.True(vmScaleSetVMOut.StorageProfile.OsDisk.ManagedDisk != null);
                Assert.True(vmScaleSetVMOut.StorageProfile.OsDisk.ManagedDisk.Id != null);
                if (vmScaleSetVM.StorageProfile.DataDisks != null)
                {
                    Assert.AreEqual(vmScaleSetVM.StorageProfile.DataDisks.Count,
                                    vmScaleSetVMOut.StorageProfile.DataDisks.Count);

                    foreach (var dataDiskOut in vmScaleSetVM.StorageProfile.DataDisks)
                    {
                        var dataDisk =
                            vmScaleSetVM.StorageProfile.DataDisks.FirstOrDefault(d => d.Lun == dataDiskOut.Lun);
                        Assert.AreEqual(dataDisk.CreateOption, dataDiskOut.CreateOption);
                        Assert.AreEqual(dataDisk.DiskSizeGB, dataDiskOut.DiskSizeGB);
                    }
                }
            }
            else
            {
                if (vmScaleSetVM.StorageProfile.OsDisk.Image != null)
                {
                    Assert.True(vmScaleSetVMOut.StorageProfile.OsDisk.Image.Uri
                                == vmScaleSetVM.StorageProfile.OsDisk.Image.Uri);
                }

                Assert.True(vmScaleSetVMOut.StorageProfile.OsDisk.Caching
                            == vmScaleSetVM.StorageProfile.OsDisk.Caching);
            }

            if (vmScaleSetVM.OsProfile.Secrets != null &&
                vmScaleSetVM.OsProfile.Secrets.Any())
            {
                foreach (var secret in vmScaleSetVM.OsProfile.Secrets)
                {
                    Assert.NotNull(secret.VaultCertificates);
                    var secretOut = vmScaleSetVMOut.OsProfile.Secrets.FirstOrDefault(s => string.Equals(secret.SourceVault.Id, s.SourceVault.Id));
                    Assert.NotNull(secretOut);

                    // Disabling resharper null-ref check as it doesn't seem to understand the not-null assert above.
                    // ReSharper disable PossibleNullReferenceException

                    Assert.NotNull(secretOut.VaultCertificates);
                    var VaultCertComparer = new VaultCertComparer();
                    Assert.True(secretOut.VaultCertificates.SequenceEqual(secret.VaultCertificates, VaultCertComparer));

                    // ReSharper enable PossibleNullReferenceException
                }
            }
        }
Пример #2
0
        protected void ValidateVMScaleSet(VirtualMachineScaleSet vmScaleSet, VirtualMachineScaleSet vmScaleSetOut, bool hasManagedDisks = false, string ppgId = null)
        {
            Assert.True(!string.IsNullOrEmpty(vmScaleSetOut.ProvisioningState));

            Assert.True(vmScaleSetOut.Sku.Name
                        == vmScaleSet.Sku.Name);

            Assert.NotNull(vmScaleSetOut.VirtualMachineProfile.StorageProfile.OsDisk);

            if (vmScaleSet.VirtualMachineProfile.StorageProfile.OsDisk?.DiskSizeGB != null)
            {
                Assert.NotNull(vmScaleSetOut.VirtualMachineProfile.StorageProfile.OsDisk.DiskSizeGB);
                Assert.AreEqual(vmScaleSet.VirtualMachineProfile.StorageProfile.OsDisk.DiskSizeGB, vmScaleSetOut.VirtualMachineProfile.StorageProfile.OsDisk.DiskSizeGB);
            }

            if (!hasManagedDisks)
            {
                Assert.True(vmScaleSetOut.VirtualMachineProfile.StorageProfile.OsDisk.Name
                            == vmScaleSet.VirtualMachineProfile.StorageProfile.OsDisk.Name);

                if (vmScaleSet.VirtualMachineProfile.StorageProfile.OsDisk.Image != null)
                {
                    Assert.True(vmScaleSetOut.VirtualMachineProfile.StorageProfile.OsDisk.Image.Uri
                                == vmScaleSet.VirtualMachineProfile.StorageProfile.OsDisk.Image.Uri);
                }

                Assert.True(vmScaleSetOut.VirtualMachineProfile.StorageProfile.OsDisk.Caching
                            == vmScaleSet.VirtualMachineProfile.StorageProfile.OsDisk.Caching);
            }
            else
            {
                Assert.NotNull(vmScaleSetOut.VirtualMachineProfile.StorageProfile.OsDisk.ManagedDisk);

                if (vmScaleSet.VirtualMachineProfile.StorageProfile.OsDisk != null)
                {
                    VirtualMachineScaleSetOSDisk osDisk    = vmScaleSet.VirtualMachineProfile.StorageProfile.OsDisk;
                    VirtualMachineScaleSetOSDisk osDiskOut =
                        vmScaleSetOut.VirtualMachineProfile.StorageProfile.OsDisk;

                    if (osDisk.Caching != null)
                    {
                        Assert.True(osDisk.Caching == osDiskOut.Caching);
                    }
                    else
                    {
                        Assert.NotNull(osDiskOut.Caching);
                    }

                    if (osDisk.DiffDiskSettings != null)
                    {
                        Assert.True(osDisk.DiffDiskSettings.Option == osDiskOut.DiffDiskSettings.Option);
                    }

                    Assert.NotNull(osDiskOut.ManagedDisk);
                    if (osDisk.ManagedDisk != null && osDisk.ManagedDisk.StorageAccountType != null)
                    {
                        Assert.True(osDisk.ManagedDisk.StorageAccountType == osDiskOut.ManagedDisk.StorageAccountType);
                    }
                    else
                    {
                        Assert.NotNull(osDiskOut.ManagedDisk.StorageAccountType);
                    }

                    if (osDisk.Name != null)
                    {
                        Assert.AreEqual(osDiskOut.Name, osDisk.Name);
                    }

                    Assert.True(osDiskOut.CreateOption == DiskCreateOptionTypes.FromImage);
                }

                if (vmScaleSet.VirtualMachineProfile.StorageProfile.DataDisks != null &&
                    vmScaleSet.VirtualMachineProfile.StorageProfile.DataDisks.Count > 0)
                {
                    Assert.AreEqual(
                        vmScaleSet.VirtualMachineProfile.StorageProfile.DataDisks.Count,
                        vmScaleSetOut.VirtualMachineProfile.StorageProfile.DataDisks.Count);

                    foreach (VirtualMachineScaleSetDataDisk dataDisk in vmScaleSet.VirtualMachineProfile.StorageProfile.DataDisks)
                    {
                        VirtualMachineScaleSetDataDisk matchingDataDisk
                            = vmScaleSetOut.VirtualMachineProfile.StorageProfile.DataDisks.FirstOrDefault(disk => disk.Lun == dataDisk.Lun);
                        Assert.NotNull(matchingDataDisk);

                        if (dataDisk.Caching != null)
                        {
                            Assert.True(dataDisk.Caching == matchingDataDisk.Caching);
                        }
                        else
                        {
                            Assert.NotNull(matchingDataDisk.Caching);
                        }

                        if (dataDisk.ManagedDisk != null && dataDisk.ManagedDisk.StorageAccountType != null)
                        {
                            Assert.True(dataDisk.ManagedDisk.StorageAccountType == matchingDataDisk.ManagedDisk.StorageAccountType);
                        }
                        else
                        {
                            Assert.NotNull(matchingDataDisk.ManagedDisk.StorageAccountType);
                        }

                        if (dataDisk.Name != null)
                        {
                            Assert.AreEqual(dataDisk.Name, matchingDataDisk.Name);
                        }
                        Assert.True(dataDisk.CreateOption == matchingDataDisk.CreateOption);
                    }
                }
            }

            if (vmScaleSet.UpgradePolicy.AutomaticOSUpgradePolicy != null)
            {
                bool expectedDisableAutomaticRollbackValue = vmScaleSet.UpgradePolicy.AutomaticOSUpgradePolicy.DisableAutomaticRollback ?? false;
                Assert.True(vmScaleSetOut.UpgradePolicy.AutomaticOSUpgradePolicy.DisableAutomaticRollback == expectedDisableAutomaticRollbackValue);

                bool expectedEnableAutomaticOSUpgradeValue = vmScaleSet.UpgradePolicy.AutomaticOSUpgradePolicy.EnableAutomaticOSUpgrade ?? false;
                Assert.True(vmScaleSetOut.UpgradePolicy.AutomaticOSUpgradePolicy.EnableAutomaticOSUpgrade == expectedEnableAutomaticOSUpgradeValue);
            }

            if (vmScaleSet.AutomaticRepairsPolicy != null)
            {
                bool expectedAutomaticRepairsEnabledValue = vmScaleSet.AutomaticRepairsPolicy.Enabled ?? false;
                Assert.True(vmScaleSetOut.AutomaticRepairsPolicy.Enabled == expectedAutomaticRepairsEnabledValue);

                string expectedAutomaticRepairsGracePeriodValue = vmScaleSet.AutomaticRepairsPolicy.GracePeriod ?? "PT30M";
                Assert.AreEqual(vmScaleSetOut.AutomaticRepairsPolicy.GracePeriod, expectedAutomaticRepairsGracePeriodValue);
            }

            if (vmScaleSet.VirtualMachineProfile.OsProfile.Secrets != null &&
                vmScaleSet.VirtualMachineProfile.OsProfile.Secrets.Any())
            {
                foreach (var secret in vmScaleSet.VirtualMachineProfile.OsProfile.Secrets)
                {
                    Assert.NotNull(secret.VaultCertificates);
                    var secretOut = vmScaleSetOut.VirtualMachineProfile.OsProfile.Secrets.FirstOrDefault(s => string.Equals(secret.SourceVault.Id, s.SourceVault.Id));
                    Assert.NotNull(secretOut);

                    // Disabling resharper null-ref check as it doesn't seem to understand the not-null assert above.
                    // ReSharper disable PossibleNullReferenceException

                    Assert.NotNull(secretOut.VaultCertificates);
                    var VaultCertComparer = new VaultCertComparer();
                    Assert.True(secretOut.VaultCertificates.SequenceEqual(secret.VaultCertificates, VaultCertComparer));

                    // ReSharper enable PossibleNullReferenceException
                }
            }

            if (vmScaleSet.VirtualMachineProfile.ExtensionProfile != null &&
                vmScaleSet.VirtualMachineProfile.ExtensionProfile.Extensions.Any())
            {
                foreach (var vmExtension in vmScaleSet.VirtualMachineProfile.ExtensionProfile.Extensions)
                {
                    var vmExt = vmScaleSetOut.VirtualMachineProfile.ExtensionProfile.Extensions.FirstOrDefault(s => String.Compare(s.Name, vmExtension.Name, StringComparison.OrdinalIgnoreCase) == 0);
                    Assert.NotNull(vmExt);
                }
            }

            if (vmScaleSet.VirtualMachineProfile.NetworkProfile != null)
            {
                if (vmScaleSet.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations != null && vmScaleSet.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.Count > 0)
                {
                    Assert.NotNull(vmScaleSetOut.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations);
                    Assert.AreEqual(
                        vmScaleSetOut.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.Count,
                        vmScaleSet.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.Count);

                    foreach (var nicconfig in vmScaleSet.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations)
                    {
                        var outnicconfig =
                            vmScaleSetOut.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.First(
                                nc => string.Equals(nc.Name, nicconfig.Name, StringComparison.OrdinalIgnoreCase));
                        Assert.NotNull(outnicconfig);
                        CompareVmssNicConfig(nicconfig, outnicconfig);
                    }
                }
            }
            else
            {
                Assert.True((vmScaleSetOut.VirtualMachineProfile.NetworkProfile == null) || (vmScaleSetOut.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.Count == 0));
            }

            if (vmScaleSet.Zones != null)
            {
                Assert.True(vmScaleSet.Zones.SequenceEqual(vmScaleSetOut.Zones), "Zones don't match");
                if (vmScaleSet.ZoneBalance.HasValue)
                {
                    Assert.AreEqual(vmScaleSet.ZoneBalance, vmScaleSetOut.ZoneBalance);
                }
                else
                {
                    if (vmScaleSet.Zones.Count > 1)
                    {
                        Assert.True(vmScaleSetOut.ZoneBalance.HasValue);
                    }
                    else
                    {
                        Assert.False(vmScaleSetOut.ZoneBalance.HasValue);
                    }
                }

                if (vmScaleSet.PlatformFaultDomainCount.HasValue)
                {
                    Assert.AreEqual(vmScaleSet.PlatformFaultDomainCount, vmScaleSetOut.PlatformFaultDomainCount);
                }
                else
                {
                    Assert.True(vmScaleSetOut.PlatformFaultDomainCount.HasValue);
                }
            }
            else
            {
                Assert.Null(vmScaleSetOut.Zones);
                Assert.Null(vmScaleSetOut.ZoneBalance);
            }

            if (ppgId != null)
            {
                Assert.AreEqual(ppgId.ToLower(), vmScaleSetOut.ProximityPlacementGroup.Id.ToLower());
            }
        }