-
Notifications
You must be signed in to change notification settings - Fork 10
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
Parse terraform template & create new service dialog with parsed input vars #75
Parse terraform template & create new service dialog with parsed input vars #75
Conversation
to parse template input/output variables
...dels/manageiq/providers/embedded_terraform/automation_manager/configuration_script_source.rb
Outdated
Show resolved
Hide resolved
...dels/manageiq/providers/embedded_terraform/automation_manager/configuration_script_source.rb
Show resolved
Hide resolved
before do | ||
ENV["TERRAFORM_RUNNER_URL"] = "https://1.2.3.4:7000" | ||
@hello_world_variables_response = JSON.parse(File.read(File.join(__dir__, "../../../../../lib/terraform/runner/data/responses/hello-world-variables-success.json"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want File.join(__dir__, "runner/data/responses/hello-world-variables-success.json")
here also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't do, different subdirectories in the parent directory tree,
Here only reusing already available data file from another spec
Failure/Error: @hello_world_variables_response = JSON.parse(File.read(File.join(__dir__, "runner/data/responses/hello-world-variables-success.json")))
Errno::ENOENT:
No such file or directory @ rb_sysopen - /Users/manoj/git/ManageIQ/manageiq-providers-embedded_terraform/spec/models/manageiq/providers/embedded_terraform/automation_manager/runner/data/responses/hello-world-variables-success.json
# ./spec/models/manageiq/providers/embedded_terraform/automation_manager/configuration_script_source_spec.rb:26:in `read'
...manageiq/providers/embedded_terraform/automation_manager/configuration_script_source_spec.rb
Outdated
Show resolved
Hide resolved
...manageiq/providers/embedded_terraform/automation_manager/configuration_script_source_spec.rb
Outdated
Show resolved
Hide resolved
...manageiq/providers/embedded_terraform/automation_manager/configuration_script_source_spec.rb
Outdated
Show resolved
Hide resolved
@@ -1,3 +1,5 @@ | |||
TERRAFORM_RUNNER_URL = 'https://1.2.3.4:7000'.freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't add constants to the global scope, a better way to do this is to have a let(:terraform_runner_url) { 'https://1.2.3.4:7000' }
inside your RSpec.describe
block so it is available to every test in this file but not globally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g. you can see it is causing issues just while running the tests
** ManageIQ master, codename: Spassky
/home/grare/adam/src/manageiq/manageiq-providers-embedded_terraform/spec/models/manageiq/providers/embedded_terraform/automation_manager/configuration_script_source_spec.rb:1: warning: already initialized constant TERRAFORM_RUNNER_URL
/home/grare/adam/src/manageiq/manageiq-providers-embedded_terraform/spec/lib/terraform/runner_spec.rb:4: warning: previous definition of TERRAFORM_RUNNER_URL was here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
spec/lib/terraform/runner_spec.rb
Outdated
@@ -1,12 +1,15 @@ | |||
require 'webmock/rspec' | |||
require 'json' | |||
|
|||
TERRAFORM_RUNNER_URL = "https://1.2.3.4:7000".freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
Re: |
Rekicking the specs after merging #76 |
Sure, thanks, will do that |
eb8bef6
to
aacd630
Compare
@@ -17,11 +17,28 @@ def self.create_catalog_item(options, _auth_user) | |||
|
|||
transaction do | |||
create_from_options(options).tap do |service_template| | |||
dialog_ids = service_template.send(:create_dialogs, config_info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use send
here? This method doesn't appear to be private and the method name isn't dynamic so I think you can just
dialog_ids = service_template.send(:create_dialogs, config_info) | |
dialog_ids = service_template.create_dialogs(config_info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This came from ansible implementation, myself was puzzled why 'send' ?
simply did not fix what was not broken
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 That's because their create_dialogs instance method is private, that isn't a good reason to use send but that is why it is needed there and not here.
opts = super | ||
return unless options.key?(:config_info) | ||
|
||
self.class.send(:validate_config_info, opts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need to call this method from an instance variable I'd prefer you make it not a private_class_method and not use send
def template_variables( | ||
template_path | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a very long argument list :) can we one-line this?
def template_variables( | |
template_path | |
) | |
def template_variables(template_path) |
@@ -15,7 +17,25 @@ | |||
let(:repos) { Dir.glob(File.join(repo_dir, "*")) } | |||
let(:repo_dir_structure) { %w[hello_world.tf] } | |||
|
|||
let(:hello_world_vars_response) do | |||
JSON.parse(File.read(File.join(__dir__, "../../../../../lib/terraform/runner/data/responses/hello-world-variables-success.json"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also use the engine.root to get a path relative to the top of the plugin
JSON.parse(File.read(File.join(__dir__, "../../../../../lib/terraform/runner/data/responses/hello-world-variables-success.json"))) | |
JSON.parse(ManageIQ::Providers::EmbeddedTerraform::Engine.root.join("spec/lib/terraform/runner/data/responses/hello-world-variables-success.json").read) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments mostly about code style so please follow-up with another PR to address these, but nothing blocking functionality so I'm going to merge to get this going
Dependent: