func TestWaitForJobOK(t *testing.T) { c, ts := clientFor(newMockAPIServer(t, mockLinodeJobListFinishedOK())) defer ts.Close() ok, err := c.WaitForJob(1139016, 25088076, 1*time.Nanosecond, 1*time.Second) require.NoError(t, err) require.True(t, ok) }
func TestImageIntegration(t *testing.T) { c := NewClient(apiKey) t.Log("creating test linode...") linodeID, err := c.LinodeCreate(2, 1, nil) require.NoError(t, err) require.NotEmpty(t, linodeID) err = c.WaitForAllJobs(linodeID, 3*time.Second, 60*time.Second) require.NoError(t, err) t.Log("creating test disk...") jobID, dDiskID, err := c.LinodeDiskCreateFromDistribution(linodeID, 130, "test-image", 600, rootPass, nil) require.NoError(t, err) require.NotEmpty(t, dDiskID) require.NotEmpty(t, jobID) ok, err := c.WaitForJob(linodeID, jobID, 3*time.Second, 60*time.Second) require.NoError(t, err) require.True(t, ok) t.Log("converting test disk to image...") jobID, imageID, err := c.LinodeDiskImagize(linodeID, dDiskID, String("foo"), String("bar")) require.NoError(t, err) require.NotEmpty(t, imageID) require.NotEmpty(t, jobID) ok, err = c.WaitForJob(linodeID, jobID, 3*time.Second, 120*time.Second) require.NoError(t, err) require.True(t, ok) t.Log("image.list...") images, err := c.ImageList(&imageID, Bool(false)) require.NoError(t, err) require.Len(t, images, 1) i := images[0] assert.Empty(t, i.LastUsedDT) assert.Equal(t, 600, i.MinSize) assert.Equal(t, "foo", i.Description) assert.Equal(t, "bar", i.Label) assert.NotEmpty(t, i.Creator) assert.Equal(t, "available", i.Status) assert.False(t, i.IsPublic) assert.NotEmpty(t, i.CreateDT) assert.Equal(t, "manual", i.Type) assert.Equal(t, "ext4", i.FSType) assert.Equal(t, imageID, i.ID) t.Log("image.update...") err = c.ImageUpdate(imageID, String("baz"), String("quux")) require.NoError(t, err) t.Log("image.list...") images, err = c.ImageList(&imageID, Bool(false)) require.NoError(t, err) require.Len(t, images, 1) i = images[0] assert.Equal(t, "baz", i.Label) assert.Equal(t, "quux", i.Description) t.Log("image.delete...") err = c.ImageDelete(imageID) require.NoError(t, err) t.Log("cleaning up linode...") err = c.LinodeDelete(linodeID, Bool(true)) require.NoError(t, err) }
func TestLinodeIntegration(t *testing.T) { c := NewClient(apiKey) t.Log("c.LinodeCreate...") id, err := c.LinodeCreate(2, 1, nil) require.NoError(t, err) require.NotEmpty(t, id) t.Log("c.WaitForAllJobs...") err = c.WaitForAllJobs(id, 2*time.Second, 60*time.Second) require.NoError(t, err) t.Log("c.LinodeList...") nodes, err := c.LinodeList(Int(id)) require.NoError(t, err) require.Len(t, nodes, 1) t.Log("c.LinodeResize...") err = c.LinodeResize(id, 2) require.NoError(t, err) t.Log("c.LinodeUpdate...") linodeOpts := LinodeOpts{ Label: String("integration-test"), DisplayGroup: String("tests"), AlertCPUEnabled: Bool(false), AlertCPUThreshold: Int(50), AlertDiskIOEnabled: Bool(false), AlertDiskIOThreshold: Int(500), AlertBWInEnabled: Bool(false), AlertBWInThreshold: Int(30), AlertBWOutEnabled: Bool(false), AlertBWOutThreshold: Int(31), AlertBWQuotaEnabled: Bool(false), AlertBWQuotaThreshold: Int(55), BackupWindow: Int(3), BackupWeeklyDay: Int(6), Watchdog: Bool(false), } err = c.LinodeUpdate(id, linodeOpts) require.NoError(t, err) t.Log("c.LinodeDiskCreate...") jobID, swapDiskID, err := c.LinodeDiskCreate(id, "test-swap", "swap", 256) require.NoError(t, err) require.NotEmpty(t, swapDiskID, "swapDiskID") require.NotEmpty(t, jobID, "jobID") t.Log("c.WaitForJob...") ok, err := c.WaitForJob(id, jobID, 2*time.Second, 60*time.Second) require.NoError(t, err) require.True(t, ok, "creating swap failed") t.Log("c.LinodeDiskCreateFromDistribution...") jobID, distDiskID, err := c.LinodeDiskCreateFromDistribution(id, 130, "test-dist", 600, rootPass, String(rootSSHKey)) require.NoError(t, err) require.NotEmpty(t, jobID) require.NotEmpty(t, distDiskID) t.Log("c.WaitForJob...") ok, err = c.WaitForJob(id, jobID, 2*time.Second, 80*time.Second) require.NoError(t, err) require.True(t, ok) t.Log("c.LinodeConfigCreate...") lcco := LinodeConfigCreateOpts{ Comments: String("foo"), RAMLimit: Int(800), VirtMode: String("paravirt"), RunLevel: String("default"), RootDeviceNum: Int(1), RootDeviceRO: Bool(true), HelperDisableUpdateDB: Bool(true), HelperDistro: Bool(true), HelperXen: Bool(true), HelperDepmod: Bool(true), HelperNetwork: Bool(true), DevTmpFSAutomount: Bool(true), } diskList := strconv.Itoa(distDiskID) + "," + strconv.Itoa(swapDiskID) + "," confID, err := c.LinodeConfigCreate(id, 138, "test-conf1", diskList, lcco) require.NoError(t, err) require.NotEmpty(t, confID) t.Log("c.LinodeConfigList...") confs, err := c.LinodeConfigList(id, Int(confID)) require.NoError(t, err) require.Len(t, confs, 1) cfg := confs[0] assert.Equal(t, "", cfg.RootDeviceCustom) assert.Equal(t, "foo", cfg.Comments) assert.Equal(t, "test-conf1", cfg.Label) assert.Equal(t, confID, cfg.ID) assert.NotEmpty(t, cfg.DiskList) assert.Equal(t, "default", cfg.RunLevel) assert.Equal(t, 1, cfg.RootDeviceNum) assert.Equal(t, 800, cfg.RAMLimit) assert.Equal(t, "paravirt", cfg.VirtMode) assert.Equal(t, id, cfg.LinodeID) assert.Equal(t, 138, cfg.KernelID) assert.True(t, cfg.DevTmpFSAutomount) assert.True(t, cfg.HelperDistro) assert.True(t, cfg.HelperDisableUpdateDB) assert.True(t, cfg.HelperDepmod) assert.True(t, cfg.HelperXen) assert.True(t, cfg.RootDeviceRO) assert.True(t, cfg.HelperNetwork) assert.False(t, cfg.IsRescue) t.Log("c.LinodeConfigUpdate...") lcuo := LinodeConfigUpdateOpts{ LinodeID: Int(id), KernelID: Int(138), Comments: String("foo"), RAMLimit: Int(800), VirtMode: String("paravirt"), RunLevel: String("default"), RootDeviceNum: Int(1), RootDeviceRO: Bool(true), HelperDisableUpdateDB: Bool(true), HelperDistro: Bool(true), HelperXen: Bool(true), HelperDepmod: Bool(true), HelperNetwork: Bool(true), DevTmpFSAutomount: Bool(true), } err = c.LinodeConfigUpdate(confID, lcuo) require.NoError(t, err) t.Log("c.LinodeDiskImagize...") jobID, imgID, err := c.LinodeDiskImagize(id, distDiskID, String("test-image desc"), String("test-image label")) require.NoError(t, err) require.NotEmpty(t, jobID) require.NotEmpty(t, imgID) t.Log("c.WaitForJob...") ok, err = c.WaitForJob(id, jobID, 2*time.Second, 120*time.Second) require.NoError(t, err) require.True(t, ok) t.Log("c.LinodeDiskCreateFromImage...") jobID, imgDiskID, err := c.LinodeDiskCreateFromImage(imgID, id, "test-image", Int(800), String(rootPass), String(rootSSHKey)) require.NoError(t, err) require.NotEmpty(t, jobID) require.NotEmpty(t, imgDiskID) t.Log("c.WaitForJob...") ok, err = c.WaitForJob(id, jobID, 2*time.Second, 120*time.Second) require.NoError(t, err) require.True(t, ok) t.Log("deleting image...") err = c.ImageDelete(imgID) assert.NoError(t, err) t.Log("c.LinodeDiskDelete...") jobID, err = c.LinodeDiskDelete(id, imgDiskID) require.NoError(t, err) require.NotEmpty(t, jobID) t.Log("c.WaitForJob...") ok, err = c.WaitForJob(id, jobID, 2*time.Second, 60*time.Second) require.NoError(t, err) require.True(t, ok) t.Log("c.LinodeDiskDuplicate...") jobID, dupeDiskID, err := c.LinodeDiskDuplicate(id, swapDiskID) require.NoError(t, err) require.NotEmpty(t, dupeDiskID) require.NotEmpty(t, jobID) t.Log("c.WaitForJob...") ok, err = c.WaitForJob(id, jobID, 2*time.Second, 60*time.Second) require.NoError(t, err) require.True(t, ok) t.Log("c.LinodeDiskResize...") jobID, err = c.LinodeDiskResize(id, dupeDiskID, 512) require.NoError(t, err) require.NotEmpty(t, jobID) t.Log("c.WaitForJob...") ok, err = c.WaitForJob(id, jobID, 1*time.Second, 60*time.Second) require.NoError(t, err) require.True(t, ok) t.Log("c.LinodeDiskUpdate...") err = c.LinodeDiskUpdate(id, dupeDiskID, String("updated-label"), Bool(true)) require.NoError(t, err) curDisks, err := c.LinodeDiskList(id, nil) require.NoError(t, err) require.Len(t, curDisks, 3) t.Log("c.LinodeIPList...") ipList, err := c.LinodeIPList(Int(id), nil) require.NoError(t, err) require.Len(t, ipList, 1) pubID := ipList[0].ID t.Log("c.LinodeIPAddPrivate...") _, _, err = c.LinodeIPAddPrivate(id) require.NoError(t, err) t.Log("c.LinodeIPList...") ipList, err = c.LinodeIPList(Int(id), nil) require.NoError(t, err) require.Len(t, ipList, 2) t.Log("c.LinodeClone...") cloneID, err := c.LinodeClone(id, 2, 1, nil, nil) require.NoError(t, err) require.NotEmpty(t, cloneID) t.Log("c.WaitForAllJobs...") err = c.WaitForAllJobs(cloneID, 2*time.Second, 60*time.Second) require.NoError(t, err) t.Log("c.LinodeIPList...") ipList, err = c.LinodeIPList(Int(cloneID), nil) require.NoError(t, err) require.Len(t, ipList, 1) clonePubID := ipList[0].ID t.Log("c.LinodeIPSwap...") err = c.LinodeIPSwap(pubID, Int(clonePubID), nil) require.NoError(t, err) t.Log("c.WaitForAllJobs...") err = c.WaitForAllJobs(cloneID, 2*time.Second, 60*time.Second) require.NoError(t, err) t.Log("c.LinodeDelete...") err = c.LinodeDelete(cloneID, Bool(true)) require.NoError(t, err) ssOpts := struct { DBPassword string `json:"db_password"` DBName string `json:"db_name"` MySQLUsername string `json:"db_user"` MySQLUserpass string `json:"db_user_password"` }{ "foo", "bar", "baz", "quux", } ssUDFResp, err := json.Marshal(ssOpts) require.NoError(t, err) t.Log("c.DiskCreateFromStackScript") jobID, diskID, err := c.LinodeDiskCreateFromStackScript(id, linodeLampStackSS, string(ssUDFResp), 130, "test-ss", 600, rootPass, String(rootSSHKey)) require.NoError(t, err) require.NotEmpty(t, jobID) require.NotEmpty(t, diskID) t.Log("c.WaitForJob...") ok, err = c.WaitForJob(id, jobID, 2*time.Second, 120*time.Second) require.NoError(t, err) require.True(t, ok) t.Log("c.LinodeBoot...") jobID, err = c.LinodeBoot(id, Int(confID)) require.NoError(t, err) require.NotEmpty(t, jobID) t.Log("c.WaitForJob...") ok, err = c.WaitForJob(id, jobID, 2*time.Second, 120*time.Second) require.NoError(t, err) require.True(t, ok) t.Log("c.LinodeReboot...") jobID, err = c.LinodeReboot(id, Int(confID)) require.NoError(t, err) require.NotEmpty(t, jobID) t.Log("c.WaitForJob...") ok, err = c.WaitForJob(id, jobID, 2*time.Second, 120*time.Second) require.NoError(t, err) require.True(t, ok) t.Log("c.LinodeShutdown...") jobID, err = c.LinodeShutdown(id) require.NoError(t, err) require.NotEmpty(t, jobID) t.Log("c.WaitForJob...") ok, err = c.WaitForJob(id, jobID, 2*time.Second, 120*time.Second) require.NoError(t, err) require.True(t, ok) err = c.LinodeConfigDelete(id, confID) require.NoError(t, err) t.Log("c.LinodeDelete...") err = c.LinodeDelete(id, Bool(true)) }