From 0cfcb882df47df13b58ac3fd1a7f12db55d48ba7 Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Tue, 7 May 2019 09:12:45 +0200 Subject: Disallow child node from having an IP address pool --- .../java/com/yahoo/vespa/hosted/provision/Node.java | 2 ++ .../vespa/hosted/provision/restapi/v2/RestApiTest.java | 18 ++++-------------- .../hosted/provision/restapi/v2/responses/node11.json | 5 +---- 3 files changed, 7 insertions(+), 18 deletions(-) (limited to 'node-repository') diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java index 196aea3e4a5..188829a24ba 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java @@ -78,6 +78,8 @@ public final class Node { if (state == State.active) requireNonEmpty(ipAddresses, "An active node must have at least one valid IP address"); + if (parentHostname.isPresent() && !ipAddressPool.isEmpty()) + throw new IllegalArgumentException("A child node cannot have an IP address pool"); this.ipAddresses = ImmutableSet.copyOf(ipAddresses); this.ipAddressPool = new IP.AddressPool(this, ipAddressPool); diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java index 64f9326f607..0c403777f3e 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java @@ -23,7 +23,6 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.regex.Pattern; import java.util.stream.Collectors; -import java.util.stream.IntStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -105,9 +104,9 @@ public class RestApiTest { // POST new nodes assertResponse(new Request("http://localhost:8080/nodes/v2/node", ("[" + asNodeJson("host8.yahoo.com", "default", "127.0.0.1") + "," + // test with only 1 ip address - asNodeJson("host9.yahoo.com", "large-variant", "127.0.0.1", "::1") + "," + - asHostJson("parent2.yahoo.com", "large-variant", "127.0.0.1", "::1") + "," + - asDockerNodeJson("host11.yahoo.com", "parent.host.yahoo.com", 2, "127.0.0.1", "::1") + "]"). + asNodeJson("host9.yahoo.com", "large-variant", "127.0.0.1", "::1") + "," + + asHostJson("parent2.yahoo.com", "large-variant", "127.0.0.1", "::1") + "," + + asDockerNodeJson("host11.yahoo.com", "parent.host.yahoo.com", "::11") + "]"). getBytes(StandardCharsets.UTF_8), Request.Method.POST), "{\"message\":\"Added 4 nodes to the provisioned state\"}"); @@ -807,10 +806,9 @@ public class RestApiTest { assertResponse(new Request("http://localhost:8080/loadbalancers/v1/?application=tenant.nonexistent.default"), "{\"loadBalancers\":[]}"); } - private String asDockerNodeJson(String hostname, String parentHostname, int additionalIpCount, String... ipAddress) { + private String asDockerNodeJson(String hostname, String parentHostname, String... ipAddress) { return "{\"hostname\":\"" + hostname + "\", \"parentHostname\":\"" + parentHostname + "\"," + createIpAddresses(ipAddress) + - createAdditionalIpAddresses(additionalIpCount) + "\"openStackId\":\"" + hostname + "\",\"flavor\":\"d-1-1-100\"}"; } @@ -827,14 +825,6 @@ public class RestApiTest { ", \"type\":\"host\"}"; } - private String createAdditionalIpAddresses(int count) { - return "\"additionalIpAddresses\":[" + - IntStream.range(10, 10+count) - .mapToObj(i -> "\"::" + i + "\"") - .collect(Collectors.joining(",")) + - "],"; - } - private String createIpAddresses(String... ipAddress) { return "\"ipAddresses\":[" + Arrays.stream(ipAddress) diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/node11.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/node11.json index 0733473c2fe..c9cff9673b8 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/node11.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/responses/node11.json @@ -28,11 +28,8 @@ } ], "ipAddresses": [ - "127.0.0.1", - "::1" + "::11" ], "additionalIpAddresses": [ - "::10", - "::11" ] } -- cgit v1.2.3