Example #1
0
 def test_yaml_load(self):
     """
         This tests the yaml_load function.
         It converts the yaml file in test_resources/ to a json string
     """
     current_pwd = os.path.dirname(__file__)
     json = yaml_load([current_pwd], "test_resources/test_yaml_load.yaml")
     expected_output = """{"test": {"key": "value", "array": ["ele1", "ele2"]}}"""
     self.assertEqual(json, expected_output)
Example #2
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)