From 4a9892257aa6d803624f1fb80e0c78ab7646b200 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Mon, 5 Aug 2024 17:24:17 +0100 Subject: [PATCH] (bug) - Fix empty inventory this provides a default inventory location in the event that one is not supplied to the provision service task. --- tasks/provision_service.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tasks/provision_service.rb b/tasks/provision_service.rb index c6c9836..4201395 100755 --- a/tasks/provision_service.rb +++ b/tasks/provision_service.rb @@ -145,10 +145,22 @@ def tear_down(node_name, inventory, _vars, retry_attempts) response.to_json end + # Runs the provision or tear_down action based on the provided parameters. + # Expects the following parameters in JSON format from stdin: + # - action: The action to perform ('provision' or 'tear_down'). + # - node_name: The name of the node to provision or tear down. + # - platform: The platform to provision. + # - vars: Additional variables to assign to nodes. + # - retry_attempts: The number of retry attempts for provisioning or tearing down. + # - inventory_location: The location of the inventory file. If not provided, defaults to './spec/fixtures/litmus_inventory.yaml'. + # The result of the action is printed to stdout in JSON format. + # Exits with status 0 on success, or 1 on failure. def self.run params = JSON.parse($stdin.read) params.transform_keys!(&:to_sym) action, node_name, platform, vars, retry_attempts, inventory_location = params.values_at(:action, :node_name, :platform, :vars, :retry_attempts, :inventory) + + inventory_location ||= File.join(Dir.pwd, '/spec/fixtures/litmus_inventory.yaml') inventory = InventoryHelper.open(inventory_location) runner = new