Skip to content

Commit

Permalink
[v4.0-rhel] all: stop using deprecated GenerateNonCryptoID
Browse files Browse the repository at this point in the history
Cherry-pick containers#15788 to v4.0-rhel branch per RHBZ 2157930

In view of containers/storage#1337, do this:

	for f in $(git grep -l stringid.GenerateNonCryptoID | grep -v '^vendor/'); do
		sed -i 's/stringid.GenerateNonCryptoID/stringid.GenerateRandomID/g' $f;
	done

Signed-off-by: Kir Kolyshkin <[email protected]>
Signed-off-by: tomsweeneyredhat <[email protected]>
  • Loading branch information
kolyshkin authored and TomSweeneyRedHat committed Feb 1, 2023
1 parent 11afff3 commit 361ec22
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 96 deletions.
4 changes: 2 additions & 2 deletions libpod/container_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (c *Container) ExecCreate(config *ExecConfig) (string, error) {
}

// Generate an ID for our new exec session
sessionID := stringid.GenerateNonCryptoID()
sessionID := stringid.GenerateRandomID()
found := true
// This really ought to be a do-while, but Go doesn't have those...
for found {
Expand All @@ -192,7 +192,7 @@ func (c *Container) ExecCreate(config *ExecConfig) (string, error) {
}
}
if found {
sessionID = stringid.GenerateNonCryptoID()
sessionID = stringid.GenerateRandomID()
}
}

Expand Down
2 changes: 1 addition & 1 deletion libpod/pod_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func newPod(runtime *Runtime) *Pod {
pod := new(Pod)
pod.config = new(PodConfig)
pod.config.ID = stringid.GenerateNonCryptoID()
pod.config.ID = stringid.GenerateRandomID()
pod.config.Labels = make(map[string]string)
pod.config.CreatedTime = time.Now()
// pod.config.InfraContainer = new(ContainerConfig)
Expand Down
6 changes: 3 additions & 3 deletions libpod/runtime_ctr.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (r *Runtime) initContainerVariables(rSpec *spec.Spec, config *ContainerConf
ctr.state = new(ContainerState)

if config == nil {
ctr.config.ID = stringid.GenerateNonCryptoID()
ctr.config.ID = stringid.GenerateRandomID()
size, err := units.FromHumanSize(r.config.Containers.ShmSize)
if err != nil {
return nil, errors.Wrapf(err, "converting containers.conf ShmSize %s to an int", r.config.Containers.ShmSize)
Expand All @@ -184,7 +184,7 @@ func (r *Runtime) initContainerVariables(rSpec *spec.Spec, config *ContainerConf
}
// If the ID is empty a new name for the restored container was requested
if ctr.config.ID == "" {
ctr.config.ID = stringid.GenerateNonCryptoID()
ctr.config.ID = stringid.GenerateRandomID()
}
// Reset the log path to point to the default
ctr.config.LogPath = ""
Expand Down Expand Up @@ -453,7 +453,7 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai
if vol.Name == "" {
// Anonymous volume. We'll need to create it.
// It needs a name first.
vol.Name = stringid.GenerateNonCryptoID()
vol.Name = stringid.GenerateRandomID()
isAnonymous = true
} else {
// Check if it exists already
Expand Down
2 changes: 1 addition & 1 deletion libpod/runtime_volume_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (r *Runtime) newVolume(ctx context.Context, options ...VolumeCreateOption)
}

if volume.config.Name == "" {
volume.config.Name = stringid.GenerateNonCryptoID()
volume.config.Name = stringid.GenerateRandomID()
}
if volume.config.Driver == "" {
volume.config.Driver = define.VolumeDriverLocal
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
// happens. So, use a podman-%s.sock-lock empty file as a marker.
tries := 0
for {
uuid := stringid.GenerateNonCryptoID()
uuid := stringid.GenerateRandomID()
lockPath := fmt.Sprintf("%s-%s.sock-lock", pathPrefix, uuid)
lockFile, err := os.OpenFile(lockPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0700)
if err == nil {
Expand Down Expand Up @@ -904,7 +904,7 @@ func generateNetworkConfig(p *PodmanTestIntegration) (string, string) {
conf string
)
// generate a random name to prevent conflicts with other tests
name := "net" + stringid.GenerateNonCryptoID()
name := "net" + stringid.GenerateRandomID()
if p.NetworkBackend != Netavark {
path = filepath.Join(p.NetworkConfigDir, fmt.Sprintf("%s.conflist", name))
conf = fmt.Sprintf(`{
Expand Down Expand Up @@ -1040,5 +1040,5 @@ func ncz(port int) bool {
}

func createNetworkName(name string) string {
return name + stringid.GenerateNonCryptoID()[:10]
return name + stringid.GenerateRandomID()[:10]
}
2 changes: 1 addition & 1 deletion test/e2e/create_staticmac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var _ = Describe("Podman run with --mac-address flag", func() {
})

It("Podman run --mac-address with custom network", func() {
net := "n1" + stringid.GenerateNonCryptoID()
net := "n1" + stringid.GenerateRandomID()
session := podmanTest.Podman([]string{"network", "create", net})
session.WaitWithDefaultTimeout()
defer podmanTest.removeNetwork(net)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ var _ = Describe("Podman create", func() {
pod.WaitWithDefaultTimeout()
Expect(pod).Should(Exit(0))

netName := "pod" + stringid.GenerateNonCryptoID()
netName := "pod" + stringid.GenerateRandomID()
session := podmanTest.Podman([]string{"network", "create", netName})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ var _ = Describe("Podman diff", func() {
})

It("podman image diff", func() {
file1 := "/" + stringid.GenerateNonCryptoID()
file2 := "/" + stringid.GenerateNonCryptoID()
file3 := "/" + stringid.GenerateNonCryptoID()
file1 := "/" + stringid.GenerateRandomID()
file2 := "/" + stringid.GenerateRandomID()
file3 := "/" + stringid.GenerateRandomID()

// Create container image with the files
containerfile := fmt.Sprintf(`
Expand Down Expand Up @@ -153,8 +153,8 @@ RUN echo test
})

It("podman diff container and image with same name", func() {
imagefile := "/" + stringid.GenerateNonCryptoID()
confile := "/" + stringid.GenerateNonCryptoID()
imagefile := "/" + stringid.GenerateRandomID()
confile := "/" + stringid.GenerateRandomID()

// Create container image with the files
containerfile := fmt.Sprintf(`
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ var _ = Describe("Podman events", func() {
})

It("podman events --until future", func() {
name1 := stringid.GenerateNonCryptoID()
name2 := stringid.GenerateNonCryptoID()
name3 := stringid.GenerateNonCryptoID()
name1 := stringid.GenerateRandomID()
name2 := stringid.GenerateRandomID()
name3 := stringid.GenerateRandomID()
session := podmanTest.Podman([]string{"create", "--name", name1, ALPINE})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expand Down
34 changes: 18 additions & 16 deletions test/e2e/network_connect_disconnect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var _ = Describe("Podman network connect and disconnect", func() {
})

It("bad container name in network disconnect should result in error", func() {
netName := "aliasTest" + stringid.GenerateNonCryptoID()
netName := "aliasTest" + stringid.GenerateRandomID()
session := podmanTest.Podman([]string{"network", "create", netName})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expand All @@ -54,7 +54,7 @@ var _ = Describe("Podman network connect and disconnect", func() {
})

It("network disconnect with net mode slirp4netns should result in error", func() {
netName := "slirp" + stringid.GenerateNonCryptoID()
netName := "slirp" + stringid.GenerateRandomID()
session := podmanTest.Podman([]string{"network", "create", netName})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expand All @@ -72,7 +72,8 @@ var _ = Describe("Podman network connect and disconnect", func() {
})

It("podman network disconnect", func() {
netName := "aliasTest" + stringid.GenerateNonCryptoID()
SkipIfRootlessCgroupsV1("stats not supported under rootless CgroupsV1")
netName := "aliasTest" + stringid.GenerateRandomID()
session := podmanTest.Podman([]string{"network", "create", netName})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expand Down Expand Up @@ -123,7 +124,7 @@ var _ = Describe("Podman network connect and disconnect", func() {
})

It("bad container name in network connect should result in error", func() {
netName := "aliasTest" + stringid.GenerateNonCryptoID()
netName := "aliasTest" + stringid.GenerateRandomID()
session := podmanTest.Podman([]string{"network", "create", netName})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expand All @@ -135,7 +136,7 @@ var _ = Describe("Podman network connect and disconnect", func() {
})

It("network connect with net mode slirp4netns should result in error", func() {
netName := "slirp" + stringid.GenerateNonCryptoID()
netName := "slirp" + stringid.GenerateRandomID()
session := podmanTest.Podman([]string{"network", "create", netName})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expand All @@ -152,8 +153,8 @@ var _ = Describe("Podman network connect and disconnect", func() {
Expect(con.ErrorToString()).To(ContainSubstring(`"slirp4netns" is not supported: invalid network mode`))
})

It("podman connect on a container that already is connected to the network should error", func() {
netName := "aliasTest" + stringid.GenerateNonCryptoID()
It("podman connect on a container that already is connected to the network should error after init", func() {
netName := "aliasTest" + stringid.GenerateRandomID()
session := podmanTest.Podman([]string{"network", "create", netName})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expand All @@ -176,7 +177,8 @@ var _ = Describe("Podman network connect and disconnect", func() {
})

It("podman network connect", func() {
netName := "aliasTest" + stringid.GenerateNonCryptoID()
SkipIfRootlessCgroupsV1("stats not supported under rootless CgroupsV1")
netName := "aliasTest" + stringid.GenerateRandomID()
session := podmanTest.Podman([]string{"network", "create", netName})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expand All @@ -192,7 +194,7 @@ var _ = Describe("Podman network connect and disconnect", func() {
Expect(exec).Should(Exit(0))

// Create a second network
newNetName := "aliasTest" + stringid.GenerateNonCryptoID()
newNetName := "aliasTest" + stringid.GenerateRandomID()
session = podmanTest.Podman([]string{"network", "create", newNetName, "--subnet", "10.11.100.0/24"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expand Down Expand Up @@ -245,13 +247,13 @@ var _ = Describe("Podman network connect and disconnect", func() {
})

It("podman network connect when not running", func() {
netName1 := "connect1" + stringid.GenerateNonCryptoID()
netName1 := "connect1" + stringid.GenerateRandomID()
session := podmanTest.Podman([]string{"network", "create", netName1})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
defer podmanTest.removeNetwork(netName1)

netName2 := "connect2" + stringid.GenerateNonCryptoID()
netName2 := "connect2" + stringid.GenerateRandomID()
session = podmanTest.Podman([]string{"network", "create", netName2})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expand Down Expand Up @@ -284,7 +286,7 @@ var _ = Describe("Podman network connect and disconnect", func() {
})

It("podman network connect and run with network ID", func() {
netName := "ID" + stringid.GenerateNonCryptoID()
netName := "ID" + stringid.GenerateRandomID()
session := podmanTest.Podman([]string{"network", "create", netName})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expand All @@ -304,7 +306,7 @@ var _ = Describe("Podman network connect and disconnect", func() {
Expect(exec).Should(Exit(0))

// Create a second network
newNetName := "ID2" + stringid.GenerateNonCryptoID()
newNetName := "ID2" + stringid.GenerateRandomID()
session = podmanTest.Podman([]string{"network", "create", newNetName})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expand All @@ -331,13 +333,13 @@ var _ = Describe("Podman network connect and disconnect", func() {
})

It("podman network disconnect when not running", func() {
netName1 := "aliasTest" + stringid.GenerateNonCryptoID()
netName1 := "aliasTest" + stringid.GenerateRandomID()
session := podmanTest.Podman([]string{"network", "create", netName1})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
defer podmanTest.removeNetwork(netName1)

netName2 := "aliasTest" + stringid.GenerateNonCryptoID()
netName2 := "aliasTest" + stringid.GenerateRandomID()
session2 := podmanTest.Podman([]string{"network", "create", netName2})
session2.WaitWithDefaultTimeout()
Expect(session2).Should(Exit(0))
Expand Down Expand Up @@ -376,7 +378,7 @@ var _ = Describe("Podman network connect and disconnect", func() {
})

It("podman network disconnect and run with network ID", func() {
netName := "aliasTest" + stringid.GenerateNonCryptoID()
netName := "aliasTest" + stringid.GenerateRandomID()
session := podmanTest.Podman([]string{"network", "create", netName})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expand Down
Loading

0 comments on commit 361ec22

Please sign in to comment.