Skip to content

Conversation

@RSabounds
Copy link
Contributor

Update hard-coded and separate Bmc communication code for bmc_credentials to use Bmc objects, handle different Dell and HP bmc types.

@RSabounds RSabounds marked this pull request as draft January 8, 2026 14:45
@RSabounds RSabounds force-pushed the PUC-1410 branch 2 times, most recently from a26a8b9 to 93b32ca Compare January 9, 2026 02:32
@RSabounds
Copy link
Contributor Author

pytest and precommit successfully completed.

Typos Spell Checker / spellcheck not related to this PR. issue exists in MAIN branch.

@RSabounds RSabounds marked this pull request as ready for review January 9, 2026 02:46

def get_base_path(self):
"""Get Base Path."""
_result = "/redfish/v1/"
Copy link
Contributor

Choose a reason for hiding this comment

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

This has changed from "/redfish/v1" - it now has a trailing slash. Not sure if that matters to the BMC.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

usually doesn't matter, some systems like HP have more issue if there is or isn't a trailing slash. This was just how it was tested as functional. Can change if preference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

applying and testing with HP in case of issue.

Comment on lines 136 to 139
if token:
a = self.redfish_request(path=account_url, token=token)
else:
a = self.redfish_request(path=account_url)
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like redfish_request would treat the parameter token=None the same as if the parameter is missing, and the type signature agrees with this:

Suggested change
if token:
a = self.redfish_request(path=account_url, token=token)
else:
a = self.redfish_request(path=account_url)
a = self.redfish_request(path=account_url, token=token)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wrote this way originally. I added the if token and else because the precommit was flagging it for cases of the token being None.
I can remove this and rerun the test again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

logger.debug("found account: %s", a)
matched_account = a
break
if not matched_account:
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it should be after (outside) the loop. Copy and paste error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, recopied code after rebase faulted. looks like the formatting got fluxed. fixed.

else:
self.redfish_request(method="PATCH", path=account_uri, payload=_payload)

def get_session(self, password: str) -> tuple[str | None, str | None]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def get_session(self, password: str) -> tuple[str | None, str | None]:
def get_session(self, password: str) -> tuple[str, str] | tuple[None, None]:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

payload: dict | None = None,
verify: bool = False,
timeout: int = 30,
) -> tuple[str | None, str | None]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
) -> tuple[str | None, str | None]:
) -> tuple[str, str] | tuple[None, None]:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 170 to 173
if token:
self.redfish_request(method="DELETE", path=session, token=token)
else:
self.redfish_request(method="DELETE", path=session)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above, can refactor to eliminate the condition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Comment on lines 95 to 128
def get_user_accounts(self, token: str | None = None) -> list[dict]:
"""A vendor agnostic approach to crawling the API for BMC accounts."""
try:
# get account service
r = (
self.redfish_request(path=self.base_path, token=token)
if token
else self.redfish_request(path=self.base_path)
)
account_service_uri = r["AccountService"]["@odata.id"]
logger.debug("account_service_url: %s", account_service_uri)

# get account collection uri
r = (
self.redfish_request(path=account_service_uri, token=token)
if token
else self.redfish_request(path=account_service_uri)
)
accounts_uri = r["Accounts"]["@odata.id"]
logger.debug("accounts_url: %s", accounts_uri)

# get accounts
r = (
self.redfish_request(path=accounts_uri, token=token)
if token
else self.redfish_request(path=accounts_uri)
)
accounts = r["Members"]
logger.debug("accounts: %s", accounts)

return accounts
except AccountServiceException:
logger.exception("Can't fetch accounts from Redfish account service.")
raise
Copy link
Contributor

Choose a reason for hiding this comment

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

This is quite verbose, it feels like this would behave the same:

Suggested change
def get_user_accounts(self, token: str | None = None) -> list[dict]:
"""A vendor agnostic approach to crawling the API for BMC accounts."""
try:
# get account service
r = (
self.redfish_request(path=self.base_path, token=token)
if token
else self.redfish_request(path=self.base_path)
)
account_service_uri = r["AccountService"]["@odata.id"]
logger.debug("account_service_url: %s", account_service_uri)
# get account collection uri
r = (
self.redfish_request(path=account_service_uri, token=token)
if token
else self.redfish_request(path=account_service_uri)
)
accounts_uri = r["Accounts"]["@odata.id"]
logger.debug("accounts_url: %s", accounts_uri)
# get accounts
r = (
self.redfish_request(path=accounts_uri, token=token)
if token
else self.redfish_request(path=accounts_uri)
)
accounts = r["Members"]
logger.debug("accounts: %s", accounts)
return accounts
except AccountServiceException:
logger.exception("Can't fetch accounts from Redfish account service.")
raise
def get_user_accounts(self, token: str | None = None) -> list[dict]:
"""Get the list of User Accounts on this BMC."""
path = self.base_path
path = self.redfish_request(path, token=token)["AccountService"]["@odata.id"]
path = self.redfish_request(path, token=token)["Accounts"]["@odata.id"]
return self.redfish_request(path, token=token)["Members"]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

original code, just shifted.
Agreed. did not like the longer code, so appreciate the shift. added.

@stevekeay
Copy link
Contributor

It was hard to see what had actually changed in this PR because the changes are hidden by a massive refactoring.

I would suggest making the commit history look like:

  1. Refactor: move session and user handling from bmc_credentials module to bmc module
  2. Have bmc module support sessions on <???> that are set via Location header
  3. anything else that changed the actual behaviour

@stevekeay
Copy link
Contributor

rebase on main should fix CI

@stevekeay stevekeay added this pull request to the merge queue Jan 9, 2026
Merged via the queue into main with commit acbf5ca Jan 9, 2026
54 checks passed
@stevekeay stevekeay deleted the PUC-1410 branch January 9, 2026 16:39
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