<s> import uuid <EOL> from openstack . network . v2 import security_group <EOL> from openstack . network . v2 import security_group_rule <EOL> from openstack . tests . functional import base <EOL> class TestSecurityGroupRule ( base . BaseFunctionalTest ) : <EOL> NAME = uuid . uuid4 ( ) . hex <EOL> IPV4 = '<STR_LIT>' <EOL> PROTO = '<STR_LIT>' <EOL> PORT = <NUM_LIT> <EOL> DIR = '<STR_LIT>' <EOL> ID = None <EOL> RULE_ID = None <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> super ( TestSecurityGroupRule , cls ) . setUpClass ( ) <EOL> sot = cls . conn . network . create_security_group ( name = cls . NAME ) <EOL> assert isinstance ( sot , security_group . SecurityGroup ) <EOL> cls . assertIs ( cls . NAME , sot . name ) <EOL> cls . ID = sot . id <EOL> rul = cls . conn . network . create_security_group_rule ( <EOL> direction = cls . DIR , ethertype = cls . IPV4 , <EOL> port_range_max = cls . PORT , port_range_min = cls . PORT , <EOL> protocol = cls . PROTO , security_group_id = cls . ID ) <EOL> assert isinstance ( rul , security_group_rule . SecurityGroupRule ) <EOL> cls . assertIs ( cls . ID , rul . security_group_id ) <EOL> cls . RULE_ID = rul . id <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> sot = cls . conn . network . delete_security_group_rule ( cls . RULE_ID , <EOL> ignore_missing = False ) <EOL> cls . assertIs ( None , sot ) <EOL> sot = cls . conn . network . delete_security_group ( cls . ID , <EOL> ignore_missing = False ) <EOL> cls . assertIs ( None , sot ) <EOL> def test_find ( self ) : <EOL> sot = self . conn . network . find_security_group_rule ( self . RULE_ID ) <EOL> self . assertEqual ( self . RULE_ID , sot . id ) <EOL> def test_get ( self ) : <EOL> sot = self . conn . network . get_security_group_rule ( self . RULE_ID ) <EOL> self . assertEqual ( self . RULE_ID , sot . id ) <EOL> self . assertEqual ( self . DIR , sot . direction ) <EOL> self . assertEqual ( self . PROTO , sot . protocol ) <EOL> self . assertEqual ( self . PORT , sot . port_range_min ) <EOL> self . assertEqual ( self . PORT , sot . port_range_max ) <EOL> self . assertEqual ( self . ID , sot . security_group_id ) <EOL> def test_list ( self ) : <EOL> ids = [ o . id for o in self . conn . network . security_group_rules ( ) ] <EOL> self . assertIn ( self . RULE_ID , ids ) </s>
