Skip to content

Commit c8ac1f7

Browse files
jtopjianstack72
authored andcommitted
provider/openstack: Acceptance Test Cleanup: Provider & Block Storage (hashicorp#10839)
* provider/openstack: Updating provider test configuration * provider/openstack: Updating Block Storage acceptance tests
1 parent 09dc632 commit c8ac1f7

5 files changed

Lines changed: 137 additions & 124 deletions

‎builtin/providers/openstack/provider_test.go‎

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ import (
99
)
1010

1111
var (
12-
OS_REGION_NAME = ""
13-
OS_POOL_NAME = ""
12+
OS_EXTGW_ID = os.Getenv("OS_EXTGW_ID")
13+
OS_FLAVOR_ID = os.Getenv("OS_FLAVOR_ID")
14+
OS_FLAVOR_NAME = os.Getenv("OS_FLAVOR_NAME")
15+
OS_IMAGE_ID = os.Getenv("OS_IMAGE_ID")
16+
OS_IMAGE_NAME = os.Getenv("OS_IMAGE_NAME")
17+
OS_NETWORK_ID = os.Getenv("OS_NETWORK_ID")
18+
OS_POOL_NAME = os.Getenv("OS_POOL_NAME")
19+
OS_REGION_NAME = os.Getenv("OS_REGION_NAME")
1420
)
1521

1622
var testAccProviders map[string]terraform.ResourceProvider
@@ -39,37 +45,23 @@ func testAccPreCheck(t *testing.T) {
3945
t.Fatal("OS_AUTH_URL must be set for acceptance tests")
4046
}
4147

42-
v = os.Getenv("OS_REGION_NAME")
43-
if v != "" {
44-
OS_REGION_NAME = v
45-
}
46-
47-
v1 := os.Getenv("OS_IMAGE_ID")
48-
v2 := os.Getenv("OS_IMAGE_NAME")
49-
50-
if v1 == "" || v2 == "" {
48+
if OS_IMAGE_ID == "" || OS_IMAGE_NAME == "" {
5149
t.Fatal("OS_IMAGE_ID and OS_IMAGE_NAME must be set for acceptance tests")
5250
}
5351

54-
v = os.Getenv("OS_POOL_NAME")
55-
if v == "" {
52+
if OS_POOL_NAME == "" {
5653
t.Fatal("OS_POOL_NAME must be set for acceptance tests")
5754
}
58-
OS_POOL_NAME = v
5955

60-
v1 = os.Getenv("OS_FLAVOR_ID")
61-
v2 = os.Getenv("OS_FLAVOR_NAME")
62-
if v1 == "" && v2 == "" {
56+
if OS_FLAVOR_ID == "" && OS_FLAVOR_NAME == "" {
6357
t.Fatal("OS_FLAVOR_ID or OS_FLAVOR_NAME must be set for acceptance tests")
6458
}
6559

66-
v = os.Getenv("OS_NETWORK_ID")
67-
if v == "" {
60+
if OS_NETWORK_ID == "" {
6861
t.Fatal("OS_NETWORK_ID must be set for acceptance tests")
6962
}
7063

71-
v = os.Getenv("OS_EXTGW_ID")
72-
if v == "" {
64+
if OS_EXTGW_ID == "" {
7365
t.Fatal("OS_EXTGW_ID must be set for acceptance tests")
7466
}
7567
}

‎builtin/providers/openstack/resource_openstack_blockstorage_volume_attach_v2_test.go‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestAccBlockStorageVolumeAttachV2_basic(t *testing.T) {
2222
resource.TestStep{
2323
Config: testAccBlockStorageVolumeAttachV2_basic,
2424
Check: resource.ComposeTestCheckFunc(
25-
testAccCheckBlockStorageVolumeAttachV2Exists(t, "openstack_blockstorage_volume_attach_v2.va_1", &va),
25+
testAccCheckBlockStorageVolumeAttachV2Exists("openstack_blockstorage_volume_attach_v2.va_1", &va),
2626
),
2727
},
2828
},
@@ -64,7 +64,7 @@ func testAccCheckBlockStorageVolumeAttachV2Destroy(s *terraform.State) error {
6464
return nil
6565
}
6666

67-
func testAccCheckBlockStorageVolumeAttachV2Exists(t *testing.T, n string, va *volumes.Attachment) resource.TestCheckFunc {
67+
func testAccCheckBlockStorageVolumeAttachV2Exists(n string, va *volumes.Attachment) resource.TestCheckFunc {
6868
return func(s *terraform.State) error {
6969
rs, ok := s.RootModule().Resources[n]
7070
if !ok {
@@ -107,20 +107,20 @@ func testAccCheckBlockStorageVolumeAttachV2Exists(t *testing.T, n string, va *vo
107107
}
108108
}
109109

110-
var testAccBlockStorageVolumeAttachV2_basic = `
111-
resource "openstack_blockstorage_volume_v2" "volume_1" {
112-
name = "volume_1"
113-
size = 1
114-
}
110+
const testAccBlockStorageVolumeAttachV2_basic = `
111+
resource "openstack_blockstorage_volume_v2" "volume_1" {
112+
name = "volume_1"
113+
size = 1
114+
}
115115
116-
resource "openstack_compute_instance_v2" "instance_1" {
117-
name = "instance_1"
118-
security_groups = ["default"]
119-
}
116+
resource "openstack_compute_instance_v2" "instance_1" {
117+
name = "instance_1"
118+
security_groups = ["default"]
119+
}
120120
121-
resource "openstack_blockstorage_volume_attach_v2" "va_1" {
122-
instance_id = "${openstack_compute_instance_v2.instance_1.id}"
123-
volume_id = "${openstack_blockstorage_volume_v2.volume_1.id}"
124-
device = "auto"
125-
}
121+
resource "openstack_blockstorage_volume_attach_v2" "va_1" {
122+
instance_id = "${openstack_compute_instance_v2.instance_1.id}"
123+
volume_id = "${openstack_blockstorage_volume_v2.volume_1.id}"
124+
device = "auto"
125+
}
126126
`

‎builtin/providers/openstack/resource_openstack_blockstorage_volume_v1_test.go‎

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package openstack
22

33
import (
44
"fmt"
5-
"os"
65
"testing"
76

87
"github.com/hashicorp/terraform/helper/resource"
@@ -15,15 +14,6 @@ import (
1514
func TestAccBlockStorageV1Volume_basic(t *testing.T) {
1615
var volume volumes.Volume
1716

18-
var testAccBlockStorageV1Volume_bootable = fmt.Sprintf(`
19-
resource "openstack_blockstorage_volume_v1" "volume_1" {
20-
region = "%s"
21-
name = "tf-test-volume-bootable"
22-
size = 5
23-
image_id = "%s"
24-
}`,
25-
os.Getenv("OS_REGION_NAME"), os.Getenv("OS_IMAGE_ID"))
26-
2717
resource.Test(t, resource.TestCase{
2818
PreCheck: func() { testAccPreCheck(t) },
2919
Providers: testAccProviders,
@@ -32,22 +22,39 @@ func TestAccBlockStorageV1Volume_basic(t *testing.T) {
3222
resource.TestStep{
3323
Config: testAccBlockStorageV1Volume_basic,
3424
Check: resource.ComposeTestCheckFunc(
35-
testAccCheckBlockStorageV1VolumeExists(t, "openstack_blockstorage_volume_v1.volume_1", &volume),
36-
resource.TestCheckResourceAttr("openstack_blockstorage_volume_v1.volume_1", "name", "tf-test-volume"),
25+
testAccCheckBlockStorageV1VolumeExists("openstack_blockstorage_volume_v1.volume_1", &volume),
3726
testAccCheckBlockStorageV1VolumeMetadata(&volume, "foo", "bar"),
27+
resource.TestCheckResourceAttr(
28+
"openstack_blockstorage_volume_v1.volume_1", "name", "volume_1"),
3829
),
3930
},
4031
resource.TestStep{
4132
Config: testAccBlockStorageV1Volume_update,
4233
Check: resource.ComposeTestCheckFunc(
43-
resource.TestCheckResourceAttr("openstack_blockstorage_volume_v1.volume_1", "name", "tf-test-volume-updated"),
34+
testAccCheckBlockStorageV1VolumeExists("openstack_blockstorage_volume_v1.volume_1", &volume),
4435
testAccCheckBlockStorageV1VolumeMetadata(&volume, "foo", "bar"),
36+
resource.TestCheckResourceAttr(
37+
"openstack_blockstorage_volume_v1.volume_1", "name", "volume_1-updated"),
4538
),
4639
},
40+
},
41+
})
42+
}
43+
44+
func TestAccBlockStorageV1Volume_image(t *testing.T) {
45+
var volume volumes.Volume
46+
47+
resource.Test(t, resource.TestCase{
48+
PreCheck: func() { testAccPreCheck(t) },
49+
Providers: testAccProviders,
50+
CheckDestroy: testAccCheckBlockStorageV1VolumeDestroy,
51+
Steps: []resource.TestStep{
4752
resource.TestStep{
48-
Config: testAccBlockStorageV1Volume_bootable,
53+
Config: testAccBlockStorageV1Volume_image,
4954
Check: resource.ComposeTestCheckFunc(
50-
resource.TestCheckResourceAttr("openstack_blockstorage_volume_v1.volume_1", "name", "tf-test-volume-bootable"),
55+
testAccCheckBlockStorageV1VolumeExists("openstack_blockstorage_volume_v1.volume_1", &volume),
56+
resource.TestCheckResourceAttr(
57+
"openstack_blockstorage_volume_v1.volume_1", "name", "volume_1"),
5158
),
5259
},
5360
},
@@ -75,7 +82,7 @@ func testAccCheckBlockStorageV1VolumeDestroy(s *terraform.State) error {
7582
return nil
7683
}
7784

78-
func testAccCheckBlockStorageV1VolumeExists(t *testing.T, n string, volume *volumes.Volume) resource.TestCheckFunc {
85+
func testAccCheckBlockStorageV1VolumeExists(n string, volume *volumes.Volume) resource.TestCheckFunc {
7986
return func(s *terraform.State) error {
8087
rs, ok := s.RootModule().Resources[n]
8188
if !ok {
@@ -151,22 +158,32 @@ func testAccCheckBlockStorageV1VolumeMetadata(
151158
}
152159
}
153160

154-
var testAccBlockStorageV1Volume_basic = fmt.Sprintf(`
155-
resource "openstack_blockstorage_volume_v1" "volume_1" {
156-
name = "tf-test-volume"
157-
description = "first test volume"
158-
metadata{
159-
foo = "bar"
160-
}
161-
size = 1
162-
}`)
163-
164-
var testAccBlockStorageV1Volume_update = fmt.Sprintf(`
165-
resource "openstack_blockstorage_volume_v1" "volume_1" {
166-
name = "tf-test-volume-updated"
167-
description = "first test volume"
168-
metadata{
169-
foo = "bar"
170-
}
171-
size = 1
172-
}`)
161+
const testAccBlockStorageV1Volume_basic = `
162+
resource "openstack_blockstorage_volume_v1" "volume_1" {
163+
name = "volume_1"
164+
description = "first test volume"
165+
metadata{
166+
foo = "bar"
167+
}
168+
size = 1
169+
}
170+
`
171+
172+
const testAccBlockStorageV1Volume_update = `
173+
resource "openstack_blockstorage_volume_v1" "volume_1" {
174+
name = "volume_1-updated"
175+
description = "first test volume"
176+
metadata{
177+
foo = "bar"
178+
}
179+
size = 1
180+
}
181+
`
182+
183+
var testAccBlockStorageV1Volume_image = fmt.Sprintf(`
184+
resource "openstack_blockstorage_volume_v1" "volume_1" {
185+
name = "volume_1"
186+
size = 5
187+
image_id = "%s"
188+
}
189+
`, OS_IMAGE_ID)

‎builtin/providers/openstack/resource_openstack_blockstorage_volume_v2_test.go‎

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package openstack
22

33
import (
44
"fmt"
5-
"os"
65
"testing"
76

87
"github.com/hashicorp/terraform/helper/resource"
@@ -23,44 +22,39 @@ func TestAccBlockStorageV2Volume_basic(t *testing.T) {
2322
resource.TestStep{
2423
Config: testAccBlockStorageV2Volume_basic,
2524
Check: resource.ComposeTestCheckFunc(
26-
testAccCheckBlockStorageV2VolumeExists(t, "openstack_blockstorage_volume_v2.volume_1", &volume),
27-
resource.TestCheckResourceAttr("openstack_blockstorage_volume_v2.volume_1", "name", "volume_1"),
25+
testAccCheckBlockStorageV2VolumeExists("openstack_blockstorage_volume_v2.volume_1", &volume),
2826
testAccCheckBlockStorageV2VolumeMetadata(&volume, "foo", "bar"),
27+
resource.TestCheckResourceAttr(
28+
"openstack_blockstorage_volume_v2.volume_1", "name", "volume_1"),
2929
),
3030
},
3131
resource.TestStep{
3232
Config: testAccBlockStorageV2Volume_update,
3333
Check: resource.ComposeTestCheckFunc(
34-
testAccCheckBlockStorageV2VolumeExists(t, "openstack_blockstorage_volume_v2.volume_1", &volume),
35-
resource.TestCheckResourceAttr("openstack_blockstorage_volume_v2.volume_1", "name", "volume_1-updated"),
34+
testAccCheckBlockStorageV2VolumeExists("openstack_blockstorage_volume_v2.volume_1", &volume),
3635
testAccCheckBlockStorageV2VolumeMetadata(&volume, "foo", "bar"),
36+
resource.TestCheckResourceAttr(
37+
"openstack_blockstorage_volume_v2.volume_1", "name", "volume_1-updated"),
3738
),
3839
},
3940
},
4041
})
4142
}
4243

43-
func TestAccBlockStorageV2Volume_bootable(t *testing.T) {
44+
func TestAccBlockStorageV2Volume_image(t *testing.T) {
4445
var volume volumes.Volume
4546

46-
var testAccBlockStorageV2Volume_bootable = fmt.Sprintf(`
47-
resource "openstack_blockstorage_volume_v2" "volume_1" {
48-
name = "volume_1-bootable"
49-
size = 5
50-
image_id = "%s"
51-
}`,
52-
os.Getenv("OS_IMAGE_ID"))
53-
5447
resource.Test(t, resource.TestCase{
5548
PreCheck: func() { testAccPreCheck(t) },
5649
Providers: testAccProviders,
5750
CheckDestroy: testAccCheckBlockStorageV2VolumeDestroy,
5851
Steps: []resource.TestStep{
5952
resource.TestStep{
60-
Config: testAccBlockStorageV2Volume_bootable,
53+
Config: testAccBlockStorageV2Volume_image,
6154
Check: resource.ComposeTestCheckFunc(
62-
testAccCheckBlockStorageV2VolumeExists(t, "openstack_blockstorage_volume_v2.volume_1", &volume),
63-
resource.TestCheckResourceAttr("openstack_blockstorage_volume_v2.volume_1", "name", "volume_1-bootable"),
55+
testAccCheckBlockStorageV2VolumeExists("openstack_blockstorage_volume_v2.volume_1", &volume),
56+
resource.TestCheckResourceAttr(
57+
"openstack_blockstorage_volume_v2.volume_1", "name", "volume_1"),
6458
),
6559
},
6660
},
@@ -88,7 +82,7 @@ func testAccCheckBlockStorageV2VolumeDestroy(s *terraform.State) error {
8882
return nil
8983
}
9084

91-
func testAccCheckBlockStorageV2VolumeExists(t *testing.T, n string, volume *volumes.Volume) resource.TestCheckFunc {
85+
func testAccCheckBlockStorageV2VolumeExists(n string, volume *volumes.Volume) resource.TestCheckFunc {
9286
return func(s *terraform.State) error {
9387
rs, ok := s.RootModule().Resources[n]
9488
if !ok {
@@ -163,22 +157,32 @@ func testAccCheckBlockStorageV2VolumeMetadata(
163157
}
164158
}
165159

166-
var testAccBlockStorageV2Volume_basic = fmt.Sprintf(`
167-
resource "openstack_blockstorage_volume_v2" "volume_1" {
168-
name = "volume_1"
169-
description = "first test volume"
170-
metadata {
171-
foo = "bar"
172-
}
173-
size = 1
174-
}`)
175-
176-
var testAccBlockStorageV2Volume_update = fmt.Sprintf(`
177-
resource "openstack_blockstorage_volume_v2" "volume_1" {
178-
name = "volume_1-updated"
179-
description = "first test volume"
180-
metadata {
181-
foo = "bar"
182-
}
183-
size = 1
184-
}`)
160+
const testAccBlockStorageV2Volume_basic = `
161+
resource "openstack_blockstorage_volume_v2" "volume_1" {
162+
name = "volume_1"
163+
description = "first test volume"
164+
metadata {
165+
foo = "bar"
166+
}
167+
size = 1
168+
}
169+
`
170+
171+
const testAccBlockStorageV2Volume_update = `
172+
resource "openstack_blockstorage_volume_v2" "volume_1" {
173+
name = "volume_1-updated"
174+
description = "first test volume"
175+
metadata {
176+
foo = "bar"
177+
}
178+
size = 1
179+
}
180+
`
181+
182+
var testAccBlockStorageV2Volume_image = fmt.Sprintf(`
183+
resource "openstack_blockstorage_volume_v2" "volume_1" {
184+
name = "volume_1"
185+
size = 5
186+
image_id = "%s"
187+
}
188+
`, OS_IMAGE_ID)

0 commit comments

Comments
 (0)