Skip to content

Fix unhandled apt_configure case (SC-526)#1065

Merged
TheRealFalcon merged 1 commit intocanonical:mainfrom
holmanb:holmanb/apt-configure-arch
Nov 1, 2021
Merged

Fix unhandled apt_configure case (SC-526)#1065
TheRealFalcon merged 1 commit intocanonical:mainfrom
holmanb:holmanb/apt-configure-arch

Conversation

@holmanb
Copy link
Member

@holmanb holmanb commented Oct 12, 2021

Proposed Commit Message

Fix schema and fix unhandled apt_configure case.

Don't throw an exception when mirror arch is unspecified.

Test Steps

Use the following config.

Checklist:

  • My code follows the process laid out in the documentation
  • I have updated or added any unit tests accordingly
  • I have updated or added any documentation accordingly

default = None
for mirror_cfg_elem in mirror_cfg_list:
arches = mirror_cfg_elem.get("arches")
arches = mirror_cfg_elem.get("arches", [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If mirror_cfg_elem = {'arches', None}, we still have a problem. I haven't checked so this might not even be possible, but just in general for these sorts of operations I prefer something more like

arches = mirror_cfg_elem.get("arches") or []

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, that looks like a safer pattern to use.

@holmanb
Copy link
Member Author

holmanb commented Oct 13, 2021

A second look at this suggests that setting arches to an empty iterable might not be the right/only solution to this problem.

From the docs:

Each config is a dictionary which must have an entry for arches, specifying which architectures that config entry is for.

For a security mirror config:

  security:
    - uri: http://security.ubuntu.com/ubuntu

Consider the following resulting log:

2021-10-12 22:56:19,342 - cc_apt_configure.py[DEBUG]: got primary mirror: http://us.archive.ubuntu.com/ubuntu
2021-10-12 22:56:19,342 - cc_apt_configure.py[DEBUG]: got security mirror: None
2021-10-12 22:56:19,343 - cc_apt_configure.py[DEBUG]: Apt Mirror info: {'PRIMARY': 'http://us.archive.ubuntu.com/ubuntu', 'SECURITY': 'http://us.archive.ubuntu.com/ubuntu', 'MIRROR': 'http://us.archive.ubuntu.com/ubuntu'}

Note that the security mirror falls back to the primary mirror.

It looks like the schema attempts to make arches 'required', however I didn't see any warnings about arches in the logs.

mirror_property = {
    'type': 'array',
    'item': {
        'type': 'object',
        'additionalProperties': False,
        'required': ['arches'],
        'properties': {

Considering this config doesn't follow the rules "must have an entry for arches", I would expect a warning log to be dropped at a minimum, rather than failing over to the primary mirror without any mention that the config is invalid.

I think probably the right solution is in addition to arches = mirror_cfg_elem.get("arches") or [] we also "fix" the schema to log the config violation properly. Thoughts?

@TheRealFalcon
Copy link
Contributor

Good catch about the schema. Yes, we should fail schema validation on that and emit a warning. Though I still think we should handle the empty case.

@holmanb
Copy link
Member Author

holmanb commented Oct 13, 2021

Good catch about the schema. Yes, we should fail schema validation on that and emit a warning. Though I still think we should handle the empty case.

Agreed

@holmanb holmanb mentioned this pull request Oct 14, 2021
3 tasks
@holmanb
Copy link
Member Author

holmanb commented Oct 18, 2021

I'm still working on this. I noticed another schema issue with this module:
From this example

    my-repo3.list:
      # this would have the same end effect as 'ppa:curtin-dev/test-archive'
      source: "deb http://ppa.launchpad.net/curtin-dev/test-archive/ubuntu xenial main"
      keyid: F430BBA5 # GPG key ID published on the key server
      filename: curtin-dev-ppa.list

Note that the filename key is not documented in the apt_configure module docs, but the key is referenced and used in the implementation (it causes a duplicate *.list file to be dropped in /etc/apt/sources.list.d iirc). This should be documented in readthedocs and the schema

@holmanb holmanb force-pushed the holmanb/apt-configure-arch branch from c76b26b to f643853 Compare October 27, 2021 01:26
@holmanb
Copy link
Member Author

holmanb commented Oct 27, 2021

The failing test pulls in the example from readthedocs and runs it. The test is fixed in #1068, so I can either pull that fix into this one, or wait until that one is merged.

@holmanb holmanb changed the title Fix unhandled apt_configure case. Fix unhandled apt_configure case (SC-526) Oct 27, 2021
@TheRealFalcon
Copy link
Contributor

Easiest to just wait for #1068 and then rebase I think.

@holmanb holmanb force-pushed the holmanb/apt-configure-arch branch from f643853 to b8055d5 Compare October 29, 2021 20:41
Don't throw an exception when mirror arch is unspecified.
@holmanb holmanb force-pushed the holmanb/apt-configure-arch branch from b8055d5 to 8af4c2c Compare October 29, 2021 21:30
@holmanb
Copy link
Member Author

holmanb commented Oct 29, 2021

I had to tweak some tests after rebasing. I think it's ready for review now.

Copy link
Contributor

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants