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

Fix fqdn nil transition on host restoration and host detail changes #2518

Merged
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
9 changes: 2 additions & 7 deletions lib/trento/hosts/host.ex
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ defmodule Trento.Hosts.Host do
def execute(
%Host{
host_id: host_id,
deregistered_at: deregistered_at,
fully_qualified_domain_name: current_fully_qualified_domain_name
deregistered_at: deregistered_at
},
%RegisterHost{
hostname: hostname,
Expand Down Expand Up @@ -264,11 +263,7 @@ defmodule Trento.Hosts.Host do
installation_source: installation_source
}
] ++
maybe_emit_software_updates_discovery_events(
host_id,
current_fully_qualified_domain_name,
new_fully_qualified_domain_name
)
maybe_emit_software_updates_discovery_events(host_id, nil, new_fully_qualified_domain_name)
end

def execute(
Expand Down
56 changes: 56 additions & 0 deletions test/trento/hosts/host_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2193,6 +2193,62 @@ defmodule Trento.Hosts.HostTest do
end
end

test "should restore and update a deregistered host but not trigger software updates discovery when FQDN stays null or gets nullified" do
scenarios = [
%{
initial_fqdn: nil,
new_fqdn: nil
},
%{
initial_fqdn: Faker.Internet.domain_name(),
new_fqdn: nil
}
]

for %{initial_fqdn: initial_fqdn, new_fqdn: new_fqdn} <- scenarios do
host_id = Faker.UUID.v4()

initial_events = [
build(:host_registered_event,
host_id: host_id,
fully_qualified_domain_name: initial_fqdn
),
%HostDeregistered{
host_id: host_id,
deregistered_at: DateTime.utc_now()
}
]

restoration_command =
build(:register_host_command, host_id: host_id, fully_qualified_domain_name: new_fqdn)

assert_events_and_state(
initial_events,
[
restoration_command
],
[
%HostRestored{host_id: host_id},
%HostDetailsUpdated{
host_id: restoration_command.host_id,
hostname: restoration_command.hostname,
ip_addresses: restoration_command.ip_addresses,
agent_version: restoration_command.agent_version,
cpu_count: restoration_command.cpu_count,
total_memory_mb: restoration_command.total_memory_mb,
socket_count: restoration_command.socket_count,
os_version: restoration_command.os_version,
installation_source: restoration_command.installation_source,
fully_qualified_domain_name: restoration_command.fully_qualified_domain_name
}
],
fn host ->
assert nil == host.deregistered_at
end
)
end
end

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