def testWithOpts(self):
        """
        test calling createWorker() with --relocatable and --allow-shutdown
        options specified.
        """
        options = self.options.copy()
        options["relocatable"] = True
        options["allow-shutdown"] = "signal"

        # patch _make*() functions to do nothing
        self.setUpMakeFunctions()

        # call createWorker() and check that we get success exit code
        self.assertEquals(create_worker.createWorker(options), 0,
                          "unexpected exit code")

        # check _make*() functions were called with correct arguments
        options["allow-shutdown"] = "'signal'"
        expected_tac_contents = \
            "".join(create_worker.workerTACTemplate) % options
        self.assertMakeFunctionsCalls(self.options["basedir"],
                                      expected_tac_contents,
                                      options["quiet"])

        # check that correct info message was printed to the log
        self.assertLogged("buildworker configured in bdir")
    def testCreateError(self):
        """
        test that errors while creating buildworker directory are handled
        correctly by createWorker()
        """
        # patch _make*() functions to raise an exception
        self.setUpMakeFunctions(create_worker.CreateWorkerError("err-msg"))

        # call createWorker() and check that we get error exit code
        self.assertEquals(create_worker.createWorker(self.options), 1,
                          "unexpected exit code")

        # check that correct error message was printed the the log
        self.assertLogged("err-msg",
                          "failed to configure buildworker in bdir")
    def testMinArgs(self):
        """
        test calling createWorker() with only required arguments
        """
        # patch _make*() functions to do nothing
        self.setUpMakeFunctions()

        # call createWorker() and check that we get success exit code
        self.assertEquals(create_worker.createWorker(self.options), 0,
                          "unexpected exit code")

        # check _make*() functions were called with correct arguments
        expected_tac_contents = \
            "".join(create_worker.workerTACTemplate) % self.options
        self.assertMakeFunctionsCalls(self.options["basedir"],
                                      expected_tac_contents,
                                      self.options["quiet"])

        # check that correct info message was printed to the log
        self.assertLogged("buildworker configured in bdir")
    def testQuiet(self):
        """
        test calling createWorker() with --quiet flag
        """
        options = self.options.copy()
        options["quiet"] = True

        # patch _make*() functions to do nothing
        self.setUpMakeFunctions()

        # call createWorker() and check that we get success exit code
        self.assertEquals(create_worker.createWorker(options), 0,
                          "unexpected exit code")

        # check _make*() functions were called with correct arguments
        expected_tac_contents = \
            "".join(create_worker.workerTACTemplate) % options
        self.assertMakeFunctionsCalls(options["basedir"],
                                      expected_tac_contents,
                                      options["quiet"])

        # there should be no output on stdout
        self.assertWasQuiet()
    def testNoLogRotate(self):
        """
        test that when --no-logrotate options is used, correct tac file
        is generated.
        """
        options = self.options.copy()
        options["no-logrotate"] = True

        # patch _make*() functions to do nothing
        self.setUpMakeFunctions()

        # call createWorker() and check that we get success exit code
        self.assertEquals(create_worker.createWorker(options), 0,
                          "unexpected exit code")

        # check _make*() functions were called with correct arguments
        expected_tac_contents = (create_worker.workerTACTemplate[0] +
                                 create_worker.workerTACTemplate[2]) % options
        self.assertMakeFunctionsCalls(self.options["basedir"],
                                      expected_tac_contents,
                                      self.options["quiet"])

        # check that correct info message was printed to the log
        self.assertLogged("buildworker configured in bdir")