[PATCH aeolus-image-rubygem 0/1] RFC/Cry for Help: OAuth support in aeolus-image-rubygem
by Matt Wagner
Howdy,
I wanted to send a patch for advance review, primarily to see if anyone had a better course of action to recommend.
I have the innocuous-sounding #2462, 'As a user, I want Conductor to use imagefactory's REST API with oauth.' Since I'd already written a generic OAuth client [1] for Conductor, and since ImageFactory already has a two-legged OAuth server, I assumed this would be a walk in the park.
Where I ran into trouble is that ActiveResource and the OAuth gem (and the client I had build on top of it) don't seem to want to play nicely. Each implements its own 'request' method that ultimately dumps into Net::HTTP. OAuth legitimately needs to own the request, because it has to sign the request before injecting its authentication headers. ActiveResource does some setup and handling in its request method that neither Net::HTTP nor OAuth do.
I tried to implement 'request' in Aeolus::Image::Factory::Base, which feels like the right thing to do. That way I can implement something that generates a signed request with OAuth and that also does the setup that other components in ActiveResource expect.
But as I started, I realized that I don't see how I can make this work. We don't call .request in any of our code; it's far more indirect. When we call, say, Image.find, Aeolus::Image::Factory::Base is nowhere in the chain, so our .request never gets called.
What I ended up doing in this (draft) patch is to monkey-patch ActiveResource::Connection and substitute in our own .request method, which returns all the stuff they want [2] but also signs the request like OAuth does [3]. There are some pretty obvious reasons why this isn't ideal, but it also has the pretty obvious advantage of actually working.
This code still needs some work; as the comments indicate, I need to bring over some of OAuth's error-detection/error-handling code, and, obviously, I need to not have credentials and a URL hard-coded in the method. Plus this module isn't actually being included yet.
What I'm looking for at this point is simply feedback on whether there's a better solution that I'm overlooking. If this pattern is too objectionable, or if there's just a cleaner solution, I'd greatly welcome your feedback before I continue with this approach.
Best,
Matt
[1] https://github.com/aeolusproject/conductor/blob/master/src/lib/oauth_clie...
[2] https://github.com/rails/rails/blob/6b4bbb427455ec1af6bdf0896a62129bd3c8c...
[3] https://github.com/oauth/oauth-ruby/blob/master/lib/oauth/consumer.rb#L151
12 years, 7 months
[PATCH aeolus-image 1/5] Updated model to talk to conductor
by Martyn Taylor
From: Martyn Taylor <mtaylor(a)redhat.com>
---
lib/aeolus_cli.rb | 7 +-
lib/aeolus_image/model/base.rb | 31 +++++
lib/aeolus_image/model/build.rb | 20 +++
lib/aeolus_image/model/image.rb | 77 +------------
lib/aeolus_image/model/image_build.rb | 68 -----------
lib/aeolus_image/model/provider_image.rb | 32 +-----
lib/aeolus_image/model/target_image.rb | 42 +------
lib/aeolus_image/model/template.rb | 29 -----
lib/aeolus_image/model/warehouse_client.rb | 179 ----------------------------
lib/aeolus_image/model/warehouse_model.rb | 162 -------------------------
spec/spec_helper.rb | 5 +-
11 files changed, 65 insertions(+), 587 deletions(-)
create mode 100644 lib/aeolus_image/model/base.rb
create mode 100644 lib/aeolus_image/model/build.rb
delete mode 100644 lib/aeolus_image/model/image_build.rb
delete mode 100644 lib/aeolus_image/model/template.rb
delete mode 100644 lib/aeolus_image/model/warehouse_client.rb
delete mode 100644 lib/aeolus_image/model/warehouse_model.rb
diff --git a/lib/aeolus_cli.rb b/lib/aeolus_cli.rb
index f17ed66..fc71073 100644
--- a/lib/aeolus_cli.rb
+++ b/lib/aeolus_cli.rb
@@ -21,10 +21,9 @@ require File.join(File.dirname(__FILE__), 'aeolus_image/command', 'push_command'
require File.join(File.dirname(__FILE__), 'aeolus_image/command', 'import_command')
require File.join(File.dirname(__FILE__), 'aeolus_image/command', 'delete_command')
require File.join(File.dirname(__FILE__), 'aeolus_image/command', 'config_parser')
-require File.join(File.dirname(__FILE__), 'aeolus_image/model', 'warehouse_client') # Not sure we need this
-require File.join(File.dirname(__FILE__), 'aeolus_image/model', 'warehouse_model') # We may be able to factor this out?
+
+require File.join(File.dirname(__FILE__), 'aeolus_image/model', 'base')
require File.join(File.dirname(__FILE__), 'aeolus_image/model', 'image')
-require File.join(File.dirname(__FILE__), 'aeolus_image/model', 'image_build')
+require File.join(File.dirname(__FILE__), 'aeolus_image/model', 'build')
require File.join(File.dirname(__FILE__), 'aeolus_image/model', 'provider_image')
require File.join(File.dirname(__FILE__), 'aeolus_image/model', 'target_image')
-require File.join(File.dirname(__FILE__), 'aeolus_image/model', 'template')
diff --git a/lib/aeolus_image/model/base.rb b/lib/aeolus_image/model/base.rb
new file mode 100644
index 0000000..692a87a
--- /dev/null
+++ b/lib/aeolus_image/model/base.rb
@@ -0,0 +1,31 @@
+# Copyright 2011 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'active_resource'
+module Aeolus
+ module CLI
+ class Base < ActiveResource::Base
+ self.timeout = 600
+ class << self
+ def instantiate_collection(collection, prefix_options = {})
+ unless collection.kind_of? Array
+ [instantiate_record(collection, prefix_options)]
+ else
+ collection.collect! { |record| instantiate_record(record, prefix_options) }
+ end
+ end
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/lib/aeolus_image/model/build.rb b/lib/aeolus_image/model/build.rb
new file mode 100644
index 0000000..624f18d
--- /dev/null
+++ b/lib/aeolus_image/model/build.rb
@@ -0,0 +1,20 @@
+# Copyright 2011 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+module Aeolus
+ module CLI
+ class Build < Base
+ end
+ end
+end
diff --git a/lib/aeolus_image/model/image.rb b/lib/aeolus_image/model/image.rb
index 73b004e..249009f 100644
--- a/lib/aeolus_image/model/image.rb
+++ b/lib/aeolus_image/model/image.rb
@@ -13,79 +13,8 @@
# limitations under the License.
module Aeolus
- module Image
- class Image < WarehouseModel
- OS = Struct.new(:name, :version, :arch)
-
- @bucket_name = 'images'
-
- def initialize(attrs)
- attrs.each do |k,v|
- if k.to_sym == :latest_build
- sym = :attr_writer
- else
- sym = :attr_accessor
- end
- self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
- send(:"#{k}=", v)
- end
- @xml_body = Nokogiri::XML @body
- end
-
- def template_xml
- unless @template_xml
- begin
- @template_xml = Nokogiri::XML image_builds.first.target_images.first.target_template.body
- rescue
- @template_xml = Nokogiri::XML "<template></template>"
- end
- end
- @template_xml
- end
-
- def latest_pushed_build
- ImageBuild.find(@latest_build) if @latest_build
- end
-
- def image_builds
- ImageBuild.find_all_by_image_uuid(@uuid)
- end
-
- #TODO: We should get the image fields from the object body once we have it defined.
- def name
- unless @name
- @name = @xml_body.xpath("/image/name").text
- if @name.empty?
- @name = template_xml.xpath("/template/name").text
- end
- end
- @name
- end
-
- def os
- unless @os
- @os = OS.new(template_xml.xpath("/template/os/name").text, template_xml.xpath("/template/os/version").text, template_xml.xpath("/template/os/arch").text)
- end
- @os
- end
-
- def description
- unless @description
- @description = template_xml.xpath("/template/description").text
- end
- @description
- end
-
- # Delete this image and all child objects
- def delete!
- begin
- image_builds.each do |build|
- build.delete!
- end
- rescue NoMethodError
- end
- Image.delete(@uuid)
- end
+ module CLI
+ class Image < Base
end
end
-end
+end
\ No newline at end of file
diff --git a/lib/aeolus_image/model/image_build.rb b/lib/aeolus_image/model/image_build.rb
deleted file mode 100644
index b751117..0000000
--- a/lib/aeolus_image/model/image_build.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-# Copyright 2011 Red Hat, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-module Aeolus
- module Image
- class ImageBuild < WarehouseModel
- @bucket_name = 'builds'
-
- def initialize(attrs)
- attrs.each do |k,v|
- if k.to_sym == :image
- sym = :attr_writer
- else
- sym = :attr_accessor
- end
- self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
- send(:"#{k}=", v)
- end
- end
-
- def self.find_all_by_image_uuid(uuid)
- self.set_warehouse_and_bucket if self.bucket.nil?
- self.bucket.objects.map do |wh_object|
- if wh_object.attr('image') == uuid
- ImageBuild.new(wh_object.attrs(wh_object.attr_list))
- end
- end.compact
- end
-
- def image
- Image.find(@image) if @image
- end
-
- def target_images
- TargetImage.all.select {|ti| ti.build and (ti.build.uuid == self.uuid)}
- end
-
- def provider_images
- targets = target_images
- ProviderImage.all.select do |pi|
- targets.include?(pi.target_image)
- end
- end
-
- # Deletes this image and all child objects
- def delete!
- begin
- target_images.each do |ti|
- ti.delete!
- end
- rescue NoMethodError
- end
- ImageBuild.delete(@uuid)
- end
- end
- end
-end
diff --git a/lib/aeolus_image/model/provider_image.rb b/lib/aeolus_image/model/provider_image.rb
index a5f319d..c3d3a52 100644
--- a/lib/aeolus_image/model/provider_image.rb
+++ b/lib/aeolus_image/model/provider_image.rb
@@ -13,34 +13,8 @@
# limitations under the License.
module Aeolus
- module Image
- class ProviderImage < WarehouseModel
- @bucket_name = 'provider_images'
-
- def initialize(attrs)
- attrs.each do |k,v|
- if [:provider, :target_image].include?(k.to_sym)
- sym = :attr_writer
- else
- sym = :attr_accessor
- end
- self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
- send(:"#{k}=", v)
- end
- end
-
- def target_image
- TargetImage.find(@target_image) if @target_image
- end
-
- def provider_name
- @provider
- end
-
- # Deletes this provider image
- def delete!
- ProviderImage.delete(@uuid)
- end
+ module CLI
+ class ProviderImage < Base
end
end
-end
+end
\ No newline at end of file
diff --git a/lib/aeolus_image/model/target_image.rb b/lib/aeolus_image/model/target_image.rb
index c029430..9972372 100644
--- a/lib/aeolus_image/model/target_image.rb
+++ b/lib/aeolus_image/model/target_image.rb
@@ -13,44 +13,8 @@
# limitations under the License.
module Aeolus
- module Image
- class TargetImage < WarehouseModel
- @bucket_name = 'target_images'
-
- def initialize(attrs)
- attrs.each do |k,v|
- if k.to_sym == :build
- sym = :attr_writer
- else
- sym = :attr_accessor
- end
- self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
- send(:"#{k}=", v)
- end
- end
-
- def build
- ImageBuild.find(@build) if @build
- end
-
- def provider_images
- ProviderImage.all.select{|pi| pi.target_image and (pi.target_image.uuid == self.uuid)}
- end
-
- def target_template
- Template.find(@template) if @template
- end
-
- # Deletes this targetimage and all child objects
- def delete!
- begin
- provider_images.each do |pi|
- pi.delete!
- end
- rescue NoMethodError
- end
- TargetImage.delete(@uuid)
- end
+ module CLI
+ class TargetImage < Base
end
end
-end
+end
\ No newline at end of file
diff --git a/lib/aeolus_image/model/template.rb b/lib/aeolus_image/model/template.rb
deleted file mode 100644
index e1ac3cb..0000000
--- a/lib/aeolus_image/model/template.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# Copyright 2011 Red Hat, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-module Aeolus
- module Image
- class Template < WarehouseModel
- @bucket_name = 'templates'
-
- def initialize(attrs)
- attrs.each do |k,v|
- sym = :attr_accessor
- self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
- send(:"#{k}=", v)
- end
- end
- end
- end
-end
diff --git a/lib/aeolus_image/model/warehouse_client.rb b/lib/aeolus_image/model/warehouse_client.rb
deleted file mode 100644
index 7210dd3..0000000
--- a/lib/aeolus_image/model/warehouse_client.rb
+++ /dev/null
@@ -1,179 +0,0 @@
-# Copyright 2011 Red Hat, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-require 'rubygems'
-
-require 'rest-client'
-require 'nokogiri'
-
-#TODO: perform iwhd version-dependent URI mapping
-module Aeolus
- module Image
- module Warehouse
-
- class BucketObject
- attr_reader :key
-
- def initialize(connection, key, bucket)
- @connection = connection
- @key = key
- @bucket = bucket
- @path = "/#{@bucket.name}/#{(a)key}"
- end
-
- def self.create(connection, key, bucket, body, attrs = {})
- obj = new(connection, key, bucket)
- obj.set_body(body)
- obj.set_attrs(attrs)
- obj
- end
-
- def body
- @connection.do_request @path, :plain => true
- end
-
- def set_body(body)
- @connection.do_request @path, :content => body, :method => :put
- end
-
- def attr_list
- result = @connection.do_request @path, :content => 'op=parts', :method => :post
- return result.xpath('/object/object_attr/@name').to_a.map {|item| item.value}
- end
-
- def attrs(list)
- attrs = {}
- list.each do |att|
- next if att.match('-')
- attrs[att] = (@connection.do_request("#{@path}/#{att}", :plain => true) rescue nil)
- end
- attrs
- end
-
- def attr(name)
- attrs([name])[name]
- end
-
- def set_attrs(hash)
- hash.each do |name, content|
- set_attr(name, content)
- end
- end
-
- def set_attr(name, content)
- path = "#{@path}/#{name}"
- @connection.do_request path, :content => content, :method => :put
- end
-
- def delete!
- @connection.do_request @path, :method => :delete
- true
- end
-
- end
-
- class Bucket
- attr_accessor :name
-
- def initialize(name, connection)
- @name = name
- @connection = connection
- end
-
- def to_s
- "Bucket: #{@name}"
- end
-
- def object_names
- result = @connection.do_request "/#{@name}"
- result.xpath('/objects/object').map do |obj|
- obj.at_xpath('./key/text()').to_s
- end
- end
-
- def objects
- object_names.map do |name|
- object(name)
- end
- end
-
- def object(key)
- BucketObject.new @connection, key, self
- end
-
- def create_object(key, body, attrs)
- BucketObject.create(@connection, key, self, body, attrs)
- end
-
- def include?(key)
- object_names.include?(key)
- end
- end
-
- class Connection
- attr_accessor :uri
-
- def initialize(uri)
- @uri = uri
- end
-
- def do_request(path = '', opts={})
- opts[:method] ||= :get
- opts[:content] ||= ''
- opts[:plain] ||= false
- opts[:headers] ||= {}
-
- result = RestClient::Request.execute :method => opts[:method], :url => @uri + path, :payload => opts[:content], :headers => opts[:headers]
-
- return Nokogiri::XML result unless opts[:plain]
- return result
- end
-
- end
-
- class Client
-
- def initialize(uri)
- @connection = Connection.new(uri)
- end
-
- def create_bucket(bucket)
- @connection.do_request "/#{bucket}", :method => :put rescue RestClient::InternalServerError
- Bucket.new(bucket, @connection)
- end
-
- def bucket(bucket)
- Bucket.new bucket, @connection
- end
-
- def buckets
- @connection.do_request.xpath('/api/link[@rel="bucket"]').map do |obj|
- obj.at_xpath('./@href').to_s.gsub(/.*\//, '')
- end
- end
-
- def get_iwhd_version
- result = @connection.do_request.at_xpath('/api[@service="image_warehouse"]/@version')
- raise "Response does not contain <api> tag or version information" if result == nil
- return result.value
- end
-
- def query(bucket_name, query_string)
- @connection.do_request "/#{bucket_name}/_query", {:method => :post, :content => query_string}
- end
- end
-
- end
- end
-end
diff --git a/lib/aeolus_image/model/warehouse_model.rb b/lib/aeolus_image/model/warehouse_model.rb
deleted file mode 100644
index 2586f6d..0000000
--- a/lib/aeolus_image/model/warehouse_model.rb
+++ /dev/null
@@ -1,162 +0,0 @@
-# Copyright 2011 Red Hat, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-module Aeolus
- module Image
- # require 'warehouse_client'
- include Warehouse
- class BucketObjectNotFound < Exception;end
- class BucketNotFound < Exception;end
-
- class WarehouseModel
-
- def ==(other_obj)
- # If the objects have different instance variables defined, they're definitely not ==
- return false unless instance_variables.sort == other_obj.instance_variables.sort
- # Otherwise, ensure that they're all the same
- instance_variables.each do |iv|
- return false unless other_obj.instance_variable_get(iv) == instance_variable_get(iv)
- end
- # They have the same instance variables and values, so they're equal
- true
- end
-
- class << self
- attr_accessor :warehouse, :bucket, :bucket_name
-
- def set_warehouse_and_bucket
- begin
- @@config ||= load_config
- self.warehouse = Warehouse::Client.new(@@config[:iwhd][:url])
- self.bucket = self.warehouse.bucket(@bucket_name)
- rescue
- raise BucketNotFound
- end
- end
-
- def bucket_objects
- self.set_warehouse_and_bucket if self.bucket.nil?
-
- begin
- self.bucket.objects
- rescue RestClient::ResourceNotFound
- []
- end
- end
-
- def first
- obj = bucket_objects.first
- obj ? self.new(obj.attrs(obj.attr_list)) : nil
- end
-
- def last
- obj = bucket_objects.last
- obj ? self.new(obj.attrs(obj.attr_list)) : nil
- end
-
- def all
- bucket_objects.map do |wh_object|
- self.new(wh_object.attrs(wh_object.attr_list))
- end
- end
-
- def find(uuid)
- self.set_warehouse_and_bucket if self.bucket.nil?
- begin
- if self.bucket.include?(uuid)
- self.new(self.bucket.object(uuid).attrs(self.bucket.object(uuid).attr_list))
- else
- nil
- end
- rescue RestClient::ResourceNotFound
- nil
- end
- end
-
- def where(query_string)
- self.set_warehouse_and_bucket if self.bucket.nil?
- self.warehouse.query(@bucket_name, query_string)
- end
-
- def delete(uuid)
- self.set_warehouse_and_bucket if self.bucket.nil?
- begin
- if self.bucket.include?(uuid)
- self.bucket.object(uuid).delete!
- else
- false
- end
- rescue RestClient::ResourceNotFound
- false
- end
- end
-
- protected
- # Copy over entirely too much code to load the config file
- def load_config
- # TODO - Is this always the case? We should probably have /etc/aeolus-cli or something too?
- # Or allow Rails to override this
- @config_location ||= "~/.aeolus-cli"
- begin
- file_str = read_file(@config_location)
- if is_file?(@config_location) && !file_str.include?(":url")
- lines = File.readlines(File.expand_path((a)config_location)).map do |line|
- "#" + line
- end
- File.open(File.expand_path(@config_location), 'w') do |file|
- file.puts lines
- end
- write_file
- end
- write_file unless is_file?(@config_location)
- YAML::load(File.open(File.expand_path(@config_location)))
- rescue Errno::ENOENT
- #TODO: Create a custom exception to wrap CLI Exceptions
- raise "Unable to locate or write configuration file: \"" + @config_location + "\""
- end
- end
-
- def write_file
- example = File.read(File.expand_path(File.dirname(__FILE__) + "/../../examples/aeolus-cli"))
- File.open(File.expand_path(@config_location), 'a+') do |f|
- f.write(example)
- end
- end
-
- def read_file(path)
- begin
- full_path = File.expand_path(path)
- if is_file?(path)
- File.read(full_path)
- else
- return nil
- end
- rescue
- nil
- end
- end
-
- def is_file?(path)
- full_path = File.expand_path(path)
- if File.exist?(full_path) && !File.directory?(full_path)
- return true
- end
- false
- end
-
- end
-
- end
- end
-end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 69b1139..53f43b4 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -16,10 +16,9 @@ $: << File.expand_path(File.join(File.dirname(__FILE__), "../lib/aeolus_image/co
$: << File.expand_path(File.join(File.dirname(__FILE__), "../lib/aeolus_image/model/"))
require 'rubygems'
-require 'warehouse_client'
-require 'warehouse_model'
+require 'base'
require 'image'
-require 'image_build'
+require 'build'
require 'target_image'
require 'provider_image'
require 'config_parser'
--
1.7.6.2
12 years, 7 months
[PATCH conductor] BZ#745193 Adding user email format validation
by Chris Alfonso
This patch adds user email validation back, but it only validates the email
address format if the email isn't nil. Note: when creating a user using the
web app form, when you don't fill the email address in it's "", not nil.
This is intentional, we want to validate emails unless it's nil, which is
the case for ldap user authentication -> user creation.
12 years, 7 months
IMPORTANT Conductor - i18n
by jzigmund@redhat.com
Hi all Conductor developers,
I'd like to request you about i18n, if you add new strings to UI could you
write them as ready to translate (what means put the new strings to en.yml
file)? Also guys who are reviewing patches, that aren't in master yet, please
check if don't contain new strings w/o translations.
Thank you,
--
Jozef Zigmund
12 years, 7 months
[PATCH conductor] Fixed hardware profile override range value
by Jan Provazník
From: Jan Provaznik <jprovazn(a)redhat.com>
If front end value is out of back end range, first/last range value
is returned instead of front end value.
---
src/app/models/hardware_profile.rb | 9 ++++++++-
src/spec/models/hardware_profile_spec.rb | 2 ++
2 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/src/app/models/hardware_profile.rb b/src/app/models/hardware_profile.rb
index cfe7022..1e3e599 100644
--- a/src/app/models/hardware_profile.rb
+++ b/src/app/models/hardware_profile.rb
@@ -161,7 +161,14 @@ class HardwareProfile < ActiveRecord::Base
when "fixed"
return back_end_property.value
when "range"
- return front_end_property.value.present? ? front_end_property.value : back_end_property.value
+ val = BigDecimal.new(front_end_property.value.to_s)
+ if val < BigDecimal.new(back_end_property.range_first.to_s)
+ return back_end_property.range_first.to_s
+ elsif val > BigDecimal.new(back_end_property.range_last.to_s)
+ return back_end_property.range_last.to_s
+ else
+ return front_end_property.value.to_s
+ end
when "enum"
create_array_from_property(back_end_property).sort!.each do |value|
if front_end_property.value.nil? or BigDecimal.new(value) >= BigDecimal.new(front_end_property.value)
diff --git a/src/spec/models/hardware_profile_spec.rb b/src/spec/models/hardware_profile_spec.rb
index 6fef1fe..9685706 100644
--- a/src/spec/models/hardware_profile_spec.rb
+++ b/src/spec/models/hardware_profile_spec.rb
@@ -137,6 +137,7 @@ describe HardwareProfile do
it "should generate the correct override property values for a given property" do
front_end_memory = FactoryGirl.create(:hwpp_fixed, :name => 'memory', :unit => 'MB', :value => '2048')
+ front_end_memory2 = FactoryGirl.create(:hwpp_fixed, :name => 'memory', :unit => 'MB', :value => '1.0')
front_end_storage = FactoryGirl.create(:hwpp_fixed, :name => 'storage', :unit => 'GB', :value => '850')
front_end_cpu = FactoryGirl.create(:hwpp_fixed, :name => 'cpu', :unit => 'count', :value => '2')
front_end_architecture = FactoryGirl.create(:hwpp_fixed, :name => 'architecture', :unit => 'label', :value => 'x86_64')
@@ -147,6 +148,7 @@ describe HardwareProfile do
back_end_architecture = FactoryGirl.create(:hwpp_fixed, :name => 'architecture', :unit => 'label', :value => 'x86_64')
HardwareProfile.generate_override_property_value(front_end_memory, back_end_memory).should == '2048'
+ HardwareProfile.generate_override_property_value(front_end_memory2, back_end_memory).should == '1024'
HardwareProfile.generate_override_property_value(front_end_storage, back_end_storage).should == '1500'
HardwareProfile.generate_override_property_value(front_end_cpu, back_end_cpu).should == '2'
end
--
1.7.6
12 years, 7 months
Script for setting up repos for dev
by Martyn Taylor
Gentlemen,
I've created and attached a script for checking out aeolus repos,
setting up the relevant git hooks, git config files etc...
I've sent this to the list in many variations in the past, however it
got outdated and I started to set this stuff up manually, and have since
found I'm make mistakes, so I decided to update it and make it a little
more user friendly so others can use it too.
Basically this script will:
1) Check out any aeolus-repo you specify
2) set up all the git hooks
3) copy in a git config file
To set up just unzip it where ever you want it installed.
Then just run `aeolus-git --<repo1> --<repo2>`
It will clone what ever repos you specify in the command options.
Specifying no arguments means clone them all.
Default behaviour is to setup all hooks. If you want to turn off any
hooks you can set them as false in top of of the aeoluis-git script. It
also copies over the git configs from aeolus-git/<repo>/gitconfig. Edit
each file with whatever you want to include in your config. I've
shipped with some sensible defaults , though they're not tested so best
to check.
aeolus-git --help for usage instructions
Any questions on how to use/setup, just ping me.
Cheers
Martyn
12 years, 7 months