func TestMain(t *testing.T) { ctx := context.Background() for i, model := range []*simulator.Model{simulator.ESX(), simulator.VPX()} { t.Logf("%d", i) defer model.Remove() err := model.Create() if err != nil { t.Fatal(err) } s := model.Service.NewServer() defer s.Close() s.URL.User = url.UserPassword("user", "pass") t.Logf("server URL: %s", s.URL) var sess *session.Session if i == 0 { sess, err = getESXSession(ctx, s.URL.String()) } else { sess, err = getVPXSession(ctx, s.URL.String()) } if err != nil { t.Fatal(err) } defer sess.Logout(ctx) testGetChildrenVMs(ctx, sess, t) testGetChildVM(ctx, sess, t) testFindResourcePool(ctx, sess, t) testGetCluster(ctx, sess, t) } }
func TestMain(t *testing.T) { log.SetLevel(log.DebugLevel) ctx := context.Background() for i, model := range []*simulator.Model{simulator.ESX(), simulator.VPX()} { t.Logf("%d", i) defer model.Remove() err := model.Create() if err != nil { t.Fatal(err) } s := model.Service.NewServer() defer s.Close() s.URL.User = url.UserPassword("user", "pass") s.URL.Path = "" t.Logf("server URL: %s", s.URL) var input *data.Data if i == 0 { input = getESXData(s.URL) } else { input = getVPXData(s.URL) } if err != nil { t.Fatal(err) } installSettings := &data.InstallerData{} installSettings.ApplianceSize.CPU.Limit = 1 installSettings.ApplianceSize.Memory.Limit = 1024 validator, err := validate.NewValidator(ctx, input) if err != nil { t.Fatalf("Failed to validator: %s", err) } validator.DisableFirewallCheck = true validator.DisableDRSCheck = true conf, err := validator.Validate(ctx, input) if err != nil { log.Errorf("Failed to validate conf: %s", err) validator.ListIssues() } // FIXME: get host NetworkSystem failed in simulator // testCreateNetwork(ctx, validator.Session, conf, t) testCreateVolumeStores(ctx, validator.Session, conf, false, t) testDeleteVolumeStores(ctx, validator.Session, conf, 1, t) errConf := &config.VirtualContainerHostConfigSpec{} *errConf = *conf errConf.VolumeLocations = make(map[string]*url.URL) errConf.VolumeLocations["volume-store"], _ = url.Parse("ds://store_not_exist/volumes/test") testCreateVolumeStores(ctx, validator.Session, errConf, true, t) testCreateAppliance(ctx, validator.Session, conf, installSettings, false, t) } }
func TestMain(t *testing.T) { log.SetLevel(log.DebugLevel) trace.Logger.Level = log.DebugLevel ctx := context.Background() for i, model := range []*simulator.Model{simulator.ESX(), simulator.VPX()} { t.Logf("%d", i) model.Datastore = 3 defer model.Remove() err := model.Create() if err != nil { t.Fatal(err) } s := model.Service.NewServer() defer s.Close() s.URL.User = url.UserPassword("user", "pass") s.URL.Path = "" t.Logf("server URL: %s", s.URL) var input *data.Data if i == 0 { input = getESXData(s.URL) } else { input = getVPXData(s.URL) } if err != nil { t.Fatal(err) } validator, err := NewValidator(ctx, input) if err != nil { t.Errorf("Failed to new validator: %s", err) } ds, _ := validator.Session.Finder.Datastore(validator.Context, "LocalDS_1") simulator.Map.Get(ds.Reference()).(mo.Entity).Entity().Name = "Local DS_0" ds, _ = validator.Session.Finder.Datastore(validator.Context, "LocalDS_2") simulator.Map.Get(ds.Reference()).(mo.Entity).Entity().Name = `😗` validator.DisableFirewallCheck = true validator.DisableDRSCheck = true t.Logf("session pool: %s", validator.Session.Pool) if err = createPool(ctx, validator.Session, input.ComputeResourcePath, "validator", t); err != nil { t.Errorf("Unable to create resource pool: %s", err) } conf := testCompute(validator, input, t) testTargets(validator, input, conf, t) testStorage(validator, input, conf, t) // testNetwork() need dvs support } }
func TestConnect(t *testing.T) { ctx := context.Background() for _, model := range []*simulator.Model{simulator.ESX(), simulator.VPX()} { defer model.Remove() err := model.Create() if err != nil { t.Fatal(err) } model.Service.TLS = new(tls.Config) s := model.Service.NewServer() defer s.Close() config := &Config{ Keepalive: time.Minute, Service: s.URL.String(), } for _, thumbprint := range []string{"", s.CertificateInfo().ThumbprintSHA1} { u := *s.URL config.Service = u.String() config.Thumbprint = thumbprint _, err = NewSession(config).Connect(ctx) if thumbprint == "" { if err == nil { t.Error("expected x509.UnknownAuthorityError error") } } else { if err != nil { t.Error(err) } } u.User = nil config.Service = u.String() _, err = NewSession(config).Connect(ctx) if err == nil { t.Fatal("expected login error") } config.Service = "" _, err = NewSession(config).Connect(ctx) if err == nil { t.Fatal("expected URL parse error") } } } }
func TestFinder(t *testing.T) { log.SetLevel(log.DebugLevel) trace.Logger.Level = log.DebugLevel ctx := context.Background() for i, model := range []*simulator.Model{simulator.ESX(), simulator.VPX()} { t.Logf("%d", i) defer model.Remove() if i == 1 { model.Datacenter = 2 model.Cluster = 2 model.Host = 2 model.Pool = 0 } err := model.Create() if err != nil { t.Fatal(err) } s := model.Service.NewServer() defer s.Close() s.URL.User = url.UserPassword("user", "pass") s.URL.Path = "" t.Logf("server URL: %s", s.URL) var input *data.Data if i == 0 { input = getESXData(s.URL) } else { input = getVPXData(s.URL) } if err != nil { t.Fatal(err) } validator, err := validate.CreateNoDCCheck(ctx, input) if err != nil { t.Errorf("Failed to create validator: %s", err) } prefix := fmt.Sprintf("p%d-", i) if err = createTestData(ctx, validator.Session, prefix); err != nil { t.Errorf("Failed to create test data: %s", err) } // FIXME: ServerFaultCode: no such object: SearchIndex:ha-searchindex // testSearchVCHs(t, validator) } }
func main() { model := simulator.VPX() flag.IntVar(&model.Datacenter, "dc", model.Datacenter, "Number of datacenters") flag.IntVar(&model.Cluster, "cluster", model.Cluster, "Number of clusters") flag.IntVar(&model.ClusterHost, "host", model.ClusterHost, "Number of hosts per cluster") flag.IntVar(&model.Host, "standalone-host", model.Host, "Number of standalone hosts") flag.IntVar(&model.Datastore, "ds", model.Datastore, "Number of local datastores") flag.IntVar(&model.Machine, "vm", model.Machine, "Number of virtual machines per resource pool") flag.IntVar(&model.Pool, "pool", model.Pool, "Number of resource pools per compute resource") isESX := flag.Bool("esx", false, "Simulate standalone ESX") flag.Parse() f := flag.Lookup("httptest.serve") if f.Value.String() == "" { f.Value.Set("localhost:8989") } if *isESX { opts := model model = simulator.ESX() // Preserve options that also apply to ESX model.Datastore = opts.Datastore model.Machine = opts.Machine } tag := " (govmomi simulator)" model.ServiceContent.About.Name += tag model.ServiceContent.About.OsType = runtime.GOOS + "-" + runtime.GOARCH esx.HostSystem.Summary.Hardware.Vendor += tag defer model.Remove() err := model.Create() if err != nil { log.Fatal(err) } model.Service.NewServer() }
func main() { model := simulator.VPX() flag.IntVar(&model.Datacenter, "dc", model.Datacenter, "Number of datacenters") flag.IntVar(&model.Cluster, "cluster", model.Cluster, "Number of clusters") flag.IntVar(&model.ClusterHost, "host", model.ClusterHost, "Number of hosts per cluster") flag.IntVar(&model.Host, "standalone-host", model.Host, "Number of standalone hosts") flag.IntVar(&model.Datastore, "ds", model.Datastore, "Number of local datastores") flag.IntVar(&model.Machine, "vm", model.Machine, "Number of virtual machines per resource pool") flag.IntVar(&model.Pool, "pool", model.Pool, "Number of resource pools per compute resource") isESX := flag.Bool("esx", false, "Simulate standalone ESX") isTLS := flag.Bool("tls", false, "Enable TLS") cert := flag.String("tlscert", "", "Path to TLS certificate file") key := flag.String("tlskey", "", "Path to TLS key file") flag.Parse() f := flag.Lookup("httptest.serve") if f.Value.String() == "" { _ = f.Value.Set("127.0.0.1:8989") } if *isESX { opts := model model = simulator.ESX() // Preserve options that also apply to ESX model.Datastore = opts.Datastore model.Machine = opts.Machine } tag := " (govmomi simulator)" model.ServiceContent.About.Name += tag model.ServiceContent.About.OsType = runtime.GOOS + "-" + runtime.GOARCH esx.HostSystem.Summary.Hardware.Vendor += tag defer model.Remove() err := model.Create() if err != nil { log.Fatal(err) } if *isTLS { model.Service.TLS = new(tls.Config) if *cert != "" { c, err := tls.LoadX509KeyPair(*cert, *key) if err != nil { log.Fatal(err) } model.Service.TLS.Certificates = []tls.Certificate{c} } } s := model.Service.NewServer() fmt.Printf("GOVC_URL=%s", s.URL) select {} }
func TestDelete(t *testing.T) { log.SetLevel(log.DebugLevel) trace.Logger.Level = log.DebugLevel ctx := context.Background() for i, model := range []*simulator.Model{simulator.ESX(), simulator.VPX()} { t.Logf("%d", i) defer model.Remove() err := model.Create() if err != nil { t.Fatal(err) } s := model.Service.NewServer() defer s.Close() s.URL.User = url.UserPassword("user", "pass") s.URL.Path = "" t.Logf("server URL: %s", s.URL) var input *data.Data if i == 0 { input = getESXData(s.URL) } else { input = getVPXData(s.URL) } if err != nil { t.Fatal(err) } installSettings := &data.InstallerData{} installSettings.ApplianceSize.CPU.Limit = 1 installSettings.ApplianceSize.Memory.Limit = 1024 installSettings.ResourcePoolPath = path.Join(input.ComputeResourcePath, input.DisplayName) validator, err := validate.NewValidator(ctx, input) if err != nil { t.Errorf("Failed to validator: %s", err) } validator.DisableFirewallCheck = true validator.DisableDRSCheck = true conf, err := validator.Validate(ctx, input) if err != nil { log.Errorf("Failed to validate conf: %s", err) validator.ListIssues() } createAppliance(ctx, validator.Session, conf, installSettings, false, t) // FIXME: cannot check if it's VCH or not // testNewVCHFromCompute(input.ComputeResourcePath, input.DisplayName, validator, t) // testDeleteVCH(validator, conf, t) testDeleteDatastoreFiles(validator, t) } }