Ejemplo n.º 1
0
    def test_submitted_apps_name_is_not_empty(self):
        """Submitted apps should have a non-empty ``name`` key"""

        with self.assertRaises(AnsibleFilterError) as cm:
            merge_with_app({"name": ""}, {"name": ""})
        self.assertEqual(cm.exception.message,
                         "input apps name cannot be empty")
Ejemplo n.º 2
0
    def test_submitted_apps_same_name_key(self):
        """Submitted apps should have the same ``name`` key"""

        # pylint: disable=bad-continuation
        for args in (
            ({
                "name": "foo"
            }, {
                "name": "bar"
            }),
            ({
                "name": "foo"
            }, {
                "name": ""
            }),
            ({
                "name": ""
            }, {
                "name": "bar"
            }),
        ):
            with self.assertRaises(AnsibleFilterError) as cm:
                merge_with_app(*args)
            self.assertEqual(cm.exception.message,
                             "input apps should have the same name")
Ejemplo n.º 3
0
    def test_submitted_apps_have_name_key(self):
        """Submitted apps should have a ``name`` key"""

        for args in (({"name": "foo"}, {}), ({}, {"name": "foo"})):
            with self.assertRaises(AnsibleFilterError) as cm:
                merge_with_app(*args)
            self.assertEqual(cm.exception.message,
                             "input apps should have a 'name' key")
Ejemplo n.º 4
0
    def test_submitted_types_to_merge(self):
        """``base`` and ``new`` arguments should both be dictionaries"""

        for args in (({}, []), ([], {}), ([], [])):
            with self.assertRaises(AnsibleFilterError) as cm:
                merge_with_app(*args)
            self.assertEqual(cm.exception.message,
                             "input apps definitions should be 'dict' types")
Ejemplo n.º 5
0
    def test_services_merge_without_duplicates(self):
        """
            Test app services merge does not create duplicates if same items
            appear in base and new apps
        """

        base = {
            "name":
            "foo",
            "services": [
                {
                    "name": "bar",
                    "configs": ["bar.conf"],
                    "templates": ["bar/dc.yml", "bar/svc.yml"],
                },
                {
                    "name": "baz",
                    "configs": ["baz.conf"],
                    "templates": ["baz/dc.yml", "baz/svc.yml", "baz/ep.yml"],
                },
            ],
            "volumes": ["volumes/foo_bar.yml", "volumes/foo_baz.yml"],
        }

        self.assertDictDeepEqual(merge_with_app(base, base), base)
Ejemplo n.º 6
0
    def test_services_merge_with_empty_new_services(self):
        """
            Test app services merge with no services or volumes for the new
            app
        """

        base = {
            "name":
            "foo",
            "services": [
                {
                    "name": "bar",
                    "configs": ["bar.conf"],
                    "templates": ["bar/dc.yml", "bar/svc.yml"],
                },
                {
                    "name": "baz",
                    "configs": ["baz.conf"],
                    "templates": ["baz/dc.yml", "baz/svc.yml", "baz/ep.yml"],
                },
            ],
            "volumes": ["volumes/foo_bar.yml", "volumes/foo_baz.yml"],
        }

        new = {"name": "foo", "services": []}

        self.assertDictDeepEqual(merge_with_app(base, new), base)
Ejemplo n.º 7
0
    def test_services_merge_with_no_config(self):
        """Test app services merge"""

        base = {
            "name": "foo",
            "services": [
                {
                    "name": "bar",
                    "configs": ["bar.conf"],
                    "templates": ["bar/dc.yml", "bar/svc.yml"],
                }
            ],
            "volumes": ["volumes/foo_bar.yml", "volumes/foo_baz.yml"],
        }

        new = {
            "name": "foo",
            "services": [{"name": "bar", "templates": ["bar/dc.yml", "bar/ep.yml"]}],
        }

        expected = {
            "name": "foo",
            "services": [
                {
                    "name": "bar",
                    "configs": ["bar.conf"],
                    "templates": ["bar/dc.yml", "bar/svc.yml", "bar/ep.yml"],
                }
            ],
            "volumes": ["volumes/foo_bar.yml", "volumes/foo_baz.yml"],
        }

        self.assertDictDeepEqual(merge_with_app(base, new), expected)
Ejemplo n.º 8
0
    def test_services_merge_with_template_overriding(self):
        """Test app services merging with template overrides"""

        base = {
            "name":
            "foo",
            "services": [
                {
                    "name": "bar",
                    "configs": ["bar.conf"],
                    "templates": ["bar/dc.yml", "bar/svc.yml"],
                    "environment_variables": "/foo/_env.yml.j2",
                },
                {
                    "name": "baz",
                    "configs": ["baz.conf"],
                    "templates": ["baz/dc.yml", "baz/svc.yml", "baz/ep.yml"],
                },
            ],
            "volumes": ["volumes/foo_bar.yml", "volumes/foo_baz.yml"],
        }

        new = {
            "name":
            "foo",
            "services": [
                {
                    "name": "bar",
                    "templates": ["baz/dc.yml"]
                },
                {
                    "name": "baz",
                    "templates": ["foo/svc.yml"]
                },
            ],
        }

        expected = {
            "name":
            "foo",
            "services": [
                {
                    "name": "bar",
                    "configs": ["bar.conf"],
                    "templates": ["baz/dc.yml", "bar/svc.yml"],
                    "environment_variables": "/foo/_env.yml.j2",
                },
                {
                    "name": "baz",
                    "configs": ["baz.conf"],
                    "templates": ["baz/dc.yml", "foo/svc.yml", "baz/ep.yml"],
                },
            ],
            "volumes": ["volumes/foo_bar.yml", "volumes/foo_baz.yml"],
        }

        self.assertDictDeepEqual(merge_with_app(base, new), expected)
Ejemplo n.º 9
0
    def test_submitted_apps_with_no_services_key(self):
        """Submitted apps may have no defined services key"""

        base = {
            "name": "foo",
            "services": [
                {"name": "bar", "templates": ["bar/dc.yml", "bar/svc.yml"]},
                {"name": "baz", "templates": ["baz/dc.yml", "baz/ep.yml"]},
            ],
        }

        new = {"name": "foo"}

        self.assertDictDeepEqual(merge_with_app(base, new), base)
Ejemplo n.º 10
0
    def test_services_merge_with_new_keys(self):
        """Test app services merge with new keys (meta)"""

        base = {
            "name":
            "foo",
            "services": [
                {
                    "name": "bar",
                    "configs": ["bar.conf"],
                    "templates": ["bar/dc.yml", "bar/svc.yml"],
                },
                {
                    "name": "baz",
                    "configs": ["baz.conf"],
                    "templates": ["baz/dc.yml", "baz/svc.yml", "baz/ep.yml"],
                },
            ],
            "volumes": ["volumes/foo_bar.yml", "volumes/foo_baz.yml"],
        }

        # As the "fun" service does not exist in the "base" app services, we
        # expect that it won't be copied, but simply ignored.
        new = {
            "name":
            "foo",
            "host":
            "foo.com",
            "services": [
                {
                    "name": "bar",
                    "configs": ["bar2.conf"],
                    "templates": ["bar/dc.yml", "bar/ep.yml"],
                    "subdomain": "bar",
                },
                {
                    "name": "fun",
                    "configs": ["fun.conf"],
                    "templates": ["fun/dc.yml", "fun/svc.yml"],
                },
            ],
            "volumes": ["volumes/foo_fun.yml"],
        }

        expected = {
            "name":
            "foo",
            "host":
            "foo.com",
            "services": [
                {
                    "name": "bar",
                    "configs": ["bar.conf", "bar2.conf"],
                    "templates": ["bar/dc.yml", "bar/svc.yml", "bar/ep.yml"],
                    "subdomain": "bar",
                },
                {
                    "name": "baz",
                    "configs": ["baz.conf"],
                    "templates": ["baz/dc.yml", "baz/svc.yml", "baz/ep.yml"],
                },
            ],
            "volumes": [
                "volumes/foo_bar.yml",
                "volumes/foo_baz.yml",
                "volumes/foo_fun.yml",
            ],
        }

        self.assertDictDeepEqual(merge_with_app(base, new), expected)
Ejemplo n.º 11
0
    def test_services_merge(self):
        """Test app services merge"""

        base = {
            "name":
            "foo",
            "services": [
                {
                    "name": "bar",
                    "configs": ["bar.conf"],
                    "templates": ["bar/dc.yml", "bar/svc.yml"],
                    "environment_variables": "/foo/_env.yml.j2",
                },
                {
                    "name": "baz",
                    "configs": ["baz.conf"],
                    "templates": ["baz/dc.yml", "baz/svc.yml", "baz/ep.yml"],
                },
            ],
            "volumes": ["volumes/foo_bar.yml", "volumes/foo_baz.yml"],
        }

        # As the "fun" service does not exist in the "base" app services, we
        # expect that it won't be copied, but simply ignored.
        new = {
            "name":
            "foo",
            "services": [
                {
                    "name": "bar",
                    "configs": ["bar2.conf"],
                    "templates": ["bar/dc.yml", "bar/ep.yml"],
                    "environment_variables": "/bar/_env.yml.j2",
                },
                {
                    "name": "fun",
                    "configs": ["fun.conf"],
                    "templates": ["fun/dc.yml", "fun/svc.yml"],
                },
            ],
            "volumes": ["volumes/foo_fun.yml"],
        }

        expected = {
            "name":
            "foo",
            "services": [
                {
                    "name": "bar",
                    "configs": ["bar.conf", "bar2.conf"],
                    "templates": ["bar/dc.yml", "bar/svc.yml", "bar/ep.yml"],
                    "environment_variables": "/bar/_env.yml.j2",
                },
                {
                    "name": "baz",
                    "configs": ["baz.conf"],
                    "templates": ["baz/dc.yml", "baz/svc.yml", "baz/ep.yml"],
                },
            ],
            "volumes": [
                "volumes/foo_bar.yml",
                "volumes/foo_baz.yml",
                "volumes/foo_fun.yml",
            ],
        }

        self.assertDictDeepEqual(merge_with_app(base, new), expected)