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

Fixes #13485 - API: Allow user to set sync type per repository #5749

Merged
merged 1 commit into from
Feb 5, 2016
Merged

Fixes #13485 - API: Allow user to set sync type per repository #5749

merged 1 commit into from
Feb 5, 2016

Conversation

daviddavis
Copy link
Contributor

@@ -84,6 +84,8 @@ class Repository < Katello::Model
:allow_blank => false,
:message => ->(_, _) { _("must be one of the following: %s") % Katello::RepositoryTypeManager.repository_types.keys.join(', ') }
}
validates :download_policy, inclusion: { in: ::Runcible::Models::Importer::DOWNLOAD_POLICIES }, if: :yum?
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs to be
NameError: uninitialized constant Runcible::Models::YumImporter::DOWNLOAD_POLICIES

@daviddavis daviddavis changed the title [Work in Progress] Fixes #13485 - Allows user to set sync type per repository [Work in Progress] Fixes #13485 - API: Allow user to set sync type per repository Feb 1, 2016
@parthaa
Copy link
Contributor

parthaa commented Feb 1, 2016

I presume tests are getting added..

@cfouant
Copy link
Member

cfouant commented Feb 1, 2016

@parthaa - yes I have a p-r opened against his branch that will add tests and show download_policy for yum repos only.

@@ -0,0 +1,5 @@
class AddDownloadPolicyToKatelloRepositories < ActiveRecord::Migration
def change
add_column :katello_repositories, :download_policy, :string
Copy link
Member

Choose a reason for hiding this comment

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

do you want to set a default in the migraiton?

Copy link
Member

Choose a reason for hiding this comment

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

@jlsherrill Probably not if only valid for yum repos, right?

@daviddavis daviddavis changed the title [Work in Progress] Fixes #13485 - API: Allow user to set sync type per repository Fixes #13485 - API: Allow user to set sync type per repository Feb 2, 2016
class AddDownloadPolicyToKatelloRepositories < ActiveRecord::Migration
def change
add_column :katello_repositories, :download_policy, :string
update "UPDATE katello_repositories SET download_policy = 'on_demand' WHERE content_type = 'yum'"
Copy link
Member

Choose a reason for hiding this comment

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

Could this be done through the ORM? We recently had a similar discussion around this on #5709 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What would be the advantage here of using ORM?

Copy link
Member

Choose a reason for hiding this comment

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

  1. Prevent database specific sequel from being used and letting the ORM handle things properly for us
  2. That's how we tend to do things everywhere else unless they can't be accomplished through the ORM

@@ -6,6 +6,9 @@ extends 'katello/api/v2/common/timestamps'
attributes :content_type
attributes :docker_upstream_name
attributes :unprotected, :full_path, :checksum_type, :container_repository_name
if (@object && @object.yum?) || (@resource.is_a?(Katello::Repository) && @resource.yum?)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ehelms @cfouant had to fix this as @resource could be defined as something other than Repository (e.g. ContentViewFilter). Also, @object isn't defined when the controller renders this directly. Are you cool with this?

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer we just show download policy on all repos. @ehelms your thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

That's fine.

@cfouant
Copy link
Member

cfouant commented Feb 4, 2016

I'd ACK this except I wrote a bunch of it myself. I have tested it a bunch and seems to work for me 👍

@ehelms
Copy link
Member

ehelms commented Feb 5, 2016

Looks like this is going to need a rebase after the cassette regeneration.

end
def change
add_column :katello_repositories, :download_policy, :string
DownloadPolicyRepository.where(content_type: 'yum').update_all(download_policy: 'immediate')
Copy link
Member

Choose a reason for hiding this comment

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

Does this need an upgrade task to change all existing repositories in Pulp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. Pulp defaults to immediate.

@ehelms
Copy link
Member

ehelms commented Feb 5, 2016

I tried to create a repository and ran into:

2016-01-31T07:22:24 [foreman-tasks/action] [E] Validation failed: Download policy is not included in the list (ActiveRecord::RecordInvalid)
 | /home/vagrant/.rvm/gems/ruby-2.2.4/gems/activerecord-4.1.5/lib/active_record/validations.rb:57:in `save!'
 | /home/vagrant/.rvm/gems/ruby-2.2.4/gems/activerecord-4.1.5/lib/active_record/attribute_methods/dirty.rb:29:in `save!'
 | /home/vagrant/.rvm/gems/ruby-2.2.4/gems/activerecord-4.1.5/lib/active_record/transactions.rb:273:in `block in save!'
 | /home/vagrant/.rvm/gems/ruby-2.2.4/gems/activerecord-4.1.5/lib/active_record/transactions.rb:329:in `block in with_transaction_returning_status'
 | /home/vagrant/.rvm/gems/ruby-2.2.4/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/database_statements.rb:199:in `transaction'
 | /home/vagrant/.rvm/gems/ruby-2.2.4/gems/activerecord-4.1.5/lib/active_record/transactions.rb:208:in `transaction'
 | /home/vagrant/.rvm/gems/ruby-2.2.4/gems/activerecord-4.1.5/lib/active_record/transactions.rb:326:in `with_transaction_returning_status'
 | /home/vagrant/.rvm/gems/ruby-2.2.4/gems/activerecord-4.1.5/lib/active_record/transactions.rb:273:in `save!'
 | /home/vagrant/katello/app/lib/katello/lazy_accessor.rb:87:in `save!'
 | /home/vagrant/katello/app/lib/actions/katello/repository/create.rb:7:in `plan'

@daviddavis
Copy link
Contributor Author

Waiting on #5754

@ehelms
Copy link
Member

ehelms commented Feb 5, 2016

I am a bit confused -- if I need all of these PRs for repository creation to work, shouldn't they be combined together?

@daviddavis
Copy link
Contributor Author

The scope of this PR is to get the API working. If we want everything to work (API, UI, etc) it seems like we might as well just create a feature branch?

@ehelms
Copy link
Member

ehelms commented Feb 5, 2016

I don't think we need a feature branch, and best to avoid those where possible. This is how I look at it, if a single PR goes in and breaks basic functionality that's bad. Further, if I need to cherry pick I might end up in a broken state. So I am all in favor of adding in lazy sync changes but where it keeps the lights on.

@daviddavis
Copy link
Contributor Author

It sounds easy in theory but having to address comments across a list of commits is a huge pain. If we get feedback or we need to change something, we either end up with new commits or we have to somehow rebase it into the old commit. Dealing with one or two commits per PR is much easier. Plus we're also dealing with being dependent on the nodes work which we could just merge into our branch even if it's not done. I agree with your idea in theory but in practice it's not as easy.

@ehelms
Copy link
Member

ehelms commented Feb 5, 2016

Let me backup, as you are right I should look at this from the API perspective. Which, fails with the same error as the UI. You argue I need to include download_policy as an attribute in my API call, but the docs do not indicate that it is a required field. Which is why I argue if #5752 accounts for that and fixes the UI that they should all be a single commit.

@daviddavis
Copy link
Contributor Author

Ok I'll add it in. You will need to test from the API unless you check out this commit locally:

cfouant@fb85b41

unprotected = unprotected.nil? ? false : unprotected
download_policy = Setting[:default_download_policy] if download_policy.blank? && yum?
Copy link
Member

Choose a reason for hiding this comment

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

self in this context is a product not a repository thus yum? fails here with no method error. I think you'll need to check the repo_type parameter passed in.

@daviddavis
Copy link
Contributor Author

ACK

@ehelms
Copy link
Member

ehelms commented Feb 5, 2016

LOL this is your own PR.... however

ACK

daviddavis added a commit that referenced this pull request Feb 5, 2016
Fixes #13485 - API: Allow user to set sync type per repository
@daviddavis daviddavis merged commit 856abe8 into Katello:master Feb 5, 2016
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.

6 participants