Ejemplo n.º 1
0
        public void GettingProcessorSettingDataListOfVirtualSystemSettingData_ExpectingOne()
        {
            using (var viridianUtils = new ViridianUtils())
            {
                viridianUtils.SUT_ComputerSystemMO(
                    ViridianUtils.GetCurrentMethod(),
                    out uint ReturnValue,
                    out ManagementPath Job,
                    out ManagementPath ResultingSystem);

                using (var computerSystem = new ComputerSystem(ResultingSystem))
                {
                    ReturnValue = computerSystem.RequestStateChange(2, null, out Job);

                    ViridianUtils.WaitForConcreteJobToEnd(Job);

                    computerSystem.UpdateObject();

                    var vssdCollection = ViridianUtils.GetVirtualSystemSettingDataListThroughSettingsDefineState(computerSystem);

                    var sut = ViridianUtils.GetProcessorSettingDataList(vssdCollection.First());

                    Assert.AreEqual(1, vssdCollection.Count);
                    Assert.AreEqual(1, sut.Count);

                    ReturnValue = computerSystem.RequestStateChange(3, null, out Job);
                }

                ViridianUtils.WaitForConcreteJobToEnd(Job);
            }
        }
Ejemplo n.º 2
0
        public void RequestStateChange_ExpectingEnabledStateIsTwo()
        {
            using (var viridianUtils = new ViridianUtils())
            {
                viridianUtils.SUT_ComputerSystemMO(
                    ViridianUtils.GetCurrentMethod(),
                    out uint ReturnValue,
                    out ManagementPath Job,
                    out ManagementPath ResultingSystem);

                using (var computerSystem = new ComputerSystem(ResultingSystem))
                {
                    ReturnValue = computerSystem.RequestStateChange(2, null, out Job);

                    ViridianUtils.WaitForConcreteJobToEnd(Job);

                    computerSystem.UpdateObject();

                    Assert.IsNotNull(ResultingSystem);
                    Assert.AreEqual(4096U, ReturnValue);
                    Assert.AreEqual(2U, computerSystem.EnabledState);

                    ReturnValue = computerSystem.RequestStateChange(3, null, out Job);

                    ViridianUtils.WaitForConcreteJobToEnd(Job);
                }
            }
        }
Ejemplo n.º 3
0
        public void GetVirtualSystemThumbnailImage_ExpectingNotNullImage()
        {
            using (var viridianUtils = new ViridianUtils())
            {
                viridianUtils.SUT_ComputerSystemMO(
                    ViridianUtils.GetCurrentMethod(),
                    out uint ReturnValue,
                    out ManagementPath Job,
                    out ManagementPath ResultingSystem);

                using (var computerSystem = new ComputerSystem(ResultingSystem))
                {
                    ReturnValue = computerSystem.RequestStateChange(2, null, out Job);

                    ViridianUtils.WaitForConcreteJobToEnd(Job);

                    ReturnValue = viridianUtils.VSMS.GetVirtualSystemThumbnailImage(1000, ResultingSystem, 1000, out byte[] ImageData);

                    Assert.AreEqual(0U, ReturnValue);
                    Assert.IsNotNull(ImageData);

                    ReturnValue = computerSystem.RequestStateChange(3, null, out Job);
                }

                ViridianUtils.WaitForConcreteJobToEnd(Job);
            }
        }
Ejemplo n.º 4
0
        public void ModifyMemorySettingDataVirtualQuantity_Expecting2048()
        {
            using (var viridianUtils = new ViridianUtils())
            {
                viridianUtils.SUT_ComputerSystemMO(
                    ViridianUtils.GetCurrentMethod(),
                    out uint ReturnValue,
                    out ManagementPath Job,
                    out ManagementPath ResultingSystem);

                using (var computerSystem = new ComputerSystem(ResultingSystem))
                {
                    ReturnValue = computerSystem.RequestStateChange(2, null, out Job);

                    ViridianUtils.WaitForConcreteJobToEnd(Job);

                    computerSystem.UpdateObject();

                    var vssdCollection = ViridianUtils.GetVirtualSystemSettingDataListThroughSettingsDefineState(computerSystem);

                    var memorySettingDataList = ViridianUtils.GetMemorySettingDataList(vssdCollection.First());

                    using (var memorySettingData = memorySettingDataList.First())
                    {
                        memorySettingData.LateBoundObject["VirtualQuantity"] = 2048;

                        ReturnValue = computerSystem.RequestStateChange(3, null, out Job);

                        ViridianUtils.WaitForConcreteJobToEnd(Job);

                        computerSystem.UpdateObject();

                        var ResourceSettings = new string[] { memorySettingData.LateBoundObject.GetText(TextFormat.WmiDtd20) };
                        viridianUtils.VSMS.ModifyResourceSettings(ResourceSettings, out Job, out ManagementPath[] ResultingResourceSettins);

                        using (var sut = new MemorySettingData(ResultingResourceSettins[0]))
                        {
                            Assert.AreEqual(1, vssdCollection.Count);
                            Assert.AreEqual(1, memorySettingDataList.Count);
                            Assert.AreEqual(2048UL, sut.VirtualQuantity);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void GettingBaseAndAggregationMetricsOnProcessorSettingData_ExpectingZeroBaseAndOneAggregation()
        {
            using (var viridianUtils = new ViridianUtils())
            {
                viridianUtils.SUT_ComputerSystemMO(
                    ViridianUtils.GetCurrentMethod(),
                    out uint ReturnValue,
                    out ManagementPath Job,
                    out ManagementPath ResultingSystem);

                using (var computerSystem = new ComputerSystem(ResultingSystem))
                {
                    ReturnValue = computerSystem.RequestStateChange(2, null, out Job);

                    ViridianUtils.WaitForConcreteJobToEnd(Job);

                    computerSystem.UpdateObject();

                    var metricServiceSettingData = MetricServiceSettingData.GetInstances().First();
                    metricServiceSettingData.LateBoundObject["MetricsFlushInterval"] = MsvmBase.ToDmtfTimeInterval(new TimeSpan(1000));
                    viridianUtils.MS.ModifyServiceSettings(metricServiceSettingData.LateBoundObject.GetText(TextFormat.WmiDtd20), out Job);

                    var baseMetricDefinitions = BaseMetricDefinition.GetInstances();
                    baseMetricDefinitions.ForEach((bsd) => viridianUtils.MS.ControlMetrics(bsd.Path, 2, computerSystem.Path));

                    var aggregationMetricDefinitions = AggregationMetricDefinition.GetInstances();
                    aggregationMetricDefinitions.ForEach((agd) => viridianUtils.MS.ControlMetrics(agd.Path, 2, computerSystem.Path));

                    var vssdCollection = ViridianUtils.GetVirtualSystemSettingDataListThroughSettingsDefineState(computerSystem);

                    var psdCollection = ViridianUtils.GetProcessorSettingDataList(vssdCollection.First());

                    var amdCollection =
                        MetricDefForME.GetInstances()
                        .Cast <MetricDefForME>()
                        .Where((mdfm) =>
                               string.Compare(mdfm.Antecedent.Path, psdCollection.First().Path.Path, true, CultureInfo.InvariantCulture) == 0 &&
                               mdfm.Dependent.ClassName == $"Msvm_{nameof(AggregationMetricDefinition)}")
                        .Select((mdfm) => new AggregationMetricDefinition(mdfm.Dependent))
                        .ToList();

                    var amvCollection =
                        MetricForME.GetInstances()
                        .Cast <MetricForME>()
                        .Where((mdfm) => string.Compare(mdfm.Antecedent.Path, psdCollection.First().Path.Path, true, CultureInfo.InvariantCulture) == 0 &&
                               mdfm.Dependent.ClassName == $"Msvm_{nameof(AggregationMetricValue)}")
                        .Select((mdfm) => new AggregationMetricValue(mdfm.Dependent))
                        .ToList();

                    var aggregationMetricMap = new Dictionary <AggregationMetricDefinition, AggregationMetricValue>();

                    amdCollection
                    .Where((amd) => amvCollection.Where((amv) => string.Compare(amv.MetricDefinitionId, amd.Id, true, CultureInfo.InvariantCulture) == 0).Any())
                    .ToList()
                    .ForEach((amd) =>
                             aggregationMetricMap.Add(
                                 amd,
                                 amvCollection.Where((amv) => string.Compare(amv.MetricDefinitionId, amd.Id, true, CultureInfo.InvariantCulture) == 0).ToList().First())
                             );

                    var bmdCollection =
                        MetricDefForME.GetInstances()
                        .Cast <MetricDefForME>()
                        .Where((mdfm) => string.Compare(mdfm.Antecedent.Path, psdCollection.First().Path.Path, true, CultureInfo.InvariantCulture) == 0 &&
                               mdfm.Dependent.ClassName == $"Msvm_{nameof(BaseMetricDefinition)}")
                        .Select((mdfm) => new BaseMetricDefinition(mdfm.Dependent))
                        .ToList();

                    var bmvCollection =
                        MetricForME.GetInstances()
                        .Cast <MetricForME>()
                        .Where((mdfm) => string.Compare(mdfm.Antecedent.Path, psdCollection.First().Path.Path, true, CultureInfo.InvariantCulture) == 0 &&
                               mdfm.Dependent.ClassName == $"Msvm_{nameof(BaseMetricValue)}")
                        .Select((mdfm) => new BaseMetricValue(mdfm.Dependent))
                        .ToList();

                    var baseMetricMap = new Dictionary <BaseMetricDefinition, BaseMetricValue>();

                    bmdCollection
                    .Where((bmd) => bmvCollection.Where((amv) => string.Compare(amv.MetricDefinitionId, bmd.Id, true, CultureInfo.InvariantCulture) == 0).Any())
                    .ToList()
                    .ForEach((bmd) =>
                             baseMetricMap.Add(
                                 bmd,
                                 bmvCollection.Where((amv) => string.Compare(amv.MetricDefinitionId, bmd.Id, true, CultureInfo.InvariantCulture) == 0).ToList().First())
                             );

                    ReturnValue = computerSystem.RequestStateChange(3, null, out Job);

                    ViridianUtils.WaitForConcreteJobToEnd(Job);

                    Assert.IsNotNull(ResultingSystem);
                    Assert.AreEqual(4096U, ReturnValue);
                    Assert.AreEqual(1, vssdCollection.Count);
                    Assert.AreEqual(1, aggregationMetricMap.Count);
                    Assert.AreEqual(0, baseMetricMap.Count);
                }
            }
        }
Ejemplo n.º 6
0
        public void AutomatedOSInstallationWindows10Version1903x64_ExpectingFileThatMarksTheJobAsFinishedInVM()
        {
            var vhdxName        = $"{AppDomain.CurrentDomain.BaseDirectory}\\{ViridianUtils.GetCurrentMethod()}.vhdx";
            var isoName         = $"{AppDomain.CurrentDomain.BaseDirectory}\\{ViridianUtils.GetCurrentMethod()}.iso";
            var uri             = "https://filetransfer.io/data-package/AwILWW3y?do=download";
            var expectedSHA256  = "4bc7170baa665f4d92ba379843b47e83b384313fb6edf3fae09bc9dd42cd8426".ToUpperInvariant();
            var fileHashMatches = false;

            var computedSHA256 = ViridianUtils.GetFileSHA256HexUpperCase(isoName);

            Trace.WriteLine($"Expected SHA256 [{expectedSHA256}] Computed SHA256 [{computedSHA256}]");

            fileHashMatches = computedSHA256 == expectedSHA256;

            if (fileHashMatches == false)
            {
                ViridianUtils.DownloadFile(uri, isoName);

                computedSHA256 = ViridianUtils.GetFileSHA256HexUpperCase(isoName);

                Trace.WriteLine($"Expected SHA256 [{expectedSHA256}] Computed SHA256 [{computedSHA256}]");

                fileHashMatches = computedSHA256 == expectedSHA256;

                if (fileHashMatches == false)
                {
                    throw new Exception($"Invalid SHA256 for file [{isoName}]!");
                }
            }

            using (var viridianUtils = new ViridianUtils())
            {
                viridianUtils.SUT_ComputerSystemMO(
                    ViridianUtils.GetCurrentMethod(),
                    out uint ReturnValue,
                    out ManagementPath Job,
                    out ManagementPath ResultingSystem);

                var primordialResourcePoolSCSI                  = ViridianUtils.GetPrimordialResourcePool("Microsoft:Hyper-V:Synthetic SCSI Controller");
                var allocationCapabilitiesSCSIController        = ViridianUtils.GetAllocationCapabilities(primordialResourcePoolSCSI);
                var resourceAllocationSettingDataSCSIController = ViridianUtils.GetDefaultResourceAllocationSettingData(allocationCapabilitiesSCSIController);

                using (var computerSystem = new ComputerSystem(ResultingSystem))
                {
                    using (var virtualSystemSettingData = ViridianUtils.GetVirtualSystemSettingDataListThroughSettingsDefineState(computerSystem).First())
                    {
                        var AffectedConfiguration = virtualSystemSettingData.Path;
                        var ResourceSettings      = new string[] { resourceAllocationSettingDataSCSIController.LateBoundObject.GetText(TextFormat.WmiDtd20) };
                        ReturnValue = viridianUtils.VSMS.AddResourceSettings(AffectedConfiguration, ResourceSettings, out Job, out ManagementPath[] ResultingResourceSettings);

                        using (var scsiController = ViridianUtils.GetResourceAllocationgSettingData(virtualSystemSettingData, 6, "Microsoft:Hyper-V:Synthetic SCSI Controller").First())
                        {
                            using (var primordialResourcePoolDVDDrive = ViridianUtils.GetPrimordialResourcePool("Microsoft:Hyper-V:Synthetic DVD Drive"))
                                using (var allocationCapabilitiesDVDDrive = ViridianUtils.GetAllocationCapabilities(primordialResourcePoolDVDDrive))
                                    using (var resourceAllocationSettingDataDVDDrive = ViridianUtils.GetDefaultResourceAllocationSettingData(allocationCapabilitiesDVDDrive))
                                    {
                                        resourceAllocationSettingDataDVDDrive.LateBoundObject["Parent"]          = scsiController.Path;
                                        resourceAllocationSettingDataDVDDrive.LateBoundObject["AddressOnParent"] = 0;

                                        ResourceSettings = new string[] { resourceAllocationSettingDataDVDDrive.LateBoundObject.GetText(TextFormat.WmiDtd20) };
                                    }
                            ReturnValue = viridianUtils.VSMS.AddResourceSettings(AffectedConfiguration, ResourceSettings, out Job, out ResultingResourceSettings);

                            using (var synthethicDVD = ViridianUtils.GetResourceAllocationgSettingData(virtualSystemSettingData, 16, "Microsoft:Hyper-V:Synthetic DVD Drive").First())
                                using (var primordialResourcePoolVirtualCDDVD = ViridianUtils.GetPrimordialResourcePool("Microsoft:Hyper-V:Virtual CD/DVD Disk"))
                                    using (var allocationCapabilitiesVirtualCDDVD = ViridianUtils.GetAllocationCapabilities(primordialResourcePoolVirtualCDDVD))
                                        using (var resourceAllocationSettingVirtualCDDVD = ViridianUtils.GetDefaultStorageAllocationSettingData(allocationCapabilitiesVirtualCDDVD))
                                        {
                                            resourceAllocationSettingVirtualCDDVD.LateBoundObject["Address"]      = 0;
                                            resourceAllocationSettingVirtualCDDVD.LateBoundObject["Parent"]       = synthethicDVD.Path;
                                            resourceAllocationSettingVirtualCDDVD.LateBoundObject["HostResource"] = new[] { isoName };

                                            ResourceSettings = new string[] { resourceAllocationSettingVirtualCDDVD.LateBoundObject.GetText(TextFormat.WmiDtd20) };
                                        }
                            ReturnValue = viridianUtils.VSMS.AddResourceSettings(AffectedConfiguration, ResourceSettings, out Job, out ResultingResourceSettings);

                            using (var primordialResourcePoolDiskDrive = ViridianUtils.GetPrimordialResourcePool("Microsoft:Hyper-V:Synthetic Disk Drive"))
                                using (var allocationCapabilitiesDiskDrive = ViridianUtils.GetAllocationCapabilities(primordialResourcePoolDiskDrive))
                                    using (var resourceAllocationSettingDataDiskDrive = ViridianUtils.GetDefaultResourceAllocationSettingData(allocationCapabilitiesDiskDrive))
                                    {
                                        resourceAllocationSettingDataDiskDrive.LateBoundObject["Parent"]          = scsiController.Path;
                                        resourceAllocationSettingDataDiskDrive.LateBoundObject["AddressOnParent"] = 1;

                                        ResourceSettings = new string[] { resourceAllocationSettingDataDiskDrive.LateBoundObject.GetText(TextFormat.WmiDtd20) };
                                    }
                        }
                        ReturnValue = viridianUtils.VSMS.AddResourceSettings(AffectedConfiguration, ResourceSettings, out Job, out ResultingResourceSettings);

                        using (var synthethicDiskDrive = ViridianUtils.GetResourceAllocationgSettingData(virtualSystemSettingData, 17, "Microsoft:Hyper-V:Synthetic Disk Drive").First())
                            using (var primordialResourcePoolVirtualHardDisk = ViridianUtils.GetPrimordialResourcePool("Microsoft:Hyper-V:Virtual Hard Disk"))
                                using (var allocationCapabilitiesVirtualHardDisk = ViridianUtils.GetAllocationCapabilities(primordialResourcePoolVirtualHardDisk))
                                    using (var resourceAllocationSettingVirtualHardDisk = ViridianUtils.GetDefaultStorageAllocationSettingData(allocationCapabilitiesVirtualHardDisk))
                                    {
                                        using (var vhdsd = VirtualHardDiskSettingData.CreateInstance())
                                        {
                                            vhdsd.LateBoundObject["Type"]            = VirtualHardDiskSettingData.TypeValues.Dynamic;
                                            vhdsd.LateBoundObject["Format"]          = VirtualHardDiskSettingData.FormatValues.VHDX;
                                            vhdsd.LateBoundObject["Path"]            = vhdxName;
                                            vhdsd.LateBoundObject["ParentPath"]      = null;
                                            vhdsd.LateBoundObject["MaxInternalSize"] = 1024UL * 1024 * 1024 * 100;

                                            var VirtualDiskSettingData = vhdsd.LateBoundObject.GetText(TextFormat.WmiDtd20);
                                            viridianUtils.IMS.CreateVirtualHardDisk(VirtualDiskSettingData, out Job);

                                            ViridianUtils.WaitForStorageJobToEnd(Job);
                                        }

                                        resourceAllocationSettingVirtualHardDisk.LateBoundObject["Access"]       = 3; // read/write
                                        resourceAllocationSettingVirtualHardDisk.LateBoundObject["Address"]      = 0;
                                        resourceAllocationSettingVirtualHardDisk.LateBoundObject["Parent"]       = synthethicDiskDrive.Path.Path;
                                        resourceAllocationSettingVirtualHardDisk.LateBoundObject["HostResource"] = new[] { vhdxName };

                                        ResourceSettings = new string[] { resourceAllocationSettingVirtualHardDisk.LateBoundObject.GetText(TextFormat.WmiDtd20) };
                                    }
                        ReturnValue = viridianUtils.VSMS.AddResourceSettings(AffectedConfiguration, ResourceSettings, out Job, out ResultingResourceSettings);

                        ReturnValue = computerSystem.RequestStateChange(2, null, out Job);

                        ViridianUtils.WaitForConcreteJobToEnd(Job);

                        using (var guestServiceInterfaceComponentSettingData = ViridianUtils.GetGuestServiceInterfaceComponentSettingData(virtualSystemSettingData))
                        {
                            guestServiceInterfaceComponentSettingData.LateBoundObject["EnabledState"] = GuestServiceInterfaceComponentSettingData.EnabledStateValues.Enabled;

                            var GuestServiceSettings = new string[1] {
                                guestServiceInterfaceComponentSettingData.LateBoundObject.GetText(TextFormat.WmiDtd20)
                            };
                            ReturnValue = viridianUtils.VSMS.ModifyGuestServiceSettings(GuestServiceSettings, out Job, out ManagementPath[] ResultingGuestServices);
                        }

                        ViridianUtils.WaitForConcreteJobToEnd(Job);

                        using (var guestServiceInterfaceComponent = ViridianUtils.GetGuestServiceInterfaceComponent(computerSystem))
                            using (var guestFileService = ViridianUtils.GetGuestFileService(guestServiceInterfaceComponent))
                                using (var copyFileToGuestSettingData = CopyFileToGuestSettingData.CreateInstance())
                                {
                                    copyFileToGuestSettingData.DestinationPath   = @"C:\finished";
                                    copyFileToGuestSettingData.OverwriteExisting = false;
                                    copyFileToGuestSettingData.SourcePath        = @"C:\copyme";
                                    copyFileToGuestSettingData.CreateFullPath    = true;

                                    // this check might still be a bit too early but.. heh
                                    // right now I do not know a decent way to check if account set up finished
                                    var retries       = 20;
                                    var retryWaitTime = 1; // minutes
                                    var lastErrorcode = 0;
                                    var fileExists    = false;

                                    for (int i = 0; i < retries; i++)
                                    {
                                        var CopyFileToGuestSettings = new string[1] {
                                            copyFileToGuestSettingData.LateBoundObject.GetText(TextFormat.CimDtd20)
                                        };
                                        ReturnValue = guestFileService.CopyFilesToGuest(CopyFileToGuestSettings, out Job);

                                        using (var copyFileToGuestJob = new CopyFileToGuestJob(Job))
                                        {
                                            ViridianUtils.WaitForCopyFileToGuestJobToEnd(Job);

                                            copyFileToGuestJob.LateBoundObject.Properties.Cast <PropertyData>().ToList().ForEach((p) => Trace.WriteLine($"{p.Name} [{p.Value?.ToString()}]"));

                                            lastErrorcode = copyFileToGuestJob.ErrorCode;
                                            fileExists    = copyFileToGuestJob.ErrorDescription.Contains("The file exists. (0x80070050)");

                                            if (fileExists)
                                            {
                                                break;
                                            }

                                            Thread.Sleep(new TimeSpan(0, retryWaitTime, 0));
                                        }
                                    }

                                    Assert.AreEqual(32768, lastErrorcode);
                                    Assert.IsTrue(fileExists);
                                }

                        ReturnValue = computerSystem.RequestStateChange(3, null, out Job);

                        ViridianUtils.WaitForConcreteJobToEnd(Job);

                        viridianUtils.Dispose(); // force destroy system

                        var vhdxMO = ResultingResourceSettings[0];

                        var jobsAffectingVHDX =
                            AffectedJobElement.GetInstances()
                            .Where((aje) => string.Compare(aje.AffectedElement.Path, vhdxMO.Path, true, CultureInfo.InvariantCulture) == 0)
                            .Select((aje) => aje.AffectingElement)
                            .ToList();

                        jobsAffectingVHDX.ForEach((job) => ViridianUtils.WaitForConcreteJobToEnd(Job));

                        File.Delete(vhdxName);
                    }
                }

                File.Delete(isoName);
            }
        }