def install(cls, *packages): fam = distro_family() mngr = cls.distro_map.get(fam, None) assert mngr, "No manager for linux distro %s" %fam manager = cls.managers.get(mngr) for package in packages: sudo(manager % package)
def returns_distro_name_when_not_part_of_known_family( self, mock_dn, cxn): # TODO: do we actually want this behavior? Seems like it'd set one # up for backwards compat issues anytime you want to add new family # definitions... mock_dn.return_value = "no-clue" assert distro_family(cxn) == "no-clue"
def returns_distro_name_when_not_part_of_known_family( self, mock_dn, cxn ): # TODO: do we actually want this behavior? Seems like it'd set one # up for backwards compat issues anytime you want to add new family # definitions... mock_dn.return_value = "no-clue" assert distro_family(cxn) == "no-clue"
def package(c, *packages): """ Installs one or more ``packages`` using the system package manager. Specifically, this function calls a package manager like ``apt-get`` or ``yum`` once per package given. """ # Try to suppress interactive prompts, assume 'yes' to all questions apt = "DEBIAN_FRONTEND=noninteractive apt-get install -y {}" # Run from cache vs updating package lists every time; assume 'yes'. yum = "yum install -y %s" manager = apt if distro_family(c) == "debian" else yum for package in packages: c.sudo(manager.format(package))
def configure(ctx): """ Configure host with Docker, docker-compose, etc. """ print("Warning! This command is still under development!") # Check distro distro = info.distro_family(ctx) if distro != "debian": print(f"Only supports Debian-based distros, got '{distro}'", file=sys.stderr) return distro = info.distro_name(ctx) print(f"Installing packages on {distro} machine...") print("This recipe was tested on Ubuntu.") # Install required packages packages.package(ctx, "python3-pip") ctx.run("pip3 install docker-compose") git_clone(ctx)
def returns_debian_for_debian_or_ubuntu(self, mock_dn, cxn): for fake in ("debian", "ubuntu"): mock_dn.return_value = fake assert distro_family(cxn) == "debian"
def returns_redhat_for_rhel_centos_or_fedora(self, mock_dn, cxn): for fake in ("rhel", "centos", "fedora"): mock_dn.return_value = fake assert distro_family(cxn) == "redhat"
def test_family_inference(self, run, distro_name_fxn, file_exists): """If debian_version exists, then it should be picked up as debian-family, even if exact type couldn't be worked out.""" distro_name_fxn.return_value = 'other' file_exists.side_effect = lambda s: s == '/etc/debian_version' self.assertEqual('debian', info.distro_family())
def test_redhat_family(self, run, distro_name_fxn): for d in ('redhat', 'centos', 'fedora', 'amazon'): distro_name_fxn.return_value = d self.assertEqual('redhat', info.distro_family()) self.assertFalse(run.called)
def test_debian_family(self, run, distro_name_fxn): for d in ('ubuntu', 'debian'): distro_name_fxn.return_value = d self.assertEqual('debian', info.distro_family()) self.assertFalse(run.called)