2018-09-11 13:26:14 +00:00
|
|
|
#!/usr/bin/env python3
|
2016-08-03 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import json
|
|
|
|
import random
|
|
|
|
from subprocess import check_call, call, check_output, Popen, PIPE, CalledProcessError
|
|
|
|
|
2020-08-11 10:42:06 +00:00
|
|
|
if (len(sys.argv) == 7):
|
2018-03-27 16:50:41 +00:00
|
|
|
target_ip = sys.argv[2]
|
|
|
|
initiator_ip = sys.argv[3]
|
|
|
|
port = sys.argv[4]
|
|
|
|
netmask = sys.argv[5]
|
2018-04-25 16:16:08 +00:00
|
|
|
namespace = sys.argv[6]
|
2018-03-27 16:50:41 +00:00
|
|
|
|
2018-04-25 16:16:08 +00:00
|
|
|
ns_cmd = 'ip netns exec ' + namespace
|
2018-03-27 16:50:41 +00:00
|
|
|
other_ip = '127.0.0.6'
|
|
|
|
initiator_name = 'ANY'
|
|
|
|
portal_tag = '1'
|
|
|
|
initiator_tag = '1'
|
|
|
|
|
2016-08-03 21:37:16 +00:00
|
|
|
rpc_param = {
|
2018-03-27 16:50:41 +00:00
|
|
|
'target_ip': target_ip,
|
2018-03-29 09:04:21 +00:00
|
|
|
'initiator_ip': initiator_ip,
|
2018-03-27 16:50:41 +00:00
|
|
|
'port': port,
|
|
|
|
'initiator_name': initiator_name,
|
2016-08-03 21:37:16 +00:00
|
|
|
'netmask': netmask,
|
|
|
|
'lun_total': 3,
|
2016-10-17 08:30:26 +00:00
|
|
|
'malloc_bdev_size': 64,
|
2016-08-03 21:37:16 +00:00
|
|
|
'malloc_block_size': 512,
|
|
|
|
'queue_depth': 64,
|
|
|
|
'target_name': 'Target3',
|
|
|
|
'alias_name': 'Target3_alias',
|
2018-02-21 17:51:16 +00:00
|
|
|
'disable_chap': True,
|
|
|
|
'mutual_chap': False,
|
|
|
|
'require_chap': False,
|
|
|
|
'chap_group': 0,
|
2018-02-21 09:47:34 +00:00
|
|
|
'header_digest': False,
|
|
|
|
'data_digest': False,
|
2018-11-27 07:26:59 +00:00
|
|
|
'log_flag': 'rpc',
|
2018-01-21 23:04:19 +00:00
|
|
|
'cpumask': 0x1
|
2016-08-03 21:37:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class RpcException(Exception):
|
|
|
|
|
2018-11-29 14:41:31 +00:00
|
|
|
def __init__(self, retval, msg):
|
|
|
|
super(RpcException, self).__init__(msg)
|
2016-08-03 21:37:16 +00:00
|
|
|
self.retval = retval
|
2018-11-29 14:41:31 +00:00
|
|
|
self.message = msg
|
2016-08-03 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
class spdk_rpc(object):
|
|
|
|
|
|
|
|
def __init__(self, rpc_py):
|
|
|
|
self.rpc_py = rpc_py
|
|
|
|
|
|
|
|
def __getattr__(self, name):
|
|
|
|
def call(*args):
|
2018-09-11 13:26:14 +00:00
|
|
|
cmd = "{} {}".format(self.rpc_py, name)
|
2016-08-03 21:37:16 +00:00
|
|
|
for arg in args:
|
|
|
|
cmd += " {}".format(arg)
|
2018-12-10 14:18:58 +00:00
|
|
|
return check_output(cmd, shell=True).decode("utf-8")
|
2016-08-03 21:37:16 +00:00
|
|
|
return call
|
|
|
|
|
|
|
|
|
|
|
|
def verify(expr, retcode, msg):
|
|
|
|
if not expr:
|
|
|
|
raise RpcException(retcode, msg)
|
|
|
|
|
|
|
|
|
2018-11-27 07:26:59 +00:00
|
|
|
def verify_log_flag_rpc_methods(rpc_py, rpc_param):
|
2016-08-03 21:37:16 +00:00
|
|
|
rpc = spdk_rpc(rpc_py)
|
2019-09-18 12:39:32 +00:00
|
|
|
output = rpc.log_get_flags()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalue = json.loads(output)
|
2018-11-27 07:26:59 +00:00
|
|
|
verify(not jsonvalue[rpc_param['log_flag']], 1,
|
2019-09-18 12:39:32 +00:00
|
|
|
"log_get_flags returned {}, expected false".format(jsonvalue))
|
2019-09-18 12:21:59 +00:00
|
|
|
rpc.log_set_flag(rpc_param['log_flag'])
|
2019-09-18 12:39:32 +00:00
|
|
|
output = rpc.log_get_flags()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalue = json.loads(output)
|
2018-11-27 07:26:59 +00:00
|
|
|
verify(jsonvalue[rpc_param['log_flag']], 1,
|
2019-09-18 12:39:32 +00:00
|
|
|
"log_get_flags returned {}, expected true".format(jsonvalue))
|
2019-09-18 12:31:30 +00:00
|
|
|
rpc.log_clear_flag(rpc_param['log_flag'])
|
2019-09-18 12:39:32 +00:00
|
|
|
output = rpc.log_get_flags()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalue = json.loads(output)
|
2018-11-27 07:26:59 +00:00
|
|
|
verify(not jsonvalue[rpc_param['log_flag']], 1,
|
2019-09-18 12:39:32 +00:00
|
|
|
"log_get_flags returned {}, expected false".format(jsonvalue))
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2018-11-27 07:26:59 +00:00
|
|
|
print("verify_log_flag_rpc_methods passed")
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2018-02-14 21:34:55 +00:00
|
|
|
|
2016-08-03 21:37:16 +00:00
|
|
|
def verify_iscsi_connection_rpc_methods(rpc_py):
|
|
|
|
rpc = spdk_rpc(rpc_py)
|
2019-09-10 09:32:18 +00:00
|
|
|
output = rpc.iscsi_get_connections()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalue = json.loads(output)
|
|
|
|
verify(not jsonvalue, 1,
|
2019-09-10 09:32:18 +00:00
|
|
|
"iscsi_get_connections returned {}, expected empty".format(jsonvalue))
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2019-08-09 11:15:35 +00:00
|
|
|
rpc.bdev_malloc_create(rpc_param['malloc_bdev_size'], rpc_param['malloc_block_size'])
|
2019-09-09 10:35:30 +00:00
|
|
|
rpc.iscsi_create_portal_group(portal_tag, "{}:{}".format(rpc_param['target_ip'], str(rpc_param['port'])))
|
2019-09-03 08:53:37 +00:00
|
|
|
rpc.iscsi_create_initiator_group(initiator_tag, rpc_param['initiator_name'], rpc_param['netmask'])
|
2016-08-03 21:37:16 +00:00
|
|
|
|
|
|
|
lun_mapping = "Malloc" + str(rpc_param['lun_total']) + ":0"
|
|
|
|
net_mapping = portal_tag + ":" + initiator_tag
|
2019-09-05 10:35:18 +00:00
|
|
|
rpc.iscsi_create_target_node(rpc_param['target_name'], rpc_param['alias_name'], lun_mapping,
|
|
|
|
net_mapping, rpc_param['queue_depth'], '-d')
|
2016-08-03 21:37:16 +00:00
|
|
|
check_output('iscsiadm -m discovery -t st -p {}'.format(rpc_param['target_ip']), shell=True)
|
|
|
|
check_output('iscsiadm -m node --login', shell=True)
|
2019-09-04 10:20:43 +00:00
|
|
|
name = json.loads(rpc.iscsi_get_target_nodes())[0]['name']
|
2019-09-10 09:32:18 +00:00
|
|
|
output = rpc.iscsi_get_connections()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
verify(jsonvalues[0]['target_node_name'] == rpc_param['target_name'], 1,
|
|
|
|
"target node name vaule is {}, expected {}".format(jsonvalues[0]['target_node_name'], rpc_param['target_name']))
|
2018-03-29 09:04:21 +00:00
|
|
|
verify(jsonvalues[0]['initiator_addr'] == rpc_param['initiator_ip'], 1,
|
|
|
|
"initiator address values is {}, expected {}".format(jsonvalues[0]['initiator_addr'], rpc_param['initiator_ip']))
|
2016-08-03 21:37:16 +00:00
|
|
|
verify(jsonvalues[0]['target_addr'] == rpc_param['target_ip'], 1,
|
|
|
|
"target address values is {}, expected {}".format(jsonvalues[0]['target_addr'], rpc_param['target_ip']))
|
|
|
|
|
|
|
|
check_output('iscsiadm -m node --logout', shell=True)
|
|
|
|
check_output('iscsiadm -m node -o delete', shell=True)
|
2019-09-03 09:30:46 +00:00
|
|
|
rpc.iscsi_delete_initiator_group(initiator_tag)
|
2019-09-09 10:51:22 +00:00
|
|
|
rpc.iscsi_delete_portal_group(portal_tag)
|
2019-09-05 10:52:14 +00:00
|
|
|
rpc.iscsi_delete_target_node(name)
|
2019-09-10 09:32:18 +00:00
|
|
|
output = rpc.iscsi_get_connections()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
verify(not jsonvalues, 1,
|
2019-09-10 09:32:18 +00:00
|
|
|
"iscsi_get_connections returned {}, expected empty".format(jsonvalues))
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2018-05-11 22:05:48 +00:00
|
|
|
print("verify_iscsi_connection_rpc_methods passed")
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2018-02-14 21:34:55 +00:00
|
|
|
|
2016-08-03 21:37:16 +00:00
|
|
|
def verify_scsi_devices_rpc_methods(rpc_py):
|
|
|
|
rpc = spdk_rpc(rpc_py)
|
2019-09-19 22:16:27 +00:00
|
|
|
output = rpc.scsi_get_devices()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalue = json.loads(output)
|
|
|
|
verify(not jsonvalue, 1,
|
2019-09-19 22:16:27 +00:00
|
|
|
"scsi_get_devices returned {}, expected empty".format(jsonvalue))
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2019-08-09 11:15:35 +00:00
|
|
|
rpc.bdev_malloc_create(rpc_param['malloc_bdev_size'], rpc_param['malloc_block_size'])
|
2019-09-09 10:35:30 +00:00
|
|
|
rpc.iscsi_create_portal_group(portal_tag, "{}:{}".format(rpc_param['target_ip'], str(rpc_param['port'])))
|
2019-09-03 08:53:37 +00:00
|
|
|
rpc.iscsi_create_initiator_group(initiator_tag, rpc_param['initiator_name'], rpc_param['netmask'])
|
2016-08-03 21:37:16 +00:00
|
|
|
|
|
|
|
lun_mapping = "Malloc" + str(rpc_param['lun_total']) + ":0"
|
|
|
|
net_mapping = portal_tag + ":" + initiator_tag
|
2019-09-05 10:35:18 +00:00
|
|
|
rpc.iscsi_create_target_node(rpc_param['target_name'], rpc_param['alias_name'], lun_mapping,
|
|
|
|
net_mapping, rpc_param['queue_depth'], '-d')
|
2016-08-03 21:37:16 +00:00
|
|
|
check_output('iscsiadm -m discovery -t st -p {}'.format(rpc_param['target_ip']), shell=True)
|
|
|
|
check_output('iscsiadm -m node --login', shell=True)
|
2019-09-04 10:20:43 +00:00
|
|
|
name = json.loads(rpc.iscsi_get_target_nodes())[0]['name']
|
2019-09-11 11:39:42 +00:00
|
|
|
output = rpc.iscsi_get_options()
|
scsi&test/iscsi_tgt: SCSI device == iSCSI name
In the iSCSI specification, the SCSI device name is defined to be
the iSCSI name of the node.
However, when g_spdk_iscsi.nodebase is used, the SCSI device name
is made of the device specific string (the part of IQN after the
colon).
The size of the temporary buffer fullname[MAX_TMPBUF] in
spdk_iscsi_tgt_node_construct() is 1024 and the size of
spdk_scsi_dev.name is 255. The former is larger than the later.
However the max length of IQN, EUI, NAA are 223, 20, and 36,
respectively. All are less than 255.
Hence even if we use fullname as the SCSI device name, no overflow
will occur. Even if fullname is more than 255, strncpy() does not
write more than 255 in spdk_scsi_dev_construct().
It's possible to check the length of iSCSI name strictly, but I
will do the least in this patch.
Change-Id: Icc6655fcd846797720867c10e316d2951c664030
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/390360
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
2017-12-18 05:41:21 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
nodebase = jsonvalues['node_base']
|
2019-09-19 22:16:27 +00:00
|
|
|
output = rpc.scsi_get_devices()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalues = json.loads(output)
|
scsi&test/iscsi_tgt: SCSI device == iSCSI name
In the iSCSI specification, the SCSI device name is defined to be
the iSCSI name of the node.
However, when g_spdk_iscsi.nodebase is used, the SCSI device name
is made of the device specific string (the part of IQN after the
colon).
The size of the temporary buffer fullname[MAX_TMPBUF] in
spdk_iscsi_tgt_node_construct() is 1024 and the size of
spdk_scsi_dev.name is 255. The former is larger than the later.
However the max length of IQN, EUI, NAA are 223, 20, and 36,
respectively. All are less than 255.
Hence even if we use fullname as the SCSI device name, no overflow
will occur. Even if fullname is more than 255, strncpy() does not
write more than 255 in spdk_scsi_dev_construct().
It's possible to check the length of iSCSI name strictly, but I
will do the least in this patch.
Change-Id: Icc6655fcd846797720867c10e316d2951c664030
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/390360
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
2017-12-18 05:41:21 +00:00
|
|
|
verify(jsonvalues[0]['device_name'] == nodebase + ":" + rpc_param['target_name'], 1,
|
2016-08-03 21:37:16 +00:00
|
|
|
"device name vaule is {}, expected {}".format(jsonvalues[0]['device_name'], rpc_param['target_name']))
|
|
|
|
verify(jsonvalues[0]['id'] == 0, 1,
|
|
|
|
"device id value is {}, expected 0".format(jsonvalues[0]['id']))
|
|
|
|
|
|
|
|
check_output('iscsiadm -m node --logout', shell=True)
|
|
|
|
check_output('iscsiadm -m node -o delete', shell=True)
|
2019-09-03 09:30:46 +00:00
|
|
|
rpc.iscsi_delete_initiator_group(initiator_tag)
|
2019-09-09 10:51:22 +00:00
|
|
|
rpc.iscsi_delete_portal_group(portal_tag)
|
2019-09-05 10:52:14 +00:00
|
|
|
rpc.iscsi_delete_target_node(name)
|
2019-09-19 22:16:27 +00:00
|
|
|
output = rpc.scsi_get_devices()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
verify(not jsonvalues, 1,
|
2019-09-19 22:16:27 +00:00
|
|
|
"scsi_get_devices returned {}, expected empty".format(jsonvalues))
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2018-05-11 22:05:48 +00:00
|
|
|
print("verify_scsi_devices_rpc_methods passed")
|
2016-08-03 21:37:16 +00:00
|
|
|
|
|
|
|
|
2018-01-03 18:58:01 +00:00
|
|
|
def create_malloc_bdevs_rpc_methods(rpc_py, rpc_param):
|
2016-08-03 21:37:16 +00:00
|
|
|
rpc = spdk_rpc(rpc_py)
|
|
|
|
|
|
|
|
for i in range(1, rpc_param['lun_total'] + 1):
|
2019-08-09 11:15:35 +00:00
|
|
|
rpc.bdev_malloc_create(rpc_param['malloc_bdev_size'], rpc_param['malloc_block_size'])
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2018-05-11 22:05:48 +00:00
|
|
|
print("create_malloc_bdevs_rpc_methods passed")
|
2016-08-03 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
def verify_portal_groups_rpc_methods(rpc_py, rpc_param):
|
|
|
|
rpc = spdk_rpc(rpc_py)
|
2019-09-09 10:12:04 +00:00
|
|
|
output = rpc.iscsi_get_portal_groups()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
verify(not jsonvalues, 1,
|
2019-09-09 10:12:04 +00:00
|
|
|
"iscsi_get_portal_groups returned {} groups, expected empty".format(jsonvalues))
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2018-03-27 16:50:41 +00:00
|
|
|
lo_ip = (target_ip, other_ip)
|
2019-09-18 09:07:01 +00:00
|
|
|
nics = json.loads(rpc.net_get_interfaces())
|
2016-08-03 21:37:16 +00:00
|
|
|
for x in nics:
|
|
|
|
if x["ifc_index"] == 'lo':
|
2019-09-18 08:53:32 +00:00
|
|
|
rpc.net_interface_add_ip_address(x["ifc_index"], lo_ip[1])
|
2016-08-03 21:37:16 +00:00
|
|
|
for idx, value in enumerate(lo_ip):
|
|
|
|
# The portal group tag must start at 1
|
|
|
|
tag = idx + 1
|
2019-09-09 10:35:30 +00:00
|
|
|
rpc.iscsi_create_portal_group(tag, "{}:{}".format(value, rpc_param['port']))
|
2019-09-09 10:12:04 +00:00
|
|
|
output = rpc.iscsi_get_portal_groups()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
verify(len(jsonvalues) == tag, 1,
|
2019-09-09 10:12:04 +00:00
|
|
|
"iscsi_get_portal_groups returned {} groups, expected {}".format(len(jsonvalues), tag))
|
2016-08-03 21:37:16 +00:00
|
|
|
|
|
|
|
tag_list = []
|
|
|
|
for idx, value in enumerate(jsonvalues):
|
|
|
|
verify(value['portals'][0]['host'] == lo_ip[idx], 1,
|
|
|
|
"host value is {}, expected {}".format(value['portals'][0]['host'], rpc_param['target_ip']))
|
|
|
|
verify(value['portals'][0]['port'] == str(rpc_param['port']), 1,
|
|
|
|
"port value is {}, expected {}".format(value['portals'][0]['port'], str(rpc_param['port'])))
|
|
|
|
tag_list.append(value['tag'])
|
|
|
|
verify(value['tag'] == idx + 1, 1,
|
|
|
|
"tag value is {}, expected {}".format(value['tag'], idx + 1))
|
|
|
|
|
|
|
|
for idx, value in enumerate(tag_list):
|
2019-09-09 10:51:22 +00:00
|
|
|
rpc.iscsi_delete_portal_group(value)
|
2019-09-09 10:12:04 +00:00
|
|
|
output = rpc.iscsi_get_portal_groups()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
verify(len(jsonvalues) == (len(tag_list) - (idx + 1)), 1,
|
|
|
|
"get_portal_group returned {} groups, expected {}".format(len(jsonvalues), (len(tag_list) - (idx + 1))))
|
|
|
|
if not jsonvalues:
|
|
|
|
break
|
|
|
|
|
|
|
|
for jidx, jvalue in enumerate(jsonvalues):
|
|
|
|
verify(jvalue['portals'][0]['host'] == lo_ip[idx + jidx + 1], 1,
|
|
|
|
"host value is {}, expected {}".format(jvalue['portals'][0]['host'], lo_ip[idx + jidx + 1]))
|
|
|
|
verify(jvalue['portals'][0]['port'] == str(rpc_param['port']), 1,
|
|
|
|
"port value is {}, expected {}".format(jvalue['portals'][0]['port'], str(rpc_param['port'])))
|
|
|
|
verify(jvalue['tag'] != value or jvalue['tag'] == tag_list[idx + jidx + 1], 1,
|
|
|
|
"tag value is {}, expected {} and not {}".format(jvalue['tag'], tag_list[idx + jidx + 1], value))
|
|
|
|
|
|
|
|
for x in nics:
|
|
|
|
if x["ifc_index"] == 'lo':
|
2019-09-18 09:00:43 +00:00
|
|
|
rpc.net_interface_delete_ip_address(x["ifc_index"], lo_ip[1])
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2018-05-11 22:05:48 +00:00
|
|
|
print("verify_portal_groups_rpc_methods passed")
|
2016-08-03 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
def verify_initiator_groups_rpc_methods(rpc_py, rpc_param):
|
|
|
|
rpc = spdk_rpc(rpc_py)
|
2019-09-02 22:10:36 +00:00
|
|
|
output = rpc.iscsi_get_initiator_groups()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
verify(not jsonvalues, 1,
|
2019-09-02 22:10:36 +00:00
|
|
|
"iscsi_get_initiator_groups returned {}, expected empty".format(jsonvalues))
|
2016-08-03 21:37:16 +00:00
|
|
|
for idx, value in enumerate(rpc_param['netmask']):
|
|
|
|
# The initiator group tag must start at 1
|
|
|
|
tag = idx + 1
|
2019-09-03 08:53:37 +00:00
|
|
|
rpc.iscsi_create_initiator_group(tag, rpc_param['initiator_name'], value)
|
2019-09-02 22:10:36 +00:00
|
|
|
output = rpc.iscsi_get_initiator_groups()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
verify(len(jsonvalues) == tag, 1,
|
2019-09-02 22:10:36 +00:00
|
|
|
"iscsi_get_initiator_groups returned {} groups, expected {}".format(len(jsonvalues), tag))
|
2016-08-03 21:37:16 +00:00
|
|
|
|
|
|
|
tag_list = []
|
|
|
|
for idx, value in enumerate(jsonvalues):
|
|
|
|
verify(value['initiators'][0] == rpc_param['initiator_name'], 1,
|
|
|
|
"initiator value is {}, expected {}".format(value['initiators'][0], rpc_param['initiator_name']))
|
|
|
|
tag_list.append(value['tag'])
|
|
|
|
verify(value['tag'] == idx + 1, 1,
|
|
|
|
"tag value is {}, expected {}".format(value['tag'], idx + 1))
|
|
|
|
verify(value['netmasks'][0] == rpc_param['netmask'][idx], 1,
|
|
|
|
"netmasks value is {}, expected {}".format(value['netmasks'][0], rpc_param['netmask'][idx]))
|
|
|
|
|
2018-02-06 23:22:00 +00:00
|
|
|
for idx, value in enumerate(rpc_param['netmask']):
|
|
|
|
tag = idx + 1
|
2019-09-04 09:52:01 +00:00
|
|
|
rpc.iscsi_initiator_group_remove_initiators(tag, '-n', rpc_param['initiator_name'], '-m', value)
|
2018-02-06 23:22:00 +00:00
|
|
|
|
2019-09-02 22:10:36 +00:00
|
|
|
output = rpc.iscsi_get_initiator_groups()
|
2018-02-06 23:22:00 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
verify(len(jsonvalues) == tag, 1,
|
2019-09-02 22:10:36 +00:00
|
|
|
"iscsi_get_initiator_groups returned {} groups, expected {}".format(len(jsonvalues), tag))
|
2018-02-06 23:22:00 +00:00
|
|
|
|
|
|
|
for idx, value in enumerate(jsonvalues):
|
|
|
|
verify(value['tag'] == idx + 1, 1,
|
|
|
|
"tag value is {}, expected {}".format(value['tag'], idx + 1))
|
|
|
|
initiators = value.get('initiators')
|
|
|
|
verify(len(initiators) == 0, 1,
|
|
|
|
"length of initiator list is {}, expected 0".format(len(initiators)))
|
|
|
|
netmasks = value.get('netmasks')
|
|
|
|
verify(len(netmasks) == 0, 1,
|
|
|
|
"length of netmask list is {}, expected 0".format(len(netmasks)))
|
|
|
|
|
|
|
|
for idx, value in enumerate(rpc_param['netmask']):
|
|
|
|
tag = idx + 1
|
2019-09-03 09:59:23 +00:00
|
|
|
rpc.iscsi_initiator_group_add_initiators(tag, '-n', rpc_param['initiator_name'], '-m', value)
|
2019-09-02 22:10:36 +00:00
|
|
|
output = rpc.iscsi_get_initiator_groups()
|
2018-02-06 23:22:00 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
verify(len(jsonvalues) == tag, 1,
|
2019-09-02 22:10:36 +00:00
|
|
|
"iscsi_get_initiator_groups returned {} groups, expected {}".format(len(jsonvalues), tag))
|
2018-02-06 23:22:00 +00:00
|
|
|
|
|
|
|
tag_list = []
|
|
|
|
for idx, value in enumerate(jsonvalues):
|
|
|
|
verify(value['initiators'][0] == rpc_param['initiator_name'], 1,
|
|
|
|
"initiator value is {}, expected {}".format(value['initiators'][0], rpc_param['initiator_name']))
|
|
|
|
tag_list.append(value['tag'])
|
|
|
|
verify(value['tag'] == idx + 1, 1,
|
|
|
|
"tag value is {}, expected {}".format(value['tag'], idx + 1))
|
|
|
|
verify(value['netmasks'][0] == rpc_param['netmask'][idx], 1,
|
|
|
|
"netmasks value is {}, expected {}".format(value['netmasks'][0], rpc_param['netmask'][idx]))
|
|
|
|
|
2016-08-03 21:37:16 +00:00
|
|
|
for idx, value in enumerate(tag_list):
|
2019-09-03 09:30:46 +00:00
|
|
|
rpc.iscsi_delete_initiator_group(value)
|
2019-09-02 22:10:36 +00:00
|
|
|
output = rpc.iscsi_get_initiator_groups()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
verify(len(jsonvalues) == (len(tag_list) - (idx + 1)), 1,
|
2019-09-02 22:10:36 +00:00
|
|
|
"iscsi_get_initiator_groups returned {} groups, expected {}".format(len(jsonvalues), (len(tag_list) - (idx + 1))))
|
2016-08-03 21:37:16 +00:00
|
|
|
if not jsonvalues:
|
|
|
|
break
|
|
|
|
for jidx, jvalue in enumerate(jsonvalues):
|
|
|
|
verify(jvalue['initiators'][0] == rpc_param['initiator_name'], 1,
|
|
|
|
"initiator value is {}, expected {}".format(jvalue['initiators'][0], rpc_param['initiator_name']))
|
|
|
|
verify(jvalue['tag'] != value or jvalue['tag'] == tag_list[idx + jidx + 1], 1,
|
|
|
|
"tag value is {}, expected {} and not {}".format(jvalue['tag'], tag_list[idx + jidx + 1], value))
|
|
|
|
verify(jvalue['netmasks'][0] == rpc_param['netmask'][idx + jidx + 1], 1,
|
|
|
|
"netmasks value is {}, expected {}".format(jvalue['netmasks'][0], rpc_param['netmask'][idx + jidx + 1]))
|
|
|
|
|
2018-05-11 22:05:48 +00:00
|
|
|
print("verify_initiator_groups_rpc_method passed.")
|
2016-08-03 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
def verify_target_nodes_rpc_methods(rpc_py, rpc_param):
|
|
|
|
rpc = spdk_rpc(rpc_py)
|
2019-09-11 11:39:42 +00:00
|
|
|
output = rpc.iscsi_get_options()
|
2018-01-12 00:45:36 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
nodebase = jsonvalues['node_base']
|
2019-09-04 10:20:43 +00:00
|
|
|
output = rpc.iscsi_get_target_nodes()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
verify(not jsonvalues, 1,
|
2019-09-04 10:20:43 +00:00
|
|
|
"iscsi_get_target_nodes returned {}, expected empty".format(jsonvalues))
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2019-08-09 11:15:35 +00:00
|
|
|
rpc.bdev_malloc_create(rpc_param['malloc_bdev_size'], rpc_param['malloc_block_size'])
|
2019-09-09 10:35:30 +00:00
|
|
|
rpc.iscsi_create_portal_group(portal_tag, "{}:{}".format(rpc_param['target_ip'], str(rpc_param['port'])))
|
2019-09-03 08:53:37 +00:00
|
|
|
rpc.iscsi_create_initiator_group(initiator_tag, rpc_param['initiator_name'], rpc_param['netmask'])
|
2016-08-03 21:37:16 +00:00
|
|
|
|
|
|
|
lun_mapping = "Malloc" + str(rpc_param['lun_total']) + ":0"
|
|
|
|
net_mapping = portal_tag + ":" + initiator_tag
|
2019-09-05 10:35:18 +00:00
|
|
|
rpc.iscsi_create_target_node(rpc_param['target_name'], rpc_param['alias_name'], lun_mapping,
|
|
|
|
net_mapping, rpc_param['queue_depth'], '-d')
|
2019-09-04 10:20:43 +00:00
|
|
|
output = rpc.iscsi_get_target_nodes()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
verify(len(jsonvalues) == 1, 1,
|
2019-09-04 10:20:43 +00:00
|
|
|
"iscsi_get_target_nodes returned {} nodes, expected 1".format(len(jsonvalues)))
|
2018-01-12 00:45:36 +00:00
|
|
|
bdev_name = jsonvalues[0]['luns'][0]['bdev_name']
|
|
|
|
verify(bdev_name == "Malloc" + str(rpc_param['lun_total']), 1,
|
2018-01-10 05:55:53 +00:00
|
|
|
"bdev_name value is {}, expected Malloc{}".format(jsonvalues[0]['luns'][0]['bdev_name'], str(rpc_param['lun_total'])))
|
2016-08-03 21:37:16 +00:00
|
|
|
name = jsonvalues[0]['name']
|
2018-01-12 00:45:36 +00:00
|
|
|
verify(name == nodebase + ":" + rpc_param['target_name'], 1,
|
|
|
|
"target name value is {}, expected {}".format(name, nodebase + ":" + rpc_param['target_name']))
|
2016-08-03 21:37:16 +00:00
|
|
|
verify(jsonvalues[0]['alias_name'] == rpc_param['alias_name'], 1,
|
|
|
|
"target alias_name value is {}, expected {}".format(jsonvalues[0]['alias_name'], rpc_param['alias_name']))
|
2018-05-13 23:02:19 +00:00
|
|
|
verify(jsonvalues[0]['luns'][0]['lun_id'] == 0, 1,
|
|
|
|
"lun id value is {}, expected 0".format(jsonvalues[0]['luns'][0]['lun_id']))
|
2016-10-09 08:56:51 +00:00
|
|
|
verify(jsonvalues[0]['pg_ig_maps'][0]['ig_tag'] == int(initiator_tag), 1,
|
|
|
|
"initiator group tag value is {}, expected {}".format(jsonvalues[0]['pg_ig_maps'][0]['ig_tag'], initiator_tag))
|
2016-08-03 21:37:16 +00:00
|
|
|
verify(jsonvalues[0]['queue_depth'] == rpc_param['queue_depth'], 1,
|
|
|
|
"queue depth value is {}, expected {}".format(jsonvalues[0]['queue_depth'], rpc_param['queue_depth']))
|
2016-10-09 08:56:51 +00:00
|
|
|
verify(jsonvalues[0]['pg_ig_maps'][0]['pg_tag'] == int(portal_tag), 1,
|
|
|
|
"portal group tag value is {}, expected {}".format(jsonvalues[0]['pg_ig_maps'][0]['pg_tag'], portal_tag))
|
2018-02-21 17:51:16 +00:00
|
|
|
verify(jsonvalues[0]['disable_chap'] == rpc_param['disable_chap'], 1,
|
|
|
|
"disable chap value is {}, expected {}".format(jsonvalues[0]['disable_chap'], rpc_param['disable_chap']))
|
|
|
|
verify(jsonvalues[0]['mutual_chap'] == rpc_param['mutual_chap'], 1,
|
|
|
|
"chap mutual value is {}, expected {}".format(jsonvalues[0]['mutual_chap'], rpc_param['mutual_chap']))
|
|
|
|
verify(jsonvalues[0]['require_chap'] == rpc_param['require_chap'], 1,
|
|
|
|
"chap required value is {}, expected {}".format(jsonvalues[0]['require_chap'], rpc_param['require_chap']))
|
|
|
|
verify(jsonvalues[0]['chap_group'] == rpc_param['chap_group'], 1,
|
|
|
|
"chap auth group value is {}, expected {}".format(jsonvalues[0]['chap_group'], rpc_param['chap_group']))
|
2018-01-12 05:48:39 +00:00
|
|
|
verify(jsonvalues[0]['header_digest'] == rpc_param['header_digest'], 1,
|
|
|
|
"header digest value is {}, expected {}".format(jsonvalues[0]['header_digest'], rpc_param['header_digest']))
|
|
|
|
verify(jsonvalues[0]['data_digest'] == rpc_param['data_digest'], 1,
|
|
|
|
"data digest value is {}, expected {}".format(jsonvalues[0]['data_digest'], rpc_param['data_digest']))
|
2018-01-12 00:45:36 +00:00
|
|
|
lun_id = '1'
|
2019-09-10 11:06:57 +00:00
|
|
|
rpc.iscsi_target_node_add_lun(name, bdev_name, "-i", lun_id)
|
2019-09-04 10:20:43 +00:00
|
|
|
output = rpc.iscsi_get_target_nodes()
|
2018-01-12 00:45:36 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
verify(jsonvalues[0]['luns'][1]['bdev_name'] == "Malloc" + str(rpc_param['lun_total']), 1,
|
|
|
|
"bdev_name value is {}, expected Malloc{}".format(jsonvalues[0]['luns'][0]['bdev_name'], str(rpc_param['lun_total'])))
|
2018-05-13 23:02:19 +00:00
|
|
|
verify(jsonvalues[0]['luns'][1]['lun_id'] == 1, 1,
|
|
|
|
"lun id value is {}, expected 1".format(jsonvalues[0]['luns'][1]['lun_id']))
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2019-09-05 10:52:14 +00:00
|
|
|
rpc.iscsi_delete_target_node(name)
|
2019-09-04 10:20:43 +00:00
|
|
|
output = rpc.iscsi_get_target_nodes()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
verify(not jsonvalues, 1,
|
2019-09-04 10:20:43 +00:00
|
|
|
"iscsi_get_target_nodes returned {}, expected empty".format(jsonvalues))
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2019-09-05 10:35:18 +00:00
|
|
|
rpc.iscsi_create_target_node(rpc_param['target_name'], rpc_param['alias_name'], lun_mapping,
|
|
|
|
net_mapping, rpc_param['queue_depth'], '-d')
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2019-09-09 10:51:22 +00:00
|
|
|
rpc.iscsi_delete_portal_group(portal_tag)
|
2019-09-03 09:30:46 +00:00
|
|
|
rpc.iscsi_delete_initiator_group(initiator_tag)
|
2019-09-05 10:52:14 +00:00
|
|
|
rpc.iscsi_delete_target_node(name)
|
2019-09-04 10:20:43 +00:00
|
|
|
output = rpc.iscsi_get_target_nodes()
|
2016-08-03 21:37:16 +00:00
|
|
|
jsonvalues = json.loads(output)
|
|
|
|
if not jsonvalues:
|
2018-05-11 22:05:48 +00:00
|
|
|
print("This issue will be fixed later.")
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2018-05-11 22:05:48 +00:00
|
|
|
print("verify_target_nodes_rpc_methods passed.")
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2018-02-14 21:34:55 +00:00
|
|
|
|
2019-09-18 09:07:01 +00:00
|
|
|
def verify_net_get_interfaces(rpc_py):
|
2016-08-03 21:37:16 +00:00
|
|
|
rpc = spdk_rpc(rpc_py)
|
2019-09-18 09:07:01 +00:00
|
|
|
nics = json.loads(rpc.net_get_interfaces())
|
2018-05-11 22:05:48 +00:00
|
|
|
nics_names = set(x["name"] for x in nics)
|
2019-09-18 09:07:01 +00:00
|
|
|
# parse ip link show to verify the net_get_interfaces result
|
2018-04-25 16:16:08 +00:00
|
|
|
ip_show = ns_cmd + " ip link show"
|
2019-02-08 17:50:49 +00:00
|
|
|
ifcfg_nics = set(re.findall(r'\S+:\s(\S+?)(?:@\S+){0,1}:\s<.*', check_output(ip_show.split()).decode()))
|
2019-09-18 09:07:01 +00:00
|
|
|
verify(nics_names == ifcfg_nics, 1, "net_get_interfaces returned {}".format(nics))
|
|
|
|
print("verify_net_get_interfaces passed.")
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2018-02-14 21:34:55 +00:00
|
|
|
|
2016-08-03 21:37:16 +00:00
|
|
|
def help_get_interface_ip_list(rpc_py, nic_name):
|
|
|
|
rpc = spdk_rpc(rpc_py)
|
2019-09-18 09:07:01 +00:00
|
|
|
nics = json.loads(rpc.net_get_interfaces())
|
2018-09-11 13:26:14 +00:00
|
|
|
nic = list([x for x in nics if x["name"] == nic_name])
|
2016-08-03 21:37:16 +00:00
|
|
|
verify(len(nic) != 0, 1,
|
|
|
|
"Nic name: {} is not found in {}".format(nic_name, [x["name"] for x in nics]))
|
|
|
|
return nic[0]["ip_addr"]
|
|
|
|
|
2018-02-14 21:34:55 +00:00
|
|
|
|
2019-09-18 09:00:43 +00:00
|
|
|
def verify_net_interface_add_delete_ip_address(rpc_py):
|
2016-08-03 21:37:16 +00:00
|
|
|
rpc = spdk_rpc(rpc_py)
|
2019-09-18 09:07:01 +00:00
|
|
|
nics = json.loads(rpc.net_get_interfaces())
|
2017-05-25 20:18:19 +00:00
|
|
|
# add ip on up to first 2 nics
|
|
|
|
for x in nics[:2]:
|
2016-08-03 21:37:16 +00:00
|
|
|
faked_ip = "123.123.{}.{}".format(random.randint(1, 254), random.randint(1, 254))
|
2018-04-25 16:16:08 +00:00
|
|
|
ping_cmd = ns_cmd + " ping -c 1 -W 1 " + faked_ip
|
2019-09-18 08:53:32 +00:00
|
|
|
rpc.net_interface_add_ip_address(x["ifc_index"], faked_ip)
|
2016-08-03 21:37:16 +00:00
|
|
|
verify(faked_ip in help_get_interface_ip_list(rpc_py, x["name"]), 1,
|
|
|
|
"add ip {} to nic {} failed.".format(faked_ip, x["name"]))
|
|
|
|
try:
|
2018-04-25 16:16:08 +00:00
|
|
|
check_call(ping_cmd.split())
|
2018-06-21 19:29:12 +00:00
|
|
|
except BaseException:
|
2016-08-03 21:37:16 +00:00
|
|
|
verify(False, 1,
|
|
|
|
"ping ip {} for {} was failed(adding was successful)".format
|
|
|
|
(faked_ip, x["name"]))
|
2019-09-18 09:00:43 +00:00
|
|
|
rpc.net_interface_delete_ip_address(x["ifc_index"], faked_ip)
|
2016-08-03 21:37:16 +00:00
|
|
|
verify(faked_ip not in help_get_interface_ip_list(rpc_py, x["name"]), 1,
|
|
|
|
"delete ip {} from nic {} failed.(adding and ping were successful)".format
|
|
|
|
(faked_ip, x["name"]))
|
|
|
|
# ping should be failed and throw an CalledProcessError exception
|
|
|
|
try:
|
2018-04-25 16:16:08 +00:00
|
|
|
check_call(ping_cmd.split())
|
2016-08-03 21:37:16 +00:00
|
|
|
except CalledProcessError as _:
|
|
|
|
pass
|
|
|
|
except Exception as e:
|
|
|
|
verify(False, 1,
|
|
|
|
"Unexpected exception was caught {}(adding/ping/delete were successful)".format
|
|
|
|
(str(e)))
|
|
|
|
else:
|
|
|
|
verify(False, 1,
|
|
|
|
"ip {} for {} could be pinged after delete ip(adding/ping/delete were successful)".format
|
|
|
|
(faked_ip, x["name"]))
|
2019-09-18 09:00:43 +00:00
|
|
|
print("verify_net_interface_add_delete_ip_address passed.")
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2018-02-14 21:34:55 +00:00
|
|
|
|
2016-08-03 21:37:16 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
rpc_py = sys.argv[1]
|
|
|
|
|
|
|
|
try:
|
2018-11-27 07:26:59 +00:00
|
|
|
verify_log_flag_rpc_methods(rpc_py, rpc_param)
|
2019-09-18 09:07:01 +00:00
|
|
|
verify_net_get_interfaces(rpc_py)
|
2020-08-11 10:42:06 +00:00
|
|
|
verify_net_interface_add_delete_ip_address(rpc_py)
|
2018-01-03 18:58:01 +00:00
|
|
|
create_malloc_bdevs_rpc_methods(rpc_py, rpc_param)
|
2016-08-03 21:37:16 +00:00
|
|
|
verify_portal_groups_rpc_methods(rpc_py, rpc_param)
|
|
|
|
verify_initiator_groups_rpc_methods(rpc_py, rpc_param)
|
|
|
|
verify_target_nodes_rpc_methods(rpc_py, rpc_param)
|
|
|
|
verify_scsi_devices_rpc_methods(rpc_py)
|
2018-04-25 16:16:08 +00:00
|
|
|
verify_iscsi_connection_rpc_methods(rpc_py)
|
2016-08-03 21:37:16 +00:00
|
|
|
except RpcException as e:
|
2018-05-11 22:05:48 +00:00
|
|
|
print("{}. Exiting with status {}".format(e.message, e.retval))
|
2016-08-03 21:37:16 +00:00
|
|
|
raise e
|
|
|
|
except Exception as e:
|
|
|
|
raise e
|
|
|
|
|
|
|
|
sys.exit(0)
|