Skip to content

Commit 62f24f8

Browse files
authored
Merge pull request #12744 from cuongdo/terraform_azure
acceptance: support nightlies on Azure
2 parents ab47406 + 9339eb0 commit 62f24f8

File tree

12 files changed

+474
-26
lines changed

12 files changed

+474
-26
lines changed

pkg/acceptance/allocator_test.go

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,30 @@ package acceptance
1818
// and run tests against dedicated test clusters.
1919
//
2020
// Required setup:
21-
// 1. Have a GCE account.
22-
// 2. Have someone grant permissions (for new *and* existing objects) for the
23-
// GCS bucket referenced in `archivedStoreURL`. You'll want permissions
24-
// granted to the following email addresses:
25-
// a. The email address you use to log into Google Cloud Console.
26-
// b. Your default Google Compute Engine service account (it'll look like
27-
// 111111111111-compute@developer.gserviceaccount.com)
28-
// 3. Set the environment variable GOOGLE_PROJECT to the name of the Google
29-
// Project you want Terraform to use.
21+
// 1. Have an Azure account.
22+
// 2. Passphrase-less SSH key in ~/.ssh/{azure,azure.pub}.
23+
// 3. Set the ARM_SUBSCRIPTION_ID, ARM_CLIENT_ID, ARM_CLIENT_SECRET, and
24+
// ARM_TENANT_ID variables as documented here:
25+
// https://www.terraform.io/docs/providers/azurerm/#argument-reference
3026
//
3127
// Example use:
3228
//
33-
// build/builder.sh make build && make test \
29+
// make test \
3430
// TESTTIMEOUT=48h \
3531
// PKG=./pkg/acceptance \
3632
// TESTS=Rebalance_3To5Small \
37-
// TESTFLAGS='-v -remote -key-name google_compute_engine -cwd terraform -tf.keep-cluster=failed -tf.cockroach-binary=../../cockroach'
33+
// TESTFLAGS='-v -remote -key-name azure -cwd terraform/azure -tf.keep-cluster=failed'
3834
//
3935
// Things to note:
40-
// - You must use an SSH key without a passphrase. It is recommended that you
41-
// create a new key for this purpose named google_compute_engine so that
42-
// gcloud and related tools can use it too. Create the key with:
43-
// ssh-keygen -f ~/.ssh/google_compute_engine
44-
// - Your SSH key (-key-name) for Google Cloud Platform must be in
45-
// ~/.ssh/google_compute_engine
36+
// - You must use an SSH key without a passphrase. This is a Terraform
37+
// requirement.
4638
// - If you want to manually fiddle with a test cluster, start the test with
4739
// `-tf.keep-cluster=failed". After the cluster has been created, press
4840
// Control-C and the cluster will remain up.
4941
// - These tests rely on a specific Terraform config that's specified using the
5042
// -cwd test flag.
5143
// - You *must* set the TESTTIMEOUT high enough for any of these tests to
52-
// finish. To be safe, specify a timeout of at least 24 hours.
53-
// - Your Google Cloud credentials must be accessible by Terraform, as described
54-
// here:
55-
// https://www.terraform.io/docs/providers/google/
44+
// finish. To be really safe, specify a timeout of at least 24 hours.
5645
// - There are various flags that start with `tf.` that control the
5746
// of Terrafarm and allocator tests, respectively. For example, you can add
5847
// "-tf.cockroach-binary" to TESTFLAGS to specify a custom Linux CockroachDB
@@ -64,7 +53,8 @@ package acceptance
6453
//
6554
// Troubleshooting:
6655
// - The minimum recommended version of Terraform is 0.7.2. If you see strange
67-
// Terraform errors, upgrade your install of Terraform.
56+
// Terraform errors, upgrade your install of Terraform. Terraform 0.8.x or
57+
// later might not work because of breaking changes to Terraform.
6858
// - Adding `-tf.keep-cluster=always` to your TESTFLAGS allows the cluster to
6959
// stay around after the test completes.
7060

pkg/acceptance/continuous_load_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
// PKG=./pkg/acceptance \
3939
// TESTTIMEOUT=6h \
4040
// TESTS=ContinuousLoad_BlockWriter \
41-
// TESTFLAGS='-v -remote -key-name google_compute_engine -cwd terraform -nodes 4 -tf.keep-cluster=failed'
41+
// TESTFLAGS='-v -remote -key-name azure -cwd terraform/azure -nodes 4 -tf.keep-cluster=failed'
4242
//
4343
// Load is generated for the duration specified by TESTTIMEOUT, minus some time
4444
// required for the orderly teardown of resources created by the test. Because
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
# Terraform configuration for nightly tests running on Azure.
2+
#
3+
# To perform the required one-time Azure setup:
4+
# 1. Create a resource group for the tests and set ${var.azure_location} to
5+
# its name.
6+
# 2. Create a storage account and set ${var.azure_vhd_storage_account} to its
7+
# name.
8+
# 3. Create a storage container for the previously created storage account and
9+
# set ${var.vhd_storage_container} to its name.
10+
11+
provider "azurerm" {
12+
# There are no Azure credentials here.
13+
#
14+
# So, set the ARM_SUBSCRIPTION_ID, ARM_CLIENT_ID, ARM_CLIENT_SECRET,
15+
# ARM_TENANT_ID environment variables to provide credentials for Azure
16+
# Resource Manager.
17+
#
18+
# See https://www.terraform.io/docs/providers/azurerm to understand the Azure
19+
# permissions needed to run Terraform against it.
20+
}
21+
22+
#
23+
# Networking.
24+
#
25+
26+
resource "azurerm_virtual_network" "cockroach" {
27+
name = "${var.prefix}-vn"
28+
address_space = ["192.168.0.0/16"]
29+
location = "${var.azure_location}"
30+
resource_group_name = "${var.azure_resource_group}"
31+
}
32+
33+
# Firewall rules.
34+
resource "azurerm_network_security_group" "cockroach" {
35+
name = "${var.prefix}-nsg"
36+
location = "${var.azure_location}"
37+
resource_group_name = "${var.azure_resource_group}"
38+
39+
security_rule {
40+
name = "${var.prefix}-cockroach-ssh"
41+
priority = 100
42+
direction = "Inbound"
43+
access = "Allow"
44+
protocol = "Tcp"
45+
source_port_range = "*"
46+
destination_port_range = "22"
47+
source_address_prefix = "*"
48+
destination_address_prefix = "*"
49+
}
50+
51+
security_rule {
52+
name = "${var.prefix}-cockroach-http"
53+
priority = 101
54+
direction = "Inbound"
55+
access = "Allow"
56+
protocol = "Tcp"
57+
source_port_range = "*"
58+
destination_port_range = "8080"
59+
source_address_prefix = "*"
60+
destination_address_prefix = "*"
61+
}
62+
63+
security_rule {
64+
name = "${var.prefix}-cockroach-sql"
65+
priority = 102
66+
direction = "Inbound"
67+
access = "Allow"
68+
protocol = "Tcp"
69+
source_port_range = "*"
70+
destination_port_range = "26257"
71+
source_address_prefix = "*"
72+
destination_address_prefix = "*"
73+
}
74+
75+
# Azure Network Security Groups have a low-priority default deny all rule.
76+
# See:
77+
# https://docs.microsoft.com/en-us/azure/virtual-network/virtual-networks-nsg#default-rules
78+
79+
tags {
80+
environment = "test"
81+
}
82+
}
83+
84+
resource "azurerm_subnet" "cockroach" {
85+
name = "${var.prefix}-subnet"
86+
resource_group_name = "${var.azure_resource_group}"
87+
virtual_network_name = "${azurerm_virtual_network.cockroach.name}"
88+
address_prefix = "192.168.1.0/24"
89+
}
90+
91+
#
92+
# CockroachDB nodes.
93+
#
94+
95+
resource "azurerm_public_ip" "cockroach" {
96+
count = "${var.num_instances}"
97+
name = "${var.prefix}-ip-${count.index + 1}"
98+
location = "${var.azure_location}"
99+
resource_group_name = "${var.azure_resource_group}"
100+
public_ip_address_allocation = "dynamic"
101+
domain_name_label="${var.prefix}-cockroach-${count.index + 1}"
102+
103+
tags {
104+
environment = "test"
105+
}
106+
}
107+
108+
resource "azurerm_network_interface" "cockroach" {
109+
count = "${var.num_instances}"
110+
111+
name = "${var.prefix}-cockroach-nic-${count.index + 1}"
112+
location = "${var.azure_location}"
113+
resource_group_name = "${var.azure_resource_group}"
114+
network_security_group_id = "${azurerm_network_security_group.cockroach.id}"
115+
116+
ip_configuration {
117+
name = "testconfiguration1"
118+
subnet_id = "${azurerm_subnet.cockroach.id}"
119+
private_ip_address_allocation = "dynamic"
120+
public_ip_address_id = "${element(azurerm_public_ip.cockroach.*.id, count.index)}"
121+
}
122+
}
123+
124+
resource "azurerm_virtual_machine" "cockroach" {
125+
count = "${var.num_instances}"
126+
name = "${var.prefix}-cockroach-${count.index + 1}"
127+
location = "${var.azure_location}"
128+
resource_group_name = "${var.azure_resource_group}"
129+
network_interface_ids = ["${element(azurerm_network_interface.cockroach.*.id, count.index)}"]
130+
vm_size = "${var.azure_vm_size}"
131+
delete_os_disk_on_termination = "true"
132+
133+
storage_image_reference {
134+
publisher = "Canonical"
135+
offer = "UbuntuServer"
136+
sku = "16.04.0-LTS"
137+
version = "latest"
138+
}
139+
140+
# Don't recreate this VM when the VHD URI changes, because that may have
141+
# unique identifiers that change every time this config is applied.
142+
lifecycle {
143+
ignore_changes = [ "storage_os_disk" ]
144+
}
145+
146+
storage_os_disk {
147+
name = "disk1"
148+
vhd_uri = "https://${var.azure_vhd_storage_account}.blob.core.windows.net/${var.vhd_storage_container}/${var.prefix}-cockroach-${count.index + 1}.vhd"
149+
create_option = "FromImage"
150+
}
151+
152+
os_profile {
153+
computer_name = "${var.prefix}-cockroach-${count.index + 1}"
154+
admin_username = "ubuntu"
155+
# This password doesn't matter, because password auth is disabled below.
156+
admin_password = "password_auth_disabled"
157+
}
158+
159+
os_profile_linux_config {
160+
disable_password_authentication = true
161+
ssh_keys {
162+
path = "/home/ubuntu/.ssh/authorized_keys"
163+
key_data = "${file("~/.ssh/${var.key_name}.pub")}"
164+
}
165+
}
166+
167+
tags {
168+
environment = "test"
169+
}
170+
}
171+
172+
# Supervisor config for CockroachDB nodes.
173+
data "template_file" "supervisor" {
174+
count = "${var.num_instances}"
175+
template = "${file("../common/supervisor.conf.tpl")}"
176+
depends_on = [ "azurerm_virtual_machine.cockroach" ]
177+
178+
vars {
179+
stores = "${var.stores}"
180+
cockroach_port = "${var.sql_port}"
181+
# The value of the --join flag must be empty for the first node,
182+
# and a running node for all others. We build a list of addresses
183+
# shifted by one (first element is empty), then take the value at index "instance.index".
184+
join_address = "${element(concat(split(",", ""), azurerm_public_ip.cockroach.*.fqdn), count.index)}"
185+
cockroach_flags = "${var.cockroach_flags}"
186+
# If the following changes, (*terrafarm.Farmer).Add() must change too.
187+
cockroach_env = "${var.cockroach_env}"
188+
benchmark_name = "${var.benchmark_name}"
189+
}
190+
}
191+
192+
# Set up CockroachDB nodes.
193+
resource "null_resource" "cockroach-runner" {
194+
count = "${var.num_instances}"
195+
depends_on = [ "azurerm_virtual_machine.cockroach" ]
196+
197+
connection {
198+
user = "ubuntu"
199+
private_key = "${file(format("~/.ssh/%s", var.key_name))}"
200+
host = "${element(azurerm_public_ip.cockroach.*.fqdn, count.index)}"
201+
}
202+
203+
provisioner "file" {
204+
source = "../common/download_binary.sh"
205+
destination = "/home/ubuntu/download_binary.sh"
206+
}
207+
208+
provisioner "file" {
209+
source = "../common/nodectl"
210+
destination = "/home/ubuntu/nodectl"
211+
}
212+
213+
# This writes the filled-in supervisor template. It would be nice if we could
214+
# use rendered templates in the file provisioner.
215+
provisioner "remote-exec" {
216+
inline = <<FILE
217+
echo '${element(data.template_file.supervisor.*.rendered, count.index)}' > supervisor.conf
218+
FILE
219+
}
220+
221+
provisioner "file" {
222+
# If no binary is specified, we'll copy /dev/null (always 0 bytes) to the
223+
# instance. The "remote-exec" block will then overwrite that. There's no
224+
# such thing as conditional file copying in Terraform, so we fake it.
225+
source = "${coalesce(var.cockroach_binary, "/dev/null")}"
226+
destination = "/home/ubuntu/cockroach"
227+
}
228+
229+
# Launch CockroachDB.
230+
provisioner "remote-exec" {
231+
inline = [
232+
# For consistency with other Terraform configs, we create the store in
233+
# /mnt/data0.
234+
"sudo mkdir /mnt/data0",
235+
"sudo chown ubuntu:ubuntu /mnt/data0",
236+
# This sleep is needed to avoid apt-get errors below. It appears that when
237+
# the VM first launches, something is interfering with launches of apt-get.
238+
"sleep 30",
239+
# Install test dependencies. NTP synchronization is especially needed for
240+
# Azure VMs.
241+
"sudo apt-get -qqy update >/dev/null",
242+
"sudo apt-get -qqy install supervisor ntpdate >/dev/null",
243+
"sudo ntpdate -b pool.ntp.org",
244+
"sudo apt-get -qqy install ntp >/dev/null",
245+
"sudo sed -i 's/^#statsdir/statsdir/' /etc/ntp.conf",
246+
"sudo service supervisor stop",
247+
# TODO(cuongdo): Remove this dependency on Google Cloud SDK after we move
248+
# the test data to Azure Storage.
249+
"export CLOUD_SDK_REPO=\"cloud-sdk-$(lsb_release -c -s)\"",
250+
"echo \"deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main\" | sudo tee /etc/apt/sources.list.d/google-cloud-sdk.list",
251+
"curl -sS https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -",
252+
"sudo apt-get -qqy update >/dev/null",
253+
"sudo apt-get -qqy install google-cloud-sdk >/dev/null",
254+
# Install CockroachDB.
255+
"mkdir /mnt/data0/logs",
256+
"ln -sf /mnt/data0/logs logs",
257+
"chmod 755 cockroach nodectl",
258+
"[ $(stat --format=%s cockroach) -ne 0 ] || bash download_binary.sh cockroach/cockroach ${var.cockroach_sha}",
259+
"if [ ! -e supervisor.pid ]; then supervisord -c supervisor.conf; fi",
260+
"supervisorctl -c supervisor.conf start cockroach",
261+
# Install load generators.
262+
"bash download_binary.sh examples-go/block_writer ${var.block_writer_sha}",
263+
"bash download_binary.sh examples-go/photos ${var.photos_sha}",
264+
]
265+
}
266+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Unlike the other cloud providers, this is a list of FQDNs instead of IP
2+
# addresses. This is because of an issue preventing the querying of dynamic
3+
# public IPs:
4+
#
5+
# https://github.com/hashicorp/terraform/issues/6634
6+
output "instances" {
7+
value = "${join(",", azurerm_public_ip.cockroach.*.fqdn)}"
8+
}

0 commit comments

Comments
 (0)