Skip to contentSkip to conversation

docker: Don't enable networking as a side-effect of DEBUG=1

PATCH In review Daniel P. Berrange 2 participants 6 messages Jul 13, 2017 – Jul 14, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 docker: Don't enable networking as a side-effect of DEBUG=1

When trying to debug problems with tests it is natural to set DEBUG=1 when starting the docker environment. Unfortunately this has a side-effect of enabling an eth0 network interface in the container, which changes the operating environment of the test suite. IOW tests with fail may suddenly start working again if DEBUG=1 is set, due to changed network setup.

Add a separate NETWORK variable to allow enablement of networking separately from DEBUG=1. This can be used in two ways. To enable the default docker network backend

make docker-test-build@fedora NETWORK=1

while to enable a specific network backend, eg join the network associated with the container 'wibble':

make docker-test-build@fedora NETWORK=container:wibble

---

Changed in v2:

- Remove reference to eth0
- Allow arbitrary docker network backend to be given

 tests/docker/Makefile.include | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tests/docker/Makefile.include +4 -1
index 037cb9e9e7..ec8e8d935d 100644
@@ -106,6 +106,8 @@ docker:
 	@echo '                         (default is 1)'
 	@echo '    DEBUG=1              Stop and drop to shell in the created container'
 	@echo '                         before running the command.'
+	@echo '    NETWORK=1            Enable virtual network interface with default backend.'
+	@echo '    NETWORK=$BACKEND     Enable virtual network interface with $BACKEND.'
 	@echo '    NOUSER               Define to disable adding current user to containers passwd.'
 	@echo '    NOCACHE=1            Ignore cache when build images.'
 	@echo '    EXECUTABLE=<path>    Include executable in image.'
@@ -132,7 +134,8 @@ docker-run: docker-qemu-src
 		$(SRC_PATH)/tests/docker/docker.py run 			\
 			$(if $(NOUSER),,-u $(shell id -u)) -t 		\
 			$(if $V,,--rm) 					\
-			$(if $(DEBUG),-i,--net=none) 			\
+			$(if $(DEBUG),-i,)				\
+			$(if $(NETWORK),$(if $(subst $(NETWORK),,1)$(subst 1,,$(NETWORK)),--net=$(NETWORK),),--net=none) \
 			-e TARGET_LIST=$(TARGET_LIST) 			\
 			-e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \
 			-e V=$V -e J=$J -e DEBUG=$(DEBUG)		\
Signature · 1 line
2.13.0
#1 lore raw
Quoted 43 lines · Daniel P. Berrange

When trying to debug problems with tests it is natural to set DEBUG=1 when starting the docker environment. Unfortunately this has a side-effect of enabling an eth0 network interface in the container, which changes the operating environment of the test suite. IOW tests with fail may suddenly start working again if DEBUG=1 is set, due to changed network setup.

Add a separate NETWORK variable to allow enablement of networking separately from DEBUG=1. This can be used in two ways. To enable the default docker network backend

make docker-test-build@fedora NETWORK=1

while to enable a specific network backend, eg join the network associated with the container 'wibble':

make docker-test-build@fedora NETWORK=container:wibble

---

Changed in v2:

- Remove reference to eth0
- Allow arbitrary docker network backend to be given

 tests/docker/Makefile.include | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tests/docker/Makefile.include +2 -0
index 037cb9e9e7..ec8e8d935d 100644
@@ -106,6 +106,8 @@ docker:
 	@echo '                         (default is 1)'
 	@echo '    DEBUG=1              Stop and drop to shell in the created container'
 	@echo '                         before running the command.'
+	@echo '    NETWORK=1            Enable virtual network interface with default backend.'
+	@echo '    NETWORK=$BACKEND     Enable virtual network interface with $BACKEND.'
 	@echo '    NOUSER               Define to disable adding current user to containers passwd.'
 	@echo '    NOCACHE=1            Ignore cache when build images.'
 	@echo '    EXECUTABLE=<path>    Include executable in image.'

tests/docker/Makefile.include docker-run: docker-qemu-src · line 138

Quoted 6 lines
tests/docker/Makefile.include +2 -1
@@ -132,7 +134,8 @@ docker-run: docker-qemu-src
 		$(SRC_PATH)/tests/docker/docker.py run 			\
 			$(if $(NOUSER),,-u $(shell id -u)) -t 		\
 			$(if $V,,--rm) 					\
-			$(if $(DEBUG),-i,--net=none) 			\
+			$(if $(DEBUG),-i,)				\
+			$(if $(NETWORK),$(if $(subst $(NETWORK),,1)$(subst 1,,$(NETWORK)),--net=$(NETWORK),),--net=none) \

Isn't the first subst enough? We already know $(NETWORK) is non-empty. If it is "1", $(subst 1,,1) is empty; otherwise, $(subst foo,,1) is non-empty:

			$(if $(NETWORK),$(if $(subst $(NETWORK),,1),,--net=$(NETWORK)),--net=none) \

The second subst is only a necessary condition.

Another way to write it is:

			$(if $(NETWORK),$(if $(findstring $(NETWORK),1),,--net=$(NETWORK)),--net=none) \

Fam

Quoted 6 lines
tests/docker/Makefile.include +0 -0
 			-e TARGET_LIST=$(TARGET_LIST) 			\
 			-e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \
 			-e V=$V -e J=$J -e DEBUG=$(DEBUG)		\
Signature · 1 line
2.13.0
#2 lore raw
Quoted 54 lines · Fam Zheng
Quoted 43 lines · Daniel P. Berrange

When trying to debug problems with tests it is natural to set DEBUG=1 when starting the docker environment. Unfortunately this has a side-effect of enabling an eth0 network interface in the container, which changes the operating environment of the test suite. IOW tests with fail may suddenly start working again if DEBUG=1 is set, due to changed network setup.

Add a separate NETWORK variable to allow enablement of networking separately from DEBUG=1. This can be used in two ways. To enable the default docker network backend

make docker-test-build@fedora NETWORK=1

while to enable a specific network backend, eg join the network associated with the container 'wibble':

make docker-test-build@fedora NETWORK=container:wibble

---

Changed in v2:

- Remove reference to eth0
- Allow arbitrary docker network backend to be given

 tests/docker/Makefile.include | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tests/docker/Makefile.include +2 -0
index 037cb9e9e7..ec8e8d935d 100644
@@ -106,6 +106,8 @@ docker:
 	@echo '                         (default is 1)'
 	@echo '    DEBUG=1              Stop and drop to shell in the created container'
 	@echo '                         before running the command.'
+	@echo '    NETWORK=1            Enable virtual network interface with default backend.'
+	@echo '    NETWORK=$BACKEND     Enable virtual network interface with $BACKEND.'
 	@echo '    NOUSER               Define to disable adding current user to containers passwd.'
 	@echo '    NOCACHE=1            Ignore cache when build images.'
 	@echo '    EXECUTABLE=<path>    Include executable in image.'

tests/docker/Makefile.include docker-run: docker-qemu-src · line 138

Quoted 6 lines
tests/docker/Makefile.include +2 -1
@@ -132,7 +134,8 @@ docker-run: docker-qemu-src
 		$(SRC_PATH)/tests/docker/docker.py run 			\
 			$(if $(NOUSER),,-u $(shell id -u)) -t 		\
 			$(if $V,,--rm) 					\
-			$(if $(DEBUG),-i,--net=none) 			\
+			$(if $(DEBUG),-i,)				\
+			$(if $(NETWORK),$(if $(subst $(NETWORK),,1)$(subst 1,,$(NETWORK)),--net=$(NETWORK),),--net=none) \

Isn't the first subst enough? We already know $(NETWORK) is non-empty. If it is "1", $(subst 1,,1) is empty; otherwise, $(subst foo,,1) is non-empty:

Quoted 1 line
			$(if $(NETWORK),$(if $(subst $(NETWORK),,1),,--net=$(NETWORK)),--net=none) \

This looks inverted to me - NETWORK=1, will generate --net=1 and NETWORK=foo generates empty string.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#3 lore raw
Quoted 55 lines · Daniel P. Berrange
Quoted 54 lines · Fam Zheng
Quoted 43 lines · Daniel P. Berrange

When trying to debug problems with tests it is natural to set DEBUG=1 when starting the docker environment. Unfortunately this has a side-effect of enabling an eth0 network interface in the container, which changes the operating environment of the test suite. IOW tests with fail may suddenly start working again if DEBUG=1 is set, due to changed network setup.

Add a separate NETWORK variable to allow enablement of networking separately from DEBUG=1. This can be used in two ways. To enable the default docker network backend

make docker-test-build@fedora NETWORK=1

while to enable a specific network backend, eg join the network associated with the container 'wibble':

make docker-test-build@fedora NETWORK=container:wibble

---

Changed in v2:

- Remove reference to eth0
- Allow arbitrary docker network backend to be given

 tests/docker/Makefile.include | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tests/docker/Makefile.include +2 -0
index 037cb9e9e7..ec8e8d935d 100644
@@ -106,6 +106,8 @@ docker:
 	@echo '                         (default is 1)'
 	@echo '    DEBUG=1              Stop and drop to shell in the created container'
 	@echo '                         before running the command.'
+	@echo '    NETWORK=1            Enable virtual network interface with default backend.'
+	@echo '    NETWORK=$BACKEND     Enable virtual network interface with $BACKEND.'
 	@echo '    NOUSER               Define to disable adding current user to containers passwd.'
 	@echo '    NOCACHE=1            Ignore cache when build images.'
 	@echo '    EXECUTABLE=<path>    Include executable in image.'

tests/docker/Makefile.include docker-run: docker-qemu-src · line 138

Quoted 6 lines
tests/docker/Makefile.include +2 -1
@@ -132,7 +134,8 @@ docker-run: docker-qemu-src
 		$(SRC_PATH)/tests/docker/docker.py run 			\
 			$(if $(NOUSER),,-u $(shell id -u)) -t 		\
 			$(if $V,,--rm) 					\
-			$(if $(DEBUG),-i,--net=none) 			\
+			$(if $(DEBUG),-i,)				\
+			$(if $(NETWORK),$(if $(subst $(NETWORK),,1)$(subst 1,,$(NETWORK)),--net=$(NETWORK),),--net=none) \

Isn't the first subst enough? We already know $(NETWORK) is non-empty. If it is "1", $(subst 1,,1) is empty; otherwise, $(subst foo,,1) is non-empty:

Quoted 4 lines
Quoted 1 line
			$(if $(NETWORK),$(if $(subst $(NETWORK),,1),,--net=$(NETWORK)),--net=none) \

This looks inverted to me - NETWORK=1, will generate --net=1 and NETWORK=foo generates empty string.

You are right, I was confused (subst succeed is FALSE branch of if). I think s/,,/,/ and it will work?

Fam

#4 lore raw
Quoted 56 lines · Fam Zheng
Quoted 55 lines · Daniel P. Berrange
Quoted 54 lines · Fam Zheng
Quoted 43 lines · Daniel P. Berrange

When trying to debug problems with tests it is natural to set DEBUG=1 when starting the docker environment. Unfortunately this has a side-effect of enabling an eth0 network interface in the container, which changes the operating environment of the test suite. IOW tests with fail may suddenly start working again if DEBUG=1 is set, due to changed network setup.

Add a separate NETWORK variable to allow enablement of networking separately from DEBUG=1. This can be used in two ways. To enable the default docker network backend

make docker-test-build@fedora NETWORK=1

while to enable a specific network backend, eg join the network associated with the container 'wibble':

make docker-test-build@fedora NETWORK=container:wibble

---

Changed in v2:

- Remove reference to eth0
- Allow arbitrary docker network backend to be given

 tests/docker/Makefile.include | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tests/docker/Makefile.include +2 -0
index 037cb9e9e7..ec8e8d935d 100644
@@ -106,6 +106,8 @@ docker:
 	@echo '                         (default is 1)'
 	@echo '    DEBUG=1              Stop and drop to shell in the created container'
 	@echo '                         before running the command.'
+	@echo '    NETWORK=1            Enable virtual network interface with default backend.'
+	@echo '    NETWORK=$BACKEND     Enable virtual network interface with $BACKEND.'
 	@echo '    NOUSER               Define to disable adding current user to containers passwd.'
 	@echo '    NOCACHE=1            Ignore cache when build images.'
 	@echo '    EXECUTABLE=<path>    Include executable in image.'

tests/docker/Makefile.include docker-run: docker-qemu-src · line 138

Quoted 6 lines
tests/docker/Makefile.include +2 -1
@@ -132,7 +134,8 @@ docker-run: docker-qemu-src
 		$(SRC_PATH)/tests/docker/docker.py run 			\
 			$(if $(NOUSER),,-u $(shell id -u)) -t 		\
 			$(if $V,,--rm) 					\
-			$(if $(DEBUG),-i,--net=none) 			\
+			$(if $(DEBUG),-i,)				\
+			$(if $(NETWORK),$(if $(subst $(NETWORK),,1)$(subst 1,,$(NETWORK)),--net=$(NETWORK),),--net=none) \

Isn't the first subst enough? We already know $(NETWORK) is non-empty. If it is "1", $(subst 1,,1) is empty; otherwise, $(subst foo,,1) is non-empty:

Quoted 7 lines
Quoted 4 lines
Quoted 1 line
			$(if $(NETWORK),$(if $(subst $(NETWORK),,1),,--net=$(NETWORK)),--net=none) \

This looks inverted to me - NETWORK=1, will generate --net=1 and NETWORK=foo generates empty string.

You are right, I was confused (subst succeed is FALSE branch of if). I think s/,,/,/ and it will work?

Yep

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#5 lore raw
Quoted 13 lines · Daniel P. Berrange
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

tests/docker/Makefile.include docker-run: docker-qemu-src · line 138

Quoted 7 lines
tests/docker/Makefile.include +2 -1
@@ -132,7 +134,8 @@ docker-run: docker-qemu-src
 		$(SRC_PATH)/tests/docker/docker.py run 			\
 			$(if $(NOUSER),,-u $(shell id -u)) -t 		\
 			$(if $V,,--rm) 					\
-			$(if $(DEBUG),-i,--net=none) 			\
+			$(if $(DEBUG),-i,)				\
+			$(if $(NETWORK),$(if $(subst $(NETWORK),,1)$(subst 1,,$(NETWORK)),--net=$(NETWORK),),--net=none) \

Isn't the first subst enough? We already know $(NETWORK) is non-empty. If it is "1", $(subst 1,,1) is empty; otherwise, $(subst foo,,1) is non-empty:

			$(if $(NETWORK),$(if $(subst $(NETWORK),,1),,--net=$(NETWORK)),--net=none) \
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

This looks inverted to me - NETWORK=1, will generate --net=1 and NETWORK=foo generates empty string.

You are right, I was confused (subst succeed is FALSE branch of if). I think s/,,/,/ and it will work?

Yep

OK, so dropping the second "$(subst ...)" and the comma we have:

			$(if $(NETWORK),$(if $(subst $(NETWORK),,1),--net=$(NETWORK)),--net=none) \

With that, queued for 2.10:

https://github.com/famz/qemu/tree/staging

Fam