You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by em...@gmail.com on 2011/10/12 22:10:39 UTC
[PATCH] fix cloud entry point xml/json bugs caused by the collection changes
From: Tong Li <li...@us.ibm.com>
---
server/views/cimi/cloudEntryPoint/index.xml.haml | 7 +++----
1 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/server/views/cimi/cloudEntryPoint/index.xml.haml b/server/views/cimi/cloudEntryPoint/index.xml.haml
index a8f0fce..75c772a 100644
--- a/server/views/cimi/cloudEntryPoint/index.xml.haml
+++ b/server/views/cimi/cloudEntryPoint/index.xml.haml
@@ -4,7 +4,6 @@
%name cloud entry point
%description cloud entry point
%created= Time.new.getutc.to_s
- - @all_apis.each do |api|
- - if api != :cloudEntryPoint
- - path_name = api.to_s.gsub(/[A-Z]/, '_\0').downcase
- = "<#{api.to_s.pluralize} href=\"#{api_url_for(path_name)}\"/>"
\ No newline at end of file
+ - @collections.each do |api|
+ - res_name = api[0].to_s.gsub(/_[a-z]/) { |match| match[1].to_s.upcase }
+ = "<#{res_name} href=\"#{api[1]}\"/>"
\ No newline at end of file
--
1.7.4.1
Re: [PATCH] fix cloud entry point xml/json bugs caused by the collection
changes
Posted by Tong Li <li...@us.ibm.com>.
Tong Li
Emerging Technologies & Standards
B062/K317
litong01@us.ibm.com
David Lutterkort <lu...@redhat.com> wrote on 10/13/2011 12:07:29 PM:
> From: David Lutterkort <lu...@redhat.com>
> To: deltacloud-dev@incubator.apache.org
> Date: 10/13/2011 12:32 PM
> Subject: Re: [PATCH] fix cloud entry point xml/json bugs caused by
> the collection changes
>
> On Thu, 2011-10-13 at 11:04 -0400, Tong Li wrote:
> > Yes, I have been using Ruby 1.9.
>
> I am glad to know that DC works on 1.9 ;)
>
> Can you confirm that "ab"[1].chr.upcase == "A" on 1.9 ?
I assume that you want to confirm "ab"[1].chr.upcase == "B" not "A", which
it does on 1.9
see this screen capture
irb(main):001:0> "ab"[1].chr.upcase
=> "B"
>
> David
>
>
Re: [PATCH] fix cloud entry point xml/json bugs caused by the
collection changes
Posted by David Lutterkort <lu...@redhat.com>.
On Thu, 2011-10-13 at 11:04 -0400, Tong Li wrote:
> Yes, I have been using Ruby 1.9.
I am glad to know that DC works on 1.9 ;)
Can you confirm that "ab"[1].chr.upcase == "A" on 1.9 ?
David
Re: [PATCH] fix cloud entry point xml/json bugs caused by the collection
changes
Posted by Tong Li <li...@us.ibm.com>.
Yes, I have been using Ruby 1.9.
Thanks.
Tong Li
Emerging Technologies & Standards
B062/K317
litong01@us.ibm.com
From: Scott Seago <ss...@redhat.com>
To: deltacloud-dev@incubator.apache.org
Date: 10/13/2011 10:47 AM
Subject: Re: [PATCH] fix cloud entry point xml/json bugs caused by the
collection changes
On 10/13/2011 09:15 AM, Tong Li wrote:
>>> \ No newline at end of file
>>> > > + - @collections.each do|api|
>>> > > + - res_name = api[0].to_s.gsub(/_[a-z]/) {|match| match
>> > [1].to_s.upcase }
>> >
>> > There's a little Ruby surprise for you: match[1] is actually an
integer;
>> > and "ab"[1].to_s.upcase == "98"
> used irb and run "ab"[1].to_s.upcase, I got "B" as I expected. This is
> using Ruby
>
> C:\Users\IBM_ADMIN>irb
> irb(main):001:0> "ab"[1].to_s.upcase
> => "B"
This is a ruby 1.8/1.9 issue.
Looks like David is using Ruby 1.8 and you're using 1.9. The []
operation on string changed between the two:
http://www.ruby-doc.org/core-1.8.6/String.html#method-i-5B-5D
vs.
http://www.ruby-doc.org/core-1.9.2/String.html#method-i-5B-5D
Scott
Re: [PATCH] fix cloud entry point xml/json bugs caused by the collection
changes
Posted by Scott Seago <ss...@redhat.com>.
On 10/13/2011 09:15 AM, Tong Li wrote:
>>> \ No newline at end of file
>>> > > + - @collections.each do|api|
>>> > > + - res_name = api[0].to_s.gsub(/_[a-z]/) {|match| match
>> > [1].to_s.upcase }
>> >
>> > There's a little Ruby surprise for you: match[1] is actually an integer;
>> > and "ab"[1].to_s.upcase == "98"
> used irb and run "ab"[1].to_s.upcase, I got "B" as I expected. This is
> using Ruby
>
> C:\Users\IBM_ADMIN>irb
> irb(main):001:0> "ab"[1].to_s.upcase
> => "B"
This is a ruby 1.8/1.9 issue.
Looks like David is using Ruby 1.8 and you're using 1.9. The []
operation on string changed between the two:
http://www.ruby-doc.org/core-1.8.6/String.html#method-i-5B-5D
vs.
http://www.ruby-doc.org/core-1.9.2/String.html#method-i-5B-5D
Scott
Re: [PATCH] fix cloud entry point xml/json bugs caused by the collection
changes
Posted by Tong Li <li...@us.ibm.com>.
David,
Please see the responses below on match.
Tong Li
Emerging Technologies & Standards
B062/K317
litong01@us.ibm.com
David Lutterkort <lu...@redhat.com> wrote on 10/12/2011 06:28:12 PM:
> From: David Lutterkort <lu...@redhat.com>
> To: deltacloud-dev@incubator.apache.org
> Date: 10/12/2011 06:29 PM
> Subject: Re: [PATCH] fix cloud entry point xml/json bugs caused by
> the collection changes
>
> On Wed, 2011-10-12 at 13:10 -0700, email4tong@gmail.com wrote:
> > From: Tong Li <li...@us.ibm.com>
> >
> > ---
> > server/views/cimi/cloudEntryPoint/index.xml.haml | 7 +++----
> > 1 files changed, 3 insertions(+), 4 deletions(-)
> >
> > diff --git a/server/views/cimi/cloudEntryPoint/index.xml.haml b/
> server/views/cimi/cloudEntryPoint/index.xml.haml
> > index a8f0fce..75c772a 100644
> > --- a/server/views/cimi/cloudEntryPoint/index.xml.haml
> > +++ b/server/views/cimi/cloudEntryPoint/index.xml.haml
> > @@ -4,7 +4,6 @@
> > %name cloud entry point
> > %description cloud entry point
> > %created= Time.new.getutc.to_s
> > - - @all_apis.each do |api|
> > - - if api != :cloudEntryPoint
> > - - path_name = api.to_s.gsub(/[A-Z]/, '_\0').downcase
> > - = "<#{api.to_s.pluralize} href=\"#{api_url_for(path_name)}\"/>"
> > \ No newline at end of file
> > + - @collections.each do |api|
> > + - res_name = api[0].to_s.gsub(/_[a-z]/) { |match| match
> [1].to_s.upcase }
>
> There's a little Ruby surprise for you: match[1] is actually an integer;
> and "ab"[1].to_s.upcase == "98"
used irb and run "ab"[1].to_s.upcase, I got "B" as I expected. This is
using Ruby
C:\Users\IBM_ADMIN>irb
irb(main):001:0> "ab"[1].to_s.upcase
=> "B"
Also, see the following code.
irb(main):005:0> "ab".gsub(/ab/) {|match| match[1].to_s.upcase}
=> "B"
irb(main):001:0> "machine_configurations".gsub(/_[a-z]/) { |match| match
[1].to_s.upcase }
=> "machineConfigurations"
The above both return what were expected. I do not think
"ab"[1].to_s.upcase will return "98" as the code executed showed different
results.
>
> Instead of your patch I am using the one below. I also rebased against
> the latest HEAD and updated the patch series at
> http://people.apache.org/~lutter/patches/dmtf/
>
> From 90c10d96d1265f8f3cc62e9420504299f2ac455d Mon Sep 17 00:00:00 2001
> From: Tong Li <li...@us.ibm.com>
> Date: Wed, 12 Oct 2011 13:10:39 -0700
> Subject: [PATCH] fix cloud entry point xml/json bugs caused by the
collection
> changes
>
>
> Signed-off-by: David Lutterkort <lu...@redhat.com>
> ---
> server/lib/deltacloud/core_ext/string.rb | 5 +++
> server/tests/core_ext/string.rb | 31 +++++++++++
> +++++++++++
> server/views/cimi/cloudEntryPoint/index.xml.haml | 7 ++---
> 3 files changed, 39 insertions(+), 4 deletions(-)
> create mode 100644 server/tests/core_ext/string.rb
>
> diff --git a/server/lib/deltacloud/core_ext/string.rb b/server/lib/
> deltacloud/core_ext/string.rb
> index 42fbad0..1cd79a0 100644
> --- a/server/lib/deltacloud/core_ext/string.rb
> +++ b/server/lib/deltacloud/core_ext/string.rb
> @@ -49,4 +49,9 @@ class String
> tr("-", "_").
> downcase
> end
> +
> +
> + def camelize
> + gsub(/_[a-z]/) { |match| match[1].chr.upcase }
> + end
> end
> diff --git a/server/tests/core_ext/string.rb
b/server/tests/core_ext/string.rb
> new file mode 100644
> index 0000000..dfa57dc
> --- /dev/null
> +++ b/server/tests/core_ext/string.rb
> @@ -0,0 +1,31 @@
> +# Licensed to the Apache Software Foundation (ASF) under one or more
> +# contributor license agreements. See the NOTICE file distributed with
> +# this work for additional information regarding copyright ownership.
The
> +# ASF licenses this file to you 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.
> +#
> +
> +$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', '..')
> +require 'tests/common'
> +
> +require 'deltacloud/drivers'
> +require 'deltacloud/drivers/mock/mock_driver'
> +
> +module DeltacloudUnitTest
> +
> + class StringTest < Test::Unit::TestCase
> + def test_camelize
> + "hello_camel".camelize.should == "helloCamel"
> + "hello_camel_lots_of_humps".camelize.should ==
"helloCamelLotsOfHumps"
> + end
> + end
> +end
> diff --git a/server/views/cimi/cloudEntryPoint/index.xml.haml b/
> server/views/cimi/cloudEntryPoint/index.xml.haml
> index a8f0fce..c39a34d 100644
> --- a/server/views/cimi/cloudEntryPoint/index.xml.haml
> +++ b/server/views/cimi/cloudEntryPoint/index.xml.haml
> @@ -4,7 +4,6 @@
> %name cloud entry point
> %description cloud entry point
> %created= Time.new.getutc.to_s
> - - @all_apis.each do |api|
> - - if api != :cloudEntryPoint
> - - path_name = api.to_s.gsub(/[A-Z]/, '_\0').downcase
> - = "<#{api.to_s.pluralize} href=\"#{api_url_for(path_name)}\"/>"
> \ No newline at end of file
> + - @collections.each do |api|
> + - res_name = api[0].to_s.camelize
> + = "<#{res_name} href=\"#{api[1]}\"/>"
> --
> 1.7.6.4
>
>
>
I've run more tests and they all work as expected. Can we commit?
Thanks.
Re: [PATCH] fix cloud entry point xml/json bugs caused by the
collection changes
Posted by David Lutterkort <lu...@redhat.com>.
On Wed, 2011-10-12 at 13:10 -0700, email4tong@gmail.com wrote:
> From: Tong Li <li...@us.ibm.com>
>
> ---
> server/views/cimi/cloudEntryPoint/index.xml.haml | 7 +++----
> 1 files changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/server/views/cimi/cloudEntryPoint/index.xml.haml b/server/views/cimi/cloudEntryPoint/index.xml.haml
> index a8f0fce..75c772a 100644
> --- a/server/views/cimi/cloudEntryPoint/index.xml.haml
> +++ b/server/views/cimi/cloudEntryPoint/index.xml.haml
> @@ -4,7 +4,6 @@
> %name cloud entry point
> %description cloud entry point
> %created= Time.new.getutc.to_s
> - - @all_apis.each do |api|
> - - if api != :cloudEntryPoint
> - - path_name = api.to_s.gsub(/[A-Z]/, '_\0').downcase
> - = "<#{api.to_s.pluralize} href=\"#{api_url_for(path_name)}\"/>"
> \ No newline at end of file
> + - @collections.each do |api|
> + - res_name = api[0].to_s.gsub(/_[a-z]/) { |match| match[1].to_s.upcase }
There's a little Ruby surprise for you: match[1] is actually an integer;
and "ab"[1].to_s.upcase == "98"
Instead of your patch I am using the one below. I also rebased against
the latest HEAD and updated the patch series at
http://people.apache.org/~lutter/patches/dmtf/
>From 90c10d96d1265f8f3cc62e9420504299f2ac455d Mon Sep 17 00:00:00 2001
From: Tong Li <li...@us.ibm.com>
Date: Wed, 12 Oct 2011 13:10:39 -0700
Subject: [PATCH] fix cloud entry point xml/json bugs caused by the collection
changes
Signed-off-by: David Lutterkort <lu...@redhat.com>
---
server/lib/deltacloud/core_ext/string.rb | 5 +++
server/tests/core_ext/string.rb | 31 ++++++++++++++++++++++
server/views/cimi/cloudEntryPoint/index.xml.haml | 7 ++---
3 files changed, 39 insertions(+), 4 deletions(-)
create mode 100644 server/tests/core_ext/string.rb
diff --git a/server/lib/deltacloud/core_ext/string.rb b/server/lib/deltacloud/core_ext/string.rb
index 42fbad0..1cd79a0 100644
--- a/server/lib/deltacloud/core_ext/string.rb
+++ b/server/lib/deltacloud/core_ext/string.rb
@@ -49,4 +49,9 @@ class String
tr("-", "_").
downcase
end
+
+
+ def camelize
+ gsub(/_[a-z]/) { |match| match[1].chr.upcase }
+ end
end
diff --git a/server/tests/core_ext/string.rb b/server/tests/core_ext/string.rb
new file mode 100644
index 0000000..dfa57dc
--- /dev/null
+++ b/server/tests/core_ext/string.rb
@@ -0,0 +1,31 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you 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.
+#
+
+$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', '..')
+require 'tests/common'
+
+require 'deltacloud/drivers'
+require 'deltacloud/drivers/mock/mock_driver'
+
+module DeltacloudUnitTest
+
+ class StringTest < Test::Unit::TestCase
+ def test_camelize
+ "hello_camel".camelize.should == "helloCamel"
+ "hello_camel_lots_of_humps".camelize.should == "helloCamelLotsOfHumps"
+ end
+ end
+end
diff --git a/server/views/cimi/cloudEntryPoint/index.xml.haml b/server/views/cimi/cloudEntryPoint/index.xml.haml
index a8f0fce..c39a34d 100644
--- a/server/views/cimi/cloudEntryPoint/index.xml.haml
+++ b/server/views/cimi/cloudEntryPoint/index.xml.haml
@@ -4,7 +4,6 @@
%name cloud entry point
%description cloud entry point
%created= Time.new.getutc.to_s
- - @all_apis.each do |api|
- - if api != :cloudEntryPoint
- - path_name = api.to_s.gsub(/[A-Z]/, '_\0').downcase
- = "<#{api.to_s.pluralize} href=\"#{api_url_for(path_name)}\"/>"
\ No newline at end of file
+ - @collections.each do |api|
+ - res_name = api[0].to_s.camelize
+ = "<#{res_name} href=\"#{api[1]}\"/>"
--
1.7.6.4