Jira (PUP-10727) Cannot define a default Timespan value for an attribute in a Ruby language data type

1 view
Skip to first unread message

Gary Larizza (Jira)

unread,
Oct 23, 2020, 4:58:03 PM10/23/20
to puppe...@googlegroups.com
Gary Larizza created an issue
 
Puppet / Bug PUP-10727
Cannot define a default Timespan value for an attribute in a Ruby language data type
Issue Type: Bug Bug
Affects Versions: PUP 6.14.0
Assignee: Unassigned
Components: Type System
Created: 2020/10/23 1:57 PM
Labels: typesystem
Priority: Normal Normal
Reporter: Gary Larizza

Puppet Version:  Demonstrated on 6.14.0
Puppet Server Version: N/A - validated locally
OS Name/Version: Tested with both CentOS 7 and MacOS 10.15.7

Given the following implementation of a Ruby language data type located at moduleroot/lib/puppet/datatypes/schedule.rb:

 Puppet::DataTypes.create_type('Mytype::Schedule') do
  interface <<-PUPPET
    attributes => {
      "name"   => Mytype::Name,
      "soak_time"       => {
        type  => Timespan,
        value => Timespan('hours' => 3),
      },
      "start_time"      => Timestamp,
    }
  PUPPET

 

My intent was to provide a default value for the soak_time attribute so that if a value isn't provided then we would default to a Timespan of 3 hours. When I declare an instance of this type without a soak_time value, I get the following error:

 Evaluation Error: Error while evaluating a Type-Name, The expression <Timespan('hours' => 3)> is not a valid type specification. 

 

I thought that perhaps I was declaring that object incorrectly, so I tried to following declarations for the right side of the 'value' key in the code above and received the following errors:

 

Timespan('0-03:00:00')

Evaluation Error: Error while evaluating a Type-Name, The expression <Timespan('0-03:00:00')> is not a valid type specification.  

 

Timespan.new('0-03:00:00')

Evaluation Error: Error while evaluating a Type-Name, The expression <Timespan.new('03:00:00')> is not a valid type specification. 

 

'0-03:00:00'

Evaluation Error: Error while evaluating a Type-Name, attribute Mytype::Schedule[soak_time] value has wrong type, expects a Timespan value, got String 

 

Timespan['0-03:00:00']

Error while evaluating a Type-Name, attribute Mytype::Schedule[soak_time] value has wrong type, expects a Timespan value, got Type[Timespan] 

 

Puppet::Pops::Time::Timespan.parse('0-03:00:00')

 Error while evaluating a Type-Name, The expression <Puppet::Pops::Time::Timespan.parse('0-03:00:00')> is not a valid type specification. 

 

At this point I tried to be clever and instantiate a variable holding a Timespan object, and then pass that in to the interface HEREDOC string:

Puppet::DataTypes.create_type('Mytype::Schedule') do
  @timespan = Puppet::Pops::Time::Timespan.parse('0-03:00:00')
  interface <<-PUPPET
    attributes => {
      "name"   => Mytype::Name,
      "soak_time"       => {
        type  => Timespan,
        value => @timespan,
      },
      "start_time"      => Timestamp,
    }
  PUPPET
 
  load_file 'puppet_x/Mytype/schedule'
 
  implementation_class PuppetX::Mytype::Schedule
end 

 

**That gets you this DIFFERENT error:

 Evaluation Error: Error while evaluating a Type-Name, Data Type Load Error for type 'Mytype::Schedule': can't modify frozen #<Class:#<Puppet::DataTypes::TypeBuilderAPI:0x00007fedbc9bfdf0> 

 

Desired Behavior:

A default value for the data type that contains a Timespan object

Actual Behavior:

So many errors....

 

 

For fun you can view the Slack conversation I had with Henrik Lindberg at this link: https://puppetcommunity.slack.com/archives/C0W1X7ZAL/p1603473374140600

 

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Gary Larizza (Jira)

unread,
Oct 23, 2020, 7:19:03 PM10/23/20
to puppe...@googlegroups.com
Gary Larizza updated an issue
Change By: Gary Larizza
*Puppet Version:*  Demonstrated on 6.14.0
*Puppet Server Version:* N/A - validated locally
*OS Name/Version:* Tested with both CentOS 7 and MacOS 10.15.7


Given the following implementation of a Ruby language data type located at moduleroot/lib/puppet/datatypes/schedule.rb:
{code:java}
Puppet::DataTypes.create_type('Mytype::Schedule') do
  interface <<-PUPPET
    attributes => {
      "name"   => Mytype::Name,
      "soak_time"       => {
        type  => Timespan,
        value => Timespan('hours' => 3),
      },
      "start_time"      => Timestamp,
    }
  PUPPET{code}

 

My intent was to provide a default value for the soak_time attribute so that if a value isn't provided then we would default to a Timespan of 3 hours. When I declare an instance of this type without a soak_time value, I get the following error:
{code:java}
Evaluation Error: Error while evaluating a Type-Name, The expression <Timespan('hours' => 3)> is not a valid type specification. {code}
 

I thought that perhaps I was declaring that object incorrectly, so I tried
to the following declarations for the right side of the 'value' key in the code above and received the following errors:

 

*Timespan('0-03:00:00')*
{code:java}

Evaluation Error: Error while evaluating a Type-Name, The expression <Timespan('0-03:00:00')> is not a valid type specification.  {code}
 

*Timespan.new('0-03:00:00')*
{code:java}

Evaluation Error: Error while evaluating a Type-Name, The expression <Timespan.new('03:00:00')> is not a valid type specification. {code}
 

*'0-03:00:00'*
{code:java}

Evaluation Error: Error while evaluating a Type-Name, attribute Mytype::Schedule[soak_time] value has wrong type, expects a Timespan value, got String {code}
 

*Timespan['0-03:00:00']*
{code:java}

Error while evaluating a Type-Name, attribute Mytype::Schedule[soak_time] value has wrong type, expects a Timespan value, got Type[Timespan] {code}
 

*Puppet::Pops::Time::Timespan.parse('0-03:00:00')*
{code:java}

Error while evaluating a Type-Name, The expression <Puppet::Pops::Time::Timespan.parse('0-03:00:00')> is not a valid type specification. {code}

 

At this point I tried to be clever and instantiate a variable holding a Timespan object, and then pass that in to the interface HEREDOC string:
{code:java}
Puppet::DataTypes.create_type('Mytype::Schedule') do
  @timespan = Puppet::Pops::Time::Timespan.parse('0-03:00:00')
  interface <<-PUPPET
    attributes => {
      "name"   => Mytype::Name,
      "soak_time"       => {
        type  => Timespan,
        value => @timespan,
      },
      "start_time"      => Timestamp,
    }
  PUPPET

  load_file 'puppet_x/Mytype/schedule'

  implementation_class PuppetX::Mytype::Schedule
end {code}

 

**That gets you this DIFFERENT error:
{code:java}
Evaluation Error: Error while evaluating a Type-Name, Data Type Load Error for type 'Mytype::Schedule': can't modify frozen #<Class:#<Puppet::DataTypes::TypeBuilderAPI:0x00007fedbc9bfdf0> {code}
 

*Desired Behavior:*


A default value for the data type that contains a Timespan object

*Actual Behavior:*

So many errors....

 

 

For fun you can view the Slack conversation I had with [~henrik.lindberg] at this link: [https://puppetcommunity.slack.com/archives/C0W1X7ZAL/p1603473374140600]

 

Henrik Lindberg (Jira)

unread,
Oct 24, 2020, 7:51:03 AM10/24/20
to puppe...@googlegroups.com
Henrik Lindberg commented on Bug PUP-10727
 
Re: Cannot define a default Timespan value for an attribute in a Ruby language data type

This could be something simple, like the static/constant evaluator used to evaluate the interface specification not handling calls to new as it should.

Mihai Buzgau (Jira)

unread,
Dec 1, 2020, 11:29:03 AM12/1/20
to puppe...@googlegroups.com

Mihai Buzgau (Jira)

unread,
Dec 1, 2020, 11:29:04 AM12/1/20
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Aug 24, 2021, 3:53:03 AM8/24/21
to puppe...@googlegroups.com
Ciprian Badescu updated an issue
Change By: Ciprian Badescu
Sprint: Triaged tickets
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo

Ciprian Badescu (Jira)

unread,
Aug 24, 2021, 3:54:02 AM8/24/21
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Sep 17, 2021, 3:45:03 AM9/17/21
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Sep 20, 2021, 6:50:03 AM9/20/21
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Oct 11, 2021, 10:39:02 AM10/11/21
to puppe...@googlegroups.com

Nirupama Mantha (Jira)

unread,
Feb 22, 2022, 4:56:01 PM2/22/22
to puppe...@googlegroups.com
Nirupama Mantha updated an issue
Change By: Nirupama Mantha
Team: Coremunity Phoenix
This message was sent by Atlassian Jira (v8.20.2#820002-sha1:829506d)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages