Пример #1
0
    def test_happy_path_taken(
        self,
        m_which,
        m_subp,
        m_tmp,
        m_debconf,
        tmpdir,
        cfg_accepted,
        install_gpgpu,
        true_value,
    ):
        """Positive path test through handle. Package should be installed."""
        new_config: dict = copy.deepcopy(cfg_accepted)
        new_config["drivers"]["nvidia"]["license-accepted"] = true_value

        tdir = tmpdir
        debconf_file = tdir.join("nvidia.template")
        m_tmp.return_value = tdir
        myCloud = mock.MagicMock()
        drivers.handle("ubuntu_drivers", new_config, myCloud, None, None)
        assert [
            mock.call(drivers.X_LOADTEMPLATEFILE, debconf_file)
        ] == m_debconf.DebconfCommunicator().__enter__().command.call_args_list
        assert [
            mock.call(["ubuntu-drivers-common"])
        ] == myCloud.distro.install_packages.call_args_list
        assert [mock.call(install_gpgpu)] == m_subp.call_args_list
Пример #2
0
    def test_handle_raises_error_if_no_drivers_found(
        self,
        m_which,
        m_subp,
        m_tmp,
        m_debconf,
        caplog,
        tmpdir,
        cfg_accepted,
        install_gpgpu,
    ):
        """If ubuntu-drivers doesn't install any drivers, raise an error."""
        tdir = tmpdir
        debconf_file = os.path.join(tdir, "nvidia.template")
        m_tmp.return_value = tdir
        myCloud = mock.MagicMock()

        m_subp.side_effect = ProcessExecutionError(
            stdout="No drivers found for installation.\n", exit_code=1
        )

        with pytest.raises(Exception):
            drivers.handle("ubuntu_drivers", cfg_accepted, myCloud, None, None)
        assert [
            mock.call(drivers.X_LOADTEMPLATEFILE, debconf_file)
        ] == m_debconf.DebconfCommunicator().__enter__().command.call_args_list
        assert [
            mock.call(["ubuntu-drivers-common"])
        ] == myCloud.distro.install_packages.call_args_list
        assert [mock.call(install_gpgpu)] == m_subp.call_args_list
        assert (
            "ubuntu-drivers found no drivers for installation" in caplog.text
        )
    def test_install_drivers_handles_old_ubuntu_drivers_gracefully(
            self, m_which, m_subp, m_tmp):
        """Older ubuntu-drivers versions should emit message and raise error"""
        tdir = self.tmp_dir()
        debconf_file = os.path.join(tdir, "nvidia.template")
        m_tmp.return_value = tdir
        myCloud = mock.MagicMock()

        def fake_subp(cmd):
            if cmd[0].startswith(tdir):
                return
            raise ProcessExecutionError(stderr=OLD_UBUNTU_DRIVERS_ERROR_STDERR,
                                        exit_code=2)

        m_subp.side_effect = fake_subp

        with self.assertRaises(Exception):
            drivers.handle("ubuntu_drivers", self.cfg_accepted, myCloud, None,
                           None)
        self.assertEqual(
            [mock.call(["ubuntu-drivers-common"])],
            myCloud.distro.install_packages.call_args_list,
        )
        self.assertEqual(
            [
                mock.call(AnyTempScriptAndDebconfFile(tdir, debconf_file)),
                mock.call(self.install_gpgpu),
            ],
            m_subp.call_args_list,
        )
        self.assertIn(
            "WARNING: the available version of ubuntu-drivers is"
            " too old to perform requested driver installation",
            self.logs.getvalue(),
        )
    def test_handle_raises_error_if_no_drivers_found(self, m_which, m_subp,
                                                     m_tmp):
        """If ubuntu-drivers doesn't install any drivers, raise an error."""
        tdir = self.tmp_dir()
        debconf_file = os.path.join(tdir, "nvidia.template")
        m_tmp.return_value = tdir
        myCloud = mock.MagicMock()

        def fake_subp(cmd):
            if cmd[0].startswith(tdir):
                return
            raise ProcessExecutionError(
                stdout="No drivers found for installation.\n", exit_code=1)

        m_subp.side_effect = fake_subp

        with self.assertRaises(Exception):
            drivers.handle("ubuntu_drivers", self.cfg_accepted, myCloud, None,
                           None)
        self.assertEqual(
            [mock.call(["ubuntu-drivers-common"])],
            myCloud.distro.install_packages.call_args_list,
        )
        self.assertEqual(
            [
                mock.call(AnyTempScriptAndDebconfFile(tdir, debconf_file)),
                mock.call(self.install_gpgpu),
            ],
            m_subp.call_args_list,
        )
        self.assertIn(
            "ubuntu-drivers found no drivers for installation",
            self.logs.getvalue(),
        )
Пример #5
0
 def test_handle_no_drivers_does_nothing(self, m_install_drivers):
     """If no 'drivers' key in the config, nothing should be done."""
     myCloud = mock.MagicMock()
     myLog = mock.MagicMock()
     drivers.handle('ubuntu_drivers', {'foo': 'bzr'}, myCloud, myLog, None)
     self.assertIn('Skipping module named',
                   myLog.debug.call_args_list[0][0][0])
     self.assertEqual(0, m_install_drivers.call_count)
Пример #6
0
 def _assert_happy_path_taken(self, config, m_which, m_subp):
     """Positive path test through handle. Package should be installed."""
     myCloud = mock.MagicMock()
     drivers.handle('ubuntu_drivers', config, myCloud, None, None)
     self.assertEqual([mock.call(['ubuntu-drivers-common'])],
                      myCloud.distro.install_packages.call_args_list)
     self.assertEqual([mock.call(self.install_gpgpu)],
                      m_subp.call_args_list)
 def test_handle_no_drivers_does_nothing(self, m_install_drivers):
     """If no 'drivers' key in the config, nothing should be done."""
     myCloud = mock.MagicMock()
     myLog = mock.MagicMock()
     drivers.handle("ubuntu_drivers", {"foo": "bzr"}, myCloud, myLog, None)
     self.assertIn("Skipping module named",
                   myLog.debug.call_args_list[0][0][0])
     self.assertEqual(0, m_install_drivers.call_count)
Пример #8
0
 def test_handle_inert(
     self, m_which, m_subp, m_debconf, cfg_accepted, install_gpgpu, config
 ):
     """Helper to reduce repetition when testing negative cases"""
     myCloud = mock.MagicMock()
     drivers.handle("ubuntu_drivers", config, myCloud, None, None)
     assert 0 == myCloud.distro.install_packages.call_count
     assert 0 == m_subp.call_count
Пример #9
0
 def _assert_happy_path_taken(self, config, m_which, m_subp):
     """Positive path test through handle. Package should be installed."""
     myCloud = mock.MagicMock()
     drivers.handle('ubuntu_drivers', config, myCloud, None, None)
     self.assertEqual([mock.call(['ubuntu-drivers-common'])],
                      myCloud.distro.install_packages.call_args_list)
     self.assertEqual([mock.call(self.install_gpgpu)],
                      m_subp.call_args_list)
Пример #10
0
 def test_version_none_uses_latest(self, m_which, m_subp):
     myCloud = mock.MagicMock()
     version_none_cfg = {
         'drivers': {'nvidia': {'license-accepted': True, 'version': None}}}
     drivers.handle(
         'ubuntu_drivers', version_none_cfg, myCloud, None, None)
     self.assertEqual(
         [mock.call(['ubuntu-drivers', 'install', '--gpgpu', 'nvidia'])],
         m_subp.call_args_list)
Пример #11
0
 def test_handle_no_drivers_does_nothing(
     self, m_install_drivers, m_debconf, cfg_accepted, install_gpgpu
 ):
     """If no 'drivers' key in the config, nothing should be done."""
     myCloud = mock.MagicMock()
     myLog = mock.MagicMock()
     drivers.handle("ubuntu_drivers", {"foo": "bzr"}, myCloud, myLog, None)
     assert "Skipping module named" in myLog.debug.call_args_list[0][0][0]
     assert 0 == m_install_drivers.call_count
Пример #12
0
 def test_handle_raises_error_if_no_drivers_found(self, m_which, m_subp):
     """If ubuntu-drivers doesn't install any drivers, raise an error."""
     myCloud = mock.MagicMock()
     with self.assertRaises(Exception):
         drivers.handle('ubuntu_drivers', self.cfg_accepted, myCloud, None,
                        None)
     self.assertEqual([mock.call(['ubuntu-drivers-common'])],
                      myCloud.distro.install_packages.call_args_list)
     self.assertEqual([mock.call(self.install_gpgpu)],
                      m_subp.call_args_list)
     self.assertIn('ubuntu-drivers found no drivers for installation',
                   self.logs.getvalue())
Пример #13
0
 def test_handle_raises_error_if_no_drivers_found(self, m_which, m_subp):
     """If ubuntu-drivers doesn't install any drivers, raise an error."""
     myCloud = mock.MagicMock()
     with self.assertRaises(Exception):
         drivers.handle(
             'ubuntu_drivers', self.cfg_accepted, myCloud, None, None)
     self.assertEqual([mock.call(['ubuntu-drivers-common'])],
                      myCloud.distro.install_packages.call_args_list)
     self.assertEqual([mock.call(self.install_gpgpu)],
                      m_subp.call_args_list)
     self.assertIn('ubuntu-drivers found no drivers for installation',
                   self.logs.getvalue())
Пример #14
0
 def _assert_happy_path_taken(self, config, m_which, m_subp, m_tmp):
     """Positive path test through handle. Package should be installed."""
     tdir = self.tmp_dir()
     debconf_file = os.path.join(tdir, 'nvidia.template')
     m_tmp.return_value = tdir
     myCloud = mock.MagicMock()
     drivers.handle('ubuntu_drivers', config, myCloud, None, None)
     self.assertEqual([mock.call(['ubuntu-drivers-common'])],
                      myCloud.distro.install_packages.call_args_list)
     self.assertEqual([
         mock.call(AnyTempScriptAndDebconfFile(tdir, debconf_file)),
         mock.call(self.install_gpgpu)
     ], m_subp.call_args_list)
Пример #15
0
 def test_version_none_uses_latest(self, m_which, m_subp, m_tmp):
     tdir = self.tmp_dir()
     debconf_file = os.path.join(tdir, 'nvidia.template')
     m_tmp.return_value = tdir
     myCloud = mock.MagicMock()
     version_none_cfg = {
         'drivers': {'nvidia': {'license-accepted': True, 'version': None}}}
     drivers.handle(
         'ubuntu_drivers', version_none_cfg, myCloud, None, None)
     self.assertEqual(
         [mock.call(AnyTempScriptAndDebconfFile(tdir, debconf_file)),
          mock.call(['ubuntu-drivers', 'install', '--gpgpu', 'nvidia'])],
         m_subp.call_args_list)
Пример #16
0
 def test_install_drivers_handles_old_ubuntu_drivers_gracefully(
         self, m_which, m_subp):
     """Older ubuntu-drivers versions should emit message and raise error"""
     myCloud = mock.MagicMock()
     with self.assertRaises(Exception):
         drivers.handle(
             'ubuntu_drivers', self.cfg_accepted, myCloud, None, None)
     self.assertEqual([mock.call(['ubuntu-drivers-common'])],
                      myCloud.distro.install_packages.call_args_list)
     self.assertEqual([mock.call(self.install_gpgpu)],
                      m_subp.call_args_list)
     self.assertIn('WARNING: the available version of ubuntu-drivers is'
                   ' too old to perform requested driver installation',
                   self.logs.getvalue())
Пример #17
0
 def test_version_none_uses_latest(self, m_which, m_subp):
     myCloud = mock.MagicMock()
     version_none_cfg = {
         'drivers': {
             'nvidia': {
                 'license-accepted': True,
                 'version': None
             }
         }
     }
     drivers.handle('ubuntu_drivers', version_none_cfg, myCloud, None, None)
     self.assertEqual(
         [mock.call(['ubuntu-drivers', 'install', '--gpgpu', 'nvidia'])],
         m_subp.call_args_list)
Пример #18
0
 def test_install_drivers_handles_old_ubuntu_drivers_gracefully(
         self, m_which, m_subp):
     """Older ubuntu-drivers versions should emit message and raise error"""
     myCloud = mock.MagicMock()
     with self.assertRaises(Exception):
         drivers.handle('ubuntu_drivers', self.cfg_accepted, myCloud, None,
                        None)
     self.assertEqual([mock.call(['ubuntu-drivers-common'])],
                      myCloud.distro.install_packages.call_args_list)
     self.assertEqual([mock.call(self.install_gpgpu)],
                      m_subp.call_args_list)
     self.assertIn(
         'WARNING: the available version of ubuntu-drivers is'
         ' too old to perform requested driver installation',
         self.logs.getvalue())
Пример #19
0
 def test_version_none_uses_latest(
     self, m_which, m_subp, m_tmp, m_debconf, tmpdir
 ):
     debconf_file = tmpdir.join("nvidia.template")
     m_tmp.return_value = tmpdir
     myCloud = mock.MagicMock()
     version_none_cfg = {
         "drivers": {"nvidia": {"license-accepted": True, "version": None}}
     }
     drivers.handle("ubuntu_drivers", version_none_cfg, myCloud, None, None)
     assert [
         mock.call(drivers.X_LOADTEMPLATEFILE, debconf_file)
     ] == m_debconf.DebconfCommunicator().__enter__().command.call_args_list
     assert [
         mock.call(["ubuntu-drivers", "install", "--gpgpu", "nvidia"]),
     ] == m_subp.call_args_list
 def test_version_none_uses_latest(self, m_which, m_subp, m_tmp):
     tdir = self.tmp_dir()
     debconf_file = os.path.join(tdir, "nvidia.template")
     m_tmp.return_value = tdir
     myCloud = mock.MagicMock()
     version_none_cfg = {
         "drivers": {
             "nvidia": {
                 "license-accepted": True,
                 "version": None
             }
         }
     }
     drivers.handle("ubuntu_drivers", version_none_cfg, myCloud, None, None)
     self.assertEqual(
         [
             mock.call(AnyTempScriptAndDebconfFile(tdir, debconf_file)),
             mock.call(["ubuntu-drivers", "install", "--gpgpu", "nvidia"]),
         ],
         m_subp.call_args_list,
     )
Пример #21
0
 def test_no_cfg_drivers_does_nothing(
     self,
     m_install_drivers,
     m_tmp,
     m_debconf,
     tmpdir,
 ):
     m_tmp.return_value = tmpdir
     m_log = mock.MagicMock()
     myCloud = mock.MagicMock()
     version_none_cfg = {}
     drivers.handle(
         "ubuntu_drivers", version_none_cfg, myCloud, m_log, None
     )
     assert 0 == m_install_drivers.call_count
     assert (
         mock.call(
             "Skipping module named %s, no 'drivers' key in config",
             "ubuntu_drivers",
         )
         == m_log.debug.call_args_list[-1]
     )
Пример #22
0
 def test_has_not_debconf_does_nothing(
     self,
     m_install_drivers,
     m_tmp,
     m_debconf,
     tmpdir,
 ):
     m_tmp.return_value = tmpdir
     m_log = mock.MagicMock()
     myCloud = mock.MagicMock()
     version_none_cfg = {"drivers": {"nvidia": {"license-accepted": True}}}
     drivers.handle(
         "ubuntu_drivers", version_none_cfg, myCloud, m_log, None
     )
     assert 0 == m_install_drivers.call_count
     assert (
         mock.call(
             "Skipping module named %s, 'python3-debconf' is not installed",
             "ubuntu_drivers",
         )
         == m_log.warning.call_args_list[-1]
     )
Пример #23
0
    def test_install_drivers_handles_old_ubuntu_drivers_gracefully(
        self,
        m_which,
        m_subp,
        m_tmp,
        m_debconf,
        caplog,
        tmpdir,
        cfg_accepted,
        install_gpgpu,
    ):
        """Older ubuntu-drivers versions should emit message and raise error"""
        debconf_file = tmpdir.join("nvidia.template")
        m_tmp.return_value = tmpdir
        myCloud = mock.MagicMock()

        m_subp.side_effect = ProcessExecutionError(
            stderr=OLD_UBUNTU_DRIVERS_ERROR_STDERR, exit_code=2
        )

        with pytest.raises(Exception):
            drivers.handle("ubuntu_drivers", cfg_accepted, myCloud, None, None)
        assert [
            mock.call(drivers.X_LOADTEMPLATEFILE, debconf_file)
        ] == m_debconf.DebconfCommunicator().__enter__().command.call_args_list
        assert [
            mock.call(["ubuntu-drivers-common"])
        ] == myCloud.distro.install_packages.call_args_list
        assert [mock.call(install_gpgpu)] == m_subp.call_args_list
        assert (
            MPATH[:-1],
            log.WARNING,
            (
                "the available version of ubuntu-drivers is"
                " too old to perform requested driver installation"
            ),
        ) == caplog.record_tuples[-1]
Пример #24
0
 def test_debconf_not_installed_does_nothing(
     self,
     m_which,
     m_subp,
     m_tmp,
     m_debconf,
     tmpdir,
     cfg_accepted,
     install_gpgpu,
 ):
     m_debconf.DebconfCommunicator.side_effect = AttributeError
     m_tmp.return_value = tmpdir
     myCloud = mock.MagicMock()
     version_none_cfg = {
         "drivers": {"nvidia": {"license-accepted": True, "version": None}}
     }
     with pytest.raises(AttributeError):
         drivers.handle(
             "ubuntu_drivers", version_none_cfg, myCloud, None, None
         )
     assert (
         0 == m_debconf.DebconfCommunicator.__enter__().command.call_count
     )
     assert 0 == m_subp.call_count
 def _assert_inert_with_config(self, config, m_which, m_subp):
     """Helper to reduce repetition when testing negative cases"""
     myCloud = mock.MagicMock()
     drivers.handle("ubuntu_drivers", config, myCloud, None, None)
     self.assertEqual(0, myCloud.distro.install_packages.call_count)
     self.assertEqual(0, m_subp.call_count)
Пример #26
0
 def _assert_inert_with_config(self, config, m_which, m_subp):
     """Helper to reduce repetition when testing negative cases"""
     myCloud = mock.MagicMock()
     drivers.handle('ubuntu_drivers', config, myCloud, None, None)
     self.assertEqual(0, myCloud.distro.install_packages.call_count)
     self.assertEqual(0, m_subp.call_count)