tliron / puccini

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

problem on get_attribute function #101

Closed philippemerle closed 2 years ago

philippemerle commented 2 years ago

Following is a simplified version of an ETSI NFV SOL001 example:

tosca_definitions_version: tosca_simple_yaml_1_3
node_types:
  tosca.nodes.nfv.VNF:
    attributes:
      scale_status:
        type: map
        entry_schema:
          type: integer
  MyCompany.SunshineDB.1_0.1_0:
    derived_from: tosca.nodes.nfv.VNF
    attributes:
      call_proc_scale_level:
        type: integer
topology_template:
  node_templates:
    SunshineDB:
      type: MyCompany.SunshineDB.1_0.1_0
      attributes:
        call_proc_scale_level: { get_attribute: [ SELF, scale_status, call_proc ] }

Compiling this template with puccini 0.21.1 produces a problem:

$ puccini-tosca compile --coerce example.yaml 
PROBLEMS (1)
  file:/.../example.yaml 
    @20,9 topology_template.node_templates["SunshineDB"].attributes["call_proc_scale_level"]: call to tosca.function.get_attribute("SELF","scale_status","call_proc") failed because nested attribute "scale_status.call_proc" not found in "SunshineDB"

scale_status is a declared attribute of SunshineDB node template, and is a map with string keys and integer entries.

Until the execution, it is impossible to check that the scale_status map contains the call_proc key.

But a TOSCA parser should only check that call_proc is of type string (else this is a typing error) and that the type of the get_attribute expression (here integer) is compatible with the type of the assigned attribute (here integer), else this is a typing error. So we could expect that this template should not be rejected by any TOSCA parser/compiler.

Am I missing something on this example?

tliron commented 2 years ago

The issue is your use of --coerce: it indeed tries to call all functions, and it's indeed a problem with attributes that do not have default values. This is by design, and it's the reason that --coerce is not the default.

Attributes are out of the scope of Puccini itself, as it's just a frontend for TOSCA. A complete system could work like this:

  1. Use puccini-tosca compile to create a Clout (no --coerce)
  2. A system will update the Clout attributes with values
  3. You can call puccini-clout scriptlet exec tosca.coerce on the Clout, whenever you want, to see all current values

(It is also possible for a system to incorporate Puccini as a library and manage Clout in a different way. The puccini-clout tool is not the only way. Even more: a system does not have have to use Puccini for this. Because all the functions are written in JavaScript, it may be possible to support Clout with a different implementation other than Puccini.)

tliron commented 2 years ago

By the way, this is discussed in the tutorial in this and the following section. Please provide feedback if you think the description is not clear enough!

philippemerle commented 2 years ago

Thank you for your explanation.