def _process_input_docs(self):
        """Load, validate and merge (with defaults) input yaml documents."""

        path_to_manifest = os.path.join(self.build_directory, MANIFEST_FILE_NAME)
        if not os.path.isfile(path_to_manifest):
            raise Exception('No manifest.yml inside the build folder')

        # Get existing manifest config documents
        self.manifest_docs = load_yamls_file(path_to_manifest)
        self.cluster_model = select_single(self.manifest_docs, lambda x: x.kind == 'epiphany-cluster')

        # Load backup / recovery configuration documents
        self.input_docs = load_yamls_file(self.file)

        # Validate input documents
        with SchemaValidator(self.cluster_model, self.input_docs) as schema_validator:
            schema_validator.run_for_individual_documents()

        # Merge the input docs with defaults
        with DefaultMerger(self.input_docs) as doc_merger:
            self.input_docs = doc_merger.run()
Esempio n. 2
0
    def _process_input_docs(self):
        """Load, validate and merge (with defaults) input yaml documents."""

        # Get existing manifest config documents
        self.manifest_docs = load_manifest_docs(self.build_directory)
        self.cluster_model = select_single(self.manifest_docs, lambda x: x.kind == 'epiphany-cluster')

        # Load backup / recovery configuration documents
        self.input_docs = load_yamls_file(self.file)

        # Validate input documents
        with SchemaValidator(self.cluster_model, self.input_docs) as schema_validator:
            schema_validator.run_for_individual_documents()

        # Merge the input docs with defaults
        with DefaultMerger(self.input_docs) as doc_merger:
            self.input_docs = doc_merger.run()
Esempio n. 3
0
    def delete(self):
        path_to_manifest = os.path.join(self.build_directory, MANIFEST_FILE_NAME)
        if not os.path.isfile(path_to_manifest):
            raise Exception('No manifest.yml inside the build folder')

        docs = load_yamls_file(path_to_manifest)
        cluster_model = select_single(docs, lambda x: x.kind == 'epiphany-cluster')
        
        if cluster_model.provider == 'any':
            raise Exception('Delete works only for cloud providers')

        with TerraformRunner(cluster_model, docs) as tf_runner:
            tf_runner.delete()     
            
        shutil.rmtree(self.build_directory, ignore_errors=True)     

        return 0
Esempio n. 4
0
    def test(self):
        # get manifest
        path_to_manifest = os.path.join(self.build_directory,
                                        MANIFEST_FILE_NAME)
        if not os.path.isfile(path_to_manifest):
            raise Exception(
                f'No "{MANIFEST_FILE_NAME}" inside the build directory: "{self.build_directory}"'
            )

        # get inventory
        path_to_inventory = os.path.join(self.build_directory,
                                         INVENTORY_FILE_NAME)
        if not os.path.isfile(path_to_inventory):
            raise Exception(
                f'No "{INVENTORY_FILE_NAME}" inside the build directory: "{self.build_directory}"'
            )

        # get admin user
        docs = load_yamls_file(path_to_manifest)
        cluster_model = select_single(docs,
                                      lambda x: x.kind == 'epiphany-cluster')
        admin_user = cluster_model.specification.admin_user
        if not os.path.isfile(admin_user.key_path):
            raise Exception(
                f'No SSH key file in directory: "{admin_user.key_path}"')

        # get and create the spec output dir if it does not exist
        spec_output = os.path.join(self.build_directory, SPEC_OUTPUT_DIR)
        if not os.path.exists(spec_output):
            os.makedirs(spec_output)

        # run the spec tests
        spec_command = SpecCommand()
        spec_command.run(spec_output, path_to_inventory, admin_user.name,
                         admin_user.key_path, self.group)

        return 0
Esempio n. 5
0
    def get_shared_config_from_manifest(self):
        # Reuse shared config from existing manifest
        # Shared config contains the use_ha_control_plane flag which is required during upgrades

        path_to_manifest = os.path.join(self.inventory_upgrade.build_dir,
                                        MANIFEST_FILE_NAME)
        if not os.path.isfile(path_to_manifest):
            raise Exception('No manifest.yml inside the build folder')

        manifest_docs = load_yamls_file(path_to_manifest)

        cluster_model = select_single(manifest_docs,
                                      lambda x: x.kind == 'epiphany-cluster')

        shared_config_doc = select_single(
            manifest_docs, lambda x: x.kind == 'configuration/shared-config')
        shared_config_doc['provider'] = cluster_model['provider']

        # Merge the shared config doc with defaults
        with DefaultMerger([shared_config_doc]) as doc_merger:
            shared_config_doc = doc_merger.run()[0]
            del shared_config_doc['provider']

        return shared_config_doc