mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 02:43:36 +00:00
rbd: provide alternatives to preserve the ceph log files
Currently, we delete the ceph client log file on unmap/detach. This patch provides additional alternatives for users who would like to persist the log files. Strategies: ----------- `remove`: delete log file on unmap/detach `compress`: compress the log file to gzip on unmap/detach `preserve`: preserve the log file in text format Note that the default strategy will be remove on unmap, and these options can be tweaked from the storage class Compression size details example: On Map: (with debug-rbd=20) --------- $ ls -lh -rw-r--r-- 1 root root 526K Sep 1 18:15 rbd-nbd-0001-0024-fed5480a-f00f-417a-a51d-31d8a8144c03-0000000000000003-d2e89c87-0b4d-11ec-8ea6-160f128e682d.log On unmap: --------- $ ls -lh -rw-r--r-- 1 root root 33K Sep 1 18:15 rbd-nbd-0001-0024-fed5480a-f00f-417a-a51d-31d8a8144c03-0000000000000003-d2e89c87-0b4d-11ec-8ea6-160f128e682d.gz Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
10bbb049f7
commit
c9cc36d8db
@ -17,6 +17,9 @@ limitations under the License.
|
||||
package rbd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@ -208,3 +211,75 @@ func TestGetCephClientLogFileName(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestStrategicActionOnLogFile(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.TODO()
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
var logFile [3]string
|
||||
for i := 0; i < 3; i++ {
|
||||
f, err := ioutil.TempFile(tmpDir, "rbd-*.log")
|
||||
if err != nil {
|
||||
t.Errorf("creating tempfile failed: %v", err)
|
||||
}
|
||||
logFile[i] = f.Name()
|
||||
}
|
||||
|
||||
type args struct {
|
||||
logStrategy string
|
||||
logFile string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
}{
|
||||
{
|
||||
name: "test for compress",
|
||||
args: args{
|
||||
logStrategy: "compress",
|
||||
logFile: logFile[0],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "test for remove",
|
||||
args: args{
|
||||
logStrategy: "remove",
|
||||
logFile: logFile[1],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "test for preserve",
|
||||
args: args{
|
||||
logStrategy: "preserve",
|
||||
logFile: logFile[2],
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
strategicActionOnLogFile(ctx, tt.args.logStrategy, tt.args.logFile)
|
||||
|
||||
var err error
|
||||
switch tt.args.logStrategy {
|
||||
case "compress":
|
||||
newExt := strings.Replace(tt.args.logFile, ".log", ".gz", -1)
|
||||
if _, err = os.Stat(newExt); os.IsNotExist(err) {
|
||||
t.Errorf("compressed logFile (%s) not found: %v", newExt, err)
|
||||
}
|
||||
os.Remove(newExt)
|
||||
case "remove":
|
||||
if _, err = os.Stat(tt.args.logFile); !os.IsNotExist(err) {
|
||||
t.Errorf("logFile (%s) not removed: %v", tt.args.logFile, err)
|
||||
}
|
||||
case "preserve":
|
||||
if _, err = os.Stat(tt.args.logFile); os.IsNotExist(err) {
|
||||
t.Errorf("logFile (%s) not preserved: %v", tt.args.logFile, err)
|
||||
}
|
||||
os.Remove(tt.args.logFile)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user