[PUP-6530] create_resources() doesn't include the file or line reference in resources it creates Created: 2016/07/21  Updated: 2016/08/17  Resolved: 2016/08/11

Status: Closed
Project: Puppet
Component/s: Language
Affects Version/s: PUP 4.5.2
Fix Version/s: PUP 4.6.0

Type: Bug Priority: Normal
Reporter: Gary Larizza Assignee: Phong Ly
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Tested on CentOS 6.8 with PE 2016.2.0


Issue Links:
Blocks
is blocked by PUP-5949 Update loaders to load pcore in place... Closed
Template:
Acceptance Criteria:

That file and line information taken from the file/line where the call to create_resources is made is used for the file/line attributes of all resources created by the call.

Epic Link: 4.x TechDebt
Story Points: 1
Sprint: Language 2016-08-10, Language 2016-08-24
Release Notes: Bug Fix
Release Notes Summary: When creating resources using the `create_resources` function there were no file and line information included in the resulting catalog for the resources created by the function. This is now fixed and this will improve downstream tooling that requires such information.

 Description   

Given the following Puppet code:

class system::hashadmins {
  require mysql::server
  ## Defaults
  Mysql_user {
    ensure               => present,
    max_queries_per_hour => 700,
  }
  ## User Data
  $users = {
    'monica@localhost' => {},
    'brad@localhost'   => {},
    'luke@localhost'   => {},
    'zack@localhost'   => {
      'max_queries_per_hour' => 1300,
    },
    'ralph@localhost'  => {
      'ensure' => 'absent',
    }
  }
  ## Call the function
  create_resources('mysql_user', $users)
}

...the resources that are queried look like this coming out of PuppetDB:

{
        "certname": "gary.puppetlabs.vm",
        "environment": "gary",
        "exported": false,
        "file": null,
        "line": null,
        "parameters": {
            "ensure": "present",
            "max_queries_per_hour": 1300
        },
        "resource": "964a8bb11e504402830b17f2818b2a848b5fe4ae",
        "tags": [
            "class",
            "system::hashadmins",
            "hashadmins",
            "system",
            "mysql_user",
            "default",
            "node"
        ],
        "title": "zack@localhost",
        "type": "Mysql_user"
    }

You'll note that the line and file keys are null. This causes issues down the line with coverage reports like the issue that was posted here --> https://github.com/rodjek/rspec-puppet/issues/364



 Comments   
Comment by Henrik Lindberg [ 2016/07/22 ]

Thanks, this is a known problem. There is work in progress on another ticket that adds the file and line numbers for create_reources (PUP-5949) where we have made a major refactoring of how resources are created.

The test case shown here is great to have to verify that the solution in PUP-5949 works as it should.

Comment by Henrik Lindberg [ 2016/07/22 ]

work on this ticket should be minimal - perhaps add tests that file/line is indeed included (it should be since code now passes through the same logic irrespective of how the resource was created (PUP-5949); from the language, or create_resources.

Comment by Henrik Lindberg [ 2016/08/01 ]

I confirmed manually that create_resources after the changes made in PUP-5949 that the catalog now has file/line information for resources created via create_resources (the file/line where the call to create_resources is made is used for all resources created by that call).

Will now write some tests.

Comment by Henrik Lindberg [ 2016/08/03 ]

merged to master at: b6215b1

Comment by Phong Ly [ 2016/08/11 ]

Bug fixed, tested with puppet-agent at SHA 5cb5a639

Steps taken to verify:
1. Installed puppet-agent the SHA above
2. On the puppet agent, PMT to install puppetlabs-mysql module
3. vi /etc/puppetlabs/code/environments/production/manifests/site.pp and added the below content:

/etc/puppetlabs/code/environments/production/manifests/site.pp

node default {
  ## Defaults
  Mysql_user {
    ensure               => present,
    max_queries_per_hour => 700,
  }
  ## User Data
  $users = {
    'monica@localhost' => {},
    'brad@localhost'   => {},
    'luke@localhost'   => {},
    'zack@localhost'   => {
      'max_queries_per_hour' => 1300,
    },
    'ralph@localhost'  => {
      'ensure' => 'absent',
    }
  }
  ## Call the function
  create_resources('mysql_user', $users)
}

Compile catalog on the node

[root@wls25xmxusjeozs ~]# puppet master --compile localhost
Warning: Could not retrieve fact ipaddress
Warning: Host is missing hostname and/or domain: localhost
Notice: Compiled catalog for localhost in environment production in 0.08 seconds
{
  "tags": ["settings","default","node"],
  "name": "localhost",
  "version": 1470946985,
  "code_id": null,
  "catalog_uuid": "9299a631-c5e1-44a4-979e-2eabd015baa6",
.......
{
      "type": "Mysql_user",
      "title": "brad@localhost",
      "tags": ["mysql_user","node","default","class"],
      "file": "/etc/puppetlabs/code/environments/production/manifests/site.pp",
      "line": 20,
      "exported": false,
      "parameters": {
        "ensure": "present",
        "max_queries_per_hour": 700
      }
    },
    {
      "type": "Mysql_user",
      "title": "luke@localhost",
      "tags": ["mysql_user","node","default","class"],
      "file": "/etc/puppetlabs/code/environments/production/manifests/site.pp",
      "line": 20,
      "exported": false,
      "parameters": {
        "ensure": "present",
        "max_queries_per_hour": 700
      }
    },

Line and file references are included in create_resources() as shown above

Generated at Sat Dec 07 15:48:23 PST 2019 using JIRA 7.7.1#77002-sha1:e75ca93d5574d9409c0630b81c894d9065296414.