translate failed in scaling policy while param involved in tosca

Bug #1740063 reported by GUO Larry
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Heat Translator
New
Undecided
Unassigned
TOSCA Parser
Fix Released
Undecided
GUO Larry
tacker
New
Undecided
Unassigned

Bug Description

Based on this tosca template: https://github.com/openstack/heat-translator/blob/master/translator/tests/data/nfv/test_tosca_nfv_autoscaling.yaml

replace image name to parameter, such like:
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0

description: >
  Template for deploying servers based on policies.

imports:
  - tacker_defs.yaml
  - tacker_nfv_defs.yaml

topology_template:
  inputs:
    image_name:
      type: string
      description: Image Name

  node_templates:
    VDU1:
      type: tosca.nodes.nfv.VDU.Tacker
      properties:
        image: { get_input: image_name }
        mgmt_driver: noop
        availability_zone: nova
        flavor: m1.tiny

    CP1:
      type: tosca.nodes.nfv.CP.Tacker
      properties:
        management: true
        order: 0
        anti_spoofing_protection: false
      requirements:
        - virtualLink:
            node: VL1
        - virtualBinding:
            node: VDU1

    VDU2:
      type: tosca.nodes.nfv.VDU.Tacker
      properties:
        image: { get_input: image_name }
        mgmt_driver: noop
        availability_zone: nova
        flavor: m1.tiny

    CP2:
      type: tosca.nodes.nfv.CP.Tacker
      properties:
        management: true
        order: 0
        anti_spoofing_protection: false
      requirements:
        - virtualLink:
            node: VL1
        - virtualBinding:
            node: VDU2

    VL1:
      type: tosca.nodes.nfv.VL
      properties:
        network_name: net_mgmt
        vendor: Tacker

  policies:
    - SP1:
        type: tosca.policies.tacker.Scaling
        targets: [VDU1, VDU2]
        properties:
          increment: 1
          cooldown: 120
          min_instances: 1
          max_instances: 3
          default_instances: 2

Run generate template command and it will fail:
# python heat_translator.py --template-file=translator/tests/data/nfv/test_tosca_nfv_autoscaling_param.yaml --template-type=tosca --parameters="image_name=cirros"
Traceback (most recent call last):
  File "heat_translator.py", line 20, in <module>
    translator_shell.main()
  File "/root/heat-translator/translator/shell.py", line 303, in main
    TranslatorShell().main(args)
  File "/root/heat-translator/translator/shell.py", line 199, in main
    self._write_output(translator, output_file)
  File "/root/heat-translator/translator/shell.py", line 297, in _write_output
    print(translator.translate())
  File "/root/heat-translator/translator/hot/tosca_translator.py", line 58, in translate
    self._translate_to_hot_yaml()
  File "/root/heat-translator/translator/hot/tosca_translator.py", line 46, in _translate_to_hot_yaml
    self.node_translator.translate()
  File "/root/heat-translator/translator/hot/translate_node_templates.py", line 168, in translate
    return self._translate_nodetemplates()
  File "/root/heat-translator/translator/hot/translate_node_templates.py", line 362, in _translate_nodetemplates
    self._recursive_handle_properties(resource)
  File "/root/heat-translator/translator/hot/translate_node_templates.py", line 191, in _recursive_handle_properties
    extra_res = copy.deepcopy(res)
  File "/usr/lib64/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib64/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib64/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib64/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib64/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python2.7/copy.py", line 230, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "/usr/lib64/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib64/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib64/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python2.7/copy.py", line 230, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "/usr/lib64/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib64/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib64/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib64/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib64/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib64/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib64/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib64/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib64/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python2.7/copy.py", line 230, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "/usr/lib64/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib64/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib64/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python2.7/copy.py", line 230, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "/usr/lib64/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib64/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib64/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib64/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib64/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python2.7/copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python2.7/copy.py", line 230, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "/usr/lib64/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib64/python2.7/copy.py", line 329, in _reconstruct
    y = callable(*args)
  File "/usr/lib64/python2.7/copy_reg.py", line 93, in __newobj__
    return cls.__new__(cls, *args)
TypeError: __new__() takes exactly 4 arguments (1 given)

It is the same error if this template used on Tacker.

GUO Larry (larrygu)
summary: - translate failed in scaling policy while param involued in tosca
+ translate failed in scaling policy while param involved in tosca
GUO Larry (larrygu)
Changed in tosca-parser:
assignee: nobody → GUO Larry (larrygu)
status: New → In Progress
Revision history for this message
GUO Larry (larrygu) wrote :

It caused by toscaparser/elements/constraints.py
class Constraint(object):
........

    def __new__(cls, property_name, property_type, constraint):

__new__ must be called during deepcopy to create a new object.
one problem is that deepcopy and copy have no way of knowing which arguments to pass to __new__, therefore they only work with classes that don't require constructor arguments.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to tosca-parser (master)

Fix proposed to branch: master
Review: https://review.openstack.org/530176

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to tosca-parser (master)

Reviewed: https://review.openstack.org/530176
Committed: https://git.openstack.org/cgit/openstack/tosca-parser/commit/?id=784227cce42569a07380076dd12c2ff5d63a0930
Submitter: Zuul
Branch: master

commit 784227cce42569a07380076dd12c2ff5d63a0930
Author: Larry GUO <guo1017138@163.com>
Date: Wed Dec 27 06:08:06 2017 +0000

    Closes-Bug: #1740063
    Add default value None to __new__ method, this avoid exception when
    __deepcopy__ method used

    Change-Id: I744d293818e7019a188f9b093d2cf12c47f1f2b4

Changed in tosca-parser:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/tosca-parser 0.9.0

This issue was fixed in the openstack/tosca-parser 0.9.0 release.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.