Beispiel #1
0
    def test_image_format_image_only(self):
        """Method to test MAP based swap (image only: \"alpine\")"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "alpine"

        expected_image = "my.example.com/mirror-docker.io/alpine"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #2
0
    def test_image_format_registry_port_project_image_tag(self):
        """Method to test MAP based swap (registry+port+project+image+tag: \"gcr.io:443/istio/istiod:latest\")"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "gcr.io:443/istio/istiod:latest"

        expected_image = "default.example.com/istio/istiod:latest"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #3
0
    def test_image_format_library_image_with_dotted_tag(self):
        """Method to test MAP based swap (library image with tag that contains a ".": \"rabbitmq:3.8.18-management\")"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "rabbitmq:3.8.18-management"

        expected_image = "my.example.com/mirror-docker.io/rabbitmq:3.8.18-management"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #4
0
    def test_image_format_registry_with_many_domain_levels(self):
        """Method to test MAP based swap (registry with more than 3 domain levels+project+image+tag: \"harbor.geo.k8s.twr.io/stuff/magtape:latest\")"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "harbor.geo.k8s.twr.io/stuff/magtape:latest"

        expected_image = "harbor.geo.k8s.twr.io/stuff/magtape:latest"
        result = imageswap.swap_image(container_spec)

        self.assertFalse(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #5
0
    def test_image_format_nested_project_image(self):
        """Method to test MAP based swap (nested project+image: \"some/random/test/without/registry-or-tag\")"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "some/random/test/without/registry-or-tag"

        expected_image = "my.example.com/mirror-docker.io/some/random/test/without/registry-or-tag"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #6
0
    def test_map_config_with_path_suffix(self):
        """Method to test Map File config (map value with path suffix)"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "gitlab.com/tmobile/pie/proxyman:latest"

        expected_image = "registry.example.com/gitlab/tmobile/pie/proxyman:latest"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #7
0
    def test_image_format_registry_project_image(self):
        """Method to test MAP based swap (registry+project+image: \"quay.io/solo/gloo\")"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "quay.io/solo/gloo"

        expected_image = "quay.example3.com/solo/gloo"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #8
0
    def test_map_config_noswap_with_extra_space(self):
        """Method to test Map File config (noswap_wildcard pattern with extra space after comma)"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "walrus.io/test/test:latest"

        expected_image = "walrus.io/test/test:latest"
        result = imageswap.swap_image(container_spec)

        self.assertFalse(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #9
0
    def test_map_config_with_no_value(self):
        """Method to test Map File config (map with no value)"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "cool.io:443/istio/istiod:latest"

        expected_image = "cool.io:443/istio/istiod:latest"
        result = imageswap.swap_image(container_spec)

        self.assertFalse(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #10
0
    def test_map_config_default(self):
        """Method to test Map File config (default swap map)"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "default.io/paulbower/hello-kubernetes:1.5"

        expected_image = "default.example.com/paulbower/hello-kubernetes:1.5"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #11
0
    def test_map_config_with_port_in_value(self):
        """Method to test Map File config (map with port in value)"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "registry.foo.com/jmsearcy/twrtools:latest"

        expected_image = "localhost:30003/foo/jmsearcy/twrtools:latest"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #12
0
    def test_image_format_project_image_tag(self):
        """Method to test MAP based swap (project+image+tag: \"ubuntu/ubuntu:latest\")"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "ubuntu/ubuntu:latest"

        expected_image = "my.example.com/mirror-docker.io/ubuntu/ubuntu:latest"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #13
0
    def test_map_config_with_trailing_dash(self):
        """Method to test Map File config (map value with trailing "-")"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "docker.io/tmobile/magtape:latest"

        expected_image = "my.example.com/mirror-docker.io/tmobile/magtape:latest"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #14
0
    def test_map_config_with_port_in_key(self):
        """Method to test Map File config (map with port in key)"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec[
            "image"] = "registry.waldo.com:8443/jmsearcy/twrtools:latest"

        expected_image = "registry.garply.com/jmsearcy/twrtools:latest"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #15
0
    def test_image_format_registry_nested_project_image_tag(self):
        """Method to test MAP based swap (registry+nested project+image+tag: \"myregistry.com/some/random/test/with/registry:latest\")"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec[
            "image"] = "myregistry.com/some/random/test/with/registry:latest"

        expected_image = "default.example.com/some/random/test/with/registry:latest"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #16
0
    def test_map_config_with_port_in_key_and_value(self):
        """Method to test Map File config (map with port in key & value)"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec[
            "image"] = "registry.bar.com:8443/jmsearcy/twrtools:latest"

        expected_image = "registry.baz.com:30003/bar/jmsearcy/twrtools:latest"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #17
0
    def test_image_format_project_image_digest(self):
        """Method to test MAP based swap (project+image@digest: \"kindest/node@sha256:15d3b5c4f521a84896ed1ead1b14e4774d02202d5c65ab68f30eeaf310a3b1a7\")"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec[
            "image"] = "kindest/node@sha256:15d3b5c4f521a84896ed1ead1b14e4774d02202d5c65ab68f30eeaf310a3b1a7"

        expected_image = "my.example.com/mirror-docker.io/kindest/node@sha256:15d3b5c4f521a84896ed1ead1b14e4774d02202d5c65ab68f30eeaf310a3b1a7"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #18
0
    def test_map_config_noswap_wildcard_override(self):
        """Method to test Map File config (map that overrides matched pattern in noswap_wildcard)"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec[
            "image"] = "registry.internal.twr.io:443/istio/istiod:latest"

        expected_image = "registry.example.com:443/istio/istiod:latest"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #19
0
    def test_map_config_noswap_wildcard(self):
        """Method to test Map File config (match of pattern in noswap_wildcard)"""

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec[
            "image"] = "registry.external.twr.io:443/istio/istiod:latest"

        expected_image = "registry.external.twr.io:443/istio/istiod:latest"
        result = imageswap.swap_image(container_spec)

        self.assertFalse(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #20
0
    def test_map_config_with_library_image_with_dotted_tag(self):
        """Method to test Map File config (map with library registry and a tag that contains a ".")"""

        imageswap.imageswap_maps_file = "./testing/map_files/map_file_library_image.conf"

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "rabbitmq:3.8.18-management"

        expected_image = "harbor.example.com/library/rabbitmq:3.8.18-management"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #21
0
    def test_map_config_default_empty(self):
        """Method to test Map File config (default swap map has no value)"""

        imageswap.imageswap_maps_file = "./testing/map_files/map_file_empty_default.conf"

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "john.io/paulbower/hello-kubernetes:1.5"

        expected_image = "john.io/paulbower/hello-kubernetes:1.5"
        result = imageswap.swap_image(container_spec)

        self.assertFalse(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #22
0
    def test_map_config_with_port_in_key_and_old_separator(self):
        """Method to test Map File config (map with port in key and old separator ":")"""

        imageswap.imageswap_maps_file = "./testing/map_files/map_file.conf"

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "registry2.bar.com/jmsearcy/twrtools:latest"

        expected_image = "default.example.com/jmsearcy/twrtools:latest"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #23
0
    def test_map_config_with_library_image(self):
        """Method to test Map File config (map with library registry)"""

        imageswap.imageswap_maps_file = "./testing/map_files/map_file_library_image.conf"

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "nginx:latest"

        expected_image = "harbor.example.com/library/nginx:latest"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #24
0
    def test_map_mysqlserver56(self):
        """Method to test exact mapping for entries without hostname but with path and image tag"""

        imageswap.imageswap_maps_file = "./testing/map_files/map_file_exact.conf"

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "mysql/mysql-server:5.6"

        expected_image = "myownrepo.example.com/base/public-image-cache:mysql_mysql-server_5.6"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #25
0
    def test_map_exact_nvcr(self):
        """Method to test exact mapping for entries with hostname and image tag (also a host based mapping exists for this host)"""

        imageswap.imageswap_maps_file = "./testing/map_files/map_file_exact.conf"

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "nvcr.io/nvidia:k8s-device-plugin_v0.9.0"

        expected_image = "myownrepo.example.com/base/private-image-cache:nvcr.io_nvidia_k8s-device-plugin_v0.9.0"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #26
0
    def test_map_host(self):
        """Method to test that host based mapping is working for config files with [EXACT] entries"""

        imageswap.imageswap_maps_file = "./testing/map_files/map_file_exact.conf"

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "nvcr.io/any-image"

        expected_image = "harbor.example.com/any-image"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)
Beispiel #27
0
    def test_map_exact_ubuntu(self):
        """Method to test exact mapping for entries with hostname but without path and image tag"""

        imageswap.imageswap_maps_file = "./testing/map_files/map_file_exact.conf"

        container_spec = {}
        container_spec["name"] = "test-container"
        container_spec["image"] = "ubutun:18.04"

        expected_image = "myownrepo.example.com/base/public-image-cache:ubuntu_18.04"
        result = imageswap.swap_image(container_spec)

        self.assertTrue(result)
        self.assertEqual(container_spec["image"], expected_image)