diff options
author | Paul Holzinger <pholzing@redhat.com> | 2021-09-27 15:34:28 +0200 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2021-09-27 16:08:30 +0200 |
commit | 1df0646b018882c35d73d1bf14c9cdfe1a0c47bd (patch) | |
tree | 4ae8f2202e6ee004eb4002fbd337ebf7bfc1a0c6 /libpod/network | |
parent | 869cb9a65413cc99bf8ed0e158c0e2f7b0df513a (diff) | |
download | podman-1df0646b018882c35d73d1bf14c9cdfe1a0c47bd.tar.gz podman-1df0646b018882c35d73d1bf14c9cdfe1a0c47bd.tar.bz2 podman-1df0646b018882c35d73d1bf14c9cdfe1a0c47bd.zip |
CNI: network remove do not error for ENOENT
Make podman network rm more robust by checking for ENOENT if we cannot
remove the config file. If it does not exists there is no reason to
error. This is especially useful for podman network prune.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'libpod/network')
-rw-r--r-- | libpod/network/cni/config.go | 6 | ||||
-rw-r--r-- | libpod/network/cni/config_test.go | 21 |
2 files changed, 26 insertions, 1 deletions
diff --git a/libpod/network/cni/config.go b/libpod/network/cni/config.go index 670ee0c65..3df155637 100644 --- a/libpod/network/cni/config.go +++ b/libpod/network/cni/config.go @@ -170,7 +170,11 @@ func (n *cniNetwork) NetworkRemove(nameOrID string) error { file := network.filename delete(n.networks, network.libpodNet.Name) - return os.Remove(file) + // make sure to not error for ErrNotExist + if err := os.Remove(file); err != nil && !errors.Is(err, os.ErrNotExist) { + return err + } + return nil } // NetworkList will return all known Networks. Optionally you can diff --git a/libpod/network/cni/config_test.go b/libpod/network/cni/config_test.go index a0a0ea1af..288cf4626 100644 --- a/libpod/network/cni/config_test.go +++ b/libpod/network/cni/config_test.go @@ -1021,6 +1021,27 @@ var _ = Describe("Config", func() { Expect(err.Error()).To(ContainSubstring("subnet 10.10.0.0/24 is already used on the host or by another config")) }) + It("remove network should not error when config file does not exists on disk", func() { + name := "mynet" + network := types.Network{Name: name} + _, err := libpodNet.NetworkCreate(network) + Expect(err).To(BeNil()) + + path := filepath.Join(cniConfDir, name+".conflist") + Expect(path).To(BeARegularFile()) + + err = os.Remove(path) + Expect(err).To(BeNil()) + Expect(path).ToNot(BeARegularFile()) + + err = libpodNet.NetworkRemove(name) + Expect(err).To(BeNil()) + + nets, err := libpodNet.NetworkList() + Expect(err).To(BeNil()) + Expect(nets).To(HaveLen(1)) + Expect(nets).ToNot(ContainElement(HaveNetworkName(name))) + }) }) Context("network load valid existing ones", func() { |