def flush_suite(suite, outdir): os.makedirs(outdir) if 'host' in suite: dir = os.path.join(outdir, "host") os.mkdir(dir) _flush_host(suite['host'], dir) _write_to_file(outdir, 'envtype', 'host') _write_to_file(outdir, 'controller', 'host') if 'container' in suite: _write_to_file(outdir, "image", suite['container']['image']) _write_to_file(outdir, 'envtype', 'container') _write_to_file(outdir, 'controller', 'container') if 'cluster' in suite: cluster = suite['cluster'] for i, host in enumerate(cluster['hosts']): dir = os.path.join(outdir, "host-%d" % i) os.mkdir(dir) _flush_host(host, dir) _write_to_file(dir, "name", host['name']) _write_to_file(outdir, 'nhosts', str(i + 1)) if 'container' in cluster: _write_to_file(outdir, "image", cluster['container']['image']) _write_to_file(outdir, 'controller', 'container') else: _write_to_file(outdir, 'controller', 'host') _write_to_file(outdir, 'envtype', 'cluster') if 'tests' in suite: _write_to_file(outdir, "tests", '\n'.join(suite['tests']), utf8=True) _write_to_file(outdir, "branches", '\n'.join(suite.get('branches', ['master']))) timeout = common.str_to_timeout(suite.get('timeout', '2h')) _write_to_file(outdir, "timeout", str(timeout)) _write_to_file(outdir, "context", suite.get('context')) if 'extra-repos' in suite: repos = '' for repo in suite['extra-repos']: repos += "[%s]\n" % repo['name'] for key, val in repo.items(): repos += "%s=%s\n" % (key, val) if repos != "": _write_to_file(outdir, "rhci-extras.repo", repos) if 'packages' in suite: packages = [] for pkg in suite['packages']: packages.append(shlex.quote(pkg)) _write_to_file(outdir, "packages", ' '.join(packages)) if 'artifacts' in suite: _write_to_file(outdir, "artifacts", '\n'.join(suite['artifacts'])) if 'env' in suite: envs = '' for k, v in suite['env'].items(): # NB: the schema already ensures that k is ASCII # only, so utf8=True will only affect the value envs += 'export %s="%s"\n' % (k, v) _write_to_file(outdir, "envs", envs, utf8=True) if 'build' in suite: v = suite['build'] if type(v) is bool and v: _write_to_file(outdir, "build", '') elif type(v) is dict: _write_to_file(outdir, "build", '') _write_to_file(outdir, "build.config_opts", v.get('config-opts', '')) _write_to_file(outdir, "build.build_opts", v.get('build-opts', '')) _write_to_file(outdir, "build.install_opts", v.get('install-opts', ''))
def ext_timeout(value, rule_obj, path): if common.str_to_timeout(value) > (2 * 60 * 60): raise SchemaError("timeout cannot be greater than 2 hours") return True
def flush_suite(suite, outdir): def write_to_file(fn, s): with open(os.path.join(outdir, fn), 'w') as f: f.write(s) os.makedirs(outdir) if 'host' in suite: host = suite['host'] if 'ostree' in host: val = host['ostree'] assert type(val) in [str, dict] if type(val) is str: assert val == "latest" write_to_file("ostree_revision", "") else: write_to_file("ostree_remote", val.get('remote', '')) write_to_file("ostree_branch", val.get('branch', '')) write_to_file("ostree_revision", val.get('revision', '')) write_to_file("distro", host['distro']) if 'container' in suite: write_to_file("image", suite['container']['image']) if 'tests' in suite: write_to_file("tests", '\n'.join(suite['tests'])) write_to_file("branches", '\n'.join(suite.get('branches', ['master']))) timeout = common.str_to_timeout(suite.get('timeout', '2h')) write_to_file("timeout", str(timeout)) write_to_file("context", suite.get('context')) if 'extra-repos' in suite: repos = '' for repo in suite['extra-repos']: repos += "[%s]\n" % repo['name'] for key, val in repo.items(): repos += "%s=%s\n" % (key, val) if repos != "": write_to_file("rhci-extras.repo", repos) if 'packages' in suite: packages = [] for pkg in suite['packages']: packages.append(shlex.quote(pkg)) write_to_file("packages", ' '.join(packages)) if 'artifacts' in suite: write_to_file("artifacts", '\n'.join(suite['artifacts'])) if 'env' in suite: envs = '' for k, v in suite['env'].items(): envs += 'export %s=%s\n' % (k, shlex.quote(v)) write_to_file("envs", envs) if 'build' in suite: v = suite['build'] if type(v) is bool and v: write_to_file("build", '') elif type(v) is dict: write_to_file("build", '') write_to_file("build.config_opts", v.get('config-opts', '')) write_to_file("build.build_opts", v.get('build-opts', '')) write_to_file("build.install_opts", v.get('install-opts', ''))