Ask Your Question
0

Userdata params got changed during stack creation in Heat

asked 2017-04-01 10:19:31 -0500

kuro gravatar image

I am using OpenStack version Mitaka. I am trying to pass some IPv6 prefixes in userdata using heat template. But the str_replace behaving rather strangely. It changes some of the prefixes to numbers. The heat template (yaml) file is as follows -

heat_template_version: 2015-10-15

resources:

  Small:
    type: OS::Nova::Flavor
    properties:
      disk: 20
      ram: 1024
      vcpus: 2

  Management:
    type: OS::Neutron::Net
    properties:
      name: Management

  Management_subnet:
    type: OS::Neutron::Subnet
    properties:
      cidr: 10.0.0.0/24
      ip_version: 4
      name: Management_subnet
      network_id:
        get_resource: Management

  Router:
    type: OS::Neutron::Router
    properties:
      external_gateway_info:
        enable_snat: false
        network: external
      name: Router

  Management_router_interface:
    type: OS::Neutron::RouterInterface
    properties:
      router_id:
        get_resource: Router
      subnet:
        get_resource: Management_subnet

  VM_config:
    type: OS::Heat::SoftwareConfig
    properties:
      group: ungrouped
      config:
        str_replace:
          params:
            prefix1: 6:0:0:10
            prefix2: 1:3:4:5
            prefix3: 3:0:0:123
          template:
            get_file: test.sh  

  VM:
    type: OS::Nova::Server
    properties:
      networks:
        - network:
            get_resource: Management
          port:
            get_resource: Management_port
      name: VM
      image: ubuntu
      key_name: default_key
      flavor:
        get_resource: Small
      user_data_format: SOFTWARE_CONFIG
      user_data:
        get_resource: VM_config

  Management_port:
    type: OS::Neutron::Port
    properties:
      security_groups:
        - default
      network_id:
        get_resource: Management

The ubuntu image is the trusty-server-cloudimg provided by Ubuntu. The userdata script is as follows -

#!/bin/bash
echo "prefix1" >> /home/ubuntu/test.txt
echo "prefix2" >> /home/ubuntu/test.txt
echo "prefix3" >> /home/ubuntu/test.txt

The userdata script just print these prefixes in a text file. After ssh to the instance, I found that the /home/ubuntu/test.txt file contents are -

1296010
227045
3:0:0:123

The prefix1 and prefix2 got modified in the process. But prefix3 is intact. I also found in case of prefix if the fourth number (e.g 123 in case of 3:0:0:123) is less than three digits, then the problem occurs.

What am I doing wrong?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-04-03 08:39:39 -0500

zaneb gravatar image

This appears to be an unfortunate (and completely undocumented AFAICT) "feature" of YAML. It's interpreting the string as a time. (At each colon, multiply the current total by 60 and add the next number - regardless of the fact that this makes no sense with >2 colons.) To avoid this, you need to quote the strings:

      params:
        prefix1: "6:0:0:10"
        prefix2: "1:3:4:5"
        prefix3: "3:0:0:123"
edit flag offensive delete link more

Comments

Thanks for the info. I was able to avoid this issue using the same method you mentioned. But I was rather curious about this behavior. Thanks again.

kuro gravatar imagekuro ( 2017-04-03 11:32:52 -0500 )edit

I raised this as an issue in pyyaml.

zaneb gravatar imagezaneb ( 2017-04-03 12:56:12 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2017-04-01 10:14:49 -0500

Seen: 289 times

Last updated: Apr 03 '17