Revert "Check if volume paths exist before executing Docker."

This reverts commit 23154b26d5.

Change-Id: I8e1c753c22ba1304ab64b64a40cbfc758ac1861f
Related-Bug: #1843734
This commit is contained in:
Alex Schultz 2019-09-12 15:56:07 +00:00
parent 23154b26d5
commit 3ea0f81971
3 changed files with 5 additions and 81 deletions

View File

@ -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':

View File

@ -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:

View File

@ -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',