1717import mock
1818from oslo_service import loopingcall
1919from oslotest import base as test_base
20- import requests
2120
2221from ironic_python_agent import errors
2322from ironic_python_agent import hardware
2423from ironic_python_agent import ironic_api_client
2524
2625API_URL = 'http://agent-api.ironic.example.org/'
27- DRIVER = 'agent_ipmitool'
2826
2927
3028class FakeResponse (object ):
@@ -38,7 +36,7 @@ def __init__(self, content=None, status_code=200, headers=None):
3836class TestBaseIronicPythonAgent (test_base .BaseTestCase ):
3937 def setUp (self ):
4038 super (TestBaseIronicPythonAgent , self ).setUp ()
41- self .api_client = ironic_api_client .APIClient (API_URL , DRIVER )
39+ self .api_client = ironic_api_client .APIClient (API_URL )
4240 self .hardware_info = {
4341 'interfaces' : [
4442 hardware .NetworkInterface (
@@ -76,24 +74,6 @@ def test_successful_heartbeat(self):
7674 self .assertEqual ('POST' , request_args [0 ])
7775 self .assertEqual (API_URL + heartbeat_path , request_args [1 ])
7876
79- def test_successful_heartbeat_old_api (self ):
80- response = FakeResponse (status_code = 202 )
81-
82- self .api_client .session .request = mock .Mock ()
83- self .api_client .session .request .return_value = response
84-
85- self .api_client .use_ramdisk_api = False
86- self .api_client .heartbeat (
87- uuid = 'deadbeef-dabb-ad00-b105-f00d00bab10c' ,
88- advertise_address = ('192.0.2.1' , '9999' )
89- )
90-
91- heartbeat_path = ('v1/nodes/deadbeef-dabb-ad00-b105-f00d00bab10c/'
92- 'vendor_passthru/heartbeat' )
93- request_args = self .api_client .session .request .call_args [0 ]
94- self .assertEqual ('POST' , request_args [0 ])
95- self .assertEqual (API_URL + heartbeat_path , request_args [1 ])
96-
9777 def test_heartbeat_requests_exception (self ):
9878 self .api_client .session .request = mock .Mock ()
9979 self .api_client .session .request .side_effect = Exception ('api is down!' )
@@ -178,7 +158,6 @@ def test_do_lookup(self):
178158 params = self .api_client .session .request .call_args [1 ]['params' ]
179159 self .assertEqual ({'addresses' : '00:0c:29:8c:11:b1,00:0c:29:8c:11:b2' },
180160 params )
181- self .assertTrue (self .api_client .use_ramdisk_api )
182161
183162 def test_do_lookup_with_uuid (self ):
184163 response = FakeResponse (status_code = 200 , content = {
@@ -262,104 +241,3 @@ def test_do_lookup_bad_response_body(self):
262241 node_uuid = None )
263242
264243 self .assertFalse (error )
265-
266- def _test_do_lookup_fallback (self , error_code ):
267- response0 = FakeResponse (status_code = error_code )
268- response = FakeResponse (status_code = 200 , content = {
269- 'node' : {
270- 'uuid' : 'deadbeef-dabb-ad00-b105-f00d00bab10c'
271- },
272- 'heartbeat_timeout' : 300
273- })
274-
275- self .api_client .session .request = mock .Mock ()
276- self .api_client .session .request .side_effect = [response0 ,
277- response ]
278-
279- self .assertRaises (loopingcall .LoopingCallDone ,
280- self .api_client ._do_lookup ,
281- hardware_info = self .hardware_info ,
282- node_uuid = None )
283-
284- url = '{api_url}v1/drivers/{driver}/vendor_passthru/lookup' .format (
285- api_url = API_URL , driver = DRIVER )
286- self .assertEqual (2 , self .api_client .session .request .call_count )
287- request_args = self .api_client .session .request .call_args_list [1 ][0 ]
288- self .assertEqual ('POST' , request_args [0 ])
289- self .assertEqual (url , request_args [1 ])
290-
291- data = self .api_client .session .request .call_args_list [1 ][1 ]['data' ]
292- content = json .loads (data )
293- self .assertEqual (self .api_client .payload_version , content ['version' ])
294- self .assertEqual ({
295- u'interfaces' : [
296- {
297- u'mac_address' : u'00:0c:29:8c:11:b1' ,
298- u'name' : u'eth0' ,
299- u'ipv4_address' : None ,
300- u'switch_chassis_descr' : None ,
301- u'switch_port_descr' : None ,
302- u'has_carrier' : True ,
303- u'lldp' : None ,
304- u'vendor' : u'0x15b3' ,
305- u'product' : u'0x1014'
306- },
307- {
308- u'mac_address' : u'00:0c:29:8c:11:b2' ,
309- u'name' : u'eth1' ,
310- u'ipv4_address' : None ,
311- u'switch_chassis_descr' : None ,
312- u'switch_port_descr' : None ,
313- u'has_carrier' : True ,
314- u'lldp' : [[1 , u'04885a92ec5459' ],
315- [2 , u'0545746865726e6574312f3138' ]],
316- u'vendor' : u'0x15b3' ,
317- u'product' : u'0x1014'
318- }
319- ],
320- u'cpu' : {
321- u'model_name' : u'Awesome Jay CPU x10 9001' ,
322- u'frequency' : u'9001' ,
323- u'count' : u'10' ,
324- u'architecture' : u'ARMv9' ,
325- u'flags' : [],
326- },
327- u'disks' : [
328- {
329- u'model' : u'small' ,
330- u'name' : u'/dev/sdj' ,
331- u'rotational' : False ,
332- u'size' : u'9001' ,
333- u'serial' : None ,
334- u'wwn' : None ,
335- u'wwn_with_extension' : None ,
336- u'wwn_vendor_extension' : None ,
337- u'vendor' : None ,
338- },
339- {
340- u'model' : u'big' ,
341- u'name' : u'/dev/hdj' ,
342- u'rotational' : False ,
343- u'size' : u'9002' ,
344- u'serial' : None ,
345- u'wwn' : None ,
346- u'wwn_with_extension' : None ,
347- u'wwn_vendor_extension' : None ,
348- u'vendor' : None ,
349- }
350- ],
351- u'memory' : {
352- u'total' : u'8675309' ,
353- u'physical_mb' : u'8675'
354- },
355- }, content ['inventory' ])
356- self .assertFalse (self .api_client .use_ramdisk_api )
357-
358- def test_do_lookup_fallback_not_found (self ):
359- self ._test_do_lookup_fallback (error_code = requests .codes .NOT_FOUND )
360-
361- def test_do_lookup_fallback_unauthorized (self ):
362- self ._test_do_lookup_fallback (error_code = requests .codes .UNAUTHORIZED )
363-
364- def test_do_lookup_fallback_not_acceptable (self ):
365- self ._test_do_lookup_fallback (error_code = requests .codes .NOT_ACCEPTABLE )
0 commit comments