@@ -303,7 +303,7 @@ def test_console_port_provider_get_line_by_device_not_found(self):
303
303
def test_console_port_info_refresh_without_session (self ):
304
304
db = Db ()
305
305
306
- port = ConsolePortInfo (db , { "LINE" : "1" })
306
+ port = ConsolePortInfo (DbUtils ( db ) , { "LINE" : "1" })
307
307
port .refresh ()
308
308
assert port .busy
309
309
assert port .session_pid == "223"
@@ -313,15 +313,15 @@ def test_console_port_info_refresh_without_session(self):
313
313
def test_console_port_info_refresh_without_session_idle (self ):
314
314
db = Db ()
315
315
316
- port = ConsolePortInfo (db , { "LINE" : "1" })
316
+ port = ConsolePortInfo (DbUtils ( db ) , { "LINE" : "1" })
317
317
port .refresh ()
318
318
assert port .busy == False
319
319
320
320
@mock .patch ('consutil.lib.SysInfoProvider.get_active_console_process_info' , mock .MagicMock (return_value = ("1" , "223" , "2020/11/2" )))
321
321
def test_console_port_info_refresh_with_session (self ):
322
322
db = Db ()
323
323
324
- port = ConsolePortInfo (db , { "LINE" : "1" })
324
+ port = ConsolePortInfo (DbUtils ( db ) , { "LINE" : "1" })
325
325
port ._session = ConsoleSession (port , mock .MagicMock (pid = "223" ))
326
326
print (port )
327
327
@@ -334,7 +334,7 @@ def test_console_port_info_refresh_with_session(self):
334
334
def test_console_port_info_refresh_with_session_line_mismatch (self ):
335
335
db = Db ()
336
336
337
- port = ConsolePortInfo (db , { "LINE" : "1" })
337
+ port = ConsolePortInfo (DbUtils ( db ) , { "LINE" : "1" })
338
338
port ._session = ConsoleSession (port , mock .MagicMock (pid = "223" ))
339
339
print (port )
340
340
@@ -347,7 +347,7 @@ def test_console_port_info_refresh_with_session_line_mismatch(self):
347
347
def test_console_port_info_refresh_with_session_process_ended (self ):
348
348
db = Db ()
349
349
350
- port = ConsolePortInfo (db , { "LINE" : "1" })
350
+ port = ConsolePortInfo (DbUtils ( db ) , { "LINE" : "1" })
351
351
port ._session = ConsoleSession (port , mock .MagicMock (pid = "223" ))
352
352
print (port )
353
353
@@ -356,23 +356,23 @@ def test_console_port_info_refresh_with_session_process_ended(self):
356
356
357
357
def test_console_port_info_connect_state_busy (self ):
358
358
db = Db ()
359
- port = ConsolePortInfo (db , { "LINE" : "1" , "CUR_STATE" : { "state" : "busy" } })
359
+ port = ConsolePortInfo (DbUtils ( db ) , { "LINE" : "1" , "CUR_STATE" : { "state" : "busy" } })
360
360
361
361
port .refresh = mock .MagicMock (return_value = None )
362
362
with pytest .raises (LineBusyError ):
363
363
port .connect ()
364
364
365
365
def test_console_port_info_connect_invalid_config (self ):
366
366
db = Db ()
367
- port = ConsolePortInfo (db , { "LINE" : "1" , "CUR_STATE" : { "state" : "idle" } })
367
+ port = ConsolePortInfo (DbUtils ( db ) , { "LINE" : "1" , "CUR_STATE" : { "state" : "idle" } })
368
368
369
369
port .refresh = mock .MagicMock (return_value = None )
370
370
with pytest .raises (InvalidConfigurationError ):
371
371
port .connect ()
372
372
373
373
def test_console_port_info_connect_device_busy (self ):
374
374
db = Db ()
375
- port = ConsolePortInfo (db , { "LINE" : "1" , "baud_rate" : "9600" , "CUR_STATE" : { "state" : "idle" } })
375
+ port = ConsolePortInfo (DbUtils ( db ) , { "LINE" : "1" , "baud_rate" : "9600" , "CUR_STATE" : { "state" : "idle" } })
376
376
377
377
port .refresh = mock .MagicMock (return_value = None )
378
378
mock_proc = mock .MagicMock (spec = subprocess .Popen )
@@ -384,7 +384,7 @@ def test_console_port_info_connect_device_busy(self):
384
384
385
385
def test_console_port_info_connect_connection_fail (self ):
386
386
db = Db ()
387
- port = ConsolePortInfo (db , { "LINE" : "1" , "baud_rate" : "9600" , "CUR_STATE" : { "state" : "idle" } })
387
+ port = ConsolePortInfo (DbUtils ( db ) , { "LINE" : "1" , "baud_rate" : "9600" , "CUR_STATE" : { "state" : "idle" } })
388
388
389
389
port .refresh = mock .MagicMock (return_value = None )
390
390
mock_proc = mock .MagicMock (spec = subprocess .Popen )
@@ -396,7 +396,7 @@ def test_console_port_info_connect_connection_fail(self):
396
396
397
397
def test_console_port_info_connect_success (self ):
398
398
db = Db ()
399
- port = ConsolePortInfo (db , { "LINE" : "1" , "baud_rate" : "9600" , "CUR_STATE" : { "state" : "idle" } })
399
+ port = ConsolePortInfo (DbUtils ( db ) , { "LINE" : "1" , "baud_rate" : "9600" , "CUR_STATE" : { "state" : "idle" } })
400
400
401
401
port .refresh = mock .MagicMock (return_value = None )
402
402
mock_proc = mock .MagicMock (spec = subprocess .Popen , pid = "223" )
@@ -409,22 +409,22 @@ def test_console_port_info_connect_success(self):
409
409
410
410
def test_console_port_info_clear_session_line_not_busy (self ):
411
411
db = Db ()
412
- port = ConsolePortInfo (db , { "LINE" : "1" , "baud_rate" : "9600" , "CUR_STATE" : { "state" : "idle" } })
412
+ port = ConsolePortInfo (DbUtils ( db ) , { "LINE" : "1" , "baud_rate" : "9600" , "CUR_STATE" : { "state" : "idle" } })
413
413
414
414
port .refresh = mock .MagicMock (return_value = None )
415
415
assert not port .clear_session ()
416
416
417
417
@mock .patch ('consutil.lib.SysInfoProvider.run_command' , mock .MagicMock (return_value = None ))
418
418
def test_console_port_info_clear_session_with_state_db (self ):
419
419
db = Db ()
420
- port = ConsolePortInfo (db , { "LINE" : "1" , "baud_rate" : "9600" , "CUR_STATE" : { "state" : "busy" , "pid" : "223" } })
420
+ port = ConsolePortInfo (DbUtils ( db ) , { "LINE" : "1" , "baud_rate" : "9600" , "CUR_STATE" : { "state" : "busy" , "pid" : "223" } })
421
421
422
422
port .refresh = mock .MagicMock (return_value = None )
423
423
assert port .clear_session ()
424
424
425
425
def test_console_port_info_clear_session_with_existing_session (self ):
426
426
db = Db ()
427
- port = ConsolePortInfo (db , { "LINE" : "1" , "baud_rate" : "9600" , "CUR_STATE" : { "state" : "busy" } })
427
+ port = ConsolePortInfo (DbUtils ( db ) , { "LINE" : "1" , "baud_rate" : "9600" , "CUR_STATE" : { "state" : "busy" } })
428
428
port ._session = ConsoleSession (port , None )
429
429
port ._session .close = mock .MagicMock (return_value = None )
430
430
port .refresh = mock .MagicMock (return_value = None )
@@ -538,6 +538,7 @@ def setup_class(cls):
538
538
3 9600 Enabled - -
539
539
"""
540
540
@mock .patch ('consutil.lib.SysInfoProvider.init_device_prefix' , mock .MagicMock (return_value = None ))
541
+ @mock .patch ('consutil.lib.SysInfoProvider.list_active_console_processes' , mock .MagicMock (return_value = { "2" : ("223" , "Wed Mar 6 08:31:35 2019" )}))
541
542
def test_show (self ):
542
543
runner = CliRunner ()
543
544
db = Db ()
@@ -556,6 +557,46 @@ def test_show(self):
556
557
assert result .exit_code == 0
557
558
assert result .output == TestConsutilShow .expect_show_output
558
559
560
+ @mock .patch ('consutil.lib.SysInfoProvider.init_device_prefix' , mock .MagicMock (return_value = None ))
561
+ @mock .patch ('consutil.lib.SysInfoProvider.list_active_console_processes' , mock .MagicMock (return_value = { "2" : ("223" , "Wed Mar 6 08:31:35 2019" )}))
562
+ def test_show_stale_idle_to_busy (self ):
563
+ runner = CliRunner ()
564
+ db = Db ()
565
+ db .cfgdb .set_entry ("CONSOLE_PORT" , 1 , { "remote_device" : "switch1" , "baud_rate" : "9600" })
566
+ db .cfgdb .set_entry ("CONSOLE_PORT" , 2 , { "remote_device" : "switch2" , "baud_rate" : "9600" })
567
+ db .cfgdb .set_entry ("CONSOLE_PORT" , 3 , { "baud_rate" : "9600" , "flow_control" : "1" })
568
+
569
+ # use '--brief' option to avoid access system
570
+ result = runner .invoke (consutil .consutil .commands ["show" ], ['--brief' ], obj = db )
571
+ print (result .exit_code )
572
+ print (sys .stderr , result .output )
573
+ assert result .exit_code == 0
574
+ assert result .output == TestConsutilShow .expect_show_output
575
+
576
+ @mock .patch ('consutil.lib.SysInfoProvider.init_device_prefix' , mock .MagicMock (return_value = None ))
577
+ @mock .patch ('consutil.lib.SysInfoProvider.list_active_console_processes' , mock .MagicMock (return_value = { "2" : ("223" , "Wed Mar 6 08:31:35 2019" )}))
578
+ def test_show_stale_busy_to_idle (self ):
579
+ runner = CliRunner ()
580
+ db = Db ()
581
+ db .cfgdb .set_entry ("CONSOLE_PORT" , 1 , { "remote_device" : "switch1" , "baud_rate" : "9600" })
582
+ db .cfgdb .set_entry ("CONSOLE_PORT" , 2 , { "remote_device" : "switch2" , "baud_rate" : "9600" })
583
+ db .cfgdb .set_entry ("CONSOLE_PORT" , 3 , { "baud_rate" : "9600" , "flow_control" : "1" })
584
+
585
+ db .db .set (db .db .STATE_DB , "CONSOLE_PORT|1" , "state" , "busy" )
586
+ db .db .set (db .db .STATE_DB , "CONSOLE_PORT|1" , "pid" , "222" )
587
+ db .db .set (db .db .STATE_DB , "CONSOLE_PORT|1" , "start_time" , "Wed Mar 6 08:31:35 2019" )
588
+
589
+ db .db .set (db .db .STATE_DB , "CONSOLE_PORT|2" , "state" , "busy" )
590
+ db .db .set (db .db .STATE_DB , "CONSOLE_PORT|2" , "pid" , "223" )
591
+ db .db .set (db .db .STATE_DB , "CONSOLE_PORT|2" , "start_time" , "Wed Mar 6 08:31:35 2019" )
592
+
593
+ # use '--brief' option to avoid access system
594
+ result = runner .invoke (consutil .consutil .commands ["show" ], ['--brief' ], obj = db )
595
+ print (result .exit_code )
596
+ print (sys .stderr , result .output )
597
+ assert result .exit_code == 0
598
+ assert result .output == TestConsutilShow .expect_show_output
599
+
559
600
class TestConsutilConnect (object ):
560
601
@classmethod
561
602
def setup_class (cls ):
0 commit comments