32
32
import time
33
33
import sys
34
34
import subprocess
35
- import paramiko
36
35
import itertools
37
36
from datetime import datetime
38
37
@@ -68,13 +67,20 @@ def setUp(self):
68
67
if 'ppc64' not in res [- 1 ]:
69
68
self .fail ("Platform does not support HTX tests" )
70
69
70
+ self .host_ip = self .conf .args .host_ip
71
+ self .host_user = self .conf .args .host_user
71
72
self .host_password = self .conf .args .host_password
72
73
self .mdt_file = self .conf .args .mdt_file
73
74
self .time_limit = int (self .conf .args .time_limit )
74
75
self .boot_count = int (self .conf .args .boot_count )
75
76
self .htx_rpm_link = self .conf .args .htx_rpm_link
77
+
78
+ self .ssh_host = OpTestSSH (self .host_ip , self .host_user , self .host_password )
79
+ self .ssh_host .set_system (self .conf .system ())
76
80
77
- if not self .execute_remote_command ('test -e {}' .format (path )):
81
+ path = "/usr/lpp/htx/mdt/%s" % self .mdt_file
82
+ res = self .ssh_host .run_command ("if [ -f %s ];then echo 'true';else echo 'false';fi" % path )
83
+ if 'false' in res :
78
84
log .debug ("MDT file %s not found due to config" % self .mdt_file )
79
85
80
86
self .host_distro_name = self .util .distro_name ()
@@ -140,9 +146,8 @@ def setup_htx(self):
140
146
for rpm in ins_htx :
141
147
self .con .run_command_ignore_fail ("rpm -e %s" % rpm , timeout = 30 )
142
148
log .debug ("Deleted old htx rpm package from host" )
143
- if self .execute_remote_command ('test -e {}' .format ('/usr/lpp/htx' )):
144
- if not self .execute_remote_command ('rm -rf {}' .format ('/usr/lpp/htx' )):
145
- self .fail ("Failed to delete the file at /usr/lpp/htx" )
149
+ self .ssh_host .run_command ("if [ -d %s ];then rm -rf %s;fi" %
150
+ ('/usr/lpp/htx' , '/usr/lpp/htx' ), timeout = 60 )
146
151
if self .current_test_case == "HtxBootme_NicDevices" :
147
152
peer_ins_htx = self .ssh .run_command_ignore_fail ('rpm -qa | grep htx' )
148
153
if peer_ins_htx :
@@ -176,9 +181,8 @@ def htx_check(self):
176
181
Checks if HTX is running, and if no errors.
177
182
"""
178
183
log .debug ("HTX Error logs" )
179
- file_size = self .check_remote_file_size_command ('wc -c {}' .format ("/tmp/htx/htxerr" ))
180
- file_size = int (file_size .split ()[0 ])
181
- if file_size != 0 :
184
+ file_size = self .ssh_host .run_command ('wc -c {}' .format ("/tmp/htx/htxerr" ))
185
+ if int (file_size [0 ].split ()[0 ]) != 0 :
182
186
self .fail ("check errorlogs for exact error and failure" )
183
187
cmd = 'htxcmdline -query -mdt %s' % self .mdt_file
184
188
res = self .con .run_command (cmd )
@@ -212,8 +216,8 @@ def htx_bootme_test(self):
212
216
time .sleep (10 )
213
217
log .debug ("Mdt start is still in progress" )
214
218
self .con .run_command (cmd )
215
- htxerr_file = self .check_remote_file_size_command ('wc -c {}' .format ("/tmp/htx/htxerr" ))
216
- if int (htxerr_file .split ()[0 ]) != 0 :
219
+ htxerr_file = self .ssh_host . run_command ('wc -c {}' .format ("/tmp/htx/htxerr" ))
220
+ if int (htxerr_file [ 0 ] .split ()[0 ]) != 0 :
217
221
self .fail ("check error logs for exact error and failure" )
218
222
log .info ("Reboot cycle %s completed successfully" % (i + 1 ))
219
223
reboot_time = time .time () - start_time
@@ -246,27 +250,6 @@ def is_system_online(self):
246
250
i_try -= 1
247
251
return False
248
252
249
- def check_remote_file_size_command (self , command ):
250
- """
251
- Creates a new SSH client connection, executes a command,
252
- and then closes the connection.
253
-
254
- :param command: Command to execute on the remote machine.
255
- :return: Command output as a string.
256
- or Returns Execption error msg if there was an error.
257
- """
258
- try :
259
- client = paramiko .SSHClient ()
260
- client .set_missing_host_key_policy (paramiko .AutoAddPolicy ())
261
- client .connect (self .cv_HOST .ip , 22 , self .cv_HOST .user , self .host_password )
262
- stdin , stdout , stderr = client .exec_command (command )
263
- output = stdout .read ().decode ().strip ()
264
- client .close ()
265
- return output
266
- except Exception as e :
267
- print (f"An error occurred: { e } " )
268
- return e
269
-
270
253
def wait_for_reboot_completion (self , ip_addr , timeout = 500 ):
271
254
"""
272
255
Wait for the system to become available after reboot.
@@ -367,13 +350,12 @@ def setUp(self):
367
350
368
351
if not self .all and self .block_devices is None :
369
352
self .fail ("Needs the block devices to run the HTX" )
370
- if self .all :
353
+ if self .all == "True" :
371
354
self .block_device = ""
372
355
else :
373
356
self .block_device = []
374
357
for dev in self .block_devices .split ():
375
- dev_path = self .get_absolute_disk_path (dev )
376
- dev_base = self .execute_remote_command ('basename $(realpath {})' .format (dev_path ))
358
+ dev_base = self .ssh_host .run_command ('basename $(realpath {})' .format (dev ))[0 ]
377
359
if 'dm' in dev_base :
378
360
dev_base = self .get_mpath_from_dm (dev_base )
379
361
self .block_device .append (dev_base )
@@ -383,7 +365,8 @@ def start_htx_run(self):
383
365
super (HtxBootme_BlockDevice , self ).start_htx_run ()
384
366
385
367
path = "/usr/lpp/htx/mdt/%s" % self .mdt_file
386
- if self .execute_remote_command ('test -e {}' .format (path )):
368
+ res = self .ssh_host .run_command ("if [ -d %s ];then echo 'true';else echo 'false';fi" % path )
369
+ if 'true' in res :
387
370
self .fail (f"MDT file { self .mdt_file } not found" )
388
371
389
372
log .debug ("selecting the mdt file " )
@@ -469,53 +452,4 @@ def get_mpath_from_dm(self, dm_id):
469
452
raise MPException (f"Multipathd Command Failed : { ex } " )
470
453
for mpath in mpaths :
471
454
if dm_id in mpath :
472
- return mpath .split ()[1 ]
473
-
474
- def get_all_disk_paths (self ):
475
- """
476
- Returns all available disk names and alias on this system
477
-
478
- This will get all the sysfs disks name entries by its device
479
- node name, by-uuid, by-id and by-path, irrespective of any
480
- platform and device type
481
-
482
- :returns: a list of all disk path names
483
- :rtype: list of str
484
- """
485
- disk_list = abs_path = []
486
- for path in [
487
- "/dev" ,
488
- "/dev/mapper" ,
489
- "/dev/disk/by-id" ,
490
- "/dev/disk/by-path" ,
491
- "/dev/disk/by-uuid" ,
492
- "/dev/disk/by-partuuid" ,
493
- "/dev/disk/by-partlabel" ,
494
- ]:
495
- if self .execute_remote_command ('test -e {}' .format (path )):
496
- directory = self .execute_remote_command ('ls -l {}' .format (path ))
497
- for device in directory :
498
- abs_path .append (path + '/' + device )
499
- disk_list .extend (abs_path )
500
- return disk_list
501
-
502
- def get_absolute_disk_path (self , device ):
503
- """
504
- Returns absolute device path of given disk
505
-
506
- This will get actual disks path of given device, it can take
507
- node name, by-uuid, by-id and by-path, irrespective of any
508
- platform and device type
509
-
510
- :param device: disk name or disk alias names sda or scsi-xxx
511
- :type device: str
512
-
513
- :returns: the device absolute path name
514
- :rtype: bool
515
- """
516
- if not self .execute_remote_command ('test -e {}' .format (device )):
517
- for dev_path in self .get_all_disk_paths ():
518
- dev_base = self .execute_remote_command ('basename $(realpath {})' .format (dev_path ))
519
- if device == dev_base :
520
- return dev_path
521
- return device
455
+ return mpath .split ()[- 1 ]
0 commit comments