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 schema for mcollective, migrator and mounts modules #1358

Merged
merged 6 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions cloudinit/config/cc_mounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
Any mounts that do not appear to either an attached block device or network
resource will be skipped with a log like "Ignoring nonexistent mount ...".

Cloud-init will attempt to add the following mount directives if available yet
Cloud-init will attempt to add the following mount directives if available and
unconfigured in `/etc/fstab`:
mounts:
- ["ephemeral0", "/mnt", "auto", "defaults,nobootwait", "0", "2"]
- ["ephemeral0", "/mnt", "auto",
"defaults,nofail,x-systemd.requires=cloud-init.service", "0", "2"]
- ["swap", "none", "swap", "sw", "0", "0"]

In order to remove a previously listed mount, an entry can be added to
Expand All @@ -45,15 +46,10 @@
``fs_spec`` and the ``fs_file``. If specified, this must be a list containing 6
values. It defaults to::

mount_default_fields: [none, none, "auto", "defaults,nobootwait", "0", "2"]

On a systemd booted system that default is the mostly equivalent::

mount_default_fields: [none, none, "auto",
"defaults,nofail,x-systemd.requires=cloud-init.service", "0", "2"]
"defaults,nofail,x-systemd.requires=cloud-init.service", "0", "2"]

Note that `nobootwait` is an upstart specific boot option that somewhat
equates to the more standard `nofail`.
Other init systems will vary in ``mount_default_fields``.
blackboxsw marked this conversation as resolved.
Show resolved Hide resolved

Swap files can be configured by setting the path to the swap file to create
with ``filename``, the size of the swap file with ``size`` maximum size of
Expand All @@ -63,11 +59,15 @@

example = dedent(
"""\
# Mount ephemeral0 with "noexec" flag, /dev/sdc with mount_default_fields,
# and /dev/xvdh with custom fs_passno "0" to avoid fsck on the mount.
# Also provide an automatically sized swap with a max size of 10485760
# bytes.
mounts:
- [ /dev/ephemeral0, /mnt, auto, "defaults,noexec" ]
- [ sdc, /opt/data ]
- [ xvdh, /opt/data, "auto", "defaults,nofail", "0", "0" ]
mount_default_fields: [None, None, "auto", "defaults,nofail", "0", "2"]
- [ xvdh, /opt/data, auto, "defaults,nofail", "0", "0" ]
mount_default_fields: [None, None, auto, "defaults,nofail", "0", "2"]
swap:
filename: /my/swapfile
blackboxsw marked this conversation as resolved.
Show resolved Hide resolved
size: auto
Expand All @@ -83,7 +83,18 @@
"title": "Configure mount points and swap files",
"description": MODULE_DESCRIPTION,
"distros": distros,
"examples": [example],
"examples": [
example,
dedent(
"""\
# Create a 2 GB swap file at /swapfile using human-readable values
swap:
filename: /swapfile
size: 2G
maxsize: 2G
"""
),
],
"frequency": PER_INSTANCE,
}

Expand Down
19 changes: 13 additions & 6 deletions cloudinit/config/cloud-init-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -838,13 +838,13 @@
"minItems": 1,
"maxItems": 6
},
"description": "List of lists. Each inner list entry is a list of ``/etc/fstab`` entries of the format: [ fs_spec, fs_file, fs_vfstype, fs_mntops, fs-freq, fs_passno ]",
"description": "List of lists. Each inner list entry is a list of ``/etc/fstab`` mount declaratiosn of the format: [ fs_spec, fs_file, fs_vfstype, fs_mntops, fs-freq, fs_passno ]. A mount declaration with less than 6 items, will get remaining values from ``mount_default_fields``. A mount declaration with only `fs_spec` and no `fs_file` mountpoint will be skipped.",
blackboxsw marked this conversation as resolved.
Show resolved Hide resolved
"minItems": 1
},
"mount_default_fields": {
"type": "array",
"description": "Default mount configuration for any mount entry with less than 6 options provided. When specified, 6 items are required and represent ``/etc/fstab`` entries. Systemd-based mount options will be ``defaults,nofail,x-systemd.requires=cloud-init.service,_netdev``",
"default": [null, null, "auto", "defaults,nobootwait", "0", "2"],
"description": "Default mount configuration for any mount entry with less than 6 options provided. When specified, 6 items are required and represent ``/etc/fstab`` entries. Default: ``defaults,nofail,x-systemd.requires=cloud-init.service,_netdev``",
"default": [null, null, "auto", "defaults,nofail,x-systemd.requires=cloud-init.service", "0", "2"],
"items": {
"oneOf": [
{"type": "string"},
Expand All @@ -862,11 +862,18 @@
"description": "Path to the swap file to create"
},
"size": {
"description": "The size in bytes of the swap file, or 'auto'",
"oneOf": [{"enum": ["auto"]}, {"type": "integer"}]
"description": "The size in bytes of the swap file, 'auto' or a human-readable size abbreviation of the format <float_size><units> where units are one of B, K, M, G or T.",
"oneOf": [
{"enum": ["auto"]},
{"type": "integer"},
{"type": "string", "pattern": "^([0-9]+)?\\.?[0-9]+[BKMGT]$"}
]
},
"maxsize": {
"type": "integer",
"oneOf": [
{"type": "integer"},
{"type": "string", "pattern": "^([0-9]+)?\\.?[0-9]+[BKMGT]$"}
],
"description": "The maxsize in bytes of the swap file"
}
},
Expand Down
16 changes: 16 additions & 0 deletions tests/unittests/config/test_cc_mounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,22 @@ class TestMountsSchema:
{"swap": {"invalidprop": True}},
"Additional properties are not allowed \('invalidprop'",
),
# Swap size/maxsize positive test cases
({"swap": {"size": ".5T", "maxsize": ".5T"}}, None),
({"swap": {"size": "1G", "maxsize": "1G"}}, None),
({"swap": {"size": "200K", "maxsize": "200K"}}, None),
({"swap": {"size": "10485760B", "maxsize": "10485760B"}}, None),
# Swap size/maxsize negative test cases
({"swap": {"size": "1.5MB"}}, "swap.size:"),
(
{"swap": {"maxsize": "1.5MT"}},
"swap.maxsize: '1.5MT' is not valid",
),
(
{"swap": {"maxsize": "..5T"}},
"swap.maxsize: '..5T' is not valid",
),
({"swap": {"size": "K"}}, "swap.size: 'K' is not valid"),
],
)
@test_helpers.skipUnlessJsonSchema()
Expand Down