-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #578 from xlab-si/physical-server-provision
Support physical server provisioning
- Loading branch information
Showing
9 changed files
with
331 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Api | ||
class CustomizationTemplatesController < BaseController | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Api | ||
class PxeImagesController < BaseController | ||
include Subcollections::CustomizationTemplates | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Api | ||
class PxeServersController < BaseController | ||
include Subcollections::PxeImages | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
app/controllers/api/subcollections/customization_templates.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Api | ||
module Subcollections | ||
module CustomizationTemplates | ||
def customization_templates_query_resource(object) | ||
object.customization_templates | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Api | ||
module Subcollections | ||
module PxeImages | ||
def pxe_images_query_resource(object) | ||
object.images | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
RSpec.describe 'CustomizationTemplates API' do | ||
let!(:template) { FactoryBot.create(:customization_template) } | ||
|
||
describe 'GET /api/customization_templates' do | ||
let(:url) { api_customization_templates_url } | ||
|
||
it 'lists all customization templates images with an appropriate role' do | ||
api_basic_authorize collection_action_identifier(:customization_templates, :read, :get) | ||
get(url) | ||
expected = { | ||
'count' => 1, | ||
'subcount' => 1, | ||
'name' => 'customization_templates', | ||
'resources' => [ | ||
hash_including('href' => api_customization_template_url(nil, template)) | ||
] | ||
} | ||
expect(response).to have_http_status(:ok) | ||
expect(response.parsed_body).to include(expected) | ||
end | ||
|
||
it 'forbids access without an appropriate role' do | ||
api_basic_authorize | ||
get(url) | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
describe 'GET /api/customization_templates/:id' do | ||
let(:url) { api_customization_template_url(nil, template) } | ||
|
||
it 'will show a customization template with an appropriate role' do | ||
api_basic_authorize action_identifier(:customization_templates, :read, :resource_actions, :get) | ||
get(url) | ||
expect(response.parsed_body).to include('href' => api_customization_template_url(nil, template)) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'forbids access without an appropriate role' do | ||
api_basic_authorize | ||
get(url) | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
RSpec.describe 'PxeImages API' do | ||
let!(:pxe_image) { FactoryBot.create(:pxe_image, :pxe_image_type => image_type) } | ||
let!(:image_type) { FactoryBot.create(:pxe_image_type) } | ||
let!(:template_1) { FactoryBot.create(:customization_template, :pxe_image_type => image_type) } | ||
let!(:template_2) { FactoryBot.create(:customization_template, :pxe_image_type => image_type) } | ||
|
||
describe 'GET /api/pxe_images' do | ||
let(:url) { api_pxe_images_url } | ||
|
||
it 'lists all pxe images with an appropriate role' do | ||
api_basic_authorize collection_action_identifier(:pxe_images, :read, :get) | ||
get(url) | ||
expected = { | ||
'count' => 1, | ||
'subcount' => 1, | ||
'name' => 'pxe_images', | ||
'resources' => [ | ||
hash_including('href' => api_pxe_image_url(nil, pxe_image)) | ||
] | ||
} | ||
expect(response).to have_http_status(:ok) | ||
expect(response.parsed_body).to include(expected) | ||
end | ||
|
||
it 'forbids access without an appropriate role' do | ||
api_basic_authorize | ||
get(url) | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
describe 'GET /api/pxe_images/:id' do | ||
let(:url) { api_pxe_image_url(nil, pxe_image) } | ||
|
||
it 'will show a pxe image with an appropriate role' do | ||
api_basic_authorize action_identifier(:pxe_images, :read, :resource_actions, :get) | ||
get(url) | ||
expect(response.parsed_body).to include('href' => api_pxe_image_url(nil, pxe_image)) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'forbids access without an appropriate role' do | ||
api_basic_authorize | ||
get(url) | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
describe 'GET /api/pxe_images/:id/customization_templates' do | ||
let(:url) { "/api/pxe_images/#{pxe_image.id}/customization_templates" } | ||
|
||
it 'lists all customization templates for a pxe image' do | ||
api_basic_authorize subcollection_action_identifier(:pxe_images, :customization_templates, :read, :get) | ||
get(url) | ||
expect_result_resources_to_include_hrefs( | ||
"resources", | ||
[ | ||
api_pxe_image_customization_template_url(nil, pxe_image, template_1), | ||
api_pxe_image_customization_template_url(nil, pxe_image, template_2), | ||
] | ||
) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'forbids access without an appropriate role' do | ||
api_basic_authorize | ||
get(url) | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
describe 'GET /api/pxe_images/:id/customization_templates/:id' do | ||
let(:url) { "/api/pxe_images/#{pxe_image.id}/customization_templates/#{template_1.id}" } | ||
|
||
it "will show a single customization template of a pxe image" do | ||
api_basic_authorize subcollection_action_identifier(:pxe_images, :customization_templates, :read, :get) | ||
get(url) | ||
expect_result_to_match_hash( | ||
response.parsed_body, | ||
"href" => api_pxe_image_customization_template_url(nil, pxe_image, template_1), | ||
"id" => template_1.id.to_s, | ||
"pxe_image_type_id" => image_type.id.to_s, | ||
"name" => template_1.name | ||
) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'forbids access without an appropriate role' do | ||
api_basic_authorize | ||
get(url) | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
RSpec.describe 'PxeServers API' do | ||
let!(:pxe_server) { FactoryBot.create(:pxe_server) } | ||
let!(:pxe_image_1) { FactoryBot.create(:pxe_image, :pxe_server => pxe_server) } | ||
let!(:pxe_image_2) { FactoryBot.create(:pxe_image, :pxe_server => pxe_server) } | ||
|
||
describe 'GET /api/pxe_servers' do | ||
let(:url) { api_pxe_servers_url } | ||
|
||
it 'lists all pxe servers with an appropriate role' do | ||
api_basic_authorize collection_action_identifier(:pxe_servers, :read, :get) | ||
get(url) | ||
expected = { | ||
'count' => 1, | ||
'subcount' => 1, | ||
'name' => 'pxe_servers', | ||
'resources' => [ | ||
hash_including('href' => api_pxe_server_url(nil, pxe_server)) | ||
] | ||
} | ||
expect(response).to have_http_status(:ok) | ||
expect(response.parsed_body).to include(expected) | ||
end | ||
|
||
it 'forbids access without an appropriate role' do | ||
api_basic_authorize | ||
get(url) | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
describe 'GET /api/pxe_servers/:id' do | ||
let(:url) { api_pxe_server_url(nil, pxe_server) } | ||
|
||
it 'will show a pxe server with an appropriate role' do | ||
api_basic_authorize action_identifier(:pxe_servers, :read, :resource_actions, :get) | ||
get(url) | ||
expect(response.parsed_body).to include('href' => api_pxe_server_url(nil, pxe_server)) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'forbids access without an appropriate role' do | ||
api_basic_authorize | ||
get(url) | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
describe 'GET /api/pxe_servers/:id/pxe_images' do | ||
let(:url) { "/api/pxe_servers/#{pxe_server.id}/pxe_images" } | ||
|
||
it 'lists all pxe images of a pxe server' do | ||
api_basic_authorize subcollection_action_identifier(:pxe_servers, :pxe_images, :read, :get) | ||
get(url) | ||
expect_result_resources_to_include_hrefs( | ||
"resources", | ||
[ | ||
api_pxe_server_pxe_image_url(nil, pxe_server, pxe_image_1), | ||
api_pxe_server_pxe_image_url(nil, pxe_server, pxe_image_2), | ||
] | ||
) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'forbids access without an appropriate role' do | ||
api_basic_authorize | ||
get(url) | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
describe 'GET /api/pxe_servers/:id/pxe_images/:id' do | ||
let(:url) { "/api/pxe_servers/#{pxe_server.id}/pxe_images/#{pxe_image_1.id}" } | ||
|
||
it "will show a single pxe image of a pxe server" do | ||
api_basic_authorize subcollection_action_identifier(:pxe_servers, :pxe_images, :read, :get) | ||
get(url) | ||
expect_result_to_match_hash( | ||
response.parsed_body, | ||
"href" => api_pxe_server_pxe_image_url(nil, pxe_server, pxe_image_1), | ||
"id" => pxe_image_1.id.to_s, | ||
"pxe_server_id" => pxe_server.id.to_s, | ||
"name" => pxe_image_1.name | ||
) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'forbids access without an appropriate role' do | ||
api_basic_authorize | ||
get(url) | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
end |