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

Merge branch 'bugs/#12190' into 'master'

Refresh fake reference-repository

See merge request !78
parents d681fe5c a08b2342
Pipeline #171579 waiting for manual action with stages
in 21 minutes and 30 seconds
......@@ -157,25 +157,60 @@ to create a test database, and a fake OAR database.
$ RAILS_ENV=test bundle exec rspec spec/ # or `bundle exec autotest` if rake fails (issue with Rails<3.1 and em_mysql2 adapter with evented code).
* Adding data to the reference repository used for tests
* Update reference-repository used for tests
Data used for tests live in the spec/fixtures/reference-repository/
directory. Before any tests, the testing script renames the git.rename
directory to .git, so that spec/fixtures/reference-repository becomes
a valid git repository. It undoes that change at the end of tests.
As the g5k-api code relies on a library that
navigates git objects directly, the only data visible to the tests is
data commited to that repository. Therefore, to change data used for
tests, you must
$ cd spec/fixtures/reference-repository/
$ mv git.rename .git
$ #make changes to files or the directory structure
$ git commit -a -m "Updates to the test date to ....."
$ mv .git git.rename
$ git commit -a -m "Updates to the test date to ....." #IMPORTANT : you must add the changed test data to the global git repository so it can be picked up by other developpers.
After these changes, a lot of tests will fail as they rely on the hash of the latest git commit. Test code needs improved here, but until now, this has been solved with a search and replace.
To update the test reference-repository with fresh real datas, remove old
repository and copy the new one:
$ rm -rf spec/fixtures/reference-repository
$ cp -r ~/git/reference-repository/data/
The repository can be quite heavy, so to limit the import size into g5k-api we
can only keep the `data` directory and rewrite the git history.
The tool [git-filter-repo](https://github.com/newren/git-filter-repo) can be
used to do that:
$ cd spec/fixtures/reference-repository
$ /usr/libexec/git-core/git-filter-repo --path data
$ git gc --aggressive
Some rspec tests require to add a symlink inside the repository, because this
aspect is not used inside our reference-repository (we don't use links at all).
For example:
$ rm data/grid5000/sites/nancy/servers/grcinq-srv-3.json
$ ln -s data/grid5000/sites/nancy/servers/grcinq-srv-2.json data/grid5000/sites/nancy/servers/grcinq-srv-3.json
Commit the change, and then move the `.git`:
$ mv .git git.rename
$ cd ../../..
Update the `@latest_commit` variable:
$ sed -ri "s/(\@latest_commit = ).*/\1 \'$(cat spec/fixtures/reference-repository/git.rename/refs/heads/master)\'/g" spec/spec_help.rb
Then, changes are to be applied manually, because some resources might not exist
anymore, and some might have been added, e.g.:
* the number and name of sites
* the clusters
* nodes inside a clusters
* servers on sites
* network_equipments
*
However, sed can be usefull to help and save time. Here to replace inside tests
a site (`bordeaux`) and a cluster (`bordemer`) which don't exist anymore:
$ find spec/ -type f -exec sed -ri 's/bordeaux/grenoble/g' {} \;
$ find spec/ -type f -exec sed -ri 's/bordemer/dahu/g' {} \;
* Adding data to the test OAR2 database
......
......@@ -106,32 +106,32 @@ describe ClustersController do
# 3. Where queues filter is specified as 'default'
# 4. Where queues filter is 'production' and a 'default' cluster is requested
it 'should return ONLY cluster mbi in nancy without any queues filter' do
expected_url = 'http://api-out.local:80/sites/nancy/clusters/mbi?branch=master&pretty=yes'
it 'should return ONLY cluster grcinq in nancy without any queues filter' do
expected_url = 'http://api-out.local:80/sites/nancy/clusters/grcinq?branch=master&pretty=yes'
stub_request(:get, expected_url)
.with(
headers: { 'Accept' => api_media_type(:json) }
)
.to_return(body: fixture('reference-repository/data/grid5000/sites/nancy/clusters/mbi/mbi.json'))
get :show, params: { branch: 'master', site_id: 'nancy', id: 'mbi', format: :json }
.to_return(body: fixture('reference-repository/data/grid5000/sites/nancy/clusters/grcinq/grcinq.json'))
get :show, params: { branch: 'master', site_id: 'nancy', id: 'grcinq', format: :json }
assert_media_type(:json)
expect(response.status).to eq 200
expect(json['queues']).to eq %w[admin production]
end
it 'should return ONLY cluster talc in nancy without any queues filter' do
expected_url = 'http://api-out.local:80/sites/nancy/clusters/talc?branch=master&pretty=yes'
it 'should return ONLY cluster graphite in nancy without any queues filter' do
expected_url = 'http://api-out.local:80/sites/nancy/clusters/graphite?branch=master&pretty=yes'
stub_request(:get, expected_url)
.with(
headers: { 'Accept' => api_media_type(:json) }
)
.to_return(body: fixture('reference-repository/data/grid5000/sites/nancy/clusters/talc/talc.json'))
get :show, params: { branch: 'master', site_id: 'nancy', id: 'talc', format: :json }
.to_return(body: fixture('reference-repository/data/grid5000/sites/nancy/clusters/graphite/graphite.json'))
get :show, params: { branch: 'master', site_id: 'nancy', id: 'graphite', format: :json }
assert_media_type(:json)
expect(response.status).to eq 200
expect(json['queues']).to eq %w[admin default]
expect(json['queues']).to eq %w[default admin]
end
it 'should return ONLY cluster graphique in nancy without any queues filter' do
......@@ -145,48 +145,48 @@ describe ClustersController do
assert_media_type(:json)
expect(response.status).to eq 200
expect(json['queues'] | []).to eq %w[admin default]
expect(json['queues'] | []).to eq %w[admin production]
end
it 'should return ONLY cluster mbi in nancy' do
expected_url = 'http://api-out.local:80/sites/nancy/clusters/mbi?branch=master&queues=production&pretty=yes'
it 'should return ONLY cluster grcinq in nancy' do
expected_url = 'http://api-out.local:80/sites/nancy/clusters/grcinq?branch=master&queues=production&pretty=yes'
stub_request(:get, expected_url)
.with(
headers: { 'Accept' => api_media_type(:json) }
)
.to_return(body: fixture('reference-repository/data/grid5000/sites/nancy/clusters/mbi/mbi.json'))
get :show, params: { branch: 'master', site_id: 'nancy', id: 'mbi', queues: 'production', format: :json }
.to_return(body: fixture('reference-repository/data/grid5000/sites/nancy/clusters/grcinq/grcinq.json'))
get :show, params: { branch: 'master', site_id: 'nancy', id: 'grcinq', queues: 'production', format: :json }
assert_media_type(:json)
expect(response.status).to eq 200
expect(json['queues']).to eq %w[admin production]
end
it 'should return ONLY cluster talc in nancy' do
expected_url = 'http://api-out.local:80/sites/nancy/clusters/talc?branch=master&queues=default&pretty=yes'
it 'should return ONLY cluster graphite in nancy' do
expected_url = 'http://api-out.local:80/sites/nancy/clusters/graphite?branch=master&queues=default&pretty=yes'
stub_request(:get, expected_url)
.with(
headers: { 'Accept' => api_media_type(:json) }
)
.to_return(body: fixture('reference-repository/data/grid5000/sites/nancy/clusters/talc/talc.json'))
get :show, params: { branch: 'master', site_id: 'nancy', id: 'talc', queues: 'default', format: :json }
.to_return(body: fixture('reference-repository/data/grid5000/sites/nancy/clusters/graphite/graphite.json'))
get :show, params: { branch: 'master', site_id: 'nancy', id: 'graphite', queues: 'default', format: :json }
assert_media_type(:json)
expect(response.status).to eq 200
expect(json['queues']).to eq %w[admin default]
expect(json['queues']).to eq %w[default admin]
end
it 'should return NO cluster because talc is NOT production cluster' do
expected_url = 'http://api-out.local:80/sites/nancy/clusters/talc?branch=master&queues=production&pretty=yes'
it 'should return NO cluster because graphite is NOT production cluster' do
expected_url = 'http://api-out.local:80/sites/nancy/clusters/graphite?branch=master&queues=production&pretty=yes'
stub_request(:get, expected_url)
.with(
headers: { 'Accept' => api_media_type(:json) }
)
.to_return(body: fixture('reference-repository/data/grid5000/sites/nancy/clusters/talc/talc.json'))
get :show, params: { branch: 'master', site_id: 'nancy', id: 'talc', queues: 'production', format: :json }
.to_return(body: fixture('reference-repository/data/grid5000/sites/nancy/clusters/graphite/graphite.json'))
get :show, params: { branch: 'master', site_id: 'nancy', id: 'graphite', queues: 'production', format: :json }
expect(response.status).to eq 404
expect(response.body).to eq 'Cannot find resource /sites/nancy/clusters/talc'
expect(response.body).to eq 'Cannot find resource /sites/nancy/clusters/graphite'
end
it 'should return 404 if a resource does not exist' do
......@@ -197,59 +197,66 @@ describe ClustersController do
describe 'GET /sites/{{site_id}}/clusters' do
# The following unit tests check the responses at level of all clusters in a site:
# 1. Where queues filter is NOT mentioned in request (mbi, talc, graphique)
# 2. Where queues filter is specified as 'production' (mbi)
# 3. Where queues filter is specified as 'default' (talc graphique)
# 4. Where queues filter is 'all' (mbi, talc, graphique)
# 1. Where queues filter is NOT mentioned in request (grcinq, graphite, graphique)
# 2. Where queues filter is specified as 'production' (grcinq)
# 3. Where queues filter is specified as 'default' (graphite graphique)
# 4. Where queues filter is 'all' (grcinq, graphite, graphique)
it 'should return ALL clusters in site nancy without any queues param' do
get :index, params: { branch: 'master', site_id: 'nancy', format: :json }
assert_media_type(:json)
expect(response.status).to eq 200
expect(json['total']).to eq 3
expect(json['total']).to eq 13
clusterList = []
json['items'].each do |cluster|
clusterList = [cluster['uid']] | clusterList
end
expect(clusterList - %w[graphique mbi talc]).to be_empty
expect(clusterList - %w[grvingt grue gros grisou graoully grimoire grimani
grele grcinq grappe graffiti graphique grcinq graphite]).to be_empty
end
it 'should return ONLY cluster mbi in site nancy' do
it 'should return ONLY cluster grcinq in site nancy' do
expected_url = 'http://api-out.local:80/sites/nancy/clusters?branch=master&queues=production&pretty=yes'
stub_request(:get, expected_url)
.with(
headers: { 'Accept' => api_media_type(:json) }
)
.to_return(body: fixture('reference-repository/data/grid5000/sites/nancy/clusters/mbi/mbi.json'))
.to_return(body: fixture('reference-repository/data/grid5000/sites/nancy/clusters/grcinq/grcinq.json'))
get :index, params: { branch: 'master', site_id: 'nancy', queues: 'production', format: :json }
assert_media_type(:json)
clusterList = []
json['items'].each do |cluster|
clusterList = [cluster['uid']] | clusterList
expect(cluster['queues']).to include('production')
end
expect(clusterList - %w[grvingt grue grimani grele grcinq graphique graoully graffiti]).to be_empty
expect(response.status).to eq 200
expect(json['total']).to eq 1
expect(json['items'][0]['uid']).to eq 'mbi'
expect(json['total']).to eq 8
expect(json['items'][0]['queues']).to include('production')
end
it 'should return ONLY clusters talc & graphique in site nancy' do
it 'should return ONLY clusters gros, grisou, grimoire, graphite in site nancy' do
expected_url = 'http://api-out.local:80/sites/nancy/clusters?branch=master&queues=default&pretty=yes'
stub_request(:get, expected_url)
.with(
headers: { 'Accept' => api_media_type(:json) }
)
.to_return(body: fixture('reference-repository/data/grid5000/sites/nancy/clusters/talc/talc.json'))
.to_return(body: fixture('reference-repository/data/grid5000/sites/nancy/clusters/graphite/graphite.json'))
get :index, params: { branch: 'master', site_id: 'nancy', queues: 'default', format: :json }
assert_media_type(:json)
expect(response.status).to eq 200
expect(json['total']).to eq 2
expect(json['total']).to eq 4
clusterList = []
json['items'].each do |cluster|
clusterList = [cluster['uid']] | clusterList
expect(cluster['queues']).to include('default')
end
expect(clusterList - %w[graphique talc]).to be_empty
expect(clusterList - %w[gros grisou grimoire graphite]).to be_empty
end
it 'should return ALL clusters in site nancy' do
......@@ -257,7 +264,7 @@ describe ClustersController do
assert_media_type(:json)
expect(response.status).to eq 200
expect(json['total']).to eq 3
expect(json['total']).to eq 13
clusterList = []
combined_queues = []
......@@ -265,9 +272,10 @@ describe ClustersController do
clusterList = [cluster['uid']] | clusterList
combined_queues = cluster['queues'] | combined_queues
end
expect(combined_queues).to eq %w[admin default production]
expect(combined_queues).to eq %w[admin production default testing]
expect(clusterList - %w[graphique mbi talc]).to be_empty
expect(clusterList - %w[grvingt grue gros grisou graoully grimoire grimani
grele grcinq grappe graffiti graphique grcinq graphite]).to be_empty
end
end # "GET /sites/{{site_id}}/clusters?branch=master&queues=all&pretty=yes"
end
......@@ -18,23 +18,23 @@ describe NetworkEquipmentsController do
render_views
describe 'GET /network_equipments' do
it 'should get 404 in default branch' do
it 'should get 200 in default' do
get :index, params: { format: :json }
expect(response.status).to eq(404)
expect(response.status).to eq(200)
end
it 'should get collection in testing branch' do
get :index, params: { format: :json, branch: 'testing' }
it 'should get collection' do
get :index, params: { format: :json }
expect(response.status).to eq(200)
expect(json['total']).to eq(4)
expect(json['items'].length).to eq(4)
expect(json['total']).to eq(9)
expect(json['items'].length).to eq(9)
end
it 'should get collection in testing branch' do
get :index, params: { site_id: 'lille', format: :json, branch: 'testing' }
it 'should get collection for a site' do
get :index, params: { site_id: 'lille', format: :json }
expect(response.status).to eq(200)
expect(json['total']).to eq(6)
expect(json['items'].length).to eq(6)
expect(json['total']).to eq(3)
expect(json['items'].length).to eq(3)
end
end # describe "GET /network_equipments"
end
......@@ -19,12 +19,12 @@ describe NodesController do
describe "GET /sites/{{site_id}}/clusters/{{cluster_id}}/nodes?deep=true" do
it "should get the correct deep view for one site" do
get :index, params: { site_id: 'rennes', cluster_id: 'paravent', format: :json, deep: true }
get :index, params: { site_id: 'rennes', cluster_id: 'parapide', format: :json, deep: true }
expect(response.status).to eq 200
expect(json['total']).to eq 99
expect(json['items'].length).to eq 99
expect(json['total']).to eq 17
expect(json['items'].length).to eq 17
expect(json['items']).to be_a(Array)
expect(json['items'].first['uid']).to eq 'paravent-1'
expect(json['items'].first['uid']).to eq 'parapide-1'
end
end
end
......@@ -23,14 +23,14 @@ describe RootController do
expect(json).to eq({
'type' => 'grid',
'uid' => 'grid5000',
'version' => '8a562420c9a659256eeaafcfd89dfa917b5fb4d0',
'version' => @latest_commit,
'timestamp' => @now.to_i,
'links' => [
{ 'rel' => 'environments', 'href' => '/environments', 'type' => 'application/vnd.grid5000.collection+json' },
{ 'rel' => 'network_equipments', 'href' => '/network_equipments', 'type' => 'application/vnd.grid5000.collection+json' },
{ 'rel' => 'sites', 'href' => '/sites', 'type' => 'application/vnd.grid5000.collection+json' },
{ 'rel' => 'self', 'type' => 'application/vnd.grid5000.item+json', 'href' => '/' },
{ 'rel' => 'parent', 'type' => 'application/vnd.grid5000.item+json', 'href' => '/' },
{ 'rel' => 'version', 'type' => 'application/vnd.grid5000.item+json', 'href' => '/versions/8a562420c9a659256eeaafcfd89dfa917b5fb4d0' },
{ 'rel' => 'version', 'type' => 'application/vnd.grid5000.item+json', 'href' => "/versions/#{@latest_commit}" },
{ 'rel' => 'versions', 'type' => 'application/vnd.grid5000.collection+json', 'href' => '/versions' },
{ 'rel' => 'users', 'type' => 'application/vnd.grid5000.collection+json', 'href' => '/users' }
]
......@@ -44,14 +44,14 @@ describe RootController do
expect(json).to eq({
'type' => 'grid',
'uid' => 'grid5000',
'version' => '8a562420c9a659256eeaafcfd89dfa917b5fb4d0',
'version' => @latest_commit,
'timestamp' => @now.to_i,
'links' => [
{ 'rel' => 'environments', 'href' => '/sid/environments', 'type' => 'application/vnd.grid5000.collection+json' },
{ 'rel' => 'network_equipments', 'href' => '/sid/network_equipments', 'type' => 'application/vnd.grid5000.collection+json' },
{ 'rel' => 'sites', 'href' => '/sid/sites', 'type' => 'application/vnd.grid5000.collection+json' },
{ 'rel' => 'self', 'type' => 'application/vnd.grid5000.item+json', 'href' => '/sid/' },
{ 'rel' => 'parent', 'type' => 'application/vnd.grid5000.item+json', 'href' => '/sid/' },
{ 'rel' => 'version', 'type' => 'application/vnd.grid5000.item+json', 'href' => '/sid/versions/8a562420c9a659256eeaafcfd89dfa917b5fb4d0' },
{ 'rel' => 'version', 'type' => 'application/vnd.grid5000.item+json', 'href' => "/sid/versions/#{@latest_commit}" },
{ 'rel' => 'versions', 'type' => 'application/vnd.grid5000.collection+json', 'href' => '/sid/versions' },
{ 'rel' => 'users', 'type' => 'application/vnd.grid5000.collection+json', 'href' => '/sid/users' }
]
......@@ -64,6 +64,5 @@ describe RootController do
expect(json['total']).to eq 4
expect(json['items'].length).to eq 4
expect(json['items']['sites']).to be_a(Hash)
expect(json['items']['environments']).to be_a(Hash)
end
end
......@@ -23,7 +23,8 @@ describe ServersController do
it 'should return ONLY cluster talc-data in nancy' do
get :show, params: { branch: 'master', site_id: 'nancy', id: 'talc-data', format: :json }
assert_media_type(:json)
expect(response.body).to eq('{"alias":[],"kind":"physical","monitoring":{"metric":"power","wattmeter":"multiple"},"network_adapters":{"bmc":{"ip":"172.17.79.21"},"default":{"ip":"172.16.79.21"}},"sensors":{"network":{"available":true,"resolution":1},"power":{"available":true,"resolution":1,"via":{"pdu":[{"port":20,"uid":"grisou-pdu1"},{"port":20,"uid":"grisou-pdu2"}]}}},"serial":"92ZLL82","type":"server","uid":"talc-data","warranty":11.202,"version":"8a562420c9a659256eeaafcfd89dfa917b5fb4d0","links":[{"rel":"self","type":"application/vnd.grid5000.item+json","href":"/sites/nancy/servers/talc-data"},{"rel":"parent","type":"application/vnd.grid5000.item+json","href":"/sites/nancy"},{"rel":"version","type":"application/vnd.grid5000.item+json","href":"/sites/nancy/servers/talc-data/versions/8a562420c9a659256eeaafcfd89dfa917b5fb4d0"},{"rel":"versions","type":"application/vnd.grid5000.collection+json","href":"/sites/nancy/servers/talc-data/versions"}]}')
cluster_output = '{"alias":[],"kind":"physical","monitoring":{"metric":"power","wattmeter":"multiple"},"network_adapters":{"bmc":{"ip":"172.17.79.21"},"default":{"ip":"172.16.79.21"}},"sensors":{"network":{"available":true,"resolution":1},"power":{"available":true,"resolution":1,"via":{"pdu":[{"port":21,"uid":"grisou-pdu1"},{"port":21,"uid":"grisou-pdu2"}]}}},"serial":"92ZLL82","type":"server","uid":"talc-data","warranty":"2022-11","version":"' + @latest_commit + '","links":[{"rel":"self","type":"application/vnd.grid5000.item+json","href":"/sites/nancy/servers/talc-data"},{"rel":"parent","type":"application/vnd.grid5000.item+json","href":"/sites/nancy"},{"rel":"version","type":"application/vnd.grid5000.item+json","href":"/sites/nancy/servers/talc-data/versions/' + @latest_commit + '"},{"rel":"versions","type":"application/vnd.grid5000.collection+json","href":"/sites/nancy/servers/talc-data/versions"}]}'
expect(response.body).to eq(cluster_output)
expect(response.status).to eq(200)
end
end
......@@ -31,32 +32,32 @@ describe ServersController do
describe 'GET /sites/{{site_id}}/servers' do
# The following unit tests check the responses at level of all servers in a site
it 'should return 2 servers in site nancy and their exact names' do
it 'should return 47 servers in site nancy their names' do
get :index, params: { branch: 'master', site_id: 'nancy', format: :json }
assert_media_type(:json)
expect(response.status).to eq(200)
expect(json['total']).to eq(2)
expect(json['total']).to eq(47)
server_list = []
json['items'].each do |server|
server_list = [server['uid']] | server_list
end
expect(server_list - %w[storage5k talc-data]).to be_empty
expect(server_list).to include('api-proxy', 'ci-runner')
end
end
describe 'GET /sites/{{site_id}}/servers?deep=true' do
it 'should return 2 servers in site nancy and their exact names' do
it 'should return 47 servers in site nancy and their exact names' do
get :index, params: { deep: true, site_id: 'nancy', format: :json }
expect(response.status).to eq(200)
expect(json['total']).to eq(2)
expect(json['total']).to eq(47)
expect(json['items']).to be_a(Array)
server_list = []
json['items'].each do |server|
server_list = [server['uid']] | server_list
end
expect(server_list - %w[storage5k talc-data]).to be_empty
expect(server_list).to include('api-proxy', 'ci-runner')
end
it 'should return 2 links, parent and self' do
......
......@@ -21,9 +21,9 @@ describe SitesController do
it 'should get the correct collection of sites' do
get :index, format: :json
expect(response.status).to eq 200
expect(json['total']).to eq 4
expect(json['items'].length).to eq 4
expect(json['items'][0]['uid']).to eq 'bordeaux'
expect(json['total']).to eq 8
expect(json['items'].length).to eq 8
expect(json['items'][0]['uid']).to eq 'grenoble'
expect(json['items'][0]['links']).to be_a(Array)
end
......@@ -64,11 +64,13 @@ describe SitesController do
expect(json['links'].map { |l| l['rel'] }.sort).to eq %w[
clusters
deployments
environments
jobs
metrics
network_equipments
parent
pdus
self
servers
status
version
versions
......@@ -82,26 +84,7 @@ describe SitesController do
end['href']).to eq '/sites/rennes/clusters'
expect(json['links'].find do |l|
l['rel'] == 'version'
end['href']).to eq '/sites/rennes/versions/8a562420c9a659256eeaafcfd89dfa917b5fb4d0'
end
it 'should return subresource links that are only in testing branch' do
get :show, params: { id: 'lille', format: :json, branch: 'testing' }
expect(response.status).to eq 200
expect(json['links'].map { |l| l['rel'] }.sort).to eq %w[
clusters
deployments
environments
jobs
metrics
network_equipments
parent
self
status
version
versions
vlans
]
end['href']).to eq "/sites/rennes/versions/#{@latest_commit}"
end
it 'should return link for deployment' do
......@@ -123,14 +106,14 @@ describe SitesController do
end
it 'should return the specified version, and the max-age value in the Cache-Control header should be big' do
get :show, params: { id: 'rennes', format: :json, version: 'b00bd30bf69c322ffe9aca7a9f6e3be0f29e20f4' }
get :show, params: { id: 'rennes', format: :json, version: '2eefdbf0e48cad1bd2db4fa9c96397df168a9c68' }
expect(response.status).to eq 200
assert_expires_in(24 * 3600 * 30, public: true)
expect(json['uid']).to eq 'rennes'
expect(json['version']).to eq 'b00bd30bf69c322ffe9aca7a9f6e3be0f29e20f4'
expect(json['version']).to eq '2eefdbf0e48cad1bd2db4fa9c96397df168a9c68'
expect(json['links'].find do |l|
l['rel'] == 'version'
end['href']).to eq '/sites/rennes/versions/b00bd30bf69c322ffe9aca7a9f6e3be0f29e20f4'
end['href']).to eq '/sites/rennes/versions/2eefdbf0e48cad1bd2db4fa9c96397df168a9c68'
end
it 'should return 404 if the specified branch does not exist' do
......@@ -152,56 +135,56 @@ describe SitesController do
it 'should return 200 and the site status' do
get :status, params: { id: 'rennes', format: :json }
expect(response.status).to eq 200
expect(json['nodes'].length).to eq 196
expect(json['nodes'].length).to eq 75
expect(json['nodes'].keys.map { |k| k.split('-')[0] }.uniq.sort).to eq %w[
paraquad
paramount
paravent
parapide
parapluie
parasilo
].sort
expect(json['disks']).to be_empty # no reservable disks on requested clusters
expect(json['nodes']['paramount-4.rennes.grid5000.fr']['reservations']).not_to be_nil
expect(json['nodes']['paramount-4.rennes.grid5000.fr']['free_slots']).not_to be_nil
expect(json['nodes']['paramount-4.rennes.grid5000.fr']['busy_slots']).not_to be_nil
expect(json['nodes']['paramount-4.rennes.grid5000.fr']['freeable_slots']).not_to be_nil
expect(json['disks']).not_to be_nil
expect(json['nodes']['parapide-5.rennes.grid5000.fr']['reservations']).not_to be_nil
expect(json['nodes']['parapide-5.rennes.grid5000.fr']['free_slots']).not_to be_nil
expect(json['nodes']['parapide-5.rennes.grid5000.fr']['busy_slots']).not_to be_nil
expect(json['nodes']['parapide-5.rennes.grid5000.fr']['freeable_slots']).not_to be_nil
expect(json.keys).to include('uid')
expect(json['uid']).to eq @now.to_i
end
# GET /sites/{{site_id}}/status?network_address={{network_address}}
it 'should return the status ONLY for the specified node' do
get :status, params: { id: 'rennes', network_address: 'paramount-4.rennes.grid5000.fr', format: :json }
get :status, params: { id: 'rennes', network_address: 'parapide-5.rennes.grid5000.fr', format: :json }
expect(response.status).to eq 200
expect(json['nodes'].keys.map { |k| k.split('.')[0] }.uniq.sort).to eq ['paramount-4']
expect(json['nodes'].keys.map { |k| k.split('.')[0] }.uniq.sort).to eq ['parapide-5']
expect(json['disks']).to be_empty
expect(json['nodes']['paramount-4.rennes.grid5000.fr']['reservations']).not_to be_nil
expect(json['nodes']['parapide-5.rennes.grid5000.fr']['reservations']).not_to be_nil
end
# GET /sites/{{site_id}}/status?disks=no
it 'should return the status of nodes but not disks' do
get :status, params: { id: 'rennes', disks: 'no', format: :json }
expect(response.status).to eq 200
expect(json['nodes'].length).to eq 196
expect(json['nodes'].length).to eq 75
expect(json['nodes'].keys.map { |k| k.split('-')[0] }.uniq.sort).to eq %w[
paraquad
paramount
paravent
parapide
parapluie
parasilo
].sort
expect(json['disks']).to be_nil
expect(json['nodes']['paramount-4.rennes.grid5000.fr']['reservations']).not_to be_nil
expect(json['nodes']['parapide-5.rennes.grid5000.fr']['reservations']).not_to be_nil
end
# GET /sites/{{site_id}}/status?job_details=no
it 'should return the status without the reservations' do
get :status, params: { id: 'rennes', job_details: 'no', format: :json }
expect(response.status).to eq 200
expect(json['nodes'].length).to eq 196
expect(json['nodes'].length).to eq 75
expect(json['nodes'].keys.map { |k| k.split('-')[0] }.uniq.sort).to eq %w[
paraquad
paramount
paravent
parapide
parapluie
parasilo
].sort
expect(json['disks']).to be_empty
expect(json['nodes']['paramount-4.rennes.grid5000.fr']['reservations']).to be_nil
expect(json['disks']).not_to be_nil
expect(json['nodes']['parapide-5.rennes.grid5000.fr']['reservations']).to be_nil
end