How to use create_firewall_rule method in localstack

Best Python code snippet using localstack_python

test_neutron_firewall.py

Source:test_neutron_firewall.py Github

copy

Full Screen

...326 self.m.StubOutWithMock(neutronclient.Client, 'show_firewall_rule')327 self.m.StubOutWithMock(neutronclient.Client, 'update_firewall_rule')328 self.patchobject(neutron.NeutronClientPlugin, 'has_extension',329 return_value=True)330 def create_firewall_rule(self):331 neutronclient.Client.create_firewall_rule({332 'firewall_rule': {333 'name': 'test-firewall-rule', 'shared': True,334 'action': 'allow', 'protocol': 'tcp', 'enabled': True,335 'ip_version': "4"}}336 ).AndReturn({'firewall_rule': {'id': '5678'}})337 snippet = template_format.parse(firewall_rule_template)338 self.stack = utils.parse_stack(snippet)339 self.tmpl = snippet340 resource_defns = self.stack.t.resource_definitions(self.stack)341 return firewall.FirewallRule(342 'firewall_rule', resource_defns['firewall_rule'], self.stack)343 def test_create(self):344 rsrc = self.create_firewall_rule()345 self.m.ReplayAll()346 scheduler.TaskRunner(rsrc.create)()347 self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)348 self.m.VerifyAll()349 def test_validate_failed_with_string_None_protocol(self):350 snippet = template_format.parse(firewall_rule_template)351 stack = utils.parse_stack(snippet)352 rsrc = stack['firewall_rule']353 props = dict(rsrc.properties)354 props['protocol'] = 'None'355 rsrc.t = rsrc.t.freeze(properties=props)356 rsrc.reparse()357 self.assertRaises(exception.StackValidationFailed, rsrc.validate)358 def test_create_with_protocol_any(self):359 neutronclient.Client.create_firewall_rule({360 'firewall_rule': {361 'name': 'test-firewall-rule', 'shared': True,362 'action': 'allow', 'protocol': None, 'enabled': True,363 'ip_version': "4"}}364 ).AndReturn({'firewall_rule': {'id': '5678'}})365 self.m.ReplayAll()366 snippet = template_format.parse(firewall_rule_template)367 snippet['resources']['firewall_rule']['properties']['protocol'] = 'any'368 stack = utils.parse_stack(snippet)369 rsrc = stack['firewall_rule']370 scheduler.TaskRunner(rsrc.create)()371 self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)372 self.m.VerifyAll()373 def test_create_failed(self):374 neutronclient.Client.create_firewall_rule({375 'firewall_rule': {376 'name': 'test-firewall-rule', 'shared': True,377 'action': 'allow', 'protocol': 'tcp', 'enabled': True,378 'ip_version': "4"}}379 ).AndRaise(exceptions.NeutronClientException())380 self.m.ReplayAll()381 snippet = template_format.parse(firewall_rule_template)382 stack = utils.parse_stack(snippet)383 resource_defns = stack.t.resource_definitions(stack)384 rsrc = firewall.FirewallRule(385 'firewall_rule', resource_defns['firewall_rule'], stack)386 error = self.assertRaises(exception.ResourceFailure,387 scheduler.TaskRunner(rsrc.create))388 self.assertEqual(389 'NeutronClientException: resources.firewall_rule: '390 'An unknown exception occurred.',391 six.text_type(error))392 self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)393 self.m.VerifyAll()394 def test_delete(self):395 neutronclient.Client.delete_firewall_rule('5678')396 neutronclient.Client.show_firewall_rule('5678').AndRaise(397 exceptions.NeutronClientException(status_code=404))398 rsrc = self.create_firewall_rule()399 self.m.ReplayAll()400 scheduler.TaskRunner(rsrc.create)()401 scheduler.TaskRunner(rsrc.delete)()402 self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)403 self.m.VerifyAll()404 def test_delete_already_gone(self):405 neutronclient.Client.delete_firewall_rule('5678').AndRaise(406 exceptions.NeutronClientException(status_code=404))407 rsrc = self.create_firewall_rule()408 self.m.ReplayAll()409 scheduler.TaskRunner(rsrc.create)()410 scheduler.TaskRunner(rsrc.delete)()411 self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)412 self.m.VerifyAll()413 def test_delete_failed(self):414 neutronclient.Client.delete_firewall_rule('5678').AndRaise(415 exceptions.NeutronClientException(status_code=400))416 rsrc = self.create_firewall_rule()417 self.m.ReplayAll()418 scheduler.TaskRunner(rsrc.create)()419 error = self.assertRaises(exception.ResourceFailure,420 scheduler.TaskRunner(rsrc.delete))421 self.assertEqual(422 'NeutronClientException: resources.firewall_rule: '423 'An unknown exception occurred.',424 six.text_type(error))425 self.assertEqual((rsrc.DELETE, rsrc.FAILED), rsrc.state)426 self.m.VerifyAll()427 def test_attribute(self):428 rsrc = self.create_firewall_rule()429 neutronclient.Client.show_firewall_rule('5678').MultipleTimes(430 ).AndReturn(431 {'firewall_rule': {'protocol': 'tcp', 'shared': True}})432 self.m.ReplayAll()433 scheduler.TaskRunner(rsrc.create)()434 self.assertEqual('tcp', rsrc.FnGetAtt('protocol'))435 self.assertIs(True, rsrc.FnGetAtt('shared'))436 self.m.VerifyAll()437 def test_attribute_failed(self):438 rsrc = self.create_firewall_rule()439 self.m.ReplayAll()440 scheduler.TaskRunner(rsrc.create)()441 error = self.assertRaises(exception.InvalidTemplateAttribute,442 rsrc.FnGetAtt, 'subnet_id')443 self.assertEqual(444 'The Referenced Attribute (firewall_rule subnet_id) is '445 'incorrect.', six.text_type(error))446 self.m.VerifyAll()447 def test_update(self):448 rsrc = self.create_firewall_rule()449 neutronclient.Client.update_firewall_rule(450 '5678', {'firewall_rule': {'protocol': 'icmp'}})451 self.m.ReplayAll()452 scheduler.TaskRunner(rsrc.create)()453 props = self.tmpl['resources']['firewall_rule']['properties'].copy()454 props['protocol'] = 'icmp'455 update_template = rsrc.t.freeze(properties=props)456 scheduler.TaskRunner(rsrc.update, update_template)()457 self.m.VerifyAll()458 def test_update_protocol_to_any(self):459 rsrc = self.create_firewall_rule()460 neutronclient.Client.update_firewall_rule(461 '5678', {'firewall_rule': {'protocol': None}})462 self.m.ReplayAll()463 scheduler.TaskRunner(rsrc.create)()464 # update to 'any' protocol465 props = self.tmpl['resources']['firewall_rule']['properties'].copy()466 props['protocol'] = 'any'467 update_template = rsrc.t.freeze(properties=props)468 scheduler.TaskRunner(rsrc.update, update_template)()...

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