1414import re
1515import uuid
1616
17- from openstackclient .tests .functional import base
17+ from openstackclient .tests .functional . network . v2 import common
1818
1919
20- class FloatingIpTests (base . TestCase ):
20+ class FloatingIpTests (common . NetworkTests ):
2121 """Functional tests for floating ip"""
2222 SUBNET_NAME = uuid .uuid4 ().hex
2323 NETWORK_NAME = uuid .uuid4 ().hex
@@ -28,78 +28,97 @@ class FloatingIpTests(base.TestCase):
2828
2929 @classmethod
3030 def setUpClass (cls ):
31- # Set up some regex for matching below
32- cls .re_id = re .compile ("id\s+\|\s+(\S+)" )
33- cls .re_floating_ip = re .compile ("floating_ip_address\s+\|\s+(\S+)" )
34- cls .re_fixed_ip = re .compile ("fixed_ip_address\s+\|\s+(\S+)" )
35- cls .re_description = re .compile ("description\s+\|\s+([^|]+?)\s+\|" )
36- cls .re_network_id = re .compile ("floating_network_id\s+\|\s+(\S+)" )
37- cls .re_port_id = re .compile ("\s+id\s+\|\s+(\S+)" )
38- cls .re_fp_port_id = re .compile ("\s+port_id\s+\|\s+(\S+)" )
39-
40- # Create a network for the floating ip
41- raw_output = cls .openstack (
42- 'network create --external ' + cls .NETWORK_NAME
43- )
44- cls .network_id = re .search (cls .re_id , raw_output ).group (1 )
31+ common .NetworkTests .setUpClass ()
32+ if cls .haz_network :
33+ # Set up some regex for matching below
34+ cls .re_id = re .compile ("id\s+\|\s+(\S+)" )
35+ cls .re_floating_ip = re .compile ("floating_ip_address\s+\|\s+(\S+)" )
36+ cls .re_fixed_ip = re .compile ("fixed_ip_address\s+\|\s+(\S+)" )
37+ cls .re_description = re .compile ("description\s+\|\s+([^|]+?)\s+\|" )
38+ cls .re_network_id = re .compile ("floating_network_id\s+\|\s+(\S+)" )
39+ cls .re_port_id = re .compile ("\s+id\s+\|\s+(\S+)" )
40+ cls .re_fp_port_id = re .compile ("\s+port_id\s+\|\s+(\S+)" )
4541
46- # Create a private network for the port
47- raw_output = cls .openstack (
48- 'network create ' + cls .PRIVATE_NETWORK_NAME
49- )
50- cls .private_network_id = re .search (cls .re_id , raw_output ).group (1 )
51-
52- # Try random subnet range for subnet creating
53- # Because we can not determine ahead of time what subnets are already
54- # in use, possibly by another test running in parallel, try 4 times
55- for i in range (4 ):
56- # Make a random subnet
57- cls .subnet = "." .join (map (
58- str ,
59- (random .randint (0 , 223 ) for _ in range (3 ))
60- )) + ".0/26"
61- cls .private_subnet = "." .join (map (
62- str ,
63- (random .randint (0 , 223 ) for _ in range (3 ))
64- )) + ".0/26"
65- try :
66- # Create a subnet for the network
67- raw_output = cls .openstack (
68- 'subnet create ' +
69- '--network ' + cls .NETWORK_NAME + ' ' +
70- '--subnet-range ' + cls .subnet + ' ' +
71- cls .SUBNET_NAME
72- )
73- # Create a subnet for the private network
74- priv_raw_output = cls .openstack (
75- 'subnet create ' +
76- '--network ' + cls .PRIVATE_NETWORK_NAME + ' ' +
77- '--subnet-range ' + cls .private_subnet + ' ' +
78- cls .PRIVATE_SUBNET_NAME
79- )
80- except Exception :
81- if (i == 3 ):
82- # raise the exception at the last time
83- raise
84- pass
85- else :
86- # break and no longer retry if create sucessfully
87- break
88-
89- cls .subnet_id = re .search (cls .re_id , raw_output ).group (1 )
90- cls .private_subnet_id = re .search (cls .re_id , priv_raw_output ).group (1 )
42+ # Create a network for the floating ip
43+ raw_output = cls .openstack (
44+ 'network create --external ' + cls .NETWORK_NAME
45+ )
46+ cls .network_id = re .search (cls .re_id , raw_output ).group (1 )
47+
48+ # Create a private network for the port
49+ raw_output = cls .openstack (
50+ 'network create ' + cls .PRIVATE_NETWORK_NAME
51+ )
52+ cls .private_network_id = re .search (cls .re_id , raw_output ).group (1 )
53+
54+ # Try random subnet range for subnet creating
55+ # Because we can not determine ahead of time what subnets are
56+ # already in use, possibly by another test running in parallel,
57+ # try 4 times
58+ for i in range (4 ):
59+ # Make a random subnet
60+ cls .subnet = "." .join (map (
61+ str ,
62+ (random .randint (0 , 223 ) for _ in range (3 ))
63+ )) + ".0/26"
64+ cls .private_subnet = "." .join (map (
65+ str ,
66+ (random .randint (0 , 223 ) for _ in range (3 ))
67+ )) + ".0/26"
68+ try :
69+ # Create a subnet for the network
70+ raw_output = cls .openstack (
71+ 'subnet create ' +
72+ '--network ' + cls .NETWORK_NAME + ' ' +
73+ '--subnet-range ' + cls .subnet + ' ' +
74+ cls .SUBNET_NAME
75+ )
76+ # Create a subnet for the private network
77+ priv_raw_output = cls .openstack (
78+ 'subnet create ' +
79+ '--network ' + cls .PRIVATE_NETWORK_NAME + ' ' +
80+ '--subnet-range ' + cls .private_subnet + ' ' +
81+ cls .PRIVATE_SUBNET_NAME
82+ )
83+ except Exception :
84+ if (i == 3 ):
85+ # raise the exception at the last time
86+ raise
87+ pass
88+ else :
89+ # break and no longer retry if create sucessfully
90+ break
91+
92+ cls .subnet_id = re .search (cls .re_id , raw_output ).group (1 )
93+ cls .private_subnet_id = re .search (
94+ cls .re_id , priv_raw_output
95+ ).group (1 )
9196
9297 @classmethod
9398 def tearDownClass (cls ):
94- raw_output = cls .openstack ('subnet delete ' + cls .SUBNET_NAME )
95- cls .assertOutput ('' , raw_output )
96- raw_output = cls .openstack ('subnet delete ' + cls .PRIVATE_SUBNET_NAME )
97- cls .assertOutput ('' , raw_output )
98- raw_output = cls .openstack ('network delete ' + cls .NETWORK_NAME )
99- cls .assertOutput ('' , raw_output )
100- raw_output = cls .openstack (
101- 'network delete ' + cls .PRIVATE_NETWORK_NAME )
102- cls .assertOutput ('' , raw_output )
99+ if cls .haz_network :
100+ raw_output = cls .openstack (
101+ 'subnet delete ' + cls .SUBNET_NAME ,
102+ )
103+ cls .assertOutput ('' , raw_output )
104+ raw_output = cls .openstack (
105+ 'subnet delete ' + cls .PRIVATE_SUBNET_NAME ,
106+ )
107+ cls .assertOutput ('' , raw_output )
108+ raw_output = cls .openstack (
109+ 'network delete ' + cls .NETWORK_NAME ,
110+ )
111+ cls .assertOutput ('' , raw_output )
112+ raw_output = cls .openstack (
113+ 'network delete ' + cls .PRIVATE_NETWORK_NAME ,
114+ )
115+ cls .assertOutput ('' , raw_output )
116+
117+ def setUp (self ):
118+ super (FloatingIpTests , self ).setUp ()
119+ # Nothing in this class works with Nova Network
120+ if not self .haz_network :
121+ self .skipTest ("No Network service present" )
103122
104123 def test_floating_ip_delete (self ):
105124 """Test create, delete multiple"""
0 commit comments