Commit 1e89d5c1 authored by Samir Noir's avatar Samir Noir 🧀
Browse files

Fix request to kadeployapi when asking for a specific environment

As we can request g5k-api for a specific environment description, it can
be a previous version of that environment. The request to Kadeploy's api
should be without '?last' to get all the available environments.

Fixes bug #13371
parent 5b687732
Pipeline #298611 passed with stages
in 18 minutes and 12 seconds
......@@ -261,10 +261,15 @@ module Grid5000
# environments. When user is anonymous, only list the public environments.
def list(params = nil)
kadeploy_params = {}
latest_only = (params && params.has_key?('latest_only')) ? params['latest_only'] : 'yes'
username = params['user'] if params && params.has_key?('user')
name = params['name'] if params && params.has_key?('name')
arch = params['arch'] if params && params.has_key?('arch')
latest_only = if params[:action] == 'show'
params&.has_key?('latest_only') ? params['latest_only'] : 'yes'
username = params['user'] if params&.has_key?('user')
name = params['name'] if params&.has_key?('name')
arch = params['arch'] if params&.has_key?('arch')
kadeploy_params['last'] = true unless latest_only == 'no' || latest_only == 'false'
kadeploy_params['username'] = username if username
......@@ -198,4 +198,34 @@ describe EnvironmentsController do
'because you are seen as an anonymous one'
describe 'GET /environments/centos7-ppc64-min_2020120219_deploy' do
it 'should return one environment' do
stub_request(:get, @base_expected_uri).
headers: {
'Accept' => 'application/json',
'Host' => 'api-out.local',
'X-Api-User-Cn' => 'snoir'
to_return(status: 200, body: fixture('environments-grenoble.json'), headers: @headers_return)
stub_request(:get, @base_expected_uri + '?username=snoir').
headers: {
'Accept' => 'application/json',
'Host' => 'api-out.local',
'X-Api-User-Cn' => 'snoir',
to_return(status: 200, body: fixture('environments-grenoble-sno.json'), headers: @headers_return)
get :show, params: { site_id: 'grenoble', id: 'centos7-ppc64-min_2020120219_deploy', format: :json }
expect(response.status).to eq(200)
expect(json['links'].length).to eq(2)
expect(json['uid']).to eq('centos7-ppc64-min_2020120219_deploy')
expect(json.length).to eq(17)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment