Exemple #1
0
    def test_create_log_tarfile_copies_configured_logs(self):
        """create_log_tarfile copies configured log_file and post_files.

        Configured log_file or post_files which don't exist are ignored.
        """
        tarfile = self.tmp_path('my.tar', _dir=self.new_root)
        log1 = self.tmp_path('some.log', _dir=self.new_root)
        write_file(log1, 'log content')
        log2 = self.tmp_path('log2.log', _dir=self.new_root)
        write_file(log2, 'log2 content')
        absent_log = self.tmp_path('log3.log', _dir=self.new_root)
        config = {
            'install': {
                'log_file': log1,
                'post_files': [log2, absent_log]
            }
        }
        self.add_patch('shutil.copy', 'm_copy')
        with mock.patch('sys.stderr') as m_stderr:
            with mock.patch('curtin.commands.collect_logs.datetime') as m_dt:
                m_dt.utcnow.return_value = self.utcnow
                collect_logs.create_log_tarfile(tarfile, config=config)
        self.assertIn(
            mock.call('Skipping logfile %s: file does not exist\n' %
                      absent_log), m_stderr.write.call_args_list)
        self.assertIn(mock.call(log1, self.tardir), self.m_copy.call_args_list)
        self.assertIn(mock.call(log2, self.tardir), self.m_copy.call_args_list)
        self.assertNotIn(mock.call(absent_log, self.tardir),
                         self.m_copy.call_args_list)
Exemple #2
0
 def test_create_log_tarfile_stores_logs_in_dated_subdirectory(self):
     """create_log_tarfile creates a dated subdir in the created tarfile."""
     tarfile = self.tmp_path('my.tar', _dir=self.new_root)
     self.add_patch('curtin.util.subp', 'mock_subp')
     self.mock_subp.return_value = ('', '')
     with mock.patch('sys.stderr'):
         with mock.patch('curtin.commands.collect_logs.datetime') as m_dt:
             m_dt.utcnow.return_value = self.utcnow
             collect_logs.create_log_tarfile(tarfile, config={})
     self.assertIn(
         mock.call(['tar', '-cvf', tarfile, self.tardir], capture=True),
         self.mock_subp.call_args_list)
     self.m_sys_info.assert_called_with(self.tardir, {})
Exemple #3
0
 def test_create_log_tarfile_creates_target_tar_directory_if_absent(self):
     """create_log_tarfile makes the tarfile's directory if needed."""
     tarfile = self.tmp_path('my.tar',
                             _dir=os.path.join(self.new_root, 'dont/exist'))
     destination_dir = os.path.dirname(tarfile)
     self.assertFalse(os.path.exists(destination_dir),
                      'Expected absent directory: %s' % destination_dir)
     self.add_patch('curtin.util.subp', 'mock_subp')
     self.mock_subp.return_value = ('', '')
     with mock.patch('sys.stderr'):
         with mock.patch('curtin.commands.collect_logs.datetime') as m_dt:
             m_dt.utcnow.return_value = self.utcnow
             collect_logs.create_log_tarfile(tarfile, config={})
     self.assertIn(
         mock.call(['tar', '-cvf', tarfile, self.tardir], capture=True),
         self.mock_subp.call_args_list)
     self.m_sys_info.assert_called_with(self.tardir, {})
     self.assertTrue(os.path.exists(destination_dir),
                     'Expected directory created: %s' % destination_dir)
Exemple #4
0
 def test_create_log_tarfile_redacts_maas_credentials(self):
     """create_log_tarfile redacts sensitive maas credentials configured."""
     tarfile = self.tmp_path('my.tar', _dir=self.new_root)
     self.add_patch(
         'curtin.commands.collect_logs._redact_sensitive_information',
         'm_redact')
     config = {
         'install': {
             'maas': {
                 'consumer_key': 'ckey',
                 'token_key': 'tkey',
                 'token_secret': 'tsecret'
             }
         }
     }
     with mock.patch('sys.stderr'):
         with mock.patch('curtin.commands.collect_logs.datetime') as m_dt:
             m_dt.utcnow.return_value = self.utcnow
             collect_logs.create_log_tarfile(tarfile, config=config)
     self.assertEqual([mock.call(self.tardir, ['ckey', 'tkey', 'tsecret'])],
                      self.m_redact.call_args_list)
     self.m_sys_info.assert_called_with(self.tardir, config)