Ejemplo n.º 1
0
    def test_node_comparison(self, service_template1,
                             service_template2):
        comparer = TemplateComparer()
        node1_1 = service_template1[0].get_node("hello-1")
        node2_1 = service_template2[0].get_node("hello-1")
        context = TemplateContext(node1_1, node2_1,
                                  service_template1[2],
                                  service_template2[2])
        equal, diff = comparer._compare_node(node1_1, node2_1, context)  # pylint: disable=protected-access

        assert equal is False

        assert "capabilities" in diff.changed
        assert "interfaces" in diff.changed
        assert "properties" in diff.changed
        assert "requirements" not in diff.changed
        assert "types" not in diff.changed

        node1_2 = service_template1[0].get_node("hello-2")
        node2_2 = service_template2[0].get_node("hello-2")
        context = TemplateContext(node1_2, node2_2, service_template1[2], service_template2[2])
        equal, diff = comparer._compare_node(node1_2, node2_2, context)  # pylint: disable=protected-access

        assert equal is False

        assert "capabilities" in diff.changed
        assert "interfaces" in diff.changed
        assert "properties" in diff.changed
        assert "requirements" in diff.changed
        assert "types" in diff.changed
 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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
    def test_requirement_comparison(self, service_template1,
                                    service_template2):
        comparer = TemplateComparer()
        node1 = service_template1[0].get_node("hello-6")
        node2 = service_template2[0].get_node("hello-6")
        context = TemplateContext(node1, node2, service_template1[2], service_template2[2])
        equal, diff = comparer._compare_node(node1, node2, context)  # pylint: disable=protected-access

        assert equal is False

        assert "requirements" in diff.changed
        assert "dependency" in diff.changed["requirements"].changed
        assert "target" in diff.changed["requirements"].changed["dependency"].changed
Ejemplo n.º 5
0
    def test_interface_comparison(self, service_template1,
                                  service_template2):
        comparer = TemplateComparer()
        node1 = service_template1[0].get_node("hello-1")
        node2 = service_template2[0].get_node("hello-1")
        context = TemplateContext(node1, node2, service_template1[2], service_template2[2])
        equal, diff = comparer._compare_node(node1, node2, context)  # pylint: disable=protected-access

        assert equal is False

        assert "interfaces" in diff.changed
        assert "create" in diff.changed["interfaces"].changed["Standard"].changed["operations"].changed
        assert "artifacts" in \
               diff.changed["interfaces"].changed["Standard"].changed["operations"].changed["create"].changed
        assert "inputs" in \
               diff.changed["interfaces"].changed["Standard"].changed["operations"].changed["create"].changed
Ejemplo n.º 6
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
Ejemplo n.º 7
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