Skip to content

Commit

Permalink
Fixes in SmartStart support
Browse files Browse the repository at this point in the history
Fixes SRHUB-188
  • Loading branch information
jfcloutier authored and mattludwigs committed Feb 12, 2020
1 parent 8c39de7 commit 8b357e3
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 36 deletions.
9 changes: 7 additions & 2 deletions lib/grizzly/command_class/node_provisioning/list_all.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ defmodule Grizzly.CommandClass.NodeProvisioning.ListAll do
}
}
) do
info = Map.drop(list_iteration_report, ~w(remaining_count seq_number)a)
{:done, {:ok, Enum.reverse([info | buffer])}}
info = %{dsk: dsk} = Map.drop(list_iteration_report, ~w(remaining_count seq_number)a)

if dsk == nil do
{:done, {:ok, Enum.reverse(buffer)}}
else
{:done, {:ok, Enum.reverse([info | buffer])}}
end
end

def handle_response(
Expand Down
44 changes: 30 additions & 14 deletions lib/grizzly/packet/body_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -612,20 +612,36 @@ defmodule Grizzly.Packet.BodyParser do
<<0x78, 0x04, seq_number::size(8), remaining_count::size(8), _reserved::size(3),
_dsk_length::size(5), rest::binary>>
) do
<<dsk_binary::binary-size(16), extensions::binary()>> = rest
{:ok, dsk_string} = DSK.binary_to_string(dsk_binary)
{:ok, meta_extensions} = Grizzly.SmartStart.MetaExtension.extensions_from_binary(extensions)

%{
command_class: :node_provisioning,
command: :list_iteration_report,
value: %{
seq_number: seq_number,
remaining_count: remaining_count,
dsk: dsk_string,
meta_extensions: meta_extensions
}
}
case rest do
<<>> ->
%{
command_class: :node_provisioning,
command: :list_iteration_report,
value: %{
seq_number: seq_number,
remaining_count: 0,
dsk: nil,
meta_extensions: []
}
}

<<dsk_binary::binary-size(16), extensions::binary()>> ->
{:ok, dsk_string} = DSK.binary_to_string(dsk_binary)

{:ok, meta_extensions} =
Grizzly.SmartStart.MetaExtension.extensions_from_binary(extensions)

%{
command_class: :node_provisioning,
command: :list_iteration_report,
value: %{
seq_number: seq_number,
remaining_count: remaining_count,
dsk: dsk_string,
meta_extensions: meta_extensions
}
}
end
end

def parse(
Expand Down
22 changes: 11 additions & 11 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
%{
"dialyxir": {:hex, :dialyxir, "1.0.0-rc.6", "78e97d9c0ff1b5521dd68041193891aebebce52fc3b93463c0a6806874557d7d", [:mix], [{:erlex, "~> 0.2.1", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm"},
"earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"},
"elixir_make": {:hex, :elixir_make, "0.6.0", "38349f3e29aff4864352084fc736fa7fa0f2995a819a737554f7ebd28b85aaab", [:mix], [], "hexpm"},
"erlex": {:hex, :erlex, "0.2.2", "cb0e6878fdf86dc63509eaf2233a71fa73fc383c8362c8ff8e8b6f0c2bb7017c", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"file_system": {:hex, :file_system, "0.2.7", "e6f7f155970975789f26e77b8b8d8ab084c59844d8ecfaf58cbda31c494d14aa", [:mix], [], "hexpm"},
"makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
"makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
"mix_test_watch": {:hex, :mix_test_watch, "0.9.0", "c72132a6071261893518fa08e121e911c9358713f62794a90c95db59042af375", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm"},
"muontrap": {:hex, :muontrap, "0.4.4", "61b676605205d59f418bee65613e1b88368ee5281e141fbc81563954037667f6", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"},
"dialyxir": {:hex, :dialyxir, "1.0.0-rc.6", "78e97d9c0ff1b5521dd68041193891aebebce52fc3b93463c0a6806874557d7d", [:mix], [{:erlex, "~> 0.2.1", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "49496d63267bc1a4614ffd5f67c45d9fc3ea62701a6797975bc98bc156d2763f"},
"earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm", "e3be2bc3ae67781db529b80aa7e7c49904a988596e2dbff897425b48b3581161"},
"elixir_make": {:hex, :elixir_make, "0.6.0", "38349f3e29aff4864352084fc736fa7fa0f2995a819a737554f7ebd28b85aaab", [:mix], [], "hexpm", "d522695b93b7f0b4c0fcb2dfe73a6b905b1c301226a5a55cb42e5b14d509e050"},
"erlex": {:hex, :erlex, "0.2.2", "cb0e6878fdf86dc63509eaf2233a71fa73fc383c8362c8ff8e8b6f0c2bb7017c", [:mix], [], "hexpm", "423a8f6ac70b77f0001c18adbff2b10413afed6901c2975aa33151a9c1263307"},
"ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "8e24fc8ff9a50b9f557ff020d6c91a03cded7e59ac3e0eec8a27e771430c7d27"},
"file_system": {:hex, :file_system, "0.2.7", "e6f7f155970975789f26e77b8b8d8ab084c59844d8ecfaf58cbda31c494d14aa", [:mix], [], "hexpm", "b4cfa2d69c7f0b18fd06db222b2398abeef743a72504e6bd7df9c52f171b047f"},
"makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5fbc8e549aa9afeea2847c0769e3970537ed302f93a23ac612602e805d9d1e7f"},
"makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "adf0218695e22caeda2820eaba703fa46c91820d53813a2223413da3ef4ba515"},
"mix_test_watch": {:hex, :mix_test_watch, "0.9.0", "c72132a6071261893518fa08e121e911c9358713f62794a90c95db59042af375", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "817dec4a7f6edf260258002f99ac8ffaf7a8f395b27bf2d13ec24018beecec8a"},
"muontrap": {:hex, :muontrap, "0.4.4", "61b676605205d59f418bee65613e1b88368ee5281e141fbc81563954037667f6", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "d4a091525ae05ca2d60dfd1bf576f67b867408661a76142052b7f745ee6a7dcb"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm", "5c040b8469c1ff1b10093d3186e2e10dbe483cd73d79ec017993fb3985b8a9b3"},
}
20 changes: 11 additions & 9 deletions test/grizzly/command_class/node_provisioning/set_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,35 @@ defmodule Grizzly.CommandClass.NodeProvisioning.SetTest do

setup do
dsk = "50285-18819-09924-30691-15973-33711-04005-03623"
{:ok, %{dsk: dsk}}
meta_extensions = []
{:ok, %{dsk: dsk, meta_extensions: meta_extensions}}
end

describe "implements the Grizzly command behaviour" do
test "initializes the command state", %{dsk: dsk} do
{:ok, command} = Set.init(dsk: dsk)
test "initializes the command state", %{dsk: dsk, meta_extensions: meta_extensions} do
{:ok, command} = Set.init(dsk: dsk, meta_extensions: meta_extensions)

assert %Set{dsk: dsk} == command
assert %Set{dsk: dsk, meta_extensions: meta_extensions} == command
end

test "encodes correctly", %{dsk: dsk} do
test "encodes correctly", %{dsk: dsk, meta_extensions: meta_extensions} do
{:ok, binary_dsk} = DSK.string_to_binary(dsk)
{:ok, command} = Set.init(dsk: dsk, seq_number: 0x06)
{:ok, command} = Set.init(dsk: dsk, meta_extensions: meta_extensions, seq_number: 0x06)

binary = <<35, 2, 128, 208, 6, 0, 0, 3, 2, 0, 0x78, 0x01, 0x06, 0x10>> <> binary_dsk

assert {:ok, binary} == Set.encode(command)
end

test "errors when dsk is too long", %{dsk: dsk} do
{:ok, command} = Set.init(seq_number: 0x06, dsk: dsk <> "-12312")
test "errors when dsk is too long", %{dsk: dsk, meta_extensions: meta_extensions} do
{:ok, command} =
Set.init(seq_number: 0x06, dsk: dsk <> "-12312", meta_extensions: meta_extensions)

assert {:error, %EncodeError{}} = Set.encode(command)
end

test "errors when dsk is too short" do
{:ok, command} = Set.init(seq_number: 0x06, dsk: "12345-12345")
{:ok, command} = Set.init(seq_number: 0x06, dsk: "12345-12345", meta_extensions: [])

assert {:error, %EncodeError{}} = Set.encode(command)
end
Expand Down

0 comments on commit 8b357e3

Please sign in to comment.