Skip to content
Draft
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
22 changes: 22 additions & 0 deletions internal/rps/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ type StatusMessage struct {
Network string `json:"Network,omitempty"`
CIRAConnection string `json:"CIRAConnection,omitempty"`
TLSConfiguration string `json:"TLSConfiguration,omitempty"`
// Components carries the additive, structured per-component provisioning result
// introduced by RPS (rps#2665). Older RPS releases omit it; in that case the flat
// fields above remain the source of truth.
Components *ComponentResults `json:"Components,omitempty"`
}

// ComponentResult is the per-component outcome of an activation step.
type ComponentResult struct {
Result string `json:"Result"`
Mode string `json:"Mode,omitempty"`
Details string `json:"Details,omitempty"`
ErrorCode int `json:"ErrorCode"`
}

// ComponentResults groups the structured per-component activation results.
type ComponentResults struct {
Activation *ComponentResult `json:"Activation,omitempty"`
WiredNetwork *ComponentResult `json:"WiredNetwork,omitempty"`
WirelessNetwork *ComponentResult `json:"WirelessNetwork,omitempty"`
TLS *ComponentResult `json:"TLS,omitempty"`
CIRAProxy *ComponentResult `json:"CIRAProxy,omitempty"`
CIRAConnection *ComponentResult `json:"CIRAConnection,omitempty"`
}

// MessagePayload struct is used for the initial request to RPS to activate or manage a device
Expand Down
45 changes: 41 additions & 4 deletions internal/rps/rps.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,7 @@ func (amt *AMTActivationServer) ProcessMessage(message []byte) []byte {
log.Error(err)
log.Info(activation.Message)
} else {
log.Info("Status: " + statusMessage.Status)
log.Info("Network: " + statusMessage.Network)
log.Info("CIRA: " + statusMessage.CIRAConnection)
log.Info("TLS: " + statusMessage.TLSConfiguration)
logStatusMessage(statusMessage)
}

return nil
Expand All @@ -263,6 +260,46 @@ func (amt *AMTActivationServer) ProcessMessage(message []byte) []byte {
return msgPayload
}

// logStatusMessage reports the activation result. When RPS provides the structured
// per-component breakdown (rps#2665) it is logged component-by-component; otherwise the
// legacy flat status fields are logged for compatibility with older RPS releases.
func logStatusMessage(statusMessage StatusMessage) {
if statusMessage.Components != nil {
c := statusMessage.Components
logComponentResult("Activation", c.Activation)
logComponentResult("Wired Network", c.WiredNetwork)
logComponentResult("Wireless Network", c.WirelessNetwork)
Comment on lines +267 to +271
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks to be valid suggestion. Please check

logComponentResult("TLS", c.TLS)
logComponentResult("CIRA Proxy", c.CIRAProxy)
logComponentResult("CIRA Connection", c.CIRAConnection)

return
}

log.Info("Status: " + statusMessage.Status)
log.Info("Network: " + statusMessage.Network)
log.Info("CIRA: " + statusMessage.CIRAConnection)
log.Info("TLS: " + statusMessage.TLSConfiguration)
}

// logComponentResult logs a single component result, skipping components RPS did not report.
func logComponentResult(label string, result *ComponentResult) {
if result == nil {
return
}

line := label + ": " + result.Result
if result.Details != "" {
line += " (" + result.Details + ")"
}
Comment on lines +291 to +294

if result.Result == "Failure" {
log.Error(line)
} else {
log.Info(line)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I tried your PR and don't see new info lines getting logged.

I see the following output, which is same as 2.x.x branch. Am I missing something here ?

sudo ./rpc-2665 activate -u wss://10.190.213.16/activate -n  --profile acmProfileCloud --tls-tunnel --password <password>
time="2026-06-03T14:53:26+05:30" level=info msg="connecting to wss://10.190.213.16/activate"
time="2026-06-03T14:53:26+05:30" level=info msg="connected to wss://10.190.213.16/activate"
time="2026-06-03T14:54:43+05:30" level=info msg="Status: Admin control mode."
time="2026-06-03T14:54:43+05:30" level=info msg="Network: Wired Network Configured"
time="2026-06-03T14:54:43+05:30" level=info msg="CIRA: Configured"
time="2026-06-03T14:54:43+05:30" level=info msg="TLS: unconfigured"

}
}

func (amt *AMTActivationServer) GenerateHeartbeatResponse(activation Message) ([]byte, error) {
activation.Method = "heartbeat_response"
activation.Status = "success"
Expand Down
37 changes: 37 additions & 0 deletions internal/rps/rps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,43 @@ func TestProcessMessageSuccess(t *testing.T) {
assert.Nil(t, decodedMessage)
}

func TestProcessMessageStructuredSuccess(t *testing.T) {
// RPS rps#2665 structured per-component result rides alongside the legacy flat fields.
activation := `{
"method": "success",
"message": "{\"Status\":\"Admin control mode.\",\"Components\":{\"Activation\":{\"Result\":\"Success\",\"Mode\":\"Admin control mode.\",\"ErrorCode\":0},\"WirelessNetwork\":{\"Result\":\"Failure\",\"Details\":\"Failed to add 1\",\"ErrorCode\":1}}}"
}`
server := NewAMTActivationServer(testFlags)
server.Connect(true)
decodedMessage := server.ProcessMessage([]byte(activation))
assert.Nil(t, decodedMessage)
}

func TestLogStatusMessageStructured(t *testing.T) {
// Structured Components present: per-component lines are logged, no panic.
statusMessage := StatusMessage{
Status: "Admin control mode.",
Comment on lines +242 to +245
Components: &ComponentResults{
Activation: &ComponentResult{Result: "Success", Mode: "Admin control mode.", ErrorCode: 0},
WirelessNetwork: &ComponentResult{Result: "Failure", Details: "Failed to add 1", ErrorCode: 1},
},
}

assert.NotPanics(t, func() { logStatusMessage(statusMessage) })
}

func TestLogStatusMessageLegacyFallback(t *testing.T) {
// No Components: falls back to legacy flat-field logging.
statusMessage := StatusMessage{
Status: "Admin control mode.",
Network: "configured",
CIRAConnection: "configured",
TLSConfiguration: "configured",
}

assert.NotPanics(t, func() { logStatusMessage(statusMessage) })
}

func TestProcessMessageUnformattedSuccess(t *testing.T) {
activation := `{
"method": "success",
Expand Down
Loading