Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid SUMA health complete on settings not configured error #2547

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading