def __init__( self, pid_file, zookeeper_hosts=None, machine_id="0", log_file=None, juju_directory="/var/lib/juju", juju_unit_namespace="", public_key=None, juju_origin="ppa"): """ :param pid_file: Path to file used to store process id. :param machine_id: machine id for the local machine. :param zookeeper_hosts: Zookeeper hosts to connect. :param log_file: A file to use for the agent logs. :param juju_directory: The directory to use for all state and logs. :param juju_unit_namespace: The machine agent will create units with a known a prefix to allow for multiple users and multiple environments to create containers. The namespace should be unique per user and per environment. :param public_key: An SSH public key (string) that will be used in the container for access. """ self._pid_file = pid_file self._machine_id = machine_id self._zookeeper_hosts = zookeeper_hosts self._juju_directory = juju_directory self._juju_unit_namespace = juju_unit_namespace self._log_file = log_file self._public_key = public_key self._juju_origin = juju_origin if self._juju_origin is None: origin, source = get_default_origin() if origin == BRANCH: origin = source self._juju_origin = origin
def test_get_default_origin_apt_cache_not_found(self): """ If the running logic isn't in /usr, installed version doesn't matter. """ bin_dir = self.makeDir() self.change_environment(PATH=bin_dir+":/bin") self.patch(juju, "__file__", "/usr/lib/pymodules/python2.7/juju/__init__.pyc") self.assertEquals(get_default_origin(), ("distro", None))
def test_get_default_origin_apt_cache_not_found(self): """ If the running logic isn't in /usr, installed version doesn't matter. """ bin_dir = self.makeDir() path = os.environ.get("PATH", "") self.change_environment(PATH=bin_dir+":/bin") self.patch(juju, "__file__", "/usr/lib/pymodules/python2.7/juju/__init__.pyc") self.assertEquals(get_default_origin(), ("distro", None))
def __init__( self, juju_unit_namespace, zookeeper_hosts=None, machine_id="0", log_file=None, juju_directory="/var/lib/juju", public_key=None, juju_origin="ppa", juju_series=None): """ :param juju_series: The release series to use (maverick, natty, etc). :param machine_id: machine id for the local machine. :param zookeeper_hosts: Zookeeper hosts to connect. :param log_file: A file to use for the agent logs. :param juju_directory: The directory to use for all state and logs. :param juju_unit_namespace: The machine agent will create units with a known a prefix to allow for multiple users and multiple environments to create containers. The namespace should be unique per user and per environment. :param public_key: An SSH public key (string) that will be used in the container for access. """ self._juju_origin = juju_origin if self._juju_origin is None: origin, source = get_default_origin() if origin == BRANCH: origin = source self._juju_origin = origin env = {"JUJU_MACHINE_ID": machine_id, "JUJU_ZOOKEEPER": zookeeper_hosts, "JUJU_HOME": juju_directory, "JUJU_ORIGIN": self._juju_origin, "JUJU_UNIT_NS": juju_unit_namespace, "JUJU_SERIES": juju_series, "PYTHONPATH": ":".join(sys.path)} if public_key: env["JUJU_PUBLIC_KEY"] = public_key self._service = UpstartService( "juju-%s-machine-agent" % juju_unit_namespace, use_sudo=True) self._service.set_description( "Juju machine agent for %s" % juju_unit_namespace) self._service.set_environ(env) self._service_args = [ "/usr/bin/python", "-m", self.agent_module, "--nodaemon", "--logfile", log_file, "--session-file", "/var/run/juju/%s-machine-agent.zksession" % juju_unit_namespace]
def test_get_default_origin(self): bin_dir = self.makeDir() filename = os.path.join(bin_dir, "apt-cache") with open(filename, "w") as f: f.write( "#!/bin/bash\n" "cat <<EOF\n" "juju:\n" " Installed: good-magic-1.0\n" " Candidate: good-magic-1.0\n" " Version table:\n" " *** good-magic-1.0 0\n" " 500 http://ppa.launchpad.net/juju/pkgs/ubuntu/ " "natty/main amd64 Packages\n" " 100 /var/lib/dpkg/status\n" "EOF\n") os.chmod(filename, stat.S_IEXEC | stat.S_IREAD) self.change_environment(PATH=bin_dir+":/bin") self.patch(juju, "__file__", "/usr/lib/pymodules/python2.7/juju/__init__.pyc") self.assertEquals(get_default_origin(), ("ppa", None))
def test_get_default_origin(self): bin_dir = self.makeDir() filename = os.path.join(bin_dir, "apt-cache") with open(filename, "w") as f: f.write( "#!/bin/bash\n" "cat <<EOF\n" "juju:\n" " Installed: good-magic-1.0\n" " Candidate: good-magic-1.0\n" " Version table:\n" " *** good-magic-1.0 0\n" " 500 http://ppa.launchpad.net/juju/pkgs/ubuntu/ " "natty/main amd64 Packages\n" " 100 /var/lib/dpkg/status\n" "EOF\n") os.chmod(filename, stat.S_IEXEC | stat.S_IREAD) path = os.environ.get("PATH", "") self.change_environment(PATH=bin_dir+":/bin") self.patch(juju, "__file__", "/usr/lib/pymodules/python2.7/juju/__init__.pyc") self.assertEquals(get_default_origin(), ("ppa", None))
def test_get_default_origin_not_from_system(self): """ If the running logic isn't in /usr, installed version doesn't matter. """ bin_dir = self.makeDir() filename = os.path.join(bin_dir, "apt-cache") with open(filename, "w") as f: f.write( "#!/bin/bash\n" "cat <<EOF\n" "juju:\n" " Installed: good-magic-1.0\n" " Candidate: good-magic-1.0\n" " Version table:\n" " *** good-magic-1.0 0\n" " 500 http://ppa.launchpad.net/juju/pkgs/ubuntu/ " "natty/main amd64 Packages\n" " 100 /var/lib/dpkg/status\n" "EOF\n") os.chmod(filename, stat.S_IEXEC | stat.S_IREAD) self.change_environment(PATH=bin_dir+":/bin") self.patch(juju, "__file__", "/home/joe/juju/__init__.pyc") self.assertEquals(get_default_origin(), ("branch", "lp:juju"))
def test_get_default_origin_not_from_system(self): """ If the running logic isn't in /usr, installed version doesn't matter. """ bin_dir = self.makeDir() filename = os.path.join(bin_dir, "apt-cache") with open(filename, "w") as f: f.write( "#!/bin/bash\n" "cat <<EOF\n" "juju:\n" " Installed: good-magic-1.0\n" " Candidate: good-magic-1.0\n" " Version table:\n" " *** good-magic-1.0 0\n" " 500 http://ppa.launchpad.net/juju/pkgs/ubuntu/ " "natty/main amd64 Packages\n" " 100 /var/lib/dpkg/status\n" "EOF\n") os.chmod(filename, stat.S_IEXEC | stat.S_IREAD) path = os.environ.get("PATH", "") self.change_environment(PATH=bin_dir+":/bin") self.patch(juju, "__file__", "/home/joe/juju/__init__.pyc") self.assertEquals(get_default_origin(), ("branch", "lp:juju"))