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)
Example #2
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
    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
    def test_get_pullspecs(self, caplog):
        csv = OperatorCSV("original.yaml", ORIGINAL.data)
        pullspecs = csv.get_pullspecs()
        assert pullspecs == self._original_pullspecs

        expected_logs = [
            "original.yaml - Found pullspec for relatedImage ri1: {ri1}",
            "original.yaml - Found pullspec for relatedImage ri2: {ri2}",
            "original.yaml - Found pullspec for RELATED_IMAGE_CE1 var: {ce1}",
            "original.yaml - Found pullspec for RELATED_IMAGE_ICE1 var: {ice1}",
            "original.yaml - Found pullspec for container c1: {c1}",
            "original.yaml - Found pullspec for container c2: {c2}",
            "original.yaml - Found pullspec for container c3: {c3}",
            "original.yaml - Found pullspec for initContainer ic1: {ic1}",
            "original.yaml - Found pullspec for {an1.key} annotation: {an1}",
            "original.yaml - Found pullspec for {an2.key} annotation: {an2}",
            "original.yaml - Found pullspec for {an2.key} annotation: {an2}",
            "original.yaml - Found pullspec for {an3.key} annotation: {an3}",
            "original.yaml - Found pullspec for {an4.key} annotation: {an4}",
            "original.yaml - Found pullspec for {an5.key} annotation: {an5}",
            "original.yaml - Found pullspec for {an6.key} annotation: {an6}",
            "original.yaml - Found pullspec for {an7.key} annotation: {an7}",
        ]
        for log in expected_logs:
            assert log.format(**PULLSPECS) in caplog.text
 def test_ignored_annotations(self):
     data = {
         'kind': 'ClusterServiceVersion',
         'metadata': {
             'annotations': {
                 'some_text': 'abcdef',
                 'some_number': 123,
                 'some_array': [],
                 'some_object': {},
                 'metadata': {
                     'annotations': {
                         'pullspec': 'metadata.annotations/nested.in:metadata.annotations'
                     }
                 }
             },
             'not_an_annotation': 'something.that/looks-like:a-pullspec',
             'not_annotations': {
                 'also_not_an_annotation': 'other.pullspec/lookalike:thing'
             },
             'metadata': {
                 'annotations': {
                     'pullspec': 'metadata.annotations/nested.in:metadata'
                 }
             }
         }
     }
     self._mock_check_csv()
     csv = OperatorCSV("original.yaml", data)
     assert csv.get_pullspecs() == set()
Example #6
0
    def test_get_pullspecs(self, caplog):
        csv = OperatorCSV("original.yaml", ORIGINAL.data)
        pullspecs = csv.get_pullspecs()
        assert pullspecs == self._original_pullspecs

        expected_logs = [
            "original.yaml - Found pullspec for related image foo: {foo}",
            "original.yaml - Found pullspec for related image bar: {bar}",
            "original.yaml - Found pullspec in RELATED_IMAGE_EGGS var: {eggs}",
            "original.yaml - Found pullspec for container spam: {spam}",
            "original.yaml - Found pullspec for container ham: {ham}",
            "original.yaml - Found pullspec for container jam: {jam}",
            "original.yaml - Found pullspec in annotations: {baz}",
        ]
        for log in expected_logs:
            assert log.format(**PULLSPECS) in caplog.text