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

[RHCLOUD-30604] return ansible_host with the high level connection status response #371

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions internal/api/connectors/inventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func (this *inventoryConnectorImpl) GetHostConnectionDetails(ctx context.Context
SatelliteVersion: satelliteFacts.SatelliteVersion,
SatelliteOrgID: satelliteFacts.SatelliteOrgID,
RHCClientID: systemProfileResults[*host.Id].SystemProfile.RhcClientId,
AnsibleHost: host.AnsibleHost,
}
}

Expand Down
2 changes: 2 additions & 0 deletions internal/api/connectors/inventory/inventory_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (this *inventoryConnectorMock) GetHostConnectionDetails(
satelliteOrgID := "5"
satelliteVersion := "6.11"
rhcClientID := "32af5948-301f-449a-a25b-ff34c83264a2"
ansibleHost := "test-ansible-host"

hostDetails := HostDetails{
ID: "c484f980-ab8d-401b-90e7-aa1d4ccf8c0e",
Expand All @@ -43,6 +44,7 @@ func (this *inventoryConnectorMock) GetHostConnectionDetails(
ID: "fe30b997-c15a-44a9-89df-c236c3b5c540",
OwnerID: &ownerID,
RHCClientID: &rhcClientID,
AnsibleHost: &ansibleHost,
}

hostDetailsList := []HostDetails{hostDetails, directConnectDetails}
Expand Down
1 change: 1 addition & 0 deletions internal/api/connectors/inventory/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type HostDetails struct {
SatelliteVersion *string `json:"satellite_version,omitempty"`
SatelliteOrgID *string `json:"satellite_org_id,omitempty"`
RHCClientID *string `json:"rhc_client_id,omitempty"`
AnsibleHost *string `json:"ansible_host,omitempty"`
}

type InventoryConnector interface {
Expand Down
37 changes: 25 additions & 12 deletions internal/api/controllers/private/highlevelConnectionStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type rhcSatellite struct {
SatelliteInstanceID string
SatelliteOrgID string
SatelliteVersion string
Hosts []string
HostsWithAnsibleHosts []HostAttribute
SourceID string
RhcClientID *string
SourceAvailabilityStatus *string
Expand Down Expand Up @@ -110,7 +110,7 @@ func sortHostsByRecipient(details []inventory.HostDetails) (satelliteDetails []i
return satelliteConnectedHosts, directConnectedHosts, hostsNotConnected
}

func formatConnectionResponse(satID *string, satOrgID *string, rhcClientID *string, orgID OrgId, hosts []string, recipientType string, status string) RecipientWithConnectionInfo {
func formatConnectionResponse(satID *string, satOrgID *string, rhcClientID *string, orgID OrgId, hosts []HostAttribute, recipientType string, status string) RecipientWithConnectionInfo {
formatedHosts := make([]HostId, len(hosts))
var formatedSatID SatelliteId
var formatedSatOrgID SatelliteOrgId
Expand All @@ -129,7 +129,7 @@ func formatConnectionResponse(satID *string, satOrgID *string, rhcClientID *stri
}

for i, host := range hosts {
formatedHosts[i] = HostId(host)
formatedHosts[i] = host.HostId
}

connectionInfo := RecipientWithConnectionInfo{
Expand All @@ -140,6 +140,7 @@ func formatConnectionResponse(satID *string, satOrgID *string, rhcClientID *stri
SatOrgId: formatedSatOrgID,
Status: status,
Systems: formatedHosts,
SystemsInfo: hosts,
}

return connectionInfo
Expand All @@ -162,7 +163,13 @@ func getDirectConnectStatus(ctx echo.Context, client connectors.CloudConnectorCl
connectionStatus = "disconnected"
}

responses = append(responses, formatConnectionResponse(nil, nil, host.RHCClientID, orgId, []string{host.ID}, string(RecipientType_directConnect), connectionStatus))
ansibleHost := AnsibleHost("")
if host.AnsibleHost != nil {
ansibleHost = AnsibleHost(*host.AnsibleHost)
}
hostWithAnsibleHost := []HostAttribute{{ansibleHost, HostId(host.ID)}}

responses = append(responses, formatConnectionResponse(nil, nil, host.RHCClientID, orgId, hostWithAnsibleHost, string(RecipientType_directConnect), connectionStatus))
}

return responses, nil
Expand All @@ -189,14 +196,20 @@ func groupHostsBySatellite(hostDetails []inventory.HostDetails) map[string]*rhcS
satInstanceAndOrg := *host.SatelliteInstanceID + *host.SatelliteOrgID
_, exists := hostsGroupedBySatellite[satInstanceAndOrg]

ansibleHost := AnsibleHost("")
if host.AnsibleHost != nil {
ansibleHost = AnsibleHost(*host.AnsibleHost)
}
hostWithAnsibleHost := HostAttribute{ansibleHost, HostId(host.ID)}

if exists {
hostsGroupedBySatellite[satInstanceAndOrg].Hosts = append(hostsGroupedBySatellite[satInstanceAndOrg].Hosts, host.ID)
hostsGroupedBySatellite[satInstanceAndOrg].HostsWithAnsibleHosts = append(hostsGroupedBySatellite[satInstanceAndOrg].HostsWithAnsibleHosts, hostWithAnsibleHost)
} else {
hostsGroupedBySatellite[satInstanceAndOrg] = &rhcSatellite{
SatelliteInstanceID: *host.SatelliteInstanceID,
SatelliteOrgID: *host.SatelliteOrgID,
SatelliteVersion: *host.SatelliteVersion,
Hosts: []string{host.ID},
SatelliteInstanceID: *host.SatelliteInstanceID,
SatelliteOrgID: *host.SatelliteOrgID,
SatelliteVersion: *host.SatelliteVersion,
HostsWithAnsibleHosts: []HostAttribute{hostWithAnsibleHost},
}
}
}
Expand Down Expand Up @@ -238,18 +251,18 @@ func createSatelliteConnectionResponses(ctx echo.Context, hostsGroupedBySatellit
connectionStatus = "disconnected"
}

responses = append(responses, formatConnectionResponse(&satellite.SatelliteInstanceID, &satellite.SatelliteOrgID, satellite.RhcClientID, orgId, satellite.Hosts, string(RecipientType_satellite), connectionStatus))
responses = append(responses, formatConnectionResponse(&satellite.SatelliteInstanceID, &satellite.SatelliteOrgID, satellite.RhcClientID, orgId, satellite.HostsWithAnsibleHosts, string(RecipientType_satellite), connectionStatus))
}
}

return responses, nil
}

func getRHCStatus(hostDetails []inventory.HostDetails, orgID OrgId) RecipientWithConnectionInfo {
hostIDs := make([]string, len(hostDetails))
hostIDs := make([]HostAttribute, len(hostDetails))

for i, host := range hostDetails {
hostIDs[i] = host.ID
hostIDs[i] = HostAttribute{AnsibleHost(*host.AnsibleHost), HostId(host.ID)}
}

return formatConnectionResponse(nil, nil, nil, orgID, hostIDs, "none", "rhc_not_configured")
Expand Down
7 changes: 6 additions & 1 deletion internal/api/controllers/private/runsCreateActions.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ func parseRunHosts(input *RunInputHosts) []generic.RunHostsInput {
result := make([]generic.RunHostsInput, len(*input))

for i, host := range *input {
var ansibleHost *string
if host.AnsibleHost != nil {
ansibleHostString := string(*host.AnsibleHost)
ansibleHost = &ansibleHostString
}
result[i] = generic.RunHostsInput{
AnsibleHost: host.AnsibleHost,
AnsibleHost: ansibleHost,
}

if host.InventoryId != nil {
Expand Down
68 changes: 35 additions & 33 deletions internal/api/controllers/private/spec.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions internal/api/controllers/private/types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions internal/api/tests/private/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions internal/api/tests/private/highLevelConnectionStatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ var _ = Describe("high level connection status", func() {
satelliteHost := []HostId{"c484f980-ab8d-401b-90e7-aa1d4ccf8c0e"}
directConnectHost := []HostId{"fe30b997-c15a-44a9-89df-c236c3b5c540"}

satelliteHostWithAnsibleHost := []HostAttribute{{HostId: "c484f980-ab8d-401b-90e7-aa1d4ccf8c0e", AnsibleHost: ""}}
directConnectHostWithAnsibleHost := []HostAttribute{{HostId: "fe30b997-c15a-44a9-89df-c236c3b5c540", AnsibleHost: "test-ansible-host"}}

payload := ApiInternalHighlevelConnectionStatusJSONRequestBody{
Hosts: []string{"c484f980-ab8d-401b-90e7-aa1d4ccf8c0e"},
OrgId: "12345",
Expand All @@ -51,6 +54,7 @@ var _ = Describe("high level connection status", func() {
Expect((*result)[0].SatOrgId).To(Equal(satOrgID))
Expect((*result)[0].Status).To(Equal("connected"))
Expect((*result)[0].Systems).To(Equal(satelliteHost))
Expect((*result)[0].SystemsInfo).To(Equal(satelliteHostWithAnsibleHost))

Expect((*result)[1].Recipient).To(Equal(public.RunRecipient("32af5948-301f-449a-a25b-ff34c83264a2")))
Expect((*result)[1].RecipientType).To(Equal(RecipientType_directConnect))
Expand All @@ -59,5 +63,6 @@ var _ = Describe("high level connection status", func() {
Expect((*result)[1].SatOrgId).To(BeEmpty())
Expect((*result)[1].Status).To(Equal("connected"))
Expect((*result)[1].Systems).To(Equal(directConnectHost))
Expect((*result)[1].SystemsInfo).To(Equal(directConnectHostWithAnsibleHost))
})
})
2 changes: 1 addition & 1 deletion internal/api/tests/private/runsCreateV1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

var (
ansibleHost = "localhost"
ansibleHost = AnsibleHost("localhost")
)

func dispatch(payload *ApiInternalRunsCreateJSONRequestBody) (*RunsCreated, *ApiInternalRunsCreateResponse) {
Expand Down
Loading
Loading