2022-01-01 06:52:31 -08:00
|
|
|
# Copyright 2022 Google LLC
|
2020-07-10 07:56:28 -07:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2021-10-04 01:46:44 -07:00
|
|
|
def test_address(plan_runner):
|
|
|
|
nics = '''[{
|
2020-07-10 07:56:28 -07:00
|
|
|
network = "https://www.googleapis.com/compute/v1/projects/my-project/global/networks/default",
|
|
|
|
subnetwork = "https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west1/subnetworks/default-default",
|
|
|
|
nat = false,
|
2021-10-04 01:46:44 -07:00
|
|
|
addresses = {external=null, internal="10.0.0.2"}
|
2020-07-10 07:56:28 -07:00
|
|
|
}]
|
|
|
|
'''
|
2022-01-10 14:29:15 -08:00
|
|
|
_, resources = plan_runner(network_interfaces=nics)
|
2021-10-04 01:46:44 -07:00
|
|
|
assert len(resources) == 1
|
|
|
|
n = resources[0]['values']['network_interface'][0]
|
|
|
|
assert n['network_ip'] == "10.0.0.2"
|
|
|
|
assert n['access_config'] == []
|
2020-07-10 07:56:28 -07:00
|
|
|
|
|
|
|
|
2021-10-04 01:46:44 -07:00
|
|
|
def test_nat_address(plan_runner):
|
|
|
|
nics = '''[{
|
2020-07-10 07:56:28 -07:00
|
|
|
network = "https://www.googleapis.com/compute/v1/projects/my-project/global/networks/default",
|
|
|
|
subnetwork = "https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west1/subnetworks/default-default",
|
|
|
|
nat = true,
|
2021-10-04 01:46:44 -07:00
|
|
|
addresses = {external="8.8.8.8", internal=null}
|
2020-07-10 07:56:28 -07:00
|
|
|
}]
|
|
|
|
'''
|
2022-01-10 14:29:15 -08:00
|
|
|
_, resources = plan_runner(network_interfaces=nics)
|
2021-10-04 01:46:44 -07:00
|
|
|
assert len(resources) == 1
|
|
|
|
n = resources[0]['values']['network_interface'][0]
|
|
|
|
assert 'network_ip' not in n
|
|
|
|
assert n['access_config'][0]['nat_ip'] == '8.8.8.8'
|