public void Nats(bool isAdmin) { try { using (CreateService(isAdmin)) { var hyperVProxy = new HyperVProxy(isAdmin, socketPath); // We're just going to list NATs because we don't want mess with // creating new swiches right now. var nats = hyperVProxy.ListNats(); foreach (var item in nats) { var nat = hyperVProxy.GetNatByName(item.Name); Assert.NotNull(nat); Assert.Equal(item.Name, nat.Name); Assert.Equal(item.Subnet, nat.Subnet); nat = hyperVProxy.GetNatBySubnet(item.Subnet); Assert.NotNull(nat); Assert.Equal(item.Name, nat.Name); Assert.Equal(item.Subnet, nat.Subnet); } } } finally { ClearState(); } }
public void Switches(bool isAdmin) { try { using (CreateService(isAdmin)) { var hyperVProxy = new HyperVProxy(isAdmin, socketPath); // List existing switches. var switches = hyperVProxy.ListSwitches(); Assert.NotEmpty(switches); foreach (var item in switches) { var @switch = hyperVProxy.GetSwitch(item.Name); Assert.NotNull(@switch); Assert.Equal(item.Name, @switch.Name); } // $todo(jefflill): // // There isn't an easy way to test switch creation without the serious // possibility of messing with the Hyper-V configuration so we'll defer // this until the future. } } finally { ClearState(); } }
public void GetWindowsOptionalFeatures(bool isAdmin) { using (CreateService(isAdmin)) { var hyperVProxy = new HyperVProxy(isAdmin, socketPath); var features = hyperVProxy.GetWindowsOptionalFeatures(); Assert.NotEmpty(features); } }
public void IsNestedVirtualization(bool isAdmin) { using (CreateService(isAdmin)) { var hyperVProxy = new HyperVProxy(isAdmin, socketPath); var isNested = hyperVProxy.IsNestedVirtualization; #pragma warning disable CA1416 Assert.Equal(global::Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Virtual Machine\Auto", "OSName", null) != null, isNested); #pragma warning restore CA1416 } }
public void VirtualMachines(bool isAdmin) { try { using (CreateService(isAdmin)) { var hyperVProxy = new HyperVProxy(isAdmin, socketPath); // List VMs before we create any below. We had an issue once where we'd see // a [NullReferenceException] when there were no VMs. var vms = hyperVProxy.ListVms(); // Create a VM and verify. hyperVProxy.AddVm( machineName: TestMachineName1, memorySize: "1 GiB", processorCount: 2, drivePath: test1VhdxPath, checkpointDrives: false, templateDrivePath: templatePath, switchName: "External"); var vm = hyperVProxy.GetVm(machineName: TestMachineName1); Assert.NotNull(vm); Assert.Equal(TestMachineName1, vm.Name); Assert.Equal(VirtualMachineState.Off, vm.State); Assert.Equal("External", vm.SwitchName); // Start the VM and verify. hyperVProxy.StartVm(machineName: TestMachineName1); vm = hyperVProxy.GetVm(machineName: TestMachineName1); Assert.NotNull(vm); Assert.Equal(VirtualMachineState.Running, vm.State); // Fetch the VM network adapters. var adapters = hyperVProxy.GetVmNetworkAdapters(TestMachineName1); Assert.NotNull(adapters); Assert.NotEmpty(adapters); // Save the VM and verify. hyperVProxy.SaveVm(machineName: TestMachineName1); vm = hyperVProxy.GetVm(machineName: TestMachineName1); Assert.NotNull(vm); Assert.Equal(VirtualMachineState.Saved, vm.State); // Create and start another VM and verify. hyperVProxy.AddVm( machineName: TestMachineName2, memorySize: "1 GiB", processorCount: 2, drivePath: test2VhdxPath, checkpointDrives: false, templateDrivePath: templatePath, switchName: "External"); vm = hyperVProxy.GetVm(machineName: TestMachineName2); Assert.NotNull(vm); Assert.Equal(TestMachineName2, vm.Name); Assert.Equal(VirtualMachineState.Off, vm.State); Assert.Equal("External", vm.SwitchName); hyperVProxy.StartVm(machineName: TestMachineName2); vm = hyperVProxy.GetVm(machineName: TestMachineName2); Assert.Equal(VirtualMachineState.Running, vm.State); // List and check the VM existence. var list = hyperVProxy.ListVms(); Assert.Contains(list, item => item.Name == TestMachineName1); Assert.Contains(list, item => item.Name == TestMachineName2); Assert.True(hyperVProxy.VmExists(TestMachineName1)); Assert.True(hyperVProxy.VmExists(TestMachineName2)); Assert.False(hyperVProxy.VmExists(Guid.NewGuid().ToString("d"))); // Test DVD/CD insert and eject operations. using (var tempFolder = new TempFolder()) { var isoFolder = Path.Combine(tempFolder.Path, "iso-contents"); var isoPath = Path.Combine(tempFolder.Path, "data.iso"); Directory.CreateDirectory(isoFolder); File.WriteAllText(Path.Combine(isoFolder, "hello.txt"), "HELLO WORLD!"); KubeHelper.CreateIsoFile(isoFolder, isoPath); // $todo(jefflill): Eject is failing: // // https://github.com/nforgeio/neonKUBE/issues/1456 // hyperVProxy.InsertVmDvd(TestMachineName2, isoPath); // hyperVProxy.EjectVmDvd(TestMachineName2); } // Stop the second VM and verify. hyperVProxy.StopVm(machineName: TestMachineName2, turnOff: true); vm = hyperVProxy.GetVm(machineName: TestMachineName2); Assert.Equal(VirtualMachineState.Off, vm.State); // Add a drive to the second VM and verify. hyperVProxy.AddVmDrive(TestMachineName2, new VirtualDrive() { Path = extraVhdxPath, Size = 1 * ByteUnits.GibiBytes, IsDynamic = true }); var drives = hyperVProxy.GetVmDrives(machineName: TestMachineName1); // $todo(jefflill): We should be seeing two drives here: // // https://github.com/nforgeio/neonKUBE/issues/1455 Assert.NotEmpty(drives); // Assert.Equal(2, drives.Count); // Compact the extra drive we added to the second VM. hyperVProxy.CompactDrive(extraVhdxPath); // Remove the VMs and verify. hyperVProxy.RemoveVm(machineName: TestMachineName1, keepDrives: false); Assert.Null(hyperVProxy.GetVm(machineName: TestMachineName1)); } } finally { ClearState(); } }