Beispiel #1
0
 def test_find_image_with_custom_defined(self):
     artifact = {"image": {"file": "imagename", "repository": "myrepo"}}
     repo = {"myrepo": "https://docker.io/registry"}
     info = Mock(artifacts=artifact, repositories=repo)
     self.container = Container(info)
     image = self.container._get_image_from_artifact()
     self.assertEqual(image, "docker.io/registry/imagename")
Beispiel #2
0
    def test_handle_pod_keys(self):
        info = Mock(properties={"stop_grace_period": "123"})
        cont = Container(info)

        cont._remove_pod_keys()
        self.pod._update_pod_spec(cont)
        self.assertIn("terminationGracePeriodSeconds", self.pod.spec)
Beispiel #3
0
 def test_find_image_with_parent(self):
     parent = {"artifacts": {"image": {"file": "parentname"}}}
     info = Mock(artifacts={})
     info.parent = parent
     self.container = Container(info)
     image = self.container._get_image_from_artifact()
     self.assertEqual(image, "parentname")
Beispiel #4
0
    def test_handle_int_port(self):
        port = {"port": "8080"}
        info = namedtuple("Data", ["name", "properties"])(
            NODE, {"ports": [8080]}
        )
        cont = Container(info)

        cont._remove_pod_keys()
        self.pod._extract_ports(cont)
        self.assertIn(port, self.pod.ports)
Beispiel #5
0
    def test_handle_container_port(self):
        port = {"containerPort": 8080}
        info = namedtuple("Data", ["name", "properties"])(
            NODE, {"ports": [port]}
        )

        cont = Container(info)
        cont._remove_pod_keys()
        self.pod._extract_ports(cont)
        self.assertIn(port, cont.spec["ports"])
Beispiel #6
0
 def setUp(self):
     """ Setup Validator object and prep a bad TOSCA template """
     info = Mock()
     self.container = Container(info)
Beispiel #7
0
 def test_add_container(self):
     info = Mock(properties={"image": "test"}, mounts={})
     cont = Container(info)
     cont.build()
     self.pod.add_containers([cont])
Beispiel #8
0
 def test_missing_image(self):
     info = Mock(artifacts={}, properties={})
     info.parent = {}
     self.container = Container(info)
     with self.assertRaises(LookupError):
         self.container._set_image()
Beispiel #9
0
 def test_get_image_version_latest(self):
     info = Mock(properties={"image": "nginx"})
     self.container = Container(info)
     self.container._set_image()
     self.assertEqual(self.container.labels[VER_LABEL], "latest")
Beispiel #10
0
 def test_find_image_with_custom_undefined(self):
     artifact = {"image": {"file": "imagename", "repository": "myrepo"}}
     info = Mock(artifacts=artifact, repositories={})
     self.container = Container(info)
     with self.assertRaises(KeyError):
         self.container._get_image_from_artifact()
Beispiel #11
0
 def test_find_image_with_dockerhub(self):
     artifact = {"image": {"file": "imagename", "repository": "DOCKER hub"}}
     info = Mock(artifacts=artifact)
     self.container = Container(info)
     image = self.container._get_image_from_artifact()
     self.assertEqual(image, "imagename")