private static string TestStartCommand() { // Arrange HypervResourceController rsrcServer = new HypervResourceController(); String sample = getSampleStartCommand(); dynamic jsonStartCmd = JsonConvert.DeserializeObject(sample); // Act dynamic startAns = rsrcServer.StartCommand(jsonStartCmd); // Assert Assert.IsNotNull(startAns[0][CloudStackTypes.StartAnswer], "StartCommand should return a StartAnswer in all cases"); Assert.IsTrue((bool)startAns[0][CloudStackTypes.StartAnswer].result, "StartCommand did not succeed " + startAns[0][CloudStackTypes.StartAnswer].details); string vmCmdName = jsonStartCmd.vm.name.Value; var vm = WmiCalls.GetComputerSystem(vmCmdName); VirtualSystemSettingData vmSettings = WmiCalls.GetVmSettings(vm); MemorySettingData memSettings = WmiCalls.GetMemSettings(vmSettings); ProcessorSettingData procSettings = WmiCalls.GetProcSettings(vmSettings); dynamic jsonObj = JsonConvert.DeserializeObject(sample); var vmInfo = jsonObj.vm; string vmName = vmInfo.name; var nicInfo = vmInfo.nics; int vcpus = vmInfo.cpus; int memSize = vmInfo.maxRam / 1048576; Assert.IsTrue((long)memSettings.VirtualQuantity == memSize); Assert.IsTrue((long)memSettings.Reservation == memSize); Assert.IsTrue((long)memSettings.Limit == memSize); Assert.IsTrue((int)procSettings.VirtualQuantity == vcpus); Assert.IsTrue((int)procSettings.Reservation == vcpus); Assert.IsTrue((int)procSettings.Limit == 100000); // examine NIC SyntheticEthernetPortSettingData[] nicSettingsViaVm = WmiCalls.GetEthernetPorts(vm); Assert.IsTrue(nicSettingsViaVm.Length > 0, "Should be at least one ethernet port on VM"); string expectedMac = (string)jsonStartCmd.vm.nics[0].mac; string strippedExpectedMac = expectedMac.Replace(":", string.Empty); Assert.AreEqual(nicSettingsViaVm[0].Address.ToLower(), strippedExpectedMac.ToLower()); // Assert switchport has correct VLAN SwitchPort[] switchPorts = WmiCalls.GetSwitchPorts(vm); VirtualSwitchManagementService vmNetMgmtSvc = WmiCalls.GetVirtualSwitchManagementService(); VLANEndpointSettingData vlanSettings = WmiCalls.GetVlanEndpointSettings(vmNetMgmtSvc, switchPorts[0].Path); string isolationUri = (string)jsonStartCmd.vm.nics[0].isolationUri; string vlan = isolationUri.Replace("vlan://", string.Empty); Assert.AreEqual(vlanSettings.AccessVLAN.ToString(), vlan); return vmName; }
public void TestStartCommand() { ComputerSystem system = new ComputerSystem(); wmiCallsV2.DeployVirtualMachine(Arg.Any<Object>(), Arg.Any<string>()).Returns(system); // Arrange HypervResourceController rsrcServer = new HypervResourceController(); HypervResourceController.wmiCallsV2 = wmiCallsV2; String sample = getSampleStartCommand(); dynamic jsonStartCmd = JsonConvert.DeserializeObject(sample); // Act dynamic startAns = rsrcServer.StartCommand(jsonStartCmd); // Assert Assert.NotNull(startAns[0][CloudStackTypes.StartAnswer]); Assert.True((bool)startAns[0][CloudStackTypes.StartAnswer].result, "StartCommand did not succeed " + startAns[0][CloudStackTypes.StartAnswer].details); Assert.Null((string)startAns[0][CloudStackTypes.StartAnswer].details); }
private static string TestStartCommand() { // Arrange HypervResourceController rsrcServer = new HypervResourceController(); String sample = getSampleStartCommand(); dynamic jsonStartCmd = JsonConvert.DeserializeObject(sample); // Act dynamic startAns = rsrcServer.StartCommand(jsonStartCmd); // Assert Assert.NotNull(startAns[0][CloudStackTypes.StartAnswer]); Assert.True((bool)startAns[0][CloudStackTypes.StartAnswer].result, "StartCommand did not succeed " + startAns[0][CloudStackTypes.StartAnswer].details); string vmCmdName = jsonStartCmd.vm.name.Value; var vm = wmiCallsV2.GetComputerSystem(vmCmdName); var vmSettings = wmiCallsV2.GetVmSettings(vm); var memSettings = wmiCallsV2.GetMemSettings(vmSettings); var procSettings = wmiCallsV2.GetProcSettings(vmSettings); dynamic jsonObj = JsonConvert.DeserializeObject(sample); var vmInfo = jsonObj.vm; string vmName = vmInfo.name; var nicInfo = vmInfo.nics; int vcpus = vmInfo.cpus; int memSize = vmInfo.maxRam / 1048576; Assert.True((long)memSettings.VirtualQuantity == memSize); Assert.True((long)memSettings.Reservation == memSize); Assert.True((long)memSettings.Limit == memSize); Assert.True((int)procSettings.VirtualQuantity == vcpus); Assert.True((int)procSettings.Reservation == vcpus); Assert.True((int)procSettings.Limit == 100000); // examine NIC for correctness var nicSettingsViaVm = wmiCallsV2.GetEthernetPortSettings(vm); Assert.True(nicSettingsViaVm.Length > 0, "Should be at least one ethernet port on VM"); string expectedMac = (string)jsonStartCmd.vm.nics[0].mac; string strippedExpectedMac = expectedMac.Replace(":", string.Empty); Assert.Equal(nicSettingsViaVm[0].Address.ToLower(), strippedExpectedMac.ToLower()); // Assert switchport has correct VLAN var ethernetConnections = wmiCallsV2.GetEthernetConnections(vm); var vlanSettings = wmiCallsV2.GetVlanSettings(ethernetConnections[0]); string isolationUri = (string)jsonStartCmd.vm.nics[0].isolationUri; string vlan = isolationUri.Replace("vlan://", string.Empty); Assert.Equal(vlanSettings.AccessVlanId.ToString(), vlan); return vmName; }