Skip to content

Commit 5557130

Browse files
committed
Merge branch 'master' of github.com:docker/docker-py
2 parents a043173 + 1aee1df commit 5557130

File tree

4 files changed

+63
-38
lines changed

4 files changed

+63
-38
lines changed

docker/auth/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def decode_auth(auth):
9292
if isinstance(auth, six.string_types):
9393
auth = auth.encode('ascii')
9494
s = base64.b64decode(auth)
95-
login, pwd = s.split(b':')
95+
login, pwd = s.split(b':', 1)
9696
return login.decode('ascii'), pwd.decode('ascii')
9797

9898

docker/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
299299
if os.path.exists(dockerignore):
300300
with open(dockerignore, 'r') as f:
301301
exclude = list(filter(bool, f.read().split('\n')))
302+
# These are handled by the docker daemon and should not be
303+
# excluded on the client
304+
if 'Dockerfile' in exclude:
305+
exclude.remove('Dockerfile')
306+
if '.dockerignore' in exclude:
307+
exclude.remove(".dockerignore")
302308
context = utils.tar(path, exclude=exclude)
303309

304310
if utils.compare_version('1.8', self._version) >= 0:

tests/integration_test.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
# export; history; import_image; insert; port; push; tag; get; load; stats;
3333

3434
DEFAULT_BASE_URL = os.environ.get('DOCKER_HOST')
35+
EXEC_DRIVER_IS_NATIVE = True
3536

3637
warnings.simplefilter('error')
3738
create_host_config = docker.utils.create_host_config
@@ -312,6 +313,7 @@ def runTest(self):
312313
self.assertFalse(inspect_data['VolumesRW'][mount_dest])
313314

314315

316+
@unittest.skipIf(not EXEC_DRIVER_IS_NATIVE, 'Exec driver not native')
315317
class TestCreateContainerReadOnlyFs(BaseTestCase):
316318
def runTest(self):
317319
ctnr = self.client.create_container(
@@ -325,6 +327,7 @@ def runTest(self):
325327
self.assertNotEqual(res, 0)
326328

327329

330+
@unittest.skipIf(not EXEC_DRIVER_IS_NATIVE, 'Exec driver not native')
328331
class TestStartContainerReadOnlyFs(BaseTestCase):
329332
def runTest(self):
330333
# Presumably a bug in 1.5.0
@@ -351,14 +354,18 @@ def runTest(self):
351354

352355
class TestRenameContainer(BaseTestCase):
353356
def runTest(self):
357+
version = self.client.version()['Version']
354358
name = 'hong_meiling'
355359
res = self.client.create_container('busybox', 'true')
356360
self.assertIn('Id', res)
357361
self.tmp_containers.append(res['Id'])
358362
self.client.rename(res, name)
359363
inspect = self.client.inspect_container(res['Id'])
360364
self.assertIn('Name', inspect)
361-
self.assertEqual(name, inspect['Name'])
365+
if version == '1.5.0':
366+
self.assertEqual(name, inspect['Name'])
367+
else:
368+
self.assertEqual('/{0}'.format(name), inspect['Name'])
362369

363370

364371
class TestStartContainer(BaseTestCase):
@@ -581,7 +588,8 @@ def runTest(self):
581588
self.assertIn('State', container_info)
582589
state = container_info['State']
583590
self.assertIn('ExitCode', state)
584-
self.assertNotEqual(state['ExitCode'], 0)
591+
if EXEC_DRIVER_IS_NATIVE:
592+
self.assertNotEqual(state['ExitCode'], 0)
585593
self.assertIn('Running', state)
586594
self.assertEqual(state['Running'], False)
587595

@@ -598,7 +606,8 @@ def runTest(self):
598606
self.assertIn('State', container_info)
599607
state = container_info['State']
600608
self.assertIn('ExitCode', state)
601-
self.assertNotEqual(state['ExitCode'], 0)
609+
if EXEC_DRIVER_IS_NATIVE:
610+
self.assertNotEqual(state['ExitCode'], 0)
602611
self.assertIn('Running', state)
603612
self.assertEqual(state['Running'], False)
604613

@@ -614,7 +623,8 @@ def runTest(self):
614623
self.assertIn('State', container_info)
615624
state = container_info['State']
616625
self.assertIn('ExitCode', state)
617-
self.assertNotEqual(state['ExitCode'], 0)
626+
if EXEC_DRIVER_IS_NATIVE:
627+
self.assertNotEqual(state['ExitCode'], 0)
618628
self.assertIn('Running', state)
619629
self.assertEqual(state['Running'], False)
620630

@@ -630,7 +640,8 @@ def runTest(self):
630640
self.assertIn('State', container_info)
631641
state = container_info['State']
632642
self.assertIn('ExitCode', state)
633-
self.assertNotEqual(state['ExitCode'], 0)
643+
if EXEC_DRIVER_IS_NATIVE:
644+
self.assertNotEqual(state['ExitCode'], 0)
634645
self.assertIn('Running', state)
635646
self.assertEqual(state['Running'], False)
636647

@@ -978,6 +989,7 @@ def runTest(self):
978989
self.client.remove_container(id, force=True)
979990

980991

992+
@unittest.skipIf(not EXEC_DRIVER_IS_NATIVE, 'Exec driver not native')
981993
class TestExecuteCommand(BaseTestCase):
982994
def runTest(self):
983995
container = self.client.create_container('busybox', 'cat',
@@ -991,6 +1003,7 @@ def runTest(self):
9911003
self.assertEqual(res, expected)
9921004

9931005

1006+
@unittest.skipIf(not EXEC_DRIVER_IS_NATIVE, 'Exec driver not native')
9941007
class TestExecuteCommandString(BaseTestCase):
9951008
def runTest(self):
9961009
container = self.client.create_container('busybox', 'cat',
@@ -1004,6 +1017,7 @@ def runTest(self):
10041017
self.assertEqual(res, expected)
10051018

10061019

1020+
@unittest.skipIf(not EXEC_DRIVER_IS_NATIVE, 'Exec driver not native')
10071021
class TestExecuteCommandStreaming(BaseTestCase):
10081022
def runTest(self):
10091023
container = self.client.create_container('busybox', 'cat',
@@ -1311,6 +1325,8 @@ def runTest(self):
13111325
with open(os.path.join(base_dir, '.dockerignore'), 'w') as f:
13121326
f.write("\n".join([
13131327
'node_modules',
1328+
'Dockerfile',
1329+
'.dockerginore',
13141330
'', # empty line
13151331
]))
13161332

@@ -1329,6 +1345,8 @@ def runTest(self):
13291345
chunk = chunk.decode('utf-8')
13301346
logs += chunk
13311347
self.assertFalse('node_modules' in logs)
1348+
self.assertFalse('Dockerfile' in logs)
1349+
self.assertFalse('.dockerginore' in logs)
13321350
self.assertTrue('not-ignored' in logs)
13331351

13341352
#######################
@@ -1458,5 +1476,7 @@ def test_443(self):
14581476
if __name__ == '__main__':
14591477
c = docker.Client(base_url=DEFAULT_BASE_URL)
14601478
c.pull('busybox')
1479+
exec_driver = c.info()['ExecutionDriver']
1480+
EXEC_DRIVER_IS_NATIVE = exec_driver.startswith('native')
14611481
c.close()
14621482
unittest.main()

tests/test.py

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,11 +2115,10 @@ def test_load_config(self):
21152115
folder = tempfile.mkdtemp()
21162116
self.addCleanup(shutil.rmtree, folder)
21172117
dockercfg_path = os.path.join(folder, '.dockercfg')
2118-
f = open(dockercfg_path, 'w')
2119-
auth_ = base64.b64encode(b'sakuya:izayoi').decode('ascii')
2120-
f.write('auth = {0}\n'.format(auth_))
2121-
f.write('email = [email protected]')
2122-
f.close()
2118+
with open(dockercfg_path, 'w') as f:
2119+
auth_ = base64.b64encode(b'sakuya:izayoi').decode('ascii')
2120+
f.write('auth = {0}\n'.format(auth_))
2121+
f.write('email = [email protected]')
21232122
cfg = docker.auth.load_config(dockercfg_path)
21242123
self.assertTrue(docker.auth.INDEX_URL in cfg)
21252124
self.assertNotEqual(cfg[docker.auth.INDEX_URL], None)
@@ -2175,18 +2174,18 @@ def test_tar_with_excludes(self):
21752174
(['test/foo', 'a.txt'], ['bar', 'bar/a.txt', 'bar/b.py',
21762175
'bar/other.png', 'test']),
21772176
):
2178-
archive = docker.utils.tar(base, exclude=exclude)
2179-
tar = tarfile.open(fileobj=archive)
2180-
self.assertEqual(sorted(tar.getnames()), names)
2177+
with docker.utils.tar(base, exclude=exclude) as archive:
2178+
tar = tarfile.open(fileobj=archive)
2179+
self.assertEqual(sorted(tar.getnames()), names)
21812180

21822181
def test_tar_with_empty_directory(self):
21832182
base = tempfile.mkdtemp()
21842183
self.addCleanup(shutil.rmtree, base)
21852184
for d in ['foo', 'bar']:
21862185
os.makedirs(os.path.join(base, d))
2187-
archive = docker.utils.tar(base)
2188-
tar = tarfile.open(fileobj=archive)
2189-
self.assertEqual(sorted(tar.getnames()), ['bar', 'foo'])
2186+
with docker.utils.tar(base) as archive:
2187+
tar = tarfile.open(fileobj=archive)
2188+
self.assertEqual(sorted(tar.getnames()), ['bar', 'foo'])
21902189

21912190
def test_tar_with_file_symlinks(self):
21922191
base = tempfile.mkdtemp()
@@ -2195,19 +2194,19 @@ def test_tar_with_file_symlinks(self):
21952194
f.write("content")
21962195
os.makedirs(os.path.join(base, 'bar'))
21972196
os.symlink('../foo', os.path.join(base, 'bar/foo'))
2198-
archive = docker.utils.tar(base)
2199-
tar = tarfile.open(fileobj=archive)
2200-
self.assertEqual(sorted(tar.getnames()), ['bar', 'bar/foo', 'foo'])
2197+
with docker.utils.tar(base) as archive:
2198+
tar = tarfile.open(fileobj=archive)
2199+
self.assertEqual(sorted(tar.getnames()), ['bar', 'bar/foo', 'foo'])
22012200

22022201
def test_tar_with_directory_symlinks(self):
22032202
base = tempfile.mkdtemp()
22042203
self.addCleanup(shutil.rmtree, base)
22052204
for d in ['foo', 'bar']:
22062205
os.makedirs(os.path.join(base, d))
22072206
os.symlink('../foo', os.path.join(base, 'bar/foo'))
2208-
archive = docker.utils.tar(base)
2209-
tar = tarfile.open(fileobj=archive)
2210-
self.assertEqual(sorted(tar.getnames()), ['bar', 'bar/foo', 'foo'])
2207+
with docker.utils.tar(base) as archive:
2208+
tar = tarfile.open(fileobj=archive)
2209+
self.assertEqual(sorted(tar.getnames()), ['bar', 'bar/foo', 'foo'])
22112210

22122211

22132212
class StreamTest(Cleanup, unittest.TestCase):
@@ -2293,21 +2292,21 @@ def test_early_stream_response(self):
22932292
b'\r\n'
22942293
) + b'\r\n'.join(lines)
22952294

2296-
client = docker.Client(base_url="http+unix://" + self.socket_file)
2297-
for i in range(5):
2298-
try:
2299-
stream = client.build(
2300-
path=self.build_context,
2301-
stream=True
2302-
)
2303-
break
2304-
except requests.ConnectionError as e:
2305-
if i == 4:
2306-
raise e
2307-
2308-
self.assertEqual(list(stream), [
2309-
str(i).encode() for i in range(50)])
2310-
2295+
with docker.Client(base_url="http+unix://" + self.socket_file) \
2296+
as client:
2297+
for i in range(5):
2298+
try:
2299+
stream = client.build(
2300+
path=self.build_context,
2301+
stream=True
2302+
)
2303+
break
2304+
except requests.ConnectionError as e:
2305+
if i == 4:
2306+
raise e
2307+
2308+
self.assertEqual(list(stream), [
2309+
str(i).encode() for i in range(50)])
23112310

23122311
if __name__ == '__main__':
23132312
unittest.main()

0 commit comments

Comments
 (0)