Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): Create multiple GCP targets #5408

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions enos/enos-scenario-e2e-docker-base-with-gcp.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"
Expand All @@ -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
Expand Down
20 changes: 5 additions & 15 deletions enos/modules/gcp_target/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
})
}

Expand All @@ -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}"
}
11 changes: 9 additions & 2 deletions enos/modules/test_e2e_docker/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [""]
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion enos/modules/test_e2e_docker/test_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/ \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Comment on lines +257 to +258
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized, is this being used anywhere?

EDIT: Wait, should all of these expected values be set tot he length of targetIps?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I have to take that out because it's not being used

For your second comment, the targetIps are 2. The private IP and the public IP.

When we create a host set with a specific filter that matches Target 1 in this example, only 1 host catalog is created with 2 IP addresses so only 1 HostId will be returned. The assertion only checks for 1 host catalog returned

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
Expand Down Expand Up @@ -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")
moduli marked this conversation as resolved.
Show resolved Hide resolved
}
3 changes: 2 additions & 1 deletion testing/internal/e2e/tests/gcp/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading