diff options
author | olaaun <ola.aunroe@gmail.com> | 2017-08-07 15:29:06 +0800 |
---|---|---|
committer | Andreas Eriksen <andreer@pvv.ntnu.no> | 2017-08-07 09:29:06 +0200 |
commit | fc9d090fb349a69f1a025b9b808f1ade2ef6247a (patch) | |
tree | d4b147b67de60018a2f787c8376754f1c546d7e9 /node-maintainer | |
parent | 3055b8c99bfdaf304648b0156ede5c797c881080 (diff) |
Interns/verification fix 3 (#3047)
* Fixed failing ping parsing
* Replace regex with InetAddresses
* NetRetriever now also accepts interfaces other than eth.
Diffstat (limited to 'node-maintainer')
12 files changed, 59 insertions, 128 deletions
diff --git a/node-maintainer/pom.xml b/node-maintainer/pom.xml index f511f5c2a08..d56e12d92c6 100644 --- a/node-maintainer/pom.xml +++ b/node-maintainer/pom.xml @@ -67,6 +67,11 @@ <artifactId>commons-exec</artifactId> <version>1.3</version> </dependency> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + <version>18.0</version> + </dependency> </dependencies> <build> diff --git a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/OutputParser.java b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/OutputParser.java index 09060bdebdf..0df3ff31dae 100644 --- a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/OutputParser.java +++ b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/OutputParser.java @@ -37,45 +37,6 @@ public class OutputParser { return parseResults.get(0); } - public static ArrayList<ParseResult> parseOutPutWithSkips(ParseInstructions parseInstructions, ArrayList<String> commandOutput) { - ArrayList<ParseResult> results = new ArrayList<>(); - int searchElementIndex = parseInstructions.getSearchElementIndex(); - int valueElementIndex = parseInstructions.getValueElementIndex(); - String skipWord = parseInstructions.getSkipWord(); - ArrayList<String> searchWords = parseInstructions.getSearchWords(); - for (int i = 0; i < commandOutput.size(); i++) { - String line = commandOutput.get(i); - String[] lineSplit = line.trim().split(parseInstructions.getSplitRegex()); - if (lineSplit.length <= Math.max(searchElementIndex, valueElementIndex)) { - continue; - } - if (lineSplit[searchElementIndex].equals(skipWord)) { - i = skipToIndex(i, parseInstructions, commandOutput); - continue; - } - String searchWordCandidate = lineSplit[searchElementIndex]; - boolean searchWordCandidateMatch = matchingSearchWord(searchWords, searchWordCandidate); - if (searchWordCandidateMatch) { - String value = lineSplit[valueElementIndex]; - results.add(new ParseResult(searchWordCandidate, value.trim())); - } - } - return results; - } - - protected static int skipToIndex(int index, ParseInstructions parseInstructions, ArrayList<String> commandOutput) { - String skipUntilKeyword = parseInstructions.getSkipUntilKeyword(); - int returnIndex = commandOutput.size(); - for (int i = index; i < commandOutput.size(); i++) { - String line = commandOutput.get(i); - if (line.equals(skipUntilKeyword)) { - returnIndex = i; - break; - } - } - return returnIndex - 1; - } - private static boolean matchingSearchWord(ArrayList<String> searchWords, String searchWordCandidate) { return searchWords.stream().anyMatch(w -> Pattern.compile(w).matcher(searchWordCandidate).matches()); } diff --git a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/spec/noderepo/NodeRepoJsonModel.java b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/spec/noderepo/NodeRepoJsonModel.java index 3b7f2058ca3..f708057f6a5 100644 --- a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/spec/noderepo/NodeRepoJsonModel.java +++ b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/spec/noderepo/NodeRepoJsonModel.java @@ -2,9 +2,15 @@ package com.yahoo.vespa.hosted.node.verification.spec.noderepo; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.net.InetAddresses; import com.yahoo.vespa.hosted.node.verification.spec.retrievers.HardwareInfo; import com.yahoo.vespa.hosted.node.verification.spec.retrievers.HardwareInfo.DiskType; +import java.net.Inet4Address; +import java.net.Inet6Address; +import java.net.InetAddress; +import java.util.stream.Stream; + /** * Created by olaa on 05/07/2017. * Object with the information node repositories has about the node. @@ -44,23 +50,17 @@ public class NodeRepoJsonModel { } public String getIpv6Address() { - String ipv6Regex = "^((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4}))*::((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4}))*|((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4})){7}$"; - for (String ipAddress : ipAddresses) { - if (ipAddress.matches(ipv6Regex)) { - return ipAddress; - } - } - return null; + return Stream.of(ipAddresses) + .map(InetAddresses::forString) + .filter(ip -> ip instanceof Inet6Address) + .findFirst().map(InetAddress::getHostAddress).orElse(null); } public String getIpv4Address() { - String ipv4Regex = "^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$"; - for (String ipAddress : ipAddresses) { - if (ipAddress.matches(ipv4Regex)) { - return ipAddress; - } - } - return null; + return Stream.of(ipAddresses) + .map(InetAddresses::forString) + .filter(ip -> ip instanceof Inet4Address) + .findFirst().map(InetAddress::getHostAddress).orElse(null); } public double getMinDiskAvailableGb() { diff --git a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/spec/retrievers/NetRetriever.java b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/spec/retrievers/NetRetriever.java index 6bf5d7b300d..c775ee7a846 100644 --- a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/spec/retrievers/NetRetriever.java +++ b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/spec/retrievers/NetRetriever.java @@ -16,25 +16,23 @@ import java.util.logging.Logger; * Created by olaa on 30/06/2017. */ public class NetRetriever implements HardwareRetriever { - private static final String NET_FIND_INTERFACE = "/sbin/ifconfig"; + private static final String NET_FIND_INTERFACE = "/sbin/ifconfig | awk 'BEGIN {RS=\"\\n\\n\"; } { if ( $1 != \"lo\") {print} }'"; private static final String NET_CHECK_INTERFACE_SPEED = "/sbin/ethtool"; private static final String SEARCH_WORD_INTERFACE_IP4 = "inet"; private static final String SEARCH_WORD_INTERFACE_IPV6 = "inet6"; - private static final String SEARCH_WORD_INTERFACE_NAME = "eth."; + private static final String SEARCH_WORD_INTERFACE_NAME = "interface name"; private static final String SEARCH_WORD_INTERFACE_SPEED = "Speed"; private static final String INTERFACE_NAME_REGEX_SPLIT = "\\s+"; - private static final String INTERFACE_NAME_SKIP_WORD = "lo"; - private static final String INTERFACE_NAME_SKIP_UNTIL_WORD = ""; - private static final int INTERFACE_NAME_SEARCH_ELEMENT_INDEX = 0; - private static final int INTERFACE_NAME_RETURN_ELEMENT_INDEX = 0; + private static final int INTERFACE_SEARCH_ELEMENT_INDEX = 0; + private static final int INTERFACE_RETURN_ELEMENT_INDEX = 0; private static final String INTERFACE_SPEED_REGEX_SPLIT = ":"; private static final int INTERFACE_SPEED_SEARCH_ELEMENT_INDEX = 0; private static final int INTERFACE_SPEED_RETURN_ELEMENT_INDEX = 1; - private static final String PING_NET_COMMAND = "ping6 -c 1 www.yahoo.com | grep transmitted"; - private static final String PING_SEARCH_WORD = "loss,"; + private static final String PING_NET_COMMAND = "ping6 -c 1 -q www.yahoo.com | grep -oP '\\d+(?=% packet loss)'"; + private static final String PING_SEARCH_WORD = "\\d+\\.?\\d*"; private static final String PING_SPLIT_REGEX_STRING = "\\s+"; - private static final int PING_SEARCH_ELEMENT_INDEX = 7; - private static final int PING_RETURN_ELEMENT_INDEX = 5; + private static final int PING_SEARCH_ELEMENT_INDEX = 0; + private static final int PING_RETURN_ELEMENT_INDEX = 0; private static final Logger logger = Logger.getLogger(NetRetriever.class.getName()); private final HardwareInfo hardwareInfo; private final CommandExecutor commandExecutor; @@ -65,17 +63,16 @@ public class NetRetriever implements HardwareRetriever { } protected ArrayList<ParseResult> parseNetInterface(ArrayList<String> commandOutput) { - ArrayList<String> searchWords = new ArrayList<>(Arrays.asList(SEARCH_WORD_INTERFACE_IP4, SEARCH_WORD_INTERFACE_IPV6, SEARCH_WORD_INTERFACE_NAME)); - ParseInstructions parseInstructions = new ParseInstructions(INTERFACE_NAME_SEARCH_ELEMENT_INDEX, INTERFACE_NAME_RETURN_ELEMENT_INDEX, INTERFACE_NAME_REGEX_SPLIT, searchWords); - parseInstructions.setSkipWord(INTERFACE_NAME_SKIP_WORD); - parseInstructions.setSkipUntilKeyword(INTERFACE_NAME_SKIP_UNTIL_WORD); - ArrayList<ParseResult> parseResults = OutputParser.parseOutPutWithSkips(parseInstructions, commandOutput); + ArrayList<String> searchWords = new ArrayList<>(Arrays.asList(SEARCH_WORD_INTERFACE_IP4, SEARCH_WORD_INTERFACE_IPV6)); + ParseInstructions parseInstructions = new ParseInstructions(INTERFACE_SEARCH_ELEMENT_INDEX, INTERFACE_RETURN_ELEMENT_INDEX, INTERFACE_NAME_REGEX_SPLIT, searchWords); + ArrayList<ParseResult> parseResults = OutputParser.parseOutput(parseInstructions, commandOutput); + parseResults.add(findInterfaceName(commandOutput)); return parseResults; } protected void findInterfaceSpeed(ArrayList<ParseResult> parseResults) { try { - String interfaceName = findInterfaceName(parseResults); + String interfaceName = getInterfaceName(parseResults); String command = NET_CHECK_INTERFACE_SPEED + " " + interfaceName; ArrayList<String> commandOutput = commandExecutor.executeCommand(command); ParseResult parseResult = parseInterfaceSpeed(commandOutput); @@ -85,7 +82,15 @@ public class NetRetriever implements HardwareRetriever { } } - protected String findInterfaceName(ArrayList<ParseResult> parseResults) { + protected ParseResult findInterfaceName(ArrayList<String> commandOutput) { + try { + return new ParseResult(SEARCH_WORD_INTERFACE_NAME, commandOutput.get(0).trim().split(" ")[0]); + } catch (NullPointerException e) { + return new ParseResult("invalid", "invalid"); + } + } + + protected String getInterfaceName(ArrayList<ParseResult> parseResults) { for (ParseResult parseResult : parseResults) { if (!parseResult.getSearchWord().matches(SEARCH_WORD_INTERFACE_NAME)) continue; return parseResult.getValue(); @@ -121,7 +126,7 @@ public class NetRetriever implements HardwareRetriever { if (!parseResult.getSearchWord().matches(PING_SEARCH_WORD)) { throw new IOException("Failed to parse ping output."); } - return parseResult; + return new ParseResult(PING_SEARCH_WORD, parseResult.getValue()); } protected void updateHardwareInfoWithNet(ArrayList<ParseResult> parseResults) { diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/commons/OutputParserTest.java b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/commons/OutputParserTest.java index 056ee2cc5c4..6fc4b7f1b0f 100644 --- a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/commons/OutputParserTest.java +++ b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/commons/OutputParserTest.java @@ -22,7 +22,6 @@ public class OutputParserTest { private static final String SEARCH_WORD_1 = "Parsing"; private static final String SEARCH_WORD_2 = "this"; private static final String REGEX_SEARCH_WORD = ".*S.*"; - private static final String PARSE_OUTPUT_WITH_SKIPS_TEST_FILE = "src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/parseOutputWithSkipsTest"; private ArrayList<String> commandOutput; private ArrayList<String> searchWords; @@ -82,28 +81,4 @@ public class OutputParserTest { assertEquals(expectedParseResult, parseResult); } - @Test - public void parseOutputWithSkips_should_return_two_matches() throws IOException { - searchWords = new ArrayList<>(Arrays.asList(SEARCH_WORD_1)); - ParseInstructions parseInstructions = new ParseInstructions(1, 7, " ", searchWords); - parseInstructions.setSkipWord("SkipFromKeyword"); - parseInstructions.setSkipUntilKeyword("skipUntilKeyword"); - ArrayList<String> commandSkipOutput = MockCommandExecutor.readFromFile(PARSE_OUTPUT_WITH_SKIPS_TEST_FILE); - ArrayList<ParseResult> parseResults = OutputParser.parseOutPutWithSkips(parseInstructions, commandSkipOutput); - ParseResult expectedParseResult = new ParseResult(SEARCH_WORD_1, RETURN_VALUE); - assertEquals(expectedParseResult, parseResults.get(0)); - assertEquals(expectedParseResult, parseResults.get(1)); - } - - @Test - public void skipToIndex_should_return_correct_index() throws IOException { - searchWords = new ArrayList<>(Arrays.asList(SEARCH_WORD_1)); - ParseInstructions parseInstructions = new ParseInstructions(0, 0, " ", searchWords); - parseInstructions.setSkipUntilKeyword("skipUntilKeyword"); - ArrayList<String> commandSkipOutput = MockCommandExecutor.readFromFile(PARSE_OUTPUT_WITH_SKIPS_TEST_FILE); - int indexReturned = OutputParser.skipToIndex(3, parseInstructions, commandSkipOutput); - int expectedReturnIndex = 10; - assertEquals(expectedReturnIndex, indexReturned); - } - }
\ No newline at end of file diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/SpecVerifierTest.java b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/SpecVerifierTest.java index f8b960749c6..710ece48631 100644 --- a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/SpecVerifierTest.java +++ b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/SpecVerifierTest.java @@ -109,7 +109,7 @@ public class SpecVerifierTest { double expectedMinMainMemoryAvailableGb = 4.04D; double expectedMinDiskAvailableGb = 1759.84; boolean expectedFastDisk = true; - String expectedIpv6Address = "2001:4998:c:2940::111c"; + String expectedIpv6Address = "2001:4998:c:2940:0:0:0:111c"; assertEquals(expectedIpv6Address, actualNodeRepoJsonModel.getIpv6Address()); assertEquals(expectedMinCpuCores, actualNodeRepoJsonModel.getMinCpuCores(), DELTA); assertEquals(expectedMinMainMemoryAvailableGb, actualNodeRepoJsonModel.getMinMainMemoryAvailableGb(), DELTA); diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/noderepo/IPAddressVerifierTest.java b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/noderepo/IPAddressVerifierTest.java index aa2b2104e38..cb809613d5e 100644 --- a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/noderepo/IPAddressVerifierTest.java +++ b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/noderepo/IPAddressVerifierTest.java @@ -28,7 +28,7 @@ public class IPAddressVerifierTest { @Before public void setup() throws Exception { ipv4Address = "10.213.181.113"; - ipv6Address = "2001:4998:c:2940::111c"; + ipv6Address = "2001:4998:c:2940:0:0:0:111c"; ArrayList<URL> nodeRepoUrl = new ArrayList<>(Arrays.asList(new URL(URL_RESOURCE_PATH))); nodeRepoJsonModel = NodeRepoInfoRetriever.retrieve(nodeRepoUrl); ipv4LookupFormat = "113.181.213.10.in-addr.arpa"; diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/ifconfig b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/ifconfig index 70ef5ea8cdc..51cd95e1351 100755 --- a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/ifconfig +++ b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/ifconfig @@ -7,10 +7,3 @@ eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:03 collisions:0 txqueuelen:0 RX bytes:75003406 (71.5 MiB) TX bytes:1839045 (1.7 MiB) -lo Link encap:Local Loopback - inet addr:127.0.0.1 Mask:255.0.0.0 - UP LOOPBACK RUNNING MTU:65536 Metric:1 - RX packets:2 errors:0 dropped:0 overruns:0 frame:0 - TX packets:2 errors:0 dropped:0 overruns:0 carrier:0 - collisions:0 txqueuelen:1 - RX bytes:100 (100.0 b) TX bytes:100 (100.0 b) diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/ifconfigNoIpv6 b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/ifconfigNoIpv6 index 1e21b9e1195..773d9576bde 100755 --- a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/ifconfigNoIpv6 +++ b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/ifconfigNoIpv6 @@ -1,11 +1,3 @@ -lo Link encap:Local Loopback - inet addr:127.0.0.1 Mask:255.0.0.0 - UP LOOPBACK RUNNING MTU:65536 Metric:1 - RX packets:2 errors:0 dropped:0 overruns:0 frame:0 - TX packets:2 errors:0 dropped:0 overruns:0 carrier:0 - collisions:0 txqueuelen:1 - RX bytes:100 (100.0 b) TX bytes:100 (100.0 b) - eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:03 inet addr:172.17.0.3 Bcast:0.0.0.0 Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/pingresponse-all-packets-lost b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/pingresponse-all-packets-lost index 0e6a67d3d89..29d6383b52c 100644 --- a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/pingresponse-all-packets-lost +++ b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/pingresponse-all-packets-lost @@ -1 +1 @@ -6 packets transmitted, 6 received, 100% packet loss, time 5002ms +100 diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/validpingresponse b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/validpingresponse index f6ef0559571..c227083464f 100644 --- a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/validpingresponse +++ b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/validpingresponse @@ -1 +1 @@ -6 packets transmitted, 6 received, 0% packet loss, time 5002ms +0
\ No newline at end of file diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/retrievers/NetRetrieverTest.java b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/retrievers/NetRetrieverTest.java index 73678d4a3b1..e20304b8448 100644 --- a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/retrievers/NetRetrieverTest.java +++ b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/retrievers/NetRetrieverTest.java @@ -24,7 +24,7 @@ public class NetRetrieverTest { private static final String NET_CHECK_INTERFACE_SPEED = RESOURCE_PATH + "eth0"; private static String VALID_PING_RESPONSE = RESOURCE_PATH + "validpingresponse"; private static String INVALID_PING_RESPONSE = RESOURCE_PATH + "invalidpingresponse"; - private static String PING_SEARCH_WORD = "loss,"; + private static String PING_SEARCH_WORD = "\\d+\\.?\\d*"; private HardwareInfo hardwareInfo; private MockCommandExecutor commandExecutor; private NetRetriever net; @@ -56,8 +56,8 @@ public class NetRetrieverTest { public void findInterface_valid_input() throws IOException { commandExecutor.addCommand("cat " + NET_FIND_INTERFACE); parseResults = net.findInterface(); - ParseResult expectedParseResult = new ParseResult("eth0", "eth0"); - assertEquals(expectedParseResult, parseResults.get(0)); + ParseResult expectedParseResult = new ParseResult("interface name", "eth0"); + assertEquals(expectedParseResult, parseResults.get(2)); } @Test @@ -84,8 +84,8 @@ public class NetRetrieverTest { ArrayList<String> mockOutput = MockCommandExecutor.readFromFile(NET_FIND_INTERFACE + "NoIpv6"); parseResults = net.parseNetInterface(mockOutput); ArrayList<ParseResult> expextedParseResults = new ArrayList<>(Arrays.asList( - new ParseResult("eth0", "eth0"), - new ParseResult("inet", "inet"))); + new ParseResult("inet", "inet"), + new ParseResult("interface name", "eth0"))); assertEquals(expextedParseResults, parseResults); } @@ -93,7 +93,7 @@ public class NetRetrieverTest { public void parseNetInterface_get_interfaceName_from_ifconfig_testFile() throws IOException { ArrayList<String> mockOutput = MockCommandExecutor.readFromFile(NET_FIND_INTERFACE); parseResults = net.parseNetInterface(mockOutput); - String interfaceName = net.findInterfaceName(parseResults); + String interfaceName = net.getInterfaceName(parseResults); String expectedInterfaceName = "eth0"; assertEquals(expectedInterfaceName, interfaceName); } @@ -108,21 +108,21 @@ public class NetRetrieverTest { @Test public void findInterfaceName_should_return_interface_name() { - parseResults.add(new ParseResult("eth0", "eth0")); + parseResults.add(new ParseResult("interface name", "eth0")); String expectedInterfaceName = "eth0"; - assertEquals(expectedInterfaceName, net.findInterfaceName(parseResults)); + assertEquals(expectedInterfaceName, net.getInterfaceName(parseResults)); } @Test public void findInterfaceName_should_return_empty_interface_name() { parseResults.add(new ParseResult("et", "et0")); String expectedInterfaceName = ""; - assertEquals(expectedInterfaceName, net.findInterfaceName(parseResults)); + assertEquals(expectedInterfaceName, net.getInterfaceName(parseResults)); } @Test public void updateHardwareinfoWithNet_valid_input() { - parseResults.add(new ParseResult("eth0", "eth0")); + parseResults.add(new ParseResult("interface name", "eth0")); parseResults.add(new ParseResult("inet", "inet")); parseResults.add(new ParseResult("inet6", "inet6")); parseResults.add(new ParseResult("Speed", "1000Mb/s")); @@ -145,7 +145,7 @@ public class NetRetrieverTest { public void parsePingResponse_valid_ping_response_should_return_ipv6_connectivity() throws IOException { ArrayList<String> mockCommandOutput = MockCommandExecutor.readFromFile(VALID_PING_RESPONSE); ParseResult parseResult = net.parsePingResponse(mockCommandOutput); - String expectedPing = "0%"; + String expectedPing = "0"; assertEquals(expectedPing, parseResult.getValue()); } @@ -163,14 +163,14 @@ public class NetRetrieverTest { @Test public void setIpv6Connectivity_valid_ping_response_should_return_ipv6_connectivity() { - ParseResult parseResult = new ParseResult(PING_SEARCH_WORD, "0%"); + ParseResult parseResult = new ParseResult(PING_SEARCH_WORD, "0"); net.setIpv6Connectivity(parseResult); assertTrue(hardwareInfo.isIpv6Connection()); } @Test public void setIpv6Connectivity_invalid_ping_response_should_return_no_ipv6_connectivity_1() { - ParseResult parseResult = new ParseResult(PING_SEARCH_WORD, "100%"); + ParseResult parseResult = new ParseResult(PING_SEARCH_WORD, "100"); net.setIpv6Connectivity(parseResult); assertFalse(hardwareInfo.isIpv6Connection()); } |