Migrate compute-mig tests
This commit is contained in:
parent
cb13d481d6
commit
df7cf3d278
|
@ -46,7 +46,7 @@ module "nginx-mig" {
|
|||
target_size = 2
|
||||
instance_template = module.nginx-template.template.self_link
|
||||
}
|
||||
# tftest modules=2 resources=2
|
||||
# tftest modules=2 resources=2 inventory=simple.yaml
|
||||
```
|
||||
|
||||
### Multiple versions
|
||||
|
@ -149,7 +149,7 @@ module "nginx-mig" {
|
|||
}
|
||||
}
|
||||
}
|
||||
# tftest modules=2 resources=3
|
||||
# tftest modules=2 resources=3 inventory=health-check.yaml
|
||||
```
|
||||
|
||||
### Autoscaling
|
||||
|
@ -202,7 +202,7 @@ module "nginx-mig" {
|
|||
}
|
||||
}
|
||||
}
|
||||
# tftest modules=2 resources=3
|
||||
# tftest modules=2 resources=3 inventory=autoscaling.yaml
|
||||
```
|
||||
|
||||
### Update policy
|
||||
|
@ -408,7 +408,7 @@ module "nginx-mig" {
|
|||
}
|
||||
}
|
||||
}
|
||||
# tftest modules=2 resources=4
|
||||
# tftest modules=2 resources=4 inventory=stateful.yaml
|
||||
|
||||
```
|
||||
<!-- BEGIN TFDOC -->
|
||||
|
|
|
@ -16,10 +16,9 @@ import pytest
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def resources(plan_summary, plan_runner, version):
|
||||
def resources(plan_summary, version):
|
||||
# convert `version` to a boolean suitable for the `v2` variable
|
||||
v2 = {'v1': 'false', 'v2': 'true'}[version]
|
||||
#_, resources = plan_runner(v2=v2)
|
||||
summary = plan_summary('modules/cloud-function',
|
||||
tf_var_files=['common.tfvars'], v2=v2)
|
||||
return summary
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
# Copyright 2023 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
values:
|
||||
module.nginx-mig.google_compute_autoscaler.default[0]:
|
||||
autoscaling_policy:
|
||||
- cooldown_period: 30
|
||||
cpu_utilization:
|
||||
- predictive_method: NONE
|
||||
target: 0.65
|
||||
load_balancing_utilization: []
|
||||
max_replicas: 3
|
||||
metric: []
|
||||
min_replicas: 1
|
||||
mode: 'ON'
|
||||
scale_in_control: []
|
||||
scaling_schedules: []
|
||||
name: mig-test
|
||||
project: my-project
|
||||
timeouts: null
|
||||
zone: europe-west1-b
|
||||
|
||||
counts:
|
||||
google_compute_autoscaler: 1
|
||||
google_compute_instance_group_manager: 1
|
||||
google_compute_instance_template: 1
|
|
@ -0,0 +1,43 @@
|
|||
# Copyright 2023 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
values:
|
||||
module.nginx-mig.google_compute_health_check.default[0]:
|
||||
check_interval_sec: 5
|
||||
grpc_health_check: []
|
||||
healthy_threshold: 2
|
||||
http2_health_check: []
|
||||
http_health_check:
|
||||
- host: null
|
||||
port: 80
|
||||
port_name: null
|
||||
port_specification: null
|
||||
proxy_header: NONE
|
||||
request_path: /
|
||||
response: null
|
||||
https_health_check: []
|
||||
log_config:
|
||||
- enable: true
|
||||
name: mig-test
|
||||
project: my-project
|
||||
ssl_health_check: []
|
||||
tcp_health_check: []
|
||||
timeout_sec: 5
|
||||
timeouts: null
|
||||
unhealthy_threshold: 2
|
||||
|
||||
counts:
|
||||
google_compute_health_check: 1
|
||||
google_compute_instance_group_manager: 1
|
||||
google_compute_instance_template: 1
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2022 Google LLC
|
||||
# Copyright 2023 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
@ -11,3 +11,15 @@
|
|||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
values:
|
||||
module.nginx-mig.google_compute_instance_group_manager.default[0]:
|
||||
base_instance_name: mig-test
|
||||
name: mig-test
|
||||
project: my-project
|
||||
target_size: 2
|
||||
zone: europe-west1-b
|
||||
|
||||
counts:
|
||||
google_compute_instance_group_manager: 1
|
||||
google_compute_instance_template: 1
|
|
@ -0,0 +1,37 @@
|
|||
# Copyright 2023 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
values:
|
||||
module.nginx-mig.google_compute_per_instance_config.default["instance-1"]:
|
||||
minimal_action: NONE
|
||||
most_disruptive_allowed_action: REPLACE
|
||||
name: instance-1
|
||||
preserved_state:
|
||||
- disk:
|
||||
- delete_rule: NEVER
|
||||
device_name: persistent-disk-1
|
||||
mode: READ_WRITE
|
||||
source: test-disk
|
||||
metadata:
|
||||
foo: bar
|
||||
project: my-project
|
||||
remove_instance_state_on_destroy: false
|
||||
timeouts: null
|
||||
zone: europe-west1-b
|
||||
|
||||
counts:
|
||||
google_compute_autoscaler: 1
|
||||
google_compute_instance_group_manager: 1
|
||||
google_compute_instance_template: 1
|
||||
google_compute_per_instance_config: 1
|
|
@ -1,41 +0,0 @@
|
|||
/**
|
||||
* Copyright 2022 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
# Used in stateful disk test
|
||||
resource "google_compute_disk" "default" {
|
||||
name = "test-disk"
|
||||
type = "pd-ssd"
|
||||
zone = "europe-west1-c"
|
||||
image = "debian-9-stretch-v20200805"
|
||||
physical_block_size_bytes = 4096
|
||||
}
|
||||
|
||||
module "test" {
|
||||
source = "../../../../modules/compute-mig"
|
||||
project_id = "my-project"
|
||||
name = "test-mig"
|
||||
target_size = 2
|
||||
default_version_name = "foo"
|
||||
instance_template = "foo-template"
|
||||
location = var.location
|
||||
autoscaler_config = var.autoscaler_config
|
||||
health_check_config = var.health_check_config
|
||||
named_ports = var.named_ports
|
||||
stateful_config = var.stateful_config
|
||||
stateful_disks = var.stateful_disks
|
||||
update_policy = var.update_policy
|
||||
versions = var.versions
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
/**
|
||||
* Copyright 2022 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
variable "all_instances_config" {
|
||||
type = any
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "auto_healing_policies" {
|
||||
type = any
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "autoscaler_config" {
|
||||
type = any
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "default_version_name" {
|
||||
type = any
|
||||
default = "default"
|
||||
}
|
||||
|
||||
variable "description" {
|
||||
type = any
|
||||
default = "Terraform managed."
|
||||
}
|
||||
|
||||
variable "distribution_policy" {
|
||||
type = any
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "health_check_config" {
|
||||
type = any
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "location" {
|
||||
type = any
|
||||
default = "europe-west1-b"
|
||||
}
|
||||
|
||||
variable "named_ports" {
|
||||
type = any
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "stateful_disks" {
|
||||
type = any
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "stateful_config" {
|
||||
type = any
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "target_pools" {
|
||||
type = any
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "target_size" {
|
||||
type = any
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "update_policy" {
|
||||
type = any
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "versions" {
|
||||
type = any
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "wait_for_instances" {
|
||||
type = any
|
||||
default = null
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
# Copyright 2022 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
def test_defaults(plan_runner):
|
||||
"Test variable defaults."
|
||||
_, resources = plan_runner()
|
||||
assert len(resources) == 1
|
||||
print(resources[0]['type'])
|
||||
mig = resources[0]
|
||||
assert mig['type'] == 'google_compute_instance_group_manager'
|
||||
assert mig['values']['target_size'] == 2
|
||||
assert mig['values']['zone']
|
||||
_, resources = plan_runner(location='"europe-west1"')
|
||||
assert len(resources) == 1
|
||||
mig = resources[0]
|
||||
assert mig['type'] == 'google_compute_region_instance_group_manager'
|
||||
assert mig['values']['target_size'] == 2
|
||||
assert mig['values']['region']
|
||||
|
||||
|
||||
def test_health_check(plan_runner):
|
||||
"Test health check resource."
|
||||
health_check_config = '''{
|
||||
enable_logging = true
|
||||
tcp = {
|
||||
port = 80
|
||||
}
|
||||
}'''
|
||||
_, resources = plan_runner(health_check_config=health_check_config)
|
||||
assert len(resources) == 2
|
||||
assert any(r['type'] == 'google_compute_health_check' for r in resources)
|
||||
|
||||
|
||||
def test_autoscaler(plan_runner):
|
||||
"Test autoscaler resource."
|
||||
autoscaler_config = '''{
|
||||
colldown_period = 60
|
||||
max_replicas = 3
|
||||
min_replicas = 1
|
||||
scaling_signals = {
|
||||
cpu_utilization = {
|
||||
target = 65
|
||||
}
|
||||
}
|
||||
}'''
|
||||
_, resources = plan_runner(autoscaler_config=autoscaler_config)
|
||||
assert len(resources) == 2
|
||||
autoscaler = resources[0]
|
||||
assert autoscaler['type'] == 'google_compute_autoscaler'
|
||||
assert autoscaler['values']['autoscaling_policy'] == [{
|
||||
'cooldown_period': 60,
|
||||
'cpu_utilization': [{
|
||||
'predictive_method': 'NONE',
|
||||
'target': 65
|
||||
}],
|
||||
'load_balancing_utilization': [],
|
||||
'max_replicas': 3,
|
||||
'metric': [],
|
||||
'min_replicas': 1,
|
||||
'mode': 'ON',
|
||||
'scale_in_control': [],
|
||||
'scaling_schedules': [],
|
||||
}]
|
||||
_, resources = plan_runner(autoscaler_config=autoscaler_config,
|
||||
location='"europe-west1"')
|
||||
assert len(resources) == 2
|
||||
autoscaler = resources[0]
|
||||
assert autoscaler['type'] == 'google_compute_region_autoscaler'
|
||||
|
||||
|
||||
def test_stateful_mig(plan_runner):
|
||||
"Test stateful instances - mig."
|
||||
|
||||
stateful_disks = '''{
|
||||
persistent-disk-1 = false
|
||||
}'''
|
||||
_, resources = plan_runner(stateful_disks=stateful_disks)
|
||||
assert len(resources) == 1
|
||||
statefuldisk = resources[0]
|
||||
assert statefuldisk['type'] == 'google_compute_instance_group_manager'
|
||||
assert statefuldisk['values']['stateful_disk'] == [{
|
||||
'device_name': 'persistent-disk-1',
|
||||
'delete_rule': 'NEVER',
|
||||
}]
|
||||
|
||||
|
||||
def test_stateful_instance(plan_runner):
|
||||
"Test stateful instances - instance."
|
||||
stateful_config = '''{
|
||||
instance-1 = {
|
||||
most_disruptive_action = "REPLACE",
|
||||
preserved_state = {
|
||||
disks = {
|
||||
persistent-disk-1 = {
|
||||
source = "test-disk"
|
||||
}
|
||||
}
|
||||
metadata = { foo = "bar" }
|
||||
}
|
||||
}
|
||||
}'''
|
||||
_, resources = plan_runner(stateful_config=stateful_config)
|
||||
assert len(resources) == 2
|
||||
instanceconfig = resources[0]
|
||||
assert instanceconfig['type'] == 'google_compute_instance_group_manager'
|
||||
instanceconfig = resources[1]
|
||||
assert instanceconfig['type'] == 'google_compute_per_instance_config'
|
||||
|
||||
assert instanceconfig['values']['preserved_state'] == [{
|
||||
'disk': [{
|
||||
'device_name': 'persistent-disk-1',
|
||||
'delete_rule': 'NEVER',
|
||||
'source': 'test-disk',
|
||||
'mode': 'READ_WRITE',
|
||||
}],
|
||||
'metadata': {
|
||||
'foo': 'bar'
|
||||
}
|
||||
}]
|
||||
assert instanceconfig['values']['minimal_action'] == 'NONE'
|
||||
assert instanceconfig['values']['most_disruptive_allowed_action'] == 'REPLACE'
|
||||
assert instanceconfig['values']['remove_instance_state_on_destroy'] == False
|
Loading…
Reference in New Issue