Skip to content

Commit

Permalink
storage: create_nvme_ functions
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <[email protected]>
  • Loading branch information
glimchb committed Feb 11, 2023
1 parent 7fde47f commit 8cb0b55
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 8 deletions.
32 changes: 29 additions & 3 deletions pydpu/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

from .inventory import get_inventory
from .ipsec import create_new_tunnel, get_stats
from .storage import nvme_subsystems
from .storage import (
create_nvme_controller,
create_nvme_namespace,
create_nvme_subsystem,
list_nvme_subsystems,
)


@click.group()
Expand Down Expand Up @@ -58,8 +63,29 @@ def storage(ctx):

@storage.command()
@click.pass_context
def subsystems(ctx, **kwargs):
nvme_subsystems(ctx.obj["ADDRESS"])
def list(ctx, **kwargs):
list_nvme_subsystems(ctx.obj["ADDRESS"])
click.echo("work in progress")


@storage.command()
@click.pass_context
def subsystem(ctx, **kwargs):
create_nvme_subsystem(ctx.obj["ADDRESS"])
click.echo("work in progress")


@storage.command()
@click.pass_context
def controller(ctx, **kwargs):
create_nvme_controller(ctx.obj["ADDRESS"])
click.echo("work in progress")


@storage.command()
@click.pass_context
def namespace(ctx, **kwargs):
create_nvme_namespace(ctx.obj["ADDRESS"])
click.echo("work in progress")


Expand Down
85 changes: 83 additions & 2 deletions pydpu/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,94 @@

import grpc

from .proto.v1 import frontend_nvme_pcie_pb2
from .proto.v1 import (
frontend_nvme_pcie_pb2,
frontend_nvme_pcie_pb2_grpc,
object_key_pb2,
opicommon_pb2,
uuid_pb2,
)


def nvme_subsystems(address):
def list_nvme_subsystems(address):
print(
"tbd",
address,
grpc.StatusCode.UNIMPLEMENTED,
frontend_nvme_pcie_pb2.ListNVMeSubsystemsRequest(),
)


def create_nvme_subsystem(address):
channel = grpc.insecure_channel(address)
stub = frontend_nvme_pcie_pb2_grpc.FrontendNvmeServiceStub(channel)
try:
res = stub.CreateNVMeSubsystem(
request=frontend_nvme_pcie_pb2.CreateNVMeSubsystemRequest(
nv_me_subsystem=frontend_nvme_pcie_pb2.NVMeSubsystem(
spec=frontend_nvme_pcie_pb2.NVMeSubsystemSpec(
id=object_key_pb2.ObjectKey(value="opi-subsystem"),
model_number="OPI Model",
serial_number="OPI SN",
max_namespaces=10,
nqn="nqn.2022-09.io.spdk:opi1",
)
)
)
)
print(res)
except grpc.RpcError as e:
print(e)


def create_nvme_controller(address):
channel = grpc.insecure_channel(address)
stub = frontend_nvme_pcie_pb2_grpc.FrontendNvmeServiceStub(channel)
try:
res = stub.CreateNVMeController(
request=frontend_nvme_pcie_pb2.CreateNVMeControllerRequest(
nv_me_controller=frontend_nvme_pcie_pb2.NVMeController(
spec=frontend_nvme_pcie_pb2.NVMeControllerSpec(
id=object_key_pb2.ObjectKey(value="opi-ctrl"),
subsystem_id=object_key_pb2.ObjectKey(value="opi-subsystem"),
pcie_id=opicommon_pb2.PciEndpoint(
physical_function=1, virtual_function=2, port_id=3
),
max_nsq=5,
max_ncq=6,
sqes=7,
cqes=8,
nvme_controller_id=1,
)
)
)
)
print(res)
except grpc.RpcError as e:
print(e)


def create_nvme_namespace(address):
channel = grpc.insecure_channel(address)
stub = frontend_nvme_pcie_pb2_grpc.FrontendNvmeServiceStub(channel)
try:
res = stub.CreateNVMeNamespace(
request=frontend_nvme_pcie_pb2.CreateNVMeNamespaceRequest(
nv_me_namespace=frontend_nvme_pcie_pb2.NVMeNamespace(
spec=frontend_nvme_pcie_pb2.NVMeNamespaceSpec(
id=object_key_pb2.ObjectKey(value="opi-ns"),
subsystem_id=object_key_pb2.ObjectKey(value="opi-subsystem"),
volume_id=object_key_pb2.ObjectKey(value="Malloc1"),
uuid=uuid_pb2.Uuid(
value="1b4e28ba-2fa1-11d2-883f-b9a761bde3fb"
),
nguid="1b4e28ba-2fa1-11d2-883f-b9a761bde3fb",
eui64=1967554867335598546,
host_nsid=1,
)
)
)
)
print(res)
except grpc.RpcError as e:
print(e)
30 changes: 27 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,33 @@ def test_cli_ipsec_create_tunnel(runner):
assert result.exit_code == 0


def test_cli_storage_subsystems(runner):
"""Test `dpu storage subsystems"""
def test_cli_storage_list(runner):
"""Test `dpu storage list"""
result = runner.invoke(
cli.main, ("--address", "localhost:50003", "storage", "subsystems")
cli.main, ("--address", "localhost:50003", "storage", "list")
)
assert result.exit_code == 0


def test_cli_storage_subsystem(runner):
"""Test `dpu storage subsystem"""
result = runner.invoke(
cli.main, ("--address", "localhost:50004", "storage", "subsystem")
)
assert result.exit_code == 0


def test_cli_storage_controller(runner):
"""Test `dpu storage controller"""
result = runner.invoke(
cli.main, ("--address", "localhost:50005", "storage", "controller")
)
assert result.exit_code == 0


def test_cli_storage_namespace(runner):
"""Test `dpu storage namespace"""
result = runner.invoke(
cli.main, ("--address", "localhost:50006", "storage", "namespace")
)
assert result.exit_code == 0

0 comments on commit 8cb0b55

Please sign in to comment.