@@ -70,8 +70,10 @@ func SetHTTPClient() *http.Client {
70
70
71
71
return client
72
72
}
73
- func SendHTTPRequest (request * http.Request , client * http.Client ) (* http.Response , []byte ) {
74
- resp , err := client .Do (request )
73
+ func SendHTTPRequest (client * http.Client , method string , url string , data []byte ) (* http.Response , []byte ) {
74
+ req := SetHTTPMethod (method , url , data )
75
+ req = SetHTTPHeader (req )
76
+ resp , err := client .Do (req )
75
77
if err != nil {
76
78
log .Fatalf ("Sending request failed with %v" , err )
77
79
}
@@ -88,7 +90,7 @@ func SendHTTPRequest(request *http.Request, client *http.Client) (*http.Response
88
90
89
91
return resp , body
90
92
}
91
- func SetHTTPRequest (method string , url string , data []byte ) * http.Request {
93
+ func SetHTTPMethod (method string , url string , data []byte ) * http.Request {
92
94
var req * http.Request
93
95
var err error
94
96
@@ -116,20 +118,14 @@ func AreEnvVariablesLoaded(env EnvConfig) bool {
116
118
func DoesTestVMExist (host string , client * http.Client , env EnvConfig ) bool {
117
119
url := fmt .Sprintf ("%s%s%s" , host , VirDomainEndpoint , env .SourceVmUUID )
118
120
119
- req := SetHTTPRequest ("GET" , url , nil )
120
- req = SetHTTPHeader (req )
121
-
122
- resp , _ := SendHTTPRequest (req , client )
121
+ resp , _ := SendHTTPRequest (client , "GET" , url , nil )
123
122
124
123
return resp .StatusCode == http .StatusOK
125
124
}
126
125
func IsTestVMRunning (host string , client * http.Client , env EnvConfig ) bool {
127
126
url := fmt .Sprintf ("%s%s%s" , host , VirDomainEndpoint , env .SourceVmUUID )
128
127
129
- req := SetHTTPRequest ("GET" , url , nil )
130
- req = SetHTTPHeader (req )
131
-
132
- _ , body := SendHTTPRequest (req , client )
128
+ _ , body := SendHTTPRequest (client , "GET" , url , nil )
133
129
134
130
var result []map [string ]interface {}
135
131
err := json .Unmarshal (body , & result )
@@ -141,21 +137,15 @@ func IsTestVMRunning(host string, client *http.Client, env EnvConfig) bool {
141
137
func DoesVirtualDiskExist (host string , client * http.Client , env EnvConfig ) bool {
142
138
url := fmt .Sprintf ("%s%s%s" , host , VirtualDiskEndpoint , env .ExistingVdiskUUID )
143
139
144
- req := SetHTTPRequest ("GET" , url , nil )
145
- req = SetHTTPHeader (req )
146
-
147
- resp , _ := SendHTTPRequest (req , client )
140
+ resp , _ := SendHTTPRequest (client , "GET" , url , nil )
148
141
149
142
return resp .StatusCode == http .StatusOK
150
143
}
151
144
func IsBootOrderCorrect (host string , client * http.Client , env EnvConfig ) bool {
152
145
expectedBootOrder := []string {env .SourceDiskUUID , env .SourceNicUUID }
153
146
url := fmt .Sprintf ("%s%s%s" , host , VirDomainEndpoint , env .SourceVmUUID )
154
147
155
- req := SetHTTPRequest ("GET" , url , nil )
156
- req = SetHTTPHeader (req )
157
-
158
- _ , body := SendHTTPRequest (req , client )
148
+ _ , body := SendHTTPRequest (client , "GET" , url , nil )
159
149
160
150
var result []map [string ]interface {}
161
151
err := json .Unmarshal (body , & result )
@@ -196,9 +186,7 @@ func PrepareEnv(host string, client *http.Client, env EnvConfig) {
196
186
func CleanUpPowerState (host string , client * http.Client , env EnvConfig ) {
197
187
data := []byte (fmt .Sprintf (`[{"virDomainUUID": "%s", "actionType": "STOP", "cause": "INTERNAL"}]` , env .SourceVmUUID ))
198
188
url := fmt .Sprintf ("%s%s" , host , VirDomainActionEndpoint )
199
- req := SetHTTPRequest ("POST" , url , data )
200
- req = SetHTTPHeader (req )
201
- SendHTTPRequest (req , client )
189
+ SendHTTPRequest (client , "POST" , url , data )
202
190
// wait 30 seconds for VM to shutdown and then proceed with other cleanup tasks
203
191
time .Sleep (30 * time .Second )
204
192
}
@@ -212,9 +200,7 @@ func CleanUpBootOrder(host string, client *http.Client, env EnvConfig) {
212
200
log .Fatalf ("Failed to marshal JSON: %v" , err )
213
201
}
214
202
url := fmt .Sprintf ("%s%s%s" , host , VirDomainEndpoint , env .SourceVmUUID )
215
- req := SetHTTPRequest ("POST" , url , data )
216
- req = SetHTTPHeader (req )
217
- SendHTTPRequest (req , client )
203
+ SendHTTPRequest (client , "POST" , url , data )
218
204
}
219
205
func CleanupEnv (host string , client * http.Client , env EnvConfig ) {
220
206
CleanUpPowerState (host , client , env )
0 commit comments