-
Notifications
You must be signed in to change notification settings - Fork 900
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
Remove cfme repos from MiqDatabase model #11304
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
476c561
Add migration to move existing repo data to Settings
carbonin e2a4f18
Add migration to remove update_repo_name column from miq_databases
carbonin 7d1c412
Use Settings to set and get the update repo names
carbonin 383c052
Change method signatures to more closely adhere to the previous versions
carbonin 9717fff
Add stub_template_settings for testing access to template config
carbonin 18d08ea
Add specs for new methods around update repos
carbonin 6732bc9
Fix up MiqServer::UpdateManagement specs
carbonin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
43 changes: 43 additions & 0 deletions
43
db/migrate/20160913195129_move_repo_data_from_database_to_settings.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,43 @@ | ||
class MoveRepoDataFromDatabaseToSettings < ActiveRecord::Migration[5.0] | ||
class MiqRegion < ActiveRecord::Base; end | ||
class MiqDatabase < ActiveRecord::Base; end | ||
class SettingsChange < ActiveRecord::Base | ||
serialize :value | ||
end | ||
|
||
SETTING_KEY = "/product/update_repo_names".freeze | ||
|
||
def up | ||
db = MiqDatabase.first | ||
return unless db && my_region | ||
|
||
say_with_time("Moving repo information from miq_databases to Settings") do | ||
repos = db.update_repo_name.split | ||
SettingsChange.create!(settings_hash.merge(:value => repos)) | ||
end | ||
end | ||
|
||
def down | ||
return unless my_region | ||
change = SettingsChange.where(settings_hash).first | ||
return unless change | ||
|
||
say_with_time("Moving repo information from Settings to miq_databases") do | ||
db = MiqDatabase.first | ||
db.update_attributes!(:update_repo_name => change.value.join(" ")) if db | ||
change.delete | ||
end | ||
end | ||
|
||
def my_region | ||
MiqRegion.find_by_region(ApplicationRecord.my_region_number) | ||
end | ||
|
||
def settings_hash | ||
{ | ||
:resource_type => "MiqRegion", | ||
:resource_id => my_region.id, | ||
:key => SETTING_KEY | ||
} | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20160913195130_remove_update_repo_name_from_miq_databases.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,5 @@ | ||
class RemoveUpdateRepoNameFromMiqDatabases < ActiveRecord::Migration[5.0] | ||
def change | ||
remove_column :miq_databases, :update_repo_name, :string | ||
end | ||
end |
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
59 changes: 59 additions & 0 deletions
59
spec/migrations/20160913195129_move_repo_data_from_database_to_settings_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,59 @@ | ||
require_migration | ||
|
||
describe MoveRepoDataFromDatabaseToSettings do | ||
let(:region_stub) { migration_stub(:MiqRegion) } | ||
let(:database_stub) { migration_stub(:MiqDatabase) } | ||
let(:settings_stub) { migration_stub(:SettingsChange) } | ||
|
||
let(:region_number) { ApplicationRecord.my_region_number } | ||
let(:region) { region_stub.find_by_region(region_number) } | ||
let(:repo_string) { "my-repo my-other-repo" } | ||
let(:repo_list) { %w(my-repo my-other-repo) } | ||
|
||
before do | ||
region_id = ApplicationRecord.region_to_range(region_number).first | ||
region_stub.create(:id => region_id, :region => region_number) | ||
end | ||
|
||
migration_context :up do | ||
it "moves the data from miq_databases to the settings" do | ||
database_attrs = { | ||
:session_secret_token => SecureRandom.hex(64), | ||
:csrf_secret_token => SecureRandom.hex(64), | ||
:update_repo_name => repo_string | ||
} | ||
database_stub.create!(database_attrs) | ||
|
||
migrate | ||
|
||
setting_change = settings_stub.where( | ||
:key => described_class::SETTING_KEY, | ||
:resource_id => region.id, | ||
:resource_type => MiqRegion | ||
).first | ||
expect(setting_change.value).to eq(repo_list) | ||
end | ||
end | ||
|
||
migration_context :down do | ||
it "moves the data from the settings to miq_databases" do | ||
database_attrs = { | ||
:session_secret_token => SecureRandom.hex(64), | ||
:csrf_secret_token => SecureRandom.hex(64), | ||
:update_repo_name => nil | ||
} | ||
db = database_stub.create!(database_attrs) | ||
settings_stub.create!( | ||
:key => described_class::SETTING_KEY, | ||
:value => repo_list, | ||
:resource_id => region.id, | ||
:resource_type => MiqRegion | ||
) | ||
|
||
migrate | ||
|
||
db.reload | ||
expect(db.update_repo_name).to eq(repo_string) | ||
end | ||
end | ||
end |
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 the save! is not doing this we need an alternate method that propogates the changes to other servers.
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.
It doesn't look like it is right now. Should I just add a
reload!
at the end of theVmdb::Settings.save!
method?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.
Can we maybe make this change in a follow up so that we can get the migrations in or do you think it is necessary for 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.
Yeah, as discussed, follow this up, For now, this will work for a single appliance.