Skip to content

Commit

Permalink
Merge 8017a99 into 5872169
Browse files Browse the repository at this point in the history
  • Loading branch information
dymurray committed Jun 10, 2016
2 parents 5872169 + 8017a99 commit b1ee92c
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 18 deletions.
75 changes: 74 additions & 1 deletion fusor-ember-cli/app/controllers/storage.js
@@ -1,12 +1,85 @@
import Ember from 'ember';
import request from 'ic-ajax';
import NeedsDeploymentMixin from "../mixins/needs-deployment-mixin";
import { AllValidator, PresenceValidator, AlphaNumericDashUnderscoreValidator, HostnameValidator } from '../utils/validators';
import {
AllValidator,
PresenceValidator,
AlphaNumericDashUnderscoreValidator,
HostnameValidator
} from '../utils/validators';

export default Ember.Controller.extend(NeedsDeploymentMixin, {
actions: {
testMountPoint() {
this.set('errorMsg', null);
const checkExport = this.get('isCloudForms');

const storageParams = {
path: this.get('model.rhev_share_path'),
address: this.get('model.rhev_storage_address'),
type: this.get('model.rhev_storage_type')
};

const validationPromises = {
storage: this.storageMountRequest(storageParams)
};

if(checkExport) {
const exportParams = {
path: this.get('model.rhev_export_domain_path'),
address: this.get('model.rhev_export_domain_address'),
type: this.get('model.rhev_storage_type')
};

validationPromises.export = this.storageMountRequest(exportParams);
}

this.set('loadingSpinnerText', `Trying to mount storage paths...`);
this.set('showLoadingSpinner', true);

Ember.RSVP.hash(validationPromises).then((resultHash) => {
this.set('showLoadingSpinner', false);

const validMounts = checkExport ?
resultHash.storage.mounted && resultHash.export.mounted :
resultHash.storage.mounted;

if(validMounts) {
this.set('errorMsg', null);
this.transitionTo(this.get('step3RouteName'));
} else {
const failedDomain = resultHash.storage.mounted ? 'export' : 'storage';
this.set(
'errorMsg',
`Error mounting ${failedDomain} domain, please make sure it is a valid mount point`);
}
}).catch(err => {
this.set(
'errorMsg',
'Error occurred while attempting to validate storage paths');
});
}
},

storageMountRequest(params) {
const deploymentId = this.get('deploymentId');
return request({
url: `/fusor/api/v21/deployments/${deploymentId}/check_mount_point`,
type: 'GET',
data: params,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-CSRF-Token': Ember.$('meta[name="csrf-token"]').attr('content')
}
});
},

deploymentId: Ember.computed.alias('deploymentController.model.id'),
step3RouteName: Ember.computed.alias("deploymentController.step3RouteName"),
isCloudForms: Ember.computed.alias("deploymentController.isCloudForms"),
rhevIsSelfHosted: Ember.computed.alias("deploymentController.model.rhev_is_self_hosted"),
errorMsg: null,

hasEndingSlashInSharePath: Ember.computed('deploymentController.model.rhev_share_path', function() {
if (Ember.isPresent(this.get('deploymentController.model.rhev_share_path'))) {
Expand Down
25 changes: 22 additions & 3 deletions fusor-ember-cli/app/templates/storage.hbs
@@ -1,3 +1,20 @@
{{#if errorMsg}}
<div class="row">
<div class='col-md-9'>
<div class='alert alert-error rhci-alert'>
<i class="fa fa-2x fa-exclamation-triangle errorForValidation"></i>
&nbsp;
{{errorMsg}}
</div>
</div>
</div>
{{else if showLoadingSpinner}}
<div class="spinner spinner-md spinner-inline"></div>
<span class='spinner-text'>
{{loadingSpinnerText}}
</span>
{{/if}}

{{#if isCloudForms}}
<h4> Data Domain </h4>
{{/if}}
Expand Down Expand Up @@ -69,9 +86,11 @@

</form>

{{cancel-back-next backRouteName='rhev-options'
{{#cancel-back-next backRouteName='rhev-options'
disableBack=false
nextRouteName=step3RouteName
disableNext=disableNextStorage
disableCancel=isStarted
deploymentName=deploymentName}}
{{#button-f disabled=disableNextStorage action="testMountPoint"}}
Next <i class="fa fa-angle-right"></i>
{{/button-f}}
{{/cancel-back-next}}
54 changes: 40 additions & 14 deletions server/app/controllers/fusor/api/v21/deployments_controller.rb
Expand Up @@ -17,7 +17,7 @@
module Fusor
class Api::V21::DeploymentsController < Api::V2::DeploymentsController

before_filter :find_deployment, :only => [:destroy, :show, :update,
before_filter :find_deployment, :only => [:destroy, :show, :update, :check_mount_point,
:deploy, :redeploy, :validate, :log, :openshift_disk_space]

rescue_from Encoding::UndefinedConversionError, :with => :ignore_it
Expand Down Expand Up @@ -122,6 +122,40 @@ def validate_cdn
end
end

def check_mount_point
mount_address = params['address']
mount_path = params['path']
mount_type = params['type']

begin
mount_storage(mount_address, mount_path, mount_type)
render json: { :mounted => true }, status: 200
rescue
render json: { :mounted => false }, status: 200
end
end

# mount_storage will return in megabytes the amount of free space left on the storage mount
def mount_storage(address, path, type)
deployment_id = @deployment.id
if type == "GFS"
type = "glusterfs"
else
type = "nfs"
end

cmd = "sudo safe-mount.sh '#{deployment_id}' '#{address}' '#{path}' '#{type}'"
status, _output = Utils::Fusor::CommandUtils.run_command(cmd)

raise 'Unable to mount NFS share at specified mount point' unless status == 0

stats = Sys::Filesystem.stat("/tmp/fusor-test-mount-#{deployment_id}")
mb_available = stats.block_size * stats.blocks_available / 1024 / 1024

Utils::Fusor::CommandUtils.run_command("sudo safe-umount.sh #{deployment_id}")
return mb_available
end

def log
log_type_param = params[:log_type] || 'fusor_log'
reader = create_log_reader(log_type_param)
Expand All @@ -139,20 +173,12 @@ def log
def openshift_disk_space
# Openshift deployments need to know how much disk space is available on the NFS storage pool
# This method mounts the specifed NFS share and gets the available disk space
begin
nfs_address = @deployment.rhev_storage_address
nfs_path = @deployment.rhev_share_path
deployment_id = @deployment.id
address = @deployment.rhev_storage_address
path = @deployment.rhev_share_path
storage_type = @deployment.rhev_storage_type

cmd = "sudo safe-mount.sh '#{deployment_id}' '#{nfs_address}' '#{nfs_path}'"
status, _output = Utils::Fusor::CommandUtils.run_command(cmd)

raise 'Unable to mount NFS share at specified mount point' unless status == 0

stats = Sys::Filesystem.stat("/tmp/fusor-test-mount-#{deployment_id}")
mb_available = stats.block_size * stats.blocks_available / 1024 / 1024

Utils::Fusor::CommandUtils.run_command("sudo safe-umount.sh #{deployment_id}")
begin
mb_available = mount_storage(address, path, storage_type)
render json: { :openshift_disk_space => mb_available }, status: 200
rescue Exception => error
message = 'Unable to retrieve Openshift disk space'
Expand Down
1 change: 1 addition & 0 deletions server/config/routes/api/v21.rb
Expand Up @@ -10,6 +10,7 @@
get :validate_cdn
get :log
get :openshift_disk_space
get :check_mount_point
end
end
resources :openstack_deployments do
Expand Down
25 changes: 25 additions & 0 deletions server/test/controllers/deployments_controller_test.rb
Expand Up @@ -397,5 +397,30 @@ def mock_stats.blocks_available
'Unable to mount NFS share at specified mount point'
end
end

context 'check_mount_point' do
test 'check_mount_point should return a 200 and indicate a successful mount' do
Utils::Fusor::CommandUtils.stubs(:run_command).returns(0, :foo)

response = JSON.parse(get(
:check_mount_point,
:id => @deployment.id).body)

assert_response 200
assert_equal response['mounted'], true
end

test 'check_mount_point should return a 200 indicating mount failed' do
Utils::Fusor::CommandUtils.stubs(:run_command).returns(1, :foo)

response = JSON.parse(get(
:check_mount_point,
:id => @deployment.id).body)

assert_response 200
assert_equal response['mounted'], false
end
end

end
end

0 comments on commit b1ee92c

Please sign in to comment.