openshift / origin-server

OpenShift 2 (deprecated)
889 stars 516 forks source link

deployments_controller.rb: Adds check for app deployment mode via REST #6320

Closed thrasher-redhat closed 8 years ago

thrasher-redhat commented 8 years ago

Bug 1104140 BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1104140

Adds additional checks to verify that the app is in the correct deployment mode when deploying via the REST api. Will throw 422 error when attempting to binary deploy in git mode or vice versa.

Adds deployment types to relevant REST api tests to specify deployment mode.

thrasher-redhat commented 8 years ago

EDIT: Disregard; symbols != strings.

Having trouble with the tests for this fix. Heres the tests that I'm running.

# cd openshift-test/broker
# /opt/rh/ruby193/root/usr/bin/ruby -I"lib:test" -I"/opt/rh/ruby193/root/usr/share/gems/gems/rake-0.9.2.2/lib" "/opt/rh/ruby193/root/usr/share/gems/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb" "test/functional/deployments_controller_test.rb"

The current changes fail 2 tests:

# /opt/rh/ruby193/root/usr/bin/ruby -I"lib:test" -I"/opt/rh/ruby193/root/usr/share/gems/gems/rake-0.9.2.2/lib" "/opt/rh/ruby193/root/usr/share/gems/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb" "test/functional/deployments_controller_test.rb"

*** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`.

Run options: 

# Running tests:

...F...F

Finished tests in 6.579429s, 1.2159 tests/s, 4.7117 assertions/s.

  1) Failure:
test_deployment_create_show_list(DeploymentsControllerTest) [/root/openshift-test/broker/test/functional/deployments_controller_test.rb:63]:
Expected response to be a <:created>, but was <422>

  2) Failure:
test_validate_supported_binary_artifact_formats(DeploymentsControllerTest) [/root/openshift-test/broker/test/functional/deployments_controller_test.rb:115]:
Expected response to be a <:success>, but was <422>

8 tests, 31 assertions, 2 failures, 0 errors, 0 skips
Coverage report generated for functional_deployment_controller_test to /root/openshift-test/broker/test/coverage/. 4785 / 12413 LOC (38.55%) covered.

Looking further at /var/log/openshift/broker/test.log, there seem to be the two errors that are coming up.

The first error is in the "deployment create show list" test, shortly after trying to set the deployment type. It looks like no method I've tried to set/change the deployment_type has stuck. There is a post request using a git ref, which hits the error case where a git ref is used when in binary mode. This is particularly odd since the deployment_type should default to git, so it shouldn't be necessary to set it at all. The error from the log is:

2015-11-23 15:44:31.433 [DEBUG] API version 1.7 (pid:8428)
2015-11-23 15:44:31.435 [DEBUG] SUCCESS ACTION=AUTHENTICATE USER_ID=56537aae5dbf3800bd000075 LOGIN=user142070178 IP=0.0.0.0 SCOPES=session Authenticated (pid:8428)
2015-11-23 15:44:31.437 [DEBUG] SUCCESS ACTION=ADD_DEPLOYMENT USER_ID=56537aae5dbf3800bd000075 LOGIN=user142070178 APP_UUID=56537aaf5dbf3800bd000078 DOMAIN=ns142070178 The git ref provided is not compatible with the app deployment type, 'binary'. (pid:8428)
2015-11-23 15:44:31.438 [INFO ] Completed 422 Unprocessable Entity in 5ms (Views: 0.5ms) (pid:8428)

The second error that appears is the ""validate supported binary artifact formats" test. This test goes through several artifacts to check the artifact_url validation. This test fails to succeed when using supported artifact_urls because the app is set to use 'git' deployment here, and it is attempting to deploy a binary artifact. Nothing I've tried so far has changed the deployment type for the test. The error from the logs is as follows:

2015-11-23 15:44:34.601 [DEBUG] API version 1.7 (pid:8428)
2015-11-23 15:44:34.602 [DEBUG] SUCCESS ACTION=AUTHENTICATE USER_ID=56537ab25dbf3800bd000119 LOGIN=user845317157 IP=0.0.0.0 SCOPES=session Authenticated (pid:8428)
2015-11-23 15:44:34.605 [DEBUG] SUCCESS ACTION=ADD_DEPLOYMENT USER_ID=56537ab25dbf3800bd000119 LOGIN=user845317157 APP_UUID=56537ab25dbf3800bd00011c DOMAIN=ns845317157 The binary artifact provided is not compatible with the app deployment type 'git'. (pid:8428)
2015-11-23 15:44:34.606 [INFO ] Completed 422 Unprocessable Entity in 6ms (Views: 0.6ms) (pid:8428)

@twillia and I have spent a few hours now (between 11/20 and 11/23) trying to debug and figure out why the deployment_type isn't changing when we want it to.

Something that I keep coming back to is the ResultIO line that precedes all of these tests. I'm not sure what exactly this stub is doing, and why the same stub that is using :ref is being used in the binary artifact tests.

ResultIO.any_instance.stubs(:deployments).returns([{:id => 1, :ref => "mybranch", :sha1 => "1234", :created_at => Time.now, :activations => [Time.now, Time.now]}])

I'd appreciate any comments on the changes or suggestions on how to fix these tests.

thrasher-redhat commented 8 years ago

[test]

thrasher-redhat commented 8 years ago

Failure due to not all changes being committed. Openshift-bot is restesting with new changes.

tiwillia commented 8 years ago

[merge] plz!

openshift-bot commented 8 years ago

Evaluated for online test up to 8a3183b4b860c9b1de530647ebc6aa6e168d4ec4

openshift-bot commented 8 years ago

Online Merge Results: SUCCESS (https://ci.dev.openshift.redhat.com/jenkins/job/merge_pull_requests/6648/) (Image: devenv_5720)

openshift-bot commented 8 years ago

Evaluated for online merge up to 8a3183b4b860c9b1de530647ebc6aa6e168d4ec4

openshift-bot commented 8 years ago

Online Test Results: SUCCESS (https://ci.dev.openshift.redhat.com/jenkins/job/test_pull_requests/9066/)