예제 #1
0
    def test_managed_agent_root(self):
        juju_directory = self.makeDir()
        log_file = tempfile.mktemp()

        # The pid file and log file get written as root
        def cleanup_root_file(cleanup_file):
            subprocess.check_call(
                ["sudo", "rm", "-f", cleanup_file], stderr=subprocess.STDOUT)
        self.addCleanup(cleanup_root_file, log_file)

        agent = ManagedMachineAgent(
            "test-ns", machine_id="0",
            log_file=log_file,
            juju_series="precise",
            zookeeper_hosts=get_test_zookeeper_address(),
            juju_directory=juju_directory)

        agent.agent_module = "juju.agents.dummy"
        self.assertFalse((yield agent.is_running()))
        yield agent.start()
        # Give a moment for the process to start and write its config
        yield self.sleep(0.1)
        self.assertTrue((yield agent.is_running()))

        # running start again is fine, detects the process is running
        yield agent.start()
        yield agent.stop()
        self.assertFalse((yield agent.is_running()))

        # running stop again is fine, detects the process is stopped.
        yield agent.stop()
예제 #2
0
    def test_managed_agent_root(self):
        juju_directory = self.makeDir()
        pid_file = tempfile.mktemp()
        log_file = tempfile.mktemp()

        # The pid file and log file get written as root
        def cleanup_root_file(cleanup_file):
            subprocess.check_call(["sudo", "rm", "-f", cleanup_file],
                                  stderr=subprocess.STDOUT)

        self.addCleanup(cleanup_root_file, pid_file)
        self.addCleanup(cleanup_root_file, log_file)

        agent = ManagedMachineAgent(
            pid_file,
            machine_id="0",
            log_file=log_file,
            zookeeper_hosts=get_test_zookeeper_address(),
            juju_directory=juju_directory)

        agent.agent_module = "juju.agents.dummy"
        self.assertFalse((yield agent.is_running()))
        yield agent.start()

        # Give a moment for the process to start and write its config
        yield self.sleep(0.1)
        self.assertTrue((yield agent.is_running()))

        # running start again is fine, detects the process is running
        yield agent.start()
        yield agent.stop()
        self.assertFalse((yield agent.is_running()))

        # running stop again is fine, detects the process is stopped.
        yield agent.stop()

        self.assertFalse(os.path.exists(pid_file))

        # Stop raises runtime error if the process doesn't match up.
        with open(pid_file, "w") as pid_handle:
            pid_handle.write("1")
        self.assertFailure(agent.stop(), RuntimeError)
예제 #3
0
파일: test_agent.py 프로젝트: mcclurmc/juju
    def test_managed_agent_root(self):
        juju_directory = self.makeDir()
        pid_file = tempfile.mktemp()
        log_file = tempfile.mktemp()

        # The pid file and log file get written as root
        def cleanup_root_file(cleanup_file):
            subprocess.check_call(
                ["sudo", "rm", "-f", cleanup_file], stderr=subprocess.STDOUT)
        self.addCleanup(cleanup_root_file, pid_file)
        self.addCleanup(cleanup_root_file, log_file)

        agent = ManagedMachineAgent(
            pid_file, machine_id="0", log_file=log_file,
            zookeeper_hosts=get_test_zookeeper_address(),
            juju_directory=juju_directory)

        agent.agent_module = "juju.agents.dummy"
        self.assertFalse((yield agent.is_running()))
        yield agent.start()

        # Give a moment for the process to start and write its config
        yield self.sleep(0.1)
        self.assertTrue((yield agent.is_running()))

        # running start again is fine, detects the process is running
        yield agent.start()
        yield agent.stop()
        self.assertFalse((yield agent.is_running()))

        # running stop again is fine, detects the process is stopped.
        yield agent.stop()

        self.assertFalse(os.path.exists(pid_file))

        # Stop raises runtime error if the process doesn't match up.
        with open(pid_file, "w") as pid_handle:
            pid_handle.write("1")
        self.assertFailure(agent.stop(), RuntimeError)