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 3 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
17 changes: 13 additions & 4 deletions internal/api/controllers/private/highlevelConnectionStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,15 @@ 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, ansibleHost *string, orgID OrgId, hosts []string, recipientType string, status string) RecipientWithConnectionInfo {
formatedHosts := make([]HostId, len(hosts))
var formatedSatID SatelliteId
var formatedSatOrgID SatelliteOrgId
var formatedRHCClientID public.RunRecipient

var formattedAnsibleHost AnsibleHost
formattedHostWithAnsibleHost := make([]HostIdWithAnsibleHost, len(hosts))

if satID != nil {
formatedSatID = SatelliteId(*satID)
}
Expand All @@ -128,8 +131,13 @@ func formatConnectionResponse(satID *string, satOrgID *string, rhcClientID *stri
formatedRHCClientID = public.RunRecipient(*rhcClientID)
}

if ansibleHost != nil {
formattedAnsibleHost = AnsibleHost(*ansibleHost)
}

for i, host := range hosts {
formatedHosts[i] = HostId(host)
formattedHostWithAnsibleHost[i] = HostIdWithAnsibleHost{HostId: HostId(host), AnsibleHost: formattedAnsibleHost}
}

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

return connectionInfo
Expand All @@ -162,7 +171,7 @@ 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))
responses = append(responses, formatConnectionResponse(nil, nil, host.RHCClientID, host.AnsibleHost, orgId, []string{host.ID}, string(RecipientType_directConnect), connectionStatus))
}

return responses, nil
Expand Down Expand Up @@ -238,7 +247,7 @@ 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, nil, orgId, satellite.Hosts, string(RecipientType_satellite), connectionStatus))
}
}

Expand All @@ -252,7 +261,7 @@ func getRHCStatus(hostDetails []inventory.HostDetails, orgID OrgId) RecipientWit
hostIDs[i] = host.ID
}

return formatConnectionResponse(nil, nil, nil, orgID, hostIDs, "none", "rhc_not_configured")
return formatConnectionResponse(nil, nil, nil, nil, orgID, hostIDs, "none", "rhc_not_configured")
}

func concatResponses(satellite []RecipientWithConnectionInfo, directConnect []RecipientWithConnectionInfo, noRHC []RecipientWithConnectionInfo) []RecipientWithConnectionInfo {
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 := []HostIdWithAnsibleHost{{HostId: "c484f980-ab8d-401b-90e7-aa1d4ccf8c0e", AnsibleHost: ""}}
directConnectHostWithAnsibleHost := []HostIdWithAnsibleHost{{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
32 changes: 26 additions & 6 deletions schema/private.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,7 @@ components:
type: object
properties:
ansible_host:
type: string
description: |
Host name as known to Ansible inventory.
Used to identify the host in status reports.
example: localhost
minLength: 1
$ref: '#/components/schemas/AnsibleHost'
inventory_id:
type: string
format: uuid
Expand Down Expand Up @@ -336,6 +331,10 @@ components:
description: Indicates the current run status of the recipient
type: string
enum: [connected, disconnected, rhc_not_configured]
systems_info:
type: array
items:
$ref: '#/components/schemas/HostIdWithAnsibleHost'
required:
- recipient
- org_id
Expand All @@ -344,6 +343,7 @@ components:
- sat_org_id
- systems
- status
- systems_info


HighLevelRecipientStatus:
Expand All @@ -356,6 +356,18 @@ components:
type: string
minLength: 1

HostIdWithAnsibleHost:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be renamed to something like HostDetails or something a bit more generic?

Its possible that we will need to add more info about the hosts later on and then this name makes less sense.

Naming is hard :(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to HostAtribute. Unfortunately, HostDetails is used quite extensively thoughout the codebase to mean a different thing, so didn't want to add to the confusion here.

description: An object containing the host id and the ansible host name
type: object
properties:
host_id:
$ref: '#/components/schemas/HostId'
ansible_host:
$ref: '#/components/schemas/AnsibleHost'
required:
- host_id
- ansible_host

SatelliteId:
description: Identifier of the Satellite instance in the uuid v4/v5 format
type: string
Expand Down Expand Up @@ -385,6 +397,14 @@ components:
example: jharting
minLength: 1

AnsibleHost:
type: string
description: |
Host name as known to Ansible inventory.
Used to identify the host in status reports.
example: localhost
minLength: 1

Version:
description: Version of the API
type: string
Expand Down
Loading