Skip to content

Commit

Permalink
1297551 fix data center / cluster name validations.
Browse files Browse the repository at this point in the history
  • Loading branch information
cfchase committed Apr 1, 2016
1 parent e955c4b commit 903cf2d
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 64 deletions.
62 changes: 26 additions & 36 deletions fusor-ember-cli/app/controllers/rhev-options.js
@@ -1,12 +1,12 @@
import Ember from 'ember';
import NeedsDeploymentMixin from "../mixins/needs-deployment-mixin";
import { PresenceValidator, EqualityValidator, PasswordValidator, AlphaNumericDashUnderscoreValidator, AllValidator } from '../utils/validators';
import { Validator, EqualityValidator, PasswordValidator, AlphaNumericDashUnderscoreValidator, AllValidator } from '../utils/validators';

export default Ember.Controller.extend(NeedsDeploymentMixin, {

rhevRootPassword: Ember.computed.alias("deploymentController.model.rhev_root_password"),
rhevEngineAdminPassword: Ember.computed.alias("deploymentController.model.rhev_engine_admin_password"),
rhevDatabaseName: Ember.computed.alias("deploymentController.model.rhev_database_name"),
rhevDataCenterName: Ember.computed.alias("deploymentController.model.rhev_data_center_name"),
rhevClusterName: Ember.computed.alias("deploymentController.model.rhev_cluster_name"),
rhevCpuType: Ember.computed.alias("deploymentController.model.rhev_cpu_type"),
rhevIsSelfHosted: Ember.computed.alias("deploymentController.model.rhev_is_self_hosted"),
Expand Down Expand Up @@ -55,40 +55,30 @@ export default Ember.Controller.extend(NeedsDeploymentMixin, {
}
],

computerNameValidator: AllValidator.create({
createComputerNameValidator(fieldName, otherFieldValue) {
if (Ember.isBlank(otherFieldValue) || otherFieldValue === 'Default') {
return AlphaNumericDashUnderscoreValidator.create({trim: false});
}

return AllValidator.create({
validators: [
PresenceValidator.create({}),
AlphaNumericDashUnderscoreValidator.create({})
Validator.create({
message: `Note: You must change the ${fieldName} after changing the cluster name`,
isValid(value) {
return Ember.isPresent(value) && value !== 'Default';
}
}),
AlphaNumericDashUnderscoreValidator.create({trim: false})
]
}),

isDirtyRhevDatabaseName: Ember.computed('rhevDatabaseName', function() {
var changedAttrs = this.get('deploymentController.model').changedAttributes();
return Ember.isPresent(changedAttrs['rhev_database_name']);
}),
});
},

isDirtyRhevClusterName: Ember.computed('rhevClusterName', function() {
var changedAttrs = this.get('deploymentController.model').changedAttributes();
return Ember.isPresent(changedAttrs['rhev_cluster_name']);
dataCenterNameValidator: Ember.computed('rhevClusterName', function() {
return this.createComputerNameValidator('data center name', this.get('rhevClusterName'));
}),
isNotDirtyRhevClusterName: Ember.computed.not('isDirtyRhevClusterName'),

isClusterNeedRenaming: false,

showMsgToChangeCluster: Ember.observer('rhevClusterName', 'rhevDatabaseName', function() {
if ((this.get('isDirtyRhevDatabaseName') &&
this.get('rhevClusterName') &&
this.get('isNotDirtyRhevClusterName')) ||
(this.get('rhevDatabaseName') !== 'Default') &&
this.get('rhevClusterName') === 'Default') {
return this.set('isClusterNeedRenaming', true);
}
}),

removeMsgToChangeCluster: Ember.observer('rhevClusterName', function() {
if (this.get('rhevClusterName.length') > 0 && this.get('isDirtyRhevClusterName')) {
return this.set('isClusterNeedRenaming', false);
}
clusterNameValidator: Ember.computed('rhevDataCenterName', function () {
return this.createComputerNameValidator('cluster name', this.get('rhevDataCenterName'));
}),

validRhevOptions: Ember.computed(
Expand All @@ -98,17 +88,17 @@ export default Ember.Controller.extend(NeedsDeploymentMixin, {
'rhevEngineAdminPassword',
'confirmRhevEngineAdminPassword',
'confirmRhevEngineAdminPasswordValidator',
'rhevDatabaseName',
'rhevDataCenterName',
'dataCenterNameValidator',
'rhevClusterName',
'isClusterNeedRenaming',
'clusterNameValidator',
function () {
return this.get('passwordValidator').isValid(this.get('rhevRootPassword')) &&
this.get('passwordValidator').isValid(this.get('rhevEngineAdminPassword')) &&
this.get('confirmRhevRootPasswordValidator').isValid(this.get('confirmRhevRootPassword')) &&
this.get('confirmRhevEngineAdminPasswordValidator').isValid(this.get('confirmRhevEngineAdminPassword')) &&
this.get('computerNameValidator').isValid(this.get('rhevDatabaseName')) &&
this.get('computerNameValidator').isValid(this.get('rhevClusterName')) &&
!this.get('isClusterNeedRenaming');
this.get('dataCenterNameValidator').isValid(this.get('rhevDataCenterName')) &&
this.get('clusterNameValidator').isValid(this.get('rhevClusterName'));
}),

disableNextRhevOptions: Ember.computed.not('validRhevOptions')
Expand Down
2 changes: 1 addition & 1 deletion fusor-ember-cli/app/mirage/factories/deployment.js
Expand Up @@ -12,7 +12,7 @@ export default Mirage.Factory.extend({
is_disconnected: false,
rhev_is_self_hosted: false,
rhev_engine_admin_password: '12345678',
rhev_database_name: 'Default',
rhev_data_center_name: 'Default',
rhev_cluster_name: 'Default',
rhev_storage_name: 'my_storage',
rhev_storage_type: 'NFS',
Expand Down
2 changes: 1 addition & 1 deletion fusor-ember-cli/app/models/deployment.js
Expand Up @@ -17,7 +17,7 @@ export default DS.Model.extend({
rhev_is_self_hosted: DS.attr('boolean'),

rhev_engine_admin_password: DS.attr('string'),
rhev_database_name: DS.attr('string'),
rhev_data_center_name: DS.attr('string'),
rhev_cluster_name: DS.attr('string'),
rhev_storage_name: DS.attr('string'),
rhev_storage_type: DS.attr('string'),
Expand Down
2 changes: 1 addition & 1 deletion fusor-ember-cli/app/routes/deployment-new.js
Expand Up @@ -16,7 +16,7 @@ export default Ember.Route.extend(DeploymentRouteMixin, {
controller.set('model.rhev_cluster_name', 'Default');
controller.set('model.rhev_storage_name', 'my_storage');
controller.set('model.rhev_export_domain_name', 'my_export');
controller.set('model.rhev_database_name', 'Default');
controller.set('model.rhev_data_center_name', 'Default');
controller.set('model.rhev_storage_type', 'NFS');
this.controllerFor('application').set('isNewDeployment', true);
},
Expand Down
2 changes: 1 addition & 1 deletion fusor-ember-cli/app/templates/review/installation.hbs
Expand Up @@ -87,7 +87,7 @@
value=model.rhev_engine_admin_password }}

{{review-link label='Datacenter Name' routeName='rhev-options' isDefault=true
value=model.rhev_database_name}}
value=model.rhev_data_center_name}}

{{review-link label='Cluster Name' routeName='rhev-options' isDefault=true
value=model.rhev_cluster_name}}
Expand Down
15 changes: 5 additions & 10 deletions fusor-ember-cli/app/templates/rhev-options.hbs
Expand Up @@ -20,16 +20,11 @@
isRequired=true disabled=isStarted validator=confirmRhevEngineAdminPasswordValidator
placeholder="Must match engine admin password"}}

{{text-f label="Data Center Name" value=rhevDatabaseName placeholder="Leave blank for default" cssId="rhev-database-name" disabled=isStarted validator=computerNameValidator}}
{{#if isClusterNeedRenaming}}
{{#base-f}}
<span class="error errorForValidation">
Note: You must change the cluster name after changing the database name
</span>
{{/base-f}}
{{/if}}

{{text-f label="Cluster Name" value=rhevClusterName placeholder="Leave blank for default" cssId="rhev-cluster-name" disabled=isStarted validator=computerNameValidator}}
{{text-f label="Data Center Name" value=rhevDataCenterName placeholder="Leave blank for default" cssId="rhev-data-center-name"
disabled=isStarted validator=dataCenterNameValidator showValidationError=true}}

{{text-f label="Cluster Name" value=rhevClusterName placeholder="Leave blank for default" cssId="rhev-cluster-name"
disabled=isStarted validator=clusterNameValidator showValidationError=true}}

{{select-simple-f label="CPU Type"
content=cpuTypes
Expand Down
4 changes: 3 additions & 1 deletion fusor-ember-cli/app/utils/validators.js
Expand Up @@ -124,8 +124,10 @@ const UniquenessValidator = Validator.extend({
// RegExp regExp;
// String message;
const RegExpValidator = Validator.extend({
trim: true,

isValid(value) {
let trimmedValue = Ember.typeOf(value) === 'string' ? value.trim() : value;
let trimmedValue = this.get('trim') && Ember.typeOf(value) === 'string' ? value.trim() : value;
return Ember.isBlank(trimmedValue) || this.get('regExp').test(trimmedValue);
}
});
Expand Down
8 changes: 4 additions & 4 deletions fusor-ember-cli/server/mocks/deployments.js
Expand Up @@ -12,7 +12,7 @@ module.exports = function(app) {
"deploy_cfme": false,
"deploy_openstack": true,
"rhev_engine_admin_password": null,
"rhev_database_name": "Default",
"rhev_data_center_name": "Default",
"rhev_cluster_name": "Default",
"rhev_storage_name": "my_storage",
"rhev_storage_type": null,
Expand Down Expand Up @@ -67,7 +67,7 @@ module.exports = function(app) {
"deploy_cfme": true,
"deploy_openstack": false,
"rhev_engine_admin_password": "11111111",
"rhev_database_name": "Default",
"rhev_data_center_name": "Default",
"rhev_cluster_name": "Default",
"rhev_storage_name": "my_storage",
"rhev_storage_type": "NFS",
Expand Down Expand Up @@ -123,7 +123,7 @@ module.exports = function(app) {
"deploy_cfme": false,
"deploy_openstack": true,
"rhev_engine_admin_password": "adfadfadfad",
"rhev_database_name": "Default",
"rhev_data_center_name": "Default",
"rhev_cluster_name": "Default",
"rhev_storage_name": "my_storage",
"rhev_storage_type": "NFS",
Expand Down Expand Up @@ -177,7 +177,7 @@ module.exports = function(app) {
"deploy_cfme": false,
"deploy_openstack": false,
"rhev_engine_admin_password": "11111111",
"rhev_database_name": "asdfadfadf",
"rhev_data_center_name": "asdfadfadf",
"rhev_cluster_name": "Default",
"rhev_storage_name": "my_storage",
"rhev_storage_type": "NFS",
Expand Down
4 changes: 2 additions & 2 deletions server/app/lib/actions/fusor/configure_host_groups.rb
Expand Up @@ -176,7 +176,7 @@ def apply_setting_parameter_overrides(hostgroup, hostgroup_settings, puppet_envi
def apply_deployment_parameter_overrides(hostgroup, deployment, product_type, puppet_environment)
# TODO: ISSUE: the following attributes exist on the deployment object, but I do not know
# if they should be mapping to puppet class parameters and if so, which class & parameter?
# :name => , :value => deployment.rhev_database_name,
# :name => , :value => deployment.rhev_data_center_name,
# :name => , :value => deployment.cfme_install_loc,
# :name => , :value => deployment.rhev_is_self_hosted,

Expand Down Expand Up @@ -206,7 +206,7 @@ def apply_deployment_parameter_overrides(hostgroup, deployment, product_type, pu
# necessary because the puppet parameter needs to store it in clear text and
# the hostgroup stores it using one-time encryption.
{ :name => "root_password", :value => root_password(deployment, product_type) },
{ :name => "dc_name", :value => deployment.rhev_database_name },
{ :name => "dc_name", :value => deployment.rhev_data_center_name },
{ :name => "cluster_name", :value => deployment.rhev_cluster_name },
{ :name => "storage_name", :value => deployment.rhev_storage_name },
{ :name => "storage_address", :value => deployment.rhev_storage_address },
Expand Down
2 changes: 1 addition & 1 deletion server/app/lib/actions/fusor/deployment/rhev/create_cr.rb
Expand Up @@ -38,7 +38,7 @@ def run
"password" => deployment.rhev_root_password,
"organization_ids" => [deployment.organization_id] }
cr = ::Foreman::Model::Ovirt.create(rhev)
cr.uuid = cr.datacenters.find { |dc| dc[0] == deployment.rhev_database_name }[1]
cr.uuid = cr.datacenters.find { |dc| dc[0] == deployment.rhev_data_center_name }[1]
cr.save
::Fusor.log.debug '=== Leaving RHEV Compute Resource run method ==='
end
Expand Down
Expand Up @@ -34,10 +34,9 @@ def run
api_host = deployment.rhev_engine_host.facts['ipaddress']

# TODO: Revisit how the data center is stored in the deployment object
# name of "rhev_database_name" is non-intuitive,
# it'd be better to store "Default" in it opposed to allowing it to be empt
# Warning, the rhev_database_name may be empty, if so then assume value of "Default"
data_center = deployment.rhev_database_name.to_s[/.+/m] || "Default"
# it'd be better to store "Default" in it opposed to allowing it to be empty
# Warning, the rhev_data_center_name may be empty, if so then assume value of "Default"
data_center = deployment.rhev_data_center_name.to_s[/.+/m] || "Default"

cmd = "#{script_dir}ovirt_import_template.py "\
"--api_user '#{api_user}' "\
Expand Down
Expand Up @@ -73,7 +73,7 @@ def get_status(deployment_id)
api_user = "admin@internal"
api_password = deployment.rhev_engine_admin_password
# if db name is empty or nil, use Default
data_center = deployment.rhev_database_name.to_s[/.+/m] || "Default"
data_center = deployment.rhev_data_center_name.to_s[/.+/m] || "Default"

cmd = "#{script_dir}ovirt_get_datacenter_status.py "\
"--api_user #{api_user} "\
Expand Down
2 changes: 1 addition & 1 deletion server/app/serializers/fusor/deployment_serializer.rb
Expand Up @@ -5,7 +5,7 @@ class DeploymentSerializer < ActiveModel::Serializer
attributes :id, :name, :label, :description,
:deploy_rhev, :deploy_cfme, :deploy_openstack,
:rhev_engine_admin_password,
:rhev_database_name, :rhev_cluster_name, :rhev_storage_name,
:rhev_data_center_name, :rhev_cluster_name, :rhev_storage_name,
:rhev_storage_type, :rhev_storage_address, :rhev_cpu_type, :rhev_share_path,
:rhev_export_domain_name, :rhev_export_domain_address,
:rhev_export_domain_path, :rhev_local_storage_path,
Expand Down
@@ -0,0 +1,5 @@
class RenameRhevDataCenterName < ActiveRecord::Migration
def change
rename_column :fusor_deployments, :rhev_database_name, :rhev_data_center_name
end
end

0 comments on commit 903cf2d

Please sign in to comment.