Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(FM-8342) Handle mocking of localhost #179

Merged
merged 1 commit into from
Sep 6, 2019
Merged

(FM-8342) Handle mocking of localhost #179

merged 1 commit into from
Sep 6, 2019

Conversation

michaeltlombardi
Copy link
Contributor

Prior to this commit it was not possible to mock features when running
acceptance tests against localhost. This is because both specifying the
node name localhost causes bolt to ignore the inventory file and also
litmus passed an empty inventory file when calling the helpers against
localhost as the target node.

This commit makes some extensive additions and patches to the existing
behavior in order to enable mocking localhost during testing:

  • It adds localhost_inventory_hash as a method in inventory_manipulation,
    which will return a valid inventory hash containing only what bolt
    needs to execute locally; it places the node litmus_localhost in
    the local group and specifies the transport as local. This node CAN
    NOT be named localhost or bolt will ignore the inventory file.
  • It adds the target_in_inventory? helper in inventory_manipulation,
    which will check to see if the specified node name is in the inventory
    and return true if it does or false if it does not.
  • It adds the targeting_localhost? helper in serverspec which replaces
    the logic reused throughout the serverspec methods for determining if
    the command is being used against localhost.
  • It updates the logic in the serverspec methods to set the target node
    name to litmus_localhost if the target is localhost, allowing the
    helpers to use the mockable entry in the inventory hash.
  • It updates the logic in the serverspec methods to use the inventory
    file if it exists and to substitute the basic localhost inventory
    hash if it does not.
  • It updates the logic in the serverspec methods to raise an error if
    the target node is not specified in the inventory hash; previously,
    specifying a target not found in the inventory hash could lead to
    errors in the actual execution which could be hard to parse.

These changes make it possible to mock features and other inventory
details when executing acceptance tests against a localhost using the
litmus library.

@michaeltlombardi michaeltlombardi changed the title (FM-8342) Handle mocking of localhost (WIP) (FM-8342) Handle mocking of localhost Sep 4, 2019
@michaeltlombardi
Copy link
Contributor Author

Working my way through rubocop and spec tests, will wrap those up in the AM!

@michaeltlombardi michaeltlombardi changed the title (WIP) (FM-8342) Handle mocking of localhost (FM-8342) Handle mocking of localhost Sep 4, 2019
@michaeltlombardi
Copy link
Contributor Author

Okay, rubocop'd and tested.

This will enable localhost testing but will need to be paired with a small update to the spec_helper_acceptance file:

if targeting_localhost?
  puts 'Running tests against this machine !'
  if File.exist?('inventory.yaml')
    inventory_hash = inventory_hash_from_inventory_file
    unless target_in_inventory?(inventory_hash, 'litmus_localhost')
      inventory_hash['groups'] = inventory_hash['groups'] | localhost_inventory_hash['groups']
      write_to_inventory_file(inventory_hash, 'inventory.yaml')
    end
  else
    write_to_inventory_file(localhost_inventory_hash, 'inventory.yaml')
  end
  if Gem.win_platform?
    set :backend, :cmd
  else
    set :backend, :exec
  end
else
  ...

@michaeltlombardi michaeltlombardi changed the title (FM-8342) Handle mocking of localhost (WIP) (FM-8342) Handle mocking of localhost Sep 4, 2019
@michaeltlombardi michaeltlombardi changed the title (WIP) (FM-8342) Handle mocking of localhost (FM-8342) Handle mocking of localhost Sep 4, 2019
Prior to this commit it was not possible to mock features when running
acceptance tests against localhost. This is because both specifying the
node name localhost causes bolt to ignore the inventory file and also
litmus passed an empty inventory file when calling the helpers against
localhost as the target node.

This commit makes some extensive additions and patches to the existing
behavior in order to enable mocking localhost during testing:

- It adds localhost_inventory_hash as a method in inventory_manipulation,
  which will return a valid inventory hash containing only what bolt
  needs to execute locally; it places the node litmus_localhost in
  the local group and specifies the transport as local. This node CAN
  NOT be named localhost or bolt will ignore the inventory file.
- It adds the target_in_inventory? helper in inventory_manipulation,
  which will check to see if the specified node name is in the inventory
  and return true if it does or false if it does not.
- It adds the targeting_localhost? helper in serverspec which replaces
  the logic reused throughout the serverspec methods for determining if
  the command is being used against localhost.
- It updates the logic in the serverspec methods to set the target node
  name to litmus_localhost if the target is localhost, allowing the
  helpers to use the mockable entry in the inventory hash.
- It updates the logic in the serverspec methods to use the inventory
  file if it exists and to substitute the basic localhost inventory
  hash if it does not.
- It updates the logic in the serverspec methods to raise an error if
  the target node is not specified in the inventory hash; previously,
  specifying a target not found in the inventory hash could lead to
  errors in the actual execution which could be hard to parse.

These changes make it possible to mock features and other inventory
details when executing acceptance tests against a localhost using the
litmus library.
@RandomNoun7 RandomNoun7 merged commit 92adfea into puppetlabs:master Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants