Add test of service creation and port mapping
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/220c7379 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/220c7379 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/220c7379 Branch: refs/heads/master Commit: 220c7379bc2c962f118d8c26f5023fd6907a1e33 Parents: 3ce905a Author: Andrew Donald Kennedy <[email protected]> Authored: Thu Feb 9 16:14:03 2017 +0000 Committer: Andrew Donald Kennedy <[email protected]> Committed: Fri May 19 14:01:20 2017 +0100 ---------------------------------------------------------------------- .../KubernetesLocationYamlLiveTest.java | 42 +++++++++++++++++--- .../resources/nginx-replication-controller.yaml | 20 ++++++++++ .../src/test/resources/nginx-service.yaml | 12 ++++++ .../src/test/resources/nginx.yaml | 20 ---------- 4 files changed, 69 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/220c7379/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationYamlLiveTest.java ---------------------------------------------------------------------- diff --git a/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationYamlLiveTest.java b/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationYamlLiveTest.java index 27272e6..f2fcac4 100644 --- a/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationYamlLiveTest.java +++ b/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationYamlLiveTest.java @@ -324,28 +324,60 @@ public class KubernetesLocationYamlLiveTest extends AbstractYamlTest { } @Test(groups={"Live"}) - public void testNginxResource() throws Exception { + public void testNginxReplicationController() throws Exception { String yaml = Joiner.on("\n").join( locationYaml, "services:", " - type: " + KubernetesResource.class.getName(), - " id: nginx", - " name: \"nginx\"", + " id: nginx-replication-controller", + " name: \"nginx-replication-controller\"", " brooklyn.config:", - " resource: classpath://nginx.yaml"); + " resource: classpath://nginx-replication-controller.yaml"); Entity app = createStartWaitAndLogApplication(yaml); KubernetesResource entity = Iterables.getOnlyElement(Entities.descendantsAndSelf(app, KubernetesResource.class)); Entities.dumpInfo(app); assertEntityHealthy(entity); - assertAttributeEqualsEventually(entity, KubernetesResource.RESOURCE_NAME, "nginx-resource"); + assertAttributeEqualsEventually(entity, KubernetesResource.RESOURCE_NAME, "nginx-replication-controller"); assertAttributeEqualsEventually(entity, KubernetesResource.RESOURCE_TYPE, "ReplicationController"); assertAttributeEqualsEventually(entity, KubernetesLocationConfig.KUBERNETES_NAMESPACE, "default"); assertAttributeEventually(entity, SoftwareProcess.ADDRESS, and(notNull(), not(equalTo("0.0.0.0")))); assertAttributeEventually(entity, SoftwareProcess.SUBNET_ADDRESS, and(notNull(), not(equalTo("0.0.0.0")))); } + @Test(groups={"Live"}) + public void testNginxService() throws Exception { + String yaml = Joiner.on("\n").join( + locationYaml, + "services:", + " - type: " + KubernetesResource.class.getName(), + " id: nginx-replication-controller", + " name: \"nginx-replication-controller\"", + " brooklyn.config:", + " resource: classpath://nginx-replication-controller.yaml", + " - type: " + KubernetesResource.class.getName(), + " id: nginx-service", + " name: \"nginx-service\"", + " brooklyn.config:", + " resource: classpath://nginx-service.yaml"); + Entity app = createStartWaitAndLogApplication(yaml); + + Iterable<KubernetesResource> resources = Entities.descendantsAndSelf(app, KubernetesResource.class); + KubernetesResource nginxReplicationController = Iterables.find(resources, EntityPredicates.displayNameEqualTo("nginx-replication-controller")); + KubernetesResource nginxService = Iterables.find(resources, EntityPredicates.displayNameEqualTo("nginx-service")); + + assertEntityHealthy(nginxReplicationController); + assertEntityHealthy(nginxService); + + Entities.dumpInfo(app); + + Integer httpPort = assertAttributeEventuallyNonNull(nginxService, Sensors.newIntegerSensor("kubernetes.port.http")); + assertEquals(httpPort, Integer.valueOf(8080)); + String httpPublicPort = assertAttributeEventuallyNonNull(nginxService, Sensors.newStringSensor("kubernetes.port.http.mapped.public")); + assertReachableEventually(HostAndPort.fromString(httpPublicPort)); + } + protected void assertReachableEventually(final HostAndPort hostAndPort) { succeedsEventually(new Runnable() { public void run() { http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/220c7379/kubernetes-location/src/test/resources/nginx-replication-controller.yaml ---------------------------------------------------------------------- diff --git a/kubernetes-location/src/test/resources/nginx-replication-controller.yaml b/kubernetes-location/src/test/resources/nginx-replication-controller.yaml new file mode 100644 index 0000000..6788a05 --- /dev/null +++ b/kubernetes-location/src/test/resources/nginx-replication-controller.yaml @@ -0,0 +1,20 @@ +apiVersion: v1 +kind: ReplicationController +metadata: + name: nginx-replication-controller + namespace: default +spec: + replicas: 2 + selector: + app: nginx + template: + metadata: + name: nginx + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx + ports: + - containerPort: 80 http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/220c7379/kubernetes-location/src/test/resources/nginx-service.yaml ---------------------------------------------------------------------- diff --git a/kubernetes-location/src/test/resources/nginx-service.yaml b/kubernetes-location/src/test/resources/nginx-service.yaml new file mode 100644 index 0000000..3964283 --- /dev/null +++ b/kubernetes-location/src/test/resources/nginx-service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: nginx-service + namespace: default +spec: + type: NodePort + ports: + - name: "http" + port: 80 + selector: + app: nginx \ No newline at end of file http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/220c7379/kubernetes-location/src/test/resources/nginx.yaml ---------------------------------------------------------------------- diff --git a/kubernetes-location/src/test/resources/nginx.yaml b/kubernetes-location/src/test/resources/nginx.yaml deleted file mode 100644 index 15d5ba5..0000000 --- a/kubernetes-location/src/test/resources/nginx.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: v1 -kind: ReplicationController -metadata: - name: nginx-resource - namespace: default -spec: - replicas: 2 - selector: - app: nginx - template: - metadata: - name: nginx - labels: - app: nginx - spec: - containers: - - name: nginx - image: nginx - ports: - - containerPort: 80
