コード例 #1
0
    def test_get_pullspecs_some_locations(self, rel_images, rel_envs,
                                          containers, annotations):
        data = ORIGINAL.data
        expected = {p.value for p in PULLSPECS.values()}

        if not rel_images:
            expected -= {FOO.value, BAR.value}
            del data["spec"]["relatedImages"]
        deployments = chain_get(data,
                                ["spec", "install", "spec", "deployments"])
        if not rel_envs:
            expected -= {EGGS.value}
            for d in deployments:
                for c in chain_get(d,
                                   ["spec", "template", "spec", "containers"]):
                    c.pop("env", None)
        if not containers:
            expected -= {SPAM.value, HAM.value, JAM.value}
            for d in deployments:
                del d["spec"]["template"]["spec"]["containers"]
        if not annotations:
            expected -= {BAZ.value}
            del data["metadata"]["annotations"]

        csv = OperatorCSV("x.yaml", data)
        assert csv.get_pullspecs() == expected
コード例 #2
0
    def test_get_pullspecs_some_locations(self, rel_images, rel_envs, containers,
                                          annotations, init_rel_envs, init_containers):
        data = ORIGINAL.data
        expected = {p.value for p in PULLSPECS.values()}

        if not rel_images:
            expected -= {RI1.value, RI2.value}
            del data["spec"]["relatedImages"]
        deployments = chain_get(data, ["spec", "install", "spec", "deployments"])
        if not rel_envs:
            expected -= {CE1.value}
            for d in deployments:
                for c in chain_get(d, ["spec", "template", "spec", "containers"]):
                    c.pop("env", None)
        if not containers:
            expected -= {C1.value, C2.value, C3.value}
            for d in deployments:
                del d["spec"]["template"]["spec"]["containers"]
        if not annotations:
            expected -= {AN1.value, AN2.value, AN3.value,
                         AN4.value, AN5.value, AN6.value, AN7.value}
            delete_all_annotations(data)
        if not init_rel_envs:
            expected -= {ICE1.value}
            for d in deployments:
                for c in chain_get(d, ["spec", "template", "spec", "initContainers"], default=[]):
                    c.pop("env", None)
        if not init_containers:
            expected -= {IC1.value}
            for d in deployments:
                d["spec"]["template"]["spec"].pop("initContainers", None)
        self._mock_check_csv()
        csv = OperatorCSV("x.yaml", data)
        assert csv.get_pullspecs() == expected
コード例 #3
0
    def _get_containers(self):
        deployments_path = ("spec", "install", "spec", "deployments")
        deployments = chain_get(self.data, deployments_path, default=[])

        containers_path = ("spec", "template", "spec", "containers")
        containers = [
            c for d in deployments
            for c in chain_get(d, containers_path, default=[])
        ]
        return containers
コード例 #4
0
 def _init_container_pullspecs(self):
     deployments = self._deployments()
     init_containers_path = ("spec", "template", "spec", "initContainers")
     return [
         InitContainer(c) for d in deployments
         for c in chain_get(d, init_containers_path, default=[])
     ]
コード例 #5
0
 def _annotation_pullspecs(self):
     annotations_path = ("metadata", "annotations")
     annotations = chain_get(self.data, annotations_path, default={})
     pullspecs = []
     if "containerImage" in annotations:
         pullspecs.append(
             Annotation(annotations).with_key("containerImage"))
     return pullspecs
コード例 #6
0
    def _related_image_pullspecs(self):
        """Get the pullspecs from spec.relatedImages section

        :return: a list of pullspecs. It could be an empty if no spec.RelatedImage section.
        :rtype: list[RelatedImage]
        """
        related_images_path = ("spec", "relatedImages")
        return [
            RelatedImage(r)
            for r in chain_get(self.data, related_images_path, default=[])
        ]
コード例 #7
0
    def test_valuefrom_references_not_allowed(self):
        data = ORIGINAL.data
        env_path = CE1.path[:-1]
        env = chain_get(data, env_path)
        env["valueFrom"] = "somewhere"

        csv = OperatorCSV("original.yaml", data)
        with pytest.raises(RuntimeError) as exc_info:
            csv.get_pullspecs()

        assert '"valueFrom" references are not supported' in str(exc_info.value)
コード例 #8
0
 def _deployments(self):
     deployments_path = ("spec", "install", "spec", "deployments")
     return chain_get(self.data, deployments_path, default=[])
コード例 #9
0
 def _related_image_pullspecs(self):
     related_images_path = ("spec", "relatedImages")
     return [
         RelatedImage(r)
         for r in chain_get(self.data, related_images_path, default=[])
     ]
コード例 #10
0
 def find_in_data(self, data):
     return ImageName.parse(chain_get(data, self.path))
コード例 #11
0
 def _get_annotations(self):
     annotations_path = ("metadata", "annotations")
     return chain_get(self.data, annotations_path, default={})
コード例 #12
0
 def _get_related_images(self):
     related_images_path = ("spec", "relatedImages")
     return chain_get(self.data, related_images_path, default=[])