diff options
| -rw-r--r-- | kolla/image/kolla_worker.py | 5 | ||||
| -rw-r--r-- | kolla/tests/test_build.py | 42 |
2 files changed, 45 insertions, 2 deletions
diff --git a/kolla/image/kolla_worker.py b/kolla/image/kolla_worker.py index 92908a6c1..837bd797c 100644 --- a/kolla/image/kolla_worker.py +++ b/kolla/image/kolla_worker.py @@ -423,7 +423,7 @@ class KollaWorker(object): if pip_args: lines = content.split('\n') for i, line in enumerate(lines): - if line.startswith('FROM '): + if re.match(r'^FROM\s', line, re.IGNORECASE): lines[i + 1:i + 1] = pip_args break content = '\n'.join(lines) @@ -756,7 +756,8 @@ class KollaWorker(object): image_name = os.path.basename(path) canonical_name = (self.namespace + '/' + self.image_prefix + image_name + ':' + self.tag) - parent_search_pattern = re.compile(r'^FROM.*$', re.MULTILINE) + parent_search_pattern = re.compile(r'^FROM.*$', + re.MULTILINE | re.IGNORECASE) match = re.search(parent_search_pattern, content) if match: parent_name = match.group(0).split(' ')[1] diff --git a/kolla/tests/test_build.py b/kolla/tests/test_build.py index 0ada46eb6..7d7c58d0f 100644 --- a/kolla/tests/test_build.py +++ b/kolla/tests/test_build.py @@ -962,6 +962,48 @@ class KollaWorkerTest(base.TestCase): self.assertRaises(jinja2.exceptions.SecurityError, kolla.create_dockerfiles) + @mock.patch(engine_client) + def test_create_dockerfiles_pip_args_lowercase_from(self, mock_client): + tmpdir = self.useFixture(fixtures.TempDir()).path + base_dir = os.path.join(tmpdir, 'base') + os.makedirs(base_dir) + with open(os.path.join(base_dir, 'Dockerfile.j2'), 'w') as f: + f.write('from {{ base_distro }}:{{ base_distro_tag }}\n') + self.conf.set_override('pip_index_url', 'https://example.org/simple') + with mock.patch.object(build.KollaWorker, '_get_images_dir', + return_value=tmpdir): + kolla = build.KollaWorker(self.conf) + kolla.setup_working_dir() + kolla.find_dockerfiles() + kolla.create_dockerfiles() + dockerfile = os.path.join(kolla.working_dir, 'base', 'Dockerfile') + with open(dockerfile) as f: + content = f.read() + self.assertIn('ARG PIP_INDEX_URL', content) + + @mock.patch(engine_client) + def test_build_image_list_parent_name_lowercase_from(self, mock_client): + tmpdir = self.useFixture(fixtures.TempDir()).path + base_dir = os.path.join(tmpdir, 'base') + os.makedirs(base_dir) + with open(os.path.join(base_dir, 'Dockerfile.j2'), 'w') as f: + f.write('FROM {{ base_distro }}:{{ base_distro_tag }}\n') + child_dir = os.path.join(tmpdir, 'child') + os.makedirs(child_dir) + with open(os.path.join(child_dir, 'Dockerfile.j2'), 'w') as f: + f.write('from {{ namespace }}/{{ image_prefix }}base:{{ tag }}\n') + with mock.patch.object(build.KollaWorker, '_get_images_dir', + return_value=tmpdir): + kolla = build.KollaWorker(self.conf) + kolla.setup_working_dir() + kolla.find_dockerfiles() + kolla.create_dockerfiles() + kolla.build_image_list() + expected_parent = '{}/{}base:{}'.format( + kolla.namespace, kolla.image_prefix, kolla.tag) + child = [i for i in kolla.images if i.name == 'child'][0] + self.assertEqual(expected_parent, child.parent_name) + def _get_matched_images(self, images): return [image for image in images if image.status == utils.Status.MATCHED] |
