Beispiel #1
0
func init() {
	sdk := env.URL(nil)
	if sdk != "" {
		flag.Set("sdk", sdk)
		flag.Set("vm-path", "docker-appliance")
		flag.Set("cluster", os.Getenv("GOVC_CLUSTER"))
	}

	// fake up a docker-host for pprof collection
	u := url.URL{Scheme: "http", Host: "127.0.0.1:6060"}

	go func() {
		log.Println(http.ListenAndServe(u.Host, nil))
	}()

	transport := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}
	insecureClient = &http.Client{Transport: transport}
	flag.Set("docker-host", u.Host)

	config.hostCertFile = "fixtures/vicadmin_test_cert.pem"
	config.hostKeyFile = "fixtures/vicadmin_test_pkey.pem"

	cert, cerr := ioutil.ReadFile(config.hostCertFile)
	key, kerr := ioutil.ReadFile(config.hostKeyFile)
	if kerr != nil || cerr != nil {
		panic("unable to load test certificate")
	}
	vchConfig.HostCertificate = &vchconfig.RawCertificate{
		Cert: cert,
		Key:  key,
	}
}
Beispiel #2
0
func TestSessionDefaults(t *testing.T) {
	ctx := context.Background()

	config := &Config{
		Service:  env.URL(t),
		Insecure: true,
	}

	session, err := NewSession(config).Create(ctx)
	if err != nil {
		eStr := err.Error()
		t.Logf("%+v", eStr)
		// FIXME: See comments below
		if strings.Contains(eStr, "resolves to multiple hosts") {
			t.SkipNow()
		}
		t.Logf("%+v", eStr)
		if _, ok := err.(*find.DefaultMultipleFoundError); !ok {
			t.Errorf(eStr)
		} else {
			t.SkipNow()
		}
	}
	if session != nil {
		defer session.Logout(ctx)
	}

	t.Logf("%+v", session)
}
Beispiel #3
0
func Session(ctx context.Context, t *testing.T) *session.Session {
	config := &session.Config{
		Service: env.URL(t),

		/// XXX Why does this insist on having this field populated?
		DatastorePath: env.DS(t),

		Insecure:  true,
		Keepalive: time.Duration(5) * time.Minute,
	}

	s, err := session.NewSession(config).Create(ctx)
	if err != nil {
		t.SkipNow()
	}

	return s
}
Beispiel #4
0
// Session returns a session.Session struct
func Session(ctx context.Context, t *testing.T) *session.Session {
	config := &session.Config{
		Service:        env.URL(t),
		Insecure:       true,
		Keepalive:      time.Duration(5) * time.Minute,
		DatacenterPath: "",
		DatastorePath:  "/ha-datacenter/datastore/*",
		HostPath:       "/ha-datacenter/host/*/*",
		NetworkPath:    "/ha-datacenter/network/VM Network",
		PoolPath:       "/ha-datacenter/host/*/Resources",
	}

	s, err := session.NewSession(config).Create(ctx)
	if err != nil {
		t.Errorf("ERROR: %s", err)
		t.SkipNow()
	}
	return s
}
Beispiel #5
0
func Session(ctx context.Context, t *testing.T) *session.Session {
	config := &session.Config{
		Service: env.URL(t),

		DatastorePath: env.DS(t),

		Insecure:  true,
		Keepalive: time.Duration(5) * time.Minute,
	}

	s, err := session.NewSession(config).Create(ctx)
	// Vsan has special UUID / URI handling of top level directories which
	// we've implemented at another level.  We can't import them here or it'd
	// be a circular dependency.  Also, we already have tests that test these
	// cases but from a higher level.
	if err != nil || s.IsVSAN(ctx) {
		t.SkipNow()
	}

	return s
}
Beispiel #6
0
func TestSession(t *testing.T) {
	ctx := context.Background()

	config := &Config{
		Service:        env.URL(t),
		Insecure:       true,
		Keepalive:      time.Duration(5) * time.Minute,
		DatacenterPath: "",
		DatastorePath:  "/ha-datacenter/datastore/*",
		HostPath:       "/ha-datacenter/host/*/*",
		PoolPath:       "/ha-datacenter/host/*/Resources",
	}

	session, err := NewSession(config).Create(ctx)
	if err != nil {
		eStr := err.Error()
		t.Logf("%+v", eStr)
		// FIXME: session.Create incorporates Populate which loses the type of any original error from vmomi
		// In the case where the test is run on a cluster with multiple hosts, find.MultipleFoundError
		// gets rolled up into a generic error in Populate. As such, the best we can do is just grep for the string, which is lame
		// The test shouldn't fail if it's run on a cluster with multiple hosts. However, it won't test for anything either.
		if strings.Contains(eStr, "resolves to multiple hosts") {
			t.SkipNow()
		}
		if _, ok := err.(*find.MultipleFoundError); !ok {
			t.Errorf(eStr)
		} else {
			t.SkipNow()
		}
	}

	if session != nil {
		defer session.Logout(ctx)

		t.Logf("Session: %+v", session)

		t.Logf("IsVC: %t", session.IsVC())
		t.Logf("IsVSAN: %t", session.IsVSAN(ctx))
	}
}
Beispiel #7
0
// Session returns a session.Session struct
func Session(ctx context.Context, t *testing.T) *session.Session {
	config := &session.Config{
		Service:        env.URL(t),
		Insecure:       true,
		Keepalive:      time.Duration(5) * time.Minute,
		DatacenterPath: "",
		DatastorePath:  "/ha-datacenter/datastore/*",
		HostPath:       "/ha-datacenter/host/*/*",
		PoolPath:       "/ha-datacenter/host/*/Resources",
	}

	s, err := session.NewSession(config).Create(ctx)
	if err != nil {
		// FIXME: See session_test.go TestSession for detail. We never get to PickRandomHost in the case of multiple hosts
		if strings.Contains(err.Error(), "resolves to multiple hosts") {
			t.SkipNow()
		} else {
			t.Errorf("ERROR: %s", err)
			t.SkipNow()
		}
	}
	return s
}
Beispiel #8
0
func TestFolder(t *testing.T) {
	ctx := context.Background()

	config := &Config{
		Service:        env.URL(t),
		Insecure:       true,
		Keepalive:      time.Duration(5) * time.Minute,
		DatacenterPath: "",
		DatastorePath:  "/ha-datacenter/datastore/*",
		HostPath:       "/ha-datacenter/host/*/*",
		PoolPath:       "/ha-datacenter/host/*/Resources",
	}

	session, err := NewSession(config).Create(ctx)
	if err != nil {
		eStr := err.Error()
		t.Logf("%+v", eStr)
		// FIXME: See comments above
		if strings.Contains(eStr, "resolves to multiple hosts") {
			t.SkipNow()
		}
		if _, ok := err.(*find.MultipleFoundError); !ok {
			t.Errorf(eStr)
		} else {
			t.SkipNow()
		}
	}

	if session != nil {
		defer session.Logout(ctx)

		folders := session.Folders(ctx)
		if folders == nil || folders.VmFolder == nil {
			t.Errorf("Get empty folder")
		}
	}
}
Beispiel #9
0
func TestVirtualMachineConfigSpec(t *testing.T) {

	ctx := context.Background()

	sessionconfig := &session.Config{
		Service:        env.URL(t),
		Insecure:       true,
		Keepalive:      time.Duration(5) * time.Minute,
		DatacenterPath: "",
		DatastorePath:  "/ha-datacenter/datastore/*",
		HostPath:       "/ha-datacenter/host/*/*",
		PoolPath:       "/ha-datacenter/host/*/Resources",
	}

	s, err := session.NewSession(sessionconfig).Create(ctx)
	if err != nil {
		t.Logf("%+v", err.Error())
		if _, ok := err.(*find.MultipleFoundError); !ok {
			t.Errorf(err.Error())
		} else {
			t.SkipNow()
		}
	}
	defer s.Logout(ctx)

	specconfig := &VirtualMachineConfigSpecConfig{
		NumCPUs:       2,
		MemoryMB:      2048,
		VMForkEnabled: true,

		ID: "zombie_attack",

		BootMediaPath: s.Datastore.Path("brainz.iso"),
		VMPathName:    fmt.Sprintf("[%s]", s.Datastore.Name()),
	}
	// FIXME: find a better way to pass those
	var scsibus int32
	var scsikey int32 = 100
	var idekey int32 = 200

	root, _ := NewVirtualMachineConfigSpec(ctx, s, specconfig)
	scsi := NewVirtualSCSIController(scsibus, scsikey)

	pv := NewParaVirtualSCSIController(scsi)
	root.AddParaVirtualSCSIController(pv)

	bl := NewVirtualBusLogicController(scsi)
	root.AddVirtualBusLogicController(bl)

	ll := NewVirtualLsiLogicController(scsi)
	root.AddVirtualLsiLogicController(ll)

	ls := NewVirtualLsiLogicSASController(scsi)
	root.AddVirtualLsiLogicSASController(ls)
	///
	ide := NewVirtualIDEController(idekey)
	root.AddVirtualIDEController(ide)

	cdrom := NewVirtualCdrom(ide)
	root.AddVirtualCdrom(cdrom)

	floppy := NewVirtualFloppy(ide)
	root.AddVirtualFloppy(floppy)

	vmxnet3 := NewVirtualVmxnet3()
	root.AddVirtualVmxnet3(vmxnet3)

	pcnet32 := NewVirtualPCNet32()
	root.AddVirtualPCNet32(pcnet32)

	e1000 := NewVirtualE1000()
	root.AddVirtualE1000(e1000)

	for i := 0; i < len(root.DeviceChange); i++ {
		t.Logf("%+v", root.DeviceChange[i].GetVirtualDeviceConfigSpec().Device)
	}

}