Ejemplo n.º 1
0
    def missing_include_split_test(self):
        ks_content = """
network --device=ens3
%include missing_include.cfg
""".strip()
        manager = KickstartManager()
        with self._create_ks_files([("ks.mgr.test.missing_include.cfg", ks_content)]) as filename:
            report = manager.read_kickstart_file(filename)

        self.assertEqual(report.is_valid(), False)
        self.assertEqual(len(report.get_messages()), 1)

        error = report.get_messages()[0]
        self.assertEqual(
            error.module_name, "org.fedoraproject.Anaconda.Boss"
        )
        self.assertEqual(
            error.file_name, "ks.mgr.test.missing_include.cfg"
        )
        self.assertEqual(
            error.line_number, 0
        )
        self.assertEqual(
            error.message,
            "Unable to open input kickstart file: Error opening file: "
            "[Errno 2] No such file or directory: 'missing_include.cfg'"
        )
Ejemplo n.º 2
0
    def test_nothing_to_parse(self):
        ks_content = ""
        manager = KickstartManager()
        with self._create_ks_files([("ks.mgr.test.empty.cfg", ks_content)]) as filename:
            report = manager.read_kickstart_file(filename)

        assert report.is_valid() is True
        assert len(report.get_messages()) == 0

        assert manager.generate_kickstart() == ""
Ejemplo n.º 3
0
    def nothing_to_parse_test(self):
        ks_content = ""
        manager = KickstartManager()
        with self._create_ks_files([("ks.mgr.test.empty.cfg", ks_content)]) as filename:
            report = manager.read_kickstart_file(filename)

        self.assertEqual(report.is_valid(), True)
        self.assertEqual(len(report.get_messages()), 0)

        self.assertEqual(manager.generate_kickstart(), "")
Ejemplo n.º 4
0
    def __init__(self):
        super().__init__()
        self._module_manager = ModuleManager()
        self._kickstart_manager = KickstartManager()
        self._install_manager = InstallManager()

        self._module_manager.module_observers_changed.connect(
            self._kickstart_manager.on_module_observers_changed)

        self._module_manager.module_observers_changed.connect(
            self._install_manager.on_module_observers_changed)
Ejemplo n.º 5
0
    def __init__(self, module_manager=None, install_manager=None, kickstart_manager=None):
        super().__init__()
        self._module_manager = module_manager or ModuleManager()
        self._install_manager = install_manager or InstallManager()
        self._kickstart_manager = kickstart_manager or KickstartManager()

        self._setup_install_manager()
        self._setup_kickstart_manager()
Ejemplo n.º 6
0
    def missing_section_end_split_test(self):
        ks_content = """
network --device=ens3
%packages
blah
""".strip()
        manager = KickstartManager()
        with self._create_ks_files([("ks.mgr.test.missing_end.cfg", ks_content)]) as filename:
            report = manager.read_kickstart_file(filename)

        self.assertEqual(report.is_valid(), False)
        self.assertEqual(len(report.get_messages()), 1)

        error = report.get_messages()[0]
        self.assertEqual(error.module_name, "org.fedoraproject.Anaconda.Boss")
        self.assertEqual(error.file_name, "ks.mgr.test.missing_end.cfg")
        self.assertEqual(error.line_number, 3)
        self.assertEqual(error.message, 'Section %packages does not end with %end.')
Ejemplo n.º 7
0
    def test_missing_section_end_split(self):
        ks_content = """
network --device=ens3
%packages
blah
""".strip()
        manager = KickstartManager()
        with self._create_ks_files([("ks.mgr.test.missing_end.cfg", ks_content)]) as filename:
            report = manager.read_kickstart_file(filename)

        assert report.is_valid() is False
        assert len(report.get_messages()) == 1

        error = report.get_messages()[0]
        assert error.module_name == "org.fedoraproject.Anaconda.Boss"
        assert error.file_name == "ks.mgr.test.missing_end.cfg"
        assert error.line_number == 3
        assert error.message == 'Section %packages does not end with %end.'
Ejemplo n.º 8
0
    def unknown_section_split_test(self):
        ks_content = """
network --device=ens3
%unknown_section
blah
%end
""".strip()
        manager = KickstartManager()
        with self._create_ks_files([("ks.mgr.test.unknown_sect.cfg", ks_content)]) as filename:
            report = manager.read_kickstart_file(filename)

        self.assertEqual(report.is_valid(), False)
        self.assertEqual(len(report.get_messages()), 1)

        error = report.get_messages()[0]
        self.assertEqual(error.module_name, "org.fedoraproject.Anaconda.Boss")
        self.assertEqual(error.file_name, "ks.mgr.test.unknown_sect.cfg")
        self.assertEqual(error.line_number, 2)
        self.assertEqual(error.message, 'Unknown kickstart section: %unknown_section')
Ejemplo n.º 9
0
    def test_unknown_section_split(self):
        ks_content = """
network --device=ens3
%unknown_section
blah
%end
""".strip()
        manager = KickstartManager()
        with self._create_ks_files([("ks.mgr.test.unknown_sect.cfg", ks_content)]) as filename:
            report = manager.read_kickstart_file(filename)

        assert report.is_valid() is False
        assert len(report.get_messages()) == 1

        error = report.get_messages()[0]
        assert error.module_name == "org.fedoraproject.Anaconda.Boss"
        assert error.file_name == "ks.mgr.test.unknown_sect.cfg"
        assert error.line_number == 2
        assert error.message == 'Unknown kickstart section: %unknown_section'
Ejemplo n.º 10
0
    def missing_include_split_test(self):
        ks_content = """
network --device=ens3
%include missing_include.cfg
""".strip()
        manager = KickstartManager()
        with self._create_ks_files([("ks.mgr.test.missing_include.cfg",
                                     ks_content)]) as filename:
            self.assertRaises(SplitKickstartMissingIncludeError, manager.split,
                              filename)
Ejemplo n.º 11
0
    def test_missing_include_split(self):
        ks_content = """
network --device=ens3
%include missing_include.cfg
""".strip()
        manager = KickstartManager()
        with self._create_ks_files([("ks.mgr.test.missing_include.cfg", ks_content)]) as filename:
            report = manager.read_kickstart_file(filename)

        assert report.is_valid() is False
        assert len(report.get_messages()) == 1

        error = report.get_messages()[0]
        assert error.module_name == "org.fedoraproject.Anaconda.Boss"
        assert error.file_name == "ks.mgr.test.missing_include.cfg"
        assert error.line_number == 0
        assert error.message == \
            "Unable to open input kickstart file: Error opening file: " \
            "[Errno 2] No such file or directory: 'missing_include.cfg'"
Ejemplo n.º 12
0
    def missing_section_end_split_test(self):
        ks_content = """
network --device=ens3
%packages
blah
""".strip()
        manager = KickstartManager()
        with self._create_ks_files([("ks.mgr.test.missing_end.cfg", ks_content)
                                    ]) as filename:
            self.assertRaises(SplitKickstartSectionParsingError, manager.split,
                              filename)
Ejemplo n.º 13
0
    def unknown_section_split_test(self):
        ks_content = """
network --device=ens3
%unknown_section
blah
%end
""".strip()
        manager = KickstartManager()
        with self._create_ks_files([("ks.mgr.test.unknown_sect.cfg",
                                     ks_content)]) as filename:
            self.assertRaises(SplitKickstartSectionParsingError, manager.split,
                              filename)
Ejemplo n.º 14
0
    def distribute_test(self):
        manager = KickstartManager()
        module1 = TestModule(commands=["network", "firewall"])
        module2 = TestModule(addons=["pony"])
        module3 = TestModule(sections=["packages"])
        module4 = TestModule(addons=["scorched"])
        m1_observer = TestModuleObserver("1", "1", module1)
        m2_observer = TestModuleObserver("2", "2", module2)
        m3_observer = TestModuleObserver("3", "3", module3)
        unavailable_observer = TestModuleObserver("4", "4", module4)
        unavailable_observer._is_service_available = False

        manager.module_observers = [
            m1_observer, m2_observer, m3_observer, unavailable_observer
        ]
        with self._create_ks_files(self._kickstart_include) as filename:
            manager.split(filename)
        errors = manager.distribute()

        self.assertEqual(module1.kickstart, self._m1_kickstart)
        self.assertEqual(module2.kickstart, self._m2_kickstart)
        self.assertEqual(module3.kickstart, self._m3_kickstart)
        self.assertEqual(module4.kickstart, "")
        self.assertEqual(manager.unprocessed_kickstart,
                         self._unprocessed_kickstart)

        expected_errors = {("1", 5, 'ks.manager.test.include1.cfg'),
                           ("3", 42, 'ks.manager.test.include.cfg')}
        actual_errors = set()
        for service_name, (lineno, file_name), _msg in errors:
            actual_errors.add((service_name, lineno, file_name))
        self.assertEqual(actual_errors, expected_errors)
Ejemplo n.º 15
0
    def distribute_test(self):
        manager = KickstartManager()

        module1 = TestModule(commands=["network", "firewall"])
        module2 = TestModule(addons=["pony"])
        module3 = TestModule(sections=["packages"])
        module4 = TestModule(addons=["scorched"])

        m1_observer = TestModuleObserver("1", "1", module1)
        m2_observer = TestModuleObserver("2", "2", module2)
        m3_observer = TestModuleObserver("3", "3", module3)

        unavailable_observer = TestModuleObserver("4", "4", module4)
        unavailable_observer._is_service_available = False

        manager.module_observers = [
            m1_observer, m2_observer, m3_observer, unavailable_observer
        ]

        with self._create_ks_files(self._kickstart_include) as filename:
            manager.split(filename)

        errors = manager.distribute()

        self.assertEqual(module1.kickstart, self._m1_kickstart)
        self.assertEqual(module2.kickstart, self._m2_kickstart)
        self.assertEqual(module3.kickstart, self._m3_kickstart)
        self.assertEqual(module4.kickstart, "")
        self.assertEqual(manager.unprocessed_kickstart,
                         self._unprocessed_kickstart)

        expected_errors = [{
            "success": False,
            "error_message": "Mocked parse error: \"PARSE_ERROR\" found",
            "line_number": 5,
            "module_name": "1",
            "file_name": "ks.manager.test.include1.cfg"
        }, {
            "success": False,
            "error_message": "Mocked parse error: \"PARSE_ERROR\" found",
            "line_number": 41,
            "module_name": "3",
            "file_name": "ks.manager.test.include.cfg"
        }]

        self.assertEqual(errors, expected_errors)
Ejemplo n.º 16
0
    def distribute_test(self):
        manager = KickstartManager()

        module1 = TestModule(commands=["network", "firewall"])
        module2 = TestModule(addons=["pony"])
        module3 = TestModule(sections=["packages"])
        module4 = TestModule(addons=["scorched"])

        m1_observer = self._get_module_observer("1", module1)
        m2_observer = self._get_module_observer("2", module2)
        m3_observer = self._get_module_observer("3", module3)
        m4_observer = self._get_module_observer("4", module4, available=False)

        manager.on_module_observers_changed([
            m1_observer,
            m2_observer,
            m3_observer,
            m4_observer
        ])

        with self._create_ks_files(self._kickstart_include) as filename:
            report = manager.read_kickstart_file(filename)

        self.assertEqual(module1.kickstart, self._m1_kickstart)
        self.assertEqual(module2.kickstart, self._m2_kickstart)
        self.assertEqual(module3.kickstart, self._m3_kickstart)
        self.assertEqual(module4.kickstart, "")

        self.assertEqual(report.is_valid(), False)
        self.assertEqual(len(report.get_messages()), 2)

        error = report.get_messages()[0]
        self.assertEqual(error.module_name, "1")
        self.assertEqual(error.file_name, "ks.manager.test.include1.cfg")
        self.assertEqual(error.line_number, 5)
        self.assertEqual(error.message, "Mocked parse error: \"PARSE_ERROR\" found")

        error = report.get_messages()[1]
        self.assertEqual(error.module_name, "3")
        self.assertEqual(error.file_name, "ks.manager.test.include.cfg")
        self.assertEqual(error.line_number, 41)
        self.assertEqual(error.message, "Mocked parse error: \"PARSE_ERROR\" found")

        self.assertEqual(manager.generate_kickstart(), self._m123_kickstart)
Ejemplo n.º 17
0
    def test_distribute(self):
        manager = KickstartManager()

        module1 = TestModule(commands=["network", "firewall"])
        module2 = TestModule(addons=["pony"])
        module3 = TestModule(sections=["packages"])
        module4 = TestModule(addons=["scorched"])

        m1_observer = self._get_module_observer("1", module1)
        m2_observer = self._get_module_observer("2", module2)
        m3_observer = self._get_module_observer("3", module3)
        m4_observer = self._get_module_observer("4", module4, available=False)

        manager.on_module_observers_changed([
            m1_observer,
            m2_observer,
            m3_observer,
            m4_observer
        ])

        with self._create_ks_files(self._kickstart_include) as filename:
            report = manager.read_kickstart_file(filename)

        assert module1.kickstart == self._m1_kickstart
        assert module2.kickstart == self._m2_kickstart
        assert module3.kickstart == self._m3_kickstart
        assert module4.kickstart == ""

        assert report.is_valid() is False
        assert len(report.get_messages()) == 2

        error = report.get_messages()[0]
        assert error.module_name == "1"
        assert error.file_name == "ks.manager.test.include1.cfg"
        assert error.line_number == 5
        assert error.message == "Mocked parse error: \"PARSE_ERROR\" found"

        error = report.get_messages()[1]
        assert error.module_name == "3"
        assert error.file_name == "ks.manager.test.include.cfg"
        assert error.line_number == 41
        assert error.message == "Mocked parse error: \"PARSE_ERROR\" found"

        assert manager.generate_kickstart() == self._m123_kickstart
Ejemplo n.º 18
0
class Boss(Service):
    """The Boss service."""
    def __init__(self):
        super().__init__()
        self._module_manager = ModuleManager()
        self._kickstart_manager = KickstartManager()
        self._install_manager = InstallManager()
        self._ui_module = UIModule()

        self._module_manager.module_observers_changed.connect(
            self._kickstart_manager.on_module_observers_changed)

        self._module_manager.module_observers_changed.connect(
            self._install_manager.on_module_observers_changed)

    def publish(self):
        """Publish the boss."""
        TaskContainer.set_namespace(BOSS.namespace)

        # Publish submodules.
        self._ui_module.publish()

        DBus.publish_object(BOSS.object_path, BossInterface(self))
        DBus.register_service(BOSS.service_name)

    def get_modules(self):
        """Get service names of running modules.

        Get a list of all running DBus modules (including addons)
        that were discovered and started by the boss.

        :return: a list of service names
        """
        return self._module_manager.get_service_names()

    def start_modules_with_task(self):
        """Start the modules with the task."""
        return self._module_manager.start_modules_with_task()

    def stop(self):
        """Stop all modules and then stop the boss."""
        self._module_manager.stop_modules()
        super().stop()

    def read_kickstart_file(self, path):
        """Read the specified kickstart file.

        :param path: a path to a file
        :returns: a kickstart report
        """
        log.info("Reading a kickstart file at %s.", path)
        return self._kickstart_manager.read_kickstart_file(path)

    def generate_kickstart(self):
        """Return a kickstart representation of modules.

        :return: a kickstart string
        """
        log.info("Generating kickstart data...")
        return self._kickstart_manager.generate_kickstart()

    def collect_requirements(self):
        """Collect requirements of the modules.

        :return: a list of requirements
        """
        return self._install_manager.collect_requirements()

    def collect_configure_runtime_tasks(self):
        """Collect tasks for configuration of the runtime environment.

        FIXME: This method temporarily uses only addons.

        :return: a list of task proxies
        """
        return self._install_manager.collect_configure_runtime_tasks()

    def collect_configure_bootloader_tasks(self, kernel_versions):
        """Collect tasks for configuration of the bootloader.

        FIXME: This method temporarily uses only addons.
        FIXME: This is a temporary workaround. The method might change.

        :param kernel_versions: a list of kernel versions
        :return: a list of task proxies
        """
        return self._install_manager.collect_configure_bootloader_tasks(
            kernel_versions)

    def collect_install_system_tasks(self):
        """Collect tasks for installation of the system.

        FIXME: This method temporarily uses only addons.

        :return: a list of task proxies
        """
        return self._install_manager.collect_install_system_tasks()

    def set_locale(self, locale):
        """Set locale of boss and all modules.

        :param str locale: locale to set
        """
        log.info("Setting locale of all modules to %s.", locale)
        super().set_locale(locale)
        self._module_manager.set_modules_locale(locale)

    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)
        ]
Ejemplo n.º 19
0
class Boss(Service):
    """The Boss service."""
    def __init__(self):
        super().__init__()
        self._module_manager = ModuleManager()
        self._kickstart_manager = KickstartManager()
        self._install_manager = InstallManager()

        self._module_manager.module_observers_changed.connect(
            self._kickstart_manager.on_module_observers_changed)

        self._module_manager.module_observers_changed.connect(
            self._install_manager.on_module_observers_changed)

    def publish(self):
        """Publish the boss."""
        TaskContainer.set_namespace(BOSS.namespace)
        DBus.publish_object(BOSS.object_path, BossInterface(self))
        DBus.register_service(BOSS.service_name)

    def get_modules(self):
        """Get service names of running modules.

        Get a list of all running DBus modules (including addons)
        that were discovered and started by the boss.

        :return: a list of service names
        """
        return self._module_manager.get_service_names()

    def start_modules_with_task(self):
        """Start the modules with the task."""
        return self._module_manager.start_modules_with_task()

    def stop(self):
        """Stop all modules and then stop the boss."""
        self._module_manager.stop_modules()
        super().stop()

    def read_kickstart_file(self, path):
        """Read the specified kickstart file.

        :param path: a path to a file
        :returns: a kickstart report
        """
        log.info("Reading a kickstart file at %s.", path)
        return self._kickstart_manager.read_kickstart_file(path)

    def generate_kickstart(self):
        """Return a kickstart representation of modules.

        :return: a kickstart string
        """
        log.info("Generating kickstart data...")
        return self._kickstart_manager.generate_kickstart()

    def collect_requirements(self):
        """Collect requirements of the modules.

        :return: a list of requirements
        """
        return self._install_manager.collect_requirements()

    def configure_runtime_with_task(self):
        """Configure the runtime environment.

        FIXME: This method temporarily uses only addons.

        :return: a task
        """
        return self._install_manager.configure_runtime_with_task()

    def install_system_with_task(self):
        """Install the system.

        FIXME: This method temporarily uses only addons.

        :return: a task
        """
        return self._install_manager.install_system_with_task()

    def set_locale(self, locale):
        """Set locale of boss and all modules.

        :param str locale: locale to set
        """
        log.info("Setting locale of all modules to %s.", locale)
        super().set_locale(locale)
        self._module_manager.set_modules_locale(locale)
Ejemplo n.º 20
0
class Boss(Service):
    """The Boss service."""
    def __init__(self):
        super().__init__()
        self._module_manager = ModuleManager()
        self._kickstart_manager = KickstartManager()
        self._install_manager = InstallManager()

        self._module_manager.module_observers_changed.connect(
            self._kickstart_manager.on_module_observers_changed)

        self._module_manager.module_observers_changed.connect(
            self._install_manager.on_module_observers_changed)

    def publish(self):
        """Publish the boss."""
        TaskContainer.set_namespace(BOSS.namespace)
        DBus.publish_object(BOSS.object_path, BossInterface(self))
        DBus.register_service(BOSS.service_name)

    def start_modules_with_task(self):
        """Start the modules with the task."""
        return self._module_manager.start_modules_with_task()

    def stop(self):
        """Stop all modules and then stop the boss."""
        self._module_manager.stop_modules()
        super().stop()

    def read_kickstart_file(self, path):
        """Read the specified kickstart file.

        :param path: a path to a file
        :returns: a kickstart report
        """
        log.info("Reading a kickstart file at %s.", path)
        return self._kickstart_manager.read_kickstart_file(path)

    def generate_kickstart(self):
        """Return a kickstart representation of modules.

        :return: a kickstart string
        """
        log.info("Generating kickstart data...")
        return self._kickstart_manager.generate_kickstart()

    def install_system_with_task(self):
        """Install the system.

        :return: the main installation task
        """
        return self._install_manager.install_system_with_task()

    def set_locale(self, locale):
        """Set locale of boss and all modules.

        :param str locale: locale to set
        """
        log.info("Setting locale of all modules to %s.", locale)
        super().set_locale(locale)
        self._module_manager.set_modules_locale(locale)