forked from osandov/blktests
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] contrib: add remote target setup/cleanup script
Use nvmetcli to setup/cleanup a remote soft target. Signed-off-by: Daniel Wagner <dwagner@suse.de>
- Loading branch information
Showing
2 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import subprocess | ||
from jinja2 import Environment, FileSystemLoader | ||
|
||
|
||
nvmetcli='/home/wagi/work/nvmetcli/nvmetcli' | ||
remote='http://nvmet:5000' | ||
|
||
|
||
def gen_conf(conf): | ||
environment = Environment(loader=FileSystemLoader('.')) | ||
template = environment.get_template('nvmet-subsys.jinja2') | ||
filename = f'{conf["subsysnqn"]}.json' | ||
content = template.render(conf) | ||
with open(filename, mode='w', encoding='utf-8') as outfile: | ||
outfile.write(content) | ||
|
||
|
||
def target_setup(args): | ||
conf = { | ||
'subsysnqn': args.subsysnqn, | ||
'subsys_uuid': args.subsys_uuid, | ||
'hostnqn': args.hostnqn, | ||
'allowed_hosts': args.hostnqn, | ||
'ctrlkey': args.ctrlkey, | ||
'hostkey': args.hostkey, | ||
'blkdev': '/dev/vdc' | ||
} | ||
|
||
gen_conf(conf) | ||
|
||
subprocess.call(['python3', nvmetcli, '--remote=' + remote, | ||
'restore', args.subsysnqn + '.json']) | ||
|
||
|
||
def target_cleanup(args): | ||
subprocess.call(['python3', nvmetcli, '--remote=' + remote, | ||
'clear', args.subsysnqn + '.json']) | ||
|
||
|
||
def build_parser(): | ||
parser = argparse.ArgumentParser() | ||
sub = parser.add_subparsers(required=True) | ||
|
||
setup = sub.add_parser('setup') | ||
setup.add_argument('--subsysnqn', required=True) | ||
setup.add_argument('--subsys-uuid', required=True) | ||
setup.add_argument('--hostnqn', required=True) | ||
setup.add_argument('--ctrlkey', default='') | ||
setup.add_argument('--hostkey', default='') | ||
setup.set_defaults(func=target_setup) | ||
|
||
cleanup = sub.add_parser('cleanup') | ||
cleanup.add_argument('--subsysnqn', required=True) | ||
cleanup.set_defaults(func=target_cleanup) | ||
|
||
return parser | ||
|
||
|
||
def test(): | ||
import pdb | ||
|
||
pdb.set_trace() | ||
|
||
parser = build_parser() | ||
args = parser.parse_args('setup --subsysnqn blktests-subsystem-1 --subsys-uuid 91fdba0d-f87b-4c25-b80f-db7be1418b9e --blkdev=/dev/vdb'.split()) | ||
args.func(args) | ||
|
||
|
||
def main(): | ||
import sys | ||
|
||
parser = build_parser() | ||
args = parser.parse_args() | ||
args.func(args) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"hosts": [ | ||
{ | ||
"nqn": "{{ hostnqn }}" | ||
} | ||
], | ||
"ports": [ | ||
{ | ||
"addr": { | ||
"adrfam": "ipv4", | ||
"traddr": "0.0.0.0", | ||
"treq": "not specified", | ||
"trsvcid": "4420", | ||
"trtype": "tcp", | ||
"tsas": "none" | ||
}, | ||
"ana_groups": [ | ||
{ | ||
"ana": { | ||
"state": "optimized" | ||
}, | ||
"grpid": 1 | ||
} | ||
], | ||
"param": { | ||
"inline_data_size": "16384", | ||
"pi_enable": "0" | ||
}, | ||
"portid": 0, | ||
"referrals": [], | ||
"subsystems": [ | ||
"{{ subsysnqn }}" | ||
] | ||
} | ||
], | ||
"subsystems": [ | ||
{ | ||
"allowed_hosts": [ | ||
"{{ allowed_hosts }}" | ||
], | ||
"attr": { | ||
"allow_any_host": "0", | ||
"cntlid_max": "65519", | ||
"cntlid_min": "1", | ||
"firmware": "yada", | ||
"ieee_oui": "0x000000", | ||
"model": "Linux", | ||
"pi_enable": "0", | ||
"qid_max": "128", | ||
"serial": "0c74361069d9db6c65ef", | ||
"version": "1.3" | ||
}, | ||
"namespaces": [ | ||
{ | ||
"ana": { | ||
"grpid": "1" | ||
}, | ||
"ana_grpid": 1, | ||
"device": { | ||
"nguid": "00000000-0000-0000-0000-000000000000", | ||
"path": "{{ blkdev }}", | ||
"uuid": "{{ subsys_uuid }}" | ||
}, | ||
"enable": 1, | ||
"nsid": 1 | ||
} | ||
], | ||
"nqn": "{{ subsysnqn }}" | ||
} | ||
] | ||
} |