|
28 | 28 | from moduleframework.avocado_testers import container_avocado_test
|
29 | 29 |
|
30 | 30 |
|
31 |
| -class DockerfileLinter(module_framework.AvocadoTest): |
| 31 | +class DockerfileSanitize(container_avocado_test.ContainerAvocadoTest): |
32 | 32 | """
|
33 | 33 | :avocado: enable
|
34 | 34 |
|
35 | 35 | """
|
36 | 36 |
|
37 |
| - dp = None |
| 37 | + dp = dockerlinter.DockerfileLinter(os.path.join(os.getcwd(), "..")) |
38 | 38 |
|
39 |
| - def setUp(self): |
40 |
| - # it is not intended just for docker, but just docker packages are |
41 |
| - # actually properly signed |
42 |
| - self.dp = dockerlinter.DockerfileLinter(os.path.join(os.getcwd(), "..")) |
43 |
| - if self.dp.dockerfile is None: |
44 |
| - self.skip() |
45 |
| - |
46 |
| - def testDockerFromBaseruntime(self): |
| 39 | + def test_docker_from_baseruntime(self): |
47 | 40 | self.assertTrue(self.dp.check_baseruntime())
|
48 | 41 |
|
49 |
| - def testDockerNodocs(self): |
50 |
| - self.start() |
51 |
| - installed_pkgs = self.run("rpm -qa --qf '%{{NAME}}\n'", ignore_status=True).stdout |
52 |
| - # This returns a list of packages defined in config.yaml for testing |
53 |
| - # e.g. ["bash", "rpm", "memcached"] in case of memcached |
54 |
| - pkgs = self.backend.getPackageList() |
55 |
| - for pkg in installed_pkgs.split('\n'): |
56 |
| - if pkg in pkgs: |
57 |
| - all_docs = self.run("rpm -qd %s" % pkg).stdout |
58 |
| - for doc in all_docs.strip().split('\n'): |
59 |
| - self.assertNotEqual(0, self.run("test -e %s" % doc, ignore_status=True).exit_status) |
60 |
| - |
61 |
| - def testDockerCleanAll(self): |
62 |
| - self.start() |
63 |
| - pkg_mgr = "yum" |
64 |
| - # Detect distro in image |
65 |
| - distro = self.run("cat /etc/os-release").stdout |
66 |
| - if 'NAME=Fedora' in distro: |
67 |
| - pkg_mgr = "dnf" |
68 |
| - # Look, whether we have solv files in /var/cache/<pkg_mgr>/*.solv |
69 |
| - # dnf|yum clean all deletes the file *.solv |
70 |
| - ret = self.run("ls /var/cache/%s/*.solv" % pkg_mgr, ignore_status=True) |
71 |
| - self.assertNotEqual(0, ret.exit_status) |
72 |
| - self.assertEqual("", ret.stdout.strip()) |
73 |
| - |
74 |
| - def testArchitectureInEnvAndLabelExists(self): |
| 42 | + def test_architecture_in_env_and_label_exists(self): |
75 | 43 | self.assertTrue(self.dp.get_docker_specific_env("ARCH="))
|
76 | 44 | self.assertTrue(self.dp.get_specific_label("architecture"))
|
77 | 45 |
|
78 |
| - def testNameInEnvAndLabelExists(self): |
| 46 | + def test_name_in_env_and_label_exists(self): |
79 | 47 | self.assertTrue(self.dp.get_docker_specific_env("NAME="))
|
80 | 48 | self.assertTrue(self.dp.get_specific_label("name"))
|
81 | 49 |
|
82 |
| - def testReleaseLabelExists(self): |
| 50 | + def test_release_label_exists(self): |
83 | 51 | self.assertTrue(self.dp.get_specific_label("release"))
|
84 | 52 |
|
85 |
| - def testVersionLabelExists(self): |
| 53 | + def test_version_label_exists(self): |
86 | 54 | self.assertTrue(self.dp.get_specific_label("version"))
|
87 | 55 |
|
88 |
| - def testComRedHatComponentLabelExists(self): |
| 56 | + def test_com_red_hat_component_label_exists(self): |
89 | 57 | self.assertTrue(self.dp.get_specific_label("com.redhat.component"))
|
90 | 58 |
|
91 |
| - def testIok8sDescriptionExists(self): |
| 59 | + def test_iok8s_description_exists(self): |
92 | 60 | self.assertTrue(self.dp.get_specific_label("io.k8s.description"))
|
93 | 61 |
|
94 |
| - def testIoOpenshiftExposeServicesExists(self): |
| 62 | + def test_io_openshift_expose_services_exists(self): |
95 | 63 | label_io_openshift = "io.openshift.expose-services"
|
96 | 64 | exposes = self.dp.get_docker_expose()
|
97 | 65 | label_list = self.dp.get_docker_labels()
|
98 | 66 | self.assertTrue(label_list[label_io_openshift])
|
99 | 67 | for exp in exposes:
|
100 | 68 | self.assertTrue("%s" % exp in label_list[label_io_openshift])
|
101 | 69 |
|
102 |
| - def testIoOpenShiftTagsExists(self): |
| 70 | + def test_io_openshift_tags_exists(self): |
103 | 71 | label_list = self.dp.get_docker_labels()
|
104 | 72 | self.assertTrue("io.openshift.tags" in label_list)
|
105 | 73 |
|
106 | 74 |
|
| 75 | +class DockerfileLinterInContainer(container_avocado_test.ContainerAvocadoTest): |
| 76 | + """ |
| 77 | + :avocado: enable |
| 78 | +
|
| 79 | + """ |
| 80 | + |
| 81 | + def test_docker_nodocs(self): |
| 82 | + self.start() |
| 83 | + installed_pkgs = self.run("rpm -qa --qf '%{{NAME}}\n'", verbose=False).stdout |
| 84 | + # This returns a list of packages defined in config.yaml for testing |
| 85 | + # e.g. ["bash", "rpm", "memcached"] in case of memcached |
| 86 | + pkgs = self.backend.getPackageList() |
| 87 | + list_pkg = [pkg for pkg in installed_pkgs.split('\n') if pkg in pkgs] |
| 88 | + for pkg in list_pkg: |
| 89 | + all_docs = self.run("rpm -qd %s" % pkg, verbose=False).stdout |
| 90 | + for doc in all_docs.strip().split('\n'): |
| 91 | + self.assertNotEqual(0, self.run("test -e %s" % doc, ignore_status=True).exit_status) |
| 92 | + |
| 93 | + def test_docker_clean_all(self): |
| 94 | + self.start() |
| 95 | + pkg_mgr = "yum" |
| 96 | + # Detect distro in image |
| 97 | + distro = self.run("cat /etc/os-release").stdout |
| 98 | + if 'NAME=Fedora' in distro: |
| 99 | + pkg_mgr = "dnf" |
| 100 | + # Look, whether we have solv files in /var/cache/<pkg_mgr>/*.solv |
| 101 | + # dnf|yum clean all deletes the file *.solv |
| 102 | + ret = self.run("ls /var/cache/%s/*.solv" % pkg_mgr, ignore_status=True) |
| 103 | + self.assertNotEqual(0, ret.exit_status) |
| 104 | + self.assertEqual("", ret.stdout.strip()) |
| 105 | + |
| 106 | + |
107 | 107 | class DockerLint(container_avocado_test.ContainerAvocadoTest):
|
108 | 108 | """
|
109 | 109 | :avocado: enable
|
|
0 commit comments