moto/tests/test_elb/test_elb_availabilityzones.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.9 KiB
Python
Raw Permalink Normal View History

2022-03-21 20:55:19 +00:00
import boto3
2024-01-07 12:03:33 +00:00
from moto import mock_aws
2022-03-21 20:55:19 +00:00
2024-01-07 12:03:33 +00:00
@mock_aws
2022-03-21 20:55:19 +00:00
def test_enable_and_disable_availability_zones():
client = boto3.client("elb", region_name="eu-north-1")
ec2 = boto3.resource("ec2", region_name="eu-north-1")
security_group = ec2.create_security_group(GroupName="sg01", Description="desc")
client.create_load_balancer(
LoadBalancerName="my-lb",
Listeners=[
{"Protocol": "tcp", "LoadBalancerPort": 80, "InstancePort": 8080},
{"Protocol": "http", "LoadBalancerPort": 81, "InstancePort": 9000},
],
AvailabilityZones=["eu-north-1a", "eu-north-1b"],
Scheme="internal",
SecurityGroups=[security_group.id],
)
describe = client.describe_load_balancers(LoadBalancerNames=["my-lb"])[
"LoadBalancerDescriptions"
][0]
assert describe["AvailabilityZones"] == ["eu-north-1a", "eu-north-1b"]
2022-03-21 20:55:19 +00:00
# enable more az's
resp = client.enable_availability_zones_for_load_balancer(
LoadBalancerName="my-lb", AvailabilityZones=["eu-north-1c", "eu-north-1d"]
)
assert resp["AvailabilityZones"] == [
"eu-north-1a",
"eu-north-1b",
"eu-north-1c",
"eu-north-1d",
]
2022-03-21 20:55:19 +00:00
describe = client.describe_load_balancers(LoadBalancerNames=["my-lb"])[
"LoadBalancerDescriptions"
][0]
assert describe["AvailabilityZones"] == [
"eu-north-1a",
"eu-north-1b",
"eu-north-1c",
"eu-north-1d",
]
2022-03-21 20:55:19 +00:00
# disable some az's
resp = client.disable_availability_zones_for_load_balancer(
LoadBalancerName="my-lb", AvailabilityZones=["eu-north-1b", "eu-north-1c"]
)
assert resp["AvailabilityZones"] == ["eu-north-1a", "eu-north-1d"]
2022-03-21 20:55:19 +00:00
describe = client.describe_load_balancers(LoadBalancerNames=["my-lb"])[
"LoadBalancerDescriptions"
][0]
assert describe["AvailabilityZones"] == ["eu-north-1a", "eu-north-1d"]