def test_create_service_with_auto_node_port(self): spec = {} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertEqual( test.services.get("docker-container-nodeport").type, "NodePort" ) self.assertEqual( test.services.get("docker-container-nodeport") .resource.get("spec") .get("type"), "NodePort", ) self.assertEqual( test.services.get("docker-container-nodeport") .resource.get("spec") .get("ports")[0] .get("targetPort"), "3000", ) self.assertEqual( test.services.get("docker-container-nodeport") .resource.get("spec") .get("ports")[0] .get("port"), 3030, ) self.assertEqual( test.services.get("docker-container-nodeport") .resource.get("spec") .get("ports")[0] .get("nodePort"), 30000, )
def test_create_service_overwrite_type(self): spec = {} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertEqual( len( test.services.get("docker-container-loadbalancer") .resource.get("spec") .get("ports") ), 1, ) self.assertEqual( test.services.get("docker-container-loadbalancer").type, "LoadBalancer" ) self.assertEqual( test.services.get("docker-container-loadbalancer") .resource.get("spec") .get("type"), "LoadBalancer", ) self.assertEqual( test.services.get("docker-container-loadbalancer") .resource.get("spec") .get("ports")[0] .get("port"), 1000, ) self.assertEqual( test.services.get("docker-container-loadbalancer") .resource.get("spec") .get("ports")[0] .get("nodePort"), 30009, )
def test_attach_configs_to_pods(self): spec = {} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) [mount] = [ x for x in test.pod.get("spec").get("containers")[0].get("volumeMounts") if x.get("name") == "fake-config-volume" ] [mount_abst] = [ x for x in test.pod.get("spec").get("containers")[0].get("volumeMounts") if x.get("name") == "fake-config-abst-volume" ] self.assertTrue(mount) self.assertTrue(mount_abst) [mount] = [ x for x in test.pod.get("spec").get("volumes") if x.get("name") == "fake-config-volume" ] [mount_abst] = [ x for x in test.pod.get("spec").get("volumes") if x.get("name") == "fake-config-abst-volume" ] self.assertTrue(mount.get("configMap")) self.assertTrue(mount_abst.get("configMap"))
def test_custom_pod_label_no_overwrite(self): spec = { "configure": {"metadata": {"labels": {"app.kubernetes.io/name": "newname"}}} } test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertNotEqual( test.pod.get("metadata").get("labels").get("app.kubernetes.io/name"), "newname", )
def test_attach_volume_default_path(self): spec = {} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) [mount] = [ x for x in test.pod.get("spec").get("containers")[0].get("volumeMounts") if x.get("name") == "fake-vol" ] self.assertEqual(mount.get("mountPath"), "/etc/micado/volumes")
def test_attach_volume_path_in_volume_properties(self): spec = {} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) [mount] = [ x for x in test.pod.get("spec").get("containers")[0].get("volumeMounts") if x.get("name") == "fake-vol-abst-no-rel" ] self.assertEqual(mount.get("mountPath"), "volinprop")
def test_create_host_port(self): spec = {} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertEqual( test.pod["spec"]["containers"][0].get("ports")[1].get("containerPort"), 5000 ) self.assertEqual( test.pod["spec"]["containers"][0].get("ports")[1].get("hostPort"), 5050 )
def test_containers_to_pod_label_first_wins(self): cont = self.getContainerbyName("add-containers-to-bare-pod") spec = {} test = WorkloadManifest("myapp", cont, spec, self.tpl.repositories) self.assertEqual( test.resource.get("metadata") .get("labels") .get("app.kubernetes.io/version"), "v123", )
def test_container_to_workload_label_no_overwrite(self): cont = self.getContainerbyName("add-container-to-workload") spec = {} test = WorkloadManifest("myapp", cont, spec, self.tpl.repositories) self.assertEqual( test.resource.get("metadata") .get("labels") .get("app.kubernetes.io/version"), "v1000", )
def test_create_service_use_service_namespace(self): cont = self.getContainerbyName("docker-by-kube-service") spec = {"create": {"metadata": {"namespace": "custom-ns"}}} test = WorkloadManifest("myapp", cont, spec, self.tpl.repositories) self.assertEqual(test.services.get("docker-by-kube-service").namespace, "service-ns") self.assertEqual( test.services.get("docker-by-kube-service") .resource.get("metadata") .get("namespace"), "service-ns", )
def test_create_service_with_multiple_ports(self): spec = {} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertEqual( len( test.services.get("docker-container-nodeport") .resource.get("spec") .get("ports") ), 2, )
def test_attach_volume_to_pod(self): spec = {} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) [mount] = [ x for x in test.pod.get("spec").get("volumes") if x.get("name") == "fake-vol" ] [mount_abst] = [ x for x in test.pod.get("spec").get("volumes") if x.get("name") == "fake-vol-abst" ] self.assertTrue(mount) self.assertTrue(mount_abst)
def test_create_service_with_custom_name(self): spec = {} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertEqual( len(test.services.get("my-custom-name").resource.get("spec").get("ports")), 1, ) self.assertEqual( test.services.get("my-custom-name") .resource.get("spec") .get("ports")[0] .get("port"), 1000, ) self.assertEqual( test.services.get("my-custom-name") .resource.get("spec") .get("ports")[0] .get("nodePort"), 30006, )
def test_create_service_with_docker_long_syntax(self): spec = {} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertEqual( len( test.services.get("docker-container").resource.get("spec").get("ports") ), 1, ) self.assertEqual( test.services.get("docker-container") .resource.get("spec") .get("ports")[0] .get("port"), 4000, ) self.assertEqual( test.services.get("docker-container") .resource.get("spec") .get("ports")[0] .get("protocol"), "UDP", )
def test_get_hosted_on(self): spec = {} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertIn("nodeAffinity", test.pod.get("spec").get("affinity"))
def test_auto_pod_spec_in_configure(self): spec = {"configure": {"metadata": {}, "subdomain": "mysubdomain"}} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertTrue(test.pod.get("spec").get("subdomain"))
def test_no_template_for_pod(self): spec = {"create": {"kind": "Pod"}} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertFalse(test.resource.get("spec").get("template"))
def test_workload_spec_to_pod(self): spec = {"create": {"kind": "doesnt-matter", "subdomain": "mysubdomain"}} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertTrue( test.resource.get("spec").get("template").get("spec").get("subdomain") )
def test_pod_property_from_container(self): spec = {} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertTrue(test.pod.get("spec").get("hostPID"))
def test_workload_namespace(self): spec = {"create": {"metadata": {"namespace": "my-ns"}}} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertEqual(test.resource.get("metadata").get("namespace"), "my-ns") self.assertEqual(test.namespace, "my-ns")
def test_multiple_containers_to_bare_pod(self): cont = self.getContainerbyName("add-containers-to-bare-pod") spec = {} test = WorkloadManifest("myapp", cont, spec, self.tpl.repositories) self.assertEqual(len(test.pod.get("spec").get("containers")), 2)
def test_template_selector_container_for_workloads(self): spec = {} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertTrue(test.resource.get("spec").get("template")) self.assertTrue(test.resource.get("spec").get("selector")) self.assertEqual(len(test.pod.get("spec").get("containers")), 1)
def test_attach_volumes_configs_to_pods(self): spec = {} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertEqual( len(test.pod.get("spec").get("containers")[0].get("volumeMounts")), 6 )
def test_manual_pod_spec_in_create(self): spec = { "create": {"spec": {"template": {"spec": {"subdomain": "mysubdomain"}}}} } test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertTrue(test.pod.get("spec").get("subdomain"))
def test_custom_pod_label(self): spec = {"configure": {"metadata": {"labels": {"custom": "label"}}}} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertTrue(test.pod.get("metadata").get("labels").get("custom"))
def test_workload_super(self): spec = {"create": {"kind": "doesnt-matter", "strategy": "Recreate"}} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertTrue(test.resource.get("spec").get("strategy"))
def test_no_selector_for_jobs(self): spec = {"create": {"kind": "Job"}} test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories) self.assertFalse(test.resource.get("spec").get("selector"))