Skip to content

Commit

Permalink
Added iscsi validations
Browse files Browse the repository at this point in the history
Signed-off-by: Sunil Kumar Nagaraju <[email protected]>
  • Loading branch information
sunilkumarn417 committed Jan 27, 2025
1 parent 3d11356 commit c7a2d4c
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 13 deletions.
9 changes: 7 additions & 2 deletions ceph/iscsi/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def exec_gw_cli(self, action, path, **kwargs):
def list(self, **kwargs):
return self.exec_gw_cli("ls", self.path, **kwargs)

def export(self):
return self.exec_gw_cli("export", self.path)

class Disks:
path = "/disks"

Expand Down Expand Up @@ -114,9 +117,11 @@ class Disks:
def __init__(self, parent):
self.parent = parent

def create(self, iqn, **kwargs):
def add(self, iqn, **kwargs):
return self.parent.exec_gw_cli(
"create", self.path.format(IQN=iqn), **kwargs
"add",
self.path.format(IQN=iqn),
**kwargs,
)

def delete(self, iqn, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion suites/squid/iscsi/iscsi_sanity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ tests:
pool: rbd
install: true
cleanup:
- initiators
- gateway
- pool
- initiators
targets:
- iqn: iscsi-target1
gateways:
Expand Down
6 changes: 6 additions & 0 deletions tests/iscsi/iscsi_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def teardown(ceph_cluster, iscsi, rbd_obj, config):
for initiator in iscsi.initiators:
initiator.cleanup()

# Delete the Individual iSCSI Targets
if "targets" in config["cleanup"]:
gwnode = iscsi.gateways[0]
for target in config["targets"]:
gwnode.gwcli.target.delete(target["iqn"])

# Delete the gateway
if "gateway" in config["cleanup"]:
delete_iscsi_service(ceph_cluster, config)
Expand Down
36 changes: 26 additions & 10 deletions tests/iscsi/workflows/iscsi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from copy import deepcopy

from ceph.ceph_admin.orch import Orch
from ceph.iscsi.gateway import Iscsi_Gateway
from ceph.utils import get_node_by_id
from tests.iscsi.workflows.initiator import Initiator
from tests.iscsi.workflows.iscsi_utils import validate_gwcli_configuration
from utility.log import Log
from utility.utils import generate_unique_id

Expand Down Expand Up @@ -31,7 +34,7 @@ def configure_targets(self, pool, config):
iqn = config["iqn"]
LOG.info(f"Configure IQN target - {iqn}")
ceph_cluster = config["ceph_cluster"]
gw_node.gwcli.target.create(iqn)
LOG.info(gw_node.gwcli.target.create(iqn))

# Add gateways
for gw in config.get("gateways"):
Expand All @@ -40,14 +43,16 @@ def configure_targets(self, pool, config):
"gateway_name": _gw.hostname,
"ip_addresses": _gw.ip_address,
}
gw_node.gwcli.target.gateways.create(iqn, **gw_cfg)
LOG.info(gw_node.gwcli.target.gateways.create(iqn, **gw_cfg))

disks = {}
# Add Hosts and its lun(s)
if config.get("hosts"):
for host in config["hosts"]:
client_iqn = host["client_iqn"]
host_args = {"client_iqn": client_iqn}
gw_node.gwcli.target.hosts.create(iqn, **host_args)
LOG.info(gw_node.gwcli.target.hosts.create(iqn, **host_args))
disks.update({client_iqn: []})

if host.get("disks"):
bdev_configs = host["disks"]
Expand All @@ -59,31 +64,42 @@ def configure_targets(self, pool, config):
size = bdev_cfg["size"]

for num in range(bdev_cfg["count"]):
disk_name = f"{name}-{num}"
args = {
"pool": pool,
"image": f"{name}-{num}",
"image": disk_name,
"size": size,
}
# Create disk
gw_node.gwcli.disks.create(**args)
LOG.info(gw_node.gwcli.disks.create(**args))

# Add Disk to target
args = {"disk": f"{pool}/{name}-{num}"}
gw_node.gwcli.target.disks.create(iqn, **args)
img = f"{pool}/{disk_name}"
args = {"disk": img}
LOG.info(gw_node.gwcli.target.disks.add(iqn, **args))
disks[client_iqn].append(img)

# Attach Disk to client
args = {
"disk": f"{pool}/{name}-{num}",
"disk": img,
"size": size,
"action": "add",
}
gw_node.gwcli.target.hosts.client.disk(
iqn, client_iqn, **args
LOG.info(
gw_node.gwcli.target.hosts.client.disk(
iqn, client_iqn, **args
)
)
out, err = gw_node.gwcli.list()
LOG.error(f"err-{err}")
LOG.debug(f"Output - {out}")

# Validate the iSCSI entities
if config.get("validate", True):
_config = deepcopy(config)
_config["disks"] = disks
validate_gwcli_configuration(self.cluster, gw_node, _config)

def prepare_initiators(self):
for initiator in self.config.get("initiators"):
_node = get_node_by_id(self.cluster, initiator["node"])
Expand Down
54 changes: 54 additions & 0 deletions tests/iscsi/workflows/iscsi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
from ceph.ceph_admin.orch import Orch
from ceph.utils import get_node_by_id
from tests.cephadm import test_iscsi
from utility.log import Log
from utility.utils import generate_unique_id

LOG = Log(__name__)


class GWCLIConfigError(Exception):
pass


def deploy_iscsi_service(ceph_cluster, config):
"""Deploy iSCSI Service with apply or with spec
Expand Down Expand Up @@ -229,3 +236,50 @@ def format_iscsiadm_output(output):
targets[target].append(target_info)

return targets


def validate_gwcli_configuration(ceph_cluster, gwcli_node, config):
"""Validate all entities existence using config export option."""
export_cfg, _ = gwcli_node.gwcli.export()
LOG.info(export_cfg)
export_cfg = json.loads(export_cfg)

# validate the iSCSI Targets
iqn = config["iqn"]
if iqn not in export_cfg["targets"]:
raise GWCLIConfigError(f"{iqn} Target Not found")
target = export_cfg["targets"][iqn]
LOG.info(f"[{iqn}] Target has created succesfully... {target}")

# Validate the iSCSI gateway portals
if config.get("gateways"):
for gw in config["gateways"]:
node = get_node_by_id(ceph_cluster, gw)

if node.hostname not in target["portals"]:
raise GWCLIConfigError(
f"[{iqn}]: {node.hostname} Host not found in target"
)
LOG.info(
f"[{iqn}] Gateway {gw} created successfully.. {target['portals'][node.hostname]}"
)

# Validate the iSCSI target hosts
for host in config["hosts"]:
client_iqn = host["client_iqn"]
if client_iqn not in target["clients"]:
raise GWCLIConfigError(f"[{iqn}]: {client_iqn} Host not found in target")
LOG.info(
f"[{iqn}] - {client_iqn} Host created sucessfully - {target['clients'][client_iqn]}"
)

if host.get("disks"):
disks = config.get("disks")
_disks = sorted(disks[client_iqn])
host_luns = target["clients"][client_iqn]["luns"]

if _disks != sorted(host_luns):
raise GWCLIConfigError(
f"[{iqn}]: Disks didn't match {host_luns} - {disks[client_iqn]}"
)
LOG.info(f"[{iqn}] - Luns created sucessfully - {host_luns}")

0 comments on commit c7a2d4c

Please sign in to comment.