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

schema: add json defs for modules U-Z #1360

Merged
merged 11 commits into from
Apr 8, 2022
Merged

Conversation

blackboxsw
Copy link
Collaborator

Proposed Commit Message

Migrate legacy schema to cloud-init-schema.json:
    - cc_ubuntu_advantage
    - cc_ubuntu_drivers
    - cc_write_files: added minItems: 1 to list to catch potential YAML typos
    - cc_write_files_deferred
    - cc_zypper_add_repo

Defined JSON schema for the following modules:
- cc_update_hostname
- cc_update_etc_hosts: Add DEPRECATED log for manage_etc_hosts: "template" as 
      it is non-intuitive alias of True value
- cc_yum_add_repo:  docstring incorrectly status PER_ALWAYS, but no module
  frequency attribute was defined, so cloud-init defaults to PER_INSTANCE.
  Set it PER_INSTANCE explicitly to avoid change in behavior.

Additional Context

Does not contain cc_user_groups as that's a fairly big module schema to sort, so I'd like to keep that module separate for
ease of review.

Test Steps

tox -re doc; xdg-open doc/rtd_html/topics/modules.html
PYTHONPATH=. python3 -m cloudinit.cmd.main devel schema --docs cc_update_hostname ....

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

Copy link
Member

@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.

Left some comments inline. Additionally, see the following diff:

diff --git a/cloudinit/config/cc_zypper_add_repo.py b/cloudinit/config/cc_zypper_add_repo.py
index 330ef346..9b682bc6 100644
--- a/cloudinit/config/cc_zypper_add_repo.py
+++ b/cloudinit/config/cc_zypper_add_repo.py
@@ -3,7 +3,7 @@
 #
 # This file is part of cloud-init. See LICENSE file for license information.
 
-"""zypper_add_repo: Add zyper repositories to the system"""
+"""zypper_add_repo: Add zypper repositories to the system"""
 
 import os
 from textwrap import dedent
@@ -16,22 +16,25 @@ from cloudinit.config.schema import MetaSchema, get_meta_doc
 from cloudinit.settings import PER_ALWAYS
 
 distros = ["opensuse", "sles"]
-
+MODULE_DESCRIPTION = """\
+Zypper behavior can be configured using the ``config`` key, which will modify
+``/etc/zypp/zypp.conf``. The configuration writer will only append the
+provided configuration options to the configuration file. Any duplicate
+options will be resolved by the way the zypp.conf INI file is parsed.
+
+.. note::
+    Setting ``configdir`` is not supported and will be skipped.
+
+The ``repos`` key may be used to add repositories to the system. Beyond the
+required ``id`` and ``baseurl`` attributions, no validation is performed
+on the ``repos`` entries. It is assumed the user is familiar with the
+zypper repository file format.
+"""
 meta: MetaSchema = {
     "id": "cc_zypper_add_repo",
-    "name": "ZypperAddRepo",
+    "name": "Zypper Add Repo",
     "title": "Configure zypper behavior and add zypper repositories",
-    "description": dedent(
-        """\
-        Configure zypper behavior by modifying /etc/zypp/zypp.conf. The
-        configuration writer is "dumb" and will simply append the provided
-        configuration options to the configuration file. Option settings
-        that may be duplicate will be resolved by the way the zypp.conf file
-        is parsed. The file is in INI format.
-        Add repositories to the system. No validation is performed on the
-        repository file entries, it is assumed the user is familiar with
-        the zypper repository file format."""
-    ),
+    "description": MODULE_DESCRIPTION,
     "distros": distros,
     "examples": [
         dedent(
diff --git a/doc/rtd/topics/modules.rst b/doc/rtd/topics/modules.rst
index 093cee61..9541f675 100644
--- a/doc/rtd/topics/modules.rst
+++ b/doc/rtd/topics/modules.rst
@@ -64,4 +64,5 @@ Modules
 .. automodule:: cloudinit.config.cc_users_groups
 .. automodule:: cloudinit.config.cc_write_files
 .. automodule:: cloudinit.config.cc_yum_add_repo
+.. automodule:: cloudinit.config.cc_zypper_add_repo
 .. vi: textwidth=79

Changes:

  • Zypper module had a typo in its docstring
  • I decided to rewrite the zypper module description. It doesn't make much sense and doesn't follow inclusive naming standards.
  • Added the zypper module to the end of modules.rst so it gets included in the documentation.

"properties": {
"manage_etc_hosts": {
"default": false,
"description": "Whether to manage /etc/hosts on the system. When set ``true``, cloud-init will render the hosts file using ``/etc/cloud/templates/hosts.tmpl`` replacing ``$hostname`` and ``$fdqn``. When set ``localhost``, Default: ``false``. DEPRECATED value ``template``will be dropped, use ``true`` instead.",
Copy link
Member

Choose a reason for hiding this comment

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

When set localhost, Default: false

^ I think you accidentally your sentence there

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

+1 I also changed the oneOf to "enum": [true, false, "template", "localhost"] which I think provides a better schema error message 'templatey' is not one of [True, False, 'template', 'localhost']`

versus
'templatey' is not valid under any of the given schemas

cloudinit/config/cc_update_etc_hosts.py Show resolved Hide resolved
cloudinit/config/cloud-init-schema.json Outdated Show resolved Hide resolved
cloudinit/config/cc_update_hostname.py Show resolved Hide resolved
cloudinit/config/cc_write_files.py Show resolved Hide resolved
cloudinit/config/cloud-init-schema.json Outdated Show resolved Hide resolved
cloudinit/config/cloud-init-schema.json Outdated Show resolved Hide resolved
cloudinit/config/cc_yum_add_repo.py Show resolved Hide resolved
cloudinit/config/cloud-init-schema.json Show resolved Hide resolved
cloudinit/config/cloud-init-schema.json Outdated Show resolved Hide resolved
Copy link
Member

@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.

One small language thing inline, but I trust you can fix that and merge when finished.

@@ -1517,8 +1517,8 @@
"properties": {
"manage_etc_hosts": {
"default": false,
"description": "Whether to manage /etc/hosts on the system. When set ``true``, cloud-init will render the hosts file using ``/etc/cloud/templates/hosts.tmpl`` replacing ``$hostname`` and ``$fdqn``. When set ``localhost``, Default: ``false``. DEPRECATED value ``template``will be dropped, use ``true`` instead.",
"oneOf": [{"type": "boolean"}, {"enum": ["template", "localhost"]}]
"description": "Whether to manage ``/etc/hosts`` on the system. Set ``true`` to render the hosts file using ``/etc/cloud/templates/hosts.tmpl`` replacing ``$hostname`` and ``$fdqn``. Set ``localhost`` to and cloud-init will append a ``127.0.1.1`` entry that resolves from FQDN and hostname every boot. Default: ``false``. DEPRECATED value ``template`` will be dropped, use ``true`` instead.",
Copy link
Member

Choose a reason for hiding this comment

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

One more nit here: Set localhost to and cloud-init will append. Set localhost to what?

Add minItems: "1" to write_files schema to avoid empty list.
While schema still supports manage_etc_hosts: template, deprecate
this value as it is an alias for true.

Add DEPRECATED log for use of 'template' value.
frequency: ALWAYS was listed in the docstring, but it wasn't
provided as a module-level freq attribute. So cloud-init actually
defaults it to PER_INSTANCE.

We don't want to change behavior, so let's set PER_INSTANCE here which
also aligns with apt_configure module for setting up repos.
- cc_update_etc_hosts: drop "template" documentation
- cc_update_hostname: missing dedents
- cc_write_files: move distros= ["all"] into Meta drop schema comment
- cc_yum: example for yum_repo_dir
- cloud-init-schema.json:
  - manage_etc_hosts: descr ++ flat enum vs  oneOf [boolean, enum]
  - yum: descr updates, patternPropery labels
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