moto/tests/test_ec2/test_dhcp_options.py

738 lines
26 KiB
Python
Raw Normal View History

from __future__ import unicode_literals
2019-10-31 15:44:26 +00:00
import pytest
import boto3
2013-02-22 04:13:01 +00:00
import boto
2014-04-15 23:02:26 +00:00
from boto.exception import EC2ResponseError
2021-09-25 11:13:07 +00:00
from botocore.exceptions import ClientError
2014-04-15 23:02:26 +00:00
2013-08-03 21:21:25 +00:00
import sure # noqa
2013-02-22 04:13:01 +00:00
2021-09-25 11:13:07 +00:00
from moto import mock_ec2, mock_ec2_deprecated, settings
from unittest import SkipTest
2013-02-22 04:13:01 +00:00
2019-10-31 15:44:26 +00:00
SAMPLE_DOMAIN_NAME = "example.com"
SAMPLE_NAME_SERVERS = ["10.0.0.6", "10.0.0.7"]
2014-04-15 23:02:26 +00:00
2021-09-25 11:13:07 +00:00
# Has boto3 equivalent
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
2014-04-15 23:02:26 +00:00
def test_dhcp_options_associate():
Merge LocalStack changes into upstream moto (#4082) * fix OPTIONS requests on non-existing API GW integrations * add cloudformation models for API Gateway deployments * bump version * add backdoor to return CloudWatch metrics * Updating implementation coverage * Updating implementation coverage * add cloudformation models for API Gateway deployments * Updating implementation coverage * Updating implementation coverage * Implemented get-caller-identity returning real data depending on the access key used. * bump version * minor fixes * fix Number data_type for SQS message attribute * fix handling of encoding errors * bump version * make CF stack queryable before starting to initialize its resources * bump version * fix integration_method for API GW method integrations * fix undefined status in CF FakeStack * Fix apigateway issues with terraform v0.12.21 * resource_methods -> add handle for "DELETE" method * integrations -> fix issue that "httpMethod" wasn't included in body request (this value was set as the value from refer method resource) * bump version * Fix setting http method for API gateway integrations (#6) * bump version * remove duplicate methods * add storage class to S3 Key when completing multipart upload (#7) * fix SQS performance issues; bump version * add pagination to SecretsManager list-secrets (#9) * fix default parameter groups in RDS * fix adding S3 metadata headers with names containing dots (#13) * Updating implementation coverage * Updating implementation coverage * add cloudformation models for API Gateway deployments * Updating implementation coverage * Updating implementation coverage * Implemented get-caller-identity returning real data depending on the access key used. * make CF stack queryable before starting to initialize its resources * bump version * remove duplicate methods * fix adding S3 metadata headers with names containing dots (#13) * Update amis.json to support EKS AMI mocks (#15) * fix PascalCase for boolean value in ListMultipartUploads response (#17); fix _get_multi_param to parse nested list/dict query params * determine non-zero container exit code in Batch API * support filtering by dimensions in CW get_metric_statistics * fix storing attributes for ELBv2 Route entities; API GW refactorings for TF tests * add missing fields for API GW resources * fix error messages for Route53 (TF-compat) * various fixes for IAM resources (tf-compat) * minor fixes for API GW models (tf-compat) * minor fixes for API GW responses (tf-compat) * add s3 exception for bucket notification filter rule validation * change the way RESTErrors generate the response body and content-type header * fix lint errors and disable "black" syntax enforcement * remove return type hint in RESTError.get_body * add RESTError XML template for IAM exceptions * add support for API GW minimumCompressionSize * fix casing getting PrivateDnsEnabled API GW attribute * minor fixes for error responses * fix escaping special chars for IAM role descriptions (tf-compat) * minor fixes and tagging support for API GW and ELB v2 (tf-compat) * Merge branch 'master' into localstack * add "AlarmRule" attribute to enable support for composite CloudWatch metrics * fix recursive parsing of complex/nested query params * bump version * add API to delete S3 website configurations (#18) * use dict copy to allow parallelism and avoid concurrent modification exceptions in S3 * fix precondition check for etags in S3 (#19) * minor fix for user filtering in Cognito * fix API Gateway error response; avoid returning empty response templates (tf-compat) * support tags and tracingEnabled attribute for API GW stages * fix boolean value in S3 encryption response (#20) * fix connection arn structure * fix api destination arn structure * black format * release 2.0.3.37 * fix s3 exception tests see botocore/parsers.py:1002 where RequestId is removed from parsed * remove python 2 from build action * add test failure annotations in build action * fix events test arn comparisons * fix s3 encryption response test * return default value "0" if EC2 availableIpAddressCount is empty * fix extracting SecurityGroupIds for EC2 VPC endpoints * support deleting/updating API Gateway DomainNames * fix(events): Return empty string instead of null when no pattern is specified in EventPattern (tf-compat) (#22) * fix logic and revert CF changes to get tests running again (#21) * add support for EC2 customer gateway API (#25) * add support for EC2 Transit Gateway APIs (#24) * feat(logs): add `kmsKeyId` into `LogGroup` entity (#23) * minor change in ELBv2 logic to fix tests * feat(events): add APIs to describe and delete CloudWatch Events connections (#26) * add support for EC2 transit gateway route tables (#27) * pass transit gateway route table ID in Describe API, minor refactoring (#29) * add support for EC2 Transit Gateway Routes (#28) * fix region on ACM certificate import (#31) * add support for EC2 transit gateway attachments (#30) * add support for EC2 Transit Gateway VPN attachments (#32) * fix account ID for logs API * add support for DeleteOrganization API * feat(events): store raw filter representation for CloudWatch events patterns (tf-compat) (#36) * feat(events): add support to describe/update/delete CloudWatch API destinations (#35) * add Cognito UpdateIdentityPool, CW Logs PutResourcePolicy * feat(events): add support for tags in EventBus API (#38) * fix parameter validation for Batch compute environments (tf-compat) * revert merge conflicts in IMPLEMENTATION_COVERAGE.md * format code using black * restore original README; re-enable and fix CloudFormation tests * restore tests and old logic for CF stack parameters from SSM * parameterize RequestId/RequestID in response messages and revert related test changes * undo LocalStack-specific adaptations * minor fix * Update CodeCov config to reflect removal of Py2 * undo change related to CW metric filtering; add additional test for CW metric statistics with dimensions * Terraform - Extend whitelist of running tests Co-authored-by: acsbendi <acsbendi28@gmail.com> Co-authored-by: Phan Duong <duongpv@outlook.com> Co-authored-by: Thomas Rausch <thomas@thrau.at> Co-authored-by: Macwan Nevil <macnev2013@gmail.com> Co-authored-by: Dominik Schubert <dominik.schubert91@gmail.com> Co-authored-by: Gonzalo Saad <saad.gonzalo.ale@gmail.com> Co-authored-by: Mohit Alonja <monty16597@users.noreply.github.com> Co-authored-by: Miguel Gagliardo <migag9@gmail.com> Co-authored-by: Bert Blommers <info@bertblommers.nl>
2021-07-26 14:21:17 +00:00
"""associate dhcp option"""
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
2014-04-15 23:02:26 +00:00
vpc = conn.create_vpc("10.0.0.0/16")
rval = conn.associate_dhcp_options(dhcp_options.id, vpc.id)
rval.should.be.equal(True)
2021-09-25 11:13:07 +00:00
@mock_ec2
def test_dhcp_options_associate_boto3():
""" associate dhcp option """
ec2 = boto3.resource("ec2", region_name="us-west-1")
client = boto3.client("ec2", region_name="us-west-1")
dhcp_options = ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": [SAMPLE_DOMAIN_NAME]},
{"Key": "domain-name-servers", "Values": SAMPLE_NAME_SERVERS},
]
)
vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")
client.associate_dhcp_options(DhcpOptionsId=dhcp_options.id, VpcId=vpc.id)
#
vpc.reload()
vpc.dhcp_options_id.should.equal(dhcp_options.id)
# Has boto3 equivalent
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
2014-04-15 23:02:26 +00:00
def test_dhcp_options_associate_invalid_dhcp_id():
Merge LocalStack changes into upstream moto (#4082) * fix OPTIONS requests on non-existing API GW integrations * add cloudformation models for API Gateway deployments * bump version * add backdoor to return CloudWatch metrics * Updating implementation coverage * Updating implementation coverage * add cloudformation models for API Gateway deployments * Updating implementation coverage * Updating implementation coverage * Implemented get-caller-identity returning real data depending on the access key used. * bump version * minor fixes * fix Number data_type for SQS message attribute * fix handling of encoding errors * bump version * make CF stack queryable before starting to initialize its resources * bump version * fix integration_method for API GW method integrations * fix undefined status in CF FakeStack * Fix apigateway issues with terraform v0.12.21 * resource_methods -> add handle for "DELETE" method * integrations -> fix issue that "httpMethod" wasn't included in body request (this value was set as the value from refer method resource) * bump version * Fix setting http method for API gateway integrations (#6) * bump version * remove duplicate methods * add storage class to S3 Key when completing multipart upload (#7) * fix SQS performance issues; bump version * add pagination to SecretsManager list-secrets (#9) * fix default parameter groups in RDS * fix adding S3 metadata headers with names containing dots (#13) * Updating implementation coverage * Updating implementation coverage * add cloudformation models for API Gateway deployments * Updating implementation coverage * Updating implementation coverage * Implemented get-caller-identity returning real data depending on the access key used. * make CF stack queryable before starting to initialize its resources * bump version * remove duplicate methods * fix adding S3 metadata headers with names containing dots (#13) * Update amis.json to support EKS AMI mocks (#15) * fix PascalCase for boolean value in ListMultipartUploads response (#17); fix _get_multi_param to parse nested list/dict query params * determine non-zero container exit code in Batch API * support filtering by dimensions in CW get_metric_statistics * fix storing attributes for ELBv2 Route entities; API GW refactorings for TF tests * add missing fields for API GW resources * fix error messages for Route53 (TF-compat) * various fixes for IAM resources (tf-compat) * minor fixes for API GW models (tf-compat) * minor fixes for API GW responses (tf-compat) * add s3 exception for bucket notification filter rule validation * change the way RESTErrors generate the response body and content-type header * fix lint errors and disable "black" syntax enforcement * remove return type hint in RESTError.get_body * add RESTError XML template for IAM exceptions * add support for API GW minimumCompressionSize * fix casing getting PrivateDnsEnabled API GW attribute * minor fixes for error responses * fix escaping special chars for IAM role descriptions (tf-compat) * minor fixes and tagging support for API GW and ELB v2 (tf-compat) * Merge branch 'master' into localstack * add "AlarmRule" attribute to enable support for composite CloudWatch metrics * fix recursive parsing of complex/nested query params * bump version * add API to delete S3 website configurations (#18) * use dict copy to allow parallelism and avoid concurrent modification exceptions in S3 * fix precondition check for etags in S3 (#19) * minor fix for user filtering in Cognito * fix API Gateway error response; avoid returning empty response templates (tf-compat) * support tags and tracingEnabled attribute for API GW stages * fix boolean value in S3 encryption response (#20) * fix connection arn structure * fix api destination arn structure * black format * release 2.0.3.37 * fix s3 exception tests see botocore/parsers.py:1002 where RequestId is removed from parsed * remove python 2 from build action * add test failure annotations in build action * fix events test arn comparisons * fix s3 encryption response test * return default value "0" if EC2 availableIpAddressCount is empty * fix extracting SecurityGroupIds for EC2 VPC endpoints * support deleting/updating API Gateway DomainNames * fix(events): Return empty string instead of null when no pattern is specified in EventPattern (tf-compat) (#22) * fix logic and revert CF changes to get tests running again (#21) * add support for EC2 customer gateway API (#25) * add support for EC2 Transit Gateway APIs (#24) * feat(logs): add `kmsKeyId` into `LogGroup` entity (#23) * minor change in ELBv2 logic to fix tests * feat(events): add APIs to describe and delete CloudWatch Events connections (#26) * add support for EC2 transit gateway route tables (#27) * pass transit gateway route table ID in Describe API, minor refactoring (#29) * add support for EC2 Transit Gateway Routes (#28) * fix region on ACM certificate import (#31) * add support for EC2 transit gateway attachments (#30) * add support for EC2 Transit Gateway VPN attachments (#32) * fix account ID for logs API * add support for DeleteOrganization API * feat(events): store raw filter representation for CloudWatch events patterns (tf-compat) (#36) * feat(events): add support to describe/update/delete CloudWatch API destinations (#35) * add Cognito UpdateIdentityPool, CW Logs PutResourcePolicy * feat(events): add support for tags in EventBus API (#38) * fix parameter validation for Batch compute environments (tf-compat) * revert merge conflicts in IMPLEMENTATION_COVERAGE.md * format code using black * restore original README; re-enable and fix CloudFormation tests * restore tests and old logic for CF stack parameters from SSM * parameterize RequestId/RequestID in response messages and revert related test changes * undo LocalStack-specific adaptations * minor fix * Update CodeCov config to reflect removal of Py2 * undo change related to CW metric filtering; add additional test for CW metric statistics with dimensions * Terraform - Extend whitelist of running tests Co-authored-by: acsbendi <acsbendi28@gmail.com> Co-authored-by: Phan Duong <duongpv@outlook.com> Co-authored-by: Thomas Rausch <thomas@thrau.at> Co-authored-by: Macwan Nevil <macnev2013@gmail.com> Co-authored-by: Dominik Schubert <dominik.schubert91@gmail.com> Co-authored-by: Gonzalo Saad <saad.gonzalo.ale@gmail.com> Co-authored-by: Mohit Alonja <monty16597@users.noreply.github.com> Co-authored-by: Miguel Gagliardo <migag9@gmail.com> Co-authored-by: Bert Blommers <info@bertblommers.nl>
2021-07-26 14:21:17 +00:00
"""associate dhcp option bad dhcp options id"""
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
2014-04-15 23:02:26 +00:00
vpc = conn.create_vpc("10.0.0.0/16")
with pytest.raises(EC2ResponseError) as cm:
conn.associate_dhcp_options("foo", vpc.id)
2020-10-06 06:04:09 +00:00
cm.value.code.should.equal("InvalidDhcpOptionID.NotFound")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
2014-04-15 23:02:26 +00:00
2021-09-25 11:13:07 +00:00
@mock_ec2
def test_dhcp_options_associate_invalid_dhcp_id_boto3():
""" associate dhcp option bad dhcp options id """
ec2 = boto3.resource("ec2", region_name="us-west-1")
client = boto3.client("ec2", region_name="us-west-1")
vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")
with pytest.raises(ClientError) as ex:
client.associate_dhcp_options(DhcpOptionsId="foo", VpcId=vpc.id)
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
ex.value.response["ResponseMetadata"].should.have.key("RequestId")
ex.value.response["Error"]["Code"].should.equal("InvalidDhcpOptionID.NotFound")
# Has boto3 equivalent
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
2014-04-15 23:02:26 +00:00
def test_dhcp_options_associate_invalid_vpc_id():
Merge LocalStack changes into upstream moto (#4082) * fix OPTIONS requests on non-existing API GW integrations * add cloudformation models for API Gateway deployments * bump version * add backdoor to return CloudWatch metrics * Updating implementation coverage * Updating implementation coverage * add cloudformation models for API Gateway deployments * Updating implementation coverage * Updating implementation coverage * Implemented get-caller-identity returning real data depending on the access key used. * bump version * minor fixes * fix Number data_type for SQS message attribute * fix handling of encoding errors * bump version * make CF stack queryable before starting to initialize its resources * bump version * fix integration_method for API GW method integrations * fix undefined status in CF FakeStack * Fix apigateway issues with terraform v0.12.21 * resource_methods -> add handle for "DELETE" method * integrations -> fix issue that "httpMethod" wasn't included in body request (this value was set as the value from refer method resource) * bump version * Fix setting http method for API gateway integrations (#6) * bump version * remove duplicate methods * add storage class to S3 Key when completing multipart upload (#7) * fix SQS performance issues; bump version * add pagination to SecretsManager list-secrets (#9) * fix default parameter groups in RDS * fix adding S3 metadata headers with names containing dots (#13) * Updating implementation coverage * Updating implementation coverage * add cloudformation models for API Gateway deployments * Updating implementation coverage * Updating implementation coverage * Implemented get-caller-identity returning real data depending on the access key used. * make CF stack queryable before starting to initialize its resources * bump version * remove duplicate methods * fix adding S3 metadata headers with names containing dots (#13) * Update amis.json to support EKS AMI mocks (#15) * fix PascalCase for boolean value in ListMultipartUploads response (#17); fix _get_multi_param to parse nested list/dict query params * determine non-zero container exit code in Batch API * support filtering by dimensions in CW get_metric_statistics * fix storing attributes for ELBv2 Route entities; API GW refactorings for TF tests * add missing fields for API GW resources * fix error messages for Route53 (TF-compat) * various fixes for IAM resources (tf-compat) * minor fixes for API GW models (tf-compat) * minor fixes for API GW responses (tf-compat) * add s3 exception for bucket notification filter rule validation * change the way RESTErrors generate the response body and content-type header * fix lint errors and disable "black" syntax enforcement * remove return type hint in RESTError.get_body * add RESTError XML template for IAM exceptions * add support for API GW minimumCompressionSize * fix casing getting PrivateDnsEnabled API GW attribute * minor fixes for error responses * fix escaping special chars for IAM role descriptions (tf-compat) * minor fixes and tagging support for API GW and ELB v2 (tf-compat) * Merge branch 'master' into localstack * add "AlarmRule" attribute to enable support for composite CloudWatch metrics * fix recursive parsing of complex/nested query params * bump version * add API to delete S3 website configurations (#18) * use dict copy to allow parallelism and avoid concurrent modification exceptions in S3 * fix precondition check for etags in S3 (#19) * minor fix for user filtering in Cognito * fix API Gateway error response; avoid returning empty response templates (tf-compat) * support tags and tracingEnabled attribute for API GW stages * fix boolean value in S3 encryption response (#20) * fix connection arn structure * fix api destination arn structure * black format * release 2.0.3.37 * fix s3 exception tests see botocore/parsers.py:1002 where RequestId is removed from parsed * remove python 2 from build action * add test failure annotations in build action * fix events test arn comparisons * fix s3 encryption response test * return default value "0" if EC2 availableIpAddressCount is empty * fix extracting SecurityGroupIds for EC2 VPC endpoints * support deleting/updating API Gateway DomainNames * fix(events): Return empty string instead of null when no pattern is specified in EventPattern (tf-compat) (#22) * fix logic and revert CF changes to get tests running again (#21) * add support for EC2 customer gateway API (#25) * add support for EC2 Transit Gateway APIs (#24) * feat(logs): add `kmsKeyId` into `LogGroup` entity (#23) * minor change in ELBv2 logic to fix tests * feat(events): add APIs to describe and delete CloudWatch Events connections (#26) * add support for EC2 transit gateway route tables (#27) * pass transit gateway route table ID in Describe API, minor refactoring (#29) * add support for EC2 Transit Gateway Routes (#28) * fix region on ACM certificate import (#31) * add support for EC2 transit gateway attachments (#30) * add support for EC2 Transit Gateway VPN attachments (#32) * fix account ID for logs API * add support for DeleteOrganization API * feat(events): store raw filter representation for CloudWatch events patterns (tf-compat) (#36) * feat(events): add support to describe/update/delete CloudWatch API destinations (#35) * add Cognito UpdateIdentityPool, CW Logs PutResourcePolicy * feat(events): add support for tags in EventBus API (#38) * fix parameter validation for Batch compute environments (tf-compat) * revert merge conflicts in IMPLEMENTATION_COVERAGE.md * format code using black * restore original README; re-enable and fix CloudFormation tests * restore tests and old logic for CF stack parameters from SSM * parameterize RequestId/RequestID in response messages and revert related test changes * undo LocalStack-specific adaptations * minor fix * Update CodeCov config to reflect removal of Py2 * undo change related to CW metric filtering; add additional test for CW metric statistics with dimensions * Terraform - Extend whitelist of running tests Co-authored-by: acsbendi <acsbendi28@gmail.com> Co-authored-by: Phan Duong <duongpv@outlook.com> Co-authored-by: Thomas Rausch <thomas@thrau.at> Co-authored-by: Macwan Nevil <macnev2013@gmail.com> Co-authored-by: Dominik Schubert <dominik.schubert91@gmail.com> Co-authored-by: Gonzalo Saad <saad.gonzalo.ale@gmail.com> Co-authored-by: Mohit Alonja <monty16597@users.noreply.github.com> Co-authored-by: Miguel Gagliardo <migag9@gmail.com> Co-authored-by: Bert Blommers <info@bertblommers.nl>
2021-07-26 14:21:17 +00:00
"""associate dhcp option invalid vpc id"""
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
2014-04-15 23:02:26 +00:00
with pytest.raises(EC2ResponseError) as cm:
conn.associate_dhcp_options(dhcp_options.id, "foo")
2020-10-06 06:04:09 +00:00
cm.value.code.should.equal("InvalidVpcID.NotFound")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
2014-04-15 23:02:26 +00:00
2021-09-25 11:13:07 +00:00
@mock_ec2
def test_dhcp_options_associate_invalid_vpc_id_boto3():
""" associate dhcp option invalid vpc id """
ec2 = boto3.resource("ec2", region_name="us-west-1")
client = boto3.client("ec2", region_name="us-west-1")
dhcp_options = ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": [SAMPLE_DOMAIN_NAME]},
{"Key": "domain-name-servers", "Values": SAMPLE_NAME_SERVERS},
]
)
with pytest.raises(ClientError) as ex:
client.associate_dhcp_options(DhcpOptionsId=dhcp_options.id, VpcId="foo")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
ex.value.response["ResponseMetadata"].should.have.key("RequestId")
ex.value.response["Error"]["Code"].should.equal("InvalidVpcID.NotFound")
# Has boto3 equivalent
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
2014-04-15 23:02:26 +00:00
def test_dhcp_options_delete_with_vpc():
"""Test deletion of dhcp options with vpc"""
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
2014-04-15 23:02:26 +00:00
dhcp_options_id = dhcp_options.id
vpc = conn.create_vpc("10.0.0.0/16")
rval = conn.associate_dhcp_options(dhcp_options_id, vpc.id)
rval.should.be.equal(True)
with pytest.raises(EC2ResponseError) as cm:
conn.delete_dhcp_options(dhcp_options_id)
2020-10-06 06:04:09 +00:00
cm.value.code.should.equal("DependencyViolation")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
2014-04-15 23:02:26 +00:00
vpc.delete()
with pytest.raises(EC2ResponseError) as cm:
conn.get_all_dhcp_options([dhcp_options_id])
2020-10-06 06:04:09 +00:00
cm.value.code.should.equal("InvalidDhcpOptionID.NotFound")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
2014-04-15 23:02:26 +00:00
2021-09-25 11:13:07 +00:00
@mock_ec2
def test_dhcp_options_delete_with_vpc_boto3():
"""Test deletion of dhcp options with vpc"""
ec2 = boto3.resource("ec2", region_name="us-west-1")
client = boto3.client("ec2", region_name="us-west-1")
dhcp_options = ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": [SAMPLE_DOMAIN_NAME]},
{"Key": "domain-name-servers", "Values": SAMPLE_NAME_SERVERS},
]
)
vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")
client.associate_dhcp_options(DhcpOptionsId=dhcp_options.id, VpcId=vpc.id)
with pytest.raises(ClientError) as ex:
client.delete_dhcp_options(DhcpOptionsId=dhcp_options.id)
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
ex.value.response["ResponseMetadata"].should.have.key("RequestId")
ex.value.response["Error"]["Code"].should.equal("DependencyViolation")
vpc.delete()
with pytest.raises(ClientError) as ex:
client.describe_dhcp_options(DhcpOptionsIds=[dhcp_options.id])
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
ex.value.response["ResponseMetadata"].should.have.key("RequestId")
ex.value.response["Error"]["Code"].should.equal("InvalidDhcpOptionID.NotFound")
# Has boto3 equivalent
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
2014-04-15 23:02:26 +00:00
def test_create_dhcp_options():
"""Create most basic dhcp option"""
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
2014-04-15 23:02:26 +00:00
2019-10-31 15:44:26 +00:00
dhcp_option = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
dhcp_option.options["domain-name"][0].should.be.equal(SAMPLE_DOMAIN_NAME)
dhcp_option.options["domain-name-servers"][0].should.be.equal(
SAMPLE_NAME_SERVERS[0]
)
dhcp_option.options["domain-name-servers"][1].should.be.equal(
SAMPLE_NAME_SERVERS[1]
)
2014-04-15 23:02:26 +00:00
2021-09-25 11:13:07 +00:00
@mock_ec2
def test_create_dhcp_options_boto3():
"""Create most basic dhcp option"""
ec2 = boto3.resource("ec2", region_name="us-west-1")
dhcp_options = ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": [SAMPLE_DOMAIN_NAME]},
{"Key": "domain-name-servers", "Values": SAMPLE_NAME_SERVERS},
]
)
config = dhcp_options.dhcp_configurations
config.should.have.length_of(2)
config.should.contain(
{
"Key": "domain-name-servers",
"Values": [{"Value": ip} for ip in SAMPLE_NAME_SERVERS],
}
)
config.should.contain(
{"Key": "domain-name", "Values": [{"Value": SAMPLE_DOMAIN_NAME}]}
)
# Has boto3 equivalent
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
2014-04-15 23:02:26 +00:00
def test_create_dhcp_options_invalid_options():
"""Create invalid dhcp options"""
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
2014-04-15 23:02:26 +00:00
servers = ["f", "f", "f", "f", "f"]
with pytest.raises(EC2ResponseError) as cm:
conn.create_dhcp_options(ntp_servers=servers)
2020-10-06 06:04:09 +00:00
cm.value.code.should.equal("InvalidParameterValue")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
with pytest.raises(EC2ResponseError) as cm:
conn.create_dhcp_options(netbios_node_type="0")
2020-10-06 06:04:09 +00:00
cm.value.code.should.equal("InvalidParameterValue")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
2014-04-15 23:02:26 +00:00
2021-09-25 11:13:07 +00:00
@mock_ec2
def test_create_dhcp_options_invalid_options_boto3():
"""Create invalid dhcp options"""
ec2 = boto3.resource("ec2", region_name="us-west-1")
servers = ["f", "f", "f", "f", "f"]
with pytest.raises(ClientError) as ex:
ec2.create_dhcp_options(
DhcpConfigurations=[{"Key": "ntp-servers", "Values": servers}]
)
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
ex.value.response["ResponseMetadata"].should.have.key("RequestId")
ex.value.response["Error"]["Code"].should.equal("InvalidParameterValue")
with pytest.raises(ClientError) as ex:
ec2.create_dhcp_options(
DhcpConfigurations=[{"Key": "netbios-node-type", "Values": ["0"]}]
)
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
ex.value.response["ResponseMetadata"].should.have.key("RequestId")
ex.value.response["Error"]["Code"].should.equal("InvalidParameterValue")
# Has boto3 equivalent
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
2014-04-15 23:02:26 +00:00
def test_describe_dhcp_options():
"""Test dhcp options lookup by id"""
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
2014-04-15 23:02:26 +00:00
dhcp_option = conn.create_dhcp_options()
dhcp_options = conn.get_all_dhcp_options([dhcp_option.id])
dhcp_options.should.be.length_of(1)
dhcp_options = conn.get_all_dhcp_options()
dhcp_options.should.be.length_of(1)
2013-02-22 04:13:01 +00:00
2021-09-25 11:13:07 +00:00
@mock_ec2
def test_describe_dhcp_options_boto3():
"""Test dhcp options lookup by id"""
ec2 = boto3.resource("ec2", region_name="us-west-1")
client = boto3.client("ec2", region_name="us-west-1")
all_options = client.describe_dhcp_options()["DhcpOptions"]
all_options.should.have.length_of(0)
dhcp_options = ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": [SAMPLE_DOMAIN_NAME]},
{"Key": "domain-name-servers", "Values": SAMPLE_NAME_SERVERS},
]
)
all_options = client.describe_dhcp_options(DhcpOptionsIds=[dhcp_options.id])[
"DhcpOptions"
]
all_options.should.have.length_of(1)
all_options = client.describe_dhcp_options()["DhcpOptions"]
all_options.should.have.length_of(1)
all_options[0]["DhcpOptionsId"].should.equal(dhcp_options.id)
config = all_options[0]["DhcpConfigurations"]
config.should.have.length_of(2)
config.should.contain(
{
"Key": "domain-name-servers",
"Values": [{"Value": ip} for ip in SAMPLE_NAME_SERVERS],
}
)
config.should.contain(
{"Key": "domain-name", "Values": [{"Value": SAMPLE_DOMAIN_NAME}]}
)
# Has boto3 equivalent
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
2014-04-15 23:02:26 +00:00
def test_describe_dhcp_options_invalid_id():
"""get error on invalid dhcp_option_id lookup"""
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
2014-04-15 23:02:26 +00:00
with pytest.raises(EC2ResponseError) as cm:
conn.get_all_dhcp_options(["1"])
2020-10-06 06:04:09 +00:00
cm.value.code.should.equal("InvalidDhcpOptionID.NotFound")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
2014-04-15 23:02:26 +00:00
2021-09-25 11:13:07 +00:00
@mock_ec2
def test_describe_dhcp_options_invalid_id_boto3():
"""get error on invalid dhcp_option_id lookup"""
client = boto3.client("ec2", region_name="us-west-1")
with pytest.raises(ClientError) as ex:
client.describe_dhcp_options(DhcpOptionsIds=["1"])
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
ex.value.response["ResponseMetadata"].should.have.key("RequestId")
ex.value.response["Error"]["Code"].should.equal("InvalidDhcpOptionID.NotFound")
# Has boto3 equivalent
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
2014-04-15 23:02:26 +00:00
def test_delete_dhcp_options():
"""delete dhcp option"""
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
2014-04-15 23:02:26 +00:00
dhcp_option = conn.create_dhcp_options()
dhcp_options = conn.get_all_dhcp_options([dhcp_option.id])
dhcp_options.should.be.length_of(1)
conn.delete_dhcp_options(dhcp_option.id) # .should.be.equal(True)
with pytest.raises(EC2ResponseError) as cm:
conn.get_all_dhcp_options([dhcp_option.id])
2020-10-06 06:04:09 +00:00
cm.value.code.should.equal("InvalidDhcpOptionID.NotFound")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
2014-04-15 23:02:26 +00:00
2021-09-25 11:13:07 +00:00
@mock_ec2
def test_delete_dhcp_options_boto3():
"""delete dhcp option"""
ec2 = boto3.resource("ec2", region_name="us-west-1")
client = boto3.client("ec2", region_name="us-west-1")
dhcp_option = ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": [SAMPLE_DOMAIN_NAME]},
{"Key": "domain-name-servers", "Values": SAMPLE_NAME_SERVERS},
]
)
client.delete_dhcp_options(DhcpOptionsId=dhcp_option.id)
with pytest.raises(ClientError) as ex:
client.describe_dhcp_options(DhcpOptionsIds=[dhcp_option.id])
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
ex.value.response["ResponseMetadata"].should.have.key("RequestId")
ex.value.response["Error"]["Code"].should.equal("InvalidDhcpOptionID.NotFound")
# Has boto3 equivalent
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
2014-04-15 23:02:26 +00:00
def test_delete_dhcp_options_invalid_id():
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
2014-04-15 23:02:26 +00:00
conn.create_dhcp_options()
with pytest.raises(EC2ResponseError) as cm:
conn.delete_dhcp_options("dopt-abcd1234")
2020-10-06 06:04:09 +00:00
cm.value.code.should.equal("InvalidDhcpOptionID.NotFound")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
2021-09-25 11:13:07 +00:00
@mock_ec2
def test_delete_dhcp_options_invalid_id_boto3():
client = boto3.client("ec2", region_name="us-west-1")
with pytest.raises(ClientError) as ex:
client.delete_dhcp_options(DhcpOptionsId="dopt-abcd1234")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
ex.value.response["ResponseMetadata"].should.have.key("RequestId")
ex.value.response["Error"]["Code"].should.equal("InvalidDhcpOptionID.NotFound")
# Has boto3 equivalent
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
def test_delete_dhcp_options_malformed_id():
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
conn.create_dhcp_options()
with pytest.raises(EC2ResponseError) as cm:
conn.delete_dhcp_options("foo-abcd1234")
2020-10-06 06:04:09 +00:00
cm.value.code.should.equal("InvalidDhcpOptionsId.Malformed")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
2021-09-25 11:13:07 +00:00
@mock_ec2
def test_delete_dhcp_options_malformed_id_boto3():
client = boto3.client("ec2", region_name="us-west-1")
with pytest.raises(ClientError) as ex:
client.delete_dhcp_options(DhcpOptionsId="foo-abcd1234")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
ex.value.response["ResponseMetadata"].should.have.key("RequestId")
ex.value.response["Error"]["Code"].should.equal("InvalidDhcpOptionsId.Malformed")
# Has boto3 equivalent
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
def test_dhcp_tagging():
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
dhcp_option = conn.create_dhcp_options()
dhcp_option.add_tag("a key", "some value")
tag = conn.get_all_tags()[0]
tag.name.should.equal("a key")
tag.value.should.equal("some value")
# Refresh the DHCP options
dhcp_option = conn.get_all_dhcp_options()[0]
dhcp_option.tags.should.have.length_of(1)
dhcp_option.tags["a key"].should.equal("some value")
2021-09-25 11:13:07 +00:00
@mock_ec2
def test_dhcp_tagging_boto3():
ec2 = boto3.resource("ec2", region_name="us-west-1")
client = boto3.client("ec2", region_name="us-west-1")
dhcp_option = ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": [SAMPLE_DOMAIN_NAME]},
{"Key": "domain-name-servers", "Values": SAMPLE_NAME_SERVERS},
]
)
dhcp_option.create_tags(Tags=[{"Key": "a tag", "Value": "some value"}])
tag = client.describe_tags()["Tags"][0]
tag.should.have.key("ResourceId").equal(dhcp_option.id)
tag.should.have.key("ResourceType").equal("dhcp-options")
tag.should.have.key("Key").equal("a tag")
tag.should.have.key("Value").equal("some value")
# Refresh the DHCP options
dhcp_option = client.describe_dhcp_options()["DhcpOptions"][0]
dhcp_option["Tags"].should.equal([{"Key": "a tag", "Value": "some value"}])
# Has boto3 equivalent
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
def test_dhcp_options_get_by_tag():
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
2019-10-31 15:44:26 +00:00
dhcp1 = conn.create_dhcp_options("example.com", ["10.0.10.2"])
dhcp1.add_tag("Name", "TestDhcpOptions1")
dhcp1.add_tag("test-tag", "test-value")
2019-10-31 15:44:26 +00:00
dhcp2 = conn.create_dhcp_options("example.com", ["10.0.20.2"])
dhcp2.add_tag("Name", "TestDhcpOptions2")
dhcp2.add_tag("test-tag", "test-value")
2019-10-31 15:44:26 +00:00
filters = {"tag:Name": "TestDhcpOptions1", "tag:test-tag": "test-value"}
dhcp_options_sets = conn.get_all_dhcp_options(filters=filters)
dhcp_options_sets.should.have.length_of(1)
2019-10-31 15:44:26 +00:00
dhcp_options_sets[0].options["domain-name"][0].should.be.equal("example.com")
dhcp_options_sets[0].options["domain-name-servers"][0].should.be.equal("10.0.10.2")
dhcp_options_sets[0].tags["Name"].should.equal("TestDhcpOptions1")
dhcp_options_sets[0].tags["test-tag"].should.equal("test-value")
filters = {"tag:Name": "TestDhcpOptions2", "tag:test-tag": "test-value"}
dhcp_options_sets = conn.get_all_dhcp_options(filters=filters)
dhcp_options_sets.should.have.length_of(1)
2019-10-31 15:44:26 +00:00
dhcp_options_sets[0].options["domain-name"][0].should.be.equal("example.com")
dhcp_options_sets[0].options["domain-name-servers"][0].should.be.equal("10.0.20.2")
dhcp_options_sets[0].tags["Name"].should.equal("TestDhcpOptions2")
dhcp_options_sets[0].tags["test-tag"].should.equal("test-value")
filters = {"tag:test-tag": "test-value"}
dhcp_options_sets = conn.get_all_dhcp_options(filters=filters)
dhcp_options_sets.should.have.length_of(2)
2021-09-25 11:13:07 +00:00
@mock_ec2
def test_dhcp_options_get_by_tag_boto3():
ec2 = boto3.resource("ec2", region_name="us-west-1")
client = boto3.client("ec2", region_name="us-west-1")
dhcp1 = ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": ["example.com"]},
{"Key": "domain-name-servers", "Values": ["10.0.10.2"]},
]
)
dhcp1.create_tags(
Tags=[
{"Key": "Name", "Value": "TestDhcpOptions1"},
{"Key": "test-tag", "Value": "test-value"},
]
)
dhcp2 = ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": ["example.com"]},
{"Key": "domain-name-servers", "Values": ["10.0.20.2"]},
]
)
dhcp2.create_tags(
Tags=[
{"Key": "Name", "Value": "TestDhcpOptions2"},
{"Key": "test-tag", "Value": "test-value"},
]
)
dhcp_options_sets = client.describe_dhcp_options(
Filters=[
{"Name": "tag:Name", "Values": ["TestDhcpOptions1"]},
{"Name": "tag:test-tag", "Values": ["test-value"]},
]
)["DhcpOptions"]
dhcp_options_sets.should.have.length_of(1)
config = dhcp_options_sets[0]["DhcpConfigurations"]
config.should.have.length_of(2)
config.should.contain({"Key": "domain-name", "Values": [{"Value": "example.com"}]})
config.should.contain(
{"Key": "domain-name-servers", "Values": [{"Value": "10.0.10.2"}]}
)
tags = dhcp_options_sets[0]["Tags"]
tags.should.have.length_of(2)
tags.should.contain({"Key": "Name", "Value": "TestDhcpOptions1"})
tags.should.contain({"Key": "test-tag", "Value": "test-value"})
dhcp_options_sets = client.describe_dhcp_options(
Filters=[
{"Name": "tag:Name", "Values": ["TestDhcpOptions2"]},
{"Name": "tag:test-tag", "Values": ["test-value"]},
]
)["DhcpOptions"]
dhcp_options_sets.should.have.length_of(1)
config = dhcp_options_sets[0]["DhcpConfigurations"]
config.should.have.length_of(2)
config.should.contain({"Key": "domain-name", "Values": [{"Value": "example.com"}]})
config.should.contain(
{"Key": "domain-name-servers", "Values": [{"Value": "10.0.20.2"}]}
)
tags = dhcp_options_sets[0]["Tags"]
tags.should.have.length_of(2)
tags.should.contain({"Key": "Name", "Value": "TestDhcpOptions2"})
tags.should.contain({"Key": "test-tag", "Value": "test-value"})
dhcp_options_sets = client.describe_dhcp_options(
Filters=[{"Name": "tag:test-tag", "Values": ["test-value"]}]
)["DhcpOptions"]
dhcp_options_sets.should.have.length_of(2)
# Has boto3 equivalent
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
def test_dhcp_options_get_by_id():
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
2019-10-31 15:44:26 +00:00
dhcp1 = conn.create_dhcp_options("test1.com", ["10.0.10.2"])
dhcp1.add_tag("Name", "TestDhcpOptions1")
dhcp1.add_tag("test-tag", "test-value")
dhcp1_id = dhcp1.id
2019-10-31 15:44:26 +00:00
dhcp2 = conn.create_dhcp_options("test2.com", ["10.0.20.2"])
dhcp2.add_tag("Name", "TestDhcpOptions2")
dhcp2.add_tag("test-tag", "test-value")
dhcp2_id = dhcp2.id
dhcp_options_sets = conn.get_all_dhcp_options()
dhcp_options_sets.should.have.length_of(2)
2019-10-31 15:44:26 +00:00
dhcp_options_sets = conn.get_all_dhcp_options(filters={"dhcp-options-id": dhcp1_id})
dhcp_options_sets.should.have.length_of(1)
2019-10-31 15:44:26 +00:00
dhcp_options_sets[0].options["domain-name"][0].should.be.equal("test1.com")
dhcp_options_sets[0].options["domain-name-servers"][0].should.be.equal("10.0.10.2")
2019-10-31 15:44:26 +00:00
dhcp_options_sets = conn.get_all_dhcp_options(filters={"dhcp-options-id": dhcp2_id})
dhcp_options_sets.should.have.length_of(1)
2019-10-31 15:44:26 +00:00
dhcp_options_sets[0].options["domain-name"][0].should.be.equal("test2.com")
dhcp_options_sets[0].options["domain-name-servers"][0].should.be.equal("10.0.20.2")
2021-09-25 11:13:07 +00:00
@mock_ec2
def test_dhcp_options_get_by_id_boto3():
ec2 = boto3.resource("ec2", region_name="us-west-1")
client = boto3.client("ec2", region_name="us-west-1")
dhcp1 = ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": ["test1.com"]},
{"Key": "domain-name-servers", "Values": ["10.0.10.2"]},
]
)
dhcp1.create_tags(Tags=[{"Key": "Name", "Value": "TestDhcpOptions1"}])
dhcp1.create_tags(Tags=[{"Key": "test-tag", "Value": "test-value"}])
dhcp2 = ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": ["test2.com"]},
{"Key": "domain-name-servers", "Values": ["10.0.20.2"]},
]
)
dhcp1.create_tags(Tags=[{"Key": "Name", "Value": "TestDhcpOptions2"}])
dhcp1.create_tags(Tags=[{"Key": "test-tag", "Value": "test-value"}])
d = client.describe_dhcp_options()["DhcpOptions"]
d.should.have.length_of(2)
d = client.describe_dhcp_options(
Filters=[{"Name": "dhcp-options-id", "Values": [dhcp1.id]}]
)["DhcpOptions"]
d.should.have.length_of(1)
d[0].should.have.key("DhcpOptionsId").equal(dhcp1.id)
d = client.describe_dhcp_options(
Filters=[{"Name": "dhcp-options-id", "Values": [dhcp2.id]}]
)["DhcpOptions"]
d.should.have.length_of(1)
d[0].should.have.key("DhcpOptionsId").equal(dhcp2.id)
@mock_ec2
def test_dhcp_options_get_by_value_filter():
2019-10-31 15:44:26 +00:00
ec2 = boto3.resource("ec2", region_name="us-west-1")
ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": ["example.com"]},
{"Key": "domain-name-servers", "Values": ["10.0.10.2"]},
]
)
ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": ["example.com"]},
{"Key": "domain-name-servers", "Values": ["10.0.20.2"]},
]
)
ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": ["example.com"]},
{"Key": "domain-name-servers", "Values": ["10.0.30.2"]},
]
)
filters = [{"Name": "value", "Values": ["10.0.10.2"]}]
dhcp_options_sets = list(ec2.dhcp_options_sets.filter(Filters=filters))
dhcp_options_sets.should.have.length_of(1)
@mock_ec2
def test_dhcp_options_get_by_key_filter():
2019-10-31 15:44:26 +00:00
ec2 = boto3.resource("ec2", region_name="us-west-1")
ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": ["example.com"]},
{"Key": "domain-name-servers", "Values": ["10.0.10.2"]},
]
)
ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": ["example.com"]},
{"Key": "domain-name-servers", "Values": ["10.0.20.2"]},
]
)
ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": ["example.com"]},
{"Key": "domain-name-servers", "Values": ["10.0.30.2"]},
]
)
filters = [{"Name": "key", "Values": ["domain-name"]}]
dhcp_options_sets = list(ec2.dhcp_options_sets.filter(Filters=filters))
dhcp_options_sets.should.have.length_of(3)
2021-09-25 11:13:07 +00:00
# Has boto3 equivalent
2017-02-16 03:35:45 +00:00
@mock_ec2_deprecated
def test_dhcp_options_get_by_invalid_filter():
2019-10-31 15:44:26 +00:00
conn = boto.connect_vpc("the_key", "the_secret")
conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
2019-10-31 15:44:26 +00:00
filters = {"invalid-filter": "invalid-value"}
2019-10-31 15:44:26 +00:00
conn.get_all_dhcp_options.when.called_with(filters=filters).should.throw(
NotImplementedError
)
2021-09-25 11:13:07 +00:00
@mock_ec2
def test_dhcp_options_get_by_invalid_filter_boto3():
if settings.TEST_SERVER_MODE:
raise SkipTest("Will throw a generic 500 in ServerMode")
ec2 = boto3.resource("ec2", region_name="us-west-1")
client = boto3.client("ec2", region_name="us-west-1")
ec2.create_dhcp_options(
DhcpConfigurations=[
{"Key": "domain-name", "Values": [SAMPLE_DOMAIN_NAME]},
{"Key": "domain-name-servers", "Values": SAMPLE_NAME_SERVERS},
]
)
filters = [{"Name": "invalid-filter", "Values": ["n/a"]}]
client.describe_dhcp_options.when.called_with(Filters=filters).should.throw(
NotImplementedError
)