Commit c5839911 authored by Samir Noir's avatar Samir Noir 🧀
Browse files

Replace kavlan-remote by kavlan-global-remote in vlan API

In Kavlan, global vlans from other sites are called 'kavlan-remote'. To
be more understandable we choose to rename it.
parent b7c9fb8d
Pipeline #181706 passed with stages
in 22 minutes and 4 seconds
......@@ -25,8 +25,10 @@ module Vlans
end
def vlan_exist
if params[:vlan_id]
raise ApplicationController::NotFound, "Vlan #{params[:vlan_id]} does not exist" unless @kavlan.vlan_exist?(params[:vlan_id])
vlan_param = params[:controller] == 'vlans' ? :id : :vlan_id
if params[vlan_param]
raise ApplicationController::NotFound, "Vlan #{params[vlan_param]} does not exist" unless @kavlan.vlan_exist?(params[vlan_param])
end
end
end
......@@ -30,6 +30,7 @@ class VlansController < ApplicationController
}
result['items'].each do |item|
replace_kavlan_remote(item)
item['links'] = links_for_item(item)
end
......@@ -47,6 +48,7 @@ class VlansController < ApplicationController
result = @kavlan.vlan(params[:id])
result.delete('links')
result['links'] = links_for_item(result)
replace_kavlan_remote(result)
respond_to do |format|
format.g5kitemjson { render json: result }
......@@ -154,4 +156,10 @@ class VlansController < ApplicationController
}
]
end
private
def replace_kavlan_remote(item)
item['type'] = 'kavlan-global-remote' if item['type'] == 'kavlan-remote'
end
end
......@@ -138,6 +138,23 @@ describe VlansController do
expect(response.status).to eq(404)
expect(response.body).to eq('Vlan 200 does not exist')
end
it 'vlan should be type kavlan-global-remote' do
stub_request(:get, File.join(@base_expected_uri, '15')).
with(
headers: {
'Accept'=>'application/json',
'Host'=>'api-out.local',
}).
to_return(status: 200, body: fixture('kavlan-rennes-vlan-remote.json'), headers: @headers_return)
get :show, params: { site_id: 'rennes', id: '15', format: :json }
expect(response.status).to eq(200)
expect(json['uid']).to eq('15')
expect(json['type']).to eq('kavlan-global-remote')
end
end
describe 'PUT /vlans/:id/dhcpd' do
......
{"uid":"15","type":"kavlan-remote","links":[{"href":"/3.0/sites/rennes/vlans/15","rel":"self","type":"application/vnd.grid5000.item+json"},{"href":"/3.0/sites/rennes/vlans","rel":"parent","type":"application/vnd.grid5000.collection+json"},{"href":"/3.0/sites/rennes/vlans/15/dhcpd","title":"dhcpd","rel":"member","type":"application/vnd.grid5000.item+json"},{"href":"/3.0/sites/rennes/vlans/15/nodes","title":"nodes","rel":"member","type":"application/vnd.grid5000.item+json"},{"href":"/3.0/sites/rennes/vlans/15/users","title":"users","rel":"member","type":"application/vnd.grid5000.collection+json"}]}
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