Bug 1014317

Summary: invalid Rails application name
Product: OpenShift Online Reporter: Marek Mahut <mmahut>
Component: ContainersAssignee: Hiro Asari <hasari>
Status: CLOSED CURRENTRELEASE QA Contact: libra bugs <libra-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 2.xCC: abhgupta, jhadvig, jkeck, mfojtik, yadu
Target Milestone: ---Keywords: UpcomingRelease
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-10-17 13:33:20 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Marek Mahut 2013-10-01 17:26:45 UTC
Description of problem:

When trying to deploy a spree question with name starting with a number, I'm getting following error on the console:

"""
    The initial build for the application failed: Shell command '/sbin/runuser -s /bin/sh 524ad0834382ec9cbd000002 -c "exec /usr/bin/runcon 'unconfined_u:system_r:openshift_t:s0:c0,c1023' /bin/sh -c \"gear postreceive >> /tmp/initial-build.log 2>&1\""' returned an error. rc=255 .Last 10 kB of build output: Stopping MySQL cartridge Stopping Ruby cartridge httpd (no pid file) not running Invalid Rails application name. Please delete this application and re-create it with a name which does not start with numbers An error occurred executing 'gear postreceive' (exit code: 1) Error message: Failed to execute: 'control pre-build' for /var/lib/openshift/524ad0834382ec9cbd000002/ruby For more details about the problem, try running the command again with the '--trace' option.
"""

We need either to fix this or to validate this in the broker (or console/rhc) before trying to build it.

Comment 1 Abhishek Gupta 2013-10-02 22:13:05 UTC
The validation is cartridge specific and is rightly implemented there. The http response code is also 422 and not 5xx.

However, the issue is that the "client_error" messages are being captured by the script executor (oo-spawn ???) and gets encapsulated with other messages in an attempt to make it more meaningful to debug (talk about irony). 

We need a way to be able to distinguish validation (and other user actionable) failures from internal errors/failures so that we do not encapsulate the validation failure messages with additional messages highlighting the script invocation hierarchy.

Comment 2 Abhishek Gupta 2013-10-02 22:13:55 UTC
Would have set the severity of the bug to 'Low' but since this was not on the Broker component, I left the severity as-is for others to decide.

Comment 3 Michal Fojtik 2013-10-03 10:12:28 UTC
After some investigation, I think the problem is the validation in the cartridge. The question is, why do we need to check if the OPENSHIFT_APP_NAME (I mean **not** Rails app name) starts with a number.

1. Rails will not let you create an application that starts with a number, because the name of the application is transformed into a Ruby class name (and in Ruby, the class cannot start with a number)

2. I don't see the reason why we limit the users in the application name... for example, I want to have application '37signal' and inside this gear, I would like to have Rails application with name 'RailsApp'... it should work work.

3. The 'spree' quickstart, is a perfect example of the 2): The spree rails application name is set to 'RailsApp'... thus it should be successfully deployed.

When we dug into this and we also found the original bug (Rails app name..), we found that it is not Rails that is failing but 'rake assets:precompile'... I don't know why (maybe worth more investigation), because this task should not know about the OPENSHIFT_APP_NAME...

Comment 4 Jakub Hadvig 2013-10-03 12:47:20 UTC
This bug is related to: 
https://bugzilla.redhat.com/show_bug.cgi?id=970150
and this PR deals with it:
https://github.com/openshift/origin-server/pull/3762

Problem was in mysql2 gem, which has been also fixed in:
https://github.com/BanzaiMan/mysql2/commit/d7d5eeeef03001786a0cb60bc20c0c20d0015cb9

I have verified it and it works now.

Comment 5 Hiro Asari 2013-10-03 17:33:12 UTC
https://github.com/openshift/origin-server/pull/3762 has been merged, so we should not see this in devenv any longer.

Also, https://github.com/openshift/rails-example/pull/29 has been merged, so new Ruby apps that use the quickstart should not have the problem, either.

https://github.com/brianmario/mysql2/pull/425 is the PR for the upstream fix. (Note that this is not necessary, given the workaround merged in the quickstart.)

Comment 6 Yan Du 2013-10-08 10:44:44 UTC
test on devenv_stage_488,

steps:
1. rhc app create 123 ruby-1.9 postgresql-9.2 --from-code  git://github.com/openshift/rails-example.git

2. make any change in local repo and git push

[root@localhost 123]# git add .; git commit -amp; git push
[master bf617ee] p
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test.log
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 256 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Stopping Ruby cartridge
<----------snip----------------->
remote: Using rails (3.2.13) 
remote: Using sass (3.2.7) 
remote: Using sass-rails (3.2.6) 
remote: Using sqlite3 (1.3.7) 
remote: Using uglifier (1.3.0) 
remote: Your bundle is complete! It was installed into ./vendor/bundle
remote: Starting application 123
remote: Starting Postgres cartridge
remote: server starting
remote: Postgres started
remote: Precompiling with 'bundle exec rake assets:precompile'
remote: /opt/rh/ruby193/root/usr/bin/ruby /var/lib/openshift/5253d2f9f141daf700000060/app-root/runtime/repo/vendor/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
remote: Starting Ruby cartridge
To ssh://5253d2f9f141daf700000060.rhcloud.com/~/git/123.git/
   692dfcb..bf617ee  master -> master

move to verified