Пример #1
0
def _write_data_to_iscsi(control_server_ip, control_username, control_password,
                         initiator_ip, initiator_username, initiator_password,
                         need_mk, create_data, disk, mount_point, file_name):
    time.sleep(10)
    cmd = ''
    if need_mk:
        cmd += 'echo yes | mkfs -t ext3 -c %s; sleep 10; ' % disk

    cmd += 'mount %s %s; sleep 10; ' % (disk, mount_point)

    if create_data:
        cmd += 'touch %s/%s; ' % (mount_point, file_name)

    # cmd += 'ls %s/%s; ' % (mount_point, file_name)
    cmd += 'ls %s' % mount_point

    find, buff = utils.sshclient_execmd(control_server_ip, control_username,
                                        control_password, initiator_ip,
                                        initiator_username, initiator_password,
                                        cmd, file_name)

    if find:
        return True
    else:
        return False
Пример #2
0
 def clean_iscsi_dirty(self, control_server_ip, control_username,
                       control_password, initiator_ip, initiator_username,
                       initiator_password):
     cmd = 'umount %s' % self.mulpath_mountpoint
     find, buff = utils.sshclient_execmd(control_server_ip,
                                         control_username, control_password,
                                         initiator_ip, initiator_username,
                                         initiator_password, cmd)
Пример #3
0
 def stop_iscsi_tgt(self, control_server_ip, control_username,
                    control_password, initiator_ip, initiator_username,
                    initiator_password):
     cmd = 'service tgtd stop'
     find, buff = utils.sshclient_execmd(control_server_ip,
                                         control_username, control_password,
                                         initiator_ip, initiator_username,
                                         initiator_password, cmd)
Пример #4
0
 def get_iscsi_multipath(self, control_server_ip, control_username,
                         control_password, initiator_ip, initiator_username,
                         initiator_password):
     cmd = 'multipath -l; '
     find, buff = utils.sshclient_execmd(control_server_ip,
                                         control_username, control_password,
                                         initiator_ip, initiator_username,
                                         initiator_password, cmd)
     return find, buff
Пример #5
0
 def do_iscsi_logout(self, control_server_ip, control_username,
                     control_password, initiator_ip, initiator_username,
                     initiator_password, target_ip):
     cmd = ('iscsiadm -m node -T %s -p %s --logout; ' %
            (self.iscsi_target_name, target_ip))
     find, buff = utils.sshclient_execmd(control_server_ip,
                                         control_username, control_password,
                                         initiator_ip, initiator_username,
                                         initiator_password, cmd)
Пример #6
0
 def get_iscsi_count(self, control_server_ip, control_username,
                     control_password, initiator_ip, initiator_username,
                     initiator_password):
     retval = 0
     cmd = ('lsblk -S | wc -l; ')
     find, buff = utils.sshclient_execmd(control_server_ip,
                                         control_username, control_password,
                                         initiator_ip, initiator_username,
                                         initiator_password, cmd)
     _lines = buff.split('\n')
     retval = string.atoi(_lines[1], 10)
     return retval
Пример #7
0
 def hit_target(self, control_server_ip, control_username, control_password,
                initiator_ip, initiator_username, initiator_password):
     for i in range(len(self.iscsi_target_hostip)):
         cmd = ('iscsiadm -m discovery -t st -p %s; ' %
                self.iscsi_target_hostip[i])
         find, buff = utils.sshclient_execmd(control_server_ip,
                                             control_username,
                                             control_password, initiator_ip,
                                             initiator_username,
                                             initiator_password, cmd)
         if buff.find(self.iscsi_target_name) == -1:
             raise exceptions.TestFail("No specified target found for %s" %
                                       self.iscsi_target_hostip[i])
Пример #8
0
    def check_iscsi_dirty(self, control_server_ip, control_username,
                          control_password, initiator_ip, initiator_username,
                          initiator_password):
        cmd = 'cat %s/%s' % (self.mulpath_mountpoint, self.mulpath_filename)
        find, buff = utils.sshclient_execmd(control_server_ip,
                                            control_username, control_password,
                                            initiator_ip, initiator_username,
                                            initiator_password, cmd)
        _lines = buff.split('\n')
        if len(_lines) < 2:
            raise exceptions.TestFail("Did not get info for validation")
        info_val = self.get_chars(_lines[1])
        if self.dirtypoint == info_val:
            LOG.info("Find %s under %s!" %
                     (self.mulpath_filename, self.mulpath_mountpoint))
        else:
            raise exceptions.TestFail(
                "%s not found under %s" %
                (self.mulpath_filename, self.mulpath_mountpoint))

        cmd = 'rm -rf %s/%s' % (self.mulpath_mountpoint, self.mulpath_filename)
        find, buff = utils.sshclient_execmd(control_server_ip,
                                            control_username, control_password,
                                            initiator_ip, initiator_username,
                                            initiator_password, cmd)
        cmd = '[ -f %s/%s ] || echo removed' % (self.mulpath_mountpoint,
                                                self.mulpath_filename)
        find, buff = utils.sshclient_execmd(control_server_ip,
                                            control_username, control_password,
                                            initiator_ip, initiator_username,
                                            initiator_password, cmd)
        _lines = buff.split('\n')
        info_val = self.get_chars(_lines[1])
        if info_val == "removed":
            LOG.info("Removed %s successfully!" % self.mulpath_filename)
        else:
            raise exceptions.TestFail("Removed %s fault!" %
                                      self.mulpath_filename)
Пример #9
0
def _logout_iscsi(control_server_ip, control_username, control_password,
                  initiator_ip, initiator_username, initiator_password,
                  mount_point, target_name, target_address):
    time.sleep(10)

    if mount_point is None:
        cmd = ''
    else:
        cmd = 'umount %s; ' % mount_point
    cmd += 'iscsiadm -m node -T %s -p %s --logout; sleep 10; ' % \
           (target_name, target_address)

    _, buff = utils.sshclient_execmd(control_server_ip, control_username,
                                     control_password, initiator_ip,
                                     initiator_username, initiator_password,
                                     cmd)
Пример #10
0
def modify_file(control_server_ip, control_username, control_password,
                initiator_ip, initiator_username, initiator_password,
                file_name, old_value_list, new_value_list):
    cmd_before = 'sed -i "s/'
    cmd_after = '/g" %s; ' % file_name
    cmd = ' '

    for i in range(len(old_value_list)):
        cmd += cmd_before + old_value_list[i] + "/" + new_value_list[i] + \
               cmd_after
        LOG.info("cmd is %s" % cmd)

    _, buff = utils.sshclient_execmd(control_server_ip, control_username,
                                     control_password, initiator_ip,
                                     initiator_username, initiator_password,
                                     cmd)
    return True
Пример #11
0
def _get_disk_partition_list(control_server_ip, control_username,
                             control_password, initiator_ip,
                             initiator_username, initiator_password, is_login,
                             target_name, target_address):
    cmd = ' '
    cmd += 'iscsiadm -m discovery -t st -p %s; ' % target_address
    if is_login:
        cmd += 'iscsiadm -m node -T %s -p %s --login &&' % (target_name,
                                                            target_address)

    cmd += 'sleep 20; lsblk; '

    _, buff = utils.sshclient_execmd(control_server_ip, control_username,
                                     control_password, initiator_ip,
                                     initiator_username, initiator_password,
                                     cmd)
    return buff
Пример #12
0
    def make_iscsi_dirty(self, control_server_ip, control_username,
                         control_password, initiator_ip, initiator_username,
                         initiator_password):
        cmd = 'ls --color=never /dev/mapper/mpath*'
        find, buff = utils.sshclient_execmd(control_server_ip,
                                            control_username, control_password,
                                            initiator_ip, initiator_username,
                                            initiator_password, cmd)
        _lines = buff.split('\n')
        if len(_lines) < 2:
            raise exceptions.TestFail("Did not get any mapper device")
        mapper_device = self.get_chars(_lines[1])
        if len(mapper_device) == 0:
            raise exceptions.TestFail("Did not get a valid mapper device name")

        cmd = 'mkdir %s' % (mapper_device)
        find, buff = utils.sshclient_execmd(control_server_ip,
                                            control_username, control_password,
                                            initiator_ip, initiator_username,
                                            initiator_password, cmd)
        cmd = 'mkfs.ext4 %s' % mapper_device
        find, buff = utils.sshclient_execmd(control_server_ip,
                                            control_username, control_password,
                                            initiator_ip, initiator_username,
                                            initiator_password, cmd)
        cmd = 'mount %s %s' % (mapper_device, self.mulpath_mountpoint)
        find, buff = utils.sshclient_execmd(control_server_ip,
                                            control_username, control_password,
                                            initiator_ip, initiator_username,
                                            initiator_password, cmd)
        cmd = 'echo "%s" > %s/%s' % (self.dirtypoint, self.mulpath_mountpoint,
                                     self.mulpath_filename)
        find, buff = utils.sshclient_execmd(control_server_ip,
                                            control_username, control_password,
                                            initiator_ip, initiator_username,
                                            initiator_password, cmd)
        cmd = 'cat %s/%s' % (self.mulpath_mountpoint, self.mulpath_filename)
        find, buff = utils.sshclient_execmd(control_server_ip,
                                            control_username, control_password,
                                            initiator_ip, initiator_username,
                                            initiator_password, cmd)
Пример #13
0
    def iscsi_actions(self, control_server_ip, control_username,
                      control_password, initiator_ip, initiator_username,
                      initiator_password, target_ip):

        cmd = 'yum -y install iscsi-initiator-utils ; '
        find, buff = utils.sshclient_execmd(control_server_ip,
                                            control_username, control_password,
                                            initiator_ip, initiator_username,
                                            initiator_password, cmd)
        if not (find):
            raise exceptions.TestFail("Install iscsi-initiator-utils fault")

        cmd = 'yum -y install device-mapper-multipath ; '
        find, buff = utils.sshclient_execmd(control_server_ip,
                                            control_username, control_password,
                                            initiator_ip, initiator_username,
                                            initiator_password, cmd)
        if not (find):
            raise exceptions.TestFail("Install device-mapper-multipath fault")

        multipathconf="""defaults{\n    user_friendly_names yes\n""" \
        """    polling_interval 10\n    checker_timeout 120\n    """ \
        """queue_without_daemon no\n}\nblacklist {\n""" \
        """    devnode "^(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*"\n""" \
        """    devnode "^hd[a-z]"\n}\ndevices {\n    device{\n        """ \
        """path_grouping_policy failover\n    }\n}"""
        cmd = 'echo \'%s\' > /etc/multipath.conf' % multipathconf
        find, buff = utils.sshclient_execmd(control_server_ip,
                                            control_username, control_password,
                                            initiator_ip, initiator_username,
                                            initiator_password, cmd)

        cmd = 'systemctl start multipathd '
        find, buff = utils.sshclient_execmd(control_server_ip,
                                            control_username, control_password,
                                            initiator_ip, initiator_username,
                                            initiator_password, cmd)
        if not find:
            raise exceptions.TestFail("Start multipath service fault")

        self.hit_target(control_server_ip, control_username, control_password,
                        initiator_ip, initiator_username, initiator_password)

        iscsi_count1 = self.get_iscsi_count(control_server_ip,
                                            control_username, control_password,
                                            initiator_ip, initiator_username,
                                            initiator_password)
        #Login iscsi
        self.do_iscsi_login(control_server_ip, control_username,
                            control_password, initiator_ip, initiator_username,
                            initiator_password, self.iscsi_target_hostip[0])
        time.sleep(1)
        iscsi_count2 = self.get_iscsi_count(control_server_ip,
                                            control_username, control_password,
                                            initiator_ip, initiator_username,
                                            initiator_password)
        #Check lsblk
        if iscsi_count2 <= iscsi_count1:
            raise exceptions.TestFail("Login target to be first iscsi fault")

        self.do_iscsi_login(control_server_ip, control_username,
                            control_password, initiator_ip, initiator_username,
                            initiator_password, self.iscsi_target_hostip[1])
        time.sleep(1)
        iscsi_count3 = self.get_iscsi_count(control_server_ip,
                                            control_username, control_password,
                                            initiator_ip, initiator_username,
                                            initiator_password)
        #Check lsblk
        if iscsi_count3 <= iscsi_count2:
            raise exceptions.TestFail("Login target to be second iscsi fault")

        #Get Multipath
        find, buff = self.get_iscsi_multipath(control_server_ip,
                                              control_username,
                                              control_password, initiator_ip,
                                              initiator_username,
                                              initiator_password)
        #Check Multipath

        #make iscsi dirty
        self.make_iscsi_dirty(control_server_ip, control_username,
                              control_password, initiator_ip,
                              initiator_username, initiator_password)
        time.sleep(1)
        #Stop one tgt
        self.stop_iscsi_tgt(control_server_ip, control_username,
                            control_password, initiator_ip, initiator_username,
                            initiator_password)
        time.sleep(1)

        #Check iscsi dirty
        self.check_iscsi_dirty(control_server_ip, control_username,
                               control_password, initiator_ip,
                               initiator_username, initiator_password)
        time.sleep(1)

        #Start one tgt
        self.start_iscsi_tgt(control_server_ip, control_username,
                             control_password, initiator_ip,
                             initiator_username, initiator_password)
        time.sleep(1)

        #Clean iscsi dirty
        self.clean_iscsi_dirty(control_server_ip, control_username,
                               control_password, initiator_ip,
                               initiator_username, initiator_password)

        #Logout iscsi
        self.do_iscsi_logout(control_server_ip, control_username,
                             control_password, initiator_ip,
                             initiator_username, initiator_password,
                             self.iscsi_target_hostip[1])
        time.sleep(1)
        self.do_iscsi_logout(control_server_ip, control_username,
                             control_password, initiator_ip,
                             initiator_username, initiator_password,
                             self.iscsi_target_hostip[0])
        time.sleep(1)