Exemple #1
0
    def test_init(self):
        with tempfile.TemporaryDirectory() as tmp_dir:
            sys.argv = ["kapitan", "init", "--directory", tmp_dir]
            main()

            template_dir = os.path.join(os.getcwd(), "kapitan", "inputs",
                                        "templates")

            diff_files = []

            for root, dirs, files in os.walk(tmp_dir):
                diff_files += files

            for root, dirs, files in os.walk(template_dir):
                for f in files:
                    if f in diff_files:
                        diff_files.remove(f)

            self.assertEqual(len(diff_files), 0)

            # check that generated directory compiles
            prevdir = os.getcwd()
            os.chdir(tmp_dir)
            sys.argv = ["kapitan", "compile"]
            main()

            os.chdir(prevdir)
            reset_cache()
Exemple #2
0
 def tearDown(self):
     os.chdir(os.getcwd() + '/../../')
     reset_cache()
Exemple #3
0
 def tearDown(self):
     os.chdir('../../')
     reset_cache()
 def tearDown(self):
     os.chdir("../../")
     reset_cache()
Exemple #5
0
 def tearDownClass(cls):
     reset_cache()
     os.chdir("../../")
Exemple #6
0
 def tearDown(self):
     reset_cache()
Exemple #7
0
 def tearDownClass(cls):
     os.chdir(os.getcwd() + "/../../")
     reset_cache()
Exemple #8
0
    def test_force_fetch(self):
        """Test overwriting inventory items while using the --force flag

        runs $ kapitan compile --fetch --cache --output-path=temp_output --inventory-pat=temp_inv --targets remoteinv-example
        runs $ kapitan compile --fetch --cache --output-path=temp_output --inventory-pat=temp_inv --targets remoteinv-example --force
        """

        temp_output = tempfile.mkdtemp()
        temp_inv = tempfile.mkdtemp()
        copy_tree(
            os.path.join(
                os.path.abspath(os.path.dirname(__file__)),
                "test_remote_inventory",
                "environment_one",
                "inventory",
            ),
            temp_inv,
        )
        sys.argv = [
            "kapitan",
            "compile",
            "--fetch",
            "--cache",
            "--output-path",
            temp_output,
            "--inventory-path",
            temp_inv,
            "--targets",
            "remoteinv-example",
        ]
        main()

        fname = os.path.join(temp_inv, "targets", "zippedinv.yml")
        data = json.loads(yaml_load([os.path.dirname(fname)], os.path.basename(fname)))
        data["parameters"]["compression_type"] = "test"
        with open(fname, "w") as yaml_file:
            yaml_file.write(yaml.dump(data, default_flow_style=False))

        reset_cache()
        main()
        # no change in zippedinv.yml
        new_data = json.loads(yaml_load([os.path.dirname(fname)], os.path.basename(fname)))

        reset_cache()
        sys.argv = [
            "kapitan",
            "compile",
            "--fetch",
            "--cache",
            "--output-path",
            temp_output,
            "--inventory-path",
            temp_inv,
            "--targets",
            "remoteinv-example",
            "--force",
        ]
        main()
        # zippedinv.yml overwritten
        force_fetched_data = json.loads(yaml_load([os.path.dirname(fname)], os.path.basename(fname)))
        self.assertEqual(new_data["parameters"]["compression_type"], "test")
        self.assertEqual(force_fetched_data["parameters"]["compression_type"], "gzip")
        rmtree(temp_inv)
        rmtree(temp_output)
Exemple #9
0
 def tearDown(self):
     cached.reset_cache()