Exemple #1
0
 def test_maybe_install_ua_tools_noop_when_ua_tools_present(self, m_which):
     """Do nothing if ubuntu-advantage-tools already exists."""
     m_which.return_value = '/usr/bin/ua'  # already installed
     distro = mock.MagicMock()
     distro.update_package_sources.side_effect = RuntimeError(
         'Some apt error')
     maybe_install_ua_tools(cloud=FakeCloud(distro))  # No RuntimeError
 def test_maybe_install_ua_tools_noop_when_ua_tools_present(self, m_which):
     """Do nothing if ubuntu-advantage-tools already exists."""
     m_which.return_value = '/usr/bin/ua'  # already installed
     distro = mock.MagicMock()
     distro.update_package_sources.side_effect = RuntimeError(
         'Some apt error')
     maybe_install_ua_tools(cloud=FakeCloud(distro))  # No RuntimeError
Exemple #3
0
 def test_maybe_install_ua_tools_happy_path(self, m_which):
     """maybe_install_ua_tools installs ubuntu-advantage-tools."""
     m_which.return_value = None
     distro = mock.MagicMock()  # No errors raised
     maybe_install_ua_tools(cloud=FakeCloud(distro))
     distro.update_package_sources.assert_called_once_with()
     distro.install_packages.assert_called_once_with(
         ['ubuntu-advantage-tools'])
 def test_maybe_install_ua_tools_happy_path(self, m_which):
     """maybe_install_ua_tools installs ubuntu-advantage-tools."""
     m_which.return_value = None
     distro = mock.MagicMock()  # No errors raised
     maybe_install_ua_tools(cloud=FakeCloud(distro))
     distro.update_package_sources.assert_called_once_with()
     distro.install_packages.assert_called_once_with(
         ['ubuntu-advantage-tools'])
Exemple #5
0
 def test_maybe_install_ua_tools_raises_update_errors(self, m_which):
     """maybe_install_ua_tools logs and raises apt update errors."""
     m_which.return_value = None
     distro = mock.MagicMock()
     distro.update_package_sources.side_effect = RuntimeError(
         'Some apt error')
     with self.assertRaises(RuntimeError) as context_manager:
         maybe_install_ua_tools(cloud=FakeCloud(distro))
     self.assertEqual('Some apt error', str(context_manager.exception))
     self.assertIn('Package update failed\nTraceback', self.logs.getvalue())
 def test_maybe_install_ua_tools_raises_update_errors(self, m_which):
     """maybe_install_ua_tools logs and raises apt update errors."""
     m_which.return_value = None
     distro = mock.MagicMock()
     distro.update_package_sources.side_effect = RuntimeError(
         'Some apt error')
     with self.assertRaises(RuntimeError) as context_manager:
         maybe_install_ua_tools(cloud=FakeCloud(distro))
     self.assertEqual('Some apt error', str(context_manager.exception))
     self.assertIn('Package update failed\nTraceback', self.logs.getvalue())
Exemple #7
0
 def test_maybe_install_ua_raises_install_errors(self, m_which):
     """maybe_install_ua_tools logs and raises package install errors."""
     m_which.return_value = None
     distro = mock.MagicMock()
     distro.update_package_sources.return_value = None
     distro.install_packages.side_effect = RuntimeError(
         'Some install error')
     with self.assertRaises(RuntimeError) as context_manager:
         maybe_install_ua_tools(cloud=FakeCloud(distro))
     self.assertEqual('Some install error', str(context_manager.exception))
     self.assertIn('Failed to install ubuntu-advantage-tools\n',
                   self.logs.getvalue())
 def test_maybe_install_ua_raises_install_errors(self, m_which):
     """maybe_install_ua_tools logs and raises package install errors."""
     m_which.return_value = None
     distro = mock.MagicMock()
     distro.update_package_sources.return_value = None
     distro.install_packages.side_effect = RuntimeError(
         'Some install error')
     with self.assertRaises(RuntimeError) as context_manager:
         maybe_install_ua_tools(cloud=FakeCloud(distro))
     self.assertEqual('Some install error', str(context_manager.exception))
     self.assertIn(
         'Failed to install ubuntu-advantage-tools\n', self.logs.getvalue())