예제 #1
0
    def realm_discover_failure_with_exception_test(self, execWithCapture):
        """Test the realm discover setup task - discovery failed with exception."""

        execWithCapture.return_value = ""
        execWithCapture.side_effect = OSError()

        with tempfile.TemporaryDirectory() as sysroot:
            os.makedirs(os.path.join(sysroot, "usr/bin"))
            os.mknod(os.path.join(sysroot, "usr/bin/realm"))
            self.assertTrue(os.path.exists(os.path.join(sysroot, "usr/bin/realm")))

            realm_data = RealmData()
            realm_data.name = "foo-domain"
            realm_data.discover_options = ["--bar", "baz"]

            task = RealmDiscoverTask(sysroot=sysroot, realm_data=realm_data)
            new_realm_data = task.run()

            # check if the realm command invocation looks right
            execWithCapture.assert_called_once_with('realm',
                                                  ['discover', '--verbose', '--bar', 'baz', 'foo-domain'],
                                                  filter_stderr=True)

            # check if the results returned by the task look correct
            self.assertFalse(new_realm_data.discovered)
            # if realm discover invocation fails hard, we don't add realmd as a required package
            self.assertListEqual(new_realm_data.required_packages, [])
예제 #2
0
    def realm_discover_success_no_extra_packages_with_garbage_task_test(self, execWithCapture):
        """Test the realm discover setup task - success, no extra packages, garbage in output."""

        execWithCapture.return_value = """foo-domain-discovered
                                       stuff, stuff
                                       stuff
                                       dsdsd dadasd
                                       """

        with tempfile.TemporaryDirectory() as sysroot:
            os.makedirs(os.path.join(sysroot, "usr/bin"))
            os.mknod(os.path.join(sysroot, "usr/bin/realm"))
            self.assertTrue(os.path.exists(os.path.join(sysroot, "usr/bin/realm")))

            realm_data = RealmData()
            realm_data.name = "foo-domain"
            realm_data.discover_options = ["--bar", "baz"]

            task = RealmDiscoverTask(sysroot=sysroot, realm_data=realm_data)
            new_realm_data = task.run()

            # check if the realm command invocation looks right
            execWithCapture.assert_called_once_with('realm',
                                                  ['discover', '--verbose', '--bar', 'baz', 'foo-domain'],
                                                  filter_stderr=True)

            # check if the results returned by the task look correct
            self.assertTrue(new_realm_data.discovered)
            self.assertListEqual(new_realm_data.required_packages, ["realmd"])
예제 #3
0
    def discover_realm_with_task(self):
        """Return the setup task for discovering a realm."""
        realm_task = RealmDiscoverTask(sysroot=conf.target.system_root,
                                      realm_data=self.realm)

        realm_task.succeeded_signal.connect(lambda: self.handle_realm_discover_results(realm_task.get_result()))
        return realm_task
예제 #4
0
    def test_realm_discover_failure(self, execWithCapture):
        """Test the realm discover setup task - discovery failed."""
        execWithCapture.return_value = ""

        with tempfile.TemporaryDirectory() as sysroot:
            os.makedirs(os.path.join(sysroot, "usr/bin"))
            os.mknod(os.path.join(sysroot, "usr/bin/realm"))
            assert os.path.exists(os.path.join(sysroot, "usr/bin/realm"))

            realm_data = RealmData()
            realm_data.name = "foo-domain"
            realm_data.discover_options = ["--bar", "baz"]

            task = RealmDiscoverTask(sysroot=sysroot, realm_data=realm_data)
            new_realm_data = task.run()

            # check if the realm command invocation looks right
            execWithCapture.assert_called_once_with(
                'realm',
                ['discover', '--verbose', '--bar', 'baz', 'foo-domain'],
                filter_stderr=True)

            # check if the results returned by the task look correct
            assert not new_realm_data.discovered
            # if realm discover invocation fails to discover a realm, we still add realmd as a required package
            assert new_realm_data.required_packages == ["realmd"]
예제 #5
0
    def test_realm_discover_success_with_garbage_task(self, execWithCapture):
        """Test the realm discover setup task - success with garbage in output."""
        execWithCapture.return_value = """foo-domain-discovered
                                          stuff-foo
                                          required-package:package-foo
                                          required-package:package-bar


                                          required-package:package-baz
                                          required-package:
                                          unrelatedstuff"""

        with tempfile.TemporaryDirectory() as sysroot:
            os.makedirs(os.path.join(sysroot, "usr/bin"))
            os.mknod(os.path.join(sysroot, "usr/bin/realm"))
            assert os.path.exists(os.path.join(sysroot, "usr/bin/realm"))

            realm_data = RealmData()
            realm_data.name = "foo-domain"
            realm_data.discover_options = ["--bar", "baz"]

            task = RealmDiscoverTask(sysroot=sysroot, realm_data=realm_data)
            new_realm_data = task.run()

            # check if the realm command invocation looks right
            execWithCapture.assert_called_once_with(
                'realm',
                ['discover', '--verbose', '--bar', 'baz', 'foo-domain'],
                filter_stderr=True)

            # check if the results returned by the task look correct
            assert new_realm_data.discovered
            assert new_realm_data.required_packages == [
                "realmd", "package-foo", "package-bar", "package-baz"
            ]
예제 #6
0
    def test_realm_discover_no_realm_name(self, execWithCapture):
        """Test the realm discover setup task - no realm name."""
        with tempfile.TemporaryDirectory() as sysroot:
            os.makedirs(os.path.join(sysroot, "usr/bin"))
            os.mknod(os.path.join(sysroot, "usr/bin/realm"))
            assert os.path.exists(os.path.join(sysroot, "usr/bin/realm"))

            realm_data = RealmData()
            realm_data.name = ""
            realm_data.discover_options = []

            task = RealmDiscoverTask(sysroot=sysroot, realm_data=realm_data)
            new_realm_data = task.run()

            # check if the realm command invocation looks right
            execWithCapture.assert_not_called()

            # no realm name so it can not be discovered
            assert not new_realm_data.discovered
            # if realm can't be discovered, we can't join it so no extra packages are needed
            assert new_realm_data.required_packages == []