Skip to content

Commit

Permalink
discovered bug with objects/hardware.save where the obj_get_changes m…
Browse files Browse the repository at this point in the history
…ethod does not detect changes to the object, added code to force properties to update to current state during call
  • Loading branch information
Soufiane Jounaid authored and System Administrator committed Dec 21, 2023
1 parent 79dd6c6 commit 704f5ca
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
7 changes: 2 additions & 5 deletions doni/driver/worker/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,13 @@ def process(
payload["created_token_secrets"] = 0
payload["issued new token"] = "null"

if 'k8s_bootstrap_token' not in hardware.properties or hardware.properties.get("k8s_bootstrap_token") == "r6nga3.ayozgi8fhjttieq1":
if 'k8s_bootstrap_token' not in hardware.properties or hardware.properties.get("k8s_bootstrap_token") == "":
LOG.info(f"Missing Token for device '{hardware.name}'. Issuing token.")
new_token = generate_k8s_bootstrap_token()

hardware.properties.update({'k8s_bootstrap_token': new_token})
LOG.info(f"New hardware properties before save'{hardware.properties}'.")
hardware.properties["k8s_bootstrap_token"] = new_token
hardware.save()

LOG.info(f"New hardware properties after save'{hardware.properties}'.")

payload["issued new token"] = new_token

bootstrap_token = hardware.properties.get("k8s_bootstrap_token")
Expand Down
4 changes: 2 additions & 2 deletions doni/objects/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def save(self, context: "RequestContext" = None):
HardwareDuplicateName: if a hardware with the same name exists.
HardwareNotFound: if the hardware does not exist.
"""
updates = self.obj_get_changes()
LOG.info(f"(hardware.save) CHANGES TO OBJECT '{updates}'")
updates = self.obj_get_changes() # BUG: Does not detect changes to hardware properties
updates["properties"] = self.properties
db_hardware = self.dbapi.update_hardware(self.uuid, updates)
self._from_db_object(self._context, self, db_hardware)

Expand Down

0 comments on commit 704f5ca

Please sign in to comment.