Charm upgrade appends ')' at the end of /usr/local/bin/auto_lint.py

Bug #1970753 reported by Przemyslaw Lal
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
charm-juju-lint
Fix Released
Undecided
Przemyslaw Lal

Bug Description

After upgrading charm from stable (rev 1) to candidate (rev 2), juju unit enters "error" state with the following error printed out in the debug-log:

unit-juju-lint-test-0: 13:07:18 ERROR unit.juju-lint-test/0.juju-log auto_lint.py failed with this output:
  File "/usr/local/bin/auto_lint.py", line 281
    )
    ^
SyntaxError: unmatched ')'

unit-juju-lint-test-0: 13:07:18 ERROR unit.juju-lint-test/0.juju-log Uncaught exception while in charm code:
Traceback (most recent call last):
  File "./src/charm.py", line 125, in <module>
    main(JujuLintCharm)
  File "/var/lib/juju/agents/unit-juju-lint-test-0/charm/venv/ops/main.py", line 431, in main
    _emit_charm_event(charm, dispatcher.event_name)
  File "/var/lib/juju/agents/unit-juju-lint-test-0/charm/venv/ops/main.py", line 142, in _emit_charm_event
    event_to_emit.emit(*args, **kwargs)
  File "/var/lib/juju/agents/unit-juju-lint-test-0/charm/venv/ops/framework.py", line 283, in emit
    framework._emit(event)
  File "/var/lib/juju/agents/unit-juju-lint-test-0/charm/venv/ops/framework.py", line 743, in _emit
    self._reemit(event_path)
  File "/var/lib/juju/agents/unit-juju-lint-test-0/charm/venv/ops/framework.py", line 790, in _reemit
    custom_handler(event)
  File "./src/charm.py", line 91, in on_config_changed
    self.helper.run_auto_lint()
  File "/var/lib/juju/agents/unit-juju-lint-test-0/charm/lib/lib_jujulint.py", line 183, in run_auto_lint
    raise error
  File "/var/lib/juju/agents/unit-juju-lint-test-0/charm/lib/lib_jujulint.py", line 173, in run_auto_lint
    subprocess.check_output([lint_script], stderr=subprocess.STDOUT).decode(
  File "/usr/lib/python3.8/subprocess.py", line 415, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.8/subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/usr/local/bin/auto_lint.py']' returned non-zero exit status 1.
unit-juju-lint-test-0: 13:07:18 ERROR juju.worker.uniter.operation hook "config-changed" (via hook dispatching script: dispatch) failed: exit status 1

It turns out that charm upgrade adds an extra line (281):

279 if __name__ == "__main__":
280 main()
281 )

at the end of the script during upgrade which breaks the auto_lint.py script.

Related branches

Revision history for this message
Przemyslaw Lal (przemeklal) wrote :

Noteworthy - clean deployment of revision 2 works fine - no extra characters at the end of file.

Changed in charm-juju-lint:
assignee: nobody → Przemysław Lal (przemeklal)
Revision history for this message
Przemyslaw Lal (przemeklal) wrote :

Found the root cause - commit b57a26c6a21c15410a7d53928ff5e6712df41dd4 removed two space characters:

-MAX_FRAME_SIZE = 2 ** 25
+MAX_FRAME_SIZE = 2**25

This makes the auto_lint.py file shorter now. This code opens the file and writes the new contents on upgrade.

fd = os.open(str(Paths.AUTO_LINT_SCRIPT_PATH), os.O_CREAT | os.O_WRONLY, 0o755)
with open(fd, "w") as f:
   f.write(auto_lint_script)

However because the file is now 2 bytes shorter, it leaves the last two bytes unchanged - which are newline char and ")".

Working on the fix now.

Revision history for this message
Przemyslaw Lal (przemeklal) wrote :
Changed in charm-juju-lint:
status: New → In Progress
Xav Paice (xavpaice)
Changed in charm-juju-lint:
status: In Progress → Fix Committed
milestone: none → 22.04
Changed in charm-juju-lint:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.