Merge pull request #8465 from parth-gr/import-rbd-mirror

ceph: use mktemp file in ImportRBDMirrorBootstrapPeer
This commit is contained in:
Sébastien Han authored and GitHub committed 2021-08-05 09:44:43 +02:00
commit bb4e572d2f
2 files changed
+10 -9

No files matched your search

+10 -7
View File
@@ -46,27 +46,30 @@ var (
)
// ImportRBDMirrorBootstrapPeer add a mirror peer in the rbd-mirror configuration
func ImportRBDMirrorBootstrapPeer(context *clusterd.Context, clusterInfo *ClusterInfo, poolName, direction string, token []byte) error {
func ImportRBDMirrorBootstrapPeer(context *clusterd.Context, clusterInfo *ClusterInfo, poolName string, direction string, token []byte) error {
logger.Infof("add rbd-mirror bootstrap peer token for pool %q", poolName)
// Token file
// TODO: use mktemp?
tokenFilePath := fmt.Sprintf("/tmp/rbd-mirror-token-%s", poolName)
tokenFilePattern := fmt.Sprintf("rbd-mirror-token-%s", poolName)
tokenFilePath, err := ioutil.TempFile("/tmp", tokenFilePattern)
if err != nil {
return errors.Wrapf(err, "failed to create temporary token file for pool %q", poolName)
}
// Write token into a file
err := ioutil.WriteFile(tokenFilePath, token, 0400)
err = ioutil.WriteFile(tokenFilePath.Name(), token, 0400)
if err != nil {
return errors.Wrapf(err, "failed to write token to file %q", tokenFilePath)
return errors.Wrapf(err, "failed to write token to file %q", tokenFilePath.Name())
}
// Remove token once we exit, we don't need it anymore
defer func() error {
err := os.Remove(tokenFilePath)
err := os.Remove(tokenFilePath.Name())
return err
}() //nolint // we don't want to return here
// Build command
args := []string{"mirror", "pool", "peer", "bootstrap", "import", poolName, tokenFilePath}
args := []string{"mirror", "pool", "peer", "bootstrap", "import", poolName, tokenFilePath.Name()}
if direction != "" {
args = append(args, "--direction", direction)
}
-2
View File
@@ -107,7 +107,6 @@ func TestImportRBDMirrorBootstrapPeer(t *testing.T) {
assert.Equal(t, "bootstrap", args[3])
assert.Equal(t, "import", args[4])
assert.Equal(t, pool, args[5])
assert.Equal(t, "/tmp/rbd-mirror-token-pool-test", args[6])
assert.Equal(t, 11, len(args))
return mirrorStatus, nil
}
@@ -125,7 +124,6 @@ func TestImportRBDMirrorBootstrapPeer(t *testing.T) {
assert.Equal(t, "bootstrap", args[3])
assert.Equal(t, "import", args[4])
assert.Equal(t, pool, args[5])
assert.Equal(t, "/tmp/rbd-mirror-token-pool-test", args[6])
assert.Equal(t, "--direction", args[7])
assert.Equal(t, "rx-tx", args[8])
assert.Equal(t, 13, len(args))