Esempio n. 1
0
    def test_scan(self):
        role_names = th.create_roles(self.test_path, 3)

        for i, role in enumerate(role_names):
            defaults_path = os.path.join(self.test_path, role, "defaults",
                                         "main.yml")
            tasks_path = os.path.join(self.test_path, role, "tasks",
                                      "main.yml")
            meta_path = os.path.join(self.test_path, role, "meta", "main.yml")
            utils.string_to_file(defaults_path, th.DEFAULTS_TEMPLATE)
            utils.string_to_file(tasks_path, th.TASKS_TEMPLATE)

            # remove 1 of the meta files
            if i == 2:
                os.remove(meta_path)

        (out, err) = utils.capture_shell("ansigenome scan {0}".format(
            self.test_path))

        th.print_out("Scan output without terminal colors:", out)

        self.assertIn("3 roles", out)
        self.assertIn("3 defaults", out)
        self.assertIn("9 defaults", out)
        self.assertIn("2 facts", out)
        self.assertIn("6 facts", out)
        self.assertIn("8 files", out)
        self.assertIn("26 files", out)
        self.assertIn("88 lines", out)
        self.assertIn("230 lines", out)

        self.assertIn(
            "0 ok       3 missing readme(s)       " + "0 missing meta(s)", out)

        self.assertEqual(err, "")
Esempio n. 2
0
    def test_gendoc(self):
        all_metas = {}
        idempotency_tag = "_idem"
        relative_readme_path = "README.rst"
        relative_meta_path = os.path.join("meta", "main.yml")

        role_names = th.create_roles(self.test_path, 3)

        # ----------------------------------------------------------------
        # add meta files to the roles
        # ----------------------------------------------------------------
        for i, role in enumerate(role_names):
            defaults_path = os.path.join(self.test_path, role,
                                         "defaults", "main.yml")
            tasks_path = os.path.join(self.test_path, role,
                                      "tasks", "main.yml")
            utils.string_to_file(defaults_path, th.DEFAULTS_TEMPLATE)
            utils.string_to_file(tasks_path, th.TASKS_TEMPLATE)

        # ----------------------------------------------------------------
        # run the genmeta command and check its output
        # ----------------------------------------------------------------
        (out, err) = utils.capture_shell(
            "ansigenome genmeta {0}".format(self.test_path))

        if os.path.exists(relative_meta_path):
            th.populate_dict_with_files(self.test_path, role_names, all_metas,
                                        relative_readme_path)

        th.print_out("Genmeta output without terminal colors:", out)

        self.assertIn("meta files    0 ok       0 skipped       " +
                      "3 changed", out)

        # ----------------------------------------------------------------
        # run the genmeta command on the same roles to test idempotency
        # ----------------------------------------------------------------
        (out, err) = utils.capture_shell(
            "ansigenome genmeta {0}".format(self.test_path))

        if os.path.exists(relative_meta_path):
            th.populate_dict_with_files(self.test_path, role_names, all_metas,
                                        relative_readme_path,
                                        idempotency_tag)

        # run a diff to help debug idempotency issues
        th.run_diff_on(all_metas, relative_meta_path, idempotency_tag)

        th.print_out("Genmeta output idempotency test:", out)

        self.assertIn("meta files    0 ok       3 skipped       " +
                      "0 changed", out)
Esempio n. 3
0
    def test_dump(self):
        out_file = os.path.join(self.test_path, "dump.json")
        role_names = th.create_roles(self.test_path)

        for role in role_names:
            defaults_path = os.path.join(self.test_path, role,
                                         "defaults", "main.yml")
            tasks_path = os.path.join(self.test_path, role,
                                      "tasks", "main.yml")
            meta_path = os.path.join(self.test_path, role,
                                     "meta", "main.yml")
            utils.string_to_file(defaults_path, th.DEFAULTS_TEMPLATE)
            utils.string_to_file(tasks_path, th.TASKS_TEMPLATE)
            utils.string_to_file(meta_path, th.META_TEMPLATE)

        (out, err) = utils.capture_shell(
            "ansigenome export -t dump {0} -o {1}".format(self.test_path,
                                                          out_file))

        self.assertTrue(os.path.exists(out_file))

        json_contents = utils.file_to_string(out_file)
        contents = th.json_to_dict(json_contents)

        self.assertIn("roles", contents)
        self.assertIn("totals", contents)
        self.assertIn("dependencies", json_contents)
        self.assertIsInstance(contents, dict)
        self.assertEqual(err, "")
Esempio n. 4
0
    def test_scan(self):
        role_names = th.create_roles(self.test_path, 3)

        for i, role in enumerate(role_names):
            defaults_path = os.path.join(self.test_path, role,
                                         "defaults", "main.yml")
            tasks_path = os.path.join(self.test_path, role,
                                      "tasks", "main.yml")
            meta_path = os.path.join(self.test_path, role,
                                     "meta", "main.yml")
            utils.string_to_file(defaults_path, th.DEFAULTS_TEMPLATE)
            utils.string_to_file(tasks_path, th.TASKS_TEMPLATE)

            # remove 1 of the meta files
            if i == 2:
                os.remove(meta_path)

        (out, err) = utils.capture_shell(
            "ansigenome scan {0}".format(self.test_path))

        th.print_out("Scan output without terminal colors:", out)

        self.assertIn("3 roles", out)
        self.assertIn("3 defaults", out)
        self.assertIn("9 defaults", out)
        self.assertIn("2 facts", out)
        self.assertIn("6 facts", out)
        self.assertIn("8 files", out)
        self.assertIn("26 files", out)
        self.assertIn("88 lines", out)
        self.assertIn("230 lines", out)

        self.assertIn("0 ok       3 missing readme(s)       " +
                      "0 missing meta(s)", out)

        self.assertEqual(err, "")
Esempio n. 5
0
    def test_templates(self):
        role = th.create_roles(self.test_path, 1)
        role_name = role[0]

        role_path = os.path.join(self.test_path, role_name)
        readme_path = os.path.join(role_path, "README.rst")
        defaults_path = os.path.join(self.test_path, role_name,
                                     "defaults", "main.yml")
        tasks_path = os.path.join(self.test_path, role_name,
                                  "tasks", "main.yml")

        meta_path = os.path.join(self.test_path, role_name,
                                 "meta", "main.yml")

        utils.string_to_file(defaults_path, th.DEFAULTS_TEMPLATE)
        utils.string_to_file(tasks_path, th.TASKS_TEMPLATE)
        utils.string_to_file(meta_path, th.META_TEMPLATE_FULL)

        (out, err) = utils.capture_shell(
            "ansigenome gendoc {0}".format(self.test_path))

        readme = utils.file_to_string(readme_path)

        print
        print "README compiled template:"
        print readme
        print
        self.assertIn("tear.drinker", readme)
        self.assertIn("Chuck Norris", readme)
        self.assertIn("Travis", readme)
        self.assertIn("poop", readme)
        self.assertIn("imposes", readme)
        self.assertIn("fists", readme)
        self.assertIn("telekinesis", readme)
        self.assertIn(role_name, readme)
        self.assertIn("testuser." + role_name, readme)
        self.assertIn("ansible-" + role_name, readme)
        self.assertIn("theuniverse", readme)
        self.assertIn("foo: bar", readme)
        self.assertIn("unix_is_cool", readme)
        self.assertIn("ansigenome", readme)
        self.assertIn("galaxy.ansible.com", readme)
        self.assertNotIn("BETA", readme)
        self.assertNotIn("beta", readme)
        self.assertNotIn("deprecated", readme)
        self.assertNotIn("galaxy-install", readme)
        self.assertNotIn("twitter", readme)
Esempio n. 6
0
    def test_templates(self):
        role = th.create_roles(self.test_path, 1)
        role_name = role[0]

        role_path = os.path.join(self.test_path, role_name)
        readme_path = os.path.join(role_path, "README.rst")
        defaults_path = os.path.join(self.test_path, role_name,
                                     "defaults", "main.yml")
        tasks_path = os.path.join(self.test_path, role_name,
                                  "tasks", "main.yml")

        meta_path = os.path.join(self.test_path, role_name,
                                 "meta", "main.yml")

        utils.string_to_file(defaults_path, th.DEFAULTS_TEMPLATE)
        utils.string_to_file(tasks_path, th.TASKS_TEMPLATE)
        utils.string_to_file(meta_path, th.META_TEMPLATE_FULL)

        (out, err) = utils.capture_shell(
            "ansigenome gendoc {0}".format(self.test_path))

        readme = utils.file_to_string(readme_path)

        print()
        print("README compiled template:")
        print(readme)
        print
        self.assertIn("tear.drinker", readme)
        self.assertIn("Chuck Norris", readme)
        self.assertIn("Travis", readme)
        self.assertIn("poop", readme)
        self.assertIn("imposes", readme)
        self.assertIn("fists", readme)
        self.assertIn("telekinesis", readme)
        self.assertIn(role_name, readme)
        self.assertIn("testuser." + role_name, readme)
        self.assertIn("ansible-" + role_name, readme)
        self.assertIn("theuniverse", readme)
        self.assertIn("foo: bar", readme)
        self.assertIn("unix_is_cool", readme)
        self.assertIn("ansigenome", readme)
        self.assertIn("galaxy.ansible.com", readme)
        self.assertNotIn("BETA", readme)
        self.assertNotIn("beta", readme)
        self.assertNotIn("deprecated", readme)
        self.assertNotIn("galaxy-install", readme)
        self.assertNotIn("twitter", readme)
Esempio n. 7
0
def create_ansigenome_config(test_path):
    """
    Create a config file to use for each test.
    """
    utils.string_to_file(test_path, CONFIG_TEMPLATE)
Esempio n. 8
0
    def test_gendoc(self):
        all_readmes = {}
        idempotency_tag = "_idem"
        relative_readme_path = "README.rst"
        relative_meta_path = os.path.join("meta", "main.yml")

        role_names = th.create_roles(self.test_path, 3)

        # ----------------------------------------------------------------
        # add readme files to the roles
        # ----------------------------------------------------------------
        for i, role in enumerate(role_names):
            defaults_path = os.path.join(self.test_path, role, "defaults",
                                         "main.yml")
            tasks_path = os.path.join(self.test_path, role, "tasks",
                                      "main.yml")
            utils.string_to_file(defaults_path, th.DEFAULTS_TEMPLATE)
            utils.string_to_file(tasks_path, th.TASKS_TEMPLATE)

        # ----------------------------------------------------------------
        # run the gendoc command and check its output
        # ----------------------------------------------------------------
        (out, err) = utils.capture_shell("ansigenome gendoc {0}".format(
            self.test_path))

        if os.path.exists(relative_meta_path):
            th.populate_dict_with_files(self.test_path, role_names,
                                        all_readmes, relative_readme_path)

        th.print_out("Gendoc output without terminal colors:", out)

        self.assertIn(
            "readme files    3 ok       0 skipped       " + "0 changed", out)

        # ----------------------------------------------------------------
        # run the gendoc command on the same roles to test idempotency
        # ----------------------------------------------------------------
        (out, err) = utils.capture_shell("ansigenome gendoc {0}".format(
            self.test_path))

        if os.path.exists(relative_meta_path):
            th.populate_dict_with_files(self.test_path, role_names,
                                        all_readmes, relative_readme_path,
                                        idempotency_tag)

        # run a diff to help debug idempotency issues
        th.run_diff_on(all_readmes, relative_readme_path, idempotency_tag)

        th.print_out("Gendoc output idempotency test:", out)

        self.assertIn(
            "readme files    0 ok       3 skipped       " + "0 changed", out)

        # ----------------------------------------------------------------
        # run the gendoc command on the same roles to test failures
        # ----------------------------------------------------------------
        broken_meta = "{{"
        first_role = role_names[0]
        fail_path = os.path.join(self.test_path, first_role,
                                 relative_meta_path)
        utils.string_to_file(fail_path, broken_meta)

        (out, err) = utils.capture_shell("ansigenome gendoc {0}".format(
            self.test_path))
        th.print_out("Gendoc output failed test:", out)

        self.assertIn("^", out)

        assert err == "", "expected empty err but got:\n{0}".format(err)
Esempio n. 9
0
def create_ansigenome_config(test_path):
    """
    Create a config file to use for each test.
    """
    utils.string_to_file(test_path, CONFIG_TEMPLATE)