Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for custom rbd export-diff command #102

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

llamerada-jp
Copy link
Contributor

No description provided.

@llamerada-jp llamerada-jp changed the title Rbd export diff test Add tests for custom rbd export-diff command Jan 21, 2025
@llamerada-jp llamerada-jp force-pushed the rbd-export-diff-test branch 14 times, most recently from f0bfef2 to 93f1358 Compare January 29, 2025 01:16
@llamerada-jp llamerada-jp force-pushed the rbd-export-diff-test branch 10 times, most recently from e7470c2 to b256928 Compare February 5, 2025 09:11
@llamerada-jp llamerada-jp force-pushed the rbd-export-diff-test branch 5 times, most recently from 9c3b1d3 to 1a230e8 Compare February 6, 2025 01:43
@llamerada-jp llamerada-jp force-pushed the rbd-export-diff-test branch 2 times, most recently from cf7706a to 9366cd3 Compare February 12, 2025 07:55
@llamerada-jp llamerada-jp force-pushed the rbd-export-diff-test branch 2 times, most recently from 45ce7b8 to fb019a9 Compare February 18, 2025 09:02
@llamerada-jp llamerada-jp marked this pull request as ready for review February 18, 2025 09:04
@satoru-takeuchi satoru-takeuchi requested review from ushitora-anqou and removed request for satoru-takeuchi February 19, 2025 00:26

func TestMTest(t *testing.T) {
if os.Getenv("CEPH_CMD_TEST") == "" {
t.Skip("Run under ceph/")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make the test fail here? I'd like to avoid using t.Skip because I remember topolvm/topolvm#1005.


description: "(181) not specify snapshot name",
exportArgs: []string{
"--read-offset", "0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value should be >0 according to the test spec?


// creating snapshots
// snapshots[0] and snapshots[1] have diff with the image
// snapshots[2] and snapshots[2] has no diff with the image
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo?

Suggested change
// snapshots[2] and snapshots[2] has no diff with the image
// snapshots[2] and snapshots[3] has no diff with the image

Expect(err).NotTo(HaveOccurred())
}
// crate snapshot[3] with the same data as snapshot[2]
// random file snapshot[3] is not exist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// random file snapshot[3] is not exist
// random file named snapshot[3] does not exist

expectedDataName: t.snapshots[0],
exportArgs: []string{
"-p", t.poolName,
fmt.Sprintf("%s@%s", t.srcImageName, t.snapshots[0]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to check pool/image@snap format, too.


args := []string{path.Join(workDir, filename), path.Join(workDir, workFilename)}
log.Printf("📂 diff %s", strings.Join(args, " "))
_, err := exec.Command("diff", args...).CombinedOutput()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be appropriate to use cmp(1) rather than diff(1) because the files are binary.

Comment on lines 38 to 55
func Kubectl(args ...string) ([]byte, error) {
if len(kubectlCmd) == 0 {
return nil, fmt.Errorf("KUBECTL environment variable should be set")
}

icon := "⚓"
if cephMatcher.MatchString(strings.Join(args, " ")) {
icon = "🐙"
}
log.Printf("%s kubectl %s", icon, strings.Join(args, " "))
var stdout bytes.Buffer
command := exec.Command(kubectlCmd, args...)
command.Stdout = &stdout
command.Stderr = os.Stderr

err := command.Run()
return stdout.Bytes(), err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we implement Kubectl by using KubectlWithInput as follows?

Suggested change
func Kubectl(args ...string) ([]byte, error) {
if len(kubectlCmd) == 0 {
return nil, fmt.Errorf("KUBECTL environment variable should be set")
}
icon := "⚓"
if cephMatcher.MatchString(strings.Join(args, " ")) {
icon = "🐙"
}
log.Printf("%s kubectl %s", icon, strings.Join(args, " "))
var stdout bytes.Buffer
command := exec.Command(kubectlCmd, args...)
command.Stdout = &stdout
command.Stderr = os.Stderr
err := command.Run()
return stdout.Bytes(), err
}
func Kubectl(args ...string) ([]byte, error) {
return KubectlWithInput(nil, args...)
}

}
if string(after) != string(before) {
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we insert some sleeps for reproducibility?

}

func CleanupGlobal() error {
SCs, err := GetObjectList[storagev1.StorageClassList]("sc", "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SCs, err := GetObjectList[storagev1.StorageClassList]("sc", "")
scs, err := GetObjectList[storagev1.StorageClassList]("sc", "")

)

func Rbd(args ...string) ([]byte, error) {
return Kubectl(append([]string{"exec", "-n", ROOK_NAMESPACE, "deploy/rook-ceph-tools", "--", "rbd"}, args...)...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we write this line as follows?

Suggested change
return Kubectl(append([]string{"exec", "-n", ROOK_NAMESPACE, "deploy/rook-ceph-tools", "--", "rbd"}, args...)...)
return Kubectl("exec", "-n", ROOK_NAMESPACE, "deploy/rook-ceph-tools", "--", "rbd", args...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it, but couldn't.

Signed-off-by: Yuji Ito <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants