def template_diff(self, service_template1, service_template2):
     comparer = TemplateComparer()
     context = TemplateContext(service_template1[0], service_template2[0],
                               service_template1[2], service_template2[2])
     equal, diff = comparer.compare_service_template(
         service_template1[0], service_template2[0], context)
     return diff
Пример #2
0
def diff_templates(
        service_template_old: str,
        workdir_old: str,
        inputs_old: typing.Optional[dict],
        service_template_new: str,
        workdir_new: str,
        inputs_new: typing.Optional[dict],
        template_comparer: TemplateComparer,
        verbose_mode: bool
):
    if inputs_new is None:
        inputs_new = {}

    if inputs_old is None:
        inputs_old = {}

    ast_old = tosca.load(Path(workdir_old), PurePath(service_template_old))
    ast_new = tosca.load(Path(workdir_new), PurePath(service_template_new))

    template_old = ast_old.get_template(inputs_old)
    template_new = ast_new.get_template(inputs_new)
    context = TemplateContext(template_old, template_new, workdir_old, workdir_new)

    _, diff = template_comparer.compare_service_template(template_old, template_new, context)
    return diff
Пример #3
0
def diff_instances(storage_old: Storage, workdir_old: Path,
                   storage_new: Storage, workdir_new: Path,
                   template_comparer: TemplateComparer,
                   instance_comparer: InstanceComparer, verbose_mode: bool):
    template_old = get_template(storage_old, workdir_old)
    template_new = get_template(storage_new, workdir_new)
    topology_old = template_old.instantiate(storage_old)
    topology_new = template_new.instantiate(storage_new)

    context = TemplateContext(template_old, template_new, workdir_old,
                              workdir_new)
    _, diff = template_comparer.compare_service_template(
        template_old, template_new, context)
    _, diff = instance_comparer.compare_topology_template(
        topology_old, topology_new, diff)

    return diff
Пример #4
0
    def test_service_template_comparison(self, service_template1, service_template2):
        comparer = TemplateComparer()
        context = TemplateContext(service_template1[0],
                                  service_template2[0],
                                  service_template1[2],
                                  service_template2[2])
        equal, diff = comparer.compare_service_template(service_template1[0], service_template2[0], context)

        assert equal is False

        assert len(diff.changed["nodes"].added) == 1
        assert len(diff.changed["nodes"].deleted) == 1
        assert len(diff.changed["nodes"].changed) == 4

        assert diff.changed["nodes"].added[0] == "hello-5"
        assert diff.changed["nodes"].deleted[0] == "hello-4"

        assert "hello-1" in diff.changed["nodes"].changed
        assert "hello-2" in diff.changed["nodes"].changed
        assert "hello-3" in diff.changed["nodes"].changed
        assert "hello-6" in diff.changed["nodes"].changed
        assert " my-workstation" not in diff.changed["nodes"].changed