Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add schema to apt configure config #357

Merged

Conversation

lucasmoura
Copy link
Contributor

@lucasmoura lucasmoura commented May 7, 2020

This PR creates a schema object for the apt_configure module and validate this schema in the handle function of the module.

There are some considerations regarding this PR:

  • The primary and security keys have the exact same properties. I tried to eliminate this redundancy by moving their properties to a common place and then just referencing it for both security and primary. Similar to what is documented here under the Reuse paragraph. However, this approach does not work, because the # pointer goes to the beginning of the file, which is a python module instead of a json file, not allowing the pointer to find the correct definition. What I did was to create a separate dict for the mirror config and reuse it for primary and security, but maybe there are better approaches to do that.
  • There was no documentation for the config debconf_selections. I tried to infer what it supposed to do by looking at the code and the debconf-set-selections manpage, but my description may not be accurate or complete.
  • In the documentation generated, all property descriptions are bundled together in a single paragraph. This does not allows us to use lists or notes in the fields descriptions. This is generated because of this line of code, I tried to remove it to see how the docs would behave, but the result, was as expected, not good. But maybe there are other ways to include such markdown notations in the property description that I don't know about.

LP: #1858884

@blackboxsw blackboxsw self-assigned this May 7, 2020
Copy link
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

Thanks for undertaking this @lucasmoura. It's a big one in that it exposes shortcomings in cloudinit/config/schema.py and gets you exercising tox -e doc vs. python3 -m cloudinit.cmd.main devel schema -d cc_apt_configure implementation.

We can chat about it a bit on Monday and come up with some thoughts on adapting schema.py to better handle structured whitespace in property descriptions.

If you have idea

'properties': {
'preserve_sources_list': {
'type': 'boolean',
'description': dedent("""\
Copy link
Collaborator

Choose a reason for hiding this comment

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

When we define the schema we should also advertize any default values with a default key too. The doc generations will add those defaults to documentation automatically at some point (they aren't added yet).

From the code below it looks like false if unprovided
if util.is_false(cfg.get('preserve_sources_list', False)):

Suggested change
'description': dedent("""\
'default': False,
'description': dedent("""\

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

**mirror_property,
'description': dedent("""\
The primary and security archive mirrors can
be specified using the ``primary`` and
Copy link
Collaborator

Choose a reason for hiding this comment

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

After the first line in a multi-line dedent, we'll need a single indent for all the remaining lines, otherwise the documentation text gets collapsed when rendering resulting in
"The primary and security archive mirrors canbe specified..."
you can validate this behavior with python3 -m cloudinit.cmd.main devel schema --docs cc_apt_configure and look at each line break in your text. some are fine, but in a few places we've missed that single space indent. I'll mark a couple below.

Suggested change
be specified using the ``primary`` and
be specified using the ``primary`` and

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

Comment on lines +195 to +201
of configs, allowing mirrors to be specified
on a per-architecture basis. Each config is a
dictionary which must have an entry for
Copy link
Collaborator

Choose a reason for hiding this comment

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

one more space indent for these lines

Suggested change
of configs, allowing mirrors to be specified
on a per-architecture basis. Each config is a
dictionary which must have an entry for
of configs, allowing mirrors to be specified
on a per-architecture basis. Each config is a
dictionary which must have an entry for

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1

on a per-architecture basis. Each config is a
dictionary which must have an entry for
``arches``, specifying which architectures
that config entry is for. The keyword
Copy link
Collaborator

Choose a reason for hiding this comment

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

indent one more (..,,etc throughout your schema description examples)

Suggested change
that config entry is for. The keyword
that config entry is for. The keyword

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1

Comment on lines 178 to 186
``updates`` => ``$RELEASE-updates``,
``backports`` => ``$RELEASE-backports``.
``security`` => ``$RELEASE-security``,
``proposed`` => ``$RELEASE-proposed``,
``release`` => ``$RELEASE``.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Each of these lines in sphinx minimally needs a leading hyphen '- ' to ensure that they are rendered in readthedocs as bullet items in a list
See https://cloudinit.readthedocs.io/en/latest/topics/modules.html#apt-configure "disable apt sources"
versus your local rendered docs.
To render your docs locally to test and view the differences:
tox -e doc # which generates docs/rtd_html/index.html
you can browse locally with your browser of choice pointing at the URL like:
file:///home//src/cloud-init/doc/rtd_html/topics/modules.html#apt-configure

Additionally, something in the schema rendering is damaging the multi-line white space that should exist between

``disable_suites``:

   - ``updates`` => ``$RELEASE-updates``,

So, we'll have to track that down because all this text is being ultimately rendered as a single wrapped line instead of separate bullet points.

this template, the following strings will be
replaced with the appropriate values:

``$MIRROR``,
Copy link
Collaborator

Choose a reason for hiding this comment

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

bullet points using a leading hyphen

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • 1

The ``source`` key supports variable
replacements for the following strings:

``$MIRROR``,
Copy link
Collaborator

Choose a reason for hiding this comment

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

bullet points.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1

regex in ``add_apt_repo_match`` will be added to
the system using ``add-apt-repository``. If
``add_apt_repo_match`` is not specified, it
defaults to ``^[\\w-]+:\\w``""")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use the global ADD_APT_REPO_MATCH from the file instead of repeating in docs (in case it changes)

It's probably worth adding a 'default': ADD_APT_REPO_MATCH, here too to the schema

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

},
'proxy': {
'type': 'string',
'description': dedent("""\
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think you need the dedent here we just use it when multiple lines of text were needed.
the below fits in 80 chars
'description': 'Alias for defining a http apt proxy.',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Each entry under ``sources`` is a dictionary which
may contain any of the following optional keys:

``source``: a sources.list entry \
Copy link
Collaborator

Choose a reason for hiding this comment

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

bullet points

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1

@lucasmoura lucasmoura force-pushed the add-schema-to-apt-configure-config branch from 70ff0b8 to 8af59d8 Compare May 12, 2020 13:01
@lucasmoura
Copy link
Contributor Author

@blackboxsw I have addressed the issues you raised. We just need to figure out how to proceed with the description problem. If you believe we can address it in this PR, I can start working on it without an issue.

@lucasmoura lucasmoura force-pushed the add-schema-to-apt-configure-config branch from f7c3eb9 to d64fc87 Compare May 13, 2020 13:21
@lucasmoura
Copy link
Contributor Author

lucasmoura commented May 13, 2020

@blackboxsw I think I have solved the description parsing problem. But if you think there is a better solution, no problem, I can work on it as well

@lucasmoura lucasmoura force-pushed the add-schema-to-apt-configure-config branch from d64fc87 to 1ff2223 Compare May 13, 2020 19:06
Copy link
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

Looks really good @lucasmoura! Couple minor nits and we are good to go.

'type': 'string',
'description': dedent("""\
Specify configuration for apt, such as proxy
configuratiun. This configuration is specified as a
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
configuratiun. This configuration is specified as a
configuration. This configuration is specified as a

'https_proxy': {
'type': 'string',
'description': dedent("""\
More convinient way to specify https apt proxy.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
More convinient way to specify https apt proxy.
More convenient way to specify https apt proxy.

'http_proxy': {
'type': 'string',
'description': dedent("""\
More convinient way to specify http apt proxy.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
More convinient way to specify http apt proxy.
More convenient way to specify http apt proxy.

cloudinit/config/cc_apt_configure.py Outdated Show resolved Hide resolved
@lucasmoura
Copy link
Contributor Author

@blackboxsw Done

Copy link
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

Excellent work thanks @lucasmoura

@blackboxsw blackboxsw merged commit 2e32c40 into canonical:master May 13, 2020
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