Example #1
0
 def test_configure_ua_attach_with_empty_services(self, m_subp):
     """When services is an empty list, do not auto-enable attach."""
     configure_ua(token='SomeToken', enable=[])
     m_subp.assert_called_once_with(['ua', 'attach', 'SomeToken'])
     self.assertEqual(
         'DEBUG: Attaching to Ubuntu Advantage. ua attach SomeToken\n',
         self.logs.getvalue())
Example #2
0
    def test_configure_ua_attach_on_service_error(self, m_subp):
        """all services should be enabled and then any failures raised"""
        def fake_subp(cmd, capture=None):
            fail_cmds = [['ua', 'enable', svc] for svc in ['esm', 'cc']]
            if cmd in fail_cmds and capture:
                svc = cmd[-1]
                raise util.ProcessExecutionError(
                    'Invalid {} credentials'.format(svc.upper()))

        m_subp.side_effect = fake_subp

        with self.assertRaises(RuntimeError) as context_manager:
            configure_ua(token='SomeToken', enable=['esm', 'cc', 'fips'])
        self.assertEqual(m_subp.call_args_list, [
            mock.call(['ua', 'attach', 'SomeToken']),
            mock.call(['ua', 'enable', 'esm'], capture=True),
            mock.call(['ua', 'enable', 'cc'], capture=True),
            mock.call(['ua', 'enable', 'fips'], capture=True)
        ])
        self.assertIn(
            'WARNING: Failure enabling "esm":\nUnexpected error'
            ' while running command.\nCommand: -\nExit code: -\nReason: -\n'
            'Stdout: Invalid ESM credentials\nStderr: -\n',
            self.logs.getvalue())
        self.assertIn(
            'WARNING: Failure enabling "cc":\nUnexpected error'
            ' while running command.\nCommand: -\nExit code: -\nReason: -\n'
            'Stdout: Invalid CC credentials\nStderr: -\n',
            self.logs.getvalue())
        self.assertEqual(
            'Failure enabling Ubuntu Advantage service(s): "esm", "cc"',
            str(context_manager.exception))
 def test_configure_ua_attach_with_empty_services(self, m_subp):
     """When services is an empty list, do not auto-enable attach."""
     configure_ua(token='SomeToken', enable=[])
     m_subp.assert_called_once_with(['ua', 'attach', 'SomeToken'])
     self.assertEqual(
         'DEBUG: Attaching to Ubuntu Advantage. ua attach SomeToken\n',
         self.logs.getvalue())
    def test_configure_ua_attach_on_service_error(self, m_subp):
        """all services should be enabled and then any failures raised"""

        def fake_subp(cmd, capture=None):
            fail_cmds = [['ua', 'enable', svc] for svc in ['esm', 'cc']]
            if cmd in fail_cmds and capture:
                svc = cmd[-1]
                raise util.ProcessExecutionError(
                    'Invalid {} credentials'.format(svc.upper()))

        m_subp.side_effect = fake_subp

        with self.assertRaises(RuntimeError) as context_manager:
            configure_ua(token='SomeToken', enable=['esm', 'cc', 'fips'])
        self.assertEqual(
            m_subp.call_args_list,
            [mock.call(['ua', 'attach', 'SomeToken']),
             mock.call(['ua', 'enable', 'esm'], capture=True),
             mock.call(['ua', 'enable', 'cc'], capture=True),
             mock.call(['ua', 'enable', 'fips'], capture=True)])
        self.assertIn(
            'WARNING: Failure enabling "esm":\nUnexpected error'
            ' while running command.\nCommand: -\nExit code: -\nReason: -\n'
            'Stdout: Invalid ESM credentials\nStderr: -\n',
            self.logs.getvalue())
        self.assertIn(
            'WARNING: Failure enabling "cc":\nUnexpected error'
            ' while running command.\nCommand: -\nExit code: -\nReason: -\n'
            'Stdout: Invalid CC credentials\nStderr: -\n',
            self.logs.getvalue())
        self.assertEqual(
            'Failure enabling Ubuntu Advantage service(s): "esm", "cc"',
            str(context_manager.exception))
 def test_configure_ua_attach_with_token(self, m_subp):
     """When token is provided, attach the machine to ua using the token."""
     configure_ua(token='SomeToken')
     m_subp.assert_called_once_with(['ua', 'attach', 'SomeToken'])
     self.assertEqual(
         'DEBUG: Attaching to Ubuntu Advantage. ua attach SomeToken\n',
         self.logs.getvalue())
Example #6
0
 def test_configure_ua_attach_with_token(self, m_subp):
     """When token is provided, attach the machine to ua using the token."""
     configure_ua(token='SomeToken')
     m_subp.assert_called_once_with(['ua', 'attach', 'SomeToken'])
     self.assertEqual(
         'DEBUG: Attaching to Ubuntu Advantage. ua attach SomeToken\n',
         self.logs.getvalue())
 def test_configure_ua_attach_with_token(self, m_subp):
     """When token is provided, attach the machine to ua using the token."""
     configure_ua(token="SomeToken")
     m_subp.assert_called_once_with(["ua", "attach", "SomeToken"])
     self.assertEqual(
         "DEBUG: Attaching to Ubuntu Advantage. ua attach SomeToken\n",
         self.logs.getvalue(),
     )
Example #8
0
 def test_configure_ua_attach_with_weird_services(self, m_subp):
     """When services not string or list, warn but still attach"""
     configure_ua(token='SomeToken', enable={'deffo': 'wont work'})
     self.assertEqual(m_subp.call_args_list,
                      [mock.call(['ua', 'attach', 'SomeToken'])])
     self.assertEqual(
         'WARNING: ubuntu_advantage: enable should be a list, not a'
         ' dict; skipping enabling services\n'
         'DEBUG: Attaching to Ubuntu Advantage. ua attach SomeToken\n',
         self.logs.getvalue())
 def test_configure_ua_attach_with_specific_services(self, m_subp):
     """When services a list, only enable specific services."""
     configure_ua(token='SomeToken', enable=['fips'])
     self.assertEqual(
         m_subp.call_args_list,
         [mock.call(['ua', 'attach', 'SomeToken']),
          mock.call(['ua', 'enable', 'fips'], capture=True)])
     self.assertEqual(
         'DEBUG: Attaching to Ubuntu Advantage. ua attach SomeToken\n',
         self.logs.getvalue())
Example #10
0
 def test_configure_ua_attach_with_specific_services(self, m_subp):
     """When services a list, only enable specific services."""
     configure_ua(token='SomeToken', enable=['fips'])
     self.assertEqual(m_subp.call_args_list, [
         mock.call(['ua', 'attach', 'SomeToken']),
         mock.call(['ua', 'enable', 'fips'], capture=True)
     ])
     self.assertEqual(
         'DEBUG: Attaching to Ubuntu Advantage. ua attach SomeToken\n',
         self.logs.getvalue())
Example #11
0
 def test_configure_ua_attach_error(self, m_subp):
     """Errors from ua attach command are raised."""
     m_subp.side_effect = util.ProcessExecutionError(
         'Invalid token SomeToken')
     with self.assertRaises(RuntimeError) as context_manager:
         configure_ua(token='SomeToken')
     self.assertEqual(
         'Failure attaching Ubuntu Advantage:\nUnexpected error while'
         ' running command.\nCommand: -\nExit code: -\nReason: -\n'
         'Stdout: Invalid token SomeToken\nStderr: -',
         str(context_manager.exception))
 def test_configure_ua_attach_with_weird_services(self, m_subp):
     """When services not string or list, warn but still attach"""
     configure_ua(token="SomeToken", enable={"deffo": "wont work"})
     self.assertEqual(m_subp.call_args_list,
                      [mock.call(["ua", "attach", "SomeToken"])])
     self.assertEqual(
         "WARNING: ubuntu_advantage: enable should be a list, not a"
         " dict; skipping enabling services\n"
         "DEBUG: Attaching to Ubuntu Advantage. ua attach SomeToken\n",
         self.logs.getvalue(),
     )
 def test_configure_ua_attach_with_weird_services(self, m_subp):
     """When services not string or list, warn but still attach"""
     configure_ua(token='SomeToken', enable={'deffo': 'wont work'})
     self.assertEqual(
         m_subp.call_args_list,
         [mock.call(['ua', 'attach', 'SomeToken'])])
     self.assertEqual(
         'WARNING: ubuntu_advantage: enable should be a list, not a'
         ' dict; skipping enabling services\n'
         'DEBUG: Attaching to Ubuntu Advantage. ua attach SomeToken\n',
         self.logs.getvalue())
 def test_configure_ua_attach_error(self, m_subp):
     """Errors from ua attach command are raised."""
     m_subp.side_effect = util.ProcessExecutionError(
         'Invalid token SomeToken')
     with self.assertRaises(RuntimeError) as context_manager:
         configure_ua(token='SomeToken')
     self.assertEqual(
         'Failure attaching Ubuntu Advantage:\nUnexpected error while'
         ' running command.\nCommand: -\nExit code: -\nReason: -\n'
         'Stdout: Invalid token SomeToken\nStderr: -',
         str(context_manager.exception))
Example #15
0
 def test_configure_ua_attach_with_string_services(self, m_subp):
     """When services a string, treat as singleton list and warn"""
     configure_ua(token='SomeToken', enable='fips')
     self.assertEqual(m_subp.call_args_list, [
         mock.call(['ua', 'attach', 'SomeToken']),
         mock.call(['ua', 'enable', 'fips'], capture=True)
     ])
     self.assertEqual(
         'WARNING: ubuntu_advantage: enable should be a list, not a'
         ' string; treating as a single enable\n'
         'DEBUG: Attaching to Ubuntu Advantage. ua attach SomeToken\n',
         self.logs.getvalue())
 def test_configure_ua_attach_with_string_services(self, m_subp):
     """When services a string, treat as singleton list and warn"""
     configure_ua(token='SomeToken', enable='fips')
     self.assertEqual(
         m_subp.call_args_list,
         [mock.call(['ua', 'attach', 'SomeToken']),
          mock.call(['ua', 'enable', 'fips'], capture=True)])
     self.assertEqual(
         'WARNING: ubuntu_advantage: enable should be a list, not a'
         ' string; treating as a single enable\n'
         'DEBUG: Attaching to Ubuntu Advantage. ua attach SomeToken\n',
         self.logs.getvalue())
 def test_configure_ua_attach_with_specific_services(self, m_subp):
     """When services a list, only enable specific services."""
     configure_ua(token="SomeToken", enable=["fips"])
     self.assertEqual(
         m_subp.call_args_list,
         [
             mock.call(["ua", "attach", "SomeToken"]),
             mock.call(["ua", "enable", "fips"], capture=True),
         ],
     )
     self.assertEqual(
         "DEBUG: Attaching to Ubuntu Advantage. ua attach SomeToken\n",
         self.logs.getvalue(),
     )
 def test_configure_ua_attach_with_string_services(self, m_subp):
     """When services a string, treat as singleton list and warn"""
     configure_ua(token="SomeToken", enable="fips")
     self.assertEqual(
         m_subp.call_args_list,
         [
             mock.call(["ua", "attach", "SomeToken"]),
             mock.call(["ua", "enable", "fips"], capture=True),
         ],
     )
     self.assertEqual(
         "WARNING: ubuntu_advantage: enable should be a list, not a"
         " string; treating as a single enable\n"
         "DEBUG: Attaching to Ubuntu Advantage. ua attach SomeToken\n",
         self.logs.getvalue(),
     )
Example #19
0
    def test_configure_ua_attach_on_service_error(self, m_subp):
        """all services should be enabled and then any failures raised"""
        def fake_subp(cmd, capture=None):
            fail_cmds = [["ua", "enable", "--assume-yes", svc]
                         for svc in ["esm", "cc"]]
            if cmd in fail_cmds and capture:
                svc = cmd[-1]
                raise subp.ProcessExecutionError(
                    "Invalid {} credentials".format(svc.upper()))

        m_subp.side_effect = fake_subp

        with self.assertRaises(RuntimeError) as context_manager:
            configure_ua(token="SomeToken", enable=["esm", "cc", "fips"])
        self.assertEqual(
            m_subp.call_args_list,
            [
                mock.call(["ua", "attach", "SomeToken"]),
                mock.call(["ua", "enable", "--assume-yes", "esm"],
                          capture=True),
                mock.call(["ua", "enable", "--assume-yes", "cc"],
                          capture=True),
                mock.call(["ua", "enable", "--assume-yes", "fips"],
                          capture=True),
            ],
        )
        self.assertIn(
            'WARNING: Failure enabling "esm":\nUnexpected error'
            " while running command.\nCommand: -\nExit code: -\nReason: -\n"
            "Stdout: Invalid ESM credentials\nStderr: -\n",
            self.logs.getvalue(),
        )
        self.assertIn(
            'WARNING: Failure enabling "cc":\nUnexpected error'
            " while running command.\nCommand: -\nExit code: -\nReason: -\n"
            "Stdout: Invalid CC credentials\nStderr: -\n",
            self.logs.getvalue(),
        )
        self.assertEqual(
            'Failure enabling Ubuntu Advantage service(s): "esm", "cc"',
            str(context_manager.exception),
        )