Re: [Cloud-init-dev] [Merge] ('~chad.smith/cloud-init', ':', 'bug/1840080-ubuntu-drivers-emit-latelink-v2') into ('cloud-init', ':', 'master')
Review: Approve continuous-integration PASSED: Continuous integration, rev:48733aa42ac30013db4ce3daa7643ee941b51b63 https://jenkins.ubuntu.com/server/job/cloud-init-ci/1062/ Executed test runs: SUCCESS: Checkout SUCCESS: Unit & Style Tests SUCCESS: Ubuntu LTS: Build SUCCESS: Ubuntu LTS: Integration IN_PROGRESS: Declarative: Post Actions Click here to trigger a rebuild: https://jenkins.ubuntu.com/server/job/cloud-init-ci/1062//rebuild -- https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/371546 Your team cloud-init commiters is requested to review the proposed merge of ~chad.smith/cloud-init:bug/1840080-ubuntu-drivers-emit-latelink-v2 into cloud-init:master. ___ Mailing list: https://launchpad.net/~cloud-init-dev Post to : cloud-init-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~cloud-init-dev More help : https://help.launchpad.net/ListHelp
Re: [Cloud-init-dev] [Merge] ('~chad.smith/cloud-init', ':', 'bug/1840080-ubuntu-drivers-emit-latelink-v2') into ('cloud-init', ':', 'master')
Review: Needs Fixing continuous-integration FAILED: Continuous integration, rev:71fcd42be6330033bcb731080053a885786f2130 https://jenkins.ubuntu.com/server/job/cloud-init-ci/1061/ Executed test runs: SUCCESS: Checkout FAILED: Unit & Style Tests Click here to trigger a rebuild: https://jenkins.ubuntu.com/server/job/cloud-init-ci/1061//rebuild -- https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/371546 Your team cloud-init commiters is requested to review the proposed merge of ~chad.smith/cloud-init:bug/1840080-ubuntu-drivers-emit-latelink-v2 into cloud-init:master. ___ Mailing list: https://launchpad.net/~cloud-init-dev Post to : cloud-init-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~cloud-init-dev More help : https://help.launchpad.net/ListHelp
Re: [Cloud-init-dev] [Merge] ~chad.smith/cloud-init:bug/1840080-ubuntu-drivers-emit-latelink-v2 into cloud-init:master
Diff comments: > diff --git a/cloudinit/config/cc_ubuntu_drivers.py > b/cloudinit/config/cc_ubuntu_drivers.py > index 4da34ee..44a2bfe 100644 > --- a/cloudinit/config/cc_ubuntu_drivers.py > +++ b/cloudinit/config/cc_ubuntu_drivers.py > @@ -65,6 +65,39 @@ OLD_UBUNTU_DRIVERS_STDERR_NEEDLE = ( > __doc__ = get_schema_doc(schema) # Supplement python help() > > > +# debconf template to allow cloud-init pre-configure the global debconf > +# variable linux/nvidia/latelink to true, allowing linux-restricted-modules > +# to accept the NVIDIA EULA and automatically link drivers to the running > +# kernel. > +# EOL_XENIAL: can then drop this script and use python3-debconf which is only > +# available in Bionic and later. Can't use python3-debconf currently as it > +# isn't in Xenial and doesn't yet support X_LOADTEMPLATEFILE debconf command. > + > +NVIDIA_DRIVER_LATELINK_DEBCONF_TMPL = """\ done. Per your other comments, I've simplified the NVIDIA_DRIVER_LATELINK_DEBCONF_SCRIPT and we'll also write the separate NVIDIA_DEBCONF_CONTENT which can be passed to the script as $1 > +#/bin/sh > +# Allow cloud-init to trigger EULA acceptance via registering a debconf > +# template to set linux/nvidia/latelink true > + > +. /usr/share/debconf/confmodule > + > +SCRIPT=$(readlink -f "$0") > +DIRNAME=$(dirname "$SCRIPT") > +tmpfile=$(mktemp -p ${DIRNAME} -t > "cloud-init-ubuntu-drivers-XX.template") > +cat > "$tmpfile" << EOF > +Template: linux/nvidia/latelink > +Type: boolean > +Default: true > +Description: Late-link NVIDIA kernel modules? > + Enable this to link the NVIDIA kernel modules in cloud-init and > + make them available for use. > +EOF > +echo BEFORE $tmpfile Good suggestion, done. > +db_x_loadtemplatefile "$tmpfile" cloud-init > +echo AFTER $tmpfile > +rm "$tmpfile" > +""" > + > + > def install_drivers(cfg, pkg_install_func): > if not isinstance(cfg, dict): > raise TypeError( > @@ -90,17 +123,22 @@ def install_drivers(cfg, pkg_install_func): > if version_cfg: > driver_arg += ':{}'.format(version_cfg) > > -LOG.debug("Installing NVIDIA drivers (%s=%s, version=%s)", > +LOG.debug("Installing and activating NVIDIA drivers (%s=%s, version=%s)", >cfgpath, nv_acc, version_cfg if version_cfg else 'latest') > > -# Setting NVIDIA latelink confirms acceptance of EULA for the package > -# linux-restricted-modules > -# Reference code defining debconf variable is here > -# https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/ > -# linux-restricted-modules/+git/eoan/tree/debian/templates/ > -# nvidia.templates.in > -selections = b'linux-restricted-modules linux/nvidia/latelink boolean > true' > -cc_apt_configure.debconf_set_selections(selections) > +# Register and set debconf selection linux/nvidia/latelink = true > +with temp_utils.ExtendedTemporaryFile( > +suffix=".sh", needs_exe=True) as tmpf: > +try: > +tmpf.write(util.encode_text(NVIDIA_DRIVER_LATELINK_DEBCONF_TMPL)) > +tmpf.flush() > +util.chmod(tmpf.name, 0o755) Agreed. fixed. > +util.subp([tmpf.name]) > +except Exception as e: > +util.logexc( > +LOG, > +"Failed to register NVIDIA debconf template: %s", str(e)) > +raise > > try: > util.subp(['ubuntu-drivers', 'install', '--gpgpu', driver_arg]) -- https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/371546 Your team cloud-init commiters is requested to review the proposed merge of ~chad.smith/cloud-init:bug/1840080-ubuntu-drivers-emit-latelink-v2 into cloud-init:master. ___ Mailing list: https://launchpad.net/~cloud-init-dev Post to : cloud-init-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~cloud-init-dev More help : https://help.launchpad.net/ListHelp
Re: [Cloud-init-dev] [Merge] ~chad.smith/cloud-init:bug/1840080-ubuntu-drivers-emit-latelink-v2 into cloud-init:master
some inline comments/suggestions. Diff comments: > diff --git a/cloudinit/config/cc_ubuntu_drivers.py > b/cloudinit/config/cc_ubuntu_drivers.py > index 4da34ee..44a2bfe 100644 > --- a/cloudinit/config/cc_ubuntu_drivers.py > +++ b/cloudinit/config/cc_ubuntu_drivers.py > @@ -65,6 +65,39 @@ OLD_UBUNTU_DRIVERS_STDERR_NEEDLE = ( > __doc__ = get_schema_doc(schema) # Supplement python help() > > > +# debconf template to allow cloud-init pre-configure the global debconf > +# variable linux/nvidia/latelink to true, allowing linux-restricted-modules > +# to accept the NVIDIA EULA and automatically link drivers to the running > +# kernel. > +# EOL_XENIAL: can then drop this script and use python3-debconf which is only > +# available in Bionic and later. Can't use python3-debconf currently as it > +# isn't in Xenial and doesn't yet support X_LOADTEMPLATEFILE debconf command. > + > +NVIDIA_DRIVER_LATELINK_DEBCONF_TMPL = """\ TMPL makes me think of jinja or some other string replacement by the caller of this. Could we replace _TMPL with _SCRIPT ? > +#/bin/sh > +# Allow cloud-init to trigger EULA acceptance via registering a debconf > +# template to set linux/nvidia/latelink true > + > +. /usr/share/debconf/confmodule > + > +SCRIPT=$(readlink -f "$0") > +DIRNAME=$(dirname "$SCRIPT") > +tmpfile=$(mktemp -p ${DIRNAME} -t > "cloud-init-ubuntu-drivers-XX.template") > +cat > "$tmpfile" << EOF > +Template: linux/nvidia/latelink > +Type: boolean > +Default: true > +Description: Late-link NVIDIA kernel modules? > + Enable this to link the NVIDIA kernel modules in cloud-init and > + make them available for use. > +EOF > +echo BEFORE $tmpfile The script would be simpler if it required $1 to be the tmpfile and then we could util.write_files() the script and the input file? We already make one tempdir to hold the script, we could just write the input file there as well and subp the script with the input file as argument? #!/bin/sh . /usr/share/debconf/confmodule db_x_loadtemplatefile "$1" cloud-init util.subp([script_name, input_file]) ? > +db_x_loadtemplatefile "$tmpfile" cloud-init > +echo AFTER $tmpfile > +rm "$tmpfile" > +""" > + > + > def install_drivers(cfg, pkg_install_func): > if not isinstance(cfg, dict): > raise TypeError( > @@ -90,17 +123,22 @@ def install_drivers(cfg, pkg_install_func): > if version_cfg: > driver_arg += ':{}'.format(version_cfg) > > -LOG.debug("Installing NVIDIA drivers (%s=%s, version=%s)", > +LOG.debug("Installing and activating NVIDIA drivers (%s=%s, version=%s)", >cfgpath, nv_acc, version_cfg if version_cfg else 'latest') > > -# Setting NVIDIA latelink confirms acceptance of EULA for the package > -# linux-restricted-modules > -# Reference code defining debconf variable is here > -# https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/ > -# linux-restricted-modules/+git/eoan/tree/debian/templates/ > -# nvidia.templates.in > -selections = b'linux-restricted-modules linux/nvidia/latelink boolean > true' > -cc_apt_configure.debconf_set_selections(selections) > +# Register and set debconf selection linux/nvidia/latelink = true > +with temp_utils.ExtendedTemporaryFile( > +suffix=".sh", needs_exe=True) as tmpf: > +try: > +tmpf.write(util.encode_text(NVIDIA_DRIVER_LATELINK_DEBCONF_TMPL)) > +tmpf.flush() > +util.chmod(tmpf.name, 0o755) Any reason not to use util.write_files(tmpf.name, content, mode=0o755) ? > +util.subp([tmpf.name]) > +except Exception as e: > +util.logexc( > +LOG, > +"Failed to register NVIDIA debconf template: %s", str(e)) > +raise > > try: > util.subp(['ubuntu-drivers', 'install', '--gpgpu', driver_arg]) -- https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/371546 Your team cloud-init commiters is requested to review the proposed merge of ~chad.smith/cloud-init:bug/1840080-ubuntu-drivers-emit-latelink-v2 into cloud-init:master. ___ Mailing list: https://launchpad.net/~cloud-init-dev Post to : cloud-init-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~cloud-init-dev More help : https://help.launchpad.net/ListHelp
Re: [Cloud-init-dev] [Merge] ('~chad.smith/cloud-init', ':', 'bug/1840080-ubuntu-drivers-emit-latelink-v2') into ('cloud-init', ':', 'master')
Review: Needs Fixing continuous-integration FAILED: Continuous integration, rev:044f9d692ebca82186b9159a69e75816ad99f998 https://jenkins.ubuntu.com/server/job/cloud-init-ci/1060/ Executed test runs: SUCCESS: Checkout FAILED: Unit & Style Tests Click here to trigger a rebuild: https://jenkins.ubuntu.com/server/job/cloud-init-ci/1060//rebuild -- https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/371546 Your team cloud-init commiters is requested to review the proposed merge of ~chad.smith/cloud-init:bug/1840080-ubuntu-drivers-emit-latelink-v2 into cloud-init:master. ___ Mailing list: https://launchpad.net/~cloud-init-dev Post to : cloud-init-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~cloud-init-dev More help : https://help.launchpad.net/ListHelp
[Cloud-init-dev] [Merge] ~chad.smith/cloud-init:bug/1840080-ubuntu-drivers-emit-latelink-v2 into cloud-init:master
Chad Smith has proposed merging ~chad.smith/cloud-init:bug/1840080-ubuntu-drivers-emit-latelink-v2 into cloud-init:master. Commit message: ubuntu-drivers: call db_x_loadtemplatefile to accept NVIDIA EULA Emit a script allowing cloud-init to set linux/nvidia/latelink debconf selection to true. This avoids having to call debconf-set-selections and allows cloud-init to pre-confgure linux-restricted-modules to link NVIDIA drivers to the running kernel. Cloud-init loads this debconf template and sets the value to true in the debconf database by sourcing debconf's /usr/share/debconf/confmodule and uses db_x_loadtemplatefile to register cloud-init's setting for linux/nvidia/latelink. LP: #1840080 Requested reviews: cloud-init commiters (cloud-init-dev) Related bugs: Bug #1840080 in cloud-init (Ubuntu): "cloud-init cc_ubuntu_drivers does not set up /etc/default/linux-modules-nvidia" https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/1840080 For more details, see: https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/371546 -- Your team cloud-init commiters is requested to review the proposed merge of ~chad.smith/cloud-init:bug/1840080-ubuntu-drivers-emit-latelink-v2 into cloud-init:master. diff --git a/cloudinit/config/cc_ubuntu_drivers.py b/cloudinit/config/cc_ubuntu_drivers.py index 4da34ee..44a2bfe 100644 --- a/cloudinit/config/cc_ubuntu_drivers.py +++ b/cloudinit/config/cc_ubuntu_drivers.py @@ -4,11 +4,11 @@ from textwrap import dedent -from cloudinit.config import cc_apt_configure from cloudinit.config.schema import ( get_schema_doc, validate_cloudconfig_schema) from cloudinit import log as logging from cloudinit.settings import PER_INSTANCE +from cloudinit import temp_utils from cloudinit import type_utils from cloudinit import util @@ -65,6 +65,39 @@ OLD_UBUNTU_DRIVERS_STDERR_NEEDLE = ( __doc__ = get_schema_doc(schema) # Supplement python help() +# debconf template to allow cloud-init pre-configure the global debconf +# variable linux/nvidia/latelink to true, allowing linux-restricted-modules +# to accept the NVIDIA EULA and automatically link drivers to the running +# kernel. +# EOL_XENIAL: can then drop this script and use python3-debconf which is only +# available in Bionic and later. Can't use python3-debconf currently as it +# isn't in Xenial and doesn't yet support X_LOADTEMPLATEFILE debconf command. + +NVIDIA_DRIVER_LATELINK_DEBCONF_TMPL = """\ +#/bin/sh +# Allow cloud-init to trigger EULA acceptance via registering a debconf +# template to set linux/nvidia/latelink true + +. /usr/share/debconf/confmodule + +SCRIPT=$(readlink -f "$0") +DIRNAME=$(dirname "$SCRIPT") +tmpfile=$(mktemp -p ${DIRNAME} -t "cloud-init-ubuntu-drivers-XX.template") +cat > "$tmpfile" << EOF +Template: linux/nvidia/latelink +Type: boolean +Default: true +Description: Late-link NVIDIA kernel modules? + Enable this to link the NVIDIA kernel modules in cloud-init and + make them available for use. +EOF +echo BEFORE $tmpfile +db_x_loadtemplatefile "$tmpfile" cloud-init +echo AFTER $tmpfile +rm "$tmpfile" +""" + + def install_drivers(cfg, pkg_install_func): if not isinstance(cfg, dict): raise TypeError( @@ -90,17 +123,22 @@ def install_drivers(cfg, pkg_install_func): if version_cfg: driver_arg += ':{}'.format(version_cfg) -LOG.debug("Installing NVIDIA drivers (%s=%s, version=%s)", +LOG.debug("Installing and activating NVIDIA drivers (%s=%s, version=%s)", cfgpath, nv_acc, version_cfg if version_cfg else 'latest') -# Setting NVIDIA latelink confirms acceptance of EULA for the package -# linux-restricted-modules -# Reference code defining debconf variable is here -# https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/ -# linux-restricted-modules/+git/eoan/tree/debian/templates/ -# nvidia.templates.in -selections = b'linux-restricted-modules linux/nvidia/latelink boolean true' -cc_apt_configure.debconf_set_selections(selections) +# Register and set debconf selection linux/nvidia/latelink = true +with temp_utils.ExtendedTemporaryFile( +suffix=".sh", needs_exe=True) as tmpf: +try: +tmpf.write(util.encode_text(NVIDIA_DRIVER_LATELINK_DEBCONF_TMPL)) +tmpf.flush() +util.chmod(tmpf.name, 0o755) +util.subp([tmpf.name]) +except Exception as e: +util.logexc( +LOG, +"Failed to register NVIDIA debconf template: %s", str(e)) +raise try: util.subp(['ubuntu-drivers', 'install', '--gpgpu', driver_arg]) diff --git a/cloudinit/config/tests/test_ubuntu_drivers.py b/cloudinit/config/tests/test_ubuntu_drivers.py index 6a763bd..ca44d63 100644 --- a/cloudinit/config/tests/test_ubuntu_drivers.py +++ b/cloudinit/config/tests/test_ubuntu_drivers.py @@ -9,11 +9,20 @@ from cloudinit.config import cc_ubuntu_drivers as drivers from cloudinit.util import
[Cloud-init-dev] [Merge] ~chad.smith/cloud-init:bug/1840080-ubuntu-drivers-emit-latelink into cloud-init:master
Chad Smith has proposed merging ~chad.smith/cloud-init:bug/1840080-ubuntu-drivers-emit-latelink into cloud-init:master. Commit message: ubuntu-drivers: call db_x_loadtemplatefile to accept NVIDIA EULA Emit a script allowing cloud-init to set linux/nvidia/latelink debconf selection to true. This avoids having to call debconf-set-selections and allows cloud-init to pre-confgure linux-restricted-modules to link NVIDIA drivers to the running kernel. Cloud-init loads this debconf template and sets the value to true in the debconf database by sourcing debconf's /usr/share/debconf/confmodule and uses db_x_loadtemplatefile to register cloud-init's setting for linux/nvidia/latelink. LP: #1840080 Requested reviews: cloud-init commiters (cloud-init-dev) Related bugs: Bug #1840080 in cloud-init (Ubuntu): "cloud-init cc_ubuntu_drivers does not set up /etc/default/linux-modules-nvidia" https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/1840080 For more details, see: https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/371545 -- Your team cloud-init commiters is requested to review the proposed merge of ~chad.smith/cloud-init:bug/1840080-ubuntu-drivers-emit-latelink into cloud-init:master. diff --git a/cloudinit/config/cc_ubuntu_drivers.py b/cloudinit/config/cc_ubuntu_drivers.py index 4da34ee..7f52987 100644 --- a/cloudinit/config/cc_ubuntu_drivers.py +++ b/cloudinit/config/cc_ubuntu_drivers.py @@ -9,6 +9,7 @@ from cloudinit.config.schema import ( get_schema_doc, validate_cloudconfig_schema) from cloudinit import log as logging from cloudinit.settings import PER_INSTANCE +from cloudinit import temp_utils from cloudinit import type_utils from cloudinit import util @@ -65,6 +66,39 @@ OLD_UBUNTU_DRIVERS_STDERR_NEEDLE = ( __doc__ = get_schema_doc(schema) # Supplement python help() +# debconf template to allow cloud-init pre-configure the global debconf +# variable linux/nvidia/latelink to true, allowing linux-restricted-modules +# to accept the NVIDIA EULA and automatically link drivers to the running +# kernel. +# EOL_XENIAL: can then drop this script and use python3-debconf which is only +# available in Bionic and later. Can't use python3-debconf currently as it +# isn't in Xenial and doesn't yet support X_LOADTEMPLATEFILE debconf command. + +NVIDIA_DRIVER_LATELINK_DEBCONF_TMPL = """\ +#/bin/sh +# Allow cloud-init to trigger EULA acceptance via registering a debconf +# template to set linux/nvidia/latelink true + +. /usr/share/debconf/confmodule + +SCRIPT=$(readlink -f "$0") +DIRNAME=$(dirname "$SCRIPT") +tmpfile=$(mktemp -p ${DIRNAME} -t "cloud-init-ubuntu-drivers-XX.template") +cat > "$tmpfile" << EOF +Template: linux/nvidia/latelink +Type: boolean +Default: true +Description: Late-link NVIDIA kernel modules? + Enable this to link the NVIDIA kernel modules in cloud-init and + make them available for use. +EOF +echo BEFORE $tmpfile +db_x_loadtemplatefile "$tmpfile" cloud-init +echo AFTER $tmpfile +rm "$tmpfile" +""" + + def install_drivers(cfg, pkg_install_func): if not isinstance(cfg, dict): raise TypeError( @@ -90,9 +124,10 @@ def install_drivers(cfg, pkg_install_func): if version_cfg: driver_arg += ':{}'.format(version_cfg) -LOG.debug("Installing NVIDIA drivers (%s=%s, version=%s)", +LOG.debug("Installing and activating NVIDIA drivers (%s=%s, version=%s)", cfgpath, nv_acc, version_cfg if version_cfg else 'latest') +<<< cloudinit/config/cc_ubuntu_drivers.py # Setting NVIDIA latelink confirms acceptance of EULA for the package # linux-restricted-modules # Reference code defining debconf variable is here @@ -101,6 +136,21 @@ def install_drivers(cfg, pkg_install_func): # nvidia.templates.in selections = b'linux-restricted-modules linux/nvidia/latelink boolean true' cc_apt_configure.debconf_set_selections(selections) +=== +# Register and set debconf selection linux/nvidia/latelink = true +with temp_utils.ExtendedTemporaryFile( +suffix=".sh", needs_exe=True) as tmpf: +try: +tmpf.write(util.encode_text(NVIDIA_DRIVER_LATELINK_DEBCONF_TMPL)) +tmpf.flush() +util.chmod(tmpf.name, 0o755) +util.subp([tmpf.name]) +except Exception as e: +util.logexc( +LOG, +"Failed to register NVIDIA debconf template: %s", str(e)) +raise +>>> cloudinit/config/cc_ubuntu_drivers.py try: util.subp(['ubuntu-drivers', 'install', '--gpgpu', driver_arg]) diff --git a/cloudinit/config/tests/test_ubuntu_drivers.py b/cloudinit/config/tests/test_ubuntu_drivers.py index 6a763bd..c5ee366 100644 --- a/cloudinit/config/tests/test_ubuntu_drivers.py +++ b/cloudinit/config/tests/test_ubuntu_drivers.py @@ -9,11 +9,20 @@ from cloudinit.config import cc_ubuntu_drivers as drivers from cloudinit.util import ProcessExecutionError MPATH = "cloudinit.c