Skip to content

Commit 22af6fe

Browse files
Add support for vsphere on robotest
1 parent ea78dcf commit 22af6fe

File tree

22 files changed

+538
-114
lines changed

22 files changed

+538
-114
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ tf/
2525
# build artifacts
2626
version.go
2727
build/
28+
.idea

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ BUILDDIR ?= $(abspath build)
2424
# docker doesn't allow "+" in image tags: https://github.com/docker/distribution/issues/1201
2525
export ROBOTEST_DOCKER_VERSION ?= $(subst +,-,$(VERSION))
2626
export ROBOTEST_DOCKER_TAG ?=
27-
export ROBOTEST_DOCKER_ARGS ?= --pull
27+
export ROBOTEST_DOCKER_ARGS ?=
2828
DOCKERFLAGS := --rm=true $(NOROOT) -v $(PWD):$(SRCDIR) -v $(BUILDDIR):$(SRCDIR)/build -w $(SRCDIR)
2929
BUILDBOX := robotest:buildbox
3030
BUILDBOX_IIDFILE := $(BUILDDIR)/.robotest-buildbox.iid

assets/terraform/vsphere/config.tf

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
variable "vsphere_user" {
2+
description = "vSphere username"
3+
type = string
4+
}
5+
6+
variable "vsphere_password" {
7+
description = "vSphere password"
8+
type = string
9+
}
10+
11+
variable "vsphere_server" {
12+
description = "vSphere server"
13+
type = string
14+
}
15+
16+
variable "datacenter" {
17+
description = "The vSphere datacenter where resources will be created"
18+
type = string
19+
}
20+
21+
variable "cluster" {
22+
description = "The vSphere cluster where resources will be created"
23+
type = string
24+
}
25+
26+
variable "datastore" {
27+
description = "The vSphere datastore where VM disks will be stored"
28+
type = string
29+
}
30+
31+
variable "vm_folder" {
32+
description = "The vSphere folder where VMs will be created"
33+
type = string
34+
}
35+
36+
variable "network" {
37+
description = "Network for VM NIC."
38+
type = string
39+
}
40+
41+
variable "template" {
42+
description = "Template to clone VMs from"
43+
type = string
44+
}
45+
46+
variable "node_tag" {
47+
description = "vSphere-friendly cluster name to use as a prefix for resources."
48+
type = string
49+
}
50+
51+
variable "vm_type" {
52+
description = "Type of VM to provision"
53+
type = string
54+
}
55+
56+
variable "os_user" {
57+
description = "SSH user to login onto nodes"
58+
type = string
59+
}
60+
61+
variable "ssh_pub_key_path" {
62+
description = "Path to the public SSH key."
63+
type = string
64+
}
65+
66+
variable "nodes" {
67+
description = "Number of nodes to provision"
68+
type = number
69+
default = 1
70+
}
71+
72+
provider "vsphere" {
73+
user = var.vsphere_user
74+
password = var.vsphere_password
75+
vsphere_server = var.vsphere_server
76+
77+
allow_unverified_ssl = true
78+
}
79+
80+
data "vsphere_datacenter" "dc" {
81+
name = var.datacenter
82+
}
83+
84+
data "vsphere_compute_cluster" "cluster" {
85+
name = var.cluster
86+
datacenter_id = data.vsphere_datacenter.dc.id
87+
}

assets/terraform/vsphere/network.tf

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Network
3+
#
4+
5+
data "vsphere_network" "network" {
6+
name = var.network
7+
datacenter_id = data.vsphere_datacenter.dc.id
8+
}

assets/terraform/vsphere/node.tf

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#
2+
# Virtual Machine node
3+
#
4+
5+
resource "vsphere_virtual_machine" "node" {
6+
#TODO: Move to vars!!
7+
guest_id = "rhel7_64Guest"
8+
count = var.nodes
9+
name = "${var.node_tag}-node-${count.index}"
10+
folder = var.vm_folder
11+
12+
resource_pool_id = data.vsphere_compute_cluster.cluster.resource_pool_id
13+
14+
# memory = 8192 #TODO(ag):Make this template specific?
15+
16+
network_interface {
17+
network_id = data.vsphere_network.network.id
18+
}
19+
20+
disk {
21+
label = "disk0"
22+
size = 64
23+
thin_provisioned = false #TODO(ag): Update the template to true and change here
24+
}
25+
26+
clone {
27+
template_uuid = data.vsphere_virtual_machine.template.id
28+
29+
}
30+
31+
extra_config = {
32+
"guestinfo.ssh_user" = var.os_user
33+
"guestinfo.ssh_public_key_data" = file(var.ssh_pub_key_path)
34+
}
35+
}
36+
37+
data "vsphere_datastore" "datastore" {
38+
name = var.datastore
39+
datacenter_id = data.vsphere_datacenter.dc.id
40+
}
41+
42+
data "vsphere_virtual_machine" "template" {
43+
name = var.template
44+
datacenter_id = data.vsphere_datacenter.dc.id
45+
}

assets/terraform/vsphere/os.tf

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# OS configuration
3+
#
4+
5+
variable "oss" {
6+
description = "Map of supported Linux distributions"
7+
type = "map"
8+
9+
default = {
10+
"redhat:7.9" = "toTemplate1"
11+
"redhat7.9" = "toTemplate1"
12+
}
13+
}
14+
15+
#variable "os" {
16+
# description = "Map of supported Linux distributions"
17+
# type = "map"
18+
#
19+
# default = {
20+
# "redhat:7.9" = "toTemplate1"
21+
# "redhat7.9" = "toTemplate1"
22+
# }
23+
#}

assets/terraform/vsphere/output.tf

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# Output Variables
3+
#
4+
5+
output "instance_names" {
6+
value = vsphere_virtual_machine.node.*.name
7+
}
8+
9+
output "private_ips" {
10+
value = vsphere_virtual_machine.node.*.default_ip_address
11+
}
12+
13+
output "public_ips" {
14+
value = vsphere_virtual_machine.node.*.default_ip_address
15+
}

assets/terraform/vsphere/versions.tf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
terraform {
2+
required_version = ">= 0.12"
3+
}

docker/Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ DOCKER_REPO := quay.io/gravitational
1717
ROBOTEST_DOCKER_VERSION ?=
1818
# An empty tag will be ignored
1919
ROBOTEST_DOCKER_TAG ?=
20-
ROBOTEST_DOCKER_ARGS ?= --pull
20+
ROBOTEST_DOCKER_ARGS ?=
2121

2222
GRAVITY_VERSION := 5.5.50
2323
TERRAFORM_VERSION := 0.12.9
@@ -27,9 +27,10 @@ TERRAFORM_PROVIDER_AZURERM_VERSION := 1.5.0
2727
TERRAFORM_PROVIDER_GOOGLE_VERSION := 2.15.0
2828
TERRAFORM_PROVIDER_RANDOM_VERSION := 2.2.0
2929
TERRAFORM_PROVIDER_TEMPLATE_VERSION := 2.1.2
30+
TERRAFORM_PROVIDER_VSPHERE_VERSION := 1.14.0
3031
export
3132

32-
providers := AZURERM AWS GOOGLE RANDOM TEMPLATE
33+
providers := AZURERM AWS GOOGLE RANDOM TEMPLATE VSPHERE
3334
provider_args := $(foreach provider,$(providers),--build-arg TERRAFORM_PROVIDER_$(provider)_VERSION=$$TERRAFORM_PROVIDER_$(provider)_VERSION)
3435

3536
BUILD_ARGS := \

docker/build/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
FROM quay.io/gravitational/debian-venti:go1.16.6-buster
14+
FROM quay.io/gravitational/debian-venti:go1.17.5-stretch
1515

1616
ARG UID
1717
ARG GID

docker/e2e/Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
FROM quay.io/gravitational/debian-grande:stretch
14+
FROM quay.io/gravitational/debian-grande:buster
1515

1616
ARG TERRAFORM_VERSION
1717
ARG CHROMEDRIVER_VERSION
@@ -59,6 +59,10 @@ RUN mkdir -p /robotest
5959
WORKDIR /robotest
6060
COPY entrypoint.sh /entrypoint.sh
6161
COPY build/robotest-e2e /usr/bin/robotest-e2e
62+
COPY polaris.pub /robotest/polaris.pub
63+
COPY polaris.pem /robotest/polaris.pem
64+
RUN chmod 0644 /robotest/polaris.pem
65+
#TODO: Change the user on the template and the SSH keys. polaris is not meant for this
6266

6367
RUN chmod +x /usr/bin/robotest-e2e && \
6468
chmod +x /entrypoint.sh

docker/suite/Dockerfile

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ARG TERRAFORM_PROVIDER_AWS_VERSION
2323
ARG TERRAFORM_PROVIDER_GOOGLE_VERSION
2424
ARG TERRAFORM_PROVIDER_TEMPLATE_VERSION
2525
ARG TERRAFORM_PROVIDER_RANDOM_VERSION
26+
ARG TERRAFORM_PROVIDER_VSPHERE_VERSION
2627
ENV TF_TARBALL https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip
2728

2829
ENV TF_PLUGINS \
@@ -33,7 +34,10 @@ ENV TF_PLUGINS \
3334
# Google Compute Engine
3435
https://releases.hashicorp.com/terraform-provider-google/${TERRAFORM_PROVIDER_GOOGLE_VERSION}/terraform-provider-google_${TERRAFORM_PROVIDER_GOOGLE_VERSION}_linux_amd64.zip \
3536
https://releases.hashicorp.com/terraform-provider-template/${TERRAFORM_PROVIDER_TEMPLATE_VERSION}/terraform-provider-template_${TERRAFORM_PROVIDER_TEMPLATE_VERSION}_linux_amd64.zip \
36-
https://releases.hashicorp.com/terraform-provider-random/${TERRAFORM_PROVIDER_RANDOM_VERSION}/terraform-provider-random_${TERRAFORM_PROVIDER_RANDOM_VERSION}_linux_amd64.zip
37+
https://releases.hashicorp.com/terraform-provider-random/${TERRAFORM_PROVIDER_RANDOM_VERSION}/terraform-provider-random_${TERRAFORM_PROVIDER_RANDOM_VERSION}_linux_amd64.zip \
38+
# vSphere
39+
https://releases.hashicorp.com/terraform-provider-vsphere/${TERRAFORM_PROVIDER_VSPHERE_VERSION}/terraform-provider-vsphere_1.14.0_linux_amd64.zip
40+
3741

3842
RUN curl ${TF_TARBALL} -o terraform.zip && \
3943
unzip terraform.zip -d /usr/bin && \
@@ -59,5 +63,9 @@ WORKDIR /robotest
5963
COPY build/robotest-suite /usr/bin/robotest-suite
6064
COPY terraform /robotest/terraform
6165
COPY run_suite.sh /usr/bin/run_suite.sh
66+
COPY polaris.pub /robotest/polaris.pub
67+
COPY polaris.pem /robotest/polaris.pem
68+
RUN chmod 0660 /robotest/polaris.pem
69+
#TODO: Change the user on the template and the SSH keys. polaris is not meant for this
6270

6371
RUN chmod +x /usr/bin/robotest-suite

infra/gravity/cluster_install.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,21 @@ func (c *TestContext) OfflineInstall(nodes []Gravity, param InstallParam) error
8787
defer cancel()
8888

8989
param.CloudProvider = c.provisionerCfg.CloudProvider
90-
master := nodes[0].(*gravity)
90+
91+
// Before the typecast, log the details of `nodes`
92+
c.Logger().Infof("Nodes slice: %v", nodes)
93+
for i, node := range nodes {
94+
c.Logger().Infof("Node[%d]: type=%T, value=%v", i, node, node)
95+
}
96+
97+
// Attempt the typecast
98+
master, ok := nodes[0].(*gravity)
99+
if !ok {
100+
c.Logger().Fatalf("Failed to typecast nodes[0] to *gravity. Actual type: %T", nodes[0])
101+
}
102+
103+
// If the typecast is successful, proceed with the rest of your code
104+
c.Logger().Infof("Typecast successful. master: %v", master)
91105
if param.Token == "" {
92106
param.Token = "ROBOTEST"
93107
}

0 commit comments

Comments
 (0)