8
8
import pytest
9
9
import six
10
10
11
- from .base import BaseAPIIntegrationTest
12
- from ..helpers import requires_api_version , requires_experimental
11
+ from .base import BaseAPIIntegrationTest , BUSYBOX
12
+ from ..helpers import random_name , requires_api_version , requires_experimental
13
13
14
14
15
15
class BuildTest (BaseAPIIntegrationTest ):
@@ -214,21 +214,31 @@ def test_build_container_with_target(self):
214
214
215
215
@requires_api_version ('1.25' )
216
216
def test_build_with_network_mode (self ):
217
+ # Set up pingable endpoint on custom network
218
+ network = self .client .create_network (random_name ())['Id' ]
219
+ self .tmp_networks .append (network )
220
+ container = self .client .create_container (BUSYBOX , 'top' )
221
+ self .tmp_containers .append (container )
222
+ self .client .start (container )
223
+ self .client .connect_container_to_network (
224
+ container , network , aliases = ['pingtarget.docker' ]
225
+ )
226
+
217
227
script = io .BytesIO ('\n ' .join ([
218
228
'FROM busybox' ,
219
- 'RUN wget http://google.com '
229
+ 'RUN ping -c1 pingtarget.docker '
220
230
]).encode ('ascii' ))
221
231
222
232
stream = self .client .build (
223
- fileobj = script , network_mode = 'bridge' ,
224
- tag = 'dockerpytest_bridgebuild '
233
+ fileobj = script , network_mode = network ,
234
+ tag = 'dockerpytest_customnetbuild '
225
235
)
226
236
227
- self .tmp_imgs .append ('dockerpytest_bridgebuild ' )
237
+ self .tmp_imgs .append ('dockerpytest_customnetbuild ' )
228
238
for chunk in stream :
229
- pass
239
+ print chunk
230
240
231
- assert self .client .inspect_image ('dockerpytest_bridgebuild ' )
241
+ assert self .client .inspect_image ('dockerpytest_customnetbuild ' )
232
242
233
243
script .seek (0 )
234
244
stream = self .client .build (
@@ -260,7 +270,7 @@ def test_build_with_extra_hosts(self):
260
270
fileobj = script , tag = img_name ,
261
271
extra_hosts = {
262
272
'extrahost.local.test' : '127.0.0.1' ,
263
- 'hello.world.test' : '8.8.8.8 ' ,
273
+ 'hello.world.test' : '127.0.0.1 ' ,
264
274
}, decode = True
265
275
)
266
276
for chunk in stream :
@@ -274,7 +284,7 @@ def test_build_with_extra_hosts(self):
274
284
if six .PY3 :
275
285
logs = logs .decode ('utf-8' )
276
286
assert '127.0.0.1\t extrahost.local.test' in logs
277
- assert '8.8.8.8 \t hello.world.test' in logs
287
+ assert '127.0.0.1 \t hello.world.test' in logs
278
288
279
289
@requires_experimental (until = None )
280
290
@requires_api_version ('1.25' )
0 commit comments