opencomputeproject / HWMgmt-DeviceMgr-DeviceManager

Device Manager collects device data and notifications from each device, and make the data available on a predetermined output bus for consumers.
Apache License 2.0
23 stars 12 forks source link

Deleting account returns error, after receiving status code 204 #18

Closed ehaligow closed 1 year ago

ehaligow commented 2 years ago

Deleting account returns error, after receiving status code 204 from BMC Simulator.

intel@ubuntu:functional_test$ ./dm deleteaccount 192.168.40.247:8888:admin:admin_1 Failed to delete device account admin_1, status code 204

According to code, receiving status codes other than 200 returns error.

JasonscHuang commented 2 years ago

It needs to change the way to match the ID by the redfish API first and then delete the account. This test case needs to change in this way to do it.

JasonscHuang commented 2 years ago

The HTTP status code 204 means "No Content". Did you make sure you created an account before you delete it? Otherwise, you will see the 204 status code returned.

ehaligow commented 2 years ago

In this case, after deleting an account, BMC simulator returns 204 No Content (according to Redfish Specification the status coded 204 should be accepted for deletion). DeviceMgr accepts only code 200 for the deletion (as in the following code from accountService.go):

func (s *Server) removeDeviceAccount(deviceIPAddress string, authStr string, removeUser string) (statusNum int, err error) {
    var statusCode int
    userAuthData := s.getUserAuthData(deviceIPAddress, authStr)
    if (userAuthData == userAuth{}) {
        logrus.Errorf(ErrUserAuthNotFound.String())
        return http.StatusBadRequest, errors.New(ErrUserAuthNotFound.String())
    }
    id, status, _, _ := s.getUserLoginID(deviceIPAddress, authStr, removeUser)
    if status == true {
        _, statusCode, _ = deleteHTTPDataByRfAPI(deviceIPAddress, RfSessionServiceSessions, userAuthData, id)
        if statusCode != http.StatusOK {
            logrus.Errorf(ErrDeleteLoginFailed.String(id, strconv.Itoa(statusCode)))
            return statusCode, errors.New(ErrDeleteLoginFailed.String(id, strconv.Itoa(statusCode)))
        }
    }
    id, status = s.getAccountDataByLabel(deviceIPAddress, authStr, removeUser, "Id")
    if status == true {
        _, statusCode, _ = deleteHTTPDataByRfAPI(deviceIPAddress, RfAccountsServiceAccounts, userAuthData, id)
        if statusCode != http.StatusOK {
            logrus.Errorf(ErrDeleteUserAccount.String(removeUser, strconv.Itoa(statusCode)))
            return http.StatusNotFound, errors.New(ErrDeleteUserAccount.String(removeUser, strconv.Itoa(statusCode)))
        }
    }
...
JasonscHuang commented 2 years ago

@ehaligow Yes, you could add those conditions of the HTTP status code (202 and 204) to this function.