-
Notifications
You must be signed in to change notification settings - Fork 11
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
Sync Terraform Templates from git repo #5
Conversation
...dels/manageiq/providers/embedded_terraform/automation_manager/configuration_script_source.rb
Outdated
Show resolved
Hide resolved
app/models/manageiq/providers/embedded_terraform/automation_manager/template.rb
Outdated
Show resolved
Hide resolved
...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
Outdated
Show resolved
Hide resolved
...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
...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
Outdated
Show resolved
Hide resolved
@putmanoj |
...dels/manageiq/providers/embedded_terraform/automation_manager/configuration_script_source.rb
Outdated
Show resolved
Hide resolved
TODO before merge:
|
...manageiq/providers/embedded_terraform/automation_manager/configuration_script_source_spec.rb
Outdated
Show resolved
Hide resolved
...dels/manageiq/providers/embedded_terraform/automation_manager/configuration_script_source.rb
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
@putmanoj I added some tests and made a few changes to the existing ones on my fork: master...jrafanie:manageiq-providers-embedded_terraform:git-sync-templates you can cherry-pick them or I can help you bring them over. Let me know what you think. |
Thanks, will cherry-pick. |
|
||
# checkout files to temp dir, we need for parsing input/output vars | ||
git_checkout_tempdir = Dir.mktmpdir("terraform-git") | ||
checkout_git_repository(git_checkout_tempdir) |
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.
Technically this isn't necessary - everything should be available from the worktree. However, I admit that working with rugged objects is complicated, so this is fine for now.
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.
Also will this checkout happen on every refresh? I feel like that could be expensive. 🤔
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.
Is the update or the checkout expensive? Maybe just doing the checkout would be ok if it's already cloned.
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.
checkout can be expensive. Under the covers we do bare repos, so it's literally having to do I/O for all of the files each time. This is why straight Rugged is better, because it's all in-memory and doesn't require creating a file.
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.
For review
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.
@putmanoj can you review this and comment here? Thanks.
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.
TODO use GitWorktree
next unless filepath.end_with?(".tf", ".tf.json") | ||
|
||
parent_dir = File.dirname(filepath) | ||
name = ManageIQ::Providers::EmbeddedTerraform::AutomationManager::ConfigurationScriptSource.template_name_from_git_repo_url( |
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.
name = ManageIQ::Providers::EmbeddedTerraform::AutomationManager::ConfigurationScriptSource.template_name_from_git_repo_url( | |
name = self.class.template_name_from_git_repo_url( |
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.
Should be resolved
next if template_dirs.key?(name) | ||
|
||
full_path = File.join(git_checkout_tempdir, parent_dir) | ||
_log.info("Local full path : #{full_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.
Do we need this line? I'm concerned it will flood the logs. Perhaps make it debug?
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.
Should be resolved
_log.info("Local full path : #{full_path}") | ||
files = Dir.children(full_path) | ||
|
||
# :TODO add parsing for input/output vars |
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.
# :TODO add parsing for input/output vars | |
# TODO: add parsing for input/output vars |
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.
Should be resolved
def get_default_terraform_object(name) | ||
default_terraform_objects.find_by(:name => name).try(:value).try(:to_i) | ||
end | ||
|
||
def set_default_terraform_object(name, value) | ||
default_terraform_objects.find_or_initialize_by(:name => name).update(:value => value) | ||
end |
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.
These helper methods don't see to be buying anything here - prefer just inlining these methods directly into the callers
(In general, in Ruby, we avoid get_ and set_ methods when a proper getter/setter method like you have on lines 10 and 14 will suffice)
@@ -0,0 +1,20 @@ | |||
class ManageIQ::Providers::EmbeddedTerraform::Provider < Provider | |||
include DefaultTerraformObjects |
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'm not sure I understand why this is a module because I don't see it reused anywhere (or do you plan to reuse in the future? Prefer inlining the methods from the module directly here unless you plan on reuse.
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.
Needs review.
@@ -0,0 +1,27 @@ | |||
module ManageIQ::Providers::EmbeddedTerraform::Provider::DefaultTerraformObjects |
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.
What is the purpose of these default_terraform_objects with respect to syncing terraform templates? I don't see any callers in this PR.
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 this is copy&paste from embedded ansible, it isn't necessary here and should be deleted https://github.com/ManageIQ/manageiq/blob/master/app/models/manageiq/providers/embedded_ansible/provider/default_ansible_objects.rb
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.
Needs review.
@putmanoj Is this built on top of another PR? If so can you indicate that in the opening post? It's hard to follow with 24 commits. |
...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
...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
@putmanoj please rebase on master rather than creating a new merge commit in this branch as it keeps the history cleaner
|
@@ -0,0 +1,20 @@ | |||
class ManageIQ::Providers::EmbeddedTerraform::Provider < Provider |
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'm not sure we need an EmbeddedTerraform::Provider
, this looks like another copy&paste from EmbeddedAnsible
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.
Needs review.
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 removed the included DefaultTerraformObjects
module. It looks like the tests are creating provider/managers through create_in_provider
, and perhaps that's why we have a provider.rb with code that does ensure_managers
. I'm not sure how it's expected to work without a provider.
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.
@@ -0,0 +1,518 @@ | |||
FakeTerraformRepo = Spec::Support::FakeAnsibleRepo # TODO: replace FakeAnsibleRepo with FakeTerraformRepo |
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.
FYI here is an example of a "pluggable" support repo class https://github.com/ManageIQ/manageiq-providers-workflows/blob/master/spec/support/fake_workflows_repo.rb
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.
Should be resolved
repo.git_branch_create("other_branch") | ||
stub_const("GitRepository::GIT_REPO_DIRECTORY", repo_dir) | ||
|
||
EvmSpecHelper.assign_embedded_terraform_role |
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.
EvmSpecHelper.assign_embedded_terraform_role | |
EvmSpecHelper.assign_role("embedded_terraform") |
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.
Should be resolved
expect(result).to be_an(described_class) | ||
expect(result.scm_type).to eq("git") | ||
expect(result.scm_branch).to eq("master") | ||
expect(result.status).to eq("successful") | ||
expect(result.last_updated_on).to be_an(Time) | ||
expect(result.last_update_error).to be_nil |
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.
NOTE you can use have_attributes
to check multiple attributes at once:
expect(result).to have_attributes(
:scm_type => "git",
:scm_branch => "master"
...
)
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.
Should be resolved
|
||
result = described_class.create_in_provider(manager.id, params) | ||
|
||
expect(result).to be_an(described_class) |
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.
Small grammar fix
expect(result).to be_an(described_class) | |
expect(result).to be_a(described_class) |
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.
Should be resolved
expect(result.scm_type).to eq("git") | ||
expect(result.scm_branch).to eq("master") | ||
expect(result.status).to eq("successful") | ||
expect(result.last_updated_on).to be_an(Time) |
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 could probably use be_within
to check the actual timestamp here: expect(result.last_updated_on).to be_within(2.seconds).of(Time.now.utc)
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.
Should be resolved
@putmanoj Ok, I think I resolved all of the comments with my 👍 in them. I think everything but provider.rb. I think that needs to be resolved. Let's remove that module and anything in there we don't need yet. We can add it later. Please review my branch: at master...jrafanie:manageiq-providers-embedded_terraform:git-sync-templates I squashed our fixup commits. My final commits can be combined once you review them. Note, I really deleted a lot of tests because they still passed when I commented out most of the configuration source class so they're not really testing it. I didn't want to push directly to your branch here but mine is correctly tracking upstream here so if you want to use my branch, we can push that. |
LGTM |
4f3d599
to
f8ad986
Compare
ok, @putmanoj, I force pushed to your fork. I've addressed all concerns not yet addressed other than the questions about provider.rb including |
f8ad986
to
78e58f6
Compare
Add relative-path of dir's with .tf/.tf.json files Add specs for git sync * add spec for .create_in_provider * Add EmbeddedTerraform Provider class * add ensure_managers * fixed .create_in_provider test * Use basename of dir, as template-name pre-fix, & full git repo url details as suffix * Add tests for: templates-in-repo update-in-provider update_in_provider_queue delete_in_provider_queue
* Add tests to describe behavior of template_name_from_git_repo_url * Drop templates_for, test both name and payload * We should test the payload contents are correct in addition to the name. * Drop redundant test since we're testing names and payloads * Add test verifying no longer existing payloads are removed on sync * Mark pending tests where we need to set the role in the queue * Create a fake terraform git repo for test
I changed configuration_script_source.rb to: ```ruby class ManageIQ::Providers::EmbeddedTerraform::AutomationManager::ConfigurationScriptSource < ManageIQ::Providers::EmbeddedAutomationManager::ConfigurationScriptSource FRIENDLY_NAME = "Embedded Terraform Repository".freeze def sync end end ``` and all of the removed tests still pass which tells me either the tests aren't needed, the code needs to be implemented and/or the test needs to test what unique behavior is provided by this class.
78e58f6
to
bf0fd97
Compare
Note, #9 was extracted from here |
private_class_method def self.queue_role | ||
"embedded_terraform" | ||
end | ||
|
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 added this to fix the three pending specs in configuration_script_source_spec
I like the changes introduced by Adam and the other code looks good (from a person who doesn't use rugged enough) LGTM |
Sync Terraform Template