-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #400 from carbonin/remove_default_configuration_sc…
…ript_sources Remove the local configuration script sources for embedded ansible (cherry picked from commit d425885)
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
db/migrate/20190726204302_remove_local_default_embedded_ansible_repos.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class RemoveLocalDefaultEmbeddedAnsibleRepos < ActiveRecord::Migration[5.1] | ||
class ConfigurationScriptSource < ActiveRecord::Base | ||
include ActiveRecord::IdRegions | ||
self.inheritance_column = :_type_disabled # disable STI | ||
end | ||
|
||
class GitRepository < ActiveRecord::Base; end | ||
|
||
CONFIGURATION_SCRIPT_TYPE = "ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScriptSource".freeze | ||
|
||
def up | ||
css = ConfigurationScriptSource.in_my_region.where(:type => CONFIGURATION_SCRIPT_TYPE).where("scm_url LIKE ? OR scm_url = ?", "%/content/ansible_consolidated", "file:///var/lib/awx_consolidated_source") | ||
|
||
GitRepository.where(:id => css.pluck(:git_repository_id).compact).delete_all | ||
css.delete_all | ||
end | ||
end |
75 changes: 75 additions & 0 deletions
75
spec/migrations/20190726204302_remove_local_default_embedded_ansible_repos_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
require_migration | ||
|
||
describe RemoveLocalDefaultEmbeddedAnsibleRepos do | ||
let(:configuration_script_source_stub) { migration_stub(:ConfigurationScriptSource) } | ||
let(:git_repository_stub) { migration_stub(:GitRepository) } | ||
let(:embedded_ansible_source_type) { "ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScriptSource" } | ||
let(:ansible_tower_source_type) { "ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScriptSource" } | ||
|
||
migration_context :up do | ||
it "removes configuration script sources at /var/lib/awx_consolidated_source" do | ||
source = configuration_script_source_stub.create!( | ||
:type => embedded_ansible_source_type, | ||
:scm_url => "file:///var/lib/awx_consolidated_source" | ||
) | ||
|
||
configuration_script_source_stub.create!( | ||
:type => embedded_ansible_source_type, | ||
:scm_url => "https://example.com/git_repos/playbooks" | ||
) | ||
|
||
migrate | ||
|
||
expect(configuration_script_source_stub.find_by(:id => source.id)).to be_nil | ||
expect(configuration_script_source_stub.count).to eq(1) | ||
expect(configuration_script_source_stub.first.scm_url).to eq("https://example.com/git_repos/playbooks") | ||
end | ||
|
||
it "removes configuration script sources at /content/ansible_consolidated" do | ||
source = configuration_script_source_stub.create!( | ||
:type => embedded_ansible_source_type, | ||
:scm_url => "file:///home/ncarboni/Source/manageiq/content/ansible_consolidated" | ||
) | ||
|
||
configuration_script_source_stub.create!( | ||
:type => embedded_ansible_source_type, | ||
:scm_url => "https://example.com/git_repos/playbooks" | ||
) | ||
|
||
migrate | ||
|
||
expect(configuration_script_source_stub.find_by(:id => source.id)).to be_nil | ||
expect(configuration_script_source_stub.count).to eq(1) | ||
expect(configuration_script_source_stub.first.scm_url).to eq("https://example.com/git_repos/playbooks") | ||
end | ||
|
||
it "removes related git repositories" do | ||
git_repository_stub.create!(:url => "https://example.com/git_repos/playbooks") | ||
|
||
repo = git_repository_stub.create!(:url => "file:///home/ncarboni/Source/manageiq/content/ansible_consolidated") | ||
source = configuration_script_source_stub.create!( | ||
:type => embedded_ansible_source_type, | ||
:scm_url => "file:///home/ncarboni/Source/manageiq/content/ansible_consolidated", | ||
:git_repository_id => repo.id | ||
) | ||
|
||
migrate | ||
|
||
expect(configuration_script_source_stub.find_by(:id => source.id)).to be_nil | ||
expect(git_repository_stub.find_by(:id => repo.id)).to be_nil | ||
expect(git_repository_stub.count).to eq(1) | ||
expect(git_repository_stub.first.url).to eq("https://example.com/git_repos/playbooks") | ||
end | ||
|
||
it "doesn't remove sources for ansible tower" do | ||
tower_source = configuration_script_source_stub.create!( | ||
:type => ansible_tower_source_type, | ||
:scm_url => "file:///home/ncarboni/Source/manageiq/content/ansible_consolidated" | ||
) | ||
|
||
migrate | ||
|
||
expect(configuration_script_source_stub.find_by(:id => tower_source.id)).to_not be_nil | ||
end | ||
end | ||
end |