backtrace on attach: KeyError: 'effectiveTo'

Bug #1829788 reported by Andreas Hasenack
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
ubuntu-advantage-script
Fix Released
Unknown
ubuntu-advantage-tools (Ubuntu)
Fix Released
High
Andreas Hasenack
Disco
Won't Fix
High
Andreas Hasenack
Eoan
Fix Released
High
Andreas Hasenack

Bug Description

[Impact]
Due to a server-side change, an expected key is no longer being sent to the client during an attach operation. This causes the client to backtrace with a KeyError exception:

Traceback (most recent call last):
File "/usr/bin/ua", line 11, in
load_entry_point('ubuntu-advantage-tools==19.2', 'console_scripts', 'ubuntu-advantage')()
File "/usr/lib/python3/dist-packages/uaclient/cli.py", line 371, in main
return args.action(args, cfg)
File "/usr/lib/python3/dist-packages/uaclient/cli.py", line 241, in action_attach
action_status(args=None, cfg=cfg)
File "/usr/lib/python3/dist-packages/uaclient/cli.py", line 295, in action_status
contractInfo['effectiveTo'], '%Y-%m-%dT%H:%M:%SZ')
KeyError: 'effectiveTo'

The client should default to a "no expiration" value in this case. Upstream already handles this, but the fix is missing for disco and eoan.

[Test Case]
Run "sudo ua attach":
$ sudo ua attach
Email: <email address hidden>
Password:
Second-factor auth: nnnnnn
This machine is now attached to '<email address hidden>'.

Traceback (most recent call last):
  File "/usr/bin/ua", line 11, in <module>
    load_entry_point('ubuntu-advantage-tools==19.2', 'console_scripts', 'ubuntu-advantage')()
  File "/usr/lib/python3/dist-packages/uaclient/cli.py", line 373, in main
    return args.action(args, cfg)
  File "/usr/lib/python3/dist-packages/uaclient/cli.py", line 241, in action_attach
    action_status(args=None, cfg=cfg)
  File "/usr/lib/python3/dist-packages/uaclient/cli.py", line 311, in action_status
    contract_expiry=expiry.date(),
AttributeError: 'str' object has no attribute 'date'

With the fixed package, you should see "n/a" for the "Valid until" header and it should not crash:
Email: <email address hidden>
Password:
Second-factor auth: pppppp
This machine is now attached to '<email address hidden>'.

Account: <email address hidden>
Subscription: <email address hidden>
Valid until: n/a
Technical support level: not included
...

[Regression Potential]
The fix is just setting a "n/a" text value to the expiration date in the case one isn't provided, and that is exactly the expected outcome, and what the (already heavily modified) upstream code does.

No existing tests were affected by the change, which means it's not covered.

Finally, the UA offerings are currently not available for non-LTS releases, so there is nothing to regress here. A crash is a bad bug, though, so we do want to get it fixed.

[Other Info]
None at this time.

Related branches

Changed in ubuntu-advantage-tools (Ubuntu Disco):
status: New → In Progress
assignee: nobody → Andreas Hasenack (ahasenack)
importance: Undecided → High
description: updated
description: updated
Changed in ubuntu-advantage-script:
status: Unknown → Fix Released
Revision history for this message
Andreas Hasenack (ahasenack) wrote :

This is fixed in eoan

Changed in ubuntu-advantage-tools (Ubuntu Eoan):
status: In Progress → Fix Released
Steve Langasek (vorlon)
Changed in ubuntu-advantage-tools (Ubuntu Disco):
status: In Progress → Won't Fix
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.