Skip to content

Commit

Permalink
Merge branch 'master' into tdd/lib_reorganization
Browse files Browse the repository at this point in the history
* master: (44 commits)
  add rubygem-little-plugger to rhel6 repos
  ...
  • Loading branch information
Petr Chalupa committed Mar 5, 2013
2 parents 9c74afc + 503331c commit 9a165d5
Show file tree
Hide file tree
Showing 35 changed files with 768 additions and 226 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
db/*.sqlite3
db/*.sqlite3-journal
log/*.log
log/*.age
hudson
yard
tmp
Expand Down
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if system('rpm -q rubygem-ruport >/dev/null') && ! defined? JRUBY_VERSION
else
gem 'ruport', '>=1.7.0', :git => 'git://github.com/ruport/ruport.git'
end
#not an actual katello dependency, but
#not an actual katello dependency, but
#Does not pull in hashery, matches RPM
gem 'pdf-reader', '<= 1.1.1'

Expand All @@ -62,6 +62,8 @@ gem "apipie-rails", '>= 0.0.18'

gem 'hooks'

# Better logging (syslog/rolling/trace)
gem 'logging', '>= 1.8.0'

# Load all sub-gemfiles from bundler.d directory
Dir[File.expand_path('bundler.d/*.rb', File.dirname(__FILE__))].each do |bundle|
Expand Down
10 changes: 4 additions & 6 deletions app/controllers/api/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def process_invalid(exception)
end

def record_not_found(exception)
logger.error(pp_exception(exception), :with_backtrace => false)
logger.error(pp_exception(exception))
logger.debug exception.backtrace.join("\n")

respond_to do |format|
Expand Down Expand Up @@ -279,10 +279,8 @@ def labelize_params(params)

protected

if Katello.config.debug_rest
def process_action(method_name, *args)
super(method_name, *args)
Rails.logger.debug "With body: #{response.body}\n"
end
def process_action(method_name, *args)
super(method_name, *args)
Rails.logger.debug "With body: #{response.body}\n"
end
end
12 changes: 9 additions & 3 deletions app/controllers/api/candlepin_proxies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@ class Api::CandlepinProxiesController < Api::ProxiesController

def get
r = ::Resources::Candlepin::Proxy.get(@request_path)
Rails.logger.debug r if Katello.config.debug_cp_proxy
logger.debug r
render :json => r
end

def delete
r = ::Resources::Candlepin::Proxy.delete(@request_path)
Rails.logger.debug r if Katello.config.debug_cp_proxy
logger.debug r
render :json => r
end

def post
r = ::Resources::Candlepin::Proxy.post(@request_path, @request_body)
Rails.logger.debug r if Katello.config.debug_cp_proxy
logger.debug r
render :json => r
end

private

def logger
::Logging.logger['cp_proxy']
end

end
35 changes: 20 additions & 15 deletions app/lib/http_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ def resource_permissions
ResourcePermissions
end

# children must redefine
def logger
raise NotImplementedError
end

def process_response(resp)
Rails.logger.debug "Processing response: #{resp.code}"
Rails.logger.debug resp.body if Katello.config.debug_rest
logger.debug "Processing response: #{resp.code}"
logger.debug resp.body
return resp unless resp.code.to_i >= 400
parsed = {}
message = "Rest exception while processing the call"
Expand All @@ -61,9 +66,9 @@ def process_response(resp)
message = parsed["displayMessage"] if parsed["displayMessage"]
service_code = parsed["code"] if parsed["code"]
rescue => error
Rails.logger.error "Error parsing the body: " << error.backtrace.join("\n")
logger.error "Error parsing the body: " << error.backtrace.join("\n")
if ["404", "500", "502", "503", "504"].member? resp.code.to_s
Rails.logger.error "Remote server status code " << resp.code.to_s
logger.error "Remote server status code " << resp.code.to_s
raise RestClientException,{:message => error.to_s, :service_code => service_code, :code => status_code}, caller
else
raise NetworkException, [resp.code.to_s, resp.body].reject{|s| s.nil? or s.empty?}.join(' ')
Expand All @@ -73,7 +78,7 @@ def process_response(resp)
end

def print_debug_info(a_path, headers={}, payload={})
Rails.logger.debug "Headers: #{headers.to_json}"
logger.debug "Headers: #{headers.to_json}"
# calling to_json on file has side-effects breaking manifest import.
# this fix prevents this problem
payload_to_print = payload.reduce({}) do |h, (k,v)|
Expand All @@ -82,14 +87,14 @@ def print_debug_info(a_path, headers={}, payload={})
else v
end
end
Rails.logger.debug "Body: #{payload_to_print.to_json}"
logger.debug "Body: #{payload_to_print.to_json}"
rescue => e
Rails.logger.debug "Unable to print debug information"
logger.debug "Unable to print debug information"
end

def get(a_path, headers={})
Rails.logger.debug "Resource GET request: #{a_path}"
print_debug_info(a_path, headers) if Katello.config.debug_rest
logger.debug "Resource GET request: #{a_path}"
print_debug_info(a_path, headers)
a_path = URI.encode(a_path)
resource_permissions.before_get_callback(a_path, headers)
client = rest_client(Net::HTTP::Get, :get, a_path)
Expand All @@ -101,8 +106,8 @@ def get(a_path, headers={})
end

def post(a_path, payload={}, headers={})
Rails.logger.debug "Resource POST request: #{a_path}, #{payload}"
print_debug_info(a_path, headers, payload) if Katello.config.debug_rest
logger.debug "Resource POST request: #{a_path}, #{payload}"
print_debug_info(a_path, headers, payload)
a_path = URI.encode(a_path)
resource_permissions.before_post_callback(a_path, payload, headers)
client = rest_client(Net::HTTP::Post, :post, a_path)
Expand All @@ -114,8 +119,8 @@ def post(a_path, payload={}, headers={})
end

def put(a_path, payload={}, headers={})
Rails.logger.debug "Resource PUT request: #{a_path}, #{payload}"
print_debug_info(a_path, headers, payload) if Katello.config.debug_rest
logger.debug "Resource PUT request: #{a_path}, #{payload}"
print_debug_info(a_path, headers, payload)
a_path = URI.encode(a_path)
resource_permissions.before_put_callback(a_path, payload, headers)
client = rest_client(Net::HTTP::Put, :put, a_path)
Expand All @@ -127,8 +132,8 @@ def put(a_path, payload={}, headers={})
end

def delete(a_path=nil, headers={})
Rails.logger.debug "Resource DELETE request: #{a_path}"
print_debug_info(a_path, headers) if Katello.config.debug_rest
logger.debug "Resource DELETE request: #{a_path}"
print_debug_info(a_path, headers)
a_path = URI.encode(a_path)
resource_permissions.before_delete_callback(a_path, headers)
client = rest_client(Net::HTTP::Delete, :delete, a_path)
Expand Down
16 changes: 12 additions & 4 deletions app/lib/resources/candlepin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,24 @@ module Resources
module Candlepin

class Proxy
def self.logger
::Logging.logger['cp_proxy']
end

def self.post path, body
Rails.logger.debug "Sending POST request to Candlepin: #{path}"
logger.debug "Sending POST request to Candlepin: #{path}"
client = CandlepinResource.rest_client(Net::HTTP::Post, :post, path_with_cp_prefix(path))
client.post body, {:accept => :json, :content_type => :json}.merge(User.cp_oauth_header)
end

def self.delete path
Rails.logger.debug "Sending DELETE request to Candlepin: #{path}"
logger.debug "Sending DELETE request to Candlepin: #{path}"
client = CandlepinResource.rest_client(Net::HTTP::Delete, :delete, path_with_cp_prefix(path))
client.delete({:accept => :json, :content_type => :json}.merge(User.cp_oauth_header))
end

def self.get path
Rails.logger.debug "Sending GET request to Candlepin: #{path}"
logger.debug "Sending GET request to Candlepin: #{path}"
client = CandlepinResource.rest_client(Net::HTTP::Get, :get, path_with_cp_prefix(path))
client.get({:accept => :json}.merge(User.cp_oauth_header))
end
Expand All @@ -54,6 +58,10 @@ class CandlepinResource < ::HttpResource
self.ca_cert_file = cfg.ca_cert_file
self.resource_permissions = CandlepinResourcePermissions

def self.logger
::Logging.logger['cp_rest']
end

def self.default_headers
{'accept' => 'application/json',
'accept-language' => I18n.locale,
Expand Down Expand Up @@ -589,7 +597,7 @@ def delete_subscriptions owner_key, product_id
products = ([s['product']] + s['providedProducts'])
products.each do |p|
if p['id'] == product_id
Rails.logger.debug "Deleting subscription: " + s.to_json
logger.debug "Deleting subscription: " + s.to_json
Candlepin::Subscription.destroy s['id']
update_subscriptions = true
end
Expand Down
30 changes: 18 additions & 12 deletions app/lib/resources/foreman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,27 @@ def self.options
{ :base_url => config.url,
:enable_validations => false,
:oauth => { :consumer_key => config.oauth_key,
:consumer_secret => config.oauth_secret } }
:consumer_secret => config.oauth_secret },
:logger => Logging.logger['foreman_rest'] }
end
end

Architecture = ForemanApi::Resources::Architecture.new options
Bookmark = ForemanApi::Resources::Bookmark.new options
Home = ForemanApi::Resources::Home.new options
OperatingSystem = ForemanApi::Resources::OperatingSystem.new options
User = ForemanApi::Resources::User.new options
Domain = ForemanApi::Resources::Domain.new options
SmartProxy = ForemanApi::Resources::SmartProxy.new options
Subnet = ForemanApi::Resources::Subnet.new options
ConfigTemplate = ForemanApi::Resources::ConfigTemplate.new options
ComputeResource = ForemanApi::Resources::ComputeResource.new options
HardwareModel = ForemanApi::Resources::Model.new options
def self.timeout_options
{ :open_timeout => Katello.config.rest_client_timeout,
:timeout => Katello.config.rest_client_timeout }
end

Architecture = ForemanApi::Resources::Architecture.new options, timeout_options
Bookmark = ForemanApi::Resources::Bookmark.new options, timeout_options
Home = ForemanApi::Resources::Home.new options, timeout_options
OperatingSystem = ForemanApi::Resources::OperatingSystem.new options, timeout_options
User = ForemanApi::Resources::User.new options, timeout_options
Domain = ForemanApi::Resources::Domain.new options, timeout_options
SmartProxy = ForemanApi::Resources::SmartProxy.new options, timeout_options
Subnet = ForemanApi::Resources::Subnet.new options, timeout_options
ConfigTemplate = ForemanApi::Resources::ConfigTemplate.new options, timeout_options
ComputeResource = ForemanApi::Resources::ComputeResource.new options, timeout_options
HardwareModel = ForemanApi::Resources::Model.new options, timeout_options

end
end
7 changes: 4 additions & 3 deletions app/lib/util/thread_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def self.set_pulp_config(user_id)
:user => user_id,
:oauth => {:oauth_secret => Katello.config.pulp.oauth_secret,
:oauth_key => Katello.config.pulp.oauth_key },
:logging => {:logger => Rails.logger,
:logging => {:logger => ::Logging.logger['pulp_rest'],
:exception => true,
:debug => true }
}
Expand Down Expand Up @@ -97,8 +97,9 @@ def self.included(base)
end

def thread_locals
# store request uuid (for Rails 3.2+ we can use Request.uuid)
Thread.current[:request_uuid] = request.respond_to?(:uuid) ? request.uuid : SecureRandom.hex(16)
# store request uuid (for Rails 3.2+ we can use Request.uuid) and process pid
uuid = request.respond_to?(:uuid) ? request.uuid : SecureRandom.hex(16)
::Logging.mdc['uuid'] = Thread.current[:request_uuid] = uuid

# store user
u = current_user
Expand Down
2 changes: 1 addition & 1 deletion app/models/async_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def error(job, exception)
s.update_attributes!(
:state => TaskStatus::Status::ERROR,
:finish_time => current_time,
:result => {:errors => [exception.message, exception.backtrace.join("/n")]})
:result => {:errors => [exception.message, exception.backtrace.join("\n")]})
end

def success
Expand Down
2 changes: 1 addition & 1 deletion app/models/glue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
module Glue
singleton_class.send :attr_writer, :logger
def self.logger
@logger ||= Rails.logger
@logger ||= Logging.logger['glue']
end

def self.included(base)
Expand Down
2 changes: 1 addition & 1 deletion app/models/glue/elastic_search/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def self.index_packages pkg_ids
pkg = self.find(pkg_id)
pkg.as_json.merge(pkg.index_options)
}
Tire.index Package.index do
Tire.index ::Package.index do
create :settings => Package.index_settings, :mappings => Package.index_mapping
import pkgs
end if !pkgs.empty?
Expand Down
4 changes: 2 additions & 2 deletions app/models/glue/elastic_search/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def update_related_index
end

def index_packages
Tire.index Package.index do
Tire.index ::Package.index do
create :settings => Package.index_settings, :mappings => Package.index_mapping
end
pkgs = self.packages.collect{|pkg| pkg.as_json.merge(pkg.index_options)}
pkgs.each_slice(Katello.config.pulp.bulk_load_size) do |sublist|
Tire.index Package.index do
Tire.index ::Package.index do
import sublist
end if !sublist.empty?
end
Expand Down
8 changes: 5 additions & 3 deletions app/models/glue/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,11 @@ def failed_products_status
end

def queue_import_manifest zip_file_path, options
output = StringIO.new
import_logger = Logger.new(output)
output = Logging.appenders.string_io.new('manifest_import_appender')
import_logger = Logging.logger['manifest_import_logger']
import_logger.additive = false
import_logger.add_appenders(output)

options.merge!(:import_logger => import_logger)
[Rails.logger, import_logger].each { |l| l.debug "Importing manifest for provider #{name}" }

Expand Down Expand Up @@ -246,7 +249,6 @@ def queue_import_manifest zip_file_path, options
message << _("You can run %s action to fix this. Note that it can take some time to complete." % link)
values.push self.failed_products.size
end
output.rewind
Notify.success message % values,
:request_type => 'providers__update_redhat_provider',
:organization => self.organization,
Expand Down
4 changes: 4 additions & 0 deletions app/models/task_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class Status
end
rescue => e
Rails.logger.debug "Unable to report status change" # minor error
# if logger level is higher than debug logger return false that would cause rollback
# since this is log only callback we must be sure to return true
ensure
return true
end
end
end
Expand Down
10 changes: 6 additions & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,15 @@ def generate_token(column)
end

def log_roles verbs, resource_type, tags, org, any_tags = false
if Katello.config.allow_roles_logging
verbs_str = verbs ? verbs.join(',') :"perform any verb"
tags_str = "any tags"
if tags
tag_str = any_tags ? "any tag in #{tags.join(',')}" : "all the tags in #{tags.join(',')}"
end

org_str = org ? "organization #{org.name} (#{org.name})" :" any organization"
Rails.logger.debug "Checking if user #{username} is allowed to #{verbs_str} in #{resource_type.inspect} " +
"scoped for #{tags_str} in #{org_str}"
end
logger.debug "Checking if user #{username} is allowed to #{verbs_str} in #{resource_type.inspect} " +
"scoped for #{tags_str} in #{org_str}"
end

def create_own_role
Expand Down Expand Up @@ -418,4 +416,8 @@ def generate_remote_id
end
end

def logger
::Logging.logger['roles']
end

end
2 changes: 1 addition & 1 deletion bundler.d/foreman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# them to resolve dependencies (even when groups would be excluded from the list)
if Katello.early_config.katello?
group :foreman do
gem 'foreman_api', '>= 0.0.10'
gem 'foreman_api', '>= 0.1.1'
end
end
Loading

0 comments on commit 9a165d5

Please sign in to comment.