From 5cd05217fe9ed1197a06f7ee645b03034ee29110 Mon Sep 17 00:00:00 2001 From: Elim Tsiagbey Date: Sun, 5 Jan 2025 17:25:13 -0500 Subject: [PATCH 1/2] test(e2e): Create multiple targets Update tests to create 2 GCP instances with different filters to test out discovering GCP instances by filter --- ...enos-scenario-e2e-docker-base-with-gcp.hcl | 27 ++++++++++++----- enos/modules/gcp_target/main.tf | 20 ++++--------- enos/modules/test_e2e_docker/main.tf | 11 +++++-- enos/modules/test_e2e_docker/test_runner.sh | 3 +- .../gcp/dynamichostcatalog_host_set_test.go | 30 ++++++++++++------- testing/internal/e2e/tests/gcp/env_test.go | 3 +- 6 files changed, 58 insertions(+), 36 deletions(-) diff --git a/enos/enos-scenario-e2e-docker-base-with-gcp.hcl b/enos/enos-scenario-e2e-docker-base-with-gcp.hcl index d70f476487..ea3c95d8c0 100644 --- a/enos/enos-scenario-e2e-docker-base-with-gcp.hcl +++ b/enos/enos-scenario-e2e-docker-base-with-gcp.hcl @@ -96,7 +96,18 @@ scenario "e2e_docker_base_with_gcp" { } } - step "create_gcp_target" { + step "create_gcp_target_1" { + module = module.gcp_target + + variables { + enos_user = var.enos_user + instance_type = var.gcp_target_instance_type + gcp_zone = var.gcp_zone + target_count = 1 + } + } + + step "create_gcp_target_2" { module = module.gcp_target variables { @@ -111,7 +122,8 @@ scenario "e2e_docker_base_with_gcp" { module = module.test_e2e_docker depends_on = [ step.create_boundary, - step.create_gcp_target + step.create_gcp_target_1, + step.create_gcp_target_2 ] variables { test_package = "github.com/hashicorp/boundary/testing/internal/e2e/tests/gcp" @@ -125,16 +137,17 @@ scenario "e2e_docker_base_with_gcp" { auth_password = step.create_boundary.password local_boundary_dir = step.build_boundary_docker_image.cli_zip_path local_boundary_src_dir = local.local_boundary_src_dir - gcp_host_set_filter1 = step.create_gcp_target.filter_label1 - gcp_host_set_filter2 = step.create_gcp_target.filter_label2 + gcp_host_set_filter1 = step.create_gcp_target_1.filter_label + gcp_host_set_filter2 = step.create_gcp_target_2.filter_label gcp_private_key_id = var.gcp_private_key_id gcp_private_key = local.gcp_private_key gcp_zone = var.gcp_zone gcp_project_id = var.gcp_project_id gcp_client_email = var.gcp_client_email - gcp_target_ssh_key = step.create_gcp_target.target_ssh_key - gcp_host_set_ips = step.create_gcp_target.target_ips - target_address = step.create_gcp_target.target_public_ips[0] + gcp_target_ssh_key = step.create_gcp_target_1.target_ssh_key + gcp_host_set_ips1 = step.create_gcp_target_1.target_ips + gcp_host_set_ips2 = step.create_gcp_target_2.target_ips + target_address = step.create_gcp_target_1.target_public_ips[0] target_port = "22" target_user = "ubuntu" max_page_size = step.create_boundary.max_page_size diff --git a/enos/modules/gcp_target/main.tf b/enos/modules/gcp_target/main.tf index 828a29dfb4..80c0e2df83 100644 --- a/enos/modules/gcp_target/main.tf +++ b/enos/modules/gcp_target/main.tf @@ -48,12 +48,7 @@ resource "google_compute_network" "boundary_compute_network" { name = "boundary-enos-network-${random_string.test_string.result}" } -resource "random_id" "filter_label1" { - prefix = "enos_boundary" - byte_length = 4 -} - -resource "random_id" "filter_label2" { +resource "random_id" "filter_label" { prefix = "enos_boundary" byte_length = 4 } @@ -126,8 +121,7 @@ resource "google_compute_instance" "boundary_target" { "project_name" : "qti-enos-boundary", "environment" : var.environment, "enos_user" : replace(var.enos_user, "/[\\W]+/", ""), - "filter_label_1" : random_id.filter_label1.hex - "filter_label_2" : random_id.filter_label2.hex + "filter_label" : random_id.filter_label.hex }) } @@ -151,10 +145,6 @@ output "target_ssh_key" { sensitive = true } -output "filter_label1" { - value = "labels.filter_label_1=${random_id.filter_label1.hex}" -} - -output "filter_label2" { - value = "labels.filter_label_2=${random_id.filter_label2.hex}" -} +output "filter_label" { + value = "labels.filter_label=${random_id.filter_label.hex}" +} \ No newline at end of file diff --git a/enos/modules/test_e2e_docker/main.tf b/enos/modules/test_e2e_docker/main.tf index 254e5d627a..179788d58a 100644 --- a/enos/modules/test_e2e_docker/main.tf +++ b/enos/modules/test_e2e_docker/main.tf @@ -274,7 +274,13 @@ variable "gcp_host_set_filter2" { default = "" } -variable "gcp_host_set_ips" { +variable "gcp_host_set_ips1" { + description = "List of IP addresses" + type = list(string) + default = [""] +} + +variable "gcp_host_set_ips2" { description = "List of IP addresses" type = list(string) default = [""] @@ -346,7 +352,8 @@ resource "enos_local_exec" "run_e2e_test" { E2E_GCP_TARGET_SSH_KEY = var.gcp_target_ssh_key E2E_GCP_HOST_SET_FILTER1 = var.gcp_host_set_filter1 E2E_GCP_HOST_SET_FILTER2 = var.gcp_host_set_filter2 - E2E_GCP_HOST_SET_IPS = jsonencode(var.gcp_host_set_ips) + E2E_GCP_HOST_SET_IPS1 = jsonencode(var.gcp_host_set_ips1) + E2E_GCP_HOST_SET_IPS2 = jsonencode(var.gcp_host_set_ips2) E2E_MAX_PAGE_SIZE = var.max_page_size E2E_CONTROLLER_CONTAINER_NAME = var.controller_container_name BOUNDARY_DIR = abspath(var.local_boundary_src_dir) diff --git a/enos/modules/test_e2e_docker/test_runner.sh b/enos/modules/test_e2e_docker/test_runner.sh index 24e1e99d5b..c91acece4c 100644 --- a/enos/modules/test_e2e_docker/test_runner.sh +++ b/enos/modules/test_e2e_docker/test_runner.sh @@ -53,7 +53,8 @@ docker run \ -e "E2E_GCP_TARGET_SSH_KEY=$E2E_GCP_TARGET_SSH_KEY" \ -e "E2E_GCP_HOST_SET_FILTER1=$E2E_GCP_HOST_SET_FILTER1" \ -e "E2E_GCP_HOST_SET_FILTER2=$E2E_GCP_HOST_SET_FILTER2" \ - -e "E2E_GCP_HOST_SET_IPS=$E2E_GCP_HOST_SET_IPS" \ + -e "E2E_GCP_HOST_SET_IPS1=$E2E_GCP_HOST_SET_IPS1" \ + -e "E2E_GCP_HOST_SET_IPS2=$E2E_GCP_HOST_SET_IPS2" \ -e "E2E_MAX_PAGE_SIZE=$E2E_MAX_PAGE_SIZE" \ -e "E2E_CONTROLLER_CONTAINER_NAME=$E2E_CONTROLLER_CONTAINER_NAME" \ --mount type=bind,src=$BOUNDARY_DIR,dst=/src/boundary/ \ diff --git a/testing/internal/e2e/tests/gcp/dynamichostcatalog_host_set_test.go b/testing/internal/e2e/tests/gcp/dynamichostcatalog_host_set_test.go index 0ac7274059..89a76bce94 100644 --- a/testing/internal/e2e/tests/gcp/dynamichostcatalog_host_set_test.go +++ b/testing/internal/e2e/tests/gcp/dynamichostcatalog_host_set_test.go @@ -50,12 +50,20 @@ func TestCliCreateGcpDynamicHostCatalogWithHostSet(t *testing.T) { // Set up a host set hostSetId1, err := boundary.CreatePluginHostSetCli(t, ctx, hostCatalogId, c.GcpHostSetFilter1) require.NoError(t, err) - boundary.WaitForNumberOfHostsInHostSetCli(t, ctx, hostSetId1, 1) + var targetIps1 []string + err = json.Unmarshal([]byte(c.GcpHostSetIps1), &targetIps1) + expectedHostSetCount1 := 1 + require.NoError(t, err) + boundary.WaitForNumberOfHostsInHostSetCli(t, ctx, hostSetId1, expectedHostSetCount1) // Set up another host set hostSetId2, err := boundary.CreatePluginHostSetCli(t, ctx, hostCatalogId, c.GcpHostSetFilter2) require.NoError(t, err) - boundary.WaitForNumberOfHostsInHostSetCli(t, ctx, hostSetId2, 1) + var targetIps2 []string + err = json.Unmarshal([]byte(c.GcpHostSetIps2), &targetIps2) + require.NoError(t, err) + expectedHostSetCount2 := 1 + boundary.WaitForNumberOfHostsInHostSetCli(t, ctx, hostSetId2, expectedHostSetCount2) // Update host set with a different filter t.Log("Updating host set 2 with host set 1's filter...") @@ -114,7 +122,8 @@ func TestCliCreateGcpDynamicHostCatalogWithHostSet(t *testing.T) { }, ) require.NoError(t, err) - assert.Equal(t, 1, actualHostCatalogCount, "Numbers of hosts in host catalog did not match expected amount") + expectedHostCatalogCount := expectedHostSetCount1 + expectedHostSetCount2 + assert.Equal(t, expectedHostCatalogCount, actualHostCatalogCount, "Numbers of hosts in host catalog did not match expected amount") // Create target targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.GcpTargetPort) @@ -156,16 +165,13 @@ func TestCliCreateGcpDynamicHostCatalogWithHostSet(t *testing.T) { t.Log("Successfully connected to the target") // Check if connected host exists in the host set - var targetIps []string - err = json.Unmarshal([]byte(c.GcpHostSetIps), &targetIps) - require.NoError(t, err) hostIpInList := false - for _, v := range targetIps { + for _, v := range targetIps1 { if v == hostIp { hostIpInList = true } } - require.True(t, hostIpInList, fmt.Sprintf("Connected host (%s) is not in expected list (%s)", hostIp, targetIps)) + require.True(t, hostIpInList, fmt.Sprintf("Connected host (%s) is not in expected list (%s)", hostIp, targetIps1)) } // TestApiCreateGcpDynamicHostCatalog uses the Go api to create a host catalog with the GCP plugin. @@ -248,7 +254,11 @@ func TestApiCreateGCPDynamicHostCatalog(t *testing.T) { ) require.NoError(t, err) t.Log("Successfully found items in the host set") - assert.Equal(t, 1, actualHostSetCount, "Numbers of hosts in host set did not match expected amount") + var targetIps []string + err = json.Unmarshal([]byte(c.GcpHostSetIps1), &targetIps) + require.NoError(t, err) + expectedHostSetCount := 1 + assert.Equal(t, expectedHostSetCount, actualHostSetCount, "Numbers of hosts in host set did not match expected amount") // Get list of all hosts from host catalog // Retry is needed here since it can take a few tries before hosts start appearing @@ -277,5 +287,5 @@ func TestApiCreateGCPDynamicHostCatalog(t *testing.T) { ) require.NoError(t, err) t.Log("Successfully found items in the host catalog") - assert.Equal(t, 1, actualHostCatalogCount, "Numbers of hosts in host catalog did not match expected amount") + assert.Equal(t, actualHostCatalogCount, expectedHostSetCount, "Numbers of hosts in host catalog did not match expected amount") } diff --git a/testing/internal/e2e/tests/gcp/env_test.go b/testing/internal/e2e/tests/gcp/env_test.go index 4df85fa915..0eae278ec2 100644 --- a/testing/internal/e2e/tests/gcp/env_test.go +++ b/testing/internal/e2e/tests/gcp/env_test.go @@ -13,7 +13,8 @@ type config struct { GcpClientEmail string `envconfig:"E2E_GCP_CLIENT_EMAIL" required:"true"` GcpHostSetFilter1 string `envconfig:"E2E_GCP_HOST_SET_FILTER1" required:"true"` GcpHostSetFilter2 string `envconfig:"E2E_GCP_HOST_SET_FILTER2" required:"true"` - GcpHostSetIps string `envconfig:"E2E_GCP_HOST_SET_IPS" required:"true"` + GcpHostSetIps1 string `envconfig:"E2E_GCP_HOST_SET_IPS1" required:"true"` + GcpHostSetIps2 string `envconfig:"E2E_GCP_HOST_SET_IPS2" required:"true"` GcpTargetSshKey string `envconfig:"E2E_GCP_TARGET_SSH_KEY" required:"true"` GcpTargetAddress string `envconfig:"E2E_TARGET_ADDRESS" required:"true"` // e.g. "192.168.0.1" GcpTargetSshUser string `envconfig:"E2E_SSH_USER" required:"true"` // e.g. "ubuntu" From 28b57c4fc59210cff8d557654363376a59e0f1f6 Mon Sep 17 00:00:00 2001 From: Elim Tsiagbey Date: Tue, 7 Jan 2025 01:14:01 -0500 Subject: [PATCH 2/2] swap gcp assertion --- .../internal/e2e/tests/gcp/dynamichostcatalog_host_set_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/internal/e2e/tests/gcp/dynamichostcatalog_host_set_test.go b/testing/internal/e2e/tests/gcp/dynamichostcatalog_host_set_test.go index 89a76bce94..92a5b3df2f 100644 --- a/testing/internal/e2e/tests/gcp/dynamichostcatalog_host_set_test.go +++ b/testing/internal/e2e/tests/gcp/dynamichostcatalog_host_set_test.go @@ -287,5 +287,5 @@ func TestApiCreateGCPDynamicHostCatalog(t *testing.T) { ) require.NoError(t, err) t.Log("Successfully found items in the host catalog") - assert.Equal(t, actualHostCatalogCount, expectedHostSetCount, "Numbers of hosts in host catalog did not match expected amount") + assert.Equal(t, expectedHostSetCount, actualHostCatalogCount, "Numbers of hosts in host catalog did not match expected amount") }