@@ -34,6 +34,117 @@ def setUp(self):
3434 self .requests_mock = self .useFixture (fixture .Fixture ())
3535
3636
37+ class TestFloatingIP (TestComputeAPIv2 ):
38+
39+ FAKE_FLOATING_IP_RESP = {
40+ 'id' : 1 ,
41+ 'ip' : '203.0.113.11' , # TEST-NET-3
42+ 'fixed_ip' : '198.51.100.11' , # TEST-NET-2
43+ 'pool' : 'nova' ,
44+ 'instance_id' : None ,
45+ }
46+ FAKE_FLOATING_IP_RESP_2 = {
47+ 'id' : 2 ,
48+ 'ip' : '203.0.113.12' , # TEST-NET-3
49+ 'fixed_ip' : '198.51.100.12' , # TEST-NET-2
50+ 'pool' : 'nova' ,
51+ 'instance_id' : None ,
52+ }
53+ LIST_FLOATING_IP_RESP = [
54+ FAKE_FLOATING_IP_RESP ,
55+ FAKE_FLOATING_IP_RESP_2 ,
56+ ]
57+
58+ def test_floating_ip_create (self ):
59+ self .requests_mock .register_uri (
60+ 'POST' ,
61+ FAKE_URL + '/os-floating-ips' ,
62+ json = {'floating_ip' : self .FAKE_FLOATING_IP_RESP },
63+ status_code = 200 ,
64+ )
65+ ret = self .api .floating_ip_create ('nova' )
66+ self .assertEqual (self .FAKE_FLOATING_IP_RESP , ret )
67+
68+ def test_floating_ip_create_not_found (self ):
69+ self .requests_mock .register_uri (
70+ 'POST' ,
71+ FAKE_URL + '/os-floating-ips' ,
72+ status_code = 404 ,
73+ )
74+ self .assertRaises (
75+ osc_lib_exceptions .NotFound ,
76+ self .api .floating_ip_create ,
77+ 'not-nova' ,
78+ )
79+
80+ def test_floating_ip_delete (self ):
81+ self .requests_mock .register_uri (
82+ 'DELETE' ,
83+ FAKE_URL + '/os-floating-ips/1' ,
84+ status_code = 202 ,
85+ )
86+ ret = self .api .floating_ip_delete ('1' )
87+ self .assertEqual (202 , ret .status_code )
88+ self .assertEqual ("" , ret .text )
89+
90+ def test_floating_ip_delete_none (self ):
91+ ret = self .api .floating_ip_delete ()
92+ self .assertIsNone (ret )
93+
94+ def test_floating_ip_find_id (self ):
95+ self .requests_mock .register_uri (
96+ 'GET' ,
97+ FAKE_URL + '/os-floating-ips/1' ,
98+ json = {'floating_ip' : self .FAKE_FLOATING_IP_RESP },
99+ status_code = 200 ,
100+ )
101+ ret = self .api .floating_ip_find ('1' )
102+ self .assertEqual (self .FAKE_FLOATING_IP_RESP , ret )
103+
104+ def test_floating_ip_find_ip (self ):
105+ self .requests_mock .register_uri (
106+ 'GET' ,
107+ FAKE_URL + '/os-floating-ips/' + self .FAKE_FLOATING_IP_RESP ['ip' ],
108+ status_code = 404 ,
109+ )
110+ self .requests_mock .register_uri (
111+ 'GET' ,
112+ FAKE_URL + '/os-floating-ips' ,
113+ json = {'floating_ips' : self .LIST_FLOATING_IP_RESP },
114+ status_code = 200 ,
115+ )
116+ ret = self .api .floating_ip_find (self .FAKE_FLOATING_IP_RESP ['ip' ])
117+ self .assertEqual (self .FAKE_FLOATING_IP_RESP , ret )
118+
119+ def test_floating_ip_find_not_found (self ):
120+ self .requests_mock .register_uri (
121+ 'GET' ,
122+ FAKE_URL + '/os-floating-ips/1.2.3.4' ,
123+ status_code = 404 ,
124+ )
125+ self .requests_mock .register_uri (
126+ 'GET' ,
127+ FAKE_URL + '/os-floating-ips' ,
128+ json = {'floating_ips' : self .LIST_FLOATING_IP_RESP },
129+ status_code = 200 ,
130+ )
131+ self .assertRaises (
132+ osc_lib_exceptions .NotFound ,
133+ self .api .floating_ip_find ,
134+ '1.2.3.4' ,
135+ )
136+
137+ def test_floating_ip_list (self ):
138+ self .requests_mock .register_uri (
139+ 'GET' ,
140+ FAKE_URL + '/os-floating-ips' ,
141+ json = {'floating_ips' : self .LIST_FLOATING_IP_RESP },
142+ status_code = 200 ,
143+ )
144+ ret = self .api .floating_ip_list ()
145+ self .assertEqual (self .LIST_FLOATING_IP_RESP , ret )
146+
147+
37148class TestSecurityGroup (TestComputeAPIv2 ):
38149
39150 FAKE_SECURITY_GROUP_RESP = {
0 commit comments