예제 #1
0
    def test_connect_handles_nonsense_session(self):
        self.change_args("es-agent")
        self.change_environment(
            JUJU_HOME=self.makeDir(),
            JUJU_ZOOKEEPER="x1.example.com")

        session_file = self.makeFile()
        with open(session_file, "w") as f:
            f.write(yaml.dump("cheesy wotsits"))
        client = self.mocker.patch(ZookeeperClient)
        client.connect("x1.example.com", client_id="cheesy wotsits")
        self.mocker.result(fail(zookeeper.ZooKeeperException()))

        mock_client = self.mocker.mock()
        client.connect("x1.example.com")
        self.mocker.result(succeed(mock_client))
        mock_client.client_id
        self.mocker.result((456, "def"))
        self.mocker.replay()

        agent = BaseAgent()
        agent.set_watch_enabled(False)
        parser = argparse.ArgumentParser()
        agent.setup_options(parser)
        options = parser.parse_args(
            ["--session-file", session_file],
            namespace=TwistedOptionNamespace())
        agent.configure(options)
        d = agent.startService()
        self.failUnlessFailure(d, NotImplementedError)
        return d
예제 #2
0
    def test_connect_env(self):
        """Zookeeper connection information can be passed via environment."""
        self.change_args("es-agent")
        self.change_environment(
            JUJU_HOME=self.makeDir(),
            JUJU_ZOOKEEPER="x1.example.com",
            JUJU_PRINCIPALS="admin:abc agent:xyz")

        client = self.mocker.patch(ZookeeperClient)
        client.connect("x1.example.com")
        self.mocker.result(succeed(client))
        client.client_id
        self.mocker.result((123, "abc"))
        client.add_auth("digest", "admin:abc")
        client.add_auth("digest", "agent:xyz")
        client.exists("/")
        self.mocker.replay()

        agent = BaseAgent()
        agent.set_watch_enabled(False)
        parser = argparse.ArgumentParser()
        agent.setup_options(parser)
        options = parser.parse_args(
            ["--session-file", self.makeFile()],
            namespace=TwistedOptionNamespace())
        agent.configure(options)
        d = agent.startService()
        self.failUnlessFailure(d, NotImplementedError)
        return d
예제 #3
0
파일: test_base.py 프로젝트: mcclurmc/juju
    def test_directory_env(self):
        """The juju directory passed via environment."""
        self.change_args("es-agent")

        juju_directory = self.makeDir()
        self.change_environment(JUJU_HOME=juju_directory, JUJU_ZOOKEEPER=get_test_zookeeper_address())

        agent = BaseAgent()
        parser = argparse.ArgumentParser()
        agent.setup_options(parser)
        options = parser.parse_args(namespace=TwistedOptionNamespace())
        agent.configure(options)
        self.assertEqual(agent.config["juju_directory"], juju_directory)
예제 #4
0
파일: test_base.py 프로젝트: mcclurmc/juju
    def test_directory_cli_option(self):
        """The juju directory can be configured on the cli."""
        juju_directory = self.makeDir()
        self.change_args(
            "es-agent", "--zookeeper-servers", get_test_zookeeper_address(), "--juju-directory", juju_directory
        )

        agent = BaseAgent()
        parser = argparse.ArgumentParser()
        agent.setup_options(parser)
        options = parser.parse_args(namespace=TwistedOptionNamespace())
        agent.configure(options)
        self.assertEqual(agent.config["juju_directory"], juju_directory)
예제 #5
0
파일: test_base.py 프로젝트: mcclurmc/juju
    def test_connect_cli_option(self):
        """The zookeeper server can be passed via cli argument."""
        mock_client = self.mocker.mock()
        client = self.mocker.patch(ZookeeperClient)
        client.connect("x2.example.com")
        self.mocker.result(succeed(mock_client))
        self.mocker.replay()

        agent = BaseAgent()
        agent.configure({"zookeeper_servers": "x2.example.com", "juju_directory": self.makeDir()})
        result = agent.connect()
        self.assertEqual(result.result, mock_client)
        self.assertEqual(agent.client, mock_client)
예제 #6
0
파일: test_base.py 프로젝트: mcclurmc/juju
    def test_run_base_raises_error(self):
        """The base class agent, raises a notimplemented error when started."""
        client = self.mocker.patch(ZookeeperClient)
        client.connect(get_test_zookeeper_address())
        client_mock = self.mocker.mock()
        self.mocker.result(succeed(client_mock))
        self.mocker.replay()

        agent = BaseAgent()
        agent.configure({"zookeeper_servers": get_test_zookeeper_address(), "juju_directory": self.makeDir()})
        d = agent.startService()
        self.failUnlessFailure(d, NotImplementedError)
        return d
예제 #7
0
    def test_directory_cli_option(self):
        """The juju directory can be configured on the cli."""
        juju_directory = self.makeDir()
        self.change_args("es-agent", "--zookeeper-servers",
                         get_test_zookeeper_address(), "--juju-directory",
                         juju_directory)

        agent = BaseAgent()
        parser = argparse.ArgumentParser()
        agent.setup_options(parser)
        options = parser.parse_args(namespace=TwistedOptionNamespace())
        agent.configure(options)
        self.assertEqual(agent.config["juju_directory"], juju_directory)
예제 #8
0
    def test_directory_env(self):
        """The juju directory passed via environment."""
        self.change_args("es-agent")

        juju_directory = self.makeDir()
        self.change_environment(JUJU_HOME=juju_directory,
                                JUJU_ZOOKEEPER=get_test_zookeeper_address())

        agent = BaseAgent()
        parser = argparse.ArgumentParser()
        agent.setup_options(parser)
        options = parser.parse_args(namespace=TwistedOptionNamespace())
        agent.configure(options)
        self.assertEqual(agent.config["juju_directory"], juju_directory)
예제 #9
0
    def test_connect_cli_option(self):
        """The zookeeper server can be passed via cli argument."""
        mock_client = self.mocker.mock()
        client = self.mocker.patch(ZookeeperClient)
        client.connect("x2.example.com")
        self.mocker.result(succeed(mock_client))
        self.mocker.replay()

        agent = BaseAgent()
        agent.configure({
            "zookeeper_servers": "x2.example.com",
            "juju_directory": self.makeDir()
        })
        result = agent.connect()
        self.assertEqual(result.result, mock_client)
        self.assertEqual(agent.client, mock_client)
예제 #10
0
    def test_run_base_raises_error(self):
        """The base class agent, raises a notimplemented error when started."""
        client = self.mocker.patch(ZookeeperClient)
        client.connect(get_test_zookeeper_address())
        client_mock = self.mocker.mock()
        self.mocker.result(succeed(client_mock))
        self.mocker.replay()

        agent = BaseAgent()
        agent.configure({
            "zookeeper_servers": get_test_zookeeper_address(),
            "juju_directory": self.makeDir()
        })
        d = agent.startService()
        self.failUnlessFailure(d, NotImplementedError)
        return d
예제 #11
0
    def test_connect_env(self):
        """Zookeeper connection information can be passed via environment."""
        self.change_args("es-agent")
        self.change_environment(JUJU_HOME=self.makeDir(),
                                JUJU_ZOOKEEPER="x1.example.com",
                                JUJU_PRINCIPALS="admin:abc agent:xyz")

        client = self.mocker.patch(ZookeeperClient)
        client.connect("x1.example.com")
        self.mocker.result(succeed(client))
        client.add_auth("digest", "admin:abc")
        client.add_auth("digest", "agent:xyz")
        client.exists("/")
        self.mocker.replay()

        agent = BaseAgent()
        parser = argparse.ArgumentParser()
        agent.setup_options(parser)
        options = parser.parse_args(namespace=TwistedOptionNamespace())
        agent.configure(options)
        d = agent.startService()
        self.failUnlessFailure(d, NotImplementedError)
        return d