def write_fakejuju_script(version, bindir, datadir, cfgdir, api_info): if version.startswith("1."): raw_api_info = { "state-servers": api_info.endpoints, "user": api_info.user, "password": api_info.password, "environ-uuid": api_info.model_uuid, } else: raw_api_info = { "details": { "api-endpoints": api_info.endpoints, }, "account": { "user": api_info.user + "@local", "password": api_info.password, }, "models": { "controller": { "uuid": api_info.model_uuid, }, "default": { "uuid": api_info.model_uuid, }, }, } output = json.dumps(raw_api_info) logfile = os.path.join(bindir, "calls.log") script = FAKE_JUJU_SCRIPT.format(datadir=datadir, cfgdir=cfgdir, logfile=logfile, output=output) filename = get_filename(version, bindir) os.makedirs(os.path.dirname(filename)) with open(filename, "w") as scriptfile: scriptfile.write(script) os.chmod(filename, 0o755) os.makedirs(datadir) return logfile
def test_missing_version(self): """get_filename() fails if version is None or empty.""" with self.assertRaises(ValueError): get_filename(None) with self.assertRaises(ValueError): get_filename("")
def test_minimal_args(self): """get_filename() works correctly when given minimal args.""" filename = get_filename("1.25.6") self.assertEqual(filename, "/usr/bin/fake-juju-1.25.6")
def test_empty_bindir(self): """get_filename() works correctly when given an empty string for bindir.""" filename = get_filename("1.25.6", "") self.assertEqual(filename, "fake-juju-1.25.6")
def test_all_args(self): """get_filename() works correctly when given all args.""" filename = get_filename("1.25.6", "/spam") self.assertEqual(filename, "/spam/fake-juju-1.25.6")