def test_collect(self):
     """test node information collection.
     """
     archive_path = os.path.join(self.tmroot, 'postmortem',
                                 'archive.tar.gz')
     with tarfile.open(archive_path, 'w:gz') as archive:
         postmortem.collect(self.tmroot, archive, 'treadmill')
     with tarfile.open(archive_path, 'r:gz') as archive:
         listing = archive.getnames()
         self.assertTrue([
             path for path in listing
             if path.endswith('init/server_init/log/current')
         ])
         if os.name == 'posix':
             self.assertIn('diag/sysctl#-a', listing)
Example #2
0
    def test_collect_init_services(self):
        """test node information collection.
        """
        # XXX(boysson): Should be all os.path.join below
        archive_file = '%s/archive.tar' % self.archive_root
        real_file = postmortem.collect(self.tmroot, archive_file)
        self.assertEquals(real_file, '%s/archive.tar.gz' % self.archive_root)

        shutil.copyfile.assert_any_call(
            '%s/init/server_init/log/current' % self.tmroot,
            '%s%s/init/server_init/log/current' % (self.tmp_dir, self.tmroot))
        shutil.copyfile.assert_any_call(
            '%s/running/foo/sys/bar/log/current' % self.tmroot,
            '%s%s/running/foo/sys/bar/log/current' %
            (self.tmp_dir, self.tmroot))

        subproc.check_output.assert_any_call(['sysctl', '-a'])
        subproc.check_output.assert_any_call(
            ['tail', '-n', '100', '/var/log/messages'])
        subproc.check_output.assert_any_call(['dmesg'])
        subproc.check_output.assert_any_call(['ifconfig'])

        shutil.copytree.assert_any_call(
            '%s/network_svc' % self.tmroot,
            '%s%s/network_svc' % (self.tmp_dir, self.tmroot))
        shutil.copytree.assert_any_call(
            '%s/cgroup_svc' % self.tmroot,
            '%s%s/cgroup_svc' % (self.tmp_dir, self.tmroot))
        shutil.copytree.assert_any_call(
            '%s/localdisk_svc' % self.tmroot,
            '%s%s/localdisk_svc' % (self.tmp_dir, self.tmroot))
Example #3
0
    def test_collect_init_services(self):
        """test node information collection.
        """
        # XXX(boysson): Should be all os.path.join below
        archive_file = os.path.join(self.archive_root, 'archive.tar')
        real_file = postmortem.collect(self.tmroot, archive_file)
        self.assertEqual(real_file,
                         os.path.join(self.archive_root, 'archive.tar.gz'))

        path = os.path.splitdrive(
            os.path.join(self.tmroot, self.service_log_current))[1]
        shutil.copyfile.assert_any_call(
            os.path.join(self.tmroot, self.service_log_current),
            '%s%s' % (self.tmp_dir, path))

        if sys.platform.startswith('linux'):
            subproc.check_output.assert_any_call(['sysctl', '-a'])
            subproc.check_output.assert_any_call(
                ['tail', '-n', '100', '/var/log/messages'])
            subproc.check_output.assert_any_call(['dmesg'])
            subproc.check_output.assert_any_call(['ifconfig'])

            shutil.copytree.assert_any_call(
                '%s/network_svc' % self.tmroot,
                '%s%s/network_svc' % (self.tmp_dir, self.tmroot))
            shutil.copytree.assert_any_call(
                '%s/cgroup_svc' % self.tmroot,
                '%s%s/cgroup_svc' % (self.tmp_dir, self.tmroot))
            shutil.copytree.assert_any_call(
                '%s/localdisk_svc' % self.tmroot,
                '%s%s/localdisk_svc' % (self.tmp_dir, self.tmroot))
Example #4
0
    def collect(install_dir, upload_script, upload_args):
        """Collect Treadmill node data"""

        filetime = utils.datetime_utcnow().strftime('%Y%m%d_%H%M%SUTC')
        hostname = socket.gethostname()

        postmortem_file_base = os.path.join(
            '/tmp', '{0}-{1}.tar'.format(hostname, filetime))

        postmortem_file = postmortem.collect(install_dir, postmortem_file_base)
        _LOGGER.info('generated postmortem file: %r', postmortem_file)
        # need to change owner of the postmortem file to treadmill proid
        # change permission to 644
        os.chmod(postmortem_file, 0o644)

        # if upload script is provided, we upload the postmortem_file
        if upload_script is not None:
            upload_arg_list = ([] if upload_args is None else
                               shlex.split(upload_args))
            utils.check_call([upload_script, postmortem_file] +
                             upload_arg_list)