XenHypervisor implements HypervisorHost { protected String getHostPrivateMacAddress(HostVO hostVo) { String returnOfArpCommand = shellCommandUtils.executeCommand(String.format(FIND_ARP_FOR_HOST_COMMAND, hostVo.getPrivateIpAddress())); Matcher matcher = compileRegexToGetArp.matcher(returnOfArpCommand); if (matcher.find()) { return matcher.group(1); } throw new CloudRuntimeException(String.format("Could not find host [name=%s, privateAddress=%s] private mac address.", hostVo.getName(), hostVo.getPrivateIpAddress())); }  @Override void shutdownHost(HostVO hostVo); @Override boolean supportsHypervisor(HypervisorType hypervisorType);  }
@Test public void getHostPrivateMacAddressTest() { String expected = "00:00:00:00:00:00"; String arpResult = "0.0.0.0 ether 00:00:00:00:00:00 C interface"; HostVO hostVo = new HostVO(""); hostVo.setPrivateIpAddress(""); Mockito.doReturn(arpResult).when(shellCommandUtils).executeCommand(Mockito.anyString()); String result = xenHypervisor.getHostPrivateMacAddress(hostVo); Assert.assertEquals(EXPECTED_REGEX_GET_ARP_FROM_ARP_COMMAND_OUTPUT, XenHypervisor.REGEX_GET_ARP_FROM_ARP_COMMAND_OUTPUT); Assert.assertEquals(EXPECTED_FIND_ARP_FOR_HOST_COMMAND, XenHypervisor.FIND_ARP_FOR_HOST_COMMAND); Assert.assertEquals(expectedCompileRegexToGetArp.toString(), xenHypervisor.compileRegexToGetArp.toString()); Assert.assertEquals(expected, result); }
@Test(expected = CloudRuntimeException.class) public void getHostPrivateMacAddressTestExpectException() { String arpResult = "0.0.0.0 ether 00:00:00:00:00 C interface"; HostVO hostVo = new HostVO(""); hostVo.setPrivateIpAddress(""); Mockito.doReturn(arpResult).when(shellCommandUtils).executeCommand(Mockito.anyString()); xenHypervisor.getHostPrivateMacAddress(hostVo); }