From 3ea0f8197170e374f54dc79e336f4382fe0bfcd7 Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Thu, 12 Sep 2019 15:56:07 +0000 Subject: [PATCH] Revert "Check if volume paths exist before executing Docker." This reverts commit 23154b26d57e4f25456b1f43bc5dff5fb373fc9e. Change-Id: I8e1c753c22ba1304ab64b64a40cbfc758ac1861f Related-Bug: #1843734 --- paunch/__init__.py | 4 +-- paunch/builder/compose1.py | 40 ++----------------------- paunch/tests/test_builder_compose1.py | 42 +-------------------------- 3 files changed, 5 insertions(+), 81 deletions(-) diff --git a/paunch/__init__.py b/paunch/__init__.py index 2ed65af..5d8131c 100644 --- a/paunch/__init__.py +++ b/paunch/__init__.py @@ -138,8 +138,8 @@ def debug(config_id, container_name, action, config, managed_by, labels=None, '--name', r.unique_container_name(container_name) ] - if builder.docker_run_args(cmd, container_name): - return r.execute_interactive(cmd) + builder.docker_run_args(cmd, container_name) + return r.execute_interactive(cmd) elif action == 'dump-yaml': print(yaml.safe_dump(config, default_flow_style=False)) elif action == 'dump-json': diff --git a/paunch/builder/compose1.py b/paunch/builder/compose1.py index cedf081..6e8c081 100644 --- a/paunch/builder/compose1.py +++ b/paunch/builder/compose1.py @@ -13,7 +13,6 @@ import json import logging -import os import re import tenacity import yaml @@ -62,15 +61,10 @@ class ComposeV1Builder(object): self.runner.unique_container_name(container) ] self.label_arguments(cmd, container) - validations_passed = self.docker_run_args(cmd, container) + self.docker_run_args(cmd, container) elif action == 'exec': cmd = [self.runner.docker_cmd, 'exec'] - validations_passed = self.docker_exec_args(cmd, container) - - if not validations_passed: - LOG.debug('Validations failed. Skipping container: %s' % - container) - continue + self.docker_exec_args(cmd, container) (cmd_stdout, cmd_stderr, returncode) = self.runner.execute(cmd) if cmd_stdout: @@ -169,12 +163,6 @@ class ComposeV1Builder(object): cmd.append('%s=%s' % (arg, v)) def docker_run_args(self, cmd, container): - """Prepare the run command args, from the container configuration. - - :param cmd: The list of command options to be modified - :param container: A dict with container configurations - :returns: True if configuration is valid, otherwise False - """ cconfig = self.config[container] if cconfig.get('detach', True): cmd.append('--detach=true') @@ -285,29 +273,7 @@ class ComposeV1Builder(object): cmd.append(cconfig.get('image', '')) cmd.extend(self.command_argument(cconfig.get('command'))) - # NOTE(xek): If the file to be mounted doesn't exist, Docker version - # 1.13.1 creates a directory in it's place. This behavior is different - # then Podman, which throws an error. We want to replicate the Podman - # behavior. Creating directories in place of files creates errors which - # are very difficult to diagnose. - for volume in cconfig.get('volumes', []): - host_path = volume.split(':', 1)[0] - if host_path and not os.path.exists(host_path): - LOG.error("Error running %s.\n" % cmd) - LOG.error('stderr: Error: error checking path "%s":' - ' stat %s: no such file or directory\n' % ( - host_path, host_path)) - return False - - return True - def docker_exec_args(self, cmd, container): - """Prepare the exec command args, from the container configuration. - - :param cmd: The list of command options to be modified - :param container: A dict with container configurations - :returns: True if configuration is valid, otherwise False - """ cconfig = self.config[container] if 'privileged' in cconfig: cmd.append('--privileged=%s' % str(cconfig['privileged']).lower()) @@ -321,8 +287,6 @@ class ComposeV1Builder(object): command[0], self.config_id) cmd.extend(command) - return True - def pull_missing_images(self, stdout, stderr): images = set() for container in self.config: diff --git a/paunch/tests/test_builder_compose1.py b/paunch/tests/test_builder_compose1.py index 114d2a4..a445b3a 100644 --- a/paunch/tests/test_builder_compose1.py +++ b/paunch/tests/test_builder_compose1.py @@ -453,44 +453,6 @@ three-12345678 three''', '', 0), cmd ) - @mock.patch('os.path.exists') - def test_docker_run_args_validation_true(self, path_exists): - path_exists.return_value = True - config = { - 'one': { - 'image': 'foo', - 'volumes': ['/foo:/foo:rw', '/bar:/bar:ro'], - } - } - builder = compose1.ComposeV1Builder('foo', config, None) - - cmd = ['docker'] - self.assertTrue(builder.docker_run_args(cmd, 'one')) - self.assertEqual( - ['docker', '--detach=true', - '--volume=/foo:/foo:rw', '--volume=/bar:/bar:ro', 'foo'], - cmd - ) - - @mock.patch('os.path.exists') - def test_docker_run_args_validation_false(self, path_exists): - path_exists.return_value = False - config = { - 'one': { - 'image': 'foo', - 'volumes': ['/foo:/foo:rw', '/bar:/bar:ro'], - } - } - builder = compose1.ComposeV1Builder('foo', config, None) - - cmd = ['docker'] - self.assertFalse(builder.docker_run_args(cmd, 'one')) - self.assertEqual( - ['docker', '--detach=true', - '--volume=/foo:/foo:rw', '--volume=/bar:/bar:ro', 'foo'], - cmd - ) - def test_durations(self): config = { 'a': {'stop_grace_period': 123}, @@ -522,9 +484,7 @@ three-12345678 three''', '', 0), builder.docker_run_args(cmd, container) self.assertIn(arg, cmd) - @mock.patch('os.path.exists') - def test_docker_run_args_lists(self, path_exists): - path_exists.return_value = True + def test_docker_run_args_lists(self): config = { 'one': { 'image': 'centos:7',