Uploaded image for project: 'Facter'
  1. Facter
  2. FACT-3050

EC2 resolver failing with ruby 2.3.8p459 when token is nil

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: FACT 4.2.1
    • Component/s: None
    • Labels:
    • Template:
    • Team:
      Night's Watch
    • Story Points:
      1
    • Sprint:
      NW - 2021-06-16
    • Method Found:
      Needs Assessment
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      Hide
      This fix checks if the token is nil before sending the HTTP request that
      gathers the needed data to resolve the Ec2 fact. Based on this token the header will be filled accordingly.
      Sending a nil token can result in failing rspec tests.
      Show
      This fix checks if the token is nil before sending the HTTP request that gathers the needed data to resolve the Ec2 fact. Based on this token the header will be filled accordingly. Sending a nil token can result in failing rspec tests.
    • QA Risk Assessment:
      Needs Assessment

      Description

      Running rspec tests using bundle exec rspec --seed 49031 -fd on a Ubuntu vm with ruby 2.3.8p459 fails with following errors:

      Failures:
       
        1) Facter::Resolvers::Ec2 when IMDSv1 behaves like ec2 with common metadata paths returns userdata
           Failure/Error: expect(ec2.resolve(:userdata)).to eql('userdata')
       
             expected: "userdata"
                  got: ""
       
             (compared using eql?)
           Shared Example Group: "ec2" called from ./spec/facter/resolvers/ec2_spec.rb:134
           # ./spec/facter/resolvers/ec2_spec.rb:51:in `block (4 levels) in <top (required)>'
       
        2) Facter::Resolvers::Ec2 when IMDSv1 behaves like ec2 with common metadata paths parses ec2 network/ directory as a multi-level hash
           Failure/Error: expect(ec2.resolve(:metadata)).to match(hash_including(network_hash))
       
             expected {} to match #<RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher:0x000055664e84a1c0 @expected={"network"=>{"interfaces"=>{"macs"=>{"12:34:56:78:9a:bc"=>{"accountId"=>"41234"}}}}}>
             Diff:
             @@ -1,5 +1 @@
             -#<RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher:0x000055664e84a1c0
             - @expected=
             -  {"network"=>
             -    {"interfaces"=>{"macs"=>{"12:34:56:78:9a:bc"=>{"accountId"=>"41234"}}}}}>
           Shared Example Group: "ec2" called from ./spec/facter/resolvers/ec2_spec.rb:134
           # ./spec/facter/resolvers/ec2_spec.rb:83:in `block (4 levels) in <top (required)>'
       
        3) Facter::Resolvers::Ec2 when IMDSv1 behaves like ec2 with common metadata paths fetches the available data
           Failure/Error:
             expect(ec2.resolve(:metadata)).to match(
               {
                 'instance_type' => '',
                 'ami_id' => 'ami-5d2dc934',
                 'security-groups' => "group1\ngroup2"
               }
             )
       
             expected {} to match {"instance_type"=>"", "ami_id"=>"ami-5d2dc934", "security-groups"=>"group1\ngroup2"}
             Diff:
             @@ -1,4 +1 @@
             -"ami_id" => "ami-5d2dc934",
             -"instance_type" => "",
             -"security-groups" => "group1\ngroup2",
           Shared Example Group: "ec2" called from ./spec/facter/resolvers/ec2_spec.rb:134
           # ./spec/facter/resolvers/ec2_spec.rb:89:in `block (4 levels) in <top (required)>'
       
        4) Facter::Resolvers::Ec2 when IMDSv1 behaves like ec2 with common metadata paths recursively fetches all the ec2 metadata
           Failure/Error:
             expect(ec2.resolve(:metadata)).to match(
               {
                 'instance_type' => 'c1.medium',
                 'ami_id' => 'ami-5d2dc934',
                 'security-groups' => "group1\ngroup2"
               }
             )
       
             expected {} to match {"instance_type"=>"c1.medium", "ami_id"=>"ami-5d2dc934", "security-groups"=>"group1\ngroup2"}
             Diff:
             @@ -1,4 +1 @@
             -"ami_id" => "ami-5d2dc934",
             -"instance_type" => "c1.medium",
             -"security-groups" => "group1\ngroup2",
           Shared Example Group: "ec2" called from ./spec/facter/resolvers/ec2_spec.rb:134
           # ./spec/facter/resolvers/ec2_spec.rb:41:in `block (4 levels) in <top (required)>'
       
      Finished in 3.76 seconds (files took 1.74 seconds to load)
      3548 examples, 4 failures
       
      Failed examples:
       
      rspec './spec/facter/resolvers/ec2_spec.rb[1:2:1:1:2]' # Facter::Resolvers::Ec2 when IMDSv1 behaves like ec2 with common metadata paths returns userdata
      rspec './spec/facter/resolvers/ec2_spec.rb[1:2:1:1:3]' # Facter::Resolvers::Ec2 when IMDSv1 behaves like ec2 with common metadata paths parses ec2 network/ directory as a multi-level hash
      rspec './spec/facter/resolvers/ec2_spec.rb[1:2:1:1:4]' # Facter::Resolvers::Ec2 when IMDSv1 behaves like ec2 with common metadata paths fetches the available data
      rspec './spec/facter/resolvers/ec2_spec.rb[1:2:1:1:1]' # Facter::Resolvers::Ec2 when IMDSv1 behaves like ec2 with common metadata paths recursively fetches all the ec2 metadata
      

      GitHub Actions job example: https://github.com/puppetlabs/facter/runs/2764167003?check_suite_focus=true

        Attachments

          Activity

            People

            Assignee:
            dorin.pleava Dorin Pleava
            Reporter:
            luchian.nemes Luchian Nemes
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Zendesk Support