1616from openstackclient .network .v2 import floating_ip
1717from openstackclient .tests .compute .v2 import fakes as compute_fakes
1818from openstackclient .tests .network .v2 import fakes as network_fakes
19+ from openstackclient .tests import utils as tests_utils
1920
2021
2122# Tests for Neutron network
@@ -29,6 +30,115 @@ def setUp(self):
2930 self .network = self .app .client_manager .network
3031
3132
33+ class TestCreateFloatingIPNetwork (TestFloatingIPNetwork ):
34+
35+ # Fake data for option tests.
36+ floating_network = network_fakes .FakeNetwork .create_one_network ()
37+ subnet = network_fakes .FakeSubnet .create_one_subnet ()
38+ port = network_fakes .FakePort .create_one_port ()
39+
40+ # The floating ip to be deleted.
41+ floating_ip = network_fakes .FakeFloatingIP .create_one_floating_ip (
42+ attrs = {
43+ 'floating_network_id' : floating_network .id ,
44+ 'port_id' : port .id ,
45+ }
46+ )
47+
48+ columns = (
49+ 'dns_domain' ,
50+ 'dns_name' ,
51+ 'fixed_ip_address' ,
52+ 'floating_ip_address' ,
53+ 'floating_network_id' ,
54+ 'id' ,
55+ 'port_id' ,
56+ 'project_id' ,
57+ 'router_id' ,
58+ 'status' ,
59+ )
60+
61+ data = (
62+ floating_ip .dns_domain ,
63+ floating_ip .dns_name ,
64+ floating_ip .fixed_ip_address ,
65+ floating_ip .floating_ip_address ,
66+ floating_ip .floating_network_id ,
67+ floating_ip .id ,
68+ floating_ip .port_id ,
69+ floating_ip .project_id ,
70+ floating_ip .router_id ,
71+ floating_ip .status ,
72+ )
73+
74+ def setUp (self ):
75+ super (TestCreateFloatingIPNetwork , self ).setUp ()
76+
77+ self .network .create_ip = mock .Mock (return_value = self .floating_ip )
78+
79+ self .network .find_network = mock .Mock (
80+ return_value = self .floating_network )
81+ self .network .find_subnet = mock .Mock (return_value = self .subnet )
82+ self .network .find_port = mock .Mock (return_value = self .port )
83+
84+ # Get the command object to test
85+ self .cmd = floating_ip .CreateFloatingIP (self .app , self .namespace )
86+
87+ def test_create_no_options (self ):
88+ arglist = []
89+ verifylist = []
90+
91+ # Missing required args should bail here
92+ self .assertRaises (tests_utils .ParserException , self .check_parser ,
93+ self .cmd , arglist , verifylist )
94+
95+ def test_create_default_options (self ):
96+ arglist = [
97+ self .floating_ip .floating_network_id ,
98+ ]
99+ verifylist = [
100+ ('network' , self .floating_ip .floating_network_id ),
101+ ]
102+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
103+
104+ columns , data = self .cmd .take_action (parsed_args )
105+
106+ self .network .create_ip .assert_called_once_with (** {
107+ 'floating_network_id' : self .floating_ip .floating_network_id ,
108+ })
109+ self .assertEqual (self .columns , columns )
110+ self .assertEqual (self .data , data )
111+
112+ def test_create_all_options (self ):
113+ arglist = [
114+ '--subnet' , self .subnet .id ,
115+ '--port' , self .floating_ip .port_id ,
116+ '--floating-ip-address' , self .floating_ip .floating_ip_address ,
117+ '--fixed-ip-address' , self .floating_ip .fixed_ip_address ,
118+ self .floating_ip .floating_network_id ,
119+ ]
120+ verifylist = [
121+ ('subnet' , self .subnet .id ),
122+ ('port' , self .floating_ip .port_id ),
123+ ('floating_ip_address' , self .floating_ip .floating_ip_address ),
124+ ('fixed_ip_address' , self .floating_ip .fixed_ip_address ),
125+ ('network' , self .floating_ip .floating_network_id ),
126+ ]
127+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
128+
129+ columns , data = self .cmd .take_action (parsed_args )
130+
131+ self .network .create_ip .assert_called_once_with (** {
132+ 'subnet_id' : self .subnet .id ,
133+ 'port_id' : self .floating_ip .port_id ,
134+ 'floating_ip_address' : self .floating_ip .floating_ip_address ,
135+ 'fixed_ip_address' : self .floating_ip .fixed_ip_address ,
136+ 'floating_network_id' : self .floating_ip .floating_network_id ,
137+ })
138+ self .assertEqual (self .columns , columns )
139+ self .assertEqual (self .data , data )
140+
141+
32142class TestDeleteFloatingIPNetwork (TestFloatingIPNetwork ):
33143
34144 # The floating ip to be deleted.
@@ -169,6 +279,62 @@ def setUp(self):
169279 self .compute = self .app .client_manager .compute
170280
171281
282+ class TestCreateFloatingIPCompute (TestFloatingIPCompute ):
283+
284+ # The floating ip to be deleted.
285+ floating_ip = compute_fakes .FakeFloatingIP .create_one_floating_ip ()
286+
287+ columns = (
288+ 'fixed_ip' ,
289+ 'id' ,
290+ 'instance_id' ,
291+ 'ip' ,
292+ 'pool' ,
293+ )
294+
295+ data = (
296+ floating_ip .fixed_ip ,
297+ floating_ip .id ,
298+ floating_ip .instance_id ,
299+ floating_ip .ip ,
300+ floating_ip .pool ,
301+ )
302+
303+ def setUp (self ):
304+ super (TestCreateFloatingIPCompute , self ).setUp ()
305+
306+ self .app .client_manager .network_endpoint_enabled = False
307+
308+ self .compute .floating_ips .create .return_value = self .floating_ip
309+
310+ # Get the command object to test
311+ self .cmd = floating_ip .CreateFloatingIP (self .app , None )
312+
313+ def test_create_no_options (self ):
314+ arglist = []
315+ verifylist = []
316+
317+ # Missing required args should bail here
318+ self .assertRaises (tests_utils .ParserException , self .check_parser ,
319+ self .cmd , arglist , verifylist )
320+
321+ def test_create_default_options (self ):
322+ arglist = [
323+ self .floating_ip .pool ,
324+ ]
325+ verifylist = [
326+ ('network' , self .floating_ip .pool ),
327+ ]
328+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
329+
330+ columns , data = self .cmd .take_action (parsed_args )
331+
332+ self .compute .floating_ips .create .assert_called_once_with (
333+ self .floating_ip .pool )
334+ self .assertEqual (self .columns , columns )
335+ self .assertEqual (self .data , data )
336+
337+
172338class TestDeleteFloatingIPCompute (TestFloatingIPCompute ):
173339
174340 # The floating ip to be deleted.
0 commit comments