@@ -76,8 +76,7 @@ def setUp(self):
76
76
self .htx_rpm_link = self .conf .args .htx_rpm_link
77
77
78
78
self .ssh_host = OpTestSSH (self .host_ip , self .host_user , self .host_password )
79
- self .ssh_host .set_system (self .conf .system ())
80
-
79
+ self .ssh_host .set_system (self .conf .system ())
81
80
path = "/usr/lpp/htx/mdt/%s" % self .mdt_file
82
81
res = self .ssh_host .run_command ("if [ -f %s ];then echo 'true';else echo 'false';fi" % path )
83
82
if 'false' in res :
@@ -111,11 +110,12 @@ def install_latest_htx_rpm(self):
111
110
if distro_pattern in htx_rpm ]
112
111
distro_specific_htx_versions .sort (reverse = True )
113
112
self .latest_htx_rpm = distro_specific_htx_versions [0 ]
114
-
115
- if "error:" in self .con .run_command ('rpm -ivh --nodeps %s%s '
116
- '--force' % (self .htx_rpm_link ,
117
- self .latest_htx_rpm
118
- ), timeout = 180 ):
113
+ cmd_wget = ('wget %s%s --no-check-certificate'
114
+ % (self .htx_rpm_link ,
115
+ self .latest_htx_rpm ))
116
+ cmd_install = ('rpm -ivh %s --force' % self .latest_htx_rpm )
117
+ if ("ERROR:" in self .con .run_command (cmd_wget , timeout = 180 ) or
118
+ "error:" in self .con .run_command (cmd_install , timeout = 180 )):
119
119
self .fail ("Installion of rpm failed" )
120
120
121
121
def setup_htx (self ):
@@ -132,14 +132,14 @@ def setup_htx(self):
132
132
packages .extend (['libncurses6' , 'gcc-c++' ,
133
133
'ncurses-devel' , 'tar' , 'wget' ])
134
134
else :
135
- self .fail ("Test not supported in %s" % host_distro_name )
135
+ self .fail ("Test not supported in %s" % self . host_distro_name )
136
136
if self .host_distro_name == 'rhel' :
137
137
self .installer = "yum install"
138
138
elif self .host_distro_name == 'sles' :
139
139
self .installer = "zypper install"
140
140
log .debug ("Installing packages" )
141
141
for pkg in packages :
142
- self .con .run_command ("%s %s -y " % (self .installer , pkg ))
142
+ self .con .run_command ("%s -y %s " % (self .installer , pkg ))
143
143
144
144
ins_htx = self .con .run_command_ignore_fail ('rpm -qa | grep htx' )
145
145
if ins_htx :
@@ -205,18 +205,19 @@ def htx_bootme_test(self):
205
205
if not self .wait_for_reboot_completion (self .cv_HOST .ip ):
206
206
log .debug ("Failed to confirm system reboot within the timeout period. Check the system manually." )
207
207
break
208
+ time .sleep (15 )
208
209
self .con = self .cv_SYSTEM .cv_HOST .get_ssh_connection ()
209
210
time .sleep (10 )
210
211
for j in range (5 ):
211
212
cmd = 'htxcmdline -query -mdt %s' % self .mdt_file
212
213
res = self .con .run_command_ignore_fail (cmd , timeout = 60 )
213
- if ("/usr/lpp/htx/mdt/mdt.all " ) in res [2 ]:
214
+ if ("/usr/lpp/htx/mdt/" ) in res [2 ]:
214
215
break
215
216
else :
216
217
time .sleep (10 )
217
218
log .debug ("Mdt start is still in progress" )
218
219
self .con .run_command (cmd )
219
- htxerr_file = self .ssh_host .run_command ('wc -c {}' .format ("/tmp/htx/htxerr" ))
220
+ htxerr_file = self .con .run_command ('wc -c {}' .format ("/tmp/htx/htxerr" ))
220
221
if int (htxerr_file [0 ].split ()[0 ]) != 0 :
221
222
self .fail ("check error logs for exact error and failure" )
222
223
log .info ("Reboot cycle %s completed successfully" % (i + 1 ))
@@ -284,24 +285,24 @@ def htx_stop(self):
284
285
self .suspend_all_block_device ()
285
286
286
287
log .debug ("shutting down the %s " , self .mdt_file )
287
- cmd = 'htxcmdline -shutdown -mdt %s' % self .mdt_file
288
- self .con .run_command (cmd )
288
+ cmd_shutdown = 'htxcmdline -shutdown -mdt %s' % self .mdt_file
289
+ self .con .run_command (cmd_shutdown )
289
290
290
291
cmd = '/usr/lpp/htx/etc/scripts/htx.d status'
291
292
daemon_state = self .con .run_command (cmd )
292
293
if 'running' in daemon_state [- 1 ]:
293
294
self .con .run_command ('/usr/lpp/htx/etc/scripts/htxd_shutdown' )
294
295
295
296
if self .current_test_case == "HtxBootme_NicDevices" :
297
+ self .ssh .run_command (cmd_shutdown )
296
298
self .ip_restore_host ()
297
299
self .ip_restore_peer ()
298
300
299
301
def teardown (self ):
300
302
"""
301
303
close the session to the console
302
304
"""
303
- if self .console_thread .isAlive ():
304
- self .console_thread .console_terminate ()
305
+ self .console_thread .console_terminate ()
305
306
306
307
class HtxBootme_AllMdt (OpTestHtxBootmeIO , unittest .TestCase ):
307
308
"""
@@ -453,3 +454,233 @@ def get_mpath_from_dm(self, dm_id):
453
454
for mpath in mpaths :
454
455
if dm_id in mpath :
455
456
return mpath .split ()[- 1 ]
457
+
458
+ class HtxBootme_NicDevices (OpTestHtxBootmeIO , unittest .TestCase ):
459
+ """
460
+ The Test case is to run htx bootme on Network device net.mdt
461
+ """
462
+ def setUp (self ):
463
+ super (HtxBootme_NicDevices , self ).setUp ()
464
+
465
+ self .current_test_case = "HtxBootme_NicDevices"
466
+ self .host_intfs = []
467
+ self .peer_ip = self .conf .args .peer_public_ip
468
+ self .peer_user = self .conf .args .peer_user
469
+ self .peer_password = self .conf .args .peer_password
470
+ devices = self .conf .args .htx_host_interfaces
471
+ if devices :
472
+ interfaces = self .ssh_host .run_command ('ls /sys/class/net' )
473
+ if interfaces :
474
+ interfaces = interfaces [0 ].split ()
475
+ for device in devices .split (" " ):
476
+ if device in interfaces :
477
+ self .host_intfs .append (device )
478
+ else :
479
+ self .fail ("Please check the network device" )
480
+ self .peer_intfs = self .conf .args .peer_interfaces .split (" " )
481
+ self .mdt_file = self .conf .args .mdt_file
482
+ self .query_cmd = "htxcmdline -query -mdt %s" % self .mdt_file
483
+
484
+ self .ssh = OpTestSSH (self .peer_ip , self .peer_user , self .peer_password )
485
+ self .ssh .set_system (self .conf .system ())
486
+
487
+ # Flush out the ip addresses on host and peer before starting the test
488
+ self .ip_restore_host ()
489
+ self .ip_restore_peer ()
490
+
491
+ # Get distro details of peer lpar
492
+ self .get_peer_distro ()
493
+ self .get_peer_distro_version ()
494
+
495
+ def get_peer_distro (self ):
496
+ """
497
+ Get the distro name that is installed on peer lpar
498
+ """
499
+ res = self .ssh .run_command ("cat /etc/os-release" )
500
+ if "Ubuntu" in res [0 ] or "Ubuntu" in res [1 ]:
501
+ self .peer_distro = "ubuntu"
502
+ elif 'Red Hat' in res [0 ] or 'Red Hat' in res [1 ]:
503
+ self .peer_distro = "rhel"
504
+ elif 'SLES' in res [0 ] or 'SLES' in res [1 ]:
505
+ self .peer_distro = "sles"
506
+ else :
507
+ self .peer_distro = "unknown"
508
+
509
+ def get_peer_distro_version (self ):
510
+ """
511
+ Get the distro version that is installed on peer lpar
512
+ """
513
+ res = self .ssh .run_command ("cat /etc/os-release" )
514
+ for line in res :
515
+ if 'VERSION_ID' in line :
516
+ self .peer_distro_version = line .split ('=' )[1 ].strip ('"' ).split ('.' )[0 ]
517
+
518
+ def update_host_peer_names (self ):
519
+ """
520
+ Update hostname & IP of both Host & Peer in /etc/hosts on both machines.
521
+ """
522
+
523
+ res = self .ssh_host .run_command ("nslookup %s" % self .host_ip )
524
+ self .host_name = re .search (r'name = (.+)\.' , res [0 ]).group (1 )
525
+ res = self .ssh .run_command ("nslookup %s" % self .peer_ip )
526
+ self .peer_name = re .search (r'name = (.+)\.' , res [0 ]).group (1 )
527
+
528
+ self .hosts_file = "/etc/hosts"
529
+
530
+ log .info ("Updating hostname of both Host & Peer in %s file" , self .hosts_file )
531
+
532
+ self .delete_unwanted_entries ()
533
+
534
+ # Update for Host
535
+ existing_entries_host = set (self .ssh_host .run_command (f"cat { self .hosts_file } " ))
536
+ for ip , name in [(self .host_ip , self .host_name )]:
537
+ line = f"{ ip } { name } "
538
+ if line not in existing_entries_host :
539
+ log .info ("Adding missing entry on Host: %s" , line )
540
+ self .ssh_host .run_command (f'echo "{ line } " | sudo tee -a { self .hosts_file } ' )
541
+ else :
542
+ log .info ("Entry exists on Host: %s" , line )
543
+
544
+ # Update for Peer
545
+ existing_entries_peer = set (self .ssh .run_command (f"cat { self .hosts_file } " ))
546
+ for ip , name in [(self .peer_ip , self .peer_name )]:
547
+ line = f"{ ip } { name } "
548
+ if line not in existing_entries_peer :
549
+ log .info ("Adding missing entry on Peer: %s" , line )
550
+ self .ssh .run_command (f'echo "{ line } " | sudo tee -a { self .hosts_file } ' )
551
+ else :
552
+ log .info ("Entry exists on Peer: %s" , line )
553
+
554
+ def delete_unwanted_entries (self ):
555
+ """
556
+ Deletes entries from /etc/hosts that match 'netXX.XX' pattern based on host and peer IPs.
557
+ """
558
+ host_last_two = "." .join (self .host_ip .split ("." )[- 2 :])
559
+ peer_last_two = "." .join (self .peer_ip .split ("." )[- 2 :])
560
+
561
+ pattern_host = rf"net{ host_last_two } "
562
+ pattern_peer = rf"net{ peer_last_two } "
563
+
564
+ sed_command = f"sudo sed -i.bak -E '/{ pattern_host } /d; /{ pattern_peer } /d' { self .hosts_file } "
565
+
566
+ # Run on host
567
+ log .debug ("Running on Host : %s" % sed_command )
568
+ self .ssh_host .run_command (sed_command )
569
+
570
+ # Run on peer
571
+ log .debug ("Running on Peer : %s" % sed_command )
572
+ self .ssh .run_command (sed_command )
573
+
574
+ log .info ("Deletion complete." )
575
+
576
+ def htx_configure_net (self ):
577
+ """
578
+ The function is to setup network topology for htx run
579
+ on both host and peer.
580
+ The build_net multisystem <hostname/IP> command
581
+ configures the netwrok interfaces on both host and peer Lpars with
582
+ some random net_ids and check pingum and also
583
+ starts the htx deamon for net.mdt
584
+ There is no need to explicitly start the htx deamon, create/select
585
+ and activate for net.mdt
586
+ """
587
+ log .debug ("Setting up the Network configuration on Host and Peer" )
588
+
589
+ cmd = "build_net multisystem %s" % self .peer_ip
590
+
591
+ # try up to 3 times if the command fails to set the network interfaces
592
+ for i in range (3 ):
593
+ output = self .con .run_command (cmd , timeout = 900 )
594
+ if "All networks ping Ok" in output :
595
+ log .debug ("Htx configuration was successful on host and peer" )
596
+ break
597
+ output = self .con .run_command ('pingum' )
598
+ if "All networks ping Ok" not in output :
599
+ self .fail ("Failed to set htx configuration on host and peer" )
600
+
601
+ def start_htx_run (self ):
602
+ super (HtxBootme_NicDevices , self ).start_htx_run ()
603
+
604
+ self .update_host_peer_names ()
605
+ self .htx_configure_net ()
606
+ log .debug ("Running the HTX for %s on Host" , self .mdt_file )
607
+ cmd = "htxcmdline -run -mdt %s" % self .mdt_file
608
+ self .con .run_command (cmd )
609
+
610
+ log .debug ("Running the HTX for %s on Peer" , self .mdt_file )
611
+ self .ssh .run_command (cmd )
612
+
613
+ def install_latest_htx_rpm (self ):
614
+ super (HtxBootme_NicDevices , self ).install_latest_htx_rpm ()
615
+
616
+ if self .host_distro_name == "SuSE" :
617
+ self .host_distro_name = "sles"
618
+ elif self .peer_distro == "SuSE" :
619
+ self .peer_distro = "sles"
620
+ host_distro_pattern = "%s%s" % (
621
+ self .host_distro_name ,
622
+ self .host_distro_version )
623
+ peer_distro_pattern = "%s%s" % (
624
+ self .peer_distro ,
625
+ self .peer_distro_version )
626
+ patterns = [host_distro_pattern , peer_distro_pattern ]
627
+ for pattern in patterns :
628
+ temp_string = subprocess .run (
629
+ "curl --silent %s" % (self .htx_rpm_link ),
630
+ shell = True , stdout = subprocess .PIPE ,
631
+ stderr = subprocess .PIPE , timeout = 30 )
632
+ matching_htx_versions = re .findall (
633
+ r"(?<=\>)htx\w*[-]\d*[-]\w*[.]\w*[.]\w*" , str (temp_string ))
634
+ distro_specific_htx_versions = [htx_rpm
635
+ for htx_rpm
636
+ in matching_htx_versions
637
+ if pattern in htx_rpm ]
638
+ distro_specific_htx_versions .sort (reverse = True )
639
+ self .latest_htx_rpm = distro_specific_htx_versions [0 ]
640
+
641
+ cmd_wget = ('wget %s%s --no-check-certificate'
642
+ % (self .htx_rpm_link ,
643
+ self .latest_htx_rpm ))
644
+ cmd_install = ('rpm -ivh %s --force' % self .latest_htx_rpm )
645
+ if host_distro_pattern == peer_distro_pattern :
646
+ if ("ERROR:" in self .con .run_command (cmd_wget , timeout = 180 ) or
647
+ "error:" in self .con .run_command (cmd_install , timeout = 180 )):
648
+ self .fail ("Installion of rpm failed" )
649
+ if ("ERROR:" in self .ssh .run_command (cmd_wget , timeout = 180 ) or
650
+ "error:" in self .ssh .run_command (cmd_install , timeout = 180 )):
651
+ self .fail ("Unable to install the package %s %s"
652
+ " on peer machine" % (self .htx_rpm_link ,
653
+ self .latest_htx_rpm ))
654
+ break
655
+
656
+ if pattern == host_distro_pattern :
657
+ if ("ERROR:" in self .con .run_command (cmd_wget , timeout = 180 ) or
658
+ "error:" in self .con .run_command (cmd_install , timeout = 180 )):
659
+ self .fail ("Installion of rpm failed" )
660
+
661
+ if pattern == peer_distro_pattern :
662
+ if ("ERROR:" in self .ssh .run_command (cmd_wget , timeout = 180 ) or
663
+ "error:" in self .ssh .run_command (cmd_install , timeout = 180 )):
664
+ self .fail ("Unable to install the package %s %s"
665
+ " on peer machine" % (self .htx_rpm_link ,
666
+ self .latest_htx_rpm ))
667
+
668
+ def ip_restore_host (self ):
669
+ '''
670
+ restoring ip for host
671
+ '''
672
+ for interface in self .host_intfs :
673
+ cmd = "ip addr flush %s" % interface
674
+ self .con .run_command (cmd )
675
+ cmd = "ip link set dev %s up" % interface
676
+ self .con .run_command (cmd )
677
+
678
+ def ip_restore_peer (self ):
679
+ '''
680
+ config ip for peer
681
+ '''
682
+ for interface in self .peer_intfs :
683
+ cmd = "ip addr flush %s" % interface
684
+ self .ssh .run_command (cmd )
685
+ cmd = "ip link set dev %s up" % interface
686
+ self .ssh .run_command (cmd )
0 commit comments