Need some rspec and ruby assistance please.

24 views
Skip to first unread message

James Perry

unread,
Jan 5, 2015, 1:03:58 PM1/5/15
to puppe...@googlegroups.com
I am trying to add some functionality to the HP-UX user provider module.  In the past I was able to submit changes that allowed it to check for trusted computing and find the password crypt properly.  Unfortunately, even through the password was updated, HP-UX was not resetting the password age back to 0 days.  I have the commands required to do that and the rspec tests work fine on HP-UX boxes, it fails elsewhere as I am using specific commands to test and get data. 

I still cannot seem to wrap my head around what is passed in and how to use rspec to verify the function works on HP-UX without trying to run the command.

I know the trusted method fails to Trusted, I have not fixed that yet as I am trying to figure out how to properly code it so that I can override it in rspec to make sure nothing else is broken.

What I have added to the modify command works by checking if the HP-UX server is trusted or not by running the trusted method.  

I am completely confused on the right ways to make rspec work with the code.  I know the code works on the HP-UX hosts without issue, so that part is functional, I just cannot test it with rspec on Linux. 

Any help / suggestions would be greatly appreciated! 



  def modifycmd(param,value)
     cmd = super(param, value)
     cmd << "-F"
     if self.trusted == "Trusted"
        cmd << ";"
        cmd << "/usr/lbin/modprpw"
        cmd << "-v"
        cmd << "-l"
        cmd << "#{resource.name}"
     end
     cmd
  end

  def trusted
      trusted_sys = %x(/usr/lbin/getprpw root 2>&1)
      if trusted_sys.chomp == "System is not trusted."
         "NotTrusted"
      else
         "Trusted"
      end
  end

     it "should return modprpw for password aging on trusted systems" do
        if provider.trusted == "Trusted"
           provider_class.command(:password).should == "/usr/lbin/modprpw"
        end
     end




Felix Frank

unread,
Jan 5, 2015, 1:23:42 PM1/5/15
to puppe...@googlegroups.com
Hi,

I don't fully understand the issue at hand, but it seems to me that
specs like the one for the gem provider do something similar.

https://github.com/puppetlabs/puppet/blob/master/spec/unit/provider/package/gem_spec.rb#L27

HTH,
Felix

Michael Smith

unread,
Jan 5, 2015, 2:27:46 PM1/5/15
to puppe...@googlegroups.com
Trying to run actual commands that require a specific OS (and verify the expected behavior) is reserved for acceptance tests, not spec tests. There are no HP-UX acceptance tests, but you can look at other acceptance tests and https://github.com/puppetlabs/puppet/blob/master/docs/index.md for guidance on how to write them.

Our testing philosophy is to verify that API commands (such as modifycmd and trusted) perform the operations you expect them to in spec tests; if they interact with the OS we just verify that the expected interaction would be initiated (such as expecting it to attempt to run a command), not that the command actually runs.

If there is interesting OS interaction, then we also write acceptance tests that will be run on a specific OS. As there is no CI infrastructure currently dedicated to HP-UX, the acceptance tests would be mainly for your own benefit.

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/54AAD67F.3020803%40alumni.tu-berlin.de.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages