Skip to content

Commit

Permalink
Avoid SUMA health complete on settings not configured error
Browse files Browse the repository at this point in the history
  • Loading branch information
arbulu89 committed Apr 24, 2024
1 parent c02fe82 commit a10eac6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/trento/software_updates/discovery.ex
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ defmodule Trento.SoftwareUpdates.Discovery do
|> commanded().dispatch() do
{:ok, host_id, system_id, relevant_patches}
else
{:error, :settings_not_configured} ->
{:error, :settings_not_configured}

{:error, discovery_error} = error ->
Logger.error(
"An error occurred during software updates discovery for host #{host_id}: #{inspect(error)}"
Expand All @@ -106,6 +109,9 @@ defmodule Trento.SoftwareUpdates.Discovery do
end
end

defp discover_host_software_updates(_, _, {:error, :settings_not_configured} = error),
do: error

defp discover_host_software_updates(host_id, _, {:error, error}) do
commanded().dispatch(
CompleteSoftwareUpdatesDiscovery.new!(%{
Expand Down
44 changes: 44 additions & 0 deletions test/trento/software_updates/discovery_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,29 @@ defmodule Trento.SoftwareUpdates.DiscoveryTest do
Discovery.discover_host_software_updates(host_id, fully_qualified_domain_name)
end

test "should handle failure when SUMA settings are not configured" do
host_id = Faker.UUID.v4()
fully_qualified_domain_name = Faker.Internet.domain_name()

expect(
SoftwareUpdatesDiscoveryMock,
:get_system_id,
fn ^fully_qualified_domain_name -> {:error, :settings_not_configured} end
)

expect(
Trento.Commanded.Mock,
:dispatch,
0,
fn _ ->
:ok
end
)

{:error, :settings_not_configured} =
Discovery.discover_host_software_updates(host_id, fully_qualified_domain_name)
end

test "should complete discovery" do
scenarios = [
%{
Expand Down Expand Up @@ -184,6 +207,27 @@ defmodule Trento.SoftwareUpdates.DiscoveryTest do
end)
end

test "should handle SUMA settings not configured error" do
expect(SoftwareUpdatesDiscoveryMock, :setup, fn -> {:error, :settings_not_configured} end)

[%{id: host_id1}, %{id: host_id2}] = insert_list(2, :host)

expect(
Trento.Commanded.Mock,
:dispatch,
0,
fn _ ->
:ok
end
)

{:ok, {[], errored_discoveries}} = Discovery.discover_software_updates()

Enum.each([host_id1, host_id2], fn host_id ->
assert {:error, host_id, :settings_not_configured} in errored_discoveries
end)
end

test "should handle hosts without fqdn" do
expect(SoftwareUpdatesDiscoveryMock, :setup, fn -> :ok end)

Expand Down

0 comments on commit a10eac6

Please sign in to comment.