Skip to content

Commit

Permalink
Run sweeper unconditionally on acc test runs and add CI Makefile targ…
Browse files Browse the repository at this point in the history
…et (#266)

* Add exponential backoff on retryable errors. Always run the sweeper

* Ensure vif vm test waits for IP to wait for network drivers to load

* Fix linting issues

* Ensure GetConfigFromEnv sets the retry mode and max time parameters

* Remove accidental change
  • Loading branch information
ddelnano authored Oct 5, 2023
1 parent dec8d50 commit 9d5e647
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ test: testclient testacc
testclient:
cd client; go test $(TEST) -v -count 1

testacc: sweep
TF_ACC=1 $(TF_LOG) go test $(TEST) -parallel $(GOMAXPROCS) -v -count 1 -timeout $(TIMEOUT)
testacc:
TF_ACC=1 $(TF_LOG) go test $(TEST) -parallel $(GOMAXPROCS) -v -count 1 -timeout $(TIMEOUT) -sweep=true
ci:
TF_ACC=1 gotestsum --debug --rerun-fails=5 --max-fails=15 --packages=./xoa -- ./xoa -v -count=1 -timeout=$(TIMEOUT) -sweep=true -parallel=$(GOMAXPROCS)
15 changes: 7 additions & 8 deletions xoa/acc_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ func TestMain(m *testing.M) {
flagSweep := flag.Lookup("sweep")

if flagSweep != nil && flagSweep.Value.String() != "" {
resource.TestMain(m)
} else {
_, runSetup := os.LookupEnv("TF_ACC")

if runSetup {
fmt.Println("Running sweeping")
resource.TestMain(m)

client.FindPoolForTests(&accTestPool)
client.FindPIFForTests(&accTestPIF)
client.FindTemplateForTests(&testTemplate, accTestPool.Id, "XOA_TEMPLATE")
Expand All @@ -46,19 +47,17 @@ func TestMain(m *testing.M) {
client.FindIsoStorageRepositoryForTests(accTestPool, &accIsoSr, accTestPrefix, "XOA_ISO_SR")
client.CreateUser(&accUser)
testIsoName = os.Getenv("XOA_ISO")
}

code := m.Run()
fmt.Printf("Found the following pool: %v sr: %v\n", accTestPool, accDefaultSr)

if runSetup {
code := m.Run()
client.RemoveNetworksWithNamePrefix(accTestPrefix)("")
client.RemoveVDIsWithPrefix(accTestPrefix)("")
client.RemoveResourceSetsWithNamePrefix(accTestPrefix)("")
client.RemoveTagFromAllObjects(accTestPrefix)("")
client.RemoveUsersWithPrefix(accTestPrefix)("")
client.RemoveCloudConfigsWithPrefix(accTestPrefix)("")
os.Exit(code)
}

os.Exit(code)
}

}
9 changes: 7 additions & 2 deletions xoa/resource_xenorchestra_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ func TestAccXenorchestraVm_addVifAndRemoveVif(t *testing.T) {
CheckDestroy: testAccCheckXenorchestraVmDestroy,
Steps: []resource.TestStep{
{
Config: testAccVmConfig(vmName),
Config: testAccVmConfigWithWaitForIp(vmName, "true"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccVmExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "id"),
Expand Down Expand Up @@ -1694,6 +1694,10 @@ resource "xenorchestra_vm" "bar" {
}

func testAccVmConfig(vmName string) string {
return testAccVmConfigWithWaitForIp(vmName, "false")
}

func testAccVmConfigWithWaitForIp(vmName, waitForIp string) string {
return testAccCloudConfigConfig(fmt.Sprintf("vm-template-%s", vmName), "template") + testAccTemplateConfig() + fmt.Sprintf(`
data "xenorchestra_network" "network" {
name_label = "%s"
Expand All @@ -1716,8 +1720,9 @@ resource "xenorchestra_vm" "bar" {
name_label = "disk 1"
size = 10001317888
}
wait_for_ip = %s
}
`, accDefaultNetwork.NameLabel, accTestPool.Id, vmName, accDefaultSr.Id)
`, accDefaultNetwork.NameLabel, accTestPool.Id, vmName, accDefaultSr.Id, waitForIp)
}

// This sets destroy_cloud_config_vdi_after_boot and wait_for_ip. The former is required for
Expand Down

0 comments on commit 9d5e647

Please sign in to comment.