示例#1
0
func dataInsert() {
	//dataInsertCluster
	func() {
		o := orm.NewOrm()
		clusterInfo := new(models.ClusterInfo)
		clusterInfo.ID = "1001"
		clusterInfo.Name = "cluster1"
		clusterInfo.Type = "A"
		clusterInfo.Status = 999
		clusterInfo.MaxNodeNum = 50
		clusterInfo.MaxNodeUsageLimit = 100
		storage := new(models.Storage)
		storage.ID = "A001"
		storage.Type = "AA"
		storage.Filesystem = "WINDOWS"
		storage.Total_MB = 100
		storage.Available_MB = 30
		clusterInfo.Storage = storage
		clusterInfo.Error = "NONE1"
		fmt.Println(o.Insert(storage))
		fmt.Println(o.Insert(clusterInfo))

		clusterInfo = new(models.ClusterInfo)
		clusterInfo.ID = "2001"
		clusterInfo.Name = "cluster2"
		clusterInfo.Type = "B"
		clusterInfo.Status = 1
		clusterInfo.MaxNodeNum = 100
		clusterInfo.MaxNodeUsageLimit = 200
		storage = new(models.Storage)
		storage.ID = "B001"
		storage.Type = "BB"
		storage.Filesystem = "LINUX"
		storage.Total_MB = 200
		storage.Available_MB = 60
		clusterInfo.Storage = storage
		clusterInfo.Error = "NONE2"
		fmt.Println(o.Insert(storage))
		fmt.Println(o.Insert(clusterInfo))
	}()

	//dataInsertNetwork
	func() {
		o := orm.NewOrm()
		iptable := new(models.IPtable)
		iptable.ID = "1001"
		iptable.Type = "A"
		iptable.IPAddress = "0.0.0.0"
		iptable.Netmask = "255.255.255.0"
		iptable.Gateway = ""
		iptable.Total = 10
		iptable.Used = 0
		iptable.Status = 0
		iptable.Error = "NONE1"
		fmt.Println(o.Insert(iptable))

		iptable = new(models.IPtable)
		iptable.ID = "2001"
		iptable.Type = "B"
		iptable.IPAddress = "0.0.0.1"
		iptable.Netmask = "255.255.255.1"
		iptable.Gateway = ""
		iptable.Total = 10
		iptable.Used = 0
		iptable.Status = 0
		iptable.Error = "NONE2"
		fmt.Println(o.Insert(iptable))
	}()

	//dataInsertNode
	func() {
		//TODO cluster
		o := orm.NewOrm()
		node := new(models.Node)
		node.ID = "1001"
		node.ClusterID = "cluster_1001"
		node.SoftwareID = "software_1001"
		node.Status = models.Enable
		node.Runtime = "running"
		node.MaxInstance = 10
		node.IPAddress = "0.0.0.1"
		node.NCPU = 24
		node.Mem_MB = 64
		fmt.Println(o.Insert(node))

		o = orm.NewOrm()
		node = new(models.Node)
		node.ID = "2001"
		node.ClusterID = "cluster_2001"
		node.SoftwareID = "software_2001"
		node.Status = models.Disable
		node.Runtime = "running"
		node.MaxInstance = 20
		node.IPAddress = "0.0.0.2"
		node.NCPU = 24
		node.Mem_MB = 64
		fmt.Println(o.Insert(node))
	}()

	//dataInsertService
	func() {
		o := orm.NewOrm()
		service := new(models.Service)
		service.ID = "1001"
		service.Status = 0
		fmt.Println(o.Insert(service))

		service = new(models.Service)
		service.ID = "2001"
		service.Status = 0
		fmt.Println(o.Insert(service))
	}()

	//dataInsertSoftware
	func() {
		o := orm.NewOrm()
		software := new(models.Software)
		software.ID = "1001"
		software.Name = "software_name_001"
		software.Type = "softwareA"
		software.Version = "V1.0"
		software.StoreURL = "C:\\"
		software.MD5 = ""
		fmt.Println(o.Insert(software))

		software = new(models.Software)
		software.ID = "2001"
		software.Name = "software_name_002"
		software.Type = "softwareB"
		software.Version = "V2.0"
		software.StoreURL = "D:\\"
		software.MD5 = ""
		fmt.Println(o.Insert(software))
	}()

	//dataInsertSoftware
	func() {
		o := orm.NewOrm()
		san := new(models.SAN)
		san.ID = "1001"
		san.Name = "san_name_1001"
		san.Vender = "san_vender_1001"
		lc := new(models.LoginConfig)
		lc.ID = "lc_1001"
		lc.Name = "lc_name_1001"
		lc.Type = "A"
		lc.IPAddress = "0.0.0.1"
		lc.UserName = "******"
		lc.Password = "******"
		san.Login = lc
		san.LUNRange = "a1"
		san.HLURange = "b1"
		san.TotalMB = 100
		san.FreeMB = 50
		san.Error = "NONE1"
		fmt.Println(o.Insert(lc))
		fmt.Println(o.Insert(san))

		san = new(models.SAN)
		san.ID = "2001"
		san.Name = "san_name_2001"
		san.Vender = "san_vender_2001"
		lc = new(models.LoginConfig)
		lc.ID = "lc_2001"
		lc.Name = "lc_name_2001"
		lc.Type = "A"
		lc.IPAddress = "0.0.0.2"
		lc.UserName = "******"
		lc.Password = "******"
		san.Login = lc
		san.LUNRange = "a2"
		san.HLURange = "b2"
		san.TotalMB = 200
		san.FreeMB = 100
		san.Error = "NONE2"
		fmt.Println(o.Insert(lc))
		fmt.Println(o.Insert(san))

		rg := new(models.RaidGroup)
		rg.ID = "1001"
		rg.SANID = "san_1001"
		rg.Number = 10
		rg.Status = 1
		rg.TotalMB = 100
		rg.FreeMB = 10
		rg.Error = "NONE1"
		fmt.Println(o.Insert(rg))

		rg = new(models.RaidGroup)
		rg.ID = "2001"
		rg.SANID = "san_2001"
		rg.Number = 15
		rg.Status = 2
		rg.TotalMB = 120
		rg.FreeMB = 12
		rg.Error = "NONE2"
		fmt.Println(o.Insert(rg))

		nas := new(models.NAS)
		nas.ID = "1001"
		nas.ServerIPAddr = "0.0.0.1"
		nas.ShareDir = "C:\\"
		fmt.Println(o.Insert(nas))

		nas = new(models.NAS)
		nas.ID = "2001"
		nas.ServerIPAddr = "0.0.0.2"
		nas.ShareDir = "D:\\"
		fmt.Println(o.Insert(nas))
	}()
}
示例#2
0
func TestAPIServer(t *testing.T) {

	objs := []string{"cluster", "network", "node", "service", "software", "storage/san", "storage/san/rg", "storage/nas"}
	//objs := []string{"cluster"}

	var req *httplib.BeegoHTTPRequest
	var b []byte
	for _, obj := range objs {
		if obj != "service" && obj != "software" {
			if strings.Contains(obj, "storage/san") == false {
				//GetTest
				req = httplib.Get("http://localhost:8080/v1.0/" + obj + "/" + "1001")
				actionTestTemplate(t, req, obj, "Get")

				if obj != "storage/nas" {
					//GetAllTest
					req = httplib.Get("http://localhost:8080/v1.0/" + obj)
					actionTestTemplate(t, req, obj, "GetAll")
				}
			}

			if obj != "storage/nas" {
				//ListTrueTest
				listBody := models.CommonRequestBody{
					All: true,
					ID:  []string{"1001", "9999"},
				}
				req = httplib.Post("http://localhost:8080/v1.0/" + obj + "/list")
				b, _ = json.Marshal(listBody)
				req.Body(b)
				actionTestTemplate(t, req, obj, "ListTrue")

				//ListFalseTest
				listBody.All = false
				req = httplib.Post("http://localhost:8080/v1.0/" + obj + "/list")
				b, _ = json.Marshal(listBody)
				req.Body(b)
				actionTestTemplate(t, req, obj, "ListFalse")
			}
		}

		//PostTest
		req = httplib.Post("http://localhost:8080/v1.0/" + obj)
		switch obj {
		case "cluster":
			postBody := models.PostCluster{
				Name:              "ClusterPostName",
				Type:              "PostType",
				StorageType:       "StoragePostType",
				StorageSystemID:   "storage_" + utils.Generate32UUID(),
				MaxNodeUsageLimit: 100,
				MaxNodeNum:        200,
			}
			b, _ = json.Marshal(postBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Post")
		case "network":
			postBody := models.IPtable{
				Type:      "PostType",
				IPAddress: "0.0.0.2",
				Netmask:   "255.255.255.2",
				//Gateway   "" //miss property,
				Total: 10,
				Used:  2,
				//Status
				//Error
			}
			b, _ = json.Marshal(postBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Post")
		case "node":
			postBodyList := make([]models.PostNode, 2)
			postBodyList[0] = models.PostNode{
				NodeID:      "node_9001",
				ClusterID:   "cluster_1001",
				SoftwareID:  "software_1001",
				MaxInstance: 11,
			}
			postBodyList[1] = models.PostNode{
				NodeID:      "node_9002",
				ClusterID:   "cluster_1002",
				SoftwareID:  "software_1002",
				MaxInstance: 12,
			}
			b, _ = json.Marshal(postBodyList)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Post")
		case "service":
			postBody := models.PostService{}
			b, _ = json.Marshal(postBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Post")
		case "software":
			postBody := models.Software{
				ID:       "software_9999",
				Name:     "software_name_9999",
				Version:  "V999",
				Type:     "999",
				StoreURL: "Z:\\",
				MD5:      "",
			}
			b, _ = json.Marshal(postBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Post")
		case "storage/san":
			san := new(models.SAN)
			san.ID = "san_1001"
			san.Name = "san_name_1001"
			san.Vender = "san_vender_1001"
			lc := new(models.LoginConfig)
			lc.Name = "lc_name_1001"
			lc.Type = "A"
			lc.IPAddress = "0.0.0.1"
			lc.UserName = "******"
			lc.Password = "******"
			san.Login = lc
			san.LUNRange = "a1"
			san.HLURange = "b1"
			san.TotalMB = 100
			san.FreeMB = 50
			san.Error = "NONE1"
			postBody := san
			b, _ = json.Marshal(postBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Post")
		case "storage/rg":
			postBody := models.PostRaidGroup{
				SANID:  "PostRaidGroup_9999",
				Number: 111,
			}
			b, _ = json.Marshal(postBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Post")
		case "storage/nas":
			postBody := models.NAS{
				ID:           "NAS_9999",
				ServerIPAddr: "0.0.0.9",
				ShareDir:     "Z:\\",
			}
			b, _ = json.Marshal(postBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Post")
		}

		//PostRollbackTest
		if obj == "cluster" {
			postBody := models.PostCluster{
				Name:              "ClusterPostName",
				Type:              "PostType",
				StorageType:       "StoragePostType",
				StorageSystemID:   "",
				MaxNodeUsageLimit: 100,
				MaxNodeNum:        200,
			}
			req = httplib.Post("http://localhost:8080/v1.0/" + obj)
			b, _ = json.Marshal(postBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "PostRollback")
		}

		//PutTest
		if obj == "node" {
			req = httplib.Put("http://localhost:8080/v1.0/" + obj + "/" + "1001")
			putBody := models.Node{
				Status:      models.Enable,
				MaxInstance: 99,
			}
			b, _ = json.Marshal(putBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Put")
		}
		if obj != "software" && obj != "storage/san" && obj != "storage/nas" {
			//EnableTest
			req = httplib.Put("http://localhost:8080/v1.0/" + obj + "/" + "1001/enable")
			actionTestTemplate(t, req, obj, "Enable")
			//DisableTest
			req = httplib.Put("http://localhost:8080/v1.0/" + obj + "/" + "1001/disable")
			actionTestTemplate(t, req, obj, "Disable")
		}

		//DeleteTest
		if obj != "storage/nas" {
			req = httplib.Delete("http://localhost:8080/v1.0/" + obj + "/" + "1001")
			actionTestTemplate(t, req, obj, "Delete")
		}

	}
}