| 
									
										
										
										
											2014-08-27 11:17:06 -04:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  | # Ensure 'pytest.raises' context manager support for Python 2.6 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2014-08-25 15:09:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  | import boto3 | 
					
						
							| 
									
										
										
										
											2013-02-21 23:13:01 -05:00
										 |  |  | import boto | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  | from boto.exception import EC2ResponseError | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-03 17:21:25 -04:00
										 |  |  | import sure  # noqa | 
					
						
							| 
									
										
										
										
											2013-02-21 23:13:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | from moto import mock_ec2, mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2013-02-21 23:13:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  | SAMPLE_DOMAIN_NAME = "example.com" | 
					
						
							|  |  |  | SAMPLE_NAME_SERVERS = ["10.0.0.6", "10.0.0.7"] | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  | def test_dhcp_options_associate(): | 
					
						
							|  |  |  |     """ associate dhcp option """ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							|  |  |  |     dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS) | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04: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) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  | def test_dhcp_options_associate_invalid_dhcp_id(): | 
					
						
							|  |  |  |     """ associate dhcp option bad dhcp options id """ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  |     vpc = conn.create_vpc("10.0.0.0/16") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |         conn.associate_dhcp_options("foo", vpc.id) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02: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 19:02:26 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  | def test_dhcp_options_associate_invalid_vpc_id(): | 
					
						
							|  |  |  |     """ associate dhcp option invalid vpc id """ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							|  |  |  |     dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS) | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |         conn.associate_dhcp_options(dhcp_options.id, "foo") | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02: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 19:02:26 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  | def test_dhcp_options_delete_with_vpc(): | 
					
						
							|  |  |  |     """Test deletion of dhcp options with vpc""" | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							|  |  |  |     dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS) | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04: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) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |         conn.delete_dhcp_options(dhcp_options_id) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     cm.value.code.should.equal("DependencyViolation") | 
					
						
							|  |  |  |     cm.value.status.should.equal(400) | 
					
						
							|  |  |  |     cm.value.request_id.should_not.be.none | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  |     vpc.delete() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |         conn.get_all_dhcp_options([dhcp_options_id]) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02: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 19:02:26 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  | def test_create_dhcp_options(): | 
					
						
							|  |  |  |     """Create most basic dhcp option""" | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07: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 19:02:26 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  | def test_create_dhcp_options_invalid_options(): | 
					
						
							|  |  |  |     """Create invalid dhcp options""" | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  |     servers = ["f", "f", "f", "f", "f"] | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |         conn.create_dhcp_options(ntp_servers=servers) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     cm.value.code.should.equal("InvalidParameterValue") | 
					
						
							|  |  |  |     cm.value.status.should.equal(400) | 
					
						
							|  |  |  |     cm.value.request_id.should_not.be.none | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |         conn.create_dhcp_options(netbios_node_type="0") | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     cm.value.code.should.equal("InvalidParameterValue") | 
					
						
							|  |  |  |     cm.value.status.should.equal(400) | 
					
						
							|  |  |  |     cm.value.request_id.should_not.be.none | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  | def test_describe_dhcp_options(): | 
					
						
							|  |  |  |     """Test dhcp options lookup by id""" | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04: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-21 23:13:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  | def test_describe_dhcp_options_invalid_id(): | 
					
						
							|  |  |  |     """get error on invalid dhcp_option_id lookup""" | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |         conn.get_all_dhcp_options(["1"]) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02: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 19:02:26 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  | def test_delete_dhcp_options(): | 
					
						
							|  |  |  |     """delete dhcp option""" | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04: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) | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |         conn.get_all_dhcp_options([dhcp_option.id]) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02: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 19:02:26 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  | def test_delete_dhcp_options_invalid_id(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-04-15 19:02:26 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-11 19:00:28 -04:00
										 |  |  |     conn.create_dhcp_options() | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |         conn.delete_dhcp_options("dopt-abcd1234") | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     cm.value.code.should.equal("InvalidDhcpOptionID.NotFound") | 
					
						
							|  |  |  |     cm.value.status.should.equal(400) | 
					
						
							|  |  |  |     cm.value.request_id.should_not.be.none | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | def test_delete_dhcp_options_malformed_id(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     conn.create_dhcp_options() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as cm: | 
					
						
							| 
									
										
										
										
											2014-08-25 10:54:47 -07:00
										 |  |  |         conn.delete_dhcp_options("foo-abcd1234") | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     cm.value.code.should.equal("InvalidDhcpOptionsId.Malformed") | 
					
						
							|  |  |  |     cm.value.status.should.equal(400) | 
					
						
							|  |  |  |     cm.value.request_id.should_not.be.none | 
					
						
							| 
									
										
										
										
											2014-05-11 19:00:28 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-05-11 19:00:28 -04:00
										 |  |  | def test_dhcp_tagging(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2014-05-11 19:00:28 -04:00
										 |  |  |     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") | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  | def test_dhcp_options_get_by_tag(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     dhcp1 = conn.create_dhcp_options("example.com", ["10.0.10.2"]) | 
					
						
							|  |  |  |     dhcp1.add_tag("Name", "TestDhcpOptions1") | 
					
						
							|  |  |  |     dhcp1.add_tag("test-tag", "test-value") | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     dhcp2 = conn.create_dhcp_options("example.com", ["10.0.20.2"]) | 
					
						
							|  |  |  |     dhcp2.add_tag("Name", "TestDhcpOptions2") | 
					
						
							|  |  |  |     dhcp2.add_tag("test-tag", "test-value") | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     filters = {"tag:Name": "TestDhcpOptions1", "tag:test-tag": "test-value"} | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  |     dhcp_options_sets = conn.get_all_dhcp_options(filters=filters) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dhcp_options_sets.should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07: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"} | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  |     dhcp_options_sets = conn.get_all_dhcp_options(filters=filters) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dhcp_options_sets.should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07: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"} | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  |     dhcp_options_sets = conn.get_all_dhcp_options(filters=filters) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dhcp_options_sets.should.have.length_of(2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  | def test_dhcp_options_get_by_id(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     dhcp1 = conn.create_dhcp_options("test1.com", ["10.0.10.2"]) | 
					
						
							|  |  |  |     dhcp1.add_tag("Name", "TestDhcpOptions1") | 
					
						
							|  |  |  |     dhcp1.add_tag("test-tag", "test-value") | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  |     dhcp1_id = dhcp1.id | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     dhcp2 = conn.create_dhcp_options("test2.com", ["10.0.20.2"]) | 
					
						
							|  |  |  |     dhcp2.add_tag("Name", "TestDhcpOptions2") | 
					
						
							|  |  |  |     dhcp2.add_tag("test-tag", "test-value") | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  |     dhcp2_id = dhcp2.id | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dhcp_options_sets = conn.get_all_dhcp_options() | 
					
						
							|  |  |  |     dhcp_options_sets.should.have.length_of(2) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     dhcp_options_sets = conn.get_all_dhcp_options(filters={"dhcp-options-id": dhcp1_id}) | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     dhcp_options_sets.should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07: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") | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     dhcp_options_sets = conn.get_all_dhcp_options(filters={"dhcp-options-id": dhcp2_id}) | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     dhcp_options_sets.should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07: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") | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | def test_dhcp_options_get_by_value_filter(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07: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"]}] | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  |     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 08:44:26 -07: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"]}] | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  |     dhcp_options_sets = list(ec2.dhcp_options_sets.filter(Filters=filters)) | 
					
						
							|  |  |  |     dhcp_options_sets.should.have.length_of(3) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  | def test_dhcp_options_get_by_invalid_filter(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto.connect_vpc("the_key", "the_secret") | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     filters = {"invalid-filter": "invalid-value"} | 
					
						
							| 
									
										
										
										
											2016-04-13 23:19:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.get_all_dhcp_options.when.called_with(filters=filters).should.throw( | 
					
						
							|  |  |  |         NotImplementedError | 
					
						
							|  |  |  |     ) |