unioslo / mreg-cli

Command Line Interface for Mreg
GNU General Public License v3.0
2 stars 7 forks source link

mreg-cli started with --record quits when doing changes #281

Open ingarv opened 4 months ago

ingarv commented 4 months ago

Hi, when mreg-cli is running with the --record-option any change, for example to a policy or host result in an error.

Printing information about hosts or roles/atoms works without any issue (and is logged in json-format as expected in the file specified at startup).

dnf info mreg-cli

  Installed Packages
  Name         : mreg-cli
  Version      : 0.9.22
  Release      : 4.20240129.e6eb660.el8
  Architecture : noarch
  Size         : 610 k
  Source       : mreg-cli-0.9.22-4.20240129.e6eb660.el8.src.rpm
  Repository   : @System
  From repo    : uio-free

cat /etc/redhat-release 

  Red Hat Enterprise Linux release 8.10 (Ootpa)

/usr/bin/mreg-cli --record mreg.json

[>'mreg.json'] mreg> policy atom_create mail_test123 "Test opprettelse"  

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/mreg_cli/outputmanager.py", line 275, in recording_request
    obj = result.json()
  File "/usr/lib/python3.6/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib64/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/mreg-cli", line 11, in <module>
    load_entry_point('mreg-cli==0.0.0', 'console_scripts', 'mreg-cli')()
  File "/usr/lib/python3.6/site-packages/mreg_cli/main.py", line 200, in main
    cli.process_command_line(line)
  File "/usr/lib/python3.6/site-packages/mreg_cli/cli.py", line 257, in process_command_line
    cli.parse(cmd)
  File "/usr/lib/python3.6/site-packages/mreg_cli/cli.py", line 157, in parse
    args.func(args)
  File "/usr/lib/python3.6/site-packages/mreg_cli/policy.py", line 84, in atom_create
    post(path, **data)
  File "/usr/lib/python3.6/site-packages/mreg_cli/util.py", line 414, in post
    return _request_wrapper("post", path, params=params, **kwargs)
  File "/usr/lib/python3.6/site-packages/mreg_cli/util.py", line 347, in _request_wrapper
    OutputManager().recording_request(operation_type, url, params, data, result)
  File "/usr/lib/python3.6/site-packages/mreg_cli/outputmanager.py", line 279, in recording_request
    except requests.JSONDecodeError:
AttributeError: module 'requests' has no attribute 'JSONDecodeError'
terjekv commented 4 months ago

This is fixed in the current codebase.

(env) ➜  mreg-cli make-testsuite-work-again-202405 ✓$ pip3 install --quiet --upgrade --target=/tmp/mreg-cli/ . && PYTHONPATH=/tmp/mreg-cli/:$PYTHONPATH /tmp/mreg-cli/bin/mreg-cli --url https://mreg-dev -u super -v DEBUG --record /tmp/flappa.json --logfile /tmp/flappa.log

[notice] A new release of pip is available: 23.3.1 -> 24.1.1
[notice] To update, run: pip install --upgrade pip
Type -h for help.
[>'/tmp/flappa.json'] super@mreg-dev> policy atom_create mail_test12345 "Test opprettelse"
[>'/tmp/flappa.json'] super@mreg-dev> policy info mail_test12345
Name:         mail_test12345
Created:      Thu Jul  4 00:00:00 2024
Updated:      Thu Jul  4 11:43:49 2024
Description:  Test opprettelse
Roles where this atom is a member:
[>'/tmp/flappa.json'] super@mreg-dev>