Page MenuHomePhabricator

Redfish _get_dummy_response() should return empty json
Open, LowPublic

Description

Running the rename cookbook in dry-run failed with:

DRY-RUN: ✔️ Downtimed host on Icinga/Alertmanager
DRY-RUN: Skipping Netbox name change from kubernetes2023 to wikikube-worker2001 in DRY-RUN.
DRY-RUN: ✔️ Netbox updated
DRY-RUN: Would have called patch on https://10.193.1.59/redfish/v1/Managers/iDRAC.Embedded.1/iDRAC.Embedded.1/EthernetInterfaces/NIC.1
DRY-RUN: Exception raised while executing cookbook sre.hosts.rename:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/spicerack/_menu.py", line 250, in _run
    raw_ret = runner.run()
  File "/home/ayounsi/cookbooks_testing/cookbooks/cookbooks/sre/hosts/rename.py", line 103, in run
    response = self.redfish.request('patch',
  File "/usr/lib/python3/dist-packages/requests/models.py", line 900, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
DRY-RUN: Exception raised while executing cookbook sre.hosts.rename rollback() (exit_code=99):
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/spicerack/netbox.py", line 118, in get_server
    server = self._get_device(hostname)
  File "/usr/lib/python3/dist-packages/spicerack/netbox.py", line 80, in _get_device
    raise NetboxHostNotFoundError(name)
spicerack.netbox.NetboxHostNotFoundError: wikikube-worker2001

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/spicerack/_menu.py", line 285, in _run
    runner.rollback()
  File "/home/ayounsi/cookbooks_testing/cookbooks/cookbooks/sre/hosts/rename.py", line 159, in rollback
    self.netbox_server = self.spicerack.netbox_server(self.new_name, read_write=True)
  File "/usr/lib/python3/dist-packages/spicerack/__init__.py", line 614, in netbox_server
    return self.netbox(read_write=read_write).get_server(hostname)
  File "/usr/lib/python3/dist-packages/spicerack/netbox.py", line 120, in get_server
    server = self._get_virtual_machine(hostname)
  File "/usr/lib/python3/dist-packages/spicerack/netbox.py", line 102, in _get_virtual_machine
    raise NetboxHostNotFoundError
spicerack.netbox.NetboxHostNotFoundError
DRY-RUN: Releasing lock for key sre.hosts.rename with ID b287e923-cfde-4e63-baf7-ab63e17a6f5f
DRY-RUN: Issuing read for key /spicerack/locks/cookbooks/sre.hosts.rename with args {'timeout': 60}
DRY-RUN: Lock for key /spicerack/locks/cookbooks/sre.hosts.rename and ID b287e923-cfde-4e63-baf7-ab63e17a6f5f not found. Unable to release it. Was expired?
DRY-RUN: __COOKBOOK_STATS__:name=sre.hosts.rename,exit_code=93,duration=3.292
DRY-RUN: END (FAIL) - Cookbook sre.hosts.rename (exit_code=93) from kubernetes2023 to wikikube-worker2001

It might be difficult to have a cookbook that fully supports DRY-RUN in a relevant way.

But a minor bug that could be fixed I think is json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
https://github.com/wikimedia/operations-software-spicerack/blob/master/spicerack/redfish.py#L561
probably needs to return some empty json ? so it doesn't fails with the `.json() ?

Event Timeline

ayounsi created this task.
Restricted Application added a subscriber: Aklapper. · View Herald Transcript

I guess we could use something like:

>>> a = requests.Response()
>>> a.status_code = 200
>>> a.raw = BytesIO(b'{}')
>>> a.raw.decode_content = True
>>> a.json()
{}

Not sure it could mess up with other assumptions but we could try.