def returns_other_by_default(self, cxn): # Sentinels don't exist -> yields default # TODO: refactor with module contents in feature branch, eg tease # out sentinel file definitions to module level data # TODO: make a Session-like thing (or just allow reuse of Session?) # that works at this level instead of what it currently does in # MockRemote, mocking lower level stuff that is doubtlessly slower # and not really necessary? cxn.run.return_value = Result(connection=cxn, exited=1) assert distro_name(cxn) == "other"
def returns_centos_if_centos_release_exists(self, cxn): def centos_exists(*args, **kwargs): # TODO: this is crazy fragile, indicates we want to refactor # the guts of exists() or just mock exists() itself instead if args[0] == 'test -e "$(echo /etc/centos-release)"': return Result(connection=cxn, exited=0) return Result(connection=cxn, exited=1) cxn.run.side_effect = centos_exists assert distro_name(cxn) == "centos"
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 test_amazon_detection_via_lsb_release(self, run, lsb_release): lsb_release.return_value = amazon2012_03_lsb_info self.assertEqual(info.distro_name(), 'amazon') lsb_release.assert_called() self.assertFalse(run.called)
def test_ubuntu_detection_via_lsb_release(self, run, lsb_release): lsb_release.return_value = ubuntu1104_lsb_info self.assertEqual(info.distro_name(), 'ubuntu') lsb_release.assert_called() self.assertFalse(run.called)
def get_distro_name(): """ Demo: Get your distro name """ name = info.distro_name() print(name)