File upload to DRS-enabled clusters (fix #202)

This commit is contained in:
Michael Kuzmin 2019-01-05 00:55:04 +03:00
parent fd2d78c73b
commit 3c005a9291
4 changed files with 83 additions and 20 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ bin/
.env .env
test*.json test*.json
crash.log crash.log
packer_cache/

View File

@ -83,11 +83,16 @@ func (ds *Datastore) ResolvePath(path string) string {
func (ds *Datastore) UploadFile(src, dst string, host string) error { func (ds *Datastore) UploadFile(src, dst string, host string) error {
p := soap.DefaultUpload p := soap.DefaultUpload
h, err := ds.driver.FindHost(host) ctx := ds.driver.ctx
if err != nil {
return err if host != "" {
h, err := ds.driver.FindHost(host)
if err != nil {
return err
}
ctx = ds.ds.HostContext(ctx, h.host)
} }
ctx := ds.ds.HostContext(ds.driver.ctx, h.host)
return ds.ds.UploadFile(ctx, src, dst, &p) return ds.ds.UploadFile(ctx, src, dst, &p)
} }

View File

@ -1,7 +1,10 @@
package driver package driver
import ( import (
"fmt"
"io/ioutil"
"testing" "testing"
"time"
) )
func TestDatastoreAcc(t *testing.T) { func TestDatastoreAcc(t *testing.T) {
@ -18,3 +21,73 @@ func TestDatastoreAcc(t *testing.T) {
t.Errorf("Wrong datastore. expected: 'datastore1', got: '%v'", info.Name) t.Errorf("Wrong datastore. expected: 'datastore1', got: '%v'", info.Name)
} }
} }
func TestFileUpload(t *testing.T) {
dsName := "datastore1"
hostName := "esxi-1.vsphere65.test"
fileName := fmt.Sprintf("test-%v", time.Now().Unix())
tmpFile, err := ioutil.TempFile("", fileName)
if err != nil {
t.Fatalf("Error creating temp file")
}
err = tmpFile.Close()
if err != nil {
t.Fatalf("Error creating temp file")
}
d := newTestDriver(t)
ds, err := d.FindDatastore(dsName, hostName)
if err != nil {
t.Fatalf("Cannot find datastore '%v': %v", dsName, err)
}
err = ds.UploadFile(tmpFile.Name(), fileName, hostName)
if err != nil {
t.Fatalf("Cannot upload file: %v", err)
}
if ds.FileExists(fileName) != true {
t.Fatalf("Cannot find file")
}
err = ds.Delete(fileName)
if err != nil {
t.Fatalf("Cannot delete file: %v", err)
}
}
func TestFileUploadDRS(t *testing.T) {
dsName := "datastore3"
hostName := ""
fileName := fmt.Sprintf("test-%v", time.Now().Unix())
tmpFile, err := ioutil.TempFile("", fileName)
if err != nil {
t.Fatalf("Error creating temp file")
}
err = tmpFile.Close()
if err != nil {
t.Fatalf("Error creating temp file")
}
d := newTestDriver(t)
ds, err := d.FindDatastore(dsName, hostName)
if err != nil {
t.Fatalf("Cannot find datastore '%v': %v", dsName, err)
}
err = ds.UploadFile(tmpFile.Name(), fileName, hostName)
if err != nil {
t.Fatalf("Cannot upload file: %v", err)
}
if ds.FileExists(fileName) != true {
t.Fatalf("Cannot find file")
}
err = ds.Delete(fileName)
if err != nil {
t.Fatalf("Cannot delete file: %v", err)
}
}

View File

@ -1,16 +0,0 @@
d-i passwd/user-fullname string jetbrains
d-i passwd/username string jetbrains
d-i passwd/user-password password jetbrains
d-i passwd/user-password-again password jetbrains
d-i user-setup/allow-password-weak boolean true
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string regular
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i pkgsel/include string open-vm-tools openssh-server
d-i finish-install/reboot_in_progress note