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 2 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
14 changes: 10 additions & 4 deletions internal/api/controllers/private/highlevelConnectionStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ 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 formatedAnsibleHost AnsibleHost

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

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

for i, host := range hosts {
formatedHosts[i] = HostId(host)
}
Expand All @@ -140,6 +145,7 @@ func formatConnectionResponse(satID *string, satOrgID *string, rhcClientID *stri
SatOrgId: formatedSatOrgID,
Status: status,
Systems: formatedHosts,
AnsibleHost: formatedAnsibleHost,
}

return connectionInfo
Expand All @@ -162,7 +168,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 +244,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 +258,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
67 changes: 34 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.

9 changes: 8 additions & 1 deletion internal/api/controllers/private/types.gen.go

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

9 changes: 8 additions & 1 deletion internal/api/tests/private/client.gen.go

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

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

payload := ApiInternalHighlevelConnectionStatusJSONRequestBody{
Hosts: []string{"c484f980-ab8d-401b-90e7-aa1d4ccf8c0e"},
Expand All @@ -51,6 +52,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].AnsibleHost).To(BeEmpty())

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 +61,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].AnsibleHost).To(Equal(ansibleHost))
})
})
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
18 changes: 12 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,8 @@ components:
description: Indicates the current run status of the recipient
type: string
enum: [connected, disconnected, rhc_not_configured]
ansible_host:
$ref: '#/components/schemas/AnsibleHost'
required:
- recipient
- org_id
Expand All @@ -344,6 +341,7 @@ components:
- sat_org_id
- systems
- status
- ansible_host


HighLevelRecipientStatus:
Expand Down Expand Up @@ -385,6 +383,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