Skip to content

feat: implement redfish kvm user consent actions#1027

Open
amarnath-ac wants to merge 1 commit into
redfishfrom
kvm_user_consent
Open

feat: implement redfish kvm user consent actions#1027
amarnath-ac wants to merge 1 commit into
redfishfrom
kvm_user_consent

Conversation

@amarnath-ac
Copy link
Copy Markdown
Contributor

@amarnath-ac amarnath-ac commented May 26, 2026

  1. Implement KVM consent request/submit/cancel end-to-end.
  2. Implement user consent status in graphical console.

Test:

  1. Request consent:
curl -u "standalone:G@ppm0ym" \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{}' \
  http://localhost:8181/redfish/v1/Systems/32bcccf9-9a56-0db3-48d6-48210b50d7ea/Actions/Oem/IntelComputerSystem.RequestKVMConsent \
  | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   236  100   234  100     2   1941     16 --:--:-- --:--:-- --:--:--  1950
{
  "error": {
    "@Message.ExtendedInfo": [
      {
        "Message": "The request completed successfully.",
        "MessageId": "Base.1.22.0.Success",
        "Resolution": "None",
        "Severity": "OK"
      }
    ],
    "code": "Base.1.22.0.Success",
    "message": "The request completed successfully."
  }
}
  1. Submit consent:
curl -u "standalone:G@ppm0ym" \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{"ConsentCode":"871306"}' \
  http://localhost:8181/redfish/v1/Systems/32bcccf9-9a56-0db3-48d6-48210b50d7ea/Actions/Oem/IntelComputerSystem.SubmitKVMConsentCode \
  | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   258  100   234  100    24   1595    163 --:--:-- --:--:-- --:--:--  1767
{
  "error": {
    "@Message.ExtendedInfo": [
      {
        "Message": "The request completed successfully.",
        "MessageId": "Base.1.22.0.Success",
        "Resolution": "None",
        "Severity": "OK"
      }
    ],
    "code": "Base.1.22.0.Success",
    "message": "The request completed successfully."
  }
}
  1. Graphical console:
curl -u "standalone:G@ppm0ym" http://localhost:8181/redfish/v1/Systems/32bcccf9-9a56-0db3-48d6-48210b50d7ea | jq .
  
"GraphicalConsole": {
    "ConnectTypesSupported": [
      "KVMIP"
    ],
    "Oem": {
      "Intel": {
        "AMT": {
          "ControlMode": "CCM",
          "KVMStatus": "Enabled",
          "UserConsentStatus": "Granted"
        }
      }
    },
    "Port": 16994,
    "ServiceEnabled": true
  },
  1. Consent cancel->request->cancel
curl -u "standalone:G@ppm0ym" \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{}' \
  http://localhost:8181/redfish/v1/Systems/32bcccf9-9a56-0db3-48d6-48210b50d7ea/Actions/Oem/IntelComputerSystem.CancelKVMConsent \
  | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   410  100   408  100     2   2025      9 --:--:-- --:--:-- --:--:--  2039
{
  "error": {
    "@Message.ExtendedInfo": [
      {
        "Message": "CancelKVMConsent failed with ReturnValue=2: cannot cancel consent in the current opt-in state (no pending request)",
        "MessageId": "Base.1.22.0.GeneralError",
        "Resolution": "None",
        "Severity": "Critical"
      }
    ],
    "code": "Base.1.22.0.GeneralError",
    "message": "CancelKVMConsent failed with ReturnValue=2: cannot cancel consent in the current opt-in state (no pending request)"
  }
}

curl -u "standalone:G@ppm0ym" \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{}' \
  http://localhost:8181/redfish/v1/Systems/32bcccf9-9a56-0db3-48d6-48210b50d7ea/Actions/Oem/IntelComputerSystem.RequestKVMConsent \
  | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   236  100   234  100     2   2003     17 --:--:-- --:--:-- --:--:--  2034
{
  "error": {
    "@Message.ExtendedInfo": [
      {
        "Message": "The request completed successfully.",
        "MessageId": "Base.1.22.0.Success",
        "Resolution": "None",
        "Severity": "OK"
      }
    ],
    "code": "Base.1.22.0.Success",
    "message": "The request completed successfully."
  }
}

curl -u "standalone:G@ppm0ym"   -H "Content-Type: application/json"   -X POST   -d '{}'   http://localhost:8181/redfish/v1/Systems/32bcccf9-9a56-0db3-48d6-48210b50d7ea/Actions/Oem/IntelComputerSystem.CancelKVMConsent   | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   236  100   234  100     2   2068     17 --:--:-- --:--:-- --:--:--  2107
{
  "error": {
    "@Message.ExtendedInfo": [
      {
        "Message": "The request completed successfully.",
        "MessageId": "Base.1.22.0.Success",
        "Resolution": "None",
        "Severity": "OK"
      }
    ],
    "code": "Base.1.22.0.Success",
    "message": "The request completed successfully."
  }
}

@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2026

Codecov Report

❌ Patch coverage is 94.78261% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 42.79%. Comparing base (4300f4c) to head (d9161eb).

Files with missing lines Patch % Lines
redfish/internal/mocks/mock_repo.go 0.00% 12 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           redfish    #1027      +/-   ##
===========================================
+ Coverage    42.03%   42.79%   +0.76%     
===========================================
  Files          152      153       +1     
  Lines        14581    14793     +212     
===========================================
+ Hits          6129     6331     +202     
- Misses        7873     7883      +10     
  Partials       579      579              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@amarnath-ac amarnath-ac requested a review from sudhir-intc May 26, 2026 08:17
@amarnath-ac amarnath-ac marked this pull request as ready for review May 26, 2026 08:17
@amarnath-ac amarnath-ac requested a review from DevipriyaS17 May 26, 2026 08:18
@amarnath-ac amarnath-ac force-pushed the kvm_user_consent branch 2 times, most recently from 4b02653 to d9161eb Compare May 27, 2026 04:16
1. Implement KVM consent request/submit/cancel end-to-end.
2. Implement KVM and user consent status in graphical console.

Signed-off-by: C, Amarnath <amarnath.c@intel.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements Redfish KVM user consent actions end-to-end and exposes KVM user consent state in the graphical console model.

Changes:

  • Adds request, submit, and cancel KVM consent flows through handler, use case, repository interface, WSMAN repository, and mocks.
  • Adds typed consent failure errors and success response handling for the new Redfish actions.
  • Updates graphical console KVM status/user-consent status logic and expands unit/controller test coverage.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
redfish/internal/usecase/wsman_repo.go Adds KVM consent repository methods and graphical console consent-status mapping.
redfish/internal/usecase/wsman_repo_test.go Adds WSMAN repo and status-mapping tests for KVM consent behavior.
redfish/internal/usecase/interfaces.go Extends the computer system repository interface with KVM consent methods.
redfish/internal/usecase/consent_errors.go Adds typed consent operation failure errors.
redfish/internal/usecase/consent_errors_test.go Tests consent failure error message formatting.
redfish/internal/usecase/computer_system.go Adds use-case pass-through methods and exposes KVM consent actions.
redfish/internal/usecase/computer_system_test.go Updates use-case mock coverage and validates exposed action targets.
redfish/internal/usecase/computer_system_fuzz_test.go Updates fuzz mock repository to satisfy the expanded interface.
redfish/internal/mocks/mock_repo.go Updates mock repository with KVM consent methods.
redfish/internal/controller/http/v1/handler/systems_test.go Updates test repository behavior for KVM consent actions.
redfish/internal/controller/http/v1/handler/systems_actions.go Implements the three KVM consent HTTP handlers and shared success/error handling.
redfish/internal/controller/http/v1/handler/systems_actions_test.go Adds controller tests for success and error paths of KVM consent actions.
redfish/internal/controller/http/v1/handler/routes_test.go Updates route test repository to satisfy the expanded interface.

Comment on lines +1005 to +1006
case int(optin.NotStarted), int(optin.Requested), int(optin.Displayed):
return userConsentRequested
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.

@amarnath-ac : Please looks into this comment. Its a valid one. I did try out this on a system after the device has been activated and I see the below:

 "GraphicalConsole": {                                                                                                                                                                                                                                             
    "ConnectTypesSupported": [                                                                                                                                                                                                                                      
      "KVMIP"                                                    
    ],                                                           
    "Oem": {                                                     
      "Intel": {                                                 
        "AMT": {                                                 
          "ControlMode": "CCM",                                  
          "KVMStatus": "PendingConsent",                         
          "UserConsentStatus": "Requested"                       
        }                                                        
      }                                                          
    },                                                                                                                            
    "Port": 16995,                                               
    "ServiceEnabled": true                                       
  },                    

We might to have add "NotStarted" or "Required" here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes its valid, same i discussed with Devipriya, will do it in new PR which required spec and code changes.

@sudhir-intc
Copy link
Copy Markdown
Contributor

sudhir-intc commented May 29, 2026

Please check the error shown for the following scenario. In ACM the request for sending a user consent seems to be incorrect

Message": "RequestKVMConsent failed with ReturnValue=2: cannot request consent in the current opt-in state (request may already be pending)

There's not need of mentioning (request may already be pending)

curl -sk   "${CONSOLE_HOST}/redfish/v1/Systems/${SYSTEM_ID}"   -u "${CONSOLE_USER}:${CONSOLE_PASS}" | jq .GraphicalConsole
{
  "ConnectTypesSupported": [
    "KVMIP"
  ],
  "Oem": {
    "Intel": {
      "AMT": {
        "ControlMode": "ACM",
        "KVMStatus": "Enabled",
        "UserConsentStatus": "NotRequired"
      }
    }
  },
  "Port": 16995,
  "ServiceEnabled": true
}

curl -sk -u "${CONSOLE_USER}:${CONSOLE_PASS}"   -H "Content-Type: application/json"   -X POST   -d '{}'   "${CONSOLE_HOST}/redfish/v1/Systems/${SYSTEM_ID}/Actions/Oem/IntelComputerSystem.RequestKVMConsent"   | jq .  
{
  "error": {
    "@Message.ExtendedInfo": [
      {
        "Message": "RequestKVMConsent failed with ReturnValue=2: cannot request consent in the current opt-in state (request may already be pending)",
        "MessageId": "Base.1.22.0.GeneralError",
        "Resolution": "None",
        "Severity": "Critical"
      }
    ],
    "code": "Base.1.22.0.GeneralError",
    "message": "RequestKVMConsent failed with ReturnValue=2: cannot request consent in the current opt-in state (request may already be pending)"
  }
}

@sudhir-intc
Copy link
Copy Markdown
Contributor

When does the "ComputerSystem_OemIntelAMTUserConsentStatus" Timeout get triggered.
I tried the scenario of sending a user consent and waiting for the timeout to happen and the user-consent on device going off. When queried for the consent status, I see the below:

curl -sk   "${CONSOLE_HOST}/redfish/v1/Systems/${SYSTEM_ID}"   -u "${CONSOLE_USER}:${CONSOLE_PASS}" | jq .GraphicalConsole
{
  "ConnectTypesSupported": [
    "KVMIP"
  ],
  "Oem": {
    "Intel": {
      "AMT": {
        "ControlMode": "ACM",
        "KVMStatus": "PendingConsent",
        "UserConsentStatus": "Requested"
      }
    }
  },
  "Port": 16995,
  "ServiceEnabled": true
}

@sudhir-intc
Copy link
Copy Markdown
Contributor

Fuzz tests for the new API's are missing could you please add them


return nil
}

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.

You need to update the fuzz tests for these three API's instead of returning not foune

return nil
}

// RequestKVMConsent starts a mock KVM consent flow for an existing system.
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.

Please update the mock repo for the GraphicConsole related changes so that these API's can be demonstrated successfully when we run console with "REDFISH_USE_MOCK=true"

assertErrorResponse(t, w)
}

func TestPostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemRequestKVMConsent_InternalError(t *testing.T) {
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.

Can you add tests for failures in RequestKVMConsent in ACM Mode

}

// RequestKVMConsent starts a user consent request on the target system.
func (r *WsmanComputerSystemRepo) RequestKVMConsent(ctx context.Context, systemID string) error {
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.

Where are the checks for the Control Mode done ? Should we not have the checks here ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants