EC2: Add EnableNetworkAddressUsageMetrics to VPC attribute (#5618)

This commit is contained in:
Marshall Mamiya 2022-10-31 15:52:28 -07:00 committed by GitHub
parent ba1919cc6f
commit f185999602
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 2 deletions

View File

@ -137,8 +137,11 @@ class VPCs(EC2BaseResponse):
def modify_vpc_attribute(self): def modify_vpc_attribute(self):
vpc_id = self._get_param("VpcId") vpc_id = self._get_param("VpcId")
for attribute in (
for attribute in ("EnableDnsSupport", "EnableDnsHostnames"): "EnableDnsSupport",
"EnableDnsHostnames",
"EnableNetworkAddressUsageMetrics",
):
if self.querystring.get("%s.Value" % attribute): if self.querystring.get("%s.Value" % attribute):
attr_name = camelcase_to_underscores(attribute) attr_name = camelcase_to_underscores(attribute)
attr_value = self.querystring.get("%s.Value" % attribute)[0] attr_value = self.querystring.get("%s.Value" % attribute)[0]

View File

@ -5,6 +5,7 @@ import boto3
import sure # noqa # pylint: disable=unused-import import sure # noqa # pylint: disable=unused-import
import random import random
import sys
from moto import mock_ec2, settings from moto import mock_ec2, settings
from unittest import SkipTest from unittest import SkipTest
@ -360,6 +361,10 @@ def test_vpc_get_by_tag_value_subset():
@mock_ec2 @mock_ec2
def test_default_vpc(): def test_default_vpc():
if sys.version_info < (3, 7):
raise SkipTest(
"Cannot test this in Py3.6; outdated botocore dependencies do not have all regions"
)
ec2 = boto3.resource("ec2", region_name="us-west-1") ec2 = boto3.resource("ec2", region_name="us-west-1")
# Create the default VPC # Create the default VPC
@ -378,9 +383,19 @@ def test_default_vpc():
attr = response.get("EnableDnsHostnames") attr = response.get("EnableDnsHostnames")
attr.get("Value").should.equal(True) attr.get("Value").should.equal(True)
response = default_vpc.describe_attribute(
Attribute="enableNetworkAddressUsageMetrics"
)
attr = response.get("EnableNetworkAddressUsageMetrics")
attr.get("Value").should.equal(False)
@mock_ec2 @mock_ec2
def test_non_default_vpc(): def test_non_default_vpc():
if sys.version_info < (3, 7):
raise SkipTest(
"Cannot test this in Py3.6; outdated botocore dependencies do not have all regions"
)
ec2 = boto3.resource("ec2", region_name="us-west-1") ec2 = boto3.resource("ec2", region_name="us-west-1")
# Create the default VPC - this already exists when backend instantiated! # Create the default VPC - this already exists when backend instantiated!
@ -403,6 +418,10 @@ def test_non_default_vpc():
attr = response.get("EnableDnsHostnames") attr = response.get("EnableDnsHostnames")
attr.get("Value").should.equal(False) attr.get("Value").should.equal(False)
response = vpc.describe_attribute(Attribute="enableNetworkAddressUsageMetrics")
attr = response.get("EnableNetworkAddressUsageMetrics")
attr.get("Value").should.equal(False)
# Check Primary CIDR Block Associations # Check Primary CIDR Block Associations
cidr_block_association_set = next(iter(vpc.cidr_block_association_set), None) cidr_block_association_set = next(iter(vpc.cidr_block_association_set), None)
cidr_block_association_set["CidrBlockState"]["State"].should.equal("associated") cidr_block_association_set["CidrBlockState"]["State"].should.equal("associated")
@ -491,6 +510,30 @@ def test_vpc_modify_enable_dns_hostnames():
attr.get("Value").should.be.ok attr.get("Value").should.be.ok
@mock_ec2
def test_vpc_modify_enable_network_address_usage_metrics():
if sys.version_info < (3, 7):
raise SkipTest(
"Cannot test this in Py3.6; outdated botocore dependencies do not have all regions"
)
ec2 = boto3.resource("ec2", region_name="us-west-1")
# Create the default VPC
ec2.create_vpc(CidrBlock="172.31.0.0/16")
vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")
# Test default values for VPC attributes
response = vpc.describe_attribute(Attribute="enableNetworkAddressUsageMetrics")
attr = response.get("EnableNetworkAddressUsageMetrics")
attr.get("Value").shouldnt.be.ok
vpc.modify_attribute(EnableNetworkAddressUsageMetrics={"Value": True})
response = vpc.describe_attribute(Attribute="enableNetworkAddressUsageMetrics")
attr = response.get("EnableNetworkAddressUsageMetrics")
attr.get("Value").should.equal(True)
@mock_ec2 @mock_ec2
def test_vpc_associate_dhcp_options(): def test_vpc_associate_dhcp_options():
ec2 = boto3.resource("ec2", region_name="us-west-1") ec2 = boto3.resource("ec2", region_name="us-west-1")