tliron / puccini

Cloud topology management and deployment tools based on TOSCA
https://puccini.cloud
Apache License 2.0
88 stars 20 forks source link

Relationship template reference gives segmentation fault #125

Closed Shishqa closed 1 year ago

Shishqa commented 1 year ago

The issue

Let's pass a TOSCA snippet to puccini:

tosca_definitions_version: tosca_simple_yaml_1_3

relationship_types:

  CustomDependsOn:
    derived_from: tosca.relationships.DependsOn

topology_template:

  node_templates:

    node_2:
      type: tosca:Root
      requirements:
        - dependency:
            node: node_1
            relationship:
              type: depends_on

    node_1:
      type: tosca:Root

  relationship_templates:

    depends_on:
      type: CustomDependsOn
      interfaces:
        Configure:
          operations:
            configure:
              implementation: playbook.yaml
              outputs:
                var: [ TARGET, tosca_id ]

This gives a stacktrace:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xc853b5]

goroutine 1 [running]:
github.com/tliron/puccini/tosca/grammars/tosca_v2_0.(*RelationshipAssignment).Render(0xc0003a2480, 0xc000129110?, 0xc0003a40e0?)
        /home/shishqa/dev/puccini/tosca/grammars/tosca_v2_0/relationship-assignment.go:90 +0x555
github.com/tliron/puccini/tosca/grammars/tosca_v2_0.(*RequirementAssignments).Render(0xc0003d4698, 0xc0003d4640, 0x104a000?)
        /home/shishqa/dev/puccini/tosca/grammars/tosca_v2_0/requirement-assignment.go:211 +0x6fd
github.com/tliron/puccini/tosca/grammars/tosca_v2_0.(*NodeTemplate).render(0xc0003d4640)
        /home/shishqa/dev/puccini/tosca/grammars/tosca_v2_0/node-template.go:83 +0x1f3
sync.(*Once).doSlow(0xd9e8a0?, 0xde1c80?)
        /usr/lib/go/src/sync/once.go:74 +0xc2
sync.(*Once).Do(...)
        /usr/lib/go/src/sync/once.go:65
github.com/tliron/puccini/tosca/grammars/tosca_v2_0.(*NodeTemplate).Render(0x5?)
        /home/shishqa/dev/puccini/tosca/grammars/tosca_v2_0/node-template.go:70 +0x47
github.com/tliron/puccini/tosca.Render(...)
        /home/shishqa/dev/puccini/tosca/entity.go:151
github.com/tliron/puccini/tosca/parser.(*ServiceContext).Render.func1({0xde1c80?, 0xc0003d4640})
        /home/shishqa/dev/puccini/tosca/parser/phase5-rendering.go:14 +0x58
github.com/tliron/kutil/reflection.EntityWork.TraverseEntities.func1({0xde1c80, 0xc0003d4640})
        /home/shishqa/go/pkg/mod/github.com/tliron/kutil@v0.1.67/reflection/traverse.go:130 +0xa3
github.com/tliron/kutil/reflection.TraverseEntities({0xde1c80?, 0xc0003d4640}, 0x7a?, 0xc00084fa48)
        /home/shishqa/go/pkg/mod/github.com/tliron/kutil@v0.1.67/reflection/traverse.go:21 +0xe8
github.com/tliron/kutil/reflection.TraverseEntities({0xdec7e0?, 0xc0003c7170}, 0x7a?, 0xc00084fa48)
        /home/shishqa/go/pkg/mod/github.com/tliron/kutil@v0.1.67/reflection/traverse.go:78 +0xa35
github.com/tliron/kutil/reflection.TraverseEntities({0xdc81c0?, 0xc0003809c0}, 0x1?, 0xc00084fa48)
        /home/shishqa/go/pkg/mod/github.com/tliron/kutil@v0.1.67/reflection/traverse.go:59 +0x510
github.com/tliron/kutil/reflection.EntityWork.TraverseEntities(0x0?, {0xdc81c0?, 0xc0003809c0?}, 0xc00084faa0?)
        /home/shishqa/go/pkg/mod/github.com/tliron/kutil@v0.1.67/reflection/traverse.go:128 +0x55
github.com/tliron/puccini/tosca/parser.(*ServiceContext).Render(0xc0003ba070)
        /home/shishqa/dev/puccini/tosca/parser/phase5-rendering.go:13 +0xf8
github.com/tliron/puccini/puccini-tosca/commands.Parse({0x72588e7ffbfa, 0xd})
        /home/shishqa/dev/puccini/puccini-tosca/commands/parse.go:179 +0x853
github.com/tliron/puccini/puccini-tosca/commands.glob..func2(0x17bab20?, {0xc000380130?, 0x1?, 0x1?})
        /home/shishqa/dev/puccini/puccini-tosca/commands/parse.go:55 +0x7e
github.com/spf13/cobra.(*Command).execute(0x17bab20, {0xc000380100, 0x1, 0x1})
        /home/shishqa/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:920 +0x847
github.com/spf13/cobra.(*Command).ExecuteC(0x17bae00)
        /home/shishqa/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:1044 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
        /home/shishqa/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:968
github.com/tliron/puccini/puccini-tosca/commands.Execute()
        /home/shishqa/dev/puccini/puccini-tosca/commands/root.go:48 +0x25
main.main()
        /home/shishqa/dev/puccini/puccini-tosca/main.go:12 +0x1e       

Expected behaviour

If relationship template assignment is not supported, then puccini must give an error like "reference to unknown relationship type: depends_on"

(however TOSCA 1.3 spec says in 3.8.2.2.3 Extended grammar with Property Assignments for the relationship’s Interfaces, that it is possible, and TOSCA 2.0 states this in 5.3.5.6.2.3 Extended grammar with Property Assignments and Interface Assignments for the relationship as well)

Shishqa commented 1 year ago

The puccini is built from 8d605c2e3e902df69876543f069e0b4352a4546a

tliron commented 1 year ago

Thank you for this. There seem to be a few different problems in the code for relationship assignments.