def test_nosave_logs(self, open_mock, conf_mock, mkdir_mock, exec_wr_mock,
                         glob_mock):
        """Test nosave for logs"""
        glob_mock.side_effect = [
            [],  # no screenshots
            []  # no script logs
        ]
        conf_mock.target.can_save_installation_logs = False
        conf_mock.target.can_copy_input_kickstart = True

        task = CopyLogsTask("/somewhere")
        with patch.object(CopyLogsTask,
                          "_copy_file_to_sysroot") as copy_file_mock:
            with patch.object(CopyLogsTask,
                              "_copy_tree_to_sysroot") as copy_tree_mock:
                task.run()

        copy_file_mock.assert_called_once_with("/run/install/ks.cfg",
                                               "/root/original-ks.cfg")

        glob_mock.assert_called_once_with("/tmp/anaconda-screenshots/*.png")
        exec_wr_mock.assert_not_called()
        mkdir_mock.assert_not_called()
        copy_tree_mock.assert_not_called()
        open_mock.assert_not_called()
    def test_nosave_input_ks(self, open_mock, conf_mock, mkdir_mock,
                             exec_wr_mock, glob_mock):
        """Test nosave for kickstart"""
        glob_mock.side_effect = [
            [],  # no screenshots
            ["/somewhere/var/log/anaconda/anaconda.log"]
        ]
        conf_mock.target.can_save_installation_logs = True
        conf_mock.target.can_copy_input_kickstart = False

        task = CopyLogsTask("/somewhere")
        with patch.object(CopyLogsTask,
                          "_copy_file_to_sysroot") as copy_file_mock:
            with patch.object(CopyLogsTask,
                              "_copy_tree_to_sysroot") as copy_tree_mock:
                task.run()

        mkdir_mock.assert_called_once_with("/somewhere/var/log/anaconda/")

        assert call("/run/install/ks.cfg", "/root/original-ks.cfg") \
               not in copy_file_mock.call_args_list

        assert copy_tree_mock.called
        assert exec_wr_mock.called
        assert glob_mock.called
        assert open_mock.called
    def test_run_all(self, open_mock, conf_mock, mkdir_mock, restore_mock,
                     exec_wr_mock, glob_mock):
        """Test the log copying task."""
        glob_mock.side_effect = [[
            "/tmp/anaconda-screenshots/screenshot-0001.png"
        ], ["/tmp/ks-script-blabblah.log"],
                                 ["/somewhere/var/log/anaconda/anaconda.log"]]
        conf_mock.target.can_save_installation_logs = True
        conf_mock.target.can_copy_input_kickstart = True

        task = CopyLogsTask("/somewhere")
        with patch.object(CopyLogsTask,
                          "_copy_file_to_sysroot") as copy_file_mock:
            with patch.object(CopyLogsTask,
                              "_copy_tree_to_sysroot") as copy_tree_mock:
                task.run()

        mkdir_mock.assert_called_once_with("/somewhere/var/log/anaconda/")

        for logfile in [
                "anaconda.log", "syslog", "X.log", "program.log",
                "packaging.log", "storage.log", "ifcfg.log", "lvm.log",
                "dnf.librepo.log", "hawkey.log", "dbus.log"
        ]:
            copy_file_mock.assert_any_call("/tmp/" + logfile,
                                           "/var/log/anaconda/" + logfile)

        copy_file_mock.assert_has_calls([
            call("/tmp/anaconda-screenshots/screenshot-0001.png",
                 "/root/anaconda-screenshots/screenshot-0001.png"),
            call("/root/lorax-packages.log",
                 "/var/log/anaconda/lorax-packages.log"),
            call("/tmp/ks-script-blabblah.log",
                 "/var/log/anaconda/ks-script-blabblah.log"),
            call("/tmp/journal.log", "/var/log/anaconda/journal.log")
        ],
                                        any_order=True)

        copy_tree_mock.assert_has_calls([
            call("/tmp/pre-anaconda-logs", "/var/log/anaconda/"),
            call("/root/debugdata", "/var/log/anaconda/dnf_debugdata/")
        ])

        glob_mock.assert_has_calls([
            call("/tmp/anaconda-screenshots/*.png"),
            call("/tmp/ks-script*.log")
        ])
        open_mock.assert_called_once_with("/tmp/journal.log", "w")
        log_file = open_mock().__enter__.return_value

        # Warning: Constructing the argument to the exec... call requires a call to one of the
        # mocks, altering its history. Any asserts about it should happen before this.
        exec_wr_mock.assert_called_once_with("journalctl", ["-b"],
                                             stdout=log_file,
                                             log_output=False)

        restore_mock.assert_called_once_with(["/var/log/anaconda/"],
                                             root="/somewhere",
                                             skip_nonexistent=True)
예제 #4
0
    def copy_logs_with_task(self):
        """Copy logs with an installation task.

        :return: an installation task
        """
        task = CopyLogsTask(conf.target.system_root)
        return task
예제 #5
0
    def finish_installation_with_tasks(self):
        """Finish installation with tasks.

        :return: a list of installation tasks
        """
        return [
            SetContextsTask(conf.target.system_root),
            CopyLogsTask(conf.target.system_root)
        ]
예제 #6
0
    def test_nosave_logs_and_input_ks(self, open_mock, conf_mock, mkdir_mock,
                                      exec_wr_mock, glob_mock):
        """Test nosave for both logs and kickstart"""
        glob_mock.return_value = []
        conf_mock.target.can_save_installation_logs = False
        conf_mock.target.can_copy_input_kickstart = False

        task = CopyLogsTask("/somewhere")
        with patch.object(CopyLogsTask,
                          "_copy_file_to_sysroot") as copy_file_mock:
            with patch.object(CopyLogsTask,
                              "_copy_tree_to_sysroot") as copy_tree_mock:
                task.run()

        exec_wr_mock.assert_not_called()
        mkdir_mock.assert_not_called()
        glob_mock.assert_not_called()
        copy_file_mock.assert_not_called()
        copy_tree_mock.assert_not_called()
        open_mock.assert_not_called()
예제 #7
0
    def finish_installation_with_tasks(self):
        """Finish installation with tasks.

        FIXME: This is a temporary workaround for the Boss module.

        :return: a list of installation tasks
        """
        return [
            SetContextsTask(conf.target.system_root),
            CopyLogsTask(conf.target.system_root)
        ]
예제 #8
0
    def test_nosave_logs(self, open_mock, conf_mock, mkdir_mock, exec_wr_mock,
                         glob_mock):
        """Test nosave for logs"""
        glob_mock.return_value = []
        conf_mock.target.can_save_installation_logs = False
        conf_mock.target.can_copy_input_kickstart = True

        task = CopyLogsTask("/somewhere")
        with patch.object(CopyLogsTask,
                          "_copy_file_to_sysroot") as copy_file_mock:
            with patch.object(CopyLogsTask,
                              "_copy_tree_to_sysroot") as copy_tree_mock:
                task.run()

        copy_file_mock.assert_called_once_with("/run/install/ks.cfg",
                                               "/root/original-ks.cfg")

        exec_wr_mock.assert_not_called()
        mkdir_mock.assert_not_called()
        glob_mock.assert_not_called()
        copy_tree_mock.assert_not_called()
        open_mock.assert_not_called()
예제 #9
0
    def test_relabel_log_files(self, log_mock, exec_wr_mock):
        """Test _relabel_log_files"""
        task = CopyLogsTask("/somewhere")

        exec_wr_mock.return_value = 0
        task._relabel_log_files()
        exec_wr_mock.assert_called_with("restorecon",
                                        ["-ir", "/var/log/anaconda/"],
                                        root="/somewhere")
        log_mock.error.assert_not_called()

        exec_wr_mock.reset_mock()
        log_mock.reset_mock()
        log_mock.error.reset_mock()

        exec_wr_mock.side_effect = FileNotFoundError(
            "Testing missing executable")
        task._relabel_log_files()
        exec_wr_mock.assert_called()
        assert "Testing missing executable" in str(log_mock.error.mock_calls)
예제 #10
0
    def test_copy_file_to_sysroot(self, chmod_mock, exists_mock,
                                  copyfile_mock):
        """Test _copy_file_to_sysroot"""
        task = CopyLogsTask("/somewhere")

        exists_mock.return_value = True
        task._copy_file_to_sysroot("/some/source", "/another/destination")
        exists_mock.assert_called_with("/some/source")
        copyfile_mock.assert_called_with("/some/source",
                                         "/somewhere/another/destination")
        chmod_mock.assert_called_with("/somewhere/another/destination", 0o0600)

        chmod_mock.reset_mock()
        exists_mock.reset_mock()
        copyfile_mock.reset_mock()

        exists_mock.return_value = False
        task._copy_file_to_sysroot("/more/data", "/there")
        exists_mock.assert_called_with("/more/data")
        copyfile_mock.assert_not_called()
        chmod_mock.assert_not_called()