Ejemplo n.º 1
0
def find_write_template_calls(fs: MockFileSystem,
                              cluster: str = None) -> List[dict]:
    calls = PyMock.calls(fs.file_system.write)
    matches = []
    for call in calls:
        if cluster is not None and call['args'][
                0] == '/var/app-root/output/' + cluster + '/k8s.yaml':
            matches = matches + load_all(call['args'][1])
        if call['args'][0] == '/temp/template.yaml':
            matches = matches + load_all(call['args'][1])
        if call['args'][0] == '/var/app-root/output/k8s.yaml':
            matches = matches + load_all(call['args'][1])
    if len(matches) > 0:
        return matches
    raise Exception('fs.write not used to write template')
Ejemplo n.º 2
0
def _write_template_plan(cluster_name, conf, file_path, template: str, cur_ctx: TemplateContext):
    template_outs = _gen_template(template, cluster_name, conf, cur_ctx)

    templates_out = y.load_all(conf.fs.read(file_path)) if conf.fs.exists(file_path) else []
    templates_out = templates_out + template_outs
    conf.fs.write(file_path, y.combine_templates(templates_out))

    return E.success(cur_ctx)
Ejemplo n.º 3
0
    def map_context(self, context: TemplateContext) -> TemplateContext:
        req = requests.get(self.url)
        if req.status_code != 200:
            raise Exception("Request fail {} failed: {}".format(
                self.url, req.status_code))

        templates = y.load_all(req.text)
        context.append_templates(templates)
        return context
Ejemplo n.º 4
0
 def map_context(self, context: TemplateContext) -> TemplateContext:
     templates = y.load_all(context.config.fs.read(self.path))
     context.append_templates(templates)
     return context
Ejemplo n.º 5
0
def _write_template_to_disk(templates: List[dict], file_path: str, conf: Config):
    templates_out = y.load_all(conf.fs.read(file_path)) if conf.fs.exists(file_path) else []
    templates_out = templates_out + templates
    conf.fs.write(file_path, y.combine_templates(templates_out))