← Back to team overview

cloud-init-dev team mailing list archive

Re: [Merge] ~adobrawy/cloud-init:swap-linux into cloud-init:master

 

Please add some sort of unit test to ensure we do not break this in the future.


Diff comments:

> diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py
> index 339baba..e54e753 100644
> --- a/cloudinit/config/cc_mounts.py
> +++ b/cloudinit/config/cc_mounts.py
> @@ -249,14 +249,22 @@ def setup_swapfile(fname, size=None, maxsize=None):
>      msg = "creating swap file '%s' of %sMB" % (fname, mbsize)
>      try:
>          util.ensure_dir(tdir)
> +        # Check if filesystem is safe for fallocate
> +        fname_fs_type = util.get_mount_info(fname)[1]
> +        if fname_fs_type in ['xfs']:
> +            create_swapfile_command = 'dd if=/dev/zero "of=$1" bs=1M "count=$2"'
> +        else:
> +            create_swapfile_command = 'fallocate -l "${2}M" "$1"'
> +
>          util.log_time(LOG.debug, msg, func=util.subp,
>                        args=[['sh', '-c',
>                              ('rm -f "$1" && umask 0066 && '
> -                             '{ fallocate -l "${2}M" "$1" || '
> -                             ' dd if=/dev/zero "of=$1" bs=1M "count=$2"; } && '
> -                             'mkswap "$1" || { r=$?; rm -f "$1"; exit $r; }'),
> +                             '%s && '
> +                             'mkswap "$1" || { r=$?; rm -f "$1"; exit $r; }' %
> +                             create_swapfile_command),
>                               'setup_swap', fname, mbsize]])
>  
> +

this probably makes 'tox -e flake8' complain.

>      except Exception as e:
>          raise IOError("Failed %s: %s" % (msg, e))
>  


-- 
https://code.launchpad.net/~adobrawy/cloud-init/+git/cloud-init/+merge/354680
Your team cloud-init commiters is requested to review the proposed merge of ~adobrawy/cloud-init:swap-linux into cloud-init:master.


References