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

Clear software updates discovered health on host deregistration #2436

Merged
merged 1 commit into from
Mar 26, 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
3 changes: 3 additions & 0 deletions lib/trento/hosts/host.ex
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ defmodule Trento.Hosts.Host do
%DeregisterHost{deregistered_at: deregistered_at}
) do
[
%SoftwareUpdatesDiscoveryCleared{
host_id: host_id
},
%HostDeregistered{
host_id: host_id,
deregistered_at: deregistered_at
Expand Down
34 changes: 33 additions & 1 deletion test/trento/hosts/host_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,35 @@ defmodule Trento.Hosts.HostTest do
)
end

test "should clear up software updates discoveries on deregistration" do
host_id = Faker.UUID.v4()
deregistered_at = DateTime.utc_now()

assert_state(
[
build(:host_registered_event, host_id: host_id),
build(:software_updates_discovery_completed_event,
host_id: host_id,
relevant_patches: %{
security_advisories: 5,
bug_fixes: 0,
software_enhancements: 0
}
)
],
%DeregisterHost{
host_id: host_id,
deregistered_at: deregistered_at
},
fn host ->
assert %Host{
software_updates_discovery_health: Health.unknown(),
deregistered_at: ^deregistered_at
} = host
end
)
end

test "should reject all the commands except the registration ones when the host is deregistered" do
host_id = Faker.UUID.v4()
dat = DateTime.utc_now()
Expand Down Expand Up @@ -1905,7 +1934,7 @@ defmodule Trento.Hosts.HostTest do
end
end

test "should emit the HostDeregistered and HostTombstoned events" do
test "should emit relevant events when deregistering a host" do
host_id = Faker.UUID.v4()
dat = DateTime.utc_now()

Expand All @@ -1920,6 +1949,9 @@ defmodule Trento.Hosts.HostTest do
}
],
[
%SoftwareUpdatesDiscoveryCleared{
host_id: host_id
},
%HostDeregistered{
host_id: host_id,
deregistered_at: dat
Expand Down
Loading