-
Notifications
You must be signed in to change notification settings - Fork 3
/
template_test.go
82 lines (78 loc) · 1.92 KB
/
template_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (C) 2017 Battelle Memorial Institute
// All rights reserved.
//
// This software may be modified and distributed under the terms
// of the BSD-2 license. See the LICENSE file for details.
package ovirtapi_test
import (
"os"
"strconv"
"testing"
"time"
"github.com/EMSL-MSC/ovirtapi"
)
func TestTemplate(t *testing.T) {
t.Parallel()
username := os.Getenv("OVIRT_USERNAME")
if username == "" {
t.Error("OVIRT_USERNAME is not set")
}
password := os.Getenv("OVIRT_PASSWORD")
if password == "" {
t.Error("OVIRT_PASSWORD is not set")
}
url := os.Getenv("OVIRT_URL")
if url == "" {
t.Error("OVIRT_URL is not set")
}
con, err := ovirtapi.NewConnection(url, username, password, false)
con.Debug, _ = strconv.ParseBool(os.Getenv("DEBUG_TRANSPORT"))
if err != nil {
t.Error("error creating connection", err)
return
}
newTemplate := con.NewTemplate()
newTemplate.Name = "test-Template"
allVMs, err := con.GetAllVMs()
if err != nil {
t.Error("Error finding a vm to duplicate", err)
return
}
for _, vm := range allVMs {
if vm.Status != "up" && vm.Status != "locked" {
newTemplate.VM = vm
break
}
}
err = newTemplate.Save()
if err != nil {
t.Fatal("Error creating new Template", err)
}
retrievedTemplate, err := con.GetTemplate(newTemplate.ID)
if err != nil {
t.Fatal("Error retrieving Template", err)
}
for retrievedTemplate.Status == "locked" {
time.Sleep(2 * time.Second)
err = retrievedTemplate.Update()
if err != nil {
t.Fatal("Error retrieving Template", err)
}
}
retrievedTemplate.Description = "about to delete"
err = retrievedTemplate.Save()
if err != nil {
t.Fatal("Error updating Template", err)
}
for retrievedTemplate.Status == "locked" {
time.Sleep(2 * time.Second)
err = retrievedTemplate.Update()
if err != nil {
t.Fatal("Error retrieving Template", err)
}
}
err = retrievedTemplate.Delete()
if err != nil {
t.Fatal("Error Deleting Template", err)
}
}