How to use create_dhcp_options method in localstack

Best Python code snippet using localstack_python

test_dhcp_options.py

Source:test_dhcp_options.py Github

copy

Full Screen

...10@mock_ec2_deprecated11def test_dhcp_options_associate():12 """ associate dhcp option """13 conn = boto.connect_vpc("the_key", "the_secret")14 dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)15 vpc = conn.create_vpc("10.0.0.0/16")16 rval = conn.associate_dhcp_options(dhcp_options.id, vpc.id)17 rval.should.be.equal(True)18@mock_ec2_deprecated19def test_dhcp_options_associate_invalid_dhcp_id():20 """ associate dhcp option bad dhcp options id """21 conn = boto.connect_vpc("the_key", "the_secret")22 vpc = conn.create_vpc("10.0.0.0/16")23 with pytest.raises(EC2ResponseError) as cm:24 conn.associate_dhcp_options("foo", vpc.id)25 cm.value.code.should.equal("InvalidDhcpOptionID.NotFound")26 cm.value.status.should.equal(400)27 cm.value.request_id.should_not.be.none28@mock_ec2_deprecated29def test_dhcp_options_associate_invalid_vpc_id():30 """ associate dhcp option invalid vpc id """31 conn = boto.connect_vpc("the_key", "the_secret")32 dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)33 with pytest.raises(EC2ResponseError) as cm:34 conn.associate_dhcp_options(dhcp_options.id, "foo")35 cm.value.code.should.equal("InvalidVpcID.NotFound")36 cm.value.status.should.equal(400)37 cm.value.request_id.should_not.be.none38@mock_ec2_deprecated39def test_dhcp_options_delete_with_vpc():40 """Test deletion of dhcp options with vpc"""41 conn = boto.connect_vpc("the_key", "the_secret")42 dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)43 dhcp_options_id = dhcp_options.id44 vpc = conn.create_vpc("10.0.0.0/16")45 rval = conn.associate_dhcp_options(dhcp_options_id, vpc.id)46 rval.should.be.equal(True)47 with pytest.raises(EC2ResponseError) as cm:48 conn.delete_dhcp_options(dhcp_options_id)49 cm.value.code.should.equal("DependencyViolation")50 cm.value.status.should.equal(400)51 cm.value.request_id.should_not.be.none52 vpc.delete()53 with pytest.raises(EC2ResponseError) as cm:54 conn.get_all_dhcp_options([dhcp_options_id])55 cm.value.code.should.equal("InvalidDhcpOptionID.NotFound")56 cm.value.status.should.equal(400)57 cm.value.request_id.should_not.be.none58@mock_ec2_deprecated59def test_create_dhcp_options():60 """Create most basic dhcp option"""61 conn = boto.connect_vpc("the_key", "the_secret")62 dhcp_option = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)63 dhcp_option.options["domain-name"][0].should.be.equal(SAMPLE_DOMAIN_NAME)64 dhcp_option.options["domain-name-servers"][0].should.be.equal(65 SAMPLE_NAME_SERVERS[0]66 )67 dhcp_option.options["domain-name-servers"][1].should.be.equal(68 SAMPLE_NAME_SERVERS[1]69 )70@mock_ec2_deprecated71def test_create_dhcp_options_invalid_options():72 """Create invalid dhcp options"""73 conn = boto.connect_vpc("the_key", "the_secret")74 servers = ["f", "f", "f", "f", "f"]75 with pytest.raises(EC2ResponseError) as cm:76 conn.create_dhcp_options(ntp_servers=servers)77 cm.value.code.should.equal("InvalidParameterValue")78 cm.value.status.should.equal(400)79 cm.value.request_id.should_not.be.none80 with pytest.raises(EC2ResponseError) as cm:81 conn.create_dhcp_options(netbios_node_type="0")82 cm.value.code.should.equal("InvalidParameterValue")83 cm.value.status.should.equal(400)84 cm.value.request_id.should_not.be.none85@mock_ec2_deprecated86def test_describe_dhcp_options():87 """Test dhcp options lookup by id"""88 conn = boto.connect_vpc("the_key", "the_secret")89 dhcp_option = conn.create_dhcp_options()90 dhcp_options = conn.get_all_dhcp_options([dhcp_option.id])91 dhcp_options.should.be.length_of(1)92 dhcp_options = conn.get_all_dhcp_options()93 dhcp_options.should.be.length_of(1)94@mock_ec2_deprecated95def test_describe_dhcp_options_invalid_id():96 """get error on invalid dhcp_option_id lookup"""97 conn = boto.connect_vpc("the_key", "the_secret")98 with pytest.raises(EC2ResponseError) as cm:99 conn.get_all_dhcp_options(["1"])100 cm.value.code.should.equal("InvalidDhcpOptionID.NotFound")101 cm.value.status.should.equal(400)102 cm.value.request_id.should_not.be.none103@mock_ec2_deprecated104def test_delete_dhcp_options():105 """delete dhcp option"""106 conn = boto.connect_vpc("the_key", "the_secret")107 dhcp_option = conn.create_dhcp_options()108 dhcp_options = conn.get_all_dhcp_options([dhcp_option.id])109 dhcp_options.should.be.length_of(1)110 conn.delete_dhcp_options(dhcp_option.id) # .should.be.equal(True)111 with pytest.raises(EC2ResponseError) as cm:112 conn.get_all_dhcp_options([dhcp_option.id])113 cm.value.code.should.equal("InvalidDhcpOptionID.NotFound")114 cm.value.status.should.equal(400)115 cm.value.request_id.should_not.be.none116@mock_ec2_deprecated117def test_delete_dhcp_options_invalid_id():118 conn = boto.connect_vpc("the_key", "the_secret")119 conn.create_dhcp_options()120 with pytest.raises(EC2ResponseError) as cm:121 conn.delete_dhcp_options("dopt-abcd1234")122 cm.value.code.should.equal("InvalidDhcpOptionID.NotFound")123 cm.value.status.should.equal(400)124 cm.value.request_id.should_not.be.none125@mock_ec2_deprecated126def test_delete_dhcp_options_malformed_id():127 conn = boto.connect_vpc("the_key", "the_secret")128 conn.create_dhcp_options()129 with pytest.raises(EC2ResponseError) as cm:130 conn.delete_dhcp_options("foo-abcd1234")131 cm.value.code.should.equal("InvalidDhcpOptionsId.Malformed")132 cm.value.status.should.equal(400)133 cm.value.request_id.should_not.be.none134@mock_ec2_deprecated135def test_dhcp_tagging():136 conn = boto.connect_vpc("the_key", "the_secret")137 dhcp_option = conn.create_dhcp_options()138 dhcp_option.add_tag("a key", "some value")139 tag = conn.get_all_tags()[0]140 tag.name.should.equal("a key")141 tag.value.should.equal("some value")142 # Refresh the DHCP options143 dhcp_option = conn.get_all_dhcp_options()[0]144 dhcp_option.tags.should.have.length_of(1)145 dhcp_option.tags["a key"].should.equal("some value")146@mock_ec2_deprecated147def test_dhcp_options_get_by_tag():148 conn = boto.connect_vpc("the_key", "the_secret")149 dhcp1 = conn.create_dhcp_options("example.com", ["10.0.10.2"])150 dhcp1.add_tag("Name", "TestDhcpOptions1")151 dhcp1.add_tag("test-tag", "test-value")152 dhcp2 = conn.create_dhcp_options("example.com", ["10.0.20.2"])153 dhcp2.add_tag("Name", "TestDhcpOptions2")154 dhcp2.add_tag("test-tag", "test-value")155 filters = {"tag:Name": "TestDhcpOptions1", "tag:test-tag": "test-value"}156 dhcp_options_sets = conn.get_all_dhcp_options(filters=filters)157 dhcp_options_sets.should.have.length_of(1)158 dhcp_options_sets[0].options["domain-name"][0].should.be.equal("example.com")159 dhcp_options_sets[0].options["domain-name-servers"][0].should.be.equal("10.0.10.2")160 dhcp_options_sets[0].tags["Name"].should.equal("TestDhcpOptions1")161 dhcp_options_sets[0].tags["test-tag"].should.equal("test-value")162 filters = {"tag:Name": "TestDhcpOptions2", "tag:test-tag": "test-value"}163 dhcp_options_sets = conn.get_all_dhcp_options(filters=filters)164 dhcp_options_sets.should.have.length_of(1)165 dhcp_options_sets[0].options["domain-name"][0].should.be.equal("example.com")166 dhcp_options_sets[0].options["domain-name-servers"][0].should.be.equal("10.0.20.2")167 dhcp_options_sets[0].tags["Name"].should.equal("TestDhcpOptions2")168 dhcp_options_sets[0].tags["test-tag"].should.equal("test-value")169 filters = {"tag:test-tag": "test-value"}170 dhcp_options_sets = conn.get_all_dhcp_options(filters=filters)171 dhcp_options_sets.should.have.length_of(2)172@mock_ec2_deprecated173def test_dhcp_options_get_by_id():174 conn = boto.connect_vpc("the_key", "the_secret")175 dhcp1 = conn.create_dhcp_options("test1.com", ["10.0.10.2"])176 dhcp1.add_tag("Name", "TestDhcpOptions1")177 dhcp1.add_tag("test-tag", "test-value")178 dhcp1_id = dhcp1.id179 dhcp2 = conn.create_dhcp_options("test2.com", ["10.0.20.2"])180 dhcp2.add_tag("Name", "TestDhcpOptions2")181 dhcp2.add_tag("test-tag", "test-value")182 dhcp2_id = dhcp2.id183 dhcp_options_sets = conn.get_all_dhcp_options()184 dhcp_options_sets.should.have.length_of(2)185 dhcp_options_sets = conn.get_all_dhcp_options(filters={"dhcp-options-id": dhcp1_id})186 dhcp_options_sets.should.have.length_of(1)187 dhcp_options_sets[0].options["domain-name"][0].should.be.equal("test1.com")188 dhcp_options_sets[0].options["domain-name-servers"][0].should.be.equal("10.0.10.2")189 dhcp_options_sets = conn.get_all_dhcp_options(filters={"dhcp-options-id": dhcp2_id})190 dhcp_options_sets.should.have.length_of(1)191 dhcp_options_sets[0].options["domain-name"][0].should.be.equal("test2.com")192 dhcp_options_sets[0].options["domain-name-servers"][0].should.be.equal("10.0.20.2")193@mock_ec2194def test_dhcp_options_get_by_value_filter():195 ec2 = boto3.resource("ec2", region_name="us-west-1")196 ec2.create_dhcp_options(197 DhcpConfigurations=[198 {"Key": "domain-name", "Values": ["example.com"]},199 {"Key": "domain-name-servers", "Values": ["10.0.10.2"]},200 ]201 )202 ec2.create_dhcp_options(203 DhcpConfigurations=[204 {"Key": "domain-name", "Values": ["example.com"]},205 {"Key": "domain-name-servers", "Values": ["10.0.20.2"]},206 ]207 )208 ec2.create_dhcp_options(209 DhcpConfigurations=[210 {"Key": "domain-name", "Values": ["example.com"]},211 {"Key": "domain-name-servers", "Values": ["10.0.30.2"]},212 ]213 )214 filters = [{"Name": "value", "Values": ["10.0.10.2"]}]215 dhcp_options_sets = list(ec2.dhcp_options_sets.filter(Filters=filters))216 dhcp_options_sets.should.have.length_of(1)217@mock_ec2218def test_dhcp_options_get_by_key_filter():219 ec2 = boto3.resource("ec2", region_name="us-west-1")220 ec2.create_dhcp_options(221 DhcpConfigurations=[222 {"Key": "domain-name", "Values": ["example.com"]},223 {"Key": "domain-name-servers", "Values": ["10.0.10.2"]},224 ]225 )226 ec2.create_dhcp_options(227 DhcpConfigurations=[228 {"Key": "domain-name", "Values": ["example.com"]},229 {"Key": "domain-name-servers", "Values": ["10.0.20.2"]},230 ]231 )232 ec2.create_dhcp_options(233 DhcpConfigurations=[234 {"Key": "domain-name", "Values": ["example.com"]},235 {"Key": "domain-name-servers", "Values": ["10.0.30.2"]},236 ]237 )238 filters = [{"Name": "key", "Values": ["domain-name"]}]239 dhcp_options_sets = list(ec2.dhcp_options_sets.filter(Filters=filters))240 dhcp_options_sets.should.have.length_of(3)241@mock_ec2_deprecated242def test_dhcp_options_get_by_invalid_filter():243 conn = boto.connect_vpc("the_key", "the_secret")244 conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)245 filters = {"invalid-filter": "invalid-value"}246 conn.get_all_dhcp_options.when.called_with(filters=filters).should.throw(247 NotImplementedError...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful