@@ -142,22 +142,53 @@ func DoesVirtualDiskExist(host string) bool {
142
142
return resp .StatusCode == http .StatusOK
143
143
}
144
144
145
- func main () {
146
- host := os .Getenv ("HC_HOST" )
147
-
148
- if ! AreEnvVariablesLoaded () {
149
- log .Fatal ("Environment variables aren't loaded, check env file in /acceptance/setup directory" )
145
+ func CleanupEnv (host string ) {
146
+ client := SetHTTPClient ()
147
+ data := []byte (fmt .Sprintf (`[{"virDomainUUID": "%s", "actionType": "STOP", "cause": "INTERNAL"}]` , source_vm_uuid ))
148
+ req , err := http .NewRequest ("POST" , fmt .Sprintf ("%s/rest/v1/VirDomain/action" , host ), bytes .NewBuffer (data ))
149
+ if err != nil {
150
+ log .Fatal (err )
150
151
}
152
+ req = SetHTTPHeader (req )
151
153
152
- if ! DoesTestVMExist (host ) {
153
- log .Fatal ("Acceptance test VM is missing in your testing environment" )
154
+ // Execute the request
155
+ resp , err := client .Do (req )
156
+ if err != nil {
157
+ log .Fatal (err )
154
158
}
159
+ defer resp .Body .Close ()
155
160
156
- if IsTestVMRunning (host ) {
157
- log .Fatal ("Acceptance test VM is RUNNING and should be turned off before the testing begins" )
161
+ // Read and print the response
162
+ body , err := io .ReadAll (resp .Body )
163
+ if err != nil {
164
+ log .Fatal (err )
158
165
}
159
166
160
- if ! DoesVirtualDiskExist (host ) {
161
- log .Fatal ("Acceptance test Virtual disk is missing in your testing environment" )
167
+ fmt .Println ("Response Status:" , resp .Status )
168
+ fmt .Println ("Response Body:" , string (body ))
169
+ }
170
+
171
+ func main () {
172
+ host := os .Getenv ("HC_HOST" )
173
+ isCleanup := len (os .Args ) < 1 && os .Args [1 ] == "cleanup"
174
+
175
+ if isCleanup {
176
+ CleanupEnv (host )
177
+ } else {
178
+ if ! AreEnvVariablesLoaded () {
179
+ log .Fatal ("Environment variables aren't loaded, check env file in /acceptance/setup directory" )
180
+ }
181
+
182
+ if ! DoesTestVMExist (host ) {
183
+ log .Fatal ("Acceptance test VM is missing in your testing environment" )
184
+ }
185
+
186
+ if IsTestVMRunning (host ) {
187
+ log .Fatal ("Acceptance test VM is RUNNING and should be turned off before the testing begins" )
188
+ }
189
+
190
+ if ! DoesVirtualDiskExist (host ) {
191
+ log .Fatal ("Acceptance test Virtual disk is missing in your testing environment" )
192
+ }
162
193
}
163
194
}
0 commit comments