def main(): args = parse_args() product_yaml = os.path.join(args.ssg_root, args.product, "product.yml") if args.input_dir: input_dir = args.input_dir else: input_dir = os.path.join(args.ssg_root, "build", args.product, "fixes", "ansible") if args.output_dir: output_dir = args.output_dir else: output_dir = os.path.join(args.ssg_root, "build", args.product, "playbooks") if args.resolved_rules_dir: resolved_rules_dir = args.resolved_rules_dir else: resolved_rules_dir = os.path.join(args.ssg_root, "build", args.product, "rules") if args.resolved_profiles_dir: resolved_profiles_dir = args.resolved_profiles_dir else: resolved_profiles_dir = os.path.join(args.ssg_root, "build", args.product, "profiles") playbook_builder = ssg.playbook_builder.PlaybookBuilder( product_yaml, input_dir, output_dir, resolved_rules_dir, resolved_profiles_dir) playbook_builder.build(args.profile, args.rule)
def test_build_rule_playbook(): playbook_builder = ssg.playbook_builder.PlaybookBuilder( product_yaml, input_dir, output_dir) playbook_builder.build(profile, rule) assert os.path.exists(real_output_filepath) with open(real_output_filepath, "r") as real_output: real_output_yaml = yaml.load(real_output) with open(expected_output_filepath, "r") as expected_output: expected_output_yaml = yaml.load(expected_output) real_play = real_output_yaml.pop() expected_play = expected_output_yaml.pop() assert real_play["become"] == expected_play["become"] assert real_play["hosts"] == expected_play["hosts"] assert real_play["name"] == expected_play["name"] real_vars = real_play["vars"] expected_vars = expected_play["vars"] assert len(real_vars) == len(expected_vars) assert real_vars["var_selinux_state"] == expected_vars["var_selinux_state"] real_tags = real_play["tags"] expected_tags = real_play["tags"] assert len(real_tags) == len(expected_tags) for tag in expected_tags: assert tag in real_tags real_tasks = real_play["tasks"] expected_tasks = expected_play["tasks"] assert len(real_tasks) == len(expected_tasks) real_task = real_tasks.pop() expected_task = expected_tasks.pop() assert real_task["name"] == expected_task["name"] assert len(real_task.keys()) == len(expected_task.keys()) shutil.rmtree(output_dir)
def test_build_rule_playbook(): playbook_builder = ssg.playbook_builder.PlaybookBuilder( product_yaml, input_dir, output_dir, resolved_rules_dir ) playbook_builder.build(profile, rule) assert os.path.exists(real_output_filepath) with open(real_output_filepath, "r") as real_output: real_output_yaml = yaml.load(real_output) with open(expected_output_filepath, "r") as expected_output: expected_output_yaml = yaml.load(expected_output) real_play = real_output_yaml.pop() expected_play = expected_output_yaml.pop() assert real_play["become"] == expected_play["become"] assert real_play["hosts"] == expected_play["hosts"] assert real_play["name"] == expected_play["name"] real_vars = real_play["vars"] expected_vars = expected_play["vars"] assert len(real_vars) == len(expected_vars) assert real_vars["var_selinux_state"] == expected_vars["var_selinux_state"] real_tags = real_play["tags"] expected_tags = expected_play["tags"] assert len(real_tags) == len(expected_tags) for tag in expected_tags: assert tag in real_tags for t1, t2 in zip(real_tags, expected_tags): assert t1 == t2 real_tasks = real_play["tasks"] expected_tasks = expected_play["tasks"] assert len(real_tasks) == len(expected_tasks) real_task = real_tasks.pop() expected_task = expected_tasks.pop() assert real_task["name"] == expected_task["name"] assert len(real_task.keys()) == len(expected_task.keys()) shutil.rmtree(output_dir)
def main(): args = parse_args() playbook_builder = ssg.playbook_builder.PlaybookBuilder( args.product_yaml, args.input_dir, args.output_dir) playbook_builder.build(args.profile, args.rule)