def get_environment(self, machine_id, zookeeper_hosts): environ = dict(os.environ) environ["JUJU_MACHINE_ID"] = str(machine_id) environ["JUJU_UNIT_NAME"] = self.unit_name environ["JUJU_HOME"] = self.juju_home environ["JUJU_ZOOKEEPER"] = zookeeper_hosts environ["PYTHONPATH"] = ":".join( filter(None, [ os.path.dirname(get_module_directory(juju)), environ.get("PYTHONPATH")])) return environ
def get_environment(self, machine_id, zookeeper_hosts): environ = dict(os.environ) environ["JUJU_MACHINE_ID"] = str(machine_id) environ["JUJU_UNIT_NAME"] = self.unit_name environ["JUJU_HOME"] = self.juju_home environ["JUJU_ZOOKEEPER"] = zookeeper_hosts environ["PYTHONPATH"] = ":".join( filter(None, [ os.path.dirname(get_module_directory(juju)), environ.get("PYTHONPATH") ])) return environ
def get_cli_environ_path(*search_path): """Construct a path environment variable. This path will contain the juju bin directory and any paths passed as *search_path. @param search_path: additional directories to put on PATH """ search_path = list(search_path) # Look for the top level juju bin directory and make sure # that is available for the client utilities. bin_path = os.path.normpath( os.path.join(get_module_directory(juju), "..", "bin")) search_path.append(bin_path) search_path.extend(os.environ.get("PATH", "").split(":")) return ":".join(search_path)
def test_service_unit_start_agent_arguments(self): """ Starting a service unit will start a service unit agent with arguments denoting the current machine id, zookeeper server location, and the unit name. Additionally it will configure the log and pid file locations. """ machine_id = "0" zookeeper_hosts = "menagerie.example.com:2181" from twisted.internet import reactor mock_reactor = self.mocker.patch(reactor) environ = dict(os.environ) environ["JUJU_UNIT_NAME"] = self.unit_name environ["JUJU_HOME"] = self.juju_directory environ["JUJU_MACHINE_ID"] = machine_id environ["JUJU_ZOOKEEPER"] = zookeeper_hosts environ["PYTHONPATH"] = ":".join( filter(None, [ os.path.dirname(get_module_directory(juju)), environ.get("PYTHONPATH")])) pid_file = os.path.join( self.units_directory, "%s.pid" % self.unit_name.replace("/", "-")) log_file = os.path.join( self.deployment.directory, "charm.log") args = [sys.executable, "-m", "juju.agents.dummy", "-n", "--pidfile", pid_file, "--logfile", log_file] mock_reactor.spawnProcess( MATCH_PROTOCOL, sys.executable, args, environ) self.mocker.replay() self.deployment.start( machine_id, zookeeper_hosts, self.bundle)
def test_service_unit_start_agent_arguments(self): """ Starting a service unit will start a service unit agent with arguments denoting the current machine id, zookeeper server location, and the unit name. Additionally it will configure the log and pid file locations. """ machine_id = "0" zookeeper_hosts = "menagerie.example.com:2181" from twisted.internet import reactor mock_reactor = self.mocker.patch(reactor) environ = dict(os.environ) environ["JUJU_UNIT_NAME"] = self.unit_name environ["JUJU_HOME"] = self.juju_directory environ["JUJU_MACHINE_ID"] = machine_id environ["JUJU_ZOOKEEPER"] = zookeeper_hosts environ["PYTHONPATH"] = ":".join( filter(None, [ os.path.dirname(get_module_directory(juju)), environ.get("PYTHONPATH") ])) pid_file = os.path.join(self.units_directory, "%s.pid" % self.unit_name.replace("/", "-")) log_file = os.path.join(self.deployment.directory, "charm.log") args = [ sys.executable, "-m", "juju.agents.dummy", "-n", "--pidfile", pid_file, "--logfile", log_file ] mock_reactor.spawnProcess(MATCH_PROTOCOL, sys.executable, args, environ) self.mocker.replay() self.deployment.start(machine_id, zookeeper_hosts, self.bundle)
def get_cli_hook(self, hook): bin_path = os.path.normpath( os.path.join(get_module_directory(juju), "..", "bin")) return os.path.join(bin_path, hook)
def test_get_module_directory(self): directory = get_module_directory(juju) self.assertIn("juju", directory) self.assertNotIn("_trial_temp", directory) self.assertTrue(os.path.isdir(directory))