Ejemplo n.º 1
0
    def _prepare_hello_world(self):
        logger = self.test_case.logger
        repo_name = 'cloudify-hello-world-example'
        branch = self.test_case.env.core_branch_name
        workdir = self.test_case.env.test_working_dir
        blueprint_tar = os.path.join(workdir, 'hello.tar.gz')
        blueprint_dir = os.path.join(workdir, '{0}-{1}'.format(repo_name,
                                                               branch))
        blueprint_file = os.path.join(blueprint_dir,
                                      'dockercompute_blueprint.yaml')

        if not os.path.exists(blueprint_dir):
            logger.info('Downloading hello world tar')
            helloworld_url = _HELLO_WORLD_URL.format(repo_name, branch)
            response = requests.get(helloworld_url, stream=True)
            with open(blueprint_tar, 'wb') as f:
                for chunk in response.iter_content(chunk_size=8192):
                    if chunk:
                        f.write(chunk)
            with tarfile.open(blueprint_tar, 'r:gz') as tar:
                tar.extractall(path=workdir)
            shutil.copy(
                test_utils.get_resource(
                        'dsl/agent_tests/dockercompute_helloworld.yaml'),
                blueprint_file)
            shutil.copy(
                test_utils.get_resource(
                    'dsl/agent_tests/plugins/diamond.yaml'
                ),
                os.path.join(blueprint_dir, 'diamond.yaml'))
            shutil.copy(
                test_utils.get_resource(
                    'dsl/agent_tests/plugins/dockercompute.yaml'
                ),
                os.path.join(blueprint_dir, 'dockercompute.yaml'))
        else:
            logger.info('Reusing existing hello world tar')

        if self.modify_blueprint_func:
            new_blueprint_dir = os.path.join(self.test_case.workdir,
                                             'test-hello-world')
            if os.path.isdir(new_blueprint_dir):
                shutil.rmtree(new_blueprint_dir)
            shutil.copytree(blueprint_dir, new_blueprint_dir)
            blueprint_dir = new_blueprint_dir
            blueprint_file = os.path.join(blueprint_dir,
                                          'dockercompute_blueprint.yaml')
            with utils.YamlPatcher(blueprint_file) as patcher:
                self.modify_blueprint_func(patcher, blueprint_dir)

        return blueprint_file
Ejemplo n.º 2
0
def patch_yaml(yaml_path, is_json=False, default_flow_style=True):
    with utils.YamlPatcher(yaml_path,
                           is_json=is_json,
                           default_flow_style=default_flow_style) as patch:
        yield patch