Skip to content
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

Data Migration: Ansible Tower Configuration Manager type to Automation Manager #13720

Merged
merged 4 commits into from
Feb 2, 2017

Conversation

jameswnl
Copy link
Contributor

@jameswnl jameswnl commented Jan 31, 2017

Existing AnsibleTower Configruration Manager in the ext_management_systems table will be modified to have the new automation manager type.

@jameswnl
Copy link
Contributor Author

@miq-bot add_labels providers/ansible_tower, enhancement

Copy link
Member

@bdunne bdunne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget about all of the other STI subclasses that were renamed by #13630


def up
say_with_time("Migrating STI_type_of ansible_tower_configuration_managers to automation_managers") do
ExtManagementSystem.where(:type => 'ManageIQ::Providers::AnsibleTower::ConfigurationManager').each do |manager|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use .each in this context, prefer .update_all

ExtManagementSystem.where(
  :type => 'ManageIQ::Providers::AnsibleTower::ConfigurationManager'
).update_all(
  :type => 'ManageIQ::Providers::AnsibleTower::AutomationManager'
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, thanks, done!


def down
say_with_time("Migrating STI_type_of ansible_tower_automation_managers to configuration_managers") do
ExtManagementSystem.where(:type => 'ManageIQ::Providers::AnsibleTower::AutomationManager').each do |manager|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same .update_all

@Fryguy
Copy link
Member

Fryguy commented Jan 31, 2017

Are there any polymorphic tables that also need to be updated? We have a helper for that rename_class_references. Should that be included here as well?

@bdunne
Copy link
Member

bdunne commented Jan 31, 2017

There is an Authentication for a Provider but it shouldn't need to change

@jameswnl
Copy link
Contributor Author

The authentication is related to provider. As shown in the following,

vmdb_dev_2=# select id, name, resource_id, resource_type, type from authentications where resource_type = 'Provider';
 id  |                         name                         | resource_id | resource_type |        type
-----+------------------------------------------------------+-------------+---------------+--------------------
 191 | ManageIQ::Providers::AnsibleTower::Provider Ansible  |           1 | Provider      | AuthUseridPassword
 192 | ManageIQ::Providers::AnsibleTower::Provider Ansible2 |           2 | Provider      | AuthUseridPassword
(2 rows)

We don't need to change those, right?

@Fryguy
Copy link
Member

Fryguy commented Feb 1, 2017

@jameswnl Correct, those are base class so those are fine.


class ExtManagementSystem < ActiveRecord::Base
self.inheritance_column = :_type_disabled
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I take it out, spec will fail as follows. How to fix it?

  1) MigrateAnsibleTowerConfigurationManagerStiTypeToAutomationManager#down migrates Ansible Tower Automation Manager to Configuration Manager type
     Failure/Error: configuration_manager = ExtManagementSystem.find(automation_manager.id)

     ActiveRecord::SubclassNotFound:
       Invalid single-table inheritance type: ManageIQ::Providers::AnsibleTower::ConfigurationManager is not a subclass of ExtManagementSystem

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So once I changed to the configuration_manager.reload.type, the above error won't happen even without the definition of ExtManagementSystem here now.
Removed now. Thanks


migrate

automation_manager = ExtManagementSystem.find(configuration_manager.id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not need this...just do a .reload on configuration_manager:

expect(configuration_manager.reload.type).to eq('ManageIQ::Providers::AnsibleTower::AutomationManager')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Thanks

@Fryguy
Copy link
Member

Fryguy commented Feb 1, 2017

You may also want a test that shows that other existing providers are not affected by this change.

@jameswnl jameswnl force-pushed the tower-migration branch 2 times, most recently from 2afb214 to 1c7866c Compare February 1, 2017 14:26
@jameswnl
Copy link
Contributor Author

jameswnl commented Feb 1, 2017

You may also want a test that shows that other existing providers are not affected by this change.

@Fryguy thanks for reminding. Had that in mind but then it slipped. Now added.

@jameswnl jameswnl force-pushed the tower-migration branch 2 times, most recently from 3e3f353 to 70da838 Compare February 1, 2017 21:55
Copy link
Member

@bdunne bdunne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget about Job and InventoryGroup

@jameswnl
Copy link
Contributor Author

jameswnl commented Feb 2, 2017

@bdunne thanks! Done.

Copy link
Member

@bdunne bdunne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I feel like the tests could be consolidated to only call migrate once per migration_context, but I'm not going to reject it because of that.

@bdunne
Copy link
Member

bdunne commented Feb 2, 2017

Rails/SkipsModelValidations - Avoid using update_all because it skips validations.

This is okay in this context because it's a migration, so:

  • There are no validations on the stub models
  • It is potentially updating many records and is more efficient than updating each record individually

@jameswnl
Copy link
Contributor Author

jameswnl commented Feb 2, 2017

@bdunne I've consolidated the specs.

Copy link
Member

@Fryguy Fryguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bdunne if I don't get to it first, please merge when green.

@miq-bot
Copy link
Member

miq-bot commented Feb 2, 2017

Checked commits jameswnl/manageiq@23ccd69~...ed1bb5f with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 10 offenses detected

db/migrate/20170131160216_migrate_ansible_tower_configuration_manager_sti_type_to_automation_manager.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants