How to use show_security_group_rule method in tempest

Best Python code snippet using tempest_python

test_neutron_security_group_rule.py

Source:test_neutron_security_group_rule.py Github

copy

Full Screen

1#2# Licensed under the Apache License, Version 2.0 (the "License"); you may3# not use this file except in compliance with the License. You may obtain4# a copy of the License at5#6# http://www.apache.org/licenses/LICENSE-2.07#8# Unless required by applicable law or agreed to in writing, software9# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT10# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the11# License for the specific language governing permissions and limitations12# under the License.13import mock14from heat.common import exception15from heat.common import template_format16from heat.engine.resources.openstack.neutron import security_group_rule17from heat.tests import common18from heat.tests.openstack.neutron import inline_templates19from heat.tests import utils20class SecurityGroupRuleTest(common.HeatTestCase):21 def test_resource_mapping(self):22 mapping = security_group_rule.resource_mapping()23 self.assertEqual(mapping['OS::Neutron::SecurityGroupRule'],24 security_group_rule.SecurityGroupRule)25 @mock.patch('heat.engine.clients.os.neutron.'26 'NeutronClientPlugin.has_extension', return_value=True)27 def _create_stack(self, ext_func,28 tmpl=inline_templates.SECURITY_GROUP_RULE_TEMPLATE):29 self.t = template_format.parse(tmpl)30 self.stack = utils.parse_stack(self.t)31 self.sg_rule = self.stack['security_group_rule']32 self.neutron_client = mock.MagicMock()33 self.sg_rule.client = mock.MagicMock(return_value=self.neutron_client)34 self.sg_rule.client_plugin().find_resourceid_by_name_or_id = (35 mock.MagicMock(return_value='123'))36 def test_create(self):37 self._create_stack()38 self.neutron_client.create_security_group_rule.return_value = {39 'security_group_rule': {'id': '1234'}}40 expected = {41 'security_group_rule': {42 'security_group_id': u'123',43 'description': u'test description',44 'remote_group_id': u'123',45 'protocol': u'tcp',46 'port_range_min': '100',47 'direction': 'ingress',48 'ethertype': 'IPv4'49 }50 }51 self.sg_rule.handle_create()52 self.neutron_client.create_security_group_rule.assert_called_with(53 expected)54 def test_validate_conflict_props(self):55 self.patchobject(security_group_rule.SecurityGroupRule,56 'is_service_available',57 return_value=(True, None))58 tmpl = inline_templates.SECURITY_GROUP_RULE_TEMPLATE59 tmpl += ' remote_ip_prefix: "123"'60 self._create_stack(tmpl=tmpl)61 self.assertRaises(exception.ResourcePropertyConflict,62 self.sg_rule.validate)63 def test_validate_max_port_less_than_min_port(self):64 self.patchobject(security_group_rule.SecurityGroupRule,65 'is_service_available',66 return_value=(True, None))67 tmpl = inline_templates.SECURITY_GROUP_RULE_TEMPLATE68 tmpl += ' port_range_max: 50'69 self._create_stack(tmpl=tmpl)70 self.assertRaises(exception.StackValidationFailed,71 self.sg_rule.validate)72 def test_show_resource(self):73 self._create_stack()74 self.sg_rule.resource_id_set('1234')75 self.neutron_client.show_security_group_rule.return_value = {76 'security_group_rule': {'id': '1234'}77 }78 self.assertEqual({'id': '1234'}, self.sg_rule._show_resource())79 self.neutron_client.show_security_group_rule.assert_called_with('1234')80 def test_delete(self):81 self._create_stack()82 self.sg_rule.resource_id_set('1234')83 self.sg_rule.handle_delete()84 self.neutron_client.delete_security_group_rule.assert_called_with(...

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 tempest 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