Skip to content

Commit

Permalink
Add new check_system implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorRigby committed Jul 2, 2020
1 parent b132ddd commit c23606f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 5 deletions.
37 changes: 34 additions & 3 deletions lib/vintage_net_wifi.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule VintageNetWiFi do
@behaviour VintageNet.Technology
alias VintageNet.Technology.SystemCheck

require Logger

Expand Down Expand Up @@ -321,10 +322,40 @@ defmodule VintageNetWiFi do
{:error, :unsupported}
end

@required_programs [
:bin_wpa_supplicant,
:bin_ip
]

@optional_programs [
:bin_udhcpc,
:bin_udhcpd,
:bin_dnsd
]

@impl true
def check_system(_opts) do
# TODO
:ok
def check_system(opts) do
programs = Keyword.take(opts, @required_programs ++ @optional_programs) |> Keyword.keys()

Enum.reduce(programs, %SystemCheck{}, fn
program, %{errors: errors} = system_check when program in @required_programs ->
case VintageNet.Command.verify_program(opts, program) do
:ok ->
system_check

{:error, reason} ->
%{system_check | errors: [reason | errors]}
end

program, %{warnings: warnings} = system_check when program in @optional_programs ->
case VintageNet.Command.verify_program(opts, program) do
:ok ->
system_check

{:error, reason} ->
%{system_check | warnings: [reason | warnings]}
end
end)
end

defp wifi_to_supplicant_contents(wifi, control_interface_dir, regulatory_domain) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ defmodule VintageNetWiFi.MixProject do

defp deps do
[
{:vintage_net, "~> 0.8.0"},
{:vintage_net, github: "nerves-networking/vintage_net", branch: "run-diagnostics"},
{:credo, "~> 1.2", only: :test, runtime: false},
{:dialyxir, "~> 1.0.0", only: [:dev, :test], runtime: false},
{:elixir_make, "~> 0.6", runtime: false},
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.5.0", "8516502659002cec19e244ebd90d312183064be95025a319a6c7e89f4bccd65b", [:rebar3], [], "hexpm", "d48d002e15f5cc105a696cf2f1bbb3fc72b4b770a184d8420c8db20da2674b38"},
"vintage_net": {:hex, :vintage_net, "0.8.0", "6d8788c3a6cfddb8b98bacd30d1c58edf29ddb61130667496828129577dca790", [:make, :mix], [{:busybox, "~> 0.1.5", [hex: :busybox, repo: "hexpm", optional: true]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:gen_state_machine, "~> 2.0.0 or ~> 2.1.0", [hex: :gen_state_machine, repo: "hexpm", optional: false]}, {:muontrap, "~> 0.5.1 or ~> 0.6.0", [hex: :muontrap, repo: "hexpm", optional: false]}], "hexpm", "492cdec21b8ee9c2a3bb0dfd6fa12d1f2aadb19875c1bf3f780dc5b899dde9eb"},
"vintage_net": {:git, "https://github.com/nerves-networking/vintage_net.git", "fdfb38bf93dcac0a91a0cdd65f0a0b009ed5e286", [branch: "run-diagnostics"]},
}
49 changes: 49 additions & 0 deletions test/vintage_net_wifi_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1845,4 +1845,53 @@ defmodule VintageNetWiFiTest do

assert output == VintageNetWiFi.to_raw_config("wlan0", input, default_opts())
end

test "check_system/1 required programs" do
:ok = File.write("/tmp/vintage_net/check_system_exists", "test")

success_opts = [
bin_wpa_supplicant: "/tmp/vintage_net/check_system_exists",
bin_ip: "/tmp/vintage_net/check_system_exists",
bin_udhcpc: "/tmp/vintage_net/check_system_exists",
bin_udhcpd: "/tmp/vintage_net/check_system_exists",
bin_dnsd: "/tmp/vintage_net/check_system_exists"
]

assert %{warnings: [], errors: []} = VintageNetWiFi.check_system(success_opts)

error_opts = [
bin_wpa_supplicant: "/tmp/vintage_net/bin_wpa_supplicant",
bin_ip: "/tmp/vintage_net/bin_ip",
bin_udhcpc: "/tmp/vintage_net/check_system_exists",
bin_udhcpd: "/tmp/vintage_net/check_system_exists",
bin_dnsd: "/tmp/vintage_net/check_system_exists"
]

assert %{
errors: [
"Can't find /tmp/vintage_net/bin_ip",
"Can't find /tmp/vintage_net/bin_wpa_supplicant"
]
} = VintageNetWiFi.check_system(error_opts)
end

test "check_system/1 optional programs" do
:ok = File.write("/tmp/vintage_net/check_system_exists", "test")

warn_opts = [
bin_wpa_supplicant: "/tmp/vintage_net/check_system_exists",
bin_ip: "/tmp/vintage_net/check_system_exists",
bin_udhcpc: "/tmp/vintage_net/bin_udhcpc",
bin_udhcpd: "/tmp/vintage_net/bin_udhcpd",
bin_dnsd: "/tmp/vintage_net/bin_dnsd"
]

assert %{
warnings: [
"Can't find /tmp/vintage_net/bin_dnsd",
"Can't find /tmp/vintage_net/bin_udhcpd",
"Can't find /tmp/vintage_net/bin_udhcpc"
]
} = VintageNetWiFi.check_system(warn_opts)
end
end

0 comments on commit c23606f

Please sign in to comment.