Skip to content

Commit

Permalink
Fixes #14491 - adding setting to turn lazy sync off
Browse files Browse the repository at this point in the history
  • Loading branch information
John Mitsch committed Apr 12, 2016
1 parent 8b9306e commit a6ec67e
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 13 deletions.
6 changes: 5 additions & 1 deletion app/helpers/katello/concerns/settings_helper_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def value_with_katello(setting)

case setting.name
when "default_download_policy"
edit_select(setting, :value, :select_values => Hash[::Runcible::Models::YumImporter::DOWNLOAD_POLICIES.collect { |p| [p, p] }].to_json)
edit_select(setting, :value, :select_values => default_download_policy_setting_values)
when "katello_default_finish"
edit_select(setting, :value, :select_values => katello_template_setting_values("finish"))
when "katello_default_iPXE"
Expand All @@ -45,6 +45,10 @@ def katello_template_setting_values(name)
templates = ProvisioningTemplate.where(:template_kind => TemplateKind.where(:name => name))
templates.each_with_object({}) { |tmpl, hash| hash[tmpl.name] = tmpl.name }.to_json
end

def default_download_policy_setting_values
Hash[Katello::RepositoryDownloadPolicy.policies.collect { |policy| [policy, policy] }].to_json
end
end
end
end
2 changes: 1 addition & 1 deletion app/models/katello/candlepin/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def kickstart?

def download_policy
if katello_content_type == Repository::YUM_TYPE
Setting[:default_download_policy]
RepositoryDownloadPolicy.default
else
""
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/katello/glue/pulp/repos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def add_repo(label, name, url, repo_type, unprotected = false, gpg = nil, checks
unprotected = unprotected.nil? ? false : unprotected

if download_policy.blank? && repo_type == Repository::YUM_TYPE
download_policy = Setting[:default_download_policy]
download_policy = RepositoryDownloadPolicy.default
end

rel_path = if repo_type == 'docker'
Expand Down
3 changes: 2 additions & 1 deletion app/models/setting/katello.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def self.load_defaults
self.set('pulp_client_key', N_("Path for ssl key used for pulp server auth"), "/etc/pki/katello/private/pulp-client.key"),
self.set('pulp_client_cert', N_("Path for ssl cert used for pulp server auth"), "/etc/pki/katello/certs/pulp-client.crt"),
self.set('remote_execution_by_default', N_("If set to true, use the remote execution over katello-agent for remote actions"), false),
self.set('use_pulp_oauth', N_("use oauth authentication for pulp instead of the default cert based authentication"), false)
self.set('use_pulp_oauth', N_("use oauth authentication for pulp instead of the default cert based authentication"), false),
self.set('enable_deferred_download_policies', N_("Enable deferred download policies for repositories"), true)
].each { |s| self.create! s.update(:category => "Setting::Katello") }
end
true
Expand Down
21 changes: 21 additions & 0 deletions app/services/katello/repository_download_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Katello
class RepositoryDownloadPolicy
class << self
def policies
if !::Foreman.in_rake? && Setting[:enable_deferred_download_policies]
::Runcible::Models::YumImporter::DOWNLOAD_POLICIES
else
["immediate"]
end
end

def default
if policies.include?(Setting[:default_download_policy])
Setting[:default_download_policy]
else
policies.first
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ BASTION_MODULES.push(
'Bastion.sync-plans',
'Bastion.host-collections',
'Bastion.content-hosts',
'Bastion.tasks'
'Bastion.tasks',
'Bastion.settings'
);
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,8 @@
//= require "bastion_katello/activation-keys/activation-keys.module.js"
//= require_tree "./activation-keys"

//= require "bastion_katello/settings/settings.module.js"
//= require_tree "./settings"

//= require "bastion_katello/bastion-katello-bootstrap.js"
//= require "bastion_katello/katello-features.run.js"
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
* @requires CurrentOrganization
* @requires DownloadPolicy
* @requires ApiErrorHandler
* @requires Setting
*
* @description
* Provides the functionality for the repository details pane.
*/
angular.module('Bastion.repositories').controller('RepositoryDetailsInfoController',
['$scope', '$state', '$q', 'translate', 'Repository', 'GPGKey', 'CurrentOrganization', 'DownloadPolicy', 'ApiErrorHandler',
function ($scope, $state, $q, translate, Repository, GPGKey, CurrentOrganization, DownloadPolicy, ApiErrorHandler) {
['$scope', '$state', '$q', 'translate', 'Repository', 'GPGKey', 'CurrentOrganization', 'DownloadPolicy', 'ApiErrorHandler', 'BastionConfig', 'Setting',
function ($scope, $state, $q, translate, Repository, GPGKey, CurrentOrganization, DownloadPolicy, ApiErrorHandler, BastionConfig, Setting) {
var updateRepositoriesTable;

$scope.successMessages = [];
Expand All @@ -36,6 +37,14 @@ angular.module('Bastion.repositories').controller('RepositoryDetailsInfoControll

$scope.progress = {uploading: false};

Setting.get({"search": "name = enable_deferred_download_policies"},
function (data) {
data = angular.fromJson(data);
$scope.enableDownloadPolicies = data.results[0].value;
}, function (data) {
ApiErrorHandler.handleGETRequestErrors(data, $scope);
});

$scope.repository = Repository.get({
'product_id': $scope.$stateParams.productId,
'id': $scope.$stateParams.repositoryId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ <h4 translate>Basic Information</h4>
</div>

<div class="detail" ng-if="repository.content_type == 'yum'">
<span class="info-label" translate>Download Policy</span>
<span class="info-label" translate> Download Policy</span>
<span class="info-value"
bst-edit-select="downloadPolicyDisplay(repository.download_policy)"
readonly="denied('edit_products', product)"
readonly="!(enableDownloadPolicies) || denied('edit_products', product)"
selector="repository.download_policy"
options="downloadPolicies"
options-format="id as name for (id, name) in options"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* Controls the creation of an empty Repository object for use by sub-controllers.
*/
angular.module('Bastion.repositories').controller('NewRepositoryController',
['$scope', 'Repository', 'GPGKey', 'FormUtils', 'translate', 'GlobalNotification',
function ($scope, Repository, GPGKey, FormUtils, translate, GlobalNotification) {
['$scope', 'Repository', 'GPGKey', 'FormUtils', 'translate', 'GlobalNotification', 'BastionConfig', 'Setting', 'ApiErrorHandler',
function ($scope, Repository, GPGKey, FormUtils, translate, GlobalNotification, BastionConfig, Setting, ApiErrorHandler) {

function success(response) {
$scope.detailsTable.rows.push(response);
Expand Down Expand Up @@ -45,6 +45,14 @@ angular.module('Bastion.repositories').controller('NewRepositoryController',
}
}

Setting.get({"search": "name = enable_deferred_download_policies"},
function (data) {
data = angular.fromJson(data);
$scope.enableDownloadPolicies = data.results[0].value;
}, function (data) {
ApiErrorHandler.handleGETRequestErrors(data, $scope);
});

$scope.repository = new Repository({'product_id': $scope.$stateParams.productId, unprotected: true,
'checksum_type': null, 'download_policy': null, 'mirror_on_sync': true});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ <h6 translate>

</div>

<div bst-form-group label="{{ 'Download Policy' | translate }}" ng-show="repository.content_type === 'yum'">
<div bst-form-group label="{{ 'Download Policy' | translate }}"
ng-show="repository.content_type === 'yum' && enableDownloadPolicies">
<select id="download_policy"
name="download_policy"
ng-model="repository.download_policy"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @ngdoc service
* @name Bastion.settings.factory:Setting
*
* @requires BastionResource
*
* @description
* Provides a BastionResource for a Setting.
*/
angular.module('Bastion.settings').factory('Setting',
['BastionResource', function (BastionResource) {
var resource = BastionResource('/api/v2/settings/');
return resource;
}]
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @ngdoc module
* @name Bastion.settings
*
* @description
* Module for settings
*/
angular.module('Bastion.settings', [
'ngResource',
'Bastion',
'Bastion.common'
]);
1 change: 1 addition & 0 deletions engines/bastion_katello/lib/bastion_katello/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Engine < ::Rails::Engine
),
:config => {
'consumerCertRPM' => consumer_cert_rpm,
'enable_deferred_download_policies' => !Foreman.in_rake? && Setting[:enable_deferred_download_policies],
'remoteExecutionPresent' => ::Katello.with_remote_execution?,
'remoteExecutionByDefault' => ::Katello.with_remote_execution? && !Foreman.in_rake?('db:migrate') &&
Setting['remote_execution_by_default']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
describe('Controller: RepositoryDetailsInfoController', function() {
var $scope, $state, translate, repository;
var $scope, $state, Setting, translate, repository;

beforeEach(module(
'Bastion.repositories',
'Bastion.test-mocks'
));

beforeEach(module({
Setting: {
get: function() {
return { results: [{ value: 'true' }]};
}
}
}));

beforeEach(inject(function($injector) {
var $controller = $injector.get('$controller'),
$q = $injector.get('$q'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ describe('Controller: NewRepositoryController', function() {
var $scope,
FormUtils,
GlobalNotification,
Setting,
$httpBackend;

beforeEach(module('Bastion.repositories', 'Bastion.test-mocks'));

beforeEach(module({
Setting: {
get: function() {
return { results: [{ value: 'true' }]};
}
}
}));

beforeEach(inject(function($injector) {
var $controller = $injector.get('$controller'),
$http = $injector.get('$http'),
Expand Down
34 changes: 34 additions & 0 deletions engines/bastion_katello/test/settings/setting.factory.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
describe('Factory: Setting', function () {
var $httpBackend,
setting;

beforeEach(module('Bastion.settings', 'Bastion.test-mocks'));

beforeEach(module(function ($provide) {
setting = {
results: [
{ value: 'true' }
]
};
}));

beforeEach(inject(function ($injector) {
$httpBackend = $injector.get('$httpBackend');
OstreeBranch = $injector.get('Setting');
}));

afterEach(function () {
$httpBackend.flush();
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});

it('provides a way to get a list of repositories', function () {
$httpBackend.expectGET('/api/v2/settings').respond(setting);

OstreeBranch.queryPaged(function (setting) {
expect(setting.results.length).toBeGreaterThan(0);
});
});
});

0 comments on commit a6ec67e

Please sign in to comment.