mirror of
https://github.com/containers/podman.git
synced 2025-09-26 08:14:14 +08:00
Merge pull request #20365 from p-fruck/fix/api-compat-network-connected
fix(API): Catch ErrNetworkConnected for compat
This commit is contained in:
@ -530,7 +530,7 @@ func (c *Container) NetworkConnect(nameOrID, netName string, netOpts types.PerNe
|
||||
|
||||
if err := c.runtime.state.NetworkConnect(c, netName, netOpts); err != nil {
|
||||
// Docker compat: treat requests to attach already attached networks as a no-op, ignoring opts
|
||||
if errors.Is(err, define.ErrNetworkConnected) && c.ensureState(define.ContainerStateConfigured) {
|
||||
if errors.Is(err, define.ErrNetworkConnected) && !c.ensureState(define.ContainerStateRunning, define.ContainerStateCreated) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -448,6 +448,10 @@ func Connect(w http.ResponseWriter, r *http.Request) {
|
||||
utils.Error(w, http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
if errors.Is(err, define.ErrNetworkConnected) {
|
||||
utils.Error(w, http.StatusForbidden, err)
|
||||
return
|
||||
}
|
||||
utils.Error(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
@ -218,4 +218,26 @@ t GET networks/$nid 200 .Name="network5" \
|
||||
# clean the network
|
||||
podman network rm -f network5
|
||||
|
||||
#
|
||||
# Test connecting container to network when connection already exists
|
||||
#
|
||||
podman network create netcon
|
||||
podman create --network bridge --name c1 $IMAGE top
|
||||
|
||||
# connect c1 to the network for the first time.
|
||||
t POST networks/netcon/connect Container=c1 200 OK
|
||||
# connect c1 to netcon again should not error
|
||||
t POST networks/netcon/connect Container=c1 200 OK
|
||||
|
||||
# connect c1 to netcon here should error as the container is running and it is already connected
|
||||
podman start c1
|
||||
t POST networks/netcon/connect Container=c1 403 .cause="network is already connected"
|
||||
|
||||
# connect c1 to netcon here should not error as container was stopped
|
||||
podman stop c1
|
||||
t POST networks/netcon/connect Container=c1 200 OK
|
||||
|
||||
# cleanup
|
||||
podman network rm -f netcon
|
||||
|
||||
# vim: filetype=sh
|
||||
|
Reference in New Issue
Block a user