infinity-aps / infinity_aps

Infinity APS - oref0 compatible closed loop built on Elixir and Nerves
27 stars 4 forks source link

Merge cfg in aps #6

Closed David-Gil closed 6 years ago

David-Gil commented 6 years ago

Notice that I have changed the cfg application to a specific supervisor for InfinityAPS.Configuration.Server.

tmecklem commented 6 years ago

I don't have it set up to comment for why the build fails in the PR (need to figure that out I guess). Anyway, credo is complaining about no moduledocs:

  Software Design                                                               
┃ 
┃ [D] → Nested modules could be aliased at the top of the invoking module.
┃       lib/infinity_aps/cfg/server.ex:55:7 #(InfinityAPS.Configuration.Server.write_config)
  Code Readability                                                              
┃ 
┃ [R] ↓ Do not use parentheses when defining a function which has no arguments.
┃       lib/infinity_aps/cfg.ex:6 #(InfinityAPS.Configuration.get_config)
┃ [R] ↓ Modules should have a @moduledoc tag.
┃       lib/infinity_aps/cfg/server.ex:1:11 #(InfinityAPS.Configuration.Server)
┃ [R] ↓ Do not use parentheses when defining a function which has no arguments.
┃       lib/infinity_aps/cfg.ex:22 #(InfinityAPS.Configuration.save_config)
┃ [R] ↓ Modules should have a @moduledoc tag.
┃       lib/infinity_aps/cfg.ex:1:11 #(InfinityAPS.Configuration)
┃ [R] ↓ Modules should have a @moduledoc tag.
┃       lib/infinity_aps/cfg/preferences.ex:1:11 #(InfinityAPS.Configuration.Preferences)
┃ [R] ↓ Modules should have a @moduledoc tag.
┃       lib/infinity_aps/cfg/configuration_data.ex:1:11 #(InfinityAPS.Configuration.ConfigurationData)
David-Gil commented 6 years ago

OK! I'm going on holidays and then a workshop. I'll be back April 9th. Then I'll fix those issues and whatever that needs to be fixed.

David-Gil commented 6 years ago

Fix port of cfg into aps, credo issues and apply mix format

David-Gil commented 6 years ago

Maybe tests don't pass because of this?:

warning: function Nerves.Runtime.reboot/0 is undefined (module Nerves.Runtime is not available) lib/infinity_aps/cfg/server.ex:56

I have found the same problem on my machine. When the target is host, the nerves_runtime doesn't initiate and therefore no Nerves.Runtime is present.

I have changed the configuration to initiate it with the host target, but it raises other issues and the app crashes.

In any case, I need your help to get this passing. Otherwise, I won't be able to continue.

Could it be that it doesn't have anything to do with this PR.

tmecklem commented 6 years ago

credo says

┃ 
┃ [D] → Nested modules could be aliased at the top of the invoking module.
┃       lib/infinity_aps/cfg/server.ex:56:7 #(InfinityAPS.Configuration.Server.write_config)

I'd be happy to take care of this if you'd like. I don't want credo to be an obstacle and I appreciate your contributions. Let me know what you'd like to do with stuff like this (have me fix it or address it yourself).

David-Gil commented 6 years ago

Don't worry, I'll take care of these Credo things.

I spent yesterday almost an hour on this issue because I wouldn't understand what it was telling me. From the Credo message, I thought that it was this code: InfinityAPS.Configuration.Server.write_config, but it actually was telling me that the problem was in that function. I suppose I entered an infinite loop and I needed some fresh air to understand it.

I also thought that it was in code that I had written, not in existing code. That's why I eventually gave up.

I've run mix test before and after my changes. Tests passed before my changes because there wasn't any call to Nerves.Runtime in aps (though the warning already appeared). Now the call to Nerves.Runtime in cfg has passed to aps and it doesn't permit the tests to go on. This is something I can't fix, because I don't know enough about Nerves. In any case, the problem is about the Nerves.Runtime init configuration.

David-Gil commented 6 years ago

Well, I don't easily give up.

Adding shoehorn and nerves_runtime to aps/mix.exs and configuring aps/config/config.exs like this allows the tests to pass.

config :shoehorn,
  overlay_path: "",
  init: [:nerves_runtime],
  app: :aps

The thing is I have to run them with sudo, otherwise it gives me this message:

log_tailer: open /proc/kmsg: Permission denied
log_tailer: bind /dev/log: Address already in use
log_tailer: open /proc/kmsg: Permission denied
log_tailer: bind /dev/log: Address already in use
[error] GenServer Nerves.Runtime.LogTailer.Kmsg terminating
** (FunctionClauseError) no function clause matching in Nerves.Runtime.LogTailer.handle_info/2                                                               
    (nerves_runtime) lib/nerves_runtime/log_tailer.ex:43: Nerves.Runtime.LogTailer.handle_info({#Port<0.26962>, {:exit_status, 1}}, %{buffer: "", port: #Port<0.26962>, type: :kmsg})                                                                                                                                     
    (stdlib) gen_server.erl:616: :gen_server.try_dispatch/4
    (stdlib) gen_server.erl:686: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: {#Port<0.26962>, {:exit_status, 1}}
State: %{buffer: "", port: #Port<0.26962>, type: :kmsg}
[error] GenServer Nerves.Runtime.LogTailer.Syslog terminating
** (FunctionClauseError) no function clause matching in Nerves.Runtime.LogTailer.handle_info/2
    (nerves_runtime) lib/nerves_runtime/log_tailer.ex:43: Nerves.Runtime.LogTailer.handle_info({#Port<0.26961>, {:exit_status, 1}}, %{buffer: "", port: #Port<0.26961>, type: :syslog})
    (stdlib) gen_server.erl:616: :gen_server.try_dispatch/4
    (stdlib) gen_server.erl:686: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: {#Port<0.26961>, {:exit_status, 1}}
State: %{buffer: "", port: #Port<0.26961>, type: :syslog}
[error] GenServer Nerves.Runtime.LogTailer.Kmsg terminating
** (FunctionClauseError) no function clause matching in Nerves.Runtime.LogTailer.handle_info/2
    (nerves_runtime) lib/nerves_runtime/log_tailer.ex:43: Nerves.Runtime.LogTailer.handle_info({#Port<0.27033>, {:exit_status, 1}}, %{buffer: "", port: #Port<0.27033>, type: :kmsg})
    (stdlib) gen_server.erl:616: :gen_server.try_dispatch/4
    (stdlib) gen_server.erl:686: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: {#Port<0.27033>, {:exit_status, 1}}
State: %{buffer: "", port: #Port<0.27033>, type: :kmsg}
[error] GenServer Nerves.Runtime.LogTailer.Syslog terminating
** (FunctionClauseError) no function clause matching in Nerves.Runtime.LogTailer.handle_info/2
    (nerves_runtime) lib/nerves_runtime/log_tailer.ex:43: Nerves.Runtime.LogTailer.handle_info({#Port<0.27036>, {:exit_status, 1}}, %{buffer: "", port: #Port<0.27036>, type: :syslog})
    (stdlib) gen_server.erl:616: :gen_server.try_dispatch/4
    (stdlib) gen_server.erl:686: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: {#Port<0.27036>, {:exit_status, 1}}
State: %{buffer: "", port: #Port<0.27036>, type: :syslog}

The problem with this is that I don't really know what I'm doing.

tmecklem commented 6 years ago

👍