sync: Fix path confusion and directory creation bugs
parent
a3fb05de71
commit
2313b72a7d
|
@ -19,6 +19,7 @@ package cluster
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
@ -37,6 +38,20 @@ func syncLocalAssets(cr command.Runner) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dirs := map[string]bool{}
|
||||||
|
for _, f := range fs {
|
||||||
|
dirs[f.GetTargetDir()] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
args := []string{"mkdir", "-p"}
|
||||||
|
for k, _ := range dirs {
|
||||||
|
args = append(args, k)
|
||||||
|
}
|
||||||
|
cmd := exec.Command("sudo", args...)
|
||||||
|
if _, err := cr.RunCmd(cmd); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
for _, f := range fs {
|
for _, f := range fs {
|
||||||
err := cr.Copy(f)
|
err := cr.Copy(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -79,6 +94,9 @@ func assetsFromDir(localRoot string, destRoot string, flatten bool) ([]assets.Co
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// On Windows, rel will be separated by \, which is not correct inside the VM
|
||||||
|
rel = filepath.ToSlash(rel)
|
||||||
|
|
||||||
// The conversion will strip the leading 0 if present, so add it back if necessary
|
// The conversion will strip the leading 0 if present, so add it back if necessary
|
||||||
ps := fmt.Sprintf("%o", fi.Mode().Perm())
|
ps := fmt.Sprintf("%o", fi.Mode().Perm())
|
||||||
if len(ps) == 3 {
|
if len(ps) == 3 {
|
||||||
|
|
|
@ -56,7 +56,13 @@ func TestFunctional(t *testing.T) {
|
||||||
|
|
||||||
profile := UniqueProfileName("functional")
|
profile := UniqueProfileName("functional")
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Minute)
|
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Minute)
|
||||||
defer CleanupWithLogs(t, profile, cancel)
|
defer func() {
|
||||||
|
p := localSyncTestPath()
|
||||||
|
if err := os.Remove(p); err != nil {
|
||||||
|
t.Logf("unable to remove %s: %v", p, err)
|
||||||
|
}
|
||||||
|
CleanupWithLogs(t, profile, cancel)
|
||||||
|
}()
|
||||||
|
|
||||||
// Serial tests
|
// Serial tests
|
||||||
t.Run("serial", func(t *testing.T) {
|
t.Run("serial", func(t *testing.T) {
|
||||||
|
@ -626,11 +632,21 @@ func validateMySQL(ctx context.Context, t *testing.T, profile string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vmSyncTestPath is where the test file will be synced into the VM
|
||||||
|
func vmSyncTestPath() string {
|
||||||
|
return fmt.Sprintf("/etc/test/nested/copy/%d/hosts", os.Getpid())
|
||||||
|
}
|
||||||
|
|
||||||
|
// localSyncTestPath is where the test file will be synced into the VM
|
||||||
|
func localSyncTestPath() string {
|
||||||
|
return filepath.Join(localpath.MiniPath(), "/files", vmSyncTestPath())
|
||||||
|
}
|
||||||
|
|
||||||
// Copy extra file into minikube home folder for file sync test
|
// Copy extra file into minikube home folder for file sync test
|
||||||
func setupFileSync(ctx context.Context, t *testing.T, profile string) {
|
func setupFileSync(ctx context.Context, t *testing.T, profile string) {
|
||||||
// 1. copy random file to MINIKUBE_HOME/files/etc
|
p := localSyncTestPath()
|
||||||
f := filepath.Join(localpath.MiniPath(), "/files/etc/sync.test")
|
t.Logf("local sync path: %s", p)
|
||||||
err := copy.Copy("./testdata/sync.test", f)
|
err := copy.Copy("./testdata/sync.test", p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("copy: %v", err)
|
t.Fatalf("copy: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -641,18 +657,22 @@ func validateFileSync(ctx context.Context, t *testing.T, profile string) {
|
||||||
if NoneDriver() {
|
if NoneDriver() {
|
||||||
t.Skipf("skipping: ssh unsupported by none")
|
t.Skipf("skipping: ssh unsupported by none")
|
||||||
}
|
}
|
||||||
// check file existence
|
|
||||||
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "cat /etc/sync.test"))
|
vp := vmSyncTestPath()
|
||||||
|
t.Logf("Checking for existence of %s within VM", vp)
|
||||||
|
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", fmt.Sprintf("cat %s", vp)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s failed: %v", rr.Args, err)
|
t.Errorf("%s failed: %v", rr.Args, err)
|
||||||
}
|
}
|
||||||
|
got := rr.Stdout.String()
|
||||||
|
t.Logf("file sync test content: %s", got)
|
||||||
|
|
||||||
expected, err := ioutil.ReadFile("./testdata/sync.test")
|
expected, err := ioutil.ReadFile("./testdata/sync.test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("test file not found: %v", err)
|
t.Errorf("test file not found: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if diff := cmp.Diff(string(expected), rr.Stdout.String()); diff != "" {
|
if diff := cmp.Diff(string(expected), got); diff != "" {
|
||||||
t.Errorf("/etc/sync.test content mismatch (-want +got):\n%s", diff)
|
t.Errorf("/etc/sync.test content mismatch (-want +got):\n%s", diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue