Skip to content

Commit

Permalink
Cherry-pick: Fix bad portmapping from container network after VCH res…
Browse files Browse the repository at this point in the history
…tart bug (#6150) (#6311)
  • Loading branch information
mhagen-vmware authored Sep 13, 2017
1 parent 1760180 commit 2623754
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ $(imagec): $(call godeps,cmd/imagec/*.go) $(portlayerapi-client)
@echo building imagec...
@$(TIME) $(GO) build $(RACE) $(ldflags) -o ./$@ ./$(dir $<)

$(docker-engine-api): $$(call godeps,cmd/docker/*.go) $(portlayerapi-client) $(admiralapi-client)
$(docker-engine-api): $(portlayerapi-client) $(admiralapi-client) $$(call godeps,cmd/docker/*.go)
ifeq ($(OS),linux)
@echo Building docker-engine-api server...
@$(TIME) $(GO) build $(RACE) -ldflags "$(LDFLAGS)" -o $@ ./cmd/docker
Expand Down Expand Up @@ -347,7 +347,7 @@ $(portlayerapi-server): $(PORTLAYER_DEPS) $(SWAGGER)
@$(SWAGGER) generate server --exclude-main -A PortLayer --target lib/apiservers/portlayer -f lib/apiservers/portlayer/swagger.json 2>>swagger-gen.log
@echo done regenerating swagger models and operations for Portlayer API server...

$(portlayerapi): $$(call godeps,cmd/port-layer-server/*.go) $(portlayerapi-server) $(portlayerapi-client)
$(portlayerapi): $(portlayerapi-server) $(portlayerapi-client) $$(call godeps,cmd/port-layer-server/*.go)
@echo building Portlayer API server...
@$(TIME) $(GO) build $(RACE) -ldflags "$(LDFLAGS)" -o $@ ./cmd/port-layer-server

Expand Down
3 changes: 2 additions & 1 deletion lib/apiservers/engine/backends/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/vmware/vic/lib/config/dynamic"
"github.com/vmware/vic/lib/config/dynamic/admiral"
"github.com/vmware/vic/lib/imagec"
"github.com/vmware/vic/lib/portlayer/constants"
"github.com/vmware/vic/pkg/errors"
"github.com/vmware/vic/pkg/registry"
"github.com/vmware/vic/pkg/vsphere/session"
Expand Down Expand Up @@ -321,7 +322,7 @@ func setPortMapping(info *models.ContainerInfo, backend *Container, container *c
return err
}
for _, e := range endpointsOK.Payload {
if len(e.Ports) > 0 {
if len(e.Ports) > 0 && e.Scope == constants.BridgeScopeType {
if err = MapPorts(container.HostConfig, e, container.ContainerID); err != nil {
log.Errorf(err.Error())
return err
Expand Down
50 changes: 45 additions & 5 deletions tests/test-cases/Group6-VIC-Machine/6-07-Create-Network.robot
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ Container network - space in network name valid
Run Keyword And Ignore Error Cleanup Dangling VMs On Test Server
Run Keyword And Ignore Error Cleanup Datastore On Test Server

Log To Console Create a portgroup with a space in it's name
Log To Console Create a portgroup with a space in its name
${out}= Run govc host.portgroup.add -vswitch vSwitchLAN 'VM Network With Spaces'

Log To Console Create a bridge portgroup.
Expand Down Expand Up @@ -475,7 +475,7 @@ Container Firewalls

${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} run --net=bridge ${busybox} nc ${ip} 1234
Should Not Be Equal As Integers ${rc} 0

# Create a container on a bridge and closed network listening on port 1234.
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create --net=bridge --name closedbridge ${busybox} nc -l -p 1234
Should Be Equal As Integers ${rc} 0
Expand Down Expand Up @@ -520,7 +520,7 @@ Container Firewalls

${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create --net=bridge --name out2 ${busybox} nc out1 1234
Should Be Equal As Integers ${rc} 0
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} network connect outbound-net out2
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} network connect outbound-net out2
Should Be Equal As Integers ${rc} 0
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} start out2

Expand Down Expand Up @@ -576,8 +576,48 @@ Container network invalid 1
Container network invalid 2
Pass execution Test not implemented

Container network 1
Pass execution Test not implemented
Reset VCH doesn't cause unintentionally exposed ports from container network
Set Test Environment Variables
# Attempt to cleanup old/canceled tests
Run Keyword And Ignore Error Cleanup Dangling VMs On Test Server
Run Keyword And Ignore Error Cleanup Datastore On Test Server

${output}= Run bin/vic-machine-linux create --name=%{VCH-NAME} --target="%{TEST_USERNAME}:%{TEST_PASSWORD}@%{TEST_URL}" --thumbprint=%{TEST_THUMBPRINT} --image-store=%{TEST_DATASTORE} --bridge-network=bridge --container-network "VM Network":vmnet ${vicmachinetls}
Log ${output}
Should Contain ${output} Installer completed successfully
Get Docker Params ${output} ${true}
Log To Console Installer completed successfully: %{VCH-NAME}

${output}= Run docker %{VCH-PARAMS} network ls
Should Contain ${output} vmnet

${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} run -d --net=vmnet -p 80 nginx
Log ${output}
Should Be Equal As Integers ${rc} 0

${output}= Run And Return Rc And Output docker %{VCH-PARAMS} ps
Should Not Contain ${output} ->80/tcp

${rc} ${output}= Run And Return Rc And Output govc vm.power -reset=true %{VCH-NAME}
Log To Console ${output}
Should Be Equal As Integers 0 ${rc}

Reboot VM %{VCH-NAME}

Log To Console Getting VCH IP ...
${new-vch-ip}= Get VM IP %{VCH-NAME}
Log To Console New VCH IP is ${new-vch-ip}
Replace String %{VCH-PARAMS} %{VCH-IP} ${new-vch-ip}

# wait for docker info to succeed
Wait Until Keyword Succeeds 20x 5 seconds Run Docker Info %{VCH-PARAMS}

${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} ps
Should Not Contain ${output} ->80/tcp

# Delete the portgroup added by env vars keyword
Cleanup VIC Appliance On Test Server


Container network 2
Pass execution Test not implemented
Expand Down

0 comments on commit 2623754

Please sign in to comment.