Skip to content

Commit e1f520e

Browse files
committed
misc: update tests to pass against omicron dev.
Update tests and docs such that the entire acceptance test suite runs against the simulated omicron environment. We either document and script all resources that the tests depend on, or teach the tests to create the dependencies themselves. We'll look into running the acceptance suite against simulated omicron in a separate patch.
1 parent ebd8b87 commit e1f520e

File tree

5 files changed

+162
-10
lines changed

5 files changed

+162
-10
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ Until all resources have been added you'll need to make sure your testing enviro
6565
- A project named "tf-acc-test".
6666
- At least one image.
6767

68+
To run tests against an empty simulated omicron environment, first provision test-related resources with `./scripts/acc-test-setup.sh`.
69+
6870
Tests that exercise the `oxide_silo` resource need a tls cert that's
6971
valid for the domain of the Oxide server used for acceptance tests. The
7072
tests will generate a self-signed cert, but need to know which DNS name

internal/provider/data_source_silo_test.go

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,78 @@ package provider
66

77
import (
88
"fmt"
9+
"os"
910
"testing"
1011

1112
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1213
)
1314

1415
type dataSourceSiloConfig struct {
15-
BlockName string
16+
BlockName string
17+
SiloDNSName string
1618
}
1719

1820
var dataSourceSiloConfigTpl = `
21+
resource "tls_private_key" "self-signed" {
22+
algorithm = "RSA"
23+
rsa_bits = 2048
24+
}
25+
26+
resource "tls_self_signed_cert" "self-signed" {
27+
private_key_pem = tls_private_key.self-signed.private_key_pem
28+
validity_period_hours = 8760
29+
30+
subject {
31+
common_name = "{{.SiloDNSName}}"
32+
organization = "Oxide Computer Company"
33+
}
34+
35+
dns_names = ["{{.SiloDNSName}}"]
36+
37+
allowed_uses = [
38+
"key_encipherment",
39+
"digital_signature",
40+
"server_auth",
41+
]
42+
}
43+
44+
resource "oxide_silo" "{{.BlockName}}" {
45+
name = "tf-acc-test"
46+
description = "Managed by Terraform."
47+
discoverable = true
48+
identity_mode = "local_only"
49+
50+
quotas = {
51+
cpus = 2
52+
memory = 8589934592
53+
storage = 8589934592
54+
}
55+
56+
mapped_fleet_roles = {
57+
admin = ["admin", "collaborator"]
58+
viewer = ["viewer"]
59+
}
60+
61+
tls_certificates = [
62+
{
63+
name = "self-signed-wildcard"
64+
description = "Self-signed wildcard certificate for *.sys.r3.oxide-preview.com."
65+
cert = tls_self_signed_cert.self-signed.cert_pem
66+
key = tls_private_key.self-signed.private_key_pem
67+
service = "external_api"
68+
},
69+
]
70+
71+
timeouts = {
72+
create = "1m"
73+
read = "2m"
74+
update = "3m"
75+
delete = "4m"
76+
}
77+
}
78+
1979
data "oxide_silo" "{{.BlockName}}" {
20-
name = "default"
80+
name = oxide_silo.{{.BlockName}}.name
2181
timeouts = {
2282
read = "1m"
2383
}
@@ -26,9 +86,16 @@ data "oxide_silo" "{{.BlockName}}" {
2686

2787
func TestAccSiloDataSourceSilo_full(t *testing.T) {
2888
blockName := newBlockName("datasource-silo")
89+
90+
dnsName := os.Getenv("OXIDE_SILO_DNS_NAME")
91+
if dnsName == "" {
92+
t.Skip("Skipping test. Export OXIDE_SILO_DNS_NAME to run.")
93+
}
94+
2995
config, err := parsedAccConfig(
3096
dataSourceSiloConfig{
31-
BlockName: blockName,
97+
BlockName: blockName,
98+
SiloDNSName: dnsName,
3299
},
33100
dataSourceSiloConfigTpl,
34101
)
@@ -39,6 +106,11 @@ func TestAccSiloDataSourceSilo_full(t *testing.T) {
39106
resource.ParallelTest(t, resource.TestCase{
40107
PreCheck: func() { testAccPreCheck(t) },
41108
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories(),
109+
ExternalProviders: map[string]resource.ExternalProvider{
110+
"tls": {
111+
Source: "hashicorp/tls",
112+
},
113+
},
42114
Steps: []resource.TestStep{
43115
{
44116
Config: config,
@@ -53,6 +125,7 @@ func TestAccSiloDataSourceSilo_full(t *testing.T) {
53125
func checkDataSourceSilo(dataName string) resource.TestCheckFunc {
54126
return resource.ComposeAggregateTestCheckFunc([]resource.TestCheckFunc{
55127
resource.TestCheckResourceAttrSet(dataName, "name"),
128+
resource.TestCheckResourceAttr(dataName, "name", "tf-acc-test"),
56129
resource.TestCheckResourceAttr(dataName, "timeouts.read", "1m"),
57130
resource.TestCheckResourceAttrSet(dataName, "id"),
58131
resource.TestCheckResourceAttrSet(dataName, "discoverable"),

internal/provider/data_source_vpc_internet_gateway_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,21 @@ type dataSourceVPCInternetGatewayConfig struct {
1717
}
1818

1919
var dataSourceVPCInternetGatewayConfigTpl = `
20+
data "oxide_vpc" "test" {
21+
project_name = "tf-acc-test"
22+
name = "default"
23+
}
24+
25+
resource "oxide_vpc_internet_gateway" "{{.BlockName}}" {
26+
vpc_id = data.oxide_vpc.test.id
27+
name = "test"
28+
description = "test description"
29+
}
30+
2031
data "oxide_vpc_internet_gateway" "{{.BlockName}}" {
2132
project_name = "tf-acc-test"
2233
vpc_name = "default"
23-
name = "default"
34+
name = oxide_vpc_internet_gateway.{{.BlockName}}.name
2435
timeouts = {
2536
read = "1m"
2637
}
@@ -57,8 +68,8 @@ func TestAccCloudDataSourceVPCInternetGateway_full(t *testing.T) {
5768
func checkDataSourceVPCInternetGateway(dataName string) resource.TestCheckFunc {
5869
return resource.ComposeAggregateTestCheckFunc([]resource.TestCheckFunc{
5970
resource.TestCheckResourceAttrSet(dataName, "id"),
60-
resource.TestCheckResourceAttr(dataName, "description", "Default VPC gateway"),
61-
resource.TestCheckResourceAttr(dataName, "name", "default"),
71+
resource.TestCheckResourceAttr(dataName, "description", "test description"),
72+
resource.TestCheckResourceAttr(dataName, "name", "test"),
6273
resource.TestCheckResourceAttrSet(dataName, "vpc_id"),
6374
resource.TestCheckResourceAttrSet(dataName, "time_created"),
6475
resource.TestCheckResourceAttrSet(dataName, "time_modified"),

internal/provider/data_source_vpc_router_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@ type dataSourceVPCRouterConfig struct {
1818
}
1919

2020
var dataSourceVPCRouterConfigTpl = `
21+
data "oxide_vpc" "test" {
22+
project_name = "tf-acc-test"
23+
name = "default"
24+
}
25+
26+
resource "oxide_vpc_router" "{{.BlockName}}" {
27+
vpc_id = data.oxide_vpc.test.id
28+
name = "test"
29+
description = "test router"
30+
}
31+
2132
data "oxide_vpc_router" "{{.BlockName}}" {
2233
project_name = "tf-acc-test"
2334
vpc_name = "default"
24-
name = "system"
35+
name = oxide_vpc_router.{{.BlockName}}.name
2536
timeouts = {
2637
read = "1m"
2738
}
@@ -61,10 +72,10 @@ func checkDataSourceVPCRouter(dataName string) resource.TestCheckFunc {
6172
resource.TestCheckResourceAttr(
6273
dataName,
6374
"description",
64-
"Routes are automatically added to this router as vpc subnets are created",
75+
"test router",
6576
),
66-
resource.TestCheckResourceAttr(dataName, "name", "system"),
67-
resource.TestCheckResourceAttr(dataName, "kind", string(oxide.VpcRouterKindSystem)),
77+
resource.TestCheckResourceAttr(dataName, "name", "test"),
78+
resource.TestCheckResourceAttr(dataName, "kind", string(oxide.VpcRouterKindCustom)),
6879
resource.TestCheckResourceAttrSet(dataName, "vpc_id"),
6980
resource.TestCheckResourceAttrSet(dataName, "time_created"),
7081
resource.TestCheckResourceAttrSet(dataName, "time_modified"),

scripts/acc-test-setup.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
3+
# Set up dependencies for the acceptance test suite. The tests expect various
4+
# resources to be configured.
5+
6+
set -euo pipefail
7+
8+
PROJECT_NAME=${OXIDE_PROJECT:-tf-acc-test}
9+
10+
# Default to test-suite-silo, the silo used by omicron-dev.
11+
SILO_NAME=${OXIDE_SILO:-test-suite-silo}
12+
13+
# Point to a .raw file, defaulting to a local alpine image. To build an image,
14+
# run:
15+
#
16+
# wget https://dl-cdn.alpinelinux.org/alpine/v3.22/releases/cloud/generic_alpine-3.22.1-x86_64-bios-tiny-r0.qcow2
17+
# qemu-img convert -f qcow2 -O raw generic_alpine-3.22.1-x86_64-bios-tiny-r0.qcow2 alpine.raw
18+
IMAGE_PATH=${OXIDE_IMAGE_PATH:-alpine.raw}
19+
20+
# oxide project create --name $PROJECT_NAME --description $PROJECT_NAME
21+
22+
# # We need to create disks, images, etc., so override the default empty quota.
23+
# oxide silo quotas update --silo $SILO_NAME --cpus 100 --memory $((2 ** 40)) --storage $((2 ** 40))
24+
25+
# # Set up the default IP pool, and add a range.
26+
# oxide ip-pool create --name default --description default
27+
# oxide ip-pool silo link --pool default --silo $SILO_NAME --is-default true
28+
# oxide ip-pool range add --first 10.0.1.0 --last 10.0.1.255 --pool default
29+
30+
# The acceptance tests expect both at least a single project-scoped image and a
31+
# silo-scoped image. Import the same image twice, then promote one copy to the
32+
# silo. Use alpine because it's small.
33+
oxide disk import \
34+
--project $PROJECT_NAME \
35+
--path $IMAGE_PATH \
36+
--disk alpine-project \
37+
--description "alpine image" \
38+
--snapshot alpine-snapshot-project \
39+
--image alpine-project \
40+
--image-description "alpine image" \
41+
--image-os alpine \
42+
--image-version "3.22.1"
43+
44+
oxide image promote --image alpine-project --project $PROJECT_NAME
45+
46+
oxide disk import \
47+
--project $PROJECT_NAME \
48+
--path $IMAGE_PATH \
49+
--disk alpine-silo \
50+
--description "alpine image" \
51+
--snapshot alpine-snapshot-silo \
52+
--image alpine-silo \
53+
--image-description "alpine image" \
54+
--image-os alpine \
55+
--image-version "3.22.1"

0 commit comments

Comments
 (0)