Merge pull request #2287 from shin-/2284-ensure-network-exists-run

Ensure network exists when calling run before up
This commit is contained in:
Daniel Nephin 2015-10-30 10:41:55 -04:00
commit 04a76dc284
2 changed files with 16 additions and 0 deletions

View File

@ -380,6 +380,8 @@ class TopLevelCommand(DocoptCommand):
start_deps=True,
strategy=ConvergenceStrategy.never,
)
elif project.use_networking:
project.ensure_network_exists()
tty = True
if detach or options['-T'] or not sys.stdin.isatty():

View File

@ -508,6 +508,20 @@ class CLITestCase(DockerClientTestCase):
container, = service.containers(stopped=True, one_off=True)
self.assertEqual(container.name, name)
@mock.patch('dockerpty.start')
def test_run_with_networking(self, _):
self.require_api_version('1.21')
client = docker_client(version='1.21')
self.command.base_dir = 'tests/fixtures/simple-dockerfile'
self.command.dispatch(['--x-networking', 'run', 'simple', 'true'], None)
service = self.project.get_service('simple')
container, = service.containers(stopped=True, one_off=True)
networks = client.networks(names=[self.project.name])
for n in networks:
self.addCleanup(client.remove_network, n['id'])
self.assertEqual(len(networks), 1)
self.assertEqual(container.human_readable_command, u'true')
def test_rm(self):
service = self.project.get_service('simple')
service.create_container()