Skip to content

Commit

Permalink
Add kvm and nutanix providers (#834)
Browse files Browse the repository at this point in the history
* Add kvm and nutanix providers

* Update tests
  • Loading branch information
fabriziosestito authored Sep 21, 2022
1 parent ce175e5 commit 53afee4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ defmodule Trento.Integration.Discovery.CloudDiscoveryPayload do
import PolymorphicEmbed, only: [cast_polymorphic_embed: 3]

deftype do
field :provider, Ecto.Enum, values: [:aws, :gcp, :azure, :unknown], default: :unknown
field :provider, Ecto.Enum,
values: [:aws, :gcp, :azure, :kvm, :nutanix, :unknown],
default: :unknown

field :metadata, PolymorphicEmbed,
types: [
Expand Down
2 changes: 1 addition & 1 deletion lib/trento/domain/host/commands/update_provider.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule Trento.Domain.Commands.UpdateProvider do

defcommand do
field :host_id, Ecto.UUID
field :provider, Ecto.Enum, values: [:azure, :aws, :gcp, :unknown]
field :provider, Ecto.Enum, values: [:azure, :aws, :gcp, :kvm, :nutanix, :unknown]

field :provider_data, PolymorphicEmbed,
types: [
Expand Down
2 changes: 1 addition & 1 deletion lib/trento/domain/host/events/provider_updated.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule Trento.Domain.Events.ProviderUpdated do

defevent do
field :host_id, Ecto.UUID
field :provider, Ecto.Enum, values: [:azure, :aws, :gcp, :unknown]
field :provider, Ecto.Enum, values: [:azure, :aws, :gcp, :kvm, :nutanix, :unknown]

field :provider_data, PolymorphicEmbed,
types: [
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/discovery/cloud_discovery_kvm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"discovery_type": "cloud_discovery",
"agent_id": "0a055c90-4cb6-54ce-ac9c-ae3fedaf40d4",
"payload": {
"Provider": "kvm",
"Metadata": {}
}
}
8 changes: 8 additions & 0 deletions test/fixtures/discovery/cloud_discovery_nutanix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"discovery_type": "cloud_discovery",
"agent_id": "0a055c90-4cb6-54ce-ac9c-ae3fedaf40d4",
"payload": {
"Provider": "nutanix",
"Metadata": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,32 @@ defmodule Trento.Integration.Discovery.HostPolicyTest do
|> HostPolicy.handle()
end

test "should return the expected commands when a cloud_discovery payload with an kvm provider is handled" do
assert {
:ok,
%UpdateProvider{
host_id: "0a055c90-4cb6-54ce-ac9c-ae3fedaf40d4",
provider: :kvm
}
} ==
"cloud_discovery_kvm"
|> load_discovery_event_fixture()
|> HostPolicy.handle()
end

test "should return the expected commands when a cloud_discovery payload with an nutanix provider is handled" do
assert {
:ok,
%UpdateProvider{
host_id: "0a055c90-4cb6-54ce-ac9c-ae3fedaf40d4",
provider: :nutanix
}
} ==
"cloud_discovery_nutanix"
|> load_discovery_event_fixture()
|> HostPolicy.handle()
end

test "should return the expected commands when a cloud_discovery payload with an unknown provider is handled" do
assert {
:ok,
Expand Down

0 comments on commit 53afee4

Please sign in to comment.