diff --git a/app/assets/javascripts/controllers/ems_common/ems_common_form_controller.js b/app/assets/javascripts/controllers/ems_common/ems_common_form_controller.js deleted file mode 100644 index 56a0d50896f..00000000000 --- a/app/assets/javascripts/controllers/ems_common/ems_common_form_controller.js +++ /dev/null @@ -1,808 +0,0 @@ -ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '$attrs', 'emsCommonFormId', 'miqService', '$timeout', 'API', function($http, $scope, $attrs, emsCommonFormId, miqService, $timeout, API) { - var init = function() { - $scope.emsCommonModel = { - name: '', - emstype: '', - openstack_infra_providers_exist: false, - provider_id: '', - zone: '', - tenant_mapping_enabled: false, - hostname: '', - default_hostname: '', - amqp_hostname: '', - amqp_fallback_hostname1: '', - amqp_fallback_hostname2: '', - provider_options: {}, - metrics_hostname: '', - metrics_selection: '', - metrics_api_port: '', - metrics_security_protocol: '', - metrics_tls_ca_certs: '', - project: '', - default_api_port: '', - amqp_api_port: '', - api_version: '', - default_security_protocol: '', - default_tls_verify: true, - default_tls_ca_certs: '', - realm: '', - security_protocol: '', - amqp_security_protocol: '', - provider_region: '', - default_userid: '', - default_password: '', - amqp_userid: '', - amqp_password: '', - console_userid: '', - console_password: '', - smartstate_docker_userid: '', - smartstate_docker_password: '', - metrics_userid: '', - metrics_password: '', - metrics_database_name: '', - ssh_keypair_userid: '', - ssh_keypair_password: '', - service_account: '', - emstype_vm: false, - ems_common: true, - azure_tenant_id: '', - keystone_v3_domain_id: '', - subscription: '', - host_default_vnc_port_start: '', - host_default_vnc_port_end: '', - event_stream_selection: '', - bearer_token_exists: false, - ems_controller: '', - default_auth_status: '', - amqp_auth_status: '', - service_account_auth_status: '', - metrics_auth_status: '', - ssh_keypair_auth_status: '', - vmware_cloud_api_version: '', - prometheus_alerts_hostname: '', - prometheus_alerts_api_port: '', - prometheus_alerts_tls_ca_certs: '', - prometheus_alerts_auth_status: '', - prometheus_alerts_security_protocol: '', - smartstate_docker_auth_status: true, - alerts_selection: '', - console_auth_status: true, - virtualization_selection: '', - kubevirt_hostname: '', - kubevirt_api_port: '', - kubevirt_auth_status: '', - kubevirt_security_protocol: '', - kubevirt_tls_ca_certs: '', - kubevirt_password: '', - kubevirt_password_exists: false, - default_url: '', - default_assume_role: '', - }; - - $scope.emsOptionsModel = { - provider_options: {}, - provider_options_original_values: {}, - }; - - $scope.formId = emsCommonFormId; - $scope.afterGet = false; - $scope.modelCopy = angular.copy( $scope.emsCommonModel ); - $scope.formFieldsUrl = $attrs.formFieldsUrl; - $scope.createUrl = $attrs.createUrl; - $scope.updateUrl = $attrs.updateUrl; - $scope.checkAuthentication = true; - - $scope.model = 'emsCommonModel'; - - ManageIQ.angular.scope = $scope; - - if (emsCommonFormId === 'new') { - $scope.newRecord = true; - - miqService.sparkleOn(); - $http.get($scope.formFieldsUrl + emsCommonFormId) - .then(getNewEmsFormDataComplete) - .catch(miqService.handleFailure); - } else { - $scope.newRecord = false; - miqService.sparkleOn(); - - $http.get($scope.formFieldsUrl + emsCommonFormId) - .then(getEmsFormIdDataComplete) - .catch(miqService.handleFailure); - } - $scope.actionUrl = $scope.newRecord ? $scope.createUrl : $scope.updateUrl; - $scope.currentTab = 'default'; - - function getEmsFormIdDataComplete(response) { - var data = response.data; - - $scope.emsCommonModel.name = data.name; - $scope.emsCommonModel.emstype = data.emstype; - $scope.emsCommonModel.zone = data.zone; - $scope.emsCommonModel.zone_hidden = data.zone_hidden; - $scope.emsCommonModel.tenant_mapping_enabled = data.tenant_mapping_enabled; - $scope.emsCommonModel.hostname = data.hostname; - $scope.emsCommonModel.default_hostname = data.default_hostname; - $scope.emsCommonModel.amqp_hostname = data.amqp_hostname; - $scope.emsCommonModel.amqp_fallback_hostname1 = data.amqp_fallback_hostname1; - $scope.emsCommonModel.amqp_fallback_hostname2 = data.amqp_fallback_hostname2; - $scope.emsCommonModel.metrics_selection = data.metrics_selection; - $scope.emsCommonModel.metrics_hostname = data.metrics_hostname; - $scope.emsCommonModel.project = data.project; - - $scope.emsCommonModel.openstack_infra_providers_exist = data.openstack_infra_providers_exist; - - $scope.emsCommonModel.provider_id = data.provider_id !== undefined ? data.provider_id.toString() : ''; - - $scope.emsCommonModel.default_api_port = data.default_api_port !== undefined && data.default_api_port !== '' ? data.default_api_port.toString() : $scope.getDefaultApiPort($scope.emsCommonModel.emstype); - $scope.emsCommonModel.metrics_port = data.metrics_port !== undefined && data.metrics_port !== '' ? data.metrics_port.toString() : '443'; - $scope.emsCommonModel.amqp_api_port = data.amqp_api_port !== undefined && data.amqp_api_port !== '' ? data.amqp_api_port.toString() : '5672'; - $scope.emsCommonModel.metrics_database_name = data.metrics_database_name !== undefined && data.metrics_database_name !== '' ? data.metrics_database_name : data.metrics_default_database_name; - $scope.emsCommonModel.api_version = data.api_version; - $scope.emsCommonModel.default_security_protocol = data.default_security_protocol; - $scope.emsCommonModel.realm = data.realm; - $scope.emsCommonModel.security_protocol = data.security_protocol; - $scope.emsCommonModel.default_tls_verify = data.default_tls_verify; - $scope.emsCommonModel.default_tls_ca_certs = data.default_tls_ca_certs; - $scope.emsCommonModel.amqp_security_protocol = data.amqp_security_protocol !== '' ? data.amqp_security_protocol : 'non-ssl'; - $scope.emsCommonModel.metrics_security_protocol = data.metrics_security_protocol; - $scope.emsCommonModel.metrics_tls_ca_certs = data.metrics_tls_ca_certs; - $scope.emsCommonModel.provider_region = data.provider_region; - $scope.emsCommonModel.default_userid = data.default_userid; - $scope.emsCommonModel.amqp_userid = data.amqp_userid; - $scope.emsCommonModel.console_userid = data.console_userid; - $scope.emsCommonModel.metrics_userid = data.metrics_userid; - $scope.emsCommonModel.smartstate_docker_userid = data.smartstate_docker_userid; - $scope.emsCommonModel.vmware_cloud_api_version = data.api_version; - - $scope.emsCommonModel.ssh_keypair_userid = data.ssh_keypair_userid; - - $scope.emsCommonModel.service_account = data.service_account; - $scope.emsCommonModel.default_assume_role = data.assume_role; - $scope.emsCommonModel.azure_tenant_id = data.azure_tenant_id; - $scope.emsCommonModel.keystone_v3_domain_id = data.keystone_v3_domain_id; - $scope.emsCommonModel.subscription = data.subscription; - - $scope.emsCommonModel.host_default_vnc_port_start = data.host_default_vnc_port_start; - $scope.emsCommonModel.host_default_vnc_port_end = data.host_default_vnc_port_end; - - $scope.emsCommonModel.event_stream_selection = data.event_stream_selection; - - $scope.emsCommonModel.bearer_token_exists = data.bearer_token_exists; - - $scope.emsCommonModel.ems_controller = data.ems_controller; - $scope.emsCommonModel.default_auth_status = data.default_auth_status; - $scope.emsCommonModel.amqp_auth_status = data.amqp_auth_status; - $scope.emsCommonModel.service_account_auth_status = data.service_account_auth_status; - $scope.emsCommonModel.metrics_auth_status = data.metrics_auth_status; - $scope.emsCommonModel.ssh_keypair_auth_status = data.ssh_keypair_auth_status; - $scope.emsCommonModel.metrics_api_port = data.metrics_api_port !== undefined && data.metrics_api_port !== '' ? data.metrics_api_port.toString() : ''; - $scope.emsCommonModel.alerts_selection = data.alerts_selection; - $scope.emsCommonModel.prometheus_alerts_hostname = data.prometheus_alerts_hostname; - $scope.emsCommonModel.prometheus_alerts_api_port = data.prometheus_alerts_api_port !== undefined && data.prometheus_alerts_api_port !== '' ? data.prometheus_alerts_api_port.toString() : '443'; - $scope.emsCommonModel.prometheus_alerts_auth_status = data.prometheus_alerts_auth_status; - $scope.emsCommonModel.prometheus_alerts_security_protocol = data.prometheus_alerts_security_protocol; - $scope.emsCommonModel.prometheus_alerts_tls_ca_certs = data.prometheus_alerts_tls_ca_certs; - - $scope.emsCommonModel.virtualization_selection = data.virtualization_selection; - $scope.emsCommonModel.kubevirt_hostname = data.kubevirt_hostname; - $scope.emsCommonModel.kubevirt_api_port = data.kubevirt_api_port !== undefined && data.kubevirt_api_port !== '' ? data.kubevirt_api_port.toString() : '443'; - $scope.emsCommonModel.kubevirt_auth_status = data.kubevirt_auth_status; - $scope.emsCommonModel.kubevirt_security_protocol = data.kubevirt_security_protocol; - $scope.emsCommonModel.kubevirt_tls_ca_certs = data.kubevirt_tls_ca_certs; - $scope.emsCommonModel.kubevirt_password_exists = data.kubevirt_password_exists; - - $scope.emsCommonModel.default_url = data.default_url; - - $scope.currentTab = data.non_default_current_tab || 'default'; - - if ($scope.emsCommonModel.default_userid !== '') { - $scope.emsCommonModel.default_password = miqService.storedPasswordPlaceholder; - } - if ($scope.emsCommonModel.amqp_userid !== '') { - $scope.emsCommonModel.amqp_password = miqService.storedPasswordPlaceholder; - } - if ($scope.emsCommonModel.console_userid !== '') { - $scope.emsCommonModel.console_password = miqService.storedPasswordPlaceholder; - } - if ($scope.emsCommonModel.metrics_userid !== '') { - $scope.emsCommonModel.metrics_password = miqService.storedPasswordPlaceholder; - } - if ($scope.emsCommonModel.smartstate_docker_userid !== '') { - $scope.emsCommonModel.smartstate_docker_password = miqService.storedPasswordPlaceholder; - } - if ($scope.emsCommonModel.ssh_keypair_userid !== '') { - $scope.emsCommonModel.ssh_keypair_password = miqService.storedPasswordPlaceholder; - } - if ($scope.emsCommonModel.bearer_token_exists) { - $scope.emsCommonModel.default_userid = '_'; - $scope.emsCommonModel.default_password = miqService.storedPasswordPlaceholder; - } - if ($scope.emsCommonModel.kubevirt_password_exists) { - $scope.emsCommonModel.kubevirt_password = miqService.storedPasswordPlaceholder; - } - - $scope.afterGet = true; - $scope.modelCopy = angular.copy( $scope.emsCommonModel ); - - $scope.populatePostValidationModel(); - - miqService.sparkleOff(); - - $scope.hideDisabledTabs(); - - $scope.emsOptionsModel.provider_options_original_values = data.provider_options; - $scope.updateProviderOptionsDescription(); - } - - function getNewEmsFormDataComplete(response) { - var data = response.data; - - $scope.emsCommonModel.emstype = ''; - $scope.emsCommonModel.zone = data.zone; - $scope.emsCommonModel.tenant_mapping_enabled = data.tenant_mapping_enabled; - $scope.emsCommonModel.emstype_vm = data.emstype_vm; - $scope.emsCommonModel.openstack_infra_providers_exist = data.openstack_infra_providers_exist; - $scope.emsCommonModel.default_api_port = ''; - $scope.emsCommonModel.amqp_api_port = '5672'; - $scope.emsCommonModel.alerts_selection = data.alerts_selection; - $scope.emsCommonModel.prometheus_alerts_api_port = '443'; - $scope.emsCommonModel.prometheus_alerts_auth_status = data.prometheus_alerts_auth_status; - $scope.emsCommonModel.prometheus_alerts_security_protocol = data.prometheus_alerts_security_protocol; - $scope.emsCommonModel.prometheus_alerts_tls_ca_certs = data.prometheus_alerts_tls_ca_certs; - if (["openstack", "openstack_infra"].includes($scope.emsCommonModel.ems_controller)) { - $scope.emsCommonModel.api_version = 'v2'; - } - $scope.emsCommonModel.ems_controller = data.ems_controller; - $scope.emsCommonModel.ems_controller === 'ems_container' ? $scope.emsCommonModel.default_api_port = '8443' : $scope.emsCommonModel.default_api_port = ''; - $scope.emsCommonModel.metrics_api_port = '443'; - $scope.emsCommonModel.metrics_selection = data.metrics_selection; - $scope.emsCommonModel.default_security_protocol = data.default_security_protocol; - $scope.emsCommonModel.metrics_security_protocol = data.metrics_security_protocol; - $scope.emsCommonModel.default_tls_ca_certs = data.default_tls_ca_certs; - $scope.emsCommonModel.metrics_tls_ca_certs = data.metrics_tls_ca_certs; - $scope.emsCommonModel.default_auth_status = data.default_auth_status; - $scope.emsCommonModel.amqp_auth_status = data.amqp_auth_status; - $scope.emsCommonModel.service_account_auth_status = data.service_account_auth_status; - $scope.emsCommonModel.ssh_keypair_auth_status = true; - $scope.emsCommonModel.metrics_auth_status = data.metrics_auth_status; - $scope.emsCommonModel.vmware_cloud_api_version = '9.0'; - $scope.emsCommonModel.virtualization_selection = data.virtualization_selection; - $scope.emsCommonModel.kubevirt_api_port = $scope.emsCommonModel.default_api_port; - $scope.emsCommonModel.kubevirt_auth_status = data.kubevirt_auth_status; - $scope.emsCommonModel.kubevirt_security_protocol = $scope.emsCommonModel.default_security_protocol; - $scope.emsCommonModel.kubevirt_tls_ca_certs = $scope.emsCommonModel.default_tls_ca_certs; - $scope.emsCommonModel.kubevirt_password = data.kubevirt_password; - - miqService.sparkleOff(); - $scope.hideDisabledTabs(); - $scope.afterGet = true; - $scope.modelCopy = angular.copy( $scope.emsCommonModel ); - } - }; - - $scope.useridPrivileged = function() { - // disabled outside the default tab - if ($scope.currentTab !== 'default') { - return false; - } - - // disabled for container providers - if ($scope.emsCommonModel.ems_controller == 'ems_container') { - return false; - } - - // disabled for specific types - var disabled_types_list = [ - 'azure_stack', - 'gce', - 'kubevirt', - ]; - return ! disabled_types_list.includes($scope.emsCommonModel.emstype); - } - - $scope.hideDisabledTabs = function() { - if ($scope.emsCommonModel.alerts_selection === 'disabled') { - angular.element('#alerts_tab').hide(); - } - - if ($scope.emsCommonModel.metrics_selection === 'disabled') { - angular.element('#metrics_tab').hide(); - } - - if ($scope.emsCommonModel.virtualization_selection === 'disabled') { - angular.element('#kubevirt_tab').hide(); - } - }; - - $scope.changeAuthTab = function(id) { - $scope.currentTab = id; - }; - - $scope.changeAuthTabToVirtualization = function(id) { - $scope.emsCommonModel.kubevirt_hostname = $scope.emsCommonModel.default_hostname; - $scope.emsCommonModel.kubevirt_api_port = $scope.emsCommonModel.default_api_port; - $scope.emsCommonModel.kubevirt_security_protocol = $scope.emsCommonModel.default_security_protocol; - $scope.emsCommonModel.kubevirt_tls_verify = $scope.emsCommonModel.default_tls_verify; - $scope.emsCommonModel.kubevirt_tls_ca_certs = $scope.emsCommonModel.default_tls_ca_certs; - $scope.changeAuthTab(id); - }; - - $scope.canValidateBasicInfo = function() { - return $scope.isBasicInfoValid(); - }; - - $scope.isBasicInfoValid = function() { - if (($scope.currentTab === 'default' && $scope.emsCommonModel.emstype !== 'azure') && - ($scope.emsCommonModel.emstype === 'ec2' || - ['kubevirt', 'nuage_network', 'openstack', 'openstack_infra', 'rhevm', 'scvmm', 'vmwarews', 'vmware_cloud'].includes($scope.emsCommonModel.emstype) && - $scope.emsCommonModel.default_hostname) && - ($scope.emsCommonModel.default_userid !== '' && $scope.angularForm.default_userid !== undefined && $scope.angularForm.default_userid.$valid && - $scope.emsCommonModel.default_password !== '' && $scope.angularForm.default_password !== undefined && $scope.angularForm.default_password.$valid)) { - return true; - } else if (($scope.currentTab === 'amqp') && - ($scope.emsCommonModel.amqp_hostname) && - ($scope.emsCommonModel.amqp_userid !== '' && $scope.angularForm.amqp_userid !== undefined && $scope.angularForm.amqp_userid.$valid && - $scope.emsCommonModel.amqp_password !== '' && $scope.angularForm.amqp_password !== undefined && $scope.angularForm.amqp_password.$valid)) { - return true; - } else if (($scope.currentTab === 'console') && - ($scope.emsCommonModel.console_userid !== '' && $scope.angularForm.console_userid !== undefined && - $scope.emsCommonModel.console_password !== '' && $scope.angularForm.console_password !== undefined)) { - return true; - } else if (($scope.currentTab === 'smartstate_docker') && - ($scope.emsCommonModel.smartstate_docker_userid !== '' && $scope.angularForm.smartstate_docker_userid !== undefined && - $scope.emsCommonModel.smartstate_docker_password !== '' && $scope.angularForm.smartstate_docker_password !== undefined)) { - return true; - } else if (($scope.currentTab === 'default' && $scope.emsCommonModel.emstype === 'azure') && - ($scope.emsCommonModel.azure_tenant_id !== '' && $scope.angularForm.azure_tenant_id.$valid) && - ($scope.emsCommonModel.default_userid !== '' && $scope.angularForm.default_userid.$valid && - $scope.emsCommonModel.default_password !== '' && $scope.angularForm.default_password.$valid) && - ($scope.newRecord && $scope.angularForm.provider_region.$valid || !$scope.newRecord)) { - return true; - } else if (($scope.currentTab === 'ssh_keypair' && - ($scope.emsCommonModel.emstype === 'openstack' || $scope.emsCommonModel.emstype === 'openstack_infra')) && - ($scope.emsCommonModel.ssh_keypair_userid !== '' && $scope.angularForm.ssh_keypair_userid.$valid && - $scope.emsCommonModel.ssh_keypair_password !== '' && $scope.angularForm.ssh_keypair_password.$valid)) { - return true; - } else if (($scope.currentTab === 'metrics' && $scope.emsCommonModel.emstype === 'rhevm') && - $scope.emsCommonModel.metrics_database_name && - ($scope.emsCommonModel.metrics_hostname !== '' && $scope.angularForm.metrics_hostname.$valid) && - ($scope.emsCommonModel.metrics_userid !== '' && $scope.angularForm.metrics_userid.$valid && - $scope.emsCommonModel.metrics_password !== '' && $scope.angularForm.metrics_password.$valid)) { - return true; - } else if ($scope.currentTab === 'default' && - ['ems_container', 'ems_physical_infra'].indexOf($scope.emsCommonModel.ems_controller) >= 0 && - ($scope.emsCommonModel.emstype) && - ($scope.emsCommonModel.default_hostname !== '' && $scope.emsCommonModel.default_api_port) && - ($scope.emsCommonModel.default_password !== '' && $scope.angularForm.default_password.$valid)) { - return true; - } else if (($scope.emsCommonModel.ems_controller === 'ems_container') && - ($scope.emsCommonModel.emstype) && - ($scope.emsCommonModel.default_password !== '' && $scope.angularForm.default_password.$valid) && - (($scope.currentTab === 'metrics' && - $scope.emsCommonModel.metrics_hostname !== '' && - $scope.emsCommonModel.metrics_api_port) || - ($scope.currentTab === 'alerts' && - $scope.emsCommonModel.prometheus_alerts_hostname !== '' && - $scope.emsCommonModel.prometheus_alerts_api_port !== '') || - ($scope.currentTab === 'kubevirt' && - $scope.emsCommonModel.kubevirt_hostname !== '' && - $scope.emsCommonModel.kubevirt_password !== '' && - $scope.emsCommonModel.kubevirt_api_port !== ''))) { - return true; - } else if ($scope.emsCommonModel.emstype === 'gce' && $scope.emsCommonModel.project !== '' && - ($scope.currentTab === 'default' || - ($scope.currentTab === 'service_account' && $scope.emsCommonModel.service_account !== ''))) { - return true; - } else if ($scope.emsCommonModel.emstype === 'kubevirt') { - return true; - } else if ($scope.emsCommonModel.emstype === 'azure_stack') { - return !!$scope.emsCommonModel.azure_tenant_id && - !!$scope.emsCommonModel.subscription && - !!$scope.emsCommonModel.api_version && - !!$scope.emsCommonModel.default_hostname && - !!$scope.emsCommonModel.default_security_protocol && - !!$scope.emsCommonModel.default_api_port && - !!$scope.emsCommonModel.default_userid && - !!$scope.emsCommonModel.default_password - } - return false; - }; - - $scope.isDetectionEnabled = function() { - return ($scope.emsCommonModel.ems_controller === 'ems_container') && - ($scope.emsCommonModel.emstype === 'openshift') && - ($scope.emsCommonModel.default_hostname && $scope.emsCommonModel.default_api_port) && - ($scope.emsCommonModel.default_password !== '' && $scope.angularForm.default_password.$valid); - }; - - var emsCommonEditButtonClicked = function(buttonName, _serializeFields, $event) { - miqService.sparkleOn(); - var url = $scope.updateUrl + '?button=' + buttonName; - miqService.restAjaxButton(url, $event.target); - }; - - var emsCommonAddButtonClicked = function(buttonName, _serializeFields, $event) { - miqService.sparkleOn(); - var url = $scope.createUrl + '?button=' + buttonName; - miqService.restAjaxButton(url, $event.target); - }; - - $scope.cancelClicked = function($event) { - angular.element('#button_name').val('cancel'); - if ($scope.newRecord) { - emsCommonAddButtonClicked('cancel', false, $event); - } else { - emsCommonEditButtonClicked('cancel', false, $event); - } - - $scope.angularForm.$setPristine(true); - }; - - $scope.resetClicked = function() { - $scope.$broadcast('resetClicked'); - $scope.emsCommonModel = angular.copy( $scope.modelCopy ); - $scope.angularForm.$setPristine(true); - miqService.miqFlash('warn', __('All changes have been reset')); - - if ($scope.emsCommonModel.event_stream_selection === 'ceilometer') { - $scope.$broadcast('clearErrorOnTab', {tab: 'amqp'}); - } - - var authStatus = $scope.currentTab + '_auth_status'; - if ($scope.emsCommonModel[authStatus] === true) { - $scope.postValidationModelRegistry($scope.currentTab); - } - }; - - $scope.detectClicked = function($event) { - miqService.sparkleOn(); - miqService.detectWithRest($event, $scope.actionUrl) - .then(function success(data) { - $scope.updateHostname(data.hostname); - miqService.miqFlash(data.level, data.message); - miqSparkleOff(); - }); - }; - - $scope.saveClicked = function($event, formSubmit) { - if (formSubmit) { - angular.element('#button_name').val('save'); - emsCommonEditButtonClicked('save', true, $event); - } else { - $event.preventDefault(); - } - }; - - $scope.addClicked = function($event, formSubmit) { - if (formSubmit) { - angular.element('#button_name').val('add'); - emsCommonAddButtonClicked('add', true, $event); - } else { - $event.preventDefault(); - } - }; - - $scope.tabSelectionChanged = function(tabSelector, selection) { - if (selection === 'disabled') { - $scope.changeAuthTab('default'); - angular.element('.nav-tabs a[href="#default"]').tab('show'); - angular.element(tabSelector).hide(); - } else { - angular.element(tabSelector).show(); - } - }; - - $scope.metricSelectionChanged = function() { - $scope.tabSelectionChanged('#metrics_tab', $scope.emsCommonModel.metrics_selection); - }; - - $scope.alertsSelectionChanged = function() { - $scope.tabSelectionChanged('#alerts_tab', $scope.emsCommonModel.alerts_selection); - }; - - $scope.virtualizationSelectionChanged = function() { - $scope.tabSelectionChanged('#kubevirt_tab', $scope.emsCommonModel.virtualization_selection); - }; - - $scope.providerTypeChanged = function() { - $scope.updateProviderOptionsDescription(); - if ($scope.emsCommonModel.ems_controller === 'ems_container') { - if ($scope.emsCommonModel.emstype === 'kubernetes') { - $scope.emsCommonModel.default_api_port = '6443'; - } else { - $scope.emsCommonModel.default_api_port = '8443'; - } - return; - } - if ($scope.emsCommonModel.emstype === 'gce') { - $scope.currentTab = 'service_account'; - return; - } - $scope.emsCommonModel.default_api_port = ''; - $scope.emsCommonModel.provider_region = ''; - $scope.emsCommonModel.default_security_protocol = ''; - $scope.emsCommonModel.default_tls_verify = true; - $scope.emsCommonModel.default_tls_ca_certs = ''; - $scope.note = ''; - if ($scope.emsCommonModel.emstype === 'openstack' || $scope.emsCommonModel.emstype === 'openstack_infra') { - $scope.emsCommonModel.default_api_port = $scope.getDefaultApiPort($scope.emsCommonModel.emstype); - $scope.emsCommonModel.event_stream_selection = 'ceilometer'; - $scope.emsCommonModel.amqp_security_protocol = 'non-ssl'; - if ($scope.emsCommonModel.emstype === 'openstack') { - $scope.emsCommonModel.tenant_mapping_enabled = false; - } - } else if ($scope.emsCommonModel.emstype === 'nuage_network') { - $scope.emsCommonModel.default_api_port = $scope.getDefaultApiPort($scope.emsCommonModel.emstype); - $scope.emsCommonModel.event_stream_selection = 'none'; - $scope.emsCommonModel.amqp_security_protocol = 'non-ssl'; - } else if ($scope.emsCommonModel.emstype === 'scvmm') { - $scope.emsCommonModel.default_security_protocol = 'ssl'; - } else if ($scope.emsCommonModel.emstype === 'rhevm') { - $scope.emsCommonModel.metrics_api_port = '5432'; - $scope.emsCommonModel.default_api_port = $scope.getDefaultApiPort($scope.emsCommonModel.emstype); - $scope.emsCommonModel.metrics_database_name = 'ovirt_engine_history'; - } else if ($scope.emsCommonModel.emstype === 'vmware_cloud') { - $scope.emsCommonModel.default_api_port = '443'; - $scope.emsCommonModel.event_stream_selection = 'none'; - $scope.emsCommonModel.amqp_security_protocol = 'non-ssl'; - } else if ($scope.emsCommonModel.emstype === 'lenovo_ph_infra') { - $scope.emsCommonModel.default_api_port = '443'; - } - }; - - $scope.openstackSecurityProtocolChanged = function() { - if ($scope.emsCommonModel.emstype === 'openstack' || $scope.emsCommonModel.emstype === 'openstack_infra') { - if ($scope.emsCommonModel.default_security_protocol === 'non-ssl') { - $scope.emsCommonModel.default_api_port = $scope.getDefaultApiPort($scope.emsCommonModel.emstype); - } else { - $scope.emsCommonModel.default_api_port = '13000'; - } - } - }; - - $scope.getDefaultApiPort = function(emstype) { - if ( emstype === 'openstack' || emstype === 'openstack_infra') { - return '5000'; - } - - return ''; - }; - - $scope.populatePostValidationModel = function() { - if ($scope.emsCommonModel.default_auth_status === true) { - $scope.postValidationModelRegistry('default'); - } - if ($scope.emsCommonModel.amqp_auth_status === true) { - $scope.postValidationModelRegistry('amqp'); - } - if ($scope.emsCommonModel.console_auth_status === true) { - $scope.postValidationModelRegistry('console'); - } - if ($scope.emsCommonModel.service_account_auth_status === true) { - $scope.postValidationModelRegistry('service_account'); - } - if ($scope.emsCommonModel.metrics_auth_status === true) { - $scope.postValidationModelRegistry('metrics'); - } - if ($scope.emsCommonModel.ssh_keypair_auth_status === true) { - $scope.postValidationModelRegistry('ssh_keypair'); - } - if ($scope.emsCommonModel.prometheus_alerts_auth_status === true) { - $scope.postValidationModelRegistry('prometheus_alerts'); - } - if ($scope.emsCommonModel.kubevirt_auth_status === true) { - $scope.postValidationModelRegistry('kubevirt'); - } - }; - - $scope.postValidationModelRegistry = function(prefix) { - if ($scope.postValidationModel === undefined) { - $scope.postValidationModel = { - default: {}, - amqp: {}, - console: {}, - metrics: {}, - ssh_keypair: {}, - prometheus_alerts: {}, - kubevirt: {}, - }; - } - if (prefix === 'default') { - if ($scope.newRecord) { - var default_password = $scope.emsCommonModel.default_password; - } else { - var default_password = $scope.emsCommonModel.default_password === '' ? '' : miqService.storedPasswordPlaceholder; - } - $scope.postValidationModel.default = { - default_hostname: $scope.emsCommonModel.default_hostname, - default_api_port: $scope.emsCommonModel.default_api_port, - default_security_protocol: $scope.emsCommonModel.default_security_protocol, - default_tls_verify: $scope.emsCommonModel.default_tls_verify, - default_tls_ca_certs: $scope.emsCommonModel.default_tls_ca_certs, - default_userid: $scope.emsCommonModel.default_userid, - default_password: default_password, - default_url: $scope.emsCommonModel.default_url, - default_assume_role: $scope.emsCommonModel.default_assume_role, - realm: $scope.emsCommonModel.realm, - azure_tenant_id: $scope.emsCommonModel.azure_tenant_id, - subscription: $scope.emsCommonModel.subscription, - provider_region: $scope.emsCommonModel.provider_region, - }; - } else if (prefix === 'amqp') { - if ($scope.newRecord) { - var amqp_password = $scope.emsCommonModel.amqp_password; - } else { - var amqp_password = $scope.emsCommonModel.amqp_password === '' ? '' : miqService.storedPasswordPlaceholder; - } - $scope.postValidationModel.amqp = { - amqp_hostname: $scope.emsCommonModel.amqp_hostname, - amqp_fallback_hostname1: $scope.emsCommonModel.amqp_fallback_hostname1, - amqp_fallback_hostname2: $scope.emsCommonModel.amqp_fallback_hostname2, - amqp_api_port: $scope.emsCommonModel.amqp_api_port, - amqp_security_protocol: $scope.emsCommonModel.amqp_security_protocol, - amqp_userid: $scope.emsCommonModel.amqp_userid, - amqp_password: amqp_password, - }; - } else if (prefix === 'console') { - if ($scope.newRecord) { - var console_password = $scope.emsCommonModel.console_password; - } else { - var console_password = $scope.emsCommonModel.console_password === '' ? '' : miqService.storedPasswordPlaceholder; - } - $scope.postValidationModel.console = { - console_userid: $scope.emsCommonModel.console_userid, - console_password: console_password, - }; - } else if (prefix === 'metrics') { - var metricsValidationModel = { - metrics_hostname: $scope.emsCommonModel.metrics_hostname, - metrics_api_port: $scope.emsCommonModel.metrics_api_port, - }; - if ($scope.emsCommonModel.metrics_selection === 'hawkular' || $scope.emsCommonModel.metrics_selection === 'prometheus') { - metricsValidationModel.metrics_security_protocol = $scope.emsCommonModel.metrics_security_protocol; - metricsValidationModel.metrics_tls_ca_certs = $scope.emsCommonModel.metrics_tls_ca_certs; - } else { - if ($scope.newRecord) { - var metrics_password = $scope.emsCommonModel.metrics_password; - } else { - var metrics_password = $scope.emsCommonModel.metrics_password === '' ? '' : miqService.storedPasswordPlaceholder; - } - metricsValidationModel.metrics_userid = $scope.emsCommonModel.metrics_userid; - metricsValidationModel.metrics_password = metrics_password; - } - $scope.postValidationModel.metrics = metricsValidationModel; - } else if (prefix === 'ssh_keypair') { - if ($scope.newRecord) { - var ssh_keypair_password = $scope.emsCommonModel.ssh_keypair_password; - } else { - var ssh_keypair_password = $scope.emsCommonModel.ssh_keypair_password === '' ? '' : miqService.storedPasswordPlaceholder; - } - $scope.postValidationModel.ssh_keypair = { - ssh_keypair_userid: $scope.emsCommonModel.ssh_keypair_userid, - ssh_keypair_password: ssh_keypair_password, - }; - } else if (prefix === 'service_account') { - $scope.postValidationModel.service_account = { - service_account: $scope.emsCommonModel.service_account, - }; - } else if (prefix === 'prometheus_alerts') { - $scope.postValidationModel.prometheus_alerts = {}; - ['prometheus_alerts_hostname', 'prometheus_alerts_api_port', 'prometheus_alerts_security_protocol', 'prometheus_alerts_tls_ca_certs'] - .forEach( function(resource) { - $scope.postValidationModel.prometheus_alerts[resource] = $scope.emsCommonModel[resource]; - }); - } else if (prefix === 'kubevirt') { - $scope.postValidationModel.kubevirt = {}; - ['kubevirt_hostname', 'kubevirt_api_port', 'kubevirt_security_protocol', 'kubevirt_tls_ca_certs', 'kubevirt_password'] - .forEach( function(resource) { - $scope.postValidationModel.kubevirt[resource] = $scope.emsCommonModel[resource]; - }); - } - }; - - $scope.validateClicked = function($event, _authType, formSubmit) { - miqService.validateWithREST($event, $scope.currentTab, $scope.actionUrl, formSubmit) - .then(function success(data) { - // check if data object is a JSON, otherwise (recieved JS or HTML) output a warning to the user. - if (data === Object(data)) { - $timeout(function() { - $scope.$apply(function() { - if (data.level === 'error') { - $scope.updateAuthStatus(false); - } else { - $scope.updateAuthStatus(true); - } - miqService.miqFlash(data.level, data.message, data.options); - miqSparkleOff(); - }); - }); - } else { - miqService.miqFlash('error', __('Something went wrong, please check the logs for more information.')); - miqSparkleOff(); - } - }); - }; - - $scope.updateAuthStatus = function(updatedValue) { - $scope.angularForm[$scope.currentTab + '_auth_status'].$setViewValue(updatedValue); - }; - - $scope.updateHostname = function(value) { - if ($scope.currentTab === 'alerts') { - $scope.emsCommonModel.prometheus_alerts_hostname = value; - } else { - $scope.emsCommonModel.metrics_hostname = value; - } - }; - - $scope.radioSelectionChanged = function() { - if ($scope.emsCommonModel.event_stream_selection === 'ceilometer' || - $scope.emsCommonModel.event_stream_selection === 'none') { - if ($scope.postValidationModel !== undefined) { - $scope.emsCommonModel.amqp_hostname = $scope.postValidationModel.amqp.amqp_hostname; - $scope.emsCommonModel.amqp_fallback_hostname1 = $scope.postValidationModel.amqp.amqp_fallback_hostname1; - $scope.emsCommonModel.amqp_fallback_hostname2 = $scope.postValidationModel.amqp.amqp_fallback_hostname2; - $scope.emsCommonModel.amqp_api_port = $scope.postValidationModel.amqp.amqp_api_port; - $scope.emsCommonModel.amqp_security_protocol = $scope.postValidationModel.amqp.amqp_security_protocol; - $scope.emsCommonModel.amqp_userid = $scope.postValidationModel.amqp.amqp_userid; - $scope.emsCommonModel.amqp_password = $scope.postValidationModel.amqp.amqp_password; - } - $scope.$broadcast('clearErrorOnTab', {tab: 'amqp'}); - } - }; - - $scope.updateProviderOptionsDescription = function() { - API.options('/api/providers').then(function(response) { - $scope.setProviderOptionsDescription(response.data); - }); - }; - - $scope.setProviderOptionsDescription = function(apiResponse) { - if (!apiResponse.hasOwnProperty('provider_settings')) { - return; - } - if (!apiResponse.provider_settings.hasOwnProperty($scope.emsCommonModel.emstype)) { - return; - } - $scope.emsOptionsModel.provider_options = apiResponse.provider_settings[$scope.emsCommonModel.emstype]; - if ($scope.emsOptionsModel.provider_options.hasOwnProperty('advanced_settings')) { - var advanced_settings = $scope.emsOptionsModel.provider_options.advanced_settings.settings; - $scope.emsCommonModel.provider_options.advanced_settings = {}; - for (var section in advanced_settings) { - if (advanced_settings.hasOwnProperty(section)) { - $scope.emsCommonModel.provider_options.advanced_settings[section] = {}; - $scope.updateProviderOptionsOldValues(advanced_settings[section], - $scope.emsCommonModel.provider_options.advanced_settings[section]); - } - } - } - if ($scope.emsOptionsModel.provider_options.hasOwnProperty('proxy_settings')) { - $scope.emsCommonModel.provider_options.proxy_settings = {}; - $scope.updateProviderOptionsOldValues($scope.emsOptionsModel.provider_options.proxy_settings, - $scope.emsCommonModel.provider_options.proxy_settings); - } - }; - - // Sets the values and names of the options in sourceSection and destSection from - // $scope.emsOptionsModel.provider_options_original_values if they exist there. - $scope.updateProviderOptionsOldValues = function(sourceSection, destSection) { - var section_name = _.snakeCase(sourceSection.label); - sourceSection.section_name = section_name; - for (var option in sourceSection.settings) { - if (sourceSection.settings.hasOwnProperty(option)) { - if ($scope.emsOptionsModel.provider_options_original_values.hasOwnProperty(section_name) && - $scope.emsOptionsModel.provider_options_original_values[section_name].hasOwnProperty(option)) { - sourceSection.settings[option].value = $scope.emsOptionsModel.provider_options_original_values[section_name][option]; - } else { - sourceSection.settings[option].value = ''; - } - sourceSection.settings[option].name = option; - destSection[option] = sourceSection.settings[option]; - } - } - }; - - init(); -}]); diff --git a/app/controllers/ems_block_storage_controller.rb b/app/controllers/ems_block_storage_controller.rb index fd00a8319ec..fd79625730b 100644 --- a/app/controllers/ems_block_storage_controller.rb +++ b/app/controllers/ems_block_storage_controller.rb @@ -2,7 +2,6 @@ class EmsBlockStorageController < ApplicationController include Mixins::GenericListMixin include Mixins::GenericShowMixin include Mixins::EmsCommon - include Mixins::EmsCommon::Angular include Mixins::GenericSessionMixin include Mixins::BreadcrumbsMixin @@ -23,19 +22,6 @@ def breadcrumb_name(_model) _('Block Storage Managers') end - def ems_path(*args) - path_hash = {:action => 'show', :id => args[0].id.to_s } - path_hash.merge(args[1]) - end - - def new_ems_path - {:action => 'new'} - end - - def ems_storage_form_fields - ems_form_fields - end - # Show the main MS list view def show_list opts = {:supported_features_filter => "supports_block_storage?", diff --git a/app/controllers/ems_cloud_controller.rb b/app/controllers/ems_cloud_controller.rb index d372458e4f4..bba176adf1d 100644 --- a/app/controllers/ems_cloud_controller.rb +++ b/app/controllers/ems_cloud_controller.rb @@ -2,7 +2,6 @@ class EmsCloudController < ApplicationController include Mixins::GenericListMixin include Mixins::GenericShowMixin include Mixins::EmsCommon # common methods for EmsInfra/Cloud controllers - include Mixins::EmsCommon::Angular include Mixins::GenericSessionMixin include Mixins::DashboardViewMixin include Mixins::BreadcrumbsMixin @@ -34,21 +33,9 @@ def show super end - def ems_path(*args) - ems_cloud_path(*args) - end - - def new_ems_path - new_ems_cloud_path - end - - def ems_cloud_form_fields - ems_form_fields - end - # Special EmsCloud link builder for restful routes def show_link(ems, options = {}) - ems_path(ems.id, options) + ems_cloud_path(ems.id, options) end def restful? diff --git a/app/controllers/ems_container_controller.rb b/app/controllers/ems_container_controller.rb index 94cefb19c56..8964d8e4bf8 100644 --- a/app/controllers/ems_container_controller.rb +++ b/app/controllers/ems_container_controller.rb @@ -2,7 +2,6 @@ class EmsContainerController < ApplicationController include Mixins::GenericListMixin include Mixins::GenericShowMixin include Mixins::EmsCommon # common methods for EmsInfra/Cloud/Container controllers - include Mixins::EmsCommon::Angular include Mixins::GenericSessionMixin include Mixins::DashboardViewMixin include ContainersExternalLoggingSupportMixin @@ -31,89 +30,6 @@ def show super end - def ems_path(*args) - ems_container_path(*args) - end - - def new_ems_path - new_ems_container_path - end - - def ems_container_form_fields - ems_form_fields - end - - def update - assert_privileges("#{permission_prefix}_edit") - if params[:button] == "detect" - update_ems_button_detect - else - super - end - end - - def create - assert_privileges("#{permission_prefix}_new") - if params[:button] == "detect" - create_ems_button_detect - else - super - end - end - - def create_ems_button_detect - ems = model.model_from_emstype(params[:emstype]).new - update_ems_button_detect(ems) - end - - def update_ems_button_detect(verify_ems = nil) - route_type = if params[:current_tab] == "alerts" - "prometheus_alerts" - else - params[:metrics_selection] - end - - verify_ems ||= find_record_with_rbac(model, params[:id]) - set_ems_record_vars(verify_ems, :validate) - @in_a_form = true - - begin - raise "Route detection not applicable for provider type" unless verify_ems.respond_to?(:hostname_for_service) - - result = verify_ems.hostname_for_service(route_type) - add_flash(_("Route Detection: success")) - rescue StandardError => e - $log.warn("MIQ(#{controller_name}_controller-#{action_name}): get_hostname_from_routes error: #{e.message}") - add_flash(_("Route Detection: failure [%{details}]") % {:details => e.message}, :error) - end - - render :json => { - :message => @flash_array.last[:message], - :level => @flash_array.last[:level], - :hostname => result - } - end - - def retrieve_metrics_selection - if @ems.connection_configurations.try(:prometheus) - "prometheus" - elsif @ems.connection_configurations.try(:hawkular) - "hawkular" - else - "disabled" - end - end - - def retrieve_alerts_selection - return "disabled" if @ems.connection_configurations.try(:prometheus_alerts).nil? - - "prometheus" - end - - def retrieve_virtualization_selection - @ems.connection_configurations.try(:kubevirt).nil? ? "disabled" : "kubevirt" - end - def restful? true end @@ -126,9 +42,9 @@ def textual_group_list helper_method :textual_group_list ############################ - # Special EmsCloud link builder for restful routes + # Special EmsContainer link builder for restful routes def show_link(ems, options = {}) - ems_path(ems.id, options) + ems_container_path(ems.id, options) end def breadcrumbs_options diff --git a/app/controllers/ems_infra_controller.rb b/app/controllers/ems_infra_controller.rb index a653bebb179..b557955cda2 100644 --- a/app/controllers/ems_infra_controller.rb +++ b/app/controllers/ems_infra_controller.rb @@ -2,7 +2,6 @@ class EmsInfraController < ApplicationController include Mixins::GenericListMixin include Mixins::GenericShowMixin include Mixins::EmsCommon # common methods for EmsInfra/Cloud controllers - include Mixins::EmsCommon::Angular include Mixins::DashboardViewMixin include Mixins::BreadcrumbsMixin @@ -33,14 +32,6 @@ def show super end - def ems_path(*args) - ems_infra_path(*args) - end - - def new_ems_path - new_ems_infra_path - end - def show_list @showtype = nil super @@ -50,11 +41,6 @@ def index redirect_to(:action => 'show_list') end - def new - @disabled_ems_infra_types = [%w[KubeVirt kubevirt]] - super - end - def scaling assert_privileges("ems_infra_scale") @@ -219,10 +205,6 @@ def open_admin_ui_done end end - def ems_infra_form_fields - ems_form_fields - end - def restful? true end @@ -243,9 +225,9 @@ def record_class end ############################ - # Special EmsCloud link builder for restful routes + # Special EmsInfra link builder for restful routes def show_link(ems, options = {}) - ems_path(ems.id, options) + ems_infra_path(ems.id, options) end def update_stack_up(stack, stack_parameters, provider_id, return_message) diff --git a/app/controllers/ems_network_controller.rb b/app/controllers/ems_network_controller.rb index 9759ca55e9c..b0f45c7994f 100644 --- a/app/controllers/ems_network_controller.rb +++ b/app/controllers/ems_network_controller.rb @@ -2,7 +2,6 @@ class EmsNetworkController < ApplicationController include Mixins::GenericListMixin include Mixins::GenericShowMixin include Mixins::EmsCommon - include Mixins::EmsCommon::Angular include Mixins::GenericSessionMixin include Mixins::BreadcrumbsMixin @@ -19,18 +18,6 @@ def self.table_name @table_name ||= "ems_network" end - def ems_path(*args) - ems_network_path(*args) - end - - def new_ems_path - {:action => 'new'} - end - - def ems_network_form_fields - ems_form_fields - end - def restful? true end diff --git a/app/controllers/ems_object_storage_controller.rb b/app/controllers/ems_object_storage_controller.rb index dede65cd9cb..a0733ff2cb2 100644 --- a/app/controllers/ems_object_storage_controller.rb +++ b/app/controllers/ems_object_storage_controller.rb @@ -2,7 +2,6 @@ class EmsObjectStorageController < ApplicationController include Mixins::GenericListMixin include Mixins::GenericShowMixin include Mixins::EmsCommon - include Mixins::EmsCommon::Angular include Mixins::GenericSessionMixin include Mixins::BreadcrumbsMixin @@ -23,11 +22,6 @@ def breadcrumb_name(_model) _('Object Storage Managers') end - def ems_path(*args) - path_hash = {:action => 'show', :id => args[0].id.to_s } - path_hash.merge(args[1]) - end - def show_list opts = {:supported_features_filter => "supports_object_storage?", :layout => "ems_storage", @@ -35,14 +29,6 @@ def show_list process_show_list(opts) end - def new_ems_path - {:action => 'new'} - end - - def ems_storage_form_fields - ems_form_fields - end - def breadcrumbs_options { :breadcrumbs => [ diff --git a/app/controllers/ems_physical_infra_controller.rb b/app/controllers/ems_physical_infra_controller.rb index 1420f990140..55481c63306 100644 --- a/app/controllers/ems_physical_infra_controller.rb +++ b/app/controllers/ems_physical_infra_controller.rb @@ -2,7 +2,6 @@ class EmsPhysicalInfraController < ApplicationController include Mixins::GenericListMixin include Mixins::GenericShowMixin include Mixins::EmsCommon # common methods for EmsInfra/Cloud controllers - include Mixins::EmsCommon::Angular include Mixins::GenericSessionMixin include Mixins::DashboardViewMixin include Mixins::BreadcrumbsMixin @@ -20,35 +19,6 @@ def self.table_name @table_name ||= "ems_physical_infra" end - def ems_path(*args) - ems_physical_infra_path(*args) - end - - def new_ems_path - new_ems_physical_infra_path - end - - def ems_physical_infra_form_fields - assert_privileges("#{permission_prefix}_edit") - @ems = model.new if params[:id] == 'new' - @ems = find_record_with_rbac(model, params[:id]) if params[:id] != 'new' - - render :json => { - :name => @ems.name, - :emstype => @ems.emstype, - :zone => zone, - :provider_id => @ems.provider_id || "", - :hostname => @ems.hostname, - :default_hostname => @ems.connection_configurations.default.endpoint.hostname, - :default_api_port => @ems.connection_configurations.default.endpoint.port, - :provider_region => @ems.provider_region, - :default_userid => @ems.authentication_userid || "", - :ems_controller => controller_name, - :default_auth_status => default_auth_status, - :default_security_protocol => @ems.security_protocol || "", - } - end - def display_physical_servers_with_host nested_list(PhysicalServer, :named_scope => :with_hosts, :breadcrumb_title => _("Physical Servers with Host")) end @@ -78,9 +48,9 @@ def restful? private ############################ - # Special EmsCloud link builder for restful routes + # Special EmsPhysicalInfra link builder for restful routes def show_link(ems, options = {}) - ems_path(ems.id, options) + ems_physical_infra_path(ems.id, options) end def breadcrumbs_options diff --git a/app/controllers/ems_storage_controller.rb b/app/controllers/ems_storage_controller.rb index cc75b543ad6..15c1ddaf75c 100644 --- a/app/controllers/ems_storage_controller.rb +++ b/app/controllers/ems_storage_controller.rb @@ -2,7 +2,6 @@ class EmsStorageController < ApplicationController include Mixins::GenericListMixin include Mixins::GenericShowMixin include Mixins::EmsCommon - include Mixins::EmsCommon::Angular include Mixins::GenericSessionMixin include Mixins::BreadcrumbsMixin @@ -19,19 +18,6 @@ def self.table_name @table_name ||= "ems_storage" end - def ems_path(*args) - path_hash = {:action => 'show', :id => args[0].id.to_s } - path_hash.merge(args[1]) - end - - def new_ems_path - {:action => 'new'} - end - - def ems_storage_form_fields - ems_form_fields - end - TYPE_CHECK_SHOW_IDENTIFIERS = %w[ems_storage_show].freeze def check_generic_rbac diff --git a/app/controllers/mixins/ems_common.rb b/app/controllers/mixins/ems_common.rb index debb1d4846a..53047950153 100644 --- a/app/controllers/mixins/ems_common.rb +++ b/app/controllers/mixins/ems_common.rb @@ -136,7 +136,6 @@ def default_show_template def new assert_privileges("#{permission_prefix}_new") @ems = model.new - set_form_vars @in_a_form = true session[:changed] = nil drop_breadcrumb(:name => _("Add New %{table}") % {:table => ui_lookup(:table => table_name)}, @@ -159,7 +158,6 @@ def edit }, :error) return redirect_to(:action => @lastaction || "show_list") end - set_form_vars @in_a_form = true session[:changed] = false drop_breadcrumb(:name => _("Edit %{object_type} '%{object_name}'") % {:object_type => ui_lookup(:tables => table_name), :object_name => @ems.name}, @@ -522,91 +520,6 @@ def process_check_compliance(model, ids) javascript_flash end - # Set form variables for edit - def set_form_vars - form_instance_vars - end - - def form_instance_vars - @server_zones = [] - zones = Zone.visible.order(Zone.arel_table[:name].lower) - zones.each do |zone| - @server_zones.push([zone.description, zone.name]) - end - @ems_types = Array(model.supported_types_and_descriptions_hash.invert).sort_by(&:first) - - @provider_regions = retrieve_provider_regions - @openstack_infra_providers = retrieve_openstack_infra_providers - @openstack_security_protocols = retrieve_openstack_security_protocols - @amqp_security_protocols = retrieve_amqp_security_protocols - @nuage_security_protocols = retrieve_nuage_security_protocols - @container_security_protocols = retrieve_container_security_protocols - @scvmm_security_protocols = [[_('Basic (SSL)'), 'ssl'], ['Kerberos', 'kerberos']] - @openstack_api_versions = retrieve_openstack_api_versions - @vmware_cloud_api_versions = retrieve_vmware_cloud_api_versions - @azure_stack_api_versions = retrieve_azure_stack_api_versions - @emstype_display = model.supported_types_and_descriptions_hash[@ems.emstype] - if @ems.respond_to?(:description) - @ems_region_display = @ems.description - end - @nuage_api_versions = retrieve_nuage_api_versions - @redfish_security_protocols = retrieve_security_protocols - end - - def retrieve_provider_regions - managers = model.supported_subclasses.select(&:supports_regions?) - managers.each_with_object({}) do |manager, provider_regions| - regions = manager.parent::Regions.all.sort_by { |r| r[:description] } - provider_regions[manager.ems_type] = regions.map do |region| - [region[:description], region[:name]] - end - end - end - private :retrieve_provider_regions - - def retrieve_openstack_infra_providers - ManageIQ::Providers::Openstack::Provider.pluck(:name, :id) - end - - def retrieve_openstack_api_versions - [['Keystone v2', 'v2'], ['Keystone v3', 'v3']] - end - - def retrieve_vmware_cloud_api_versions - [['vCloud API 5.1', '5.1'], ['vCloud API 5.5', '5.5'], ['vCloud API 5.6', '5.6'], ['vCloud API 9.0', '9.0']] - end - - def retrieve_nuage_api_versions - [['Version 3.2', 'v3_2'], ['Version 4.0', 'v4_0'], ['Version 5.0', 'v5.0']] - end - - def retrieve_azure_stack_api_versions - [['2017-03-09 Profile', 'V2017_03_09'], ['2018-03-01 Profile', 'V2018_03_01']] - end - - def retrieve_security_protocols - [[_('SSL without validation'), 'ssl'], [_('SSL'), 'ssl-with-validation'], [_('Non-SSL'), 'non-ssl']] - end - - def retrieve_openstack_security_protocols - retrieve_security_protocols - end - - def retrieve_nuage_security_protocols - retrieve_security_protocols - end - - def retrieve_amqp_security_protocols - # OSP8 doesn't support SSL for AMQP - [[_('Non-SSL'), 'non-ssl']] - end - - def retrieve_container_security_protocols - [[_('SSL'), 'ssl-with-validation'], - [_('SSL trusting custom CA'), 'ssl-with-validation-custom-ca'], - [_('SSL without validation'), 'ssl-without-validation']] - end - # Delete all selected or single displayed ems(s) def deleteemss assert_privileges(params[:pressed]) diff --git a/app/controllers/mixins/ems_common/angular.rb b/app/controllers/mixins/ems_common/angular.rb deleted file mode 100644 index 5ad03b38ef0..00000000000 --- a/app/controllers/mixins/ems_common/angular.rb +++ /dev/null @@ -1,895 +0,0 @@ -require 'openssl' -require 'webrick/httputils' - -module Mixins - module EmsCommon - module Angular - extend ActiveSupport::Concern - - OPENSTACK_PARAMS = %i[name provider_region api_version default_security_protocol keystone_v3_domain_id default_hostname default_api_port default_userid event_stream_selection].freeze - OPENSTACK_AMQP_PARAMS = %i[name provider_region api_version amqp_security_protocol keystone_v3_domain_id amqp_hostname amqp_api_port amqp_userid event_stream_selection].freeze - - included do - include Mixins::GenericFormMixin - end - - def update - assert_privileges("#{permission_prefix}_edit") - case params[:button] - when "cancel" then update_ems_button_cancel - when "save" then update_ems_button_save - when "validate" then update_ems_button_validate - end - end - - def update_ems_button_cancel - update_ems = find_record_with_rbac(model, params[:id]) - flash_to_session(_("Edit of %{model} \"%{name}\" was cancelled by the user") % - {:model => ui_lookup(:model => model.to_s), :name => update_ems.name}) - url_args = { - :action => @lastaction == 'show_dashboard' ? 'show' : @lastaction, - :id => update_ems.id, - :display => session[:ems_display], - :record => update_ems - } - - begin - javascript_redirect(javascript_process_redirect_args(url_args)) - rescue ActionController::UrlGenerationError - # if the target URL does not exist, redirect to 'show' - url_args[:action] = 'show' - javascript_redirect(javascript_process_redirect_args(url_args)) - end - end - - def update_ems_button_save - update_ems = find_record_with_rbac(model, params[:id]) - set_ems_record_vars(update_ems) - if update_ems.save - update_ems.reload - add_flash( - _("%{model} \"%{name}\" was saved") % {:model => ui_lookup(:model => model.to_s), :name => update_ems.name} - ) - construct_edit_for_audit(update_ems) - AuditEvent.success(build_saved_audit(update_ems, @edit)) - update_ems.authentication_check_types_queue(update_ems.authentication_for_summary.pluck(:authtype), - :save => true) - flash_to_session - javascript_redirect(@lastaction == 'show_list' ? ems_path('show_list') : ems_path(update_ems)) - else - update_ems.errors.each do |field, msg| - add_flash("#{field.to_s.capitalize} #{msg}", :error) - end - drop_breadcrumb(:name => _("Edit %{table} '%{name}'") % - {:table => ui_lookup(:table => table_name), :name => update_ems.name}, - :url => "/#{table_name}/edit/#{update_ems.id}") - @in_a_form = true - render_flash - end - end - - def update_ems_button_validate - result, details = realtime_authentication_check - render_validation_result(result, details) - end - - def realtime_authentication_check(verify_ems = nil) - verify_ems ||= find_record_with_rbac(model, params[:id]) - set_ems_record_vars(verify_ems, :validate) - @in_a_form = true - verify_ems.authentication_check(params[:cred_type], :save => false, :database => params[:metrics_database_name]) - end - - def create_ems_button_validate - @in_a_form = true - ems_type = model.model_from_emstype(params[:emstype]) - result, details = if %w[ems_cloud ems_infra].include?(params[:controller]) - ems_type.validate_credentials_task(get_task_args(ems_type), session[:userid], params[:zone]) - else - realtime_authentication_check(ems_type.new) - end - render_validation_result(result, details) - end - - def render_validation_result(result, details) - if result - msg = if details.blank? - _("Credential validation was successful") - else - _("Credential validation was successful: %{details}") % {:details => strip_tags(details)} - end - else - msg = _("Credential validation was not successful: %{details}") % {:details => strip_tags(details)} - level = :error - end - - render_flash_json(msg, level, :long_alert => true) - end - - def create - assert_privileges("#{permission_prefix}_new") - - case params[:button] - when "add" then create_ems_button_add - when "validate" then create_ems_button_validate - when "cancel" then create_ems_button_cancel - end - end - - def get_task_args(ems) - user, password = params[:default_userid], ManageIQ::Password.encrypt(params[:default_password]) - case ems.to_s - when 'ManageIQ::Providers::Openstack::CloudManager', 'ManageIQ::Providers::Openstack::InfraManager' - case params[:cred_type] - when 'default' - [password, params.to_unsafe_h.slice(*OPENSTACK_PARAMS)] - when 'amqp' - [ManageIQ::Password.encrypt(params[:amqp_password]), params.to_unsafe_h.slice(*OPENSTACK_AMQP_PARAMS)] - end - when 'ManageIQ::Providers::Amazon::CloudManager' - uri = URI.parse(WEBrick::HTTPUtils.escape(params[:default_url])) - [ - user, - password, - :EC2, - params[:provider_region], - ems.http_proxy_uri, - true, - uri, - {:assume_role => params[:default_assume_role].presence}, - ] - when 'ManageIQ::Providers::Azure::CloudManager' - uri = URI.parse(WEBrick::HTTPUtils.escape(params[:default_url])) - [user, password, params[:azure_tenant_id], params[:subscription], ems.http_proxy_uri, params[:provider_region], uri] - when 'ManageIQ::Providers::AzureStack::CloudManager' - base_url = "#{params[:default_security_protocol] == 'non-ssl' ? 'http' : 'https'}://#{params[:default_hostname]}:#{params[:default_api_port]}" - [base_url, params[:azure_tenant_id], user, password, params[:subscription], :Resources, params[:api_version], { :validate => true }] - when 'ManageIQ::Providers::Vmware::CloudManager' - case params[:cred_type] - when 'amqp' - [params[:amqp_hostname], params[:amqp_api_port], params[:amqp_userid], ManageIQ::Password.encrypt(params[:amqp_password]), params[:api_version], true] - when 'default' - [params[:default_hostname], params[:default_api_port], user, password, params[:api_version], true] - end - when 'ManageIQ::Providers::Google::CloudManager' - [params[:project], ManageIQ::Password.encrypt(params[:service_account]), {:service => "compute"}, ems.http_proxy_uri, true] - when 'ManageIQ::Providers::Microsoft::InfraManager' - connect_opts = { - :hostname => params[:default_hostname], - :user => user, - :password => password, - :port => params[:default_api_port], - :realm => params[:realm], - :security_protocol => params[:default_security_protocol], - } - - [ems.build_connect_params(connect_opts), true] - when 'ManageIQ::Providers::Redhat::InfraManager' - metrics_user, metrics_password = params[:metrics_userid], ManageIQ::Password.encrypt(params[:metrics_password]) - [{ - :username => user, - :password => password, - :server => params[:default_hostname], - :port => params[:default_api_port], - :verify_ssl => params[:default_tls_verify] == 'on' ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE, - :ca_certs => params[:default_tls_ca_certs], - :metrics_username => metrics_user, - :metrics_password => metrics_password, - :metrics_server => params[:metrics_hostname], - :metrics_port => params[:metrics_api_port], - :metrics_database => params[:metrics_database_name], - }] - when 'ManageIQ::Providers::Kubevirt::InfraManager' - [{ - :password => params[:kubevirt_password], - :server => params[:kubevirt_hostname], - :port => params[:kubevirt_api_port], - :verify_ssl => params[:kubevirt_tls_verify] == 'on' ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE, - :ca_certs => params[:kubevirt_tls_ca_certs], - }] - when 'ManageIQ::Providers::Vmware::InfraManager' - case params[:cred_type] - when 'console' - [{:pass => ManageIQ::Password.encrypt(params[:console_password]), :user => params[:console_userid], :ip => params[:default_hostname], :use_broker => false}] - when 'default' - [{:pass => password, :user => user, :ip => params[:default_hostname], :use_broker => false}] - end - when 'ManageIQ::Providers::Nuage::NetworkManager' - endpoint_opts = {:protocol => params[:default_security_protocol], :hostname => params[:default_hostname], :api_port => params[:default_api_port], :api_version => params[:api_version]} - [user, params[:default_password], endpoint_opts] - when 'ManageIQ::Providers::Lenovo::PhysicalInfraManager' - [user, password, params[:default_hostname], params[:default_api_port], "token", false, true] - when 'ManageIQ::Providers::Redfish::PhysicalInfraManager' - [user, password, params[:default_hostname], params[:default_api_port], - params[:default_security_protocol]] - end - end - - def create_ems_button_add - ems = model.model_from_emstype(params[:emstype]).new - set_ems_record_vars(ems) unless @flash_array - if ems.valid? && ems.save - construct_edit_for_audit(ems) - AuditEvent.success(build_created_audit(ems, @edit)) - flash_to_session(_("%{model} \"%{name}\" was saved") % {:model => ui_lookup(:tables => table_name), :name => ems.name}) - javascript_redirect(:action => 'show_list') - else - @in_a_form = true - ems.errors.each do |field, msg| - add_flash("#{ems.class.human_attribute_name(field, :ui => true)} #{msg}", :error) - end - - drop_breadcrumb(:name => _("Add New %{tables}") % {:tables => ui_lookup(:tables => table_name)}, - :url => new_ems_path) - javascript_flash - end - end - - def create_ems_button_cancel - model_name = model.to_s - flash_to_session(_("Add of %{model} was cancelled by the user") % {:model => ui_lookup(:model => model_name)}) - javascript_redirect(:action => @lastaction, - :display => session[:ems_display]) - end - - def ems_form_fields - assert_privileges("#{permission_prefix}_edit") - @ems = params[:id] == 'new' ? model.new : find_record_with_rbac(model, params[:id]) - default_endpoint = @ems.default_endpoint - default_security_protocol = default_endpoint.security_protocol || security_protocol_default - default_tls_verify = default_endpoint.verify_ssl != 0 - default_tls_ca_certs = default_endpoint.certificate_authority || "" - - amqp_userid = "" - amqp_hostname = "" - amqp_port = "" - amqp_security_protocol = "" - console_userid = "" - smartstate_docker_userid = "" - ssh_keypair_userid = "" - metrics_userid = "" - metrics_hostname = "" - metrics_port = "" - metrics_database_name = "" - metrics_security_protocol = security_protocol_default - metrics_tls_ca_certs = "" - keystone_v3_domain_id = "" - prometheus_alerts_hostname = "" - prometheus_alerts_api_port = "" - prometheus_alerts_security_protocol = security_protocol_default - prometheus_alerts_tls_ca_certs = "" - kubevirt_hostname = "" - kubevirt_api_port = "" - kubevirt_security_protocol = default_security_protocol - kubevirt_tls_ca_certs = "" - kubevirt_password = "" - kubevirt_tls_verify = false - - provider_options = @ems.options || {} - - if @ems.connection_configurations.amqp.try(:endpoint) - amqp_hostname = @ems.connection_configurations.amqp.endpoint.hostname - amqp_port = @ems.connection_configurations.amqp.endpoint.port - amqp_security_protocol = @ems.connection_configurations.amqp.endpoint.security_protocol || 'ssl' - end - - if @ems.has_authentication_type?(:amqp) - amqp_userid = @ems.authentication_userid(:amqp).to_s - amqp_auth_status = @ems.authentication_status_ok?(:amqp) - end - - if @ems.has_authentication_type?(:console) - console_userid = @ems.authentication_userid(:console).to_s - console_auth_status = true - end - - if @ems.has_authentication_type?(:smartstate_docker) - smartstate_docker_userid = @ems.authentication_userid(:smartstate_docker).to_s - end - - if @ems.has_authentication_type?(:ssh_keypair) - ssh_keypair_userid = @ems.authentication_userid(:ssh_keypair).to_s - ssh_keypair_auth_status = @ems.authentication_status_ok?(:ssh_keypair) - end - - if @ems.connection_configurations.metrics.try(:endpoint) - metrics_hostname = @ems.connection_configurations.metrics.endpoint.hostname - metrics_port = @ems.connection_configurations.metrics.endpoint.port - metrics_database_name = @ems.connection_configurations.metrics.endpoint.path - end - - if @ems.has_authentication_type?(:metrics) - metrics_userid = @ems.authentication_userid(:metrics).to_s - metrics_auth_status = @ems.authentication_status_ok?(:metrics) - end - - if @ems.respond_to?(:keystone_v3_domain_id) - keystone_v3_domain_id = @ems.keystone_v3_domain_id - end - - if respond_to?(:retrieve_metrics_selection) - metrics_selection = retrieve_metrics_selection.to_sym - connection_configurations_metrics_endpoint = @ems.connection_configurations.try(metrics_selection).try(:endpoint) - else - connection_configurations_metrics_endpoint = nil - end - - if connection_configurations_metrics_endpoint - metrics_hostname = connection_configurations_metrics_endpoint.hostname - metrics_port = connection_configurations_metrics_endpoint.port - metrics_auth_status = @ems.authentication_status_ok?(metrics_selection) - metrics_security_protocol = connection_configurations_metrics_endpoint.security_protocol - metrics_security_protocol ||= security_protocol_default - metrics_tls_ca_certs = connection_configurations_metrics_endpoint.certificate_authority - end - - if @ems.connection_configurations.prometheus_alerts.try(:endpoint) - prometheus_alerts_hostname = @ems.connection_configurations.prometheus_alerts.endpoint.hostname - prometheus_alerts_api_port = @ems.connection_configurations.prometheus_alerts.endpoint.port - prometheus_alerts_auth_status = @ems.authentication_status_ok?(:alerts) - prometheus_alerts_security_protocol = @ems.connection_configurations.prometheus_alerts.endpoint.security_protocol - prometheus_alerts_security_protocol ||= security_protocol_default - prometheus_alerts_tls_ca_certs = @ems.connection_configurations.prometheus_alerts.endpoint.certificate_authority - end - - if @ems.connection_configurations.kubevirt.try(:endpoint) - kubevirt_hostname = @ems.connection_configurations.kubevirt.endpoint.hostname - kubevirt_api_port = @ems.connection_configurations.kubevirt.endpoint.port - kubevirt_auth_status = @ems.authentication_status_ok?(:kubevirt) - kubevirt_security_protocol = @ems.connection_configurations.kubevirt.endpoint.security_protocol - kubevirt_security_protocol ||= default_security_protocol - kubevirt_tls_ca_certs = @ems.connection_configurations.kubevirt.endpoint.certificate_authority - kubevirt_tls_verify = @ems.connection_configurations.kubevirt.endpoint.verify_ssl - end - - if @ems.connection_configurations.default.try(:endpoint) - default_hostname = @ems.connection_configurations.default.endpoint.hostname - default_api_port = @ems.connection_configurations.default.endpoint.port - else - default_hostname = @ems.hostname - default_api_port = @ems.port - end - - @ems_types = Array(model.supported_types_and_descriptions_hash.invert).sort_by(&:first) - - if @ems.kind_of?(ManageIQ::Providers::Vmware::InfraManager) - host_default_vnc_port_start = @ems.host_default_vnc_port_start.to_s - host_default_vnc_port_end = @ems.host_default_vnc_port_end.to_s - end - - if @ems.supports?(:assume_role) - assume_role = @ems.authentication_service_account - end - - if @ems.kind_of?(ManageIQ::Providers::Azure::CloudManager) - azure_tenant_id = @ems.azure_tenant_id - subscription = @ems.subscription - client_id = @ems.authentication_userid.to_s - client_key = @ems.authentication_password.to_s - end - - if @ems.kind_of?(ManageIQ::Providers::AzureStack::CloudManager) - azure_tenant_id = @ems.azure_tenant_id - subscription = @ems.subscription - end - - if @ems.kind_of?(ManageIQ::Providers::Google::CloudManager) - project = @ems.project - service_account = @ems.authentication_token - service_account_auth_status = @ems.authentication_status_ok? - end - - if @ems.kind_of?(ManageIQ::Providers::Nuage::NetworkManager) - amqp_fallback_hostname1 = @ems.connection_configurations.amqp_fallback1 ? @ems.connection_configurations.amqp_fallback1.endpoint.hostname : "" - amqp_fallback_hostname2 = @ems.connection_configurations.amqp_fallback2 ? @ems.connection_configurations.amqp_fallback2.endpoint.hostname : "" - end - - if %w[ems_cloud ems_network].include?(controller_name) - render :json => {:name => @ems.name, - :emstype => @ems.emstype, - :zone => zone, - :zone_hidden => zone == MiqRegion.my_region.maintenance_zone.name, - :tenant_mapping_enabled => @ems.tenant_mapping_enabled == true, - :provider_id => @ems.provider_id || "", - :hostname => @ems.hostname, - :default_hostname => default_hostname, - :amqp_hostname => amqp_hostname, - :default_api_port => default_api_port || "", - :amqp_api_port => amqp_port || "", - :api_version => @ems.api_version || "v2", - :default_security_protocol => default_security_protocol, - :amqp_security_protocol => amqp_security_protocol, - :provider_region => @ems.provider_region, - :openstack_infra_providers_exist => retrieve_openstack_infra_providers.length.positive?, - :default_userid => @ems.authentication_userid.to_s, - :amqp_userid => amqp_userid, - :ssh_keypair_userid => ssh_keypair_userid, - :smartstate_docker_userid => smartstate_docker_userid, - :service_account => service_account.to_s, - :azure_tenant_id => azure_tenant_id.to_s, - :keystone_v3_domain_id => keystone_v3_domain_id, - :subscription => subscription.to_s, - :client_id => client_id.to_s, - :client_key => client_key.to_s, - :project => project.to_s, - :emstype_vm => @ems.kind_of?(ManageIQ::Providers::Vmware::InfraManager), - :event_stream_selection => retrieve_event_stream_selection, - :ems_controller => controller_name, - :default_auth_status => default_auth_status, - :amqp_auth_status => amqp_auth_status, - :ssh_keypair_auth_status => ssh_keypair_auth_status.nil? ? true : ssh_keypair_auth_status, - :service_account_auth_status => service_account_auth_status, - :non_default_current_tab => @ems.emstype == "gce" ? "service_account" : nil, - :amqp_fallback_hostname1 => amqp_fallback_hostname1 || "", - :amqp_fallback_hostname2 => amqp_fallback_hostname2 || "", - :default_url => @ems.endpoints.first.url, - :assume_role => assume_role} - end - - if controller_name == "ems_infra" - render :json => { :name => @ems.name, - :emstype => @ems.emstype, - :zone => zone, - :zone_hidden => zone == MiqRegion.my_region.maintenance_zone.name, - :provider_id => @ems.provider_id || "", - :default_hostname => @ems.connection_configurations.default.endpoint.hostname, - :amqp_hostname => amqp_hostname, - :console_userid => console_userid, - :metrics_hostname => metrics_hostname, - :metrics_database_name => metrics_database_name, - :metrics_default_database_name => metrics_default_database_name, - :default_api_port => default_api_port || "", - :amqp_api_port => amqp_port || "", - :metrics_api_port => metrics_port || "", - :default_security_protocol => default_security_protocol, - :amqp_security_protocol => amqp_security_protocol, - :default_tls_verify => default_tls_verify, - :default_tls_ca_certs => default_tls_ca_certs, - :api_version => @ems.api_version || "v2", - :provider_region => @ems.provider_region, - :default_userid => @ems.authentication_userid.to_s, - :amqp_userid => amqp_userid, - :ssh_keypair_userid => ssh_keypair_userid, - :metrics_userid => metrics_userid, - :keystone_v3_domain_id => keystone_v3_domain_id, - :emstype_vm => @ems.kind_of?(ManageIQ::Providers::Vmware::InfraManager), - :host_default_vnc_port_start => host_default_vnc_port_start || "", - :host_default_vnc_port_end => host_default_vnc_port_end || "", - :event_stream_selection => retrieve_event_stream_selection, - :ems_controller => controller_name, - :default_auth_status => default_auth_status, - :console_auth_status => console_auth_status, - :metrics_auth_status => metrics_auth_status.nil? ? true : metrics_auth_status, - :ssh_keypair_auth_status => ssh_keypair_auth_status.nil? ? true : ssh_keypair_auth_status, - :non_default_current_tab => @ems.emstype == "kubevirt" ? "kubevirt" : nil, - :kubevirt_api_port => kubevirt_api_port, - :kubevirt_hostname => kubevirt_hostname, - :kubevirt_security_protocol => kubevirt_security_protocol, - :kubevirt_tls_verify => kubevirt_tls_verify, - :kubevirt_tls_ca_certs => kubevirt_tls_ca_certs, - :kubevirt_auth_status => kubevirt_auth_status, - :kubevirt_password => kubevirt_password, - :kubevirt_password_exists => !@ems.authentication_token(:kubevirt).nil?} - end - - if controller_name == "ems_container" - render :json => {:name => @ems.name, - :emstype => @ems.emstype, - :zone => zone, - :zone_hidden => zone == MiqRegion.my_region.maintenance_zone.name, - :hostname => @ems.hostname, - :default_hostname => @ems.connection_configurations.default.endpoint.hostname, - :default_api_port => @ems.connection_configurations.default.endpoint.port, - :metrics_selection => retrieve_metrics_selection, - :metrics_selection_default => @ems.emstype == 'kubernetes' ? 'disabled' : 'enabled', - :metrics_hostname => metrics_hostname, - :metrics_api_port => metrics_port, - :metrics_tls_ca_certs => metrics_tls_ca_certs, - :metrics_security_protocol => metrics_security_protocol, - :api_version => @ems.api_version || "v2", - :default_security_protocol => default_security_protocol, - :default_tls_ca_certs => default_tls_ca_certs, - :provider_region => @ems.provider_region, - :default_userid => @ems.authentication_userid.to_s, - :service_account => service_account.to_s, - :bearer_token_exists => !@ems.authentication_token(:bearer).nil?, - :ems_controller => controller_name, - :default_auth_status => default_auth_status, - :metrics_auth_status => metrics_auth_status.nil? ? false : metrics_auth_status, - :prometheus_alerts_api_port => prometheus_alerts_api_port, - :prometheus_alerts_hostname => prometheus_alerts_hostname, - :prometheus_alerts_security_protocol => prometheus_alerts_security_protocol, - :prometheus_alerts_tls_ca_certs => prometheus_alerts_tls_ca_certs, - :prometheus_alerts_auth_status => prometheus_alerts_auth_status, - :provider_options => provider_options, - :alerts_selection => retrieve_alerts_selection, - :kubevirt_api_port => kubevirt_api_port, - :kubevirt_hostname => kubevirt_hostname, - :kubevirt_security_protocol => kubevirt_security_protocol, - :kubevirt_tls_verify => kubevirt_tls_verify, - :kubevirt_tls_ca_certs => kubevirt_tls_ca_certs, - :kubevirt_auth_status => kubevirt_auth_status, - :kubevirt_password => kubevirt_password, - :kubevirt_password_exists => !@ems.authentication_token(:kubevirt).nil?, - :virtualization_selection => retrieve_virtualization_selection} - end - end - - private - - def metrics_default_database_name - if @ems.class.name == 'ManageIQ::Providers::Redhat::InfraManager' - ManageIQ::Providers::Redhat::InfraManager.default_history_database_name - end - end - - def security_protocol_default - case controller_name - when "ems_container" then "ssl-with-validation" - else "ssl" - end - end - - def table_name - self.class.table_name - end - - def set_ems_record_vars(ems, mode = nil) - ems.name = params[:name].strip if params[:name] - ems.provider_region = params[:provider_region] if params[:provider_region] - ems.api_version = params[:api_version].strip if params[:api_version] - ems.provider_id = params[:provider_id] - ems.zone = Zone.find_by(:name => params[:zone]) if params[:zone] - ems.tenant_mapping_enabled = params[:tenant_mapping_enabled] == "on" if ems.class.supports_cloud_tenant_mapping? - ems.security_protocol = params[:default_security_protocol].strip if params[:default_security_protocol] - - hostname = params[:default_hostname].strip if params[:default_hostname] - port = params[:default_api_port].strip if params[:default_api_port] - amqp_hostname = params[:amqp_hostname].strip if params[:amqp_hostname] - amqp_fallback_hostname1 = params[:amqp_fallback_hostname1].strip if params[:amqp_fallback_hostname1] - amqp_fallback_hostname2 = params[:amqp_fallback_hostname2].strip if params[:amqp_fallback_hostname2] - amqp_port = params[:amqp_api_port].strip if params[:amqp_api_port] - amqp_security_protocol = params[:amqp_security_protocol].strip if params[:amqp_security_protocol] - metrics_hostname = params[:metrics_hostname].strip if params[:metrics_hostname] - metrics_port = params[:metrics_api_port].strip if params[:metrics_api_port] - metrics_database_name = params[:metrics_database_name].strip if params[:metrics_database_name] - metrics_security_protocol = params[:metrics_security_protocol].strip if params[:metrics_security_protocol] - metrics_tls_ca_certs = params[:metrics_tls_ca_certs].strip if params[:metrics_tls_ca_certs] - default_tls_ca_certs = params[:default_tls_ca_certs].strip if params[:default_tls_ca_certs] - prometheus_alerts_tls_ca_certs = params[:prometheus_alerts_tls_ca_certs].strip if params[:prometheus_alerts_tls_ca_certs] - prometheus_alerts_hostname = params[:prometheus_alerts_hostname].strip if params[:prometheus_alerts_hostname] - prometheus_alerts_api_port = params[:prometheus_alerts_api_port].strip if params[:prometheus_alerts_api_port] - prometheus_alerts_security_protocol = params[:prometheus_alerts_security_protocol].strip if params[:prometheus_alerts_security_protocol] - kubevirt_tls_ca_certs = params[:kubevirt_tls_ca_certs].strip if params[:kubevirt_tls_ca_certs] - kubevirt_hostname = params[:kubevirt_hostname].strip if params[:kubevirt_hostname] - kubevirt_api_port = params[:kubevirt_api_port].strip if params[:kubevirt_api_port] - kubevirt_security_protocol = ems.security_protocol - default_endpoint = {} - amqp_endpoint = {} - amqp_fallback_endpoint1 = {} - amqp_fallback_endpoint2 = {} - ceilometer_endpoint = {} - ssh_keypair_endpoint = {} - metrics_endpoint = {} - hawkular_endpoint = {} - prometheus_endpoint = {} - prometheus_alerts_endpoint = {} - kubevirt_endpoint = {} - - if ems.kind_of?(ManageIQ::Providers::Openstack::CloudManager) || ems.kind_of?(ManageIQ::Providers::Openstack::InfraManager) - default_endpoint = {:role => :default, :hostname => hostname, :port => port, :security_protocol => ems.security_protocol} - ems.keystone_v3_domain_id = params[:keystone_v3_domain_id] - if params[:event_stream_selection] == "amqp" - amqp_endpoint = {:role => :amqp, :hostname => amqp_hostname, :port => amqp_port, :security_protocol => amqp_security_protocol} - else - ceilometer_endpoint = {:role => :ceilometer} - end - end - - if ems.kind_of?(ManageIQ::Providers::Openstack::CloudManager) || ems.kind_of?(ManageIQ::Providers::Openstack::InfraManager) || ems.kind_of?(ManageIQ::Providers::Redhat::InfraManager) - ssh_keypair_endpoint = {:role => :ssh_keypair} - end - - if ems.kind_of?(ManageIQ::Providers::Redhat::InfraManager) - default_endpoint = { - :role => :default, - :hostname => hostname, - :port => port, - :security_protocol => ems.security_protocol, - :verify_ssl => params[:default_tls_verify] == 'on' ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE, - :certificate_authority => params[:default_tls_ca_certs], - } - metrics_endpoint = { :role => :metrics, - :hostname => metrics_hostname, - :port => metrics_port, - :path => metrics_database_name } - end - - if ems.kind_of?(ManageIQ::Providers::Kubevirt::InfraManager) - kubevirt_endpoint = { - :role => :kubevirt, - :hostname => kubevirt_hostname, - :port => kubevirt_api_port, - } - - kubevirt_endpoint.merge!(endpoint_security_options(kubevirt_security_protocol, kubevirt_tls_ca_certs)) - end - - if ems.kind_of?(ManageIQ::Providers::Google::CloudManager) - ems.project = params[:project] - end - - if ems.kind_of?(ManageIQ::Providers::Microsoft::InfraManager) - default_endpoint = {:role => :default, :hostname => hostname, :security_protocol => ems.security_protocol} - ems.realm = params[:realm] - end - - if ems.kind_of?(ManageIQ::Providers::Vmware::InfraManager) - default_endpoint = {:role => :default, :hostname => hostname} - ems.host_default_vnc_port_start = params[:host_default_vnc_port_start].blank? ? nil : params[:host_default_vnc_port_start].to_i - ems.host_default_vnc_port_end = params[:host_default_vnc_port_end].blank? ? nil : params[:host_default_vnc_port_end].to_i - end - - if ems.kind_of?(ManageIQ::Providers::Vmware::CloudManager) - default_endpoint = {:role => :default, :hostname => hostname, :port => port} - if params[:event_stream_selection] == "amqp" - amqp_endpoint = {:role => :amqp, :hostname => amqp_hostname, :port => amqp_port, :security_protocol => amqp_security_protocol} - end - end - - if ems.kind_of?(ManageIQ::Providers::Azure::CloudManager) - ems.azure_tenant_id = params[:azure_tenant_id] - ems.subscription = params[:subscription] if params[:subscription].present? - uri = URI.parse(WEBrick::HTTPUtils.escape(params[:default_url])) - default_endpoint = {:role => :default, :hostname => uri.host, :port => uri.port, :path => uri.path, :url => params[:default_url]} - end - - if ems.kind_of?(ManageIQ::Providers::AzureStack::CloudManager) - ems.azure_tenant_id = params[:azure_tenant_id] - ems.subscription = params[:subscription] if params[:subscription].present? - default_endpoint = {:role => :default, :hostname => hostname, :port => port, :security_protocol => ems.security_protocol} - end - - if ems.kind_of?(ManageIQ::Providers::ContainerManager) - params[:cred_type] = ems.default_authentication_type if params[:cred_type] == "default" - default_endpoint = {:role => :default, :hostname => hostname, :port => port} - default_endpoint.merge!(endpoint_security_options(ems.security_protocol, default_tls_ca_certs)) - if params[:metrics_selection] == 'hawkular' - params[:cred_type] = "hawkular" if params[:cred_type] == "metrics" - hawkular_endpoint = {:role => :hawkular, :hostname => metrics_hostname, :port => metrics_port} - hawkular_endpoint.merge!(endpoint_security_options(metrics_security_protocol, metrics_tls_ca_certs)) - elsif params[:metrics_selection] == 'prometheus' - params[:cred_type] = "prometheus" if params[:cred_type] == "metrics" - prometheus_endpoint = {:role => :prometheus, :hostname => metrics_hostname, :port => metrics_port} - prometheus_endpoint.merge!(endpoint_security_options(metrics_security_protocol, metrics_tls_ca_certs)) - end - - if params[:alerts_selection] == 'prometheus' - prometheus_alerts_endpoint = {:role => :prometheus_alerts, :hostname => prometheus_alerts_hostname, :port => prometheus_alerts_api_port} - prometheus_alerts_endpoint.merge!(endpoint_security_options(prometheus_alerts_security_protocol, prometheus_alerts_tls_ca_certs)) - end - - if params[:virtualization_selection] == 'kubevirt' - kubevirt_endpoint = {:role => :kubevirt, :hostname => kubevirt_hostname, :port => kubevirt_api_port} - kubevirt_endpoint.merge!(endpoint_security_options(kubevirt_security_protocol, kubevirt_tls_ca_certs)) - end - end - - if ems.kind_of?(ManageIQ::Providers::Nuage::NetworkManager) - default_endpoint = {:role => :default, :hostname => hostname, :port => port, :security_protocol => ems.security_protocol} - amqp_endpoint = {:role => :amqp, :hostname => amqp_hostname, :port => amqp_port, :security_protocol => amqp_security_protocol} - amqp_fallback_endpoint1 = {:role => :amqp_fallback1, :hostname => amqp_fallback_hostname1, :port => amqp_port, :security_protocol => amqp_security_protocol} if amqp_fallback_hostname1.present? - amqp_fallback_endpoint2 = {:role => :amqp_fallback2, :hostname => amqp_fallback_hostname2, :port => amqp_port, :security_protocol => amqp_security_protocol} if amqp_fallback_hostname2.present? - end - - if ems.kind_of?(ManageIQ::Providers::Lenovo::PhysicalInfraManager) - default_endpoint = {:role => :default, :hostname => hostname, :port => port} - end - - if ems.kind_of?(ManageIQ::Providers::Amazon::CloudManager) - uri = URI.parse(WEBrick::HTTPUtils.escape(params[:default_url])) - default_endpoint = {:role => :default, :hostname => uri.host, :port => uri.port, :path => uri.path, :url => params[:default_url]} - end - - if ems.kind_of?(ManageIQ::Providers::Redfish::PhysicalInfraManager) - default_endpoint = { - :role => :default, - :hostname => hostname, - :port => port, - :security_protocol => ems.security_protocol - } - end - - new_options = {} - if ems.class.respond_to?(:advanced_settings) - ems.class.advanced_settings.each do |section_name, section| - section[:settings].each_key do |opt| - new_options[section_name.to_sym] ||= {} - value = params["provider_options_#{section_name}_#{opt}".to_sym] - new_options[section_name.to_sym][opt.to_sym] = value if value.present? - end - end - end - if ems.class.respond_to?(:proxy_settings) - new_options[:proxy_settings] = {} - ems.class.proxy_settings.each_key do |opt| - value = params["provider_options_proxy_settings_#{opt}".to_sym] - new_options[:proxy_settings][opt] = value if value.present? - end - end - ems.options = new_options - - endpoints = {:default => default_endpoint, - :ceilometer => ceilometer_endpoint, - :amqp => amqp_endpoint, - :console => default_endpoint, - :smartstate_docker => default_endpoint, - :amqp_fallback1 => amqp_fallback_endpoint1, - :amqp_fallback2 => amqp_fallback_endpoint2, - :ssh_keypair => ssh_keypair_endpoint, - :metrics => metrics_endpoint, - :hawkular => hawkular_endpoint, - :prometheus => prometheus_endpoint, - :prometheus_alerts => prometheus_alerts_endpoint, - :kubevirt => kubevirt_endpoint} - - build_connection(ems, endpoints, mode) - end - - def endpoint_security_options(security_protocol, certificate_authority) - { - :security_protocol => security_protocol, - :verify_ssl => %w[ssl-without-validation non-ssl].exclude?(security_protocol), - :certificate_authority => security_protocol == 'ssl-with-validation-custom-ca' ? certificate_authority : nil - } - end - - def build_connection(ems, endpoints, mode) - authentications = build_credentials(ems, mode) - configurations = [] - - %i[default ceilometer amqp amqp_fallback1 amqp_fallback2 console smartstate_docker ssh_keypair metrics hawkular prometheus prometheus_alerts kubevirt].each do |role| - configurations << build_configuration(ems, authentications, endpoints, role) - end - - ems.connection_configurations = configurations - end - - def build_configuration(ems, authentications, endpoints, role) - authtype = role == :default ? ems.default_authentication_type.to_sym : role - return {:endpoint => endpoints[role], :authentication => nil} unless authentications[authtype] - - authentication = authentications.delete(authtype) - authentication[:role] = authtype.to_s - authentication[:authtype] = authtype.to_s - {:endpoint => endpoints[role], :authentication => authentication} - end - - def build_credentials(ems, mode) - creds = {} - if params[:default_userid] - default_password = params[:default_password] || ems.authentication_password - creds[:default] = {:userid => params[:default_userid], :password => default_password, :save => (mode != :validate)} - end - if ems.supports_authentication?(:amqp) && params[:amqp_userid] - amqp_password = params[:amqp_password] || ems.authentication_password(:amqp) - creds[:amqp] = {:userid => params[:amqp_userid], :password => amqp_password, :save => (mode != :validate)} - end - if ems.kind_of?(ManageIQ::Providers::Vmware::InfraManager) && - ems.supports_authentication?(:console) && params[:console_userid] - console_password = params[:console_password] || ems.authentication_password(:console) - creds[:console] = {:userid => params[:console_userid], :password => console_password, :save => (mode != :validate)} # FIXME: skateman was here - end - if ems.kind_of?(ManageIQ::Providers::Amazon::CloudManager) && - ems.supports_authentication?(:smartstate_docker) && params[:smartstate_docker_userid] - smartstate_docker_password = params[:smartstate_docker_password] || ems.authentication_password(:smartstate_docker) - creds[:smartstate_docker] = {:userid => params[:smartstate_docker_userid], :password => smartstate_docker_password, :save => true} - end - if ems.supports?(:assume_role) - (creds[:default] ||= {})[:service_account] = params[:default_assume_role] - end - if (ems.kind_of?(ManageIQ::Providers::Openstack::InfraManager) || - ems.kind_of?(ManageIQ::Providers::Openstack::CloudManager) || - ems.kind_of?(ManageIQ::Providers::Redhat::InfraManager)) && - ems.supports_authentication?(:ssh_keypair) && params[:ssh_keypair_userid] - ssh_keypair_password = params[:ssh_keypair_password] ? params[:ssh_keypair_password].gsub(/\r\n/, "\n") : ems.authentication_key(:ssh_keypair) - creds[:ssh_keypair] = {:userid => params[:ssh_keypair_userid], :auth_key => ssh_keypair_password, :save => (mode != :validate)} - end - if ems.kind_of?(ManageIQ::Providers::Redhat::InfraManager) && - ems.supports_authentication?(:metrics) && params[:metrics_userid] - metrics_password = params[:metrics_password] || ems.authentication_password(:metrics) - creds[:metrics] = {:userid => params[:metrics_userid], :password => metrics_password, :save => (mode != :validate)} - end - if ems.kind_of?(ManageIQ::Providers::Kubevirt::InfraManager) - creds[:kubevirt] = { - :auth_key => params[:kubevirt_password] || ems.authentication_token(:kubevirt), - :save => mode != :validate, - } - end - if ems.supports_authentication?(:auth_key) && params[:service_account] - creds[:default] = {:auth_key => params[:service_account], :userid => "_", :save => (mode != :validate)} - end - if ems.supports_authentication?(:oauth) && session[:oauth_response].present? - auth = session[:oauth_response] - credentials = auth["credentials"] - creds[:oauth] = {:refresh_token => credentials["refresh_token"], - :access_token => credentials["access_token"], - :expires => credentials["expires"], - :userid => auth["info"]["name"], - :save => (mode != :validate)} - session[:oauth_response] = nil - end - if ems.kind_of?(ManageIQ::Providers::ContainerManager) - default_key = params[:default_password] || ems.authentication_key - if params[:metrics_selection] == "hawkular" - creds[:hawkular] = {:auth_key => default_key, :save => (mode != :validate)} - elsif params[:metrics_selection] == "prometheus" - creds[:prometheus] = {:auth_key => default_key, :save => (mode != :validate)} - end - if params[:alerts_selection] == 'prometheus' - creds[:prometheus_alerts] = {:auth_key => default_key, :save => (mode != :validate)} - end - if params[:virtualization_selection] == 'kubevirt' - kubevirt_key = params[:kubevirt_password] || ems.authentication_key(:kubevirt) - creds[:kubevirt] = { :auth_key => kubevirt_key, :save => (mode != :validate) } - end - creds[:bearer] = {:auth_key => default_key, :save => (mode != :validate)} - creds.delete(:default) - end - creds - end - - def retrieve_event_stream_selection - return 'amqp' if @ems.connection_configurations.amqp&.endpoint&.hostname&.present? - return 'ceilometer' if @ems.connection_configurations.ceilometer&.endpoint&.hostname&.present? - - @ems.kind_of?(ManageIQ::Providers::Openstack::CloudManager) || @ems.kind_of?(ManageIQ::Providers::Openstack::InfraManager) ? 'ceilometer' : 'none' - end - - def construct_edit_for_audit(ems) - @edit ||= {} - azure_tenant_id = ems.kind_of?(ManageIQ::Providers::Azure::CloudManager) ? ems.azure_tenant_id : nil - @edit[:current] = { - :name => ems.name, - :provider_region => ems.provider_region, - :hostname => ems.hostname, - :azure_tenant_id => azure_tenant_id, - :keystone_v3_domain_id => ems.respond_to?(:keystone_v3_domain_id) ? ems.keystone_v3_domain_id : nil, - :subscription => ems.subscription, - :port => ems.port, - :api_version => ems.api_version, - :security_protocol => ems.security_protocol, - :provider_id => ems.provider_id, - :zone => ems.zone - } - - @edit[:current][:tenant_mapping_enabled] = ems.tenant_mapping_enabled if ems.class.supports_cloud_tenant_mapping? - - @edit[:new] = {:name => params[:name], - :provider_region => params[:provider_region], - :hostname => params[:hostname], - :azure_tenant_id => params[:azure_tenant_id], - :keystone_v3_domain_id => params[:keystone_v3_domain_id], - :port => params[:port], - :api_version => params[:api_version], - :security_protocol => params[:default_security_protocol], - :provider_id => params[:provider_id], - :zone => params[:zone]} - - @edit[:new][:tenant_mapping_enabled] = params[:tenant_mapping_enabled] if ems.class.supports_cloud_tenant_mapping? - end - - def zone - if @ems.zone.nil? || @ems.my_zone == "" - "default" - else - @ems.my_zone - end - end - - def default_auth_status - @ems.authentication_status_ok? unless @ems.kind_of?(ManageIQ::Providers::Google::CloudManager) - end - end - end -end diff --git a/app/views/ems_block_storage/edit.html.haml b/app/views/ems_block_storage/edit.html.haml deleted file mode 100644 index 22a43006c03..00000000000 --- a/app/views/ems_block_storage/edit.html.haml +++ /dev/null @@ -1,19 +0,0 @@ -- url = url_for_only_path(:controller => 'ems_block_storage', :action => 'update', :id => (@ems.id || 'new')) -= form_for(@ems, - :url => url, - :method => :post, - :html => {"ng-controller" => "emsCommonFormController", - "name" => "angularForm", - "ng-show" => "afterGet", - "update-url" => url, - "form-fields-url" => "/#{controller_name}/ems_block_storage_form_fields/", - "novalidate" => true}) do |f| - %input{:type => 'hidden', :id => "form_id", :value => "##{f.options[:html][:id]}"} - %input{:type => 'hidden', :id => "button_name", :name => "button", :value => "save"} - %input{:type => 'hidden', :id => "cred_type", :name => "cred_type", :value => "default"} - = render :partial => "shared/views/ems_common/angular/form" - -:javascript - ManageIQ.angular.app.value('emsCommonFormId', '#{@ems.id || "new"}'); - miq_bootstrap($('#form_id').val()); - diff --git a/app/views/ems_block_storage/new.html.haml b/app/views/ems_block_storage/new.html.haml deleted file mode 100644 index 4e1d22e1d80..00000000000 --- a/app/views/ems_block_storage/new.html.haml +++ /dev/null @@ -1,20 +0,0 @@ -- url = url_for_only_path(:controller => 'ems_block_storage', :action => 'create', :id => (@ems.id || 'new')) -= form_for(@ems, - :url => url, - :method => :post, - :html => {"ng-controller" => "emsCommonFormController", - "name" => "angularForm", - "ng-show" => "afterGet", - "create-url" => url, - "form-fields-url" => "/#{controller_name}/ems_block_storage_form_fields/", - "novalidate" => true}) do |f| - %input{:type => 'hidden', :id => "form_id", :value => "##{f.options[:html][:id]}"} - %input{:type => 'hidden', :id => "button_name", :name => "button", :value => "add"} - %input{:type => 'hidden', :id => "cred_type", :name => "cred_type", :value => "default"} - - = render :partial => "shared/views/ems_common/angular/form" - -:javascript - ManageIQ.angular.app.value('emsCommonFormId', '#{@ems.id || "new"}'); - miq_bootstrap($('#form_id').val()); - diff --git a/app/views/shared/views/ems_common/angular/_form.html.haml b/app/views/shared/views/ems_common/angular/_form.html.haml deleted file mode 100644 index 120c34b1d04..00000000000 --- a/app/views/shared/views/ems_common/angular/_form.html.haml +++ /dev/null @@ -1,302 +0,0 @@ -- @angular_form = true - -.form-horizontal{'ng-cloak' => '', - 'ng-show' => 'afterGet'} - = render :partial => "layouts/flash_msg" - %div - .form-group{"ng-class" => "{'has-error': angularForm.name.$invalid}"} - %label.col-md-2.control-label{"for" => "ems_name"} - = _('Name') - .col-md-4 - %input.form-control{"type" => "text", - "id" => "ems_name", - "name" => "name", - "ng-model" => "emsCommonModel.name", - "maxlength" => "#{ViewHelper::MAX_NAME_LEN}", - "required" => "", - "checkchange" => "", - "auto-focus" => ""} - %span.help-block{"ng-show" => "angularForm.name.$error.required"} - = _("Required") - - .form-group{"ng-class" => "{'has-error': angularForm.emstype.$invalid}"} - %label.col-md-2.control-label{"for" => "ems_type"} - = _('Type') - .col-md-8 - = select_tag('emstype', - options_for_select([["<#{_('Choose')}>", nil]] + @ems_types, disabled: ["<#{_('Choose')}>", nil]), - "ng-if" => "newRecord", - "ng-model" => "emsCommonModel.emstype", - "ng-change" => "providerTypeChanged()", - "id" => "ems_type", - "required" => "", - "checkchange" => "", - "selectpicker-for-select-tag" => "") - %div{"ng-if" => "!newRecord"} - %label.form-control{"type" => "text", - "id" => "ems_type", - "name" => "emstype", - "ng-if" => "!newRecord", - "readonly" => true, - "style" => "color: black; font-weight: normal;"} - = @emstype_display - - - .form-group{"ng-class" => "{'has-error': angularForm.provider_region.$invalid}", "ng-if" => "#{@provider_regions.keys.to_json}.includes(emsCommonModel.emstype)", "ng-switch" => "", "on" => "emsCommonModel.emstype"} - %label.col-md-2.control-label{"for" => "ems_region"} - = _('Region') - .col-md-8 - - @provider_regions.each do |name, regions| - %div{"ng-switch-when" => name} - = select_tag('provider_region', - options_for_select([["<#{_('Choose')}>", nil]] + regions, disabled: ["<#{_('Choose')}>", nil]), - "ng-model" => "emsCommonModel.provider_region", - "required" => "", - "checkchange" => "", - "selectpicker-for-select-tag" => "", - "prefix" => "default", - "reset-validation-status" => "default_auth_status", - "ng-if" => "newRecord") - %label.form-control{"type" => "text", - "id" => "provider_region", - "name" => "provider_region", - "readonly" => true, - "style" => "color: black; font-weight: normal;", - "ng-if" => "!newRecord"} - = @ems_region_display - - .form-group{"ng-class" => "{'has-error': angularForm.project.$invalid}", "ng-if" => "emsCommonModel.emstype == 'gce'"} - %label.col-md-2.control-label{"for" => "ems_project"} - = _('Project ID') - .col-md-4 - %input.form-control{"type" => "text", - "id" => "ems_project", - "name" => "project", - "ng-model" => "emsCommonModel.project", - "maxlength" => "#{ViewHelper::MAX_NAME_LEN}", - "required" => "", - "checkchange" => ""} - %span.help-block{"ng-show" => "angularForm.project.$error.required"} - = _("Required") - - .form-group{"ng-class" => "{'has-error': angularForm.azure_tenant_id.$invalid}", "ng-if" => "emsCommonModel.emstype != '' && emsCommonModel.emstype == 'azure'"} - %label.col-md-2.control-label{"for" => "ems_tenant_id"} - = _('Tenant ID') - .col-md-4 - %input.form-control{"type" => "text", - "id" => "ems_tenant_id", - "name" => "azure_tenant_id", - "ng-model" => "emsCommonModel.azure_tenant_id", - "required" => "", - "checkchange" => "", - "is-uuid" => 4, - "prefix" => "default", - "reset-validation-status" => "default_auth_status"} - %span.help-block{"ng-show" => "angularForm.azure_tenant_id.$error.required"} - = _("Required") - %span.help-block{"ng-show" => "angularForm.azure_tenant_id.$error.isUuid"} - = _("Invalid input format, please enter a GUID") - - .form-group{"ng-class" => "{'has-error': angularForm.azure_tenant_id.$invalid}", "ng-if" => "emsCommonModel.emstype == 'azure_stack'"} - %label.col-md-2.control-label{"for" => "ems_tenant_id"} - = _('Tenant ID') - .col-md-4 - %input.form-control{"type" => "text", - "id" => "ems_tenant_id", - "name" => "azure_tenant_id", - "ng-model" => "emsCommonModel.azure_tenant_id", - "required" => "", - "checkchange" => "", - "prefix" => "default", - "reset-validation-status" => "default_auth_status"} - %span.help-block{"ng-show" => "angularForm.azure_tenant_id.$error.required"} - = _("Required") - - .form-group{"ng-class" => "{'has-error': angularForm.subscription.$invalid}", "ng-if" => "['azure', 'azure_stack'].includes(emsCommonModel.emstype)"} - %label.col-md-2.control-label{"for" => "ems_subscription"} - = _('Subscription ID') - .col-md-4 - %input.form-control{"type" => "text", - "id" => "ems_subscription", - "name" => "subscription", - "ng-model" => "emsCommonModel.subscription", - "checkchange" => "", - "required" => true, - "prefix" => "default", - "ng-readonly" => @ems.id ? true : false, - "is-uuid" => 4, - "reset-validation-status" => "default_auth_status"} - %span.help-block{"ng-show" => "angularForm.subscription.$error.isUuid"} - = _("Invalid input format, please enter a GUID") - %span.help-block{"ng-show" => "angularForm.subscription.$error.required"} - = _("Required") - - .form-group{"ng-class" => "{'has-error': angularForm.api_version.$invalid}", "ng-if" => "emsCommonModel.emstype == 'openstack' || emsCommonModel.emstype == 'openstack_infra'"} - %label.col-md-2.control-label{"for" => "ems_api_version"} - = _("API Version") - .col-md-8 - = select_tag('api_version', - options_for_select(@openstack_api_versions), - "ng-model" => "emsCommonModel.api_version", - "id" => "ems_api_version", - "checkchange" => "", - "selectpicker-for-select-tag" => "") - - .form-group{"ng-class" => "{'has-error': angularForm.vmware_cloud_api_version.$invalid}", "ng-if" => "emsCommonModel.emstype == 'vmware_cloud'"} - %label.col-md-2.control-label{"for" => "ems_api_version"} - = _("API Version") - .col-md-8 - = select_tag('api_version', - options_for_select(@vmware_cloud_api_versions), - "ng-model" => "emsCommonModel.vmware_cloud_api_version", - "id" => "ems_vmware_cloud_api_version", - "checkchange" => "", - "selectpicker-for-select-tag" => "") - - .form-group{"ng-class" => "{'has-error': angularForm.api_version.$invalid}", "ng-if" => "emsCommonModel.emstype == 'azure_stack'"} - %label.col-md-2.control-label{"for" => "ems_api_version"} - = _("API Version") - .col-md-8 - = select_tag('api_version', - options_for_select(@azure_stack_api_versions), - "ng-model" => "emsCommonModel.api_version", - "id" => "ems_azure_stack_api_version", - "required" => true, - "checkchange" => "", - "selectpicker-for-select-tag" => "") - %span.help-block{"ng-show" => "angularForm.api_version.$error.required"} - = _("Required") - - .form-group{"ng-class" => "{'has-error': angularForm.api_version.$invalid}", - "ng-if" => "emsCommonModel.emstype == 'openstack' || emsCommonModel.emstype == 'openstack_infra'"} - %label.col-md-2.control-label{"for" => "ems_region_input"} - = _('Region') - .col-md-4 - %input.form-control{"type" => "text", - "id" => "ems_region_input", - "name" => "provider_region", - "ng-model" => "emsCommonModel.provider_region", - "checkchange" => ""} - - .form-group{"ng-class" => "{'has-error': angularForm.keystone_v3_domain_id.$invalid}", "ng-if" => "emsCommonModel.api_version == 'v3' && (emsCommonModel.emstype == 'openstack' || emsCommonModel.emstype == 'openstack_infra')"} - %label.col-md-2.control-label{"for" => "ems_keystone_domain_id"} - = _('Keystone V3 Domain ID') - .col-md-4 - %input.form-control{"type" => "text", - "id" => "ems_keystone_domain_id", - "name" => "keystone_v3_domain_id", - "ng-model" => "emsCommonModel.keystone_v3_domain_id", - "required" => true, - "checkchange" => ""} - - .form-group{"ng-class" => "{'has-error': angularForm.api_version.$invalid}", "ng-if" => "emsCommonModel.emstype == 'nuage_network'"} - %label.col-md-2.control-label{"for" => "textInput-markup"} - = _("API Version") - .col-md-8 - = select_tag('api_version', - options_for_select(@nuage_api_versions), - "ng-model" => "emsCommonModel.api_version", - "checkchange" => "", - "selectpicker-for-select-tag" => "") - - .form-group{"ng-class" => "{'has-error': angularForm.provider_id.$invalid}", "ng-if" => "emsCommonModel.emstype == 'openstack' && emsCommonModel.openstack_infra_providers_exist"} - %label.col-md-2.control-label{"for" => "ems_infra_provider_id"} - = _("Openstack Infra Provider") - .col-md-8 - = select_tag('provider_id', - options_for_select([["<#{_('blank')}>", nil]] + @openstack_infra_providers.sort_by { |name, _name| name }), - "ng-model" => "emsCommonModel.provider_id", - "id" => "ems_infra_provider_id", - "checkchange" => "", - "selectpicker-for-select-tag" => "") - - .form-group{"ng-class" => "{'has-error': angularForm.zone.$invalid}", "ng-if" => "!emsCommonModel.zone_hidden"} - %label.col-md-2.control-label{"for" => "ems_zone"} - = _("Zone") - .col-md-4 - - if @server_zones.length <= 1 - %input.form-control{"type" => "text", - "id" => "ems_zone", - "name" => "zone", - "ng-model" => "emsCommonModel.zone", - "maxlength" => 15, - "required" => "", - "checkchange" => "", - "readonly" => true, - "style" => "color: black;"} - - else - = select_tag('zone', - options_for_select(@server_zones.sort_by { |name, _name| name }), - "ng-model" => "emsCommonModel.zone", - "id" => "ems_zone", - "checkchange" => "", - "required" => "", - "selectpicker-for-select-tag" => "") - .form-group{"ng-if" => "emsCommonModel.emstype == 'openstack'"} - %label.control-label.col-md-2{"for" => "ems_tenant_mapping_enabled"} - = _('Tenant Mapping Enabled') - .col-md-8 - %input{"bs-switch" => "", - :data => {:on_text => _('Yes'), :off_text => _('No'), :size => 'mini'}, - "type" => "checkbox", - "id" => "ems_tenant_mapping_enabled", - "name" => "tenant_mapping_enabled", - "checkchange" => "true", - "ng-model" => "emsCommonModel.tenant_mapping_enabled"} - - .form-group{"ng-class" => "{'has-error': angularForm.host_default_vnc_port_start.$invalid}", "ng-if" => "emsCommonModel.emstype_vm"} - %label.col-md-2.control-label{"for" => "ems_vnc_start_port"} - = _('Host Default VNC Start Port') - .col-md-8 - %input.form-control{"type" => "text", - "id" => "ems_vnc_start_port", - "name" => "host_default_vnc_port_start", - "ng-model" => "emsCommonModel.host_default_vnc_port_start", - "maxlength" => 6, - "checkchange" => ""} - %span.help-block{"ng-show" => "angularForm.name.$error.required"} - = _("Required") - - .form-group{"ng-class" => "{'has-error': angularForm.host_default_vnc_port_end.$invalid}", "ng-if" => "emsCommonModel.emstype_vm"} - %label.col-md-2.control-label{"for" => "ems_vnc_end_port"} - = _('Host Default VNC End Port') - .col-md-8 - %input.form-control{"type" => "text", - "id" => "ems_vnc_end_port", - "name" => "host_default_vnc_port_end", - "ng-model" => "emsCommonModel.host_default_vnc_port_end", - "maxlength" => 6, - "checkchange" => ""} - %span.help-block{"ng-show" => "angularForm.name.$error.required"} - = _("Required") - - %hr - - if controller_name == "ems_container" - = render :partial => "/layouts/container_auth", :locals => {:record => @ems} - - else - %div{"ng-if" => "emsCommonModel.emstype != '' && emsCommonModel.emstype == 'azure'"} - %h3 - = _("Credentials") - = render :partial => "layouts/angular-bootstrap/endpoints_for_url", - :locals => {:prefix => "default", :ng_model => "emsCommonModel"} - = render :partial => "/layouts/angular-bootstrap/auth_credentials_angular_bootstrap", - :locals => {:record => @ems, - :ng_model => "emsCommonModel", - :ng_reqd_userid => true, - :ng_reqd_password => true, - :prefix => "default", - :validate_url => @ems.id ? "update" : "create", - :id => @ems.id || "new", - :basic_info_needed => true, - :guid_regex => true, - :userid_label => _("Client ID"), - :password_label => _("Client Key"), - :verify_label => _("Confirm Client Key"), - :passwd_mismatch => _("Client Keys do not match"), - :change_stored_password => _("Change stored client key"), - :cancel_password_change => _("Cancel client key change"), - :verify_title_off => _("Tenant ID, Client ID and matching Client Key fields are needed to perform verification of credentials")} - %div{"ng-if" => "emsCommonModel.emstype != '' && emsCommonModel.emstype != 'azure'"} - = render :partial => "/layouts/angular/multi_auth_credentials", :locals => {:record => @ems, :ng_model => "emsCommonModel"} - - = render :partial => "layouts/angular/x_edit_buttons_angular", :locals => {:record => @ems, :restful => true} diff --git a/config/routes.rb b/config/routes.rb index 92009205cb9..7c6d44fef70 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1086,7 +1086,6 @@ discover download_data download_summary_pdf - ems_cloud_form_fields protect show show_list @@ -1097,7 +1096,6 @@ :post => %w( new button - create dynamic_checkbox_refresh dynamic_radio_button_refresh dynamic_text_box_refresh @@ -1110,7 +1108,6 @@ sync_users tagging_edit tl_chooser - update wait_for_task ) + adv_search_post + @@ -1172,7 +1169,6 @@ discover download_data download_summary_pdf - ems_infra_form_fields register_nodes protect scaledown @@ -1185,7 +1181,6 @@ :post => %w( new button - create register_nodes listnav_search_selected protect @@ -1196,7 +1191,6 @@ tagging_edit tl_chooser tree_autoload - update wait_for_task scaling scaledown @@ -1227,7 +1221,6 @@ discover download_data download_summary_pdf - ems_physical_infra_form_fields protect show show_list @@ -1237,7 +1230,6 @@ :post => %w( new button - create listnav_search_selected protect quick_search @@ -1246,7 +1238,6 @@ tagging_edit tl_chooser tree_autoload - update wait_for_task launch_console ) + @@ -1390,12 +1381,10 @@ show show_list tagging_edit - ems_container_form_fields ), :post => %w( new button - create dynamic_checkbox_refresh listnav_search_selected protect @@ -1404,7 +1393,6 @@ show show_list tl_chooser - update wait_for_task tagging_edit launch_external_logging @@ -1421,7 +1409,6 @@ dialog_load download_data download_summary_pdf - ems_network_form_fields index protect show_list @@ -1430,7 +1417,6 @@ :post => %w( new button - create dynamic_checkbox_refresh dynamic_radio_button_refresh dynamic_text_box_refresh @@ -1441,7 +1427,6 @@ show_list tagging_edit tl_chooser - update wait_for_task ) + adv_search_post + @@ -2216,7 +2201,6 @@ download_data download_summary_pdf edit - ems_storage_form_fields index new protect @@ -2226,7 +2210,6 @@ ), :post => %w( button - create dynamic_checkbox_refresh dynamic_radio_button_refresh dynamic_text_box_refresh @@ -2239,7 +2222,6 @@ quick_search tagging_edit tl_chooser - update wait_for_task ) + adv_search_post + @@ -2254,7 +2236,6 @@ download_data download_summary_pdf edit - ems_storage_form_fields index new protect @@ -2264,7 +2245,6 @@ ), :post => %w( button - create dynamic_checkbox_refresh dynamic_radio_button_refresh dynamic_text_box_refresh @@ -2276,7 +2256,6 @@ show_list tagging_edit tl_chooser - update wait_for_task ) + adv_search_post + @@ -2291,7 +2270,6 @@ download_data download_summary_pdf edit - ems_storage_form_fields index new protect @@ -2301,7 +2279,6 @@ ), :post => %w( button - create dynamic_checkbox_refresh dynamic_radio_button_refresh dynamic_text_box_refresh @@ -2313,7 +2290,6 @@ show_list tagging_edit tl_chooser - update wait_for_task ) + adv_search_post + @@ -3230,9 +3206,7 @@ # prevent No route matches [GET] "/favicon.ico" get '/favicon.ico' => 'static#favicon', :format => false - resources :ems_cloud, :as => :ems_clouds, :except => :destroy - resources :ems_infra, :as => :ems_infras, :except => :destroy - resources :ems_physical_infra, :as => :ems_physical_infras, :except => :destroy - resources :ems_container, :as => :ems_containers, :except => :destroy - resources :ems_network, :as => :ems_networks, :except => :destroy + %w[ems_cloud ems_infra ems_physical_infra ems_container ems_network].each do |resource| + resources(resource.to_sym, :as => resource.pluralize.to_sym, :except => %i[create update destroy]) + end end diff --git a/spec/controllers/ems_cloud_controller_spec.rb b/spec/controllers/ems_cloud_controller_spec.rb index 5609be3a1b9..647ecc1868d 100644 --- a/spec/controllers/ems_cloud_controller_spec.rb +++ b/spec/controllers/ems_cloud_controller_spec.rb @@ -2,231 +2,6 @@ let!(:server) { EvmSpecHelper.local_miq_server(:zone => zone) } let(:zone) { FactoryBot.build(:zone) } - describe "#create" do - before do - allow(controller).to receive(:check_privileges).and_return(true) - allow(controller).to receive(:assert_privileges).and_return(true) - login_as FactoryBot.create(:user, :features => "ems_cloud_new") - end - - it "adds a new provider" do - controller.instance_variable_set(:@breadcrumbs, []) - get :new - expect(response.status).to eq(200) - end - - render_views - - it 'shows the edit page' do - get :edit, :params => { :id => FactoryBot.create(:ems_amazon).id } - expect(response.status).to eq(200) - end - - it 'creates on post' do - expect do - post :create, :params => { - "button" => "add", - "name" => "foo", - "emstype" => "ec2", - "provider_region" => "ap-southeast-1", - "port" => "", - "zone" => zone.name, - "default_userid" => "foo", - "default_password" => "[FILTERED]", - "default_url" => "http://abc.test/path" - } - end.to change { ManageIQ::Providers::Amazon::CloudManager.count }.by(1) - end - - it 'creates and updates an authentication record on post' do - expect do - post :create, :params => { - "button" => "add", - "default_hostname" => "openstack.example.com", - "name" => "foo_openstack", - "emstype" => "openstack", - "provider_region" => "", - "default_port" => "5000", - "zone" => zone.name, - "default_userid" => "foo", - "default_password" => "[FILTERED]", - } - end.to change { Authentication.count }.by(1) - - expect(response.status).to eq(200) - openstack = ManageIQ::Providers::Openstack::CloudManager.where(:name => "foo_openstack").first - expect(openstack.authentications.size).to eq(1) - - expect do - post :update, :params => { - "id" => openstack.id, - "button" => "save", - "default_hostname" => "openstack.example.com", - "name" => "foo_openstack", - "emstype" => "openstack", - "provider_region" => "", - "default_port" => "5000", - "default_userid" => "bar", - "default_password" => "[FILTERED]", - } - end.not_to change { Authentication.count } - - expect(response.status).to eq(200) - expect(openstack.authentications.first).to have_attributes(:userid => "bar", :password => "[FILTERED]") - end - - it "validates credentials for a new record" do - expect(ManageIQ::Providers::Amazon::CloudManager).to receive(:validate_credentials_task).with( - match_array([ - 'foo', - 'v2:{SRpWIJC0Y1AOrUrKC0KDiw==}', - :EC2, - 'ap-southeast-1', - nil, - true, - instance_of(URI::Generic), - :assume_role => nil, - ]), - User.current_user.userid, - zone.name - ) - - post :create, :params => { - "button" => "validate", - "cred_type" => "default", - "name" => "foo_ec2", - "emstype" => "ec2", - "provider_region" => "ap-southeast-1", - "zone" => zone.name, - "default_userid" => "foo", - "default_password" => "[FILTERED]", - "default_url" => "" - } - - expect(response.status).to eq(200) - end - - it "cancels a new record" do - post :create, :params => { - "button" => "cancel", - "cred_type" => "default", - "name" => "foo_ec2", - "emstype" => "ec2", - "provider_region" => "ap-southeast-1", - "zone" => "default", - "default_userid" => "foo", - "default_password" => "[FILTERED]", - } - - expect(response.status).to eq(200) - end - - it "adds a record of type azure" do - post :create, :params => { - "button" => "add", - "azure_tenant_id" => "azure", - "name" => "foo_azure", - "emstype" => "azure", - "zone" => zone.name, - "default_userid" => "foo", - "default_password" => "[FILTERED]", - "default_url" => "http://abc.test/path" - } - - expect(response.status).to eq(200) - edit = controller.instance_variable_get(:@edit) - expect(edit[:new][:azure_tenant_id]).to eq("azure") - end - end - - describe "#ems_cloud_form_fields" do - before do - allow_any_instance_of(described_class).to receive(:set_user_time_zone) - allow(controller).to receive(:check_privileges).and_return(true) - allow(controller).to receive(:assert_privileges).and_return(true) - end - - it 'gets the ems cloud form fields on a get' do - Zone.seed - post :create, :params => { - "button" => "add", - "default_hostname" => "openstack.example.com", - "name" => "foo_openstack", - "emstype" => "openstack", - "provider_region" => "", - "default_port" => "5000", - "zone" => zone.name, - "default_userid" => "foo", - "default_password" => "[FILTERED]", - } - - expect(response.status).to eq(200) - openstack = ManageIQ::Providers::Openstack::CloudManager.where(:name => "foo_openstack").first - get :ems_cloud_form_fields, :params => { "id" => openstack.id } - expect(response.status).to eq(200) - expect(response.body).to include('"name":"foo_openstack"') - end - - let(:openstack_form_params) do - { - "button" => "add", - "default_hostname" => "openstack.example.com", - "name" => "foo_openstack", - "emstype" => "openstack", - "tenant_mapping_enabled" => "on", - "provider_region" => "", - "default_port" => "5000", - "zone" => zone.name, - "default_userid" => "foo", - "default_password" => "[FILTERED]", - } - end - - it "creates openstack cloud manager with attributes from form" do - post :create, :params => openstack_form_params - - openstack = ManageIQ::Providers::Openstack::CloudManager.where(:name => "foo_openstack").first - - expect(openstack.zone.name).to eq(zone.name) - expect(openstack.name).to eq("foo_openstack") - expect(openstack.emstype).to eq("openstack") - expect(openstack.tenant_mapping_enabled).to be_truthy - expect(openstack.provider_region).to eq("") - end - - it "updates openstack cloud manager's attribute tenant_mapping_enabled" do - post :create, :params => openstack_form_params - - openstack = ManageIQ::Providers::Openstack::CloudManager.where(:name => "foo_openstack").first - openstack_form_params[:id] = openstack.id - openstack_form_params[:button] = "save" - openstack_form_params[:tenant_mapping_enabled] = "off" - - post :update, :params => openstack_form_params - - expect(openstack.reload.tenant_mapping_enabled).to be_falsey - end - - it 'strips whitespace from name, hostname and api_port form fields on create' do - post :create, :params => { - "button" => "add", - "default_hostname" => "openstack.example.com", - "name" => " foo_openstack ", - "emstype" => "openstack", - "provider_region" => "", - "default_api_port" => " 5000 ", - "zone" => zone.name, - "default_userid" => "foo", - "default_password" => "[FILTERED]", - } - expect(response.status).to eq(200) - expect(ManageIQ::Providers::Openstack::CloudManager.with_hostname('openstack.example.com') - .with_port('5000') - .where(:name => 'foo_openstack') - .count).to eq(1) - end - end - describe "#show_link" do before do allow_any_instance_of(described_class).to receive(:set_user_time_zone) @@ -235,21 +10,7 @@ end it 'gets the restful show link and timeline link paths' do - session[:settings] = {:views => {:vm_summary_cool => ""}} - post :create, :params => { - "button" => "add", - "default_hostname" => "openstack.example.com", - "name" => "foo_openstack", - "emstype" => "openstack", - "provider_region" => "", - "default_port" => "5000", - "zone" => zone.name, - "default_userid" => "foo", - "default_password" => "[FILTERED]", - } - - expect(response.status).to eq(200) - openstack = ManageIQ::Providers::Openstack::CloudManager.where(:name => "foo_openstack").first + openstack = FactoryBot.create(:ems_openstack, :name => 'foo_openstack') show_link_actual_path = controller.send(:show_link, openstack) expect(show_link_actual_path).to eq("/ems_cloud/#{openstack.id}") @@ -265,130 +26,6 @@ end end - describe "#build_credentials only contains credentials that it supports and has a username for in params" do - let(:mocked_ems) { double(ManageIQ::Providers::Openstack::CloudManager) } - let(:default_creds) { {:userid => "default_userid", :password => "default_password"} } - let(:amqp_creds) { {:userid => "amqp_userid", :password => "amqp_password"} } - - it "uses the passwords from params for validation if they exist" do - controller.params = {:default_userid => default_creds[:userid], - :default_password => default_creds[:password], - :amqp_userid => amqp_creds[:userid], - :amqp_password => amqp_creds[:password]} - expect(mocked_ems).to receive(:supports_authentication?).with(:amqp).and_return(true) - expect(mocked_ems).to receive(:supports_authentication?).with(:oauth) - expect(mocked_ems).to receive(:supports_authentication?).with(:auth_key) - expect(mocked_ems).to receive(:supports?).with(:assume_role).and_return(false) - expect(controller.send(:build_credentials, mocked_ems, :validate)).to eq(:default => default_creds.merge!(:save => false), :amqp => amqp_creds.merge!(:save => false)) - end - - it "uses the stored passwords for validation if passwords dont exist in params" do - controller.params = {:default_userid => default_creds[:userid], - :amqp_userid => amqp_creds[:userid]} - expect(mocked_ems).to receive(:authentication_password).and_return(default_creds[:password]) - expect(mocked_ems).to receive(:authentication_password).with(:amqp).and_return(amqp_creds[:password]) - expect(mocked_ems).to receive(:supports_authentication?).with(:amqp).and_return(true) - expect(mocked_ems).to receive(:supports_authentication?).with(:oauth) - expect(mocked_ems).to receive(:supports_authentication?).with(:auth_key) - expect(mocked_ems).to receive(:supports?).with(:assume_role).and_return(false) - expect(controller.send(:build_credentials, mocked_ems, :validate)).to eq(:default => default_creds.merge!(:save => false), :amqp => amqp_creds.merge!(:save => false)) - end - end - - describe "#update_ems_button_validate" do - let(:mocked_ems) { FactoryBot.create(:ems_openstack) } - - it "calls authentication_check with save = false" do - allow(controller).to receive(:set_ems_record_vars) - allow(controller).to receive(:render) - allow(controller).to receive(:find_record_with_rbac).and_return(mocked_ems) - controller.params = {:button => "validate", :id => mocked_ems.id, :cred_type => "default"} - - expect(mocked_ems).to receive(:authentication_check).with("default", hash_including(:save => false)) - controller.send(:update_ems_button_validate) - end - end - - describe "#create_ems_button_validate" do - let(:mocked_params) { {:controller => mocked_class_controller, :cred_type => "default"} } - - before do - allow(controller).to receive(:render) - controller.params = mocked_params - allow(ExtManagementSystem).to receive(:model_from_emstype).and_return(mocked_class) - end - - context "with a cloud manager" do - let(:mocked_class) { ManageIQ::Providers::Amazon::CloudManager } - let(:mocked_class_controller) { "ems_cloud" } - let(:mocked_params) { {:controller => mocked_class_controller, :cred_type => "default", :default_url => ""} } - - it "queues the authentication type if it is a cloud provider" do - expect(mocked_class).to receive(:validate_credentials_task) - controller.send(:create_ems_button_validate) - end - - it "does queue the authentication check even if it is a cloud provider with a ui role" do - session[:selected_roles] = ['user_interface'] - - expect(mocked_class).not_to receive(:raw_connect) - expect(mocked_class).to receive(:validate_credentials_task) - controller.send(:create_ems_button_validate) - end - - context "google compute engine" do - let(:mocked_params) { {:controller => mocked_class_controller, :cred_type => "default", :project => project, :service_account => service_account} } - let(:mocked_class) { ManageIQ::Providers::Google::CloudManager } - let(:project) { "gce-project-1" } - let(:service_account) { "PRIVATE_KEY" } - let(:compute_service) { {:service => "compute"} } - - it "queues the correct number of arguments" do - expected_validate_args = [project, ManageIQ::Password.encrypt(service_account), compute_service, nil, true] - expect(mocked_class).to receive(:validate_credentials_task).with(expected_validate_args, nil, nil) - controller.send(:create_ems_button_validate) - end - end - end - - context "with an infrastructure manager" do - let(:mocked_class) { ManageIQ::Providers::Redhat::InfraManager } - let(:mocked_class_controller) { "ems_infra" } - - it "queues the authentication check" do - expect(mocked_class).to receive(:validate_credentials_task) - controller.send(:create_ems_button_validate) - end - - context "vmware infrastructure manager" do - let(:mocked_class) { ManageIQ::Providers::Vmware::InfraManager } - let(:mocked_class_controller) { "ems_infra" } - - it "disables the broker" do - expected_validate_args = [{:pass => nil, :user => nil, :ip => nil, :use_broker => false}] - expect(mocked_class).to receive(:validate_credentials_task).with(expected_validate_args, nil, nil) - controller.send(:create_ems_button_validate) - end - end - end - - context "with a container manager" do - let(:mocked_class) { ManageIQ::Providers::Openshift::ContainerManager } - let(:mocked_class_controller) { "ems_container" } - let(:mocked_container) { double(ManageIQ::Providers::Openshift::ContainerManager) } - - before do - allow(mocked_class).to receive(:new).and_return(mocked_container) - allow(controller).to receive(:set_ems_record_vars) - end - - it "does not queue the authentication check if it is a container provider" do - expect(mocked_container).to receive(:authentication_check).with("default", hash_including(:save => false)) - controller.send(:create_ems_button_validate) - end - end - end - describe "#test_toolbars" do before do allow(controller).to receive(:check_privileges).and_return(true) @@ -516,152 +153,6 @@ end end - describe "Ceilometer/AMQP Events" do - before do - allow(controller).to receive(:check_privileges).and_return(true) - allow(controller).to receive(:assert_privileges).and_return(true) - end - - it "creates ceilometer endpoint and on update to AMQP deletes ceilometer endpoint" do - post :create, :params => { - "button" => "add", - "default_hostname" => "openstack.default.example.com", - "default_userid" => "", - "default_password" => "", - "name" => "openstack_cloud", - "emstype" => "openstack", - "api_version" => "v2", - "provider_region" => "", - "zone" => zone.name, - "default_api_port" => "5000", - "default_security_protocol" => "ssl-with-validation", - "event_stream_selection" => "ceilometer" - } - ems_openstack = EmsCloud.where(:name => "openstack_cloud").first - amqp = Endpoint.where(:role => "amqp", :resource_id => ems_openstack.id).first - amqp_auth = Authentication.where(:authtype => "amqp", :resource_id => ems_openstack.id).first - ceilometer = Endpoint.where(:role => "ceilometer", :resource_id => ems_openstack.id).first - ceilometer_auth = Authentication.where(:authtype => "ceilometer", :resource_id => ems_openstack.id).first - expect(amqp).to be_nil - expect(amqp_auth).to be_nil - expect(ceilometer).not_to be_nil - expect(ceilometer_auth).to be_nil - - post :update, :params => { - "id" => ems_openstack.id, - "button" => "save", - "default_hostname" => "openstack.default.example.com", - "default_userid" => "", - "default_password" => "", - "name" => "openstack_cloud", - "emstype" => "openstack", - "provider_region" => "", - "zone" => zone.name, - "default_api_port" => "5000", - "default_security_protocol" => "ssl-with-validation", - "event_stream_selection" => "amqp", - "amqp_hostname" => "amqp.example.com", - "amqp_api_port" => "5672", - "amqp_security_protocol" => "ssl", - "amqp_userid" => "", - "amqp_password" => "" - } - amqp = Endpoint.where(:role => "amqp", :resource_id => ems_openstack.id).first - ceilometer = Endpoint.where(:role => "ceilometer", :resource_id => ems_openstack.id).first - expect(amqp).not_to be_nil - expect(ceilometer).to be_nil - end - - it "restarts event monitor worker on endpoints or credentials change" do - post :create, :params => { - "button" => "add", - "default_hostname" => "openstack.default.example.com", - "default_userid" => "", - "default_password" => "", - "name" => "openstack_cloud", - "emstype" => "openstack", - "api_version" => "v2", - "provider_region" => "", - "zone" => zone.name, - "default_api_port" => "5000", - "default_security_protocol" => "ssl-with-validation", - "event_stream_selection" => "ceilometer" - } - - # Change from ceilometer to amqp - ems_openstack = EmsCloud.where(:name => "openstack_cloud").first - allow(controller).to receive(:find_record_with_rbac).and_return(ems_openstack) - expect(ems_openstack).to receive(:stop_event_monitor_queue).once - - post :update, :params => { - "id" => ems_openstack.id, - "button" => "save", - "default_hostname" => "openstack.default.example.com", - "default_userid" => "", - "default_password" => "", - "name" => "openstack_cloud", - "emstype" => "openstack", - "provider_region" => "", - "zone" => zone.name, - "default_api_port" => "5000", - "default_security_protocol" => "ssl-with-validation", - "event_stream_selection" => "amqp", - "amqp_hostname" => "amqp.example.com", - "amqp_api_port" => "5672", - "amqp_security_protocol" => "ssl", - "amqp_userid" => "", - "amqp_password" => "" - } - - # Change of all endpoints and credentials - ems_openstack = EmsCloud.where(:name => "openstack_cloud").first - allow(controller).to receive(:find_record_with_rbac).and_return(ems_openstack) - # This is a bug in ems saving mechanism, there are 3 saves now, 2 for each auth and one for ems. We need to fix - # that, then stop_event_monitor_queue should be called once - expect(ems_openstack).to receive(:stop_event_monitor_queue).exactly(3).times - - post :update, :params => { - "id" => ems_openstack.id, - "button" => "save", - "default_hostname" => "openstack.default.changed.example.com", - "default_userid" => "changed", - "default_password" => "changed", - "name" => "openstack_cloud", - "emstype" => "openstack", - "provider_region" => "", - "zone" => zone.name, - "default_api_port" => "5000", - "default_security_protocol" => "ssl-with-validation", - "event_stream_selection" => "amqp", - "amqp_hostname" => "amqp.changed.example.com", - "amqp_api_port" => "5672", - "amqp_security_protocol" => "ssl", - "amqp_userid" => "changed", - "amqp_password" => "changed" - } - - # Change from amqp to ceilometer - ems_openstack = EmsCloud.where(:name => "openstack_cloud").first - allow(controller).to receive(:find_record_with_rbac).and_return(ems_openstack) - expect(ems_openstack).to receive(:stop_event_monitor_queue).once - - post :update, :params => { - "id" => ems_openstack.id, - "button" => "save", - "default_hostname" => "openstack.default.changed.example.com", - "default_userid" => "changed", - "default_password" => "changed", - "name" => "openstack_cloud", - "emstype" => "openstack", - "provider_region" => "", - "zone" => zone.name, - "default_api_port" => "5000", - "default_security_protocol" => "ssl-with-validation", - "event_stream_selection" => "ceilometer" - } - end - end - include_examples '#download_summary_pdf', :ems_amazon it_behaves_like "controller with custom buttons" diff --git a/spec/controllers/ems_container_controller_spec.rb b/spec/controllers/ems_container_controller_spec.rb index df35fc843eb..330ab15390f 100644 --- a/spec/controllers/ems_container_controller_spec.rb +++ b/spec/controllers/ems_container_controller_spec.rb @@ -60,316 +60,6 @@ end end - describe ".update_ems_button_detect" do - let(:kubernetes_manager) { FactoryBot.create(:ems_kubernetes) } - let(:openshift_manager) { FactoryBot.create(:ems_openshift) } - let(:hawkular_route) { RecursiveOpenStruct.new(:spec => {:host => "myhawkularroute.com"}) } - let(:mock_client) { double('kubeclient') } - - context "with route set" do - before do - EvmSpecHelper.create_guid_miq_server_zone - # set kubeclient to return a mock route. - allow(Kubeclient::Client).to receive(:new).and_return(mock_client) - allow(mock_client).to receive(:discover) - end - - it "detects openshift hawkular metric route" do - controller.params = {:id => openshift_manager.id, - :current_tab => "metrics", - :metrics_selection => 'hawkular'} - controller.instance_variable_set(:@_response, ActionDispatch::TestResponse.new) - - expect(mock_client).to receive(:get_route).with('hawkular-metrics', 'openshift-infra') - .and_return(hawkular_route) - - ret = JSON.parse(controller.send(:update_ems_button_detect)) - - expect(ret["hostname"]).to eq("myhawkularroute.com") - expect(controller.send(:flash_errors?)).to be_falsey - expect(assigns(:flash_array).first[:message]).to eq('Route Detection: success') - end - - it "detects openshift prometheus metric route" do - controller.params = {:id => openshift_manager.id, - :current_tab => "metrics", - :metrics_selection => 'prometheus'} - controller.instance_variable_set(:@_response, ActionDispatch::TestResponse.new) - - expect(mock_client).to receive(:get_route).with('prometheus', 'openshift-metrics') - .and_return(RecursiveOpenStruct.new(:spec => {:host => "prometheus-metrics.example.com"})) - - ret = JSON.parse(controller.send(:update_ems_button_detect)) - - expect(ret["hostname"]).to eq("prometheus-metrics.example.com") - expect(controller.send(:flash_errors?)).to be_falsey - expect(assigns(:flash_array).first[:message]).to eq('Route Detection: success') - end - - it "detects openshift prometheus alert route" do - require 'kubeclient' - controller.params = {:id => openshift_manager.id, - :current_tab => "alerts"} - controller.instance_variable_set(:@_response, ActionDispatch::TestResponse.new) - - expect(mock_client).to receive(:get_route).with('alerts', 'openshift-metrics') - .and_return(RecursiveOpenStruct.new(:spec => {:host => "prometheus-alerts.example.com"})) - - ret = JSON.parse(controller.send(:update_ems_button_detect)) - - expect(ret["hostname"]).to eq("prometheus-alerts.example.com") - expect(controller.send(:flash_errors?)).to be_falsey - expect(assigns(:flash_array).first[:message]).to eq('Route Detection: success') - end - - it "tolerates detection exceptions" do - controller.params = {:id => openshift_manager.id, - :current_tab => "metrics", - :metrics_selection => 'hawkular'} - controller.instance_variable_set(:@_response, ActionDispatch::TestResponse.new) - - expect(mock_client).to receive(:get_route).with('hawkular-metrics', 'openshift-infra') - .and_raise(StandardError, "message") - - controller.send(:update_ems_button_detect) - - expect(controller.send(:flash_errors?)).to be_truthy - expect(assigns(:flash_array).first[:message]).to include( - 'Route Detection: failure [message]' - ) - end - end - - it "errors on kubernetes detection" do - EvmSpecHelper.create_guid_miq_server_zone - controller.params = {:id => kubernetes_manager.id} - controller.instance_variable_set(:@_response, ActionDispatch::TestResponse.new) - - controller.send(:update_ems_button_detect) - - expect(controller.send(:flash_errors?)).to be_truthy - expect(assigns(:flash_array).first[:message]).to eq( - 'Route Detection: failure [Route detection not applicable for provider type]' - ) - end - end - - describe "create with provider options" do - let(:zone) { FactoryBot.build(:zone) } - let!(:server) { EvmSpecHelper.local_miq_server(:zone => zone) } - - before do - allow(controller).to receive(:check_privileges).and_return(true) - allow(controller).to receive(:assert_privileges).and_return(true) - end - - it "Creates a provider with provider options" do - params = { - "button" => "add", - "name" => "openshift_no_hawkular", - "emstype" => "openshift", - "zone" => zone.name, - "default_security_protocol" => "ssl-without-validation", - "default_hostname" => "openstack.default.example.com", - "default_api_port" => "5000", - "default_userid" => "", - "default_password" => "", - "provider_region" => "", - "metrics_selection" => "hawkular_disabled", - } - params["provider_options_image_inspector_options_http_proxy"] = "hello.com" - post :create, :params => params - expect(response.status).to eq(200) - ems_openshift = ManageIQ::Providers::ContainerManager.first - expect(ems_openshift.options[:image_inspector_options][:http_proxy]).to eq("hello.com") - end - end - - describe "Hawkular Disabled/Enabled" do - let(:zone) { FactoryBot.build(:zone) } - let!(:server) { EvmSpecHelper.local_miq_server(:zone => zone) } - - before do - allow(controller).to receive(:check_privileges).and_return(true) - allow(controller).to receive(:assert_privileges).and_return(true) - end - - it "Creates a provider with only one endpoint if hawkular is disabled" do - post :create, :params => { - "button" => "add", - "cred_type" => "hawkular", - "name" => "openshift_no_hawkular", - "emstype" => "openshift", - "zone" => zone.name, - "default_security_protocol" => "ssl-without-validation", - "default_hostname" => "openstack.default.example.com", - "default_api_port" => "5000", - "default_userid" => "", - "default_password" => "", - "provider_region" => "", - "metrics_selection" => "hawkular_disabled" - } - expect(response.status).to eq(200) - ems_openshift = ManageIQ::Providers::ContainerManager.first - expect(ems_openshift.endpoints.pluck(:role)).to contain_exactly('default') - end - - it "Creates a provider with two endpoints if hawkular is enabled" do - post :create, :params => { - "button" => "add", - "cred_type" => "hawkular", - "name" => "openshift_no_hawkular", - "emstype" => "openshift", - "zone" => zone.name, - "default_security_protocol" => "ssl-without-validation", - "default_hostname" => "hawkular.default.example.com", - "default_api_port" => "5000", - "default_userid" => "", - "default_password" => "", - "provider_region" => "", - "metrics_selection" => "hawkular", - "metrics_security_protocol" => "ssl-without-validation", - "metrics_hostname" => "hawkular_hostname", - "metrics_api_port" => "443", - } - expect(response.status).to eq(200) - ems_openshift = ManageIQ::Providers::ContainerManager.first - expect(ems_openshift.endpoints.count).to be(2) - expect(ems_openshift.endpoints.pluck(:role)).to contain_exactly('default', 'hawkular') - end - end - - describe "Kubevirt Disabled/Enabled" do - let(:zone) { FactoryBot.build(:zone) } - let!(:server) { EvmSpecHelper.local_miq_server(:zone => zone) } - - before do - allow(controller).to receive(:check_privileges).and_return(true) - allow(controller).to receive(:assert_privileges).and_return(true) - end - - context "Provider creation" do - it "Creates a provider with only one endpoint if kubevirt is disabled" do - post :create, :params => { - "button" => "add", - "cred_type" => "kubevirt", - "name" => "openshift_no_kubevirt", - "emstype" => "openshift", - "zone" => zone.name, - "default_security_protocol" => "ssl-without-validation", - "default_hostname" => "openstack.default.example.com", - "default_api_port" => "5000", - "default_userid" => "", - "default_password" => "", - "provider_region" => "", - "virtualization_selection" => "disabled" - } - expect(response.status).to eq(200) - ems_openshift = ManageIQ::Providers::ContainerManager.first - expect(ems_openshift.endpoints.pluck(:role)).to contain_exactly('default') - end - - it "Creates a provider with two endpoints if kubevirt is enabled" do - post :create, :params => { - "button" => "add", - "cred_type" => "kubevirt", - "name" => "openshift_with_kubevirt", - "emstype" => "openshift", - "zone" => zone.name, - "default_security_protocol" => "ssl-without-validation", - "default_hostname" => "server.example.com", - "default_api_port" => "5000", - "default_userid" => "", - "default_password" => "", - "provider_region" => "", - "virtualization_selection" => "kubevirt", - "kubevirt_security_protocol" => "ssl-without-validation", - "kubevirt_hostname" => "server.example.com", - "kubevirt_api_port" => "5000", - } - expect(response.status).to eq(200) - ems_openshift = ManageIQ::Providers::ContainerManager.first - expect(ems_openshift.endpoints.count).to be(2) - expect(ems_openshift.endpoints.pluck(:role)).to contain_exactly('default', 'kubevirt') - end - end - - context "Provider update with kubevirt provider" do - context "update when virtualization selection is enabled" do - before do - stub_user(:features => :all) - session[:edit] = assigns(:edit) - end - - def test_setting_many_fields - controller.params = {:name => 'EMS 2', - :default_userid => '_', - :default_hostname => '10.10.10.11', - :default_api_port => '5000', - :default_security_protocol => 'ssl-with-validation-custom-ca', - :default_tls_ca_certs => '-----BEGIN DUMMY...', - :default_password => 'valid-token', - :virtualization_selection => 'kubevirt', - :kubevirt_hostname => '10.10.10.11', - :kubevirt_api_port => '5000', - :kubevirt_security_protocol => 'ssl-with-validation-custom-ca', - :kubevirt_tls_ca_certs => '-----BEGIN DUMMY...', - :kubevirt_password => 'other-valid-token', - :emstype => @type} - controller.send(:set_ems_record_vars, @ems) - expect(@flash_array).to be_nil - cc = @ems.connection_configurations - - # verify default endpoint expectations - expect(cc.default.endpoint.hostname).to eq('10.10.10.11') - expect(cc.default.endpoint.port).to eq(5000) - expect(cc.default.endpoint.security_protocol).to eq('ssl-with-validation-custom-ca') - expect(cc.default.endpoint.verify_ssl?).to eq(true) - expect(cc.default.endpoint.certificate_authority).to eq('-----BEGIN DUMMY...') - - # verify kubevirt endpoint expectations - expect(cc.kubevirt.endpoint.hostname).to eq('10.10.10.11') - expect(cc.kubevirt.endpoint.port).to eq(5000) - expect(cc.kubevirt.endpoint.security_protocol).to eq('ssl-with-validation-custom-ca') - expect(cc.kubevirt.endpoint.verify_ssl?).to eq(true) - expect(cc.kubevirt.endpoint.certificate_authority).to eq('-----BEGIN DUMMY...') - - # verify authentications for default and kubevirt providers - expect(@ems.authentication_token("default")).to eq('valid-token') - expect(@ems.authentication_token("kubevirt")).to eq('other-valid-token') - expect(@ems.hostname).to eq('10.10.10.11') - end - - def test_setting_few_fields - controller.remove_instance_variable(:@_params) - controller.params = {:name => 'EMS 3', :default_userid => '_'} - controller.send(:set_ems_record_vars, @ems) - expect(@flash_array).to be_nil - expect(@ems.authentication_token("default")).to eq('valid-token') - expect(@ems.authentication_type("default")).to be_nil - end - - it "when editing kubernetes EMS" do - @type = 'kubernetes' - @ems = ManageIQ::Providers::Kubernetes::ContainerManager.new - test_setting_many_fields - - test_setting_few_fields - expect(@ems.connection_configurations.kubevirt.endpoint.hostname).to eq('10.10.10.11') - end - - it "when editing openshift EMS" do - @type = 'openshift' - @ems = ManageIQ::Providers::Openshift::ContainerManager.new - test_setting_many_fields - - test_setting_few_fields - expect(@ems.connection_configurations.kubevirt.endpoint.hostname).to eq('10.10.10.11') - end - end - end - end - include_examples '#download_summary_pdf', :ems_kubernetes %w(container_projects container_nodes container_images container_volumes container_templates).each do |custom_button_class| diff --git a/spec/controllers/ems_infra_controller_spec.rb b/spec/controllers/ems_infra_controller_spec.rb index 1be34781446..edc751b322a 100644 --- a/spec/controllers/ems_infra_controller_spec.rb +++ b/spec/controllers/ems_infra_controller_spec.rb @@ -485,449 +485,6 @@ end end - describe "#build_credentials" do - before { @ems = FactoryBot.create(:ems_openstack_infra) } - - context "#build_credentials only contains credentials that it supports and has a username for in params" do - let(:default_creds) { {:userid => "default_userid", :password => "default_password"} } - let(:amqp_creds) { {:userid => "amqp_userid", :password => "amqp_password"} } - let(:ssh_keypair_creds) { {:userid => "ssh_keypair_userid", :auth_key => "ssh_keypair_password"} } - - it "uses the passwords from params for validation if they exist" do - controller.params = {:default_userid => default_creds[:userid], - :default_password => default_creds[:password], - :amqp_userid => amqp_creds[:userid], - :amqp_password => amqp_creds[:password], - :ssh_keypair_userid => ssh_keypair_creds[:userid], - :ssh_keypair_password => ssh_keypair_creds[:auth_key]} - expect(@ems).to receive(:supports_authentication?).with(:amqp).and_return(true) - expect(@ems).to receive(:supports_authentication?).with(:ssh_keypair).and_return(true) - expect(@ems).to receive(:supports_authentication?).with(:oauth) - expect(@ems).to receive(:supports_authentication?).with(:auth_key) - expect(controller.send(:build_credentials, @ems, :validate)).to eq(:default => default_creds.merge!(:save => false), - :amqp => amqp_creds.merge!(:save => false), - :ssh_keypair => ssh_keypair_creds.merge!(:save => false)) - end - - it "uses the stored passwords for validation if passwords dont exist in params" do - controller.params = {:default_userid => default_creds[:userid], - :amqp_userid => amqp_creds[:userid], - :ssh_keypair_userid => ssh_keypair_creds[:userid]} - expect(@ems).to receive(:authentication_password).and_return(default_creds[:password]) - expect(@ems).to receive(:authentication_password).with(:amqp).and_return(amqp_creds[:password]) - expect(@ems).to receive(:supports_authentication?).with(:amqp).and_return(true) - expect(@ems).to receive(:authentication_key).with(:ssh_keypair).and_return(ssh_keypair_creds[:auth_key]) - expect(@ems).to receive(:supports_authentication?).with(:ssh_keypair).and_return(true) - expect(@ems).to receive(:supports_authentication?).with(:oauth) - expect(@ems).to receive(:supports_authentication?).with(:auth_key) - expect(controller.send(:build_credentials, @ems, :validate)).to eq(:default => default_creds.merge!(:save => false), - :amqp => amqp_creds.merge!(:save => false), - :ssh_keypair => ssh_keypair_creds.merge!(:save => false)) - end - end - end - - context "SCVMM - create, update, validate, cancel" do - before { login_as FactoryBot.create(:user, :features => %w[ems_infra_new ems_infra_edit]) } - - render_views - - it 'creates on post' do - expect do - post :create, :params => { - "button" => "add", - "name" => "foo", - "emstype" => "scvmm", - "zone" => zone.name, - "cred_type" => "default", - "default_hostname" => "foo.com", - "default_security_protocol" => "ssl", - "default_userid" => "foo", - "default_password" => "[FILTERED]", - } - end.to change { ManageIQ::Providers::Microsoft::InfraManager.count }.by(1) - end - - it 'creates and updates an authentication record on post' do - expect do - post :create, :params => { - "button" => "add", - "name" => "foo_scvmm", - "emstype" => "scvmm", - "zone" => zone.name, - "cred_type" => "default", - "default_hostname" => "foo.com", - "default_security_protocol" => "ssl", - "default_userid" => "foo", - "default_password" => "[FILTERED]", - } - end.to change { Authentication.count }.by(1) - - expect(response.status).to eq(200) - scvmm = ManageIQ::Providers::Microsoft::InfraManager.where(:name => "foo_scvmm").first - expect(scvmm.authentications.size).to eq(1) - - expect do - post :update, :params => { - "id" => scvmm.id, - "button" => "save", - "default_hostname" => "host_scvmm_updated", - "name" => "foo_scvmm", - "emstype" => "scvmm", - "default_userid" => "bar", - "default_password" => "[FILTERED]", - } - end.not_to change { Authentication.count } - - expect(response.status).to eq(200) - expect(scvmm.authentications.first).to have_attributes(:userid => "bar", :password => "[FILTERED]") - end - - it "validates credentials for a new record" do - expect(ManageIQ::Providers::Microsoft::InfraManager).to receive(:build_connect_params) - expect(ManageIQ::Providers::Microsoft::InfraManager).to receive(:validate_credentials_task) - - post :create, :params => { - "button" => "validate", - "cred_type" => "default", - "name" => "foo_scvmm", - "emstype" => "scvmm", - "zone" => zone.name, - "default_userid" => "foo", - "default_password" => "[FILTERED]", - } - - expect(response.status).to eq(200) - end - - it "cancels a new record" do - post :create, :params => { - "button" => "cancel", - "cred_type" => "default", - "name" => "foo_scvmm", - "emstype" => "scvmm", - "zone" => zone.name, - "default_userid" => "foo", - "default_password" => "[FILTERED]", - } - - expect(response.status).to eq(200) - end - end - - context "Openstack - create, update" do - before { login_as FactoryBot.create(:user, :features => %w[ems_infra_new ems_infra_edit]) } - - render_views - - it 'creates on post' do - expect do - post :create, :params => { - "button" => "add", - "name" => "foo", - "emstype" => "openstack_infra", - "zone" => zone.name, - "cred_type" => "default", - "default_hostname" => "foo.com", - "default_api_port" => "5000", - "default_security_protocol" => "ssl", - "default_userid" => "foo", - "default_password" => "[FILTERED]", - "amqp_hostname" => "foo_amqp.com", - "amqp_api_port" => "5672", - "amqp_security_protocol" => "ssl", - "amqp_userid" => "amqp_foo", - "amqp_password" => "[FILTERED]", - "ssh_keypair_hostname" => "foo_ssh.com", - "ssh_keypair_port" => "5372", - "ssh_keypair_security_protocol" => "ssl", - "ssh_keypair_userid" => "ssh_foo", - "ssh_keypair_password" => "[FILTERED]", - } - end.to change { ManageIQ::Providers::Openstack::InfraManager.count }.by(1) - end - - it 'creates and updates an authentication record on post' do - expect do - post :create, :params => { - "button" => "add", - "name" => "foo_openstack", - "emstype" => "openstack_infra", - "zone" => zone.name, - "cred_type" => "default", - "default_hostname" => "foo.com", - "default_api_port" => "5000", - "default_security_protocol" => "ssl", - "default_userid" => "foo", - "default_password" => "[FILTERED]", - "amqp_hostname" => "foo_amqp.com", - "amqp_api_port" => "5672", - "amqp_security_protocol" => "ssl", - "amqp_userid" => "amqp_foo", - "amqp_password" => "[FILTERED]", - "ssh_keypair_hostname" => "foo_ssh.com", - "ssh_keypair_port" => "5372", - "ssh_keypair_security_protocol" => "ssl", - "ssh_keypair_userid" => "ssh_foo", - "ssh_keypair_password" => "[FILTERED]", - } - end.to change { Authentication.count }.by(3) - - expect(response.status).to eq(200) - openstack = ManageIQ::Providers::Openstack::InfraManager.where(:name => "foo_openstack").first - expect(openstack.authentications.size).to eq(3) - - expect do - post :update, :params => { - "id" => openstack.id, - "button" => "save", - "default_hostname" => "host_openstack_updated", - "name" => "foo_openstack", - "emstype" => "openstack_infra", - "default_userid" => "bar", - "default_password" => "[FILTERED]", - } - end.not_to change { Authentication.count } - - expect(response.status).to eq(200) - expect(openstack.authentications.first).to have_attributes(:userid => "bar", :password => "[FILTERED]") - end - end - - context "Redhat - create, update" do - before do - login_as FactoryBot.create(:user, :features => %w(ems_infra_new ems_infra_edit)) - allow_any_instance_of(ManageIQ::Providers::Redhat::InfraManager) - .to receive(:supported_api_versions).and_return([3, 4]) - end - - render_views - - let(:creation_params) do - { - "button" => "add", - "name" => "foo_rhevm", - "emstype" => "rhevm", - "zone" => zone.name, - "cred_type" => "default", - "default_hostname" => "foo.com", - "default_api_port" => "5000", - "default_userid" => "foo", - "default_password" => "[FILTERED]", - "metrics_hostname" => "foo_metrics.com", - "metrics_api_port" => "5672", - "metrics_userid" => "metrics_foo", - "metrics_password" => "[FILTERED]", - "metrics_database_name" => "metrics_dwh" - } - end - - subject(:create) { post :create, :params => creation_params } - - it 'creates on post' do - expect do - create - end.to change { ManageIQ::Providers::Redhat::InfraManager.where("name" => creation_params["name"]).count }.by(1) - end - - it 'creates authentication records on post' do - expect do - create - end.to change { Authentication.count }.by(2) - - expect(response.status).to eq(200) - rhevm = ManageIQ::Providers::Redhat::InfraManager.where(:name => "foo_rhevm").first - expect(rhevm.authentications.size).to eq(2) - end - - it 'updates authentication records on post' do - create - rhevm = ManageIQ::Providers::Redhat::InfraManager.where(:name => "foo_rhevm").first - expect do - post :update, :params => { - "id" => rhevm.id, - "button" => "save", - "default_hostname" => "host_rhevm_updated", - "name" => "foo_rhevm", - "emstype" => "rhevm", - "default_userid" => "bar", - "default_password" => "[FILTERED]", - } - end.not_to change { Authentication.count } - - expect(response.status).to eq(200) - expect(rhevm.authentications.first).to have_attributes(:userid => "bar", :password => "[FILTERED]") - end - - context "Metrics endpoint" do - it 'creates endpoints records on post' do - create - expect(response.status).to eq(200) - rhevm = ManageIQ::Providers::Redhat::InfraManager.where(:name => "foo_rhevm").first - expect(rhevm.endpoints.size).to eq(3) - end - - it 'updates metrics endpoint records on post when button is "save"' do - create - rhevm = ManageIQ::Providers::Redhat::InfraManager.where(:name => "foo_rhevm").first - - updated_metrics_params = { "default_hostname" => "default.hostname.example.com", - "metrics_hostname" => "foo_metrics.com", - "metrics_api_port" => "5672", - "metrics_userid" => "metrics_foo", - "metrics_password" => "[FILTERED]", - "metrics_database_name" => "metrics_dwh_updated"} - - expect do - post :update, :params => { "id" => rhevm.id, :button => 'save' }.merge(updated_metrics_params) - end.not_to change { Endpoint.count } - - expect(Endpoint.where(:path => updated_metrics_params["metrics_database_name"]).count) - .to eq(1) - end - - it 'tries to varify with the right params on post when button is "validate"' do - create - rhevm = ManageIQ::Providers::Redhat::InfraManager.where(:name => "foo_rhevm").first - expect_any_instance_of(ManageIQ::Providers::Redhat::InfraManager).to receive(:authentication_check) - .with("metrics", - hash_including(:save => false, :database => creation_params["metrics_database_name"])) - post :update, :params => creation_params.merge(:button => "validate", :cred_type => "metrics", :id => rhevm.id) - end - end - end - - context "Kubevirt - update" do - before do - Zone.seed - login_as FactoryBot.create(:user, :features => %w[ems_infra_new ems_infra_edit]) - end - - render_views - - it 'creates ems container with virtualization endpoint on post' do - expect do - post :create, :params => { - "button" => "add", - "cred_type" => "kubevirt", - "name" => "openshift_with_kubevirt", - "emstype" => "openshift", - "zone" => 'default', - "default_security_protocol" => "ssl-without-validation", - "default_hostname" => "server.example.com", - "default_api_port" => "5000", - "default_userid" => "", - "default_password" => "", - "provider_region" => "", - "virtualization_selection" => "kubevirt", - "kubevirt_security_protocol" => "ssl-without-validation", - "kubevirt_hostname" => "server.example.com", - "kubevirt_api_port" => "5000", - } - end.to change { ManageIQ::Providers::Kubevirt::InfraManager.count }.by(1) - end - - it 'creates and updates an authentication record on post' do - expect do - post :create, :params => { - "button" => "add", - "cred_type" => "kubevirt", - "name" => "openshift_with_kubevirt", - "emstype" => "openshift", - "zone" => 'default', - "default_security_protocol" => "ssl-without-validation", - "default_hostname" => "server.example.com", - "default_api_port" => "5000", - "default_userid" => "", - "default_password" => "", - "provider_region" => "", - "virtualization_selection" => "kubevirt", - "kubevirt_security_protocol" => "ssl-without-validation", - "kubevirt_hostname" => "server.example.com", - "kubevirt_api_port" => "5000", - "kubevirt_password" => "[FILTERED]" - } - end.to change { ManageIQ::Providers::Kubevirt::InfraManager.count }.by(1) - - expect(response.status).to eq(200) - kubevirt = ManageIQ::Providers::Kubevirt::InfraManager.where(:name => "openshift_with_kubevirt Virtualization Manager").first - expect(kubevirt.authentications.size).to eq(2) - expect(kubevirt.authentication_token(:kubevirt)).to eq('[FILTERED]') - - expect do - post :update, :params => { - "id" => kubevirt.id, - "button" => "save", - "name" => "foo_kubevirt_name_changed", - "emstype" => "kubevirt", - "cred_type" => "kubevirt", - "kubevirt_password" => "XXXXXX", - } - end.not_to change { Authentication.count } - - expect(response.status).to eq(200) - - kubevirt.reload - expect(kubevirt.name).to eq('foo_kubevirt_name_changed') - expect(kubevirt.authentication_token(:kubevirt)).to eq('XXXXXX') - end - end - - context "VMWare - create, update" do - before { login_as FactoryBot.create(:user, :features => %w[ems_infra_new ems_infra_edit]) } - - render_views - - it 'creates on post' do - expect do - post :create, :params => { - "button" => "add", - "name" => "foo", - "emstype" => "vmwarews", - "zone" => zone.name, - "cred_type" => "default", - "default_hostname" => "foo.com", - "default_userid" => "foo", - "default_password" => "[FILTERED]", - } - end.to change { ManageIQ::Providers::Vmware::InfraManager.count }.by(1) - end - - it 'creates and updates an authentication record on post' do - expect do - post :create, :params => { - "button" => "add", - "name" => "foo_vmware", - "emstype" => "vmwarews", - "zone" => zone.name, - "cred_type" => "default", - "default_hostname" => "foo.com", - "default_userid" => "foo", - "default_password" => "[FILTERED]", - } - end.to change { Authentication.count }.by(1) - - expect(response.status).to eq(200) - vmware = ManageIQ::Providers::Vmware::InfraManager.where(:name => "foo_vmware").first - expect(vmware.authentications.size).to eq(1) - - expect do - post :update, :params => { - "id" => vmware.id, - "button" => "save", - "default_hostname" => "host_vmware_updated", - "name" => "foo_vmware", - "emstype" => "vmwarews", - "default_userid" => "bar", - "default_password" => "[FILTERED]", - } - end.not_to change { Authentication.count } - - expect(response.status).to eq(200) - expect(vmware.authentications.first).to have_attributes(:userid => "bar", :password => "[FILTERED]") - end - end - include_examples '#download_summary_pdf', :ems_vmware it_behaves_like "controller with custom buttons" diff --git a/spec/controllers/ems_physical_infra_controller_spec.rb b/spec/controllers/ems_physical_infra_controller_spec.rb index f764c9c15fa..da9771865a0 100644 --- a/spec/controllers/ems_physical_infra_controller_spec.rb +++ b/spec/controllers/ems_physical_infra_controller_spec.rb @@ -2,22 +2,6 @@ let!(:server) { EvmSpecHelper.local_miq_server(:zone => zone) } let(:zone) { FactoryBot.build(:zone) } - describe "#create" do - before do - user = FactoryBot.create(:user, :features => "ems_physical_infra_new") - - allow_any_instance_of(described_class).to receive(:set_user_time_zone) - allow(controller).to receive(:check_privileges).and_return(true) - login_as user - end - - it "adds a new provider" do - controller.instance_variable_set(:@breadcrumbs, []) - get :new - expect(response.status).to eq(200) - end - end - describe "#show" do render_views before do @@ -104,114 +88,6 @@ end end - describe "#build_credentials" do - before do - @ems = FactoryBot.create(:ems_physical_infra) - end - context "#build_credentials only contains credentials that it supports and has a username for in params" do - let(:default_creds) { {:userid => "default_userid", :password => "default_password"} } - - it "uses the passwords from params for validation if they exist" do - controller.params = {:default_userid => default_creds[:userid], - :default_password => default_creds[:password]} - expect(controller.send(:build_credentials, @ems, :validate)).to eq(:default => default_creds.merge!(:save => false)) - end - - it "uses the stored passwords for validation if passwords dont exist in params" do - controller.params = {:default_userid => default_creds[:userid]} - expect(@ems).to receive(:authentication_password).and_return(default_creds[:password]) - expect(controller.send(:build_credentials, @ems, :validate)).to eq(:default => default_creds.merge!(:save => false)) - end - end - end - - describe "Lenovo XClarity (lenovo_ph_infra) - create, update, validate, cancel" do - before do - allow(controller).to receive(:check_privileges).and_return(true) - allow(controller).to receive(:assert_privileges).and_return(true) - login_as FactoryBot.create(:user, :features => "ems_physical_infra_new") - end - - render_views - - it 'creates on post' do - expect do - post :create, :params => { - "button" => "add", - "name" => "foo", - "emstype" => "lenovo_ph_infra", - "zone" => zone.name, - "cred_type" => "default", - "default_hostname" => "foo.com", - "default_userid" => "foo", - "default_password" => "[FILTERED]", - } - end.to change { ManageIQ::Providers::PhysicalInfraManager.count }.by(1) - end - - it 'creates and updates an authentication record on post' do - expect do - post :create, :params => { - "button" => "add", - "name" => "foo_lenovo_ph_infra", - "emstype" => "lenovo_ph_infra", - "zone" => zone.name, - "cred_type" => "default", - "default_hostname" => "foo.com", - "default_userid" => "foo", - "default_password" => "[FILTERED]", - } - end.to change { Authentication.count }.by(1) - - expect(response.status).to eq(200) - lenovo_ph_infra = ManageIQ::Providers::PhysicalInfraManager.where(:name => "foo_lenovo_ph_infra").first - expect(lenovo_ph_infra.authentications.size).to eq(1) - - expect do - post :update, :params => { - "id" => lenovo_ph_infra.id, - "button" => "save", - "default_hostname" => "host_lenovo_ph_infra_updated", - "name" => "foo_lenovo_ph_infra", - "emstype" => "lenovo_ph_infra", - "default_userid" => "bar", - "default_password" => "[FILTERED]", - } - end.not_to change { Authentication.count } - - expect(response.status).to eq(200) - expect(lenovo_ph_infra.authentications.first).to have_attributes(:userid => "bar", :password => "[FILTERED]") - end - - it "validates credentials for a new record" do - post :create, :params => { - "button" => "validate", - "cred_type" => "default", - "name" => "foo_lenovo_ph_infra", - "emstype" => "lenovo_ph_infra", - "zone" => zone.name, - "default_userid" => "foo", - "default_password" => "[FILTERED]", - } - - expect(response.status).to eq(200) - end - - it "cancels a new record" do - post :create, :params => { - "button" => "cancel", - "cred_type" => "default", - "name" => "foo_lenovo_ph_infra", - "emstype" => "lenovo_ph_infra", - "zone" => zone.name, - "default_userid" => "foo", - "default_password" => "[FILTERED]", - } - - expect(response.status).to eq(200) - end - end - describe "When the console button is pressed" do before do allow(controller).to receive(:launch_console).and_return(true) diff --git a/spec/controllers/mixins/ems_common/angular_spec.rb b/spec/controllers/mixins/ems_common/angular_spec.rb deleted file mode 100644 index 248a84c54e7..00000000000 --- a/spec/controllers/mixins/ems_common/angular_spec.rb +++ /dev/null @@ -1,276 +0,0 @@ -describe Mixins::EmsCommon::Angular do - context '.retrieve_event_stream_selection' do - let(:network_controller) { EmsNetworkController.new } - let(:ems_nuage) { FactoryBot.create(:ems_nuage_network_with_authentication) } - let(:ems_openstack) { FactoryBot.create(:ems_openstack_with_authentication) } - - it 'when amqp' do - # remove default endpoints - ems_nuage.endpoints = [] - ems_nuage.endpoints << Endpoint.create(:role => 'amqp', :hostname => 'hostname') - network_controller.instance_variable_set(:@ems, ems_nuage) - - expect(network_controller.send(:retrieve_event_stream_selection)).to eq('amqp') - end - - it 'when ceilometer' do - ems_openstack.endpoints << Endpoint.create(:role => 'ceilometer', :hostname => 'hostname') - network_controller.instance_variable_set(:@ems, ems_openstack) - - expect(network_controller.send(:retrieve_event_stream_selection)).to eq('ceilometer') - end - - it 'when ceilometer and amqp has empty hostname' do - # remove default endpoints - ems_nuage.endpoints = [] - ems_nuage.endpoints << Endpoint.create(:role => 'ceilometer', :hostname => 'hostname') - ems_nuage.endpoints << Endpoint.create(:role => 'amqp') - network_controller.instance_variable_set(:@ems, ems_nuage) - - expect(network_controller.send(:retrieve_event_stream_selection)).to eq('ceilometer') - end - - it 'when amqp and ceilometer has empty hostname' do - # remove default endpoints - ems_nuage.endpoints = [] - ems_nuage.endpoints << Endpoint.create(:role => 'ceilometer') - ems_nuage.endpoints << Endpoint.create(:role => 'amqp', :hostname => 'hostname') - network_controller.instance_variable_set(:@ems, ems_nuage) - - expect(network_controller.send(:retrieve_event_stream_selection)).to eq('amqp') - end - - it 'none when amqp and ceilometer have empty hostnames' do - # remove default endpoints - ems_nuage.endpoints = [] - ems_nuage.endpoints << Endpoint.create(:role => 'ceilometer') - ems_nuage.endpoints << Endpoint.create(:role => 'amqp') - network_controller.instance_variable_set(:@ems, ems_nuage) - - expect(network_controller.send(:retrieve_event_stream_selection)).to eq('none') - end - - it 'ceilometer when openstack provider when amqp and ceilometer have nil endpoints' do - network_controller.instance_variable_set(:@ems, ems_openstack) - - expect(network_controller.send(:retrieve_event_stream_selection)).to eq('ceilometer') - end - - it 'when none' do - # remove default endpoints - ems_nuage.endpoints = [] - network_controller.instance_variable_set(:@ems, ems_nuage) - - expect(network_controller.send(:retrieve_event_stream_selection)).to eq('none') - end - end - - describe 'get_task_args' do - context 'openstack cloud' do - before do - @ems_cloud_controller = EmsCloudController.new - @params = { - :default_security_protocol => "ssl", - :default_hostname => "host_default", - :default_api_port => "13000", - :default_userid => "abc", - :default_password => "abc", - :amqp_security_protocol => "non_ssl", - :amqp_hostname => "host_amqp", - :amqp_api_port => "5462", - :amqp_userid => "xyz", - :amqp_password => "xyz" - } - end - - it "returns connect options for openstack cloud default tab" do - @params[:cred_type] = "default" - @ems_cloud_controller.params = @params - - expected_connect_options = ["v2:{XpADRTTI7f11hNT7AuDaKg==}", - {:default_security_protocol => "ssl", - :default_hostname => "host_default", - :default_api_port => "13000", - :default_userid => "abc"}.with_indifferent_access] - expect(@ems_cloud_controller.send(:get_task_args, 'ManageIQ::Providers::Openstack::CloudManager')).to eq(expected_connect_options) - end - - it "returns connect options for openstack cloud AMQP tab" do - @params[:cred_type] = "amqp" - @ems_cloud_controller.params = @params - - expected_connect_options = ["v2:{k8Sm5ygvDAvvY5zkvev1ag==}", - {:amqp_security_protocol => "non_ssl", - :amqp_hostname => "host_amqp", - :amqp_api_port => "5462", - :amqp_userid => "xyz"}.with_indifferent_access] - expect(@ems_cloud_controller.send(:get_task_args, 'ManageIQ::Providers::Openstack::CloudManager')).to eq(expected_connect_options) - end - end - - context 'vmware cloud' do - before do - @ems_cloud_controller = EmsCloudController.new - @params = { - :default_hostname => "host_default", - :default_api_port => "443", - :default_userid => "abc", - :default_password => "abc", - :amqp_security_protocol => "non_ssl", - :amqp_hostname => "host_amqp", - :amqp_api_port => "5472", - :amqp_userid => "xyz", - :amqp_password => "xyz" - } - end - - it "returns connect options for vmware cloud default tab" do - @params[:cred_type] = "default" - @ems_cloud_controller.params = @params - - expected_connect_options = ["host_default", "443", "abc", "v2:{XpADRTTI7f11hNT7AuDaKg==}", nil, true] - expect(@ems_cloud_controller.send(:get_task_args, 'ManageIQ::Providers::Vmware::CloudManager')).to eq(expected_connect_options) - end - - it "returns connect options for vmware cloud AMQP tab" do - @params[:cred_type] = "amqp" - @ems_cloud_controller.params = @params - - expected_connect_options = ["host_amqp", "5472", "xyz", "v2:{k8Sm5ygvDAvvY5zkvev1ag==}", nil, true] - expect(@ems_cloud_controller.send(:get_task_args, 'ManageIQ::Providers::Vmware::CloudManager')).to eq(expected_connect_options) - end - end - - context 'openstack infra' do - before do - @ems_infra_controller = EmsInfraController.new - @params = { - :default_security_protocol => "ssl", - :default_hostname => "host_default", - :default_api_port => "13000", - :default_userid => "abc", - :default_password => "abc", - :amqp_security_protocol => "non_ssl", - :amqp_hostname => "host_amqp", - :amqp_api_port => "5462", - :amqp_userid => "xyz", - :amqp_password => "xyz" - } - end - - it "returns connect options for openstack infra default tab" do - @params[:cred_type] = "default" - @ems_infra_controller.params = @params - - expected_connect_options = ["v2:{XpADRTTI7f11hNT7AuDaKg==}", - {:default_security_protocol => "ssl", - :default_hostname => "host_default", - :default_api_port => "13000", - :default_userid => "abc"}.with_indifferent_access] - expect(@ems_infra_controller.send(:get_task_args, 'ManageIQ::Providers::Openstack::InfraManager')).to eq(expected_connect_options) - end - - it "returns connect options for openstack infra AMQP tab" do - @params[:cred_type] = "amqp" - @ems_infra_controller.params = @params - - expected_connect_options = ["v2:{k8Sm5ygvDAvvY5zkvev1ag==}", - {:amqp_security_protocol => "non_ssl", - :amqp_hostname => "host_amqp", - :amqp_api_port => "5462", - :amqp_userid => "xyz"}.with_indifferent_access] - expect(@ems_infra_controller.send(:get_task_args, 'ManageIQ::Providers::Openstack::InfraManager')).to eq(expected_connect_options) - end - end - - context 'vmware infra' do - before do - @ems_infra_controller = EmsInfraController.new - @params = { - :default_hostname => "host_default", - :default_userid => "abc", - :default_password => "abc", - :console_userid => "xyz", - :console_password => "xyz" - } - end - - it "returns connect options for vmware infra default tab" do - @params[:cred_type] = "default" - @ems_infra_controller.params = @params - - expected_connect_options = [{:pass => "v2:{XpADRTTI7f11hNT7AuDaKg==}", - :user => "abc", - :ip => "host_default", - :use_broker => false}] - expect(@ems_infra_controller.send(:get_task_args, 'ManageIQ::Providers::Vmware::InfraManager')).to eq(expected_connect_options) - end - - it "returns connect options for vmware infra console tab" do - @params[:cred_type] = "console" - @ems_infra_controller.params = @params - - expected_connect_options = [{:pass => "v2:{k8Sm5ygvDAvvY5zkvev1ag==}", - :user => "xyz", - :ip => "host_default", - :use_broker => false}] - expect(@ems_infra_controller.send(:get_task_args, 'ManageIQ::Providers::Vmware::InfraManager')).to eq(expected_connect_options) - end - end - - context 'aws cloud' do - before do - @ems_cloud_controller = EmsCloudController.new - @params = { - :default_userid => "abc", - :default_password => "abc", - :default_url => "http://abc.test/mypath", - :default_assume_role => "test_arn", - } - @ems = FactoryBot.create(:ems_amazon) - allow(@ems).to receive(:to_s).and_return('ManageIQ::Providers::Amazon::CloudManager') - end - - it "returns connect options for aws cloud" do - @params[:cred_type] = "default" - @ems_cloud_controller.params = @params - - expected_connect_options = [ - "abc", - "v2:{XpADRTTI7f11hNT7AuDaKg==}", - :EC2, - nil, - nil, - true, - URI.parse("http://abc.test/mypath"), - {:assume_role => "test_arn"}, - ] - expect(@ems_cloud_controller.send(:get_task_args, @ems)).to eq(expected_connect_options) - end - end - - context 'azure cloud' do - before do - @ems_cloud_controller = EmsCloudController.new - @params = { - :default_userid => "abc", - :default_password => "abc", - :azure_tenant_id => "77ecefb6-cff0-4e8d-a446-757a69cb9444", - :subscription => "2586c64b-38b4-4527-a140-012d49dfc444", - :provider_region => "East US", - :default_url => "http://abc.test/mypath" - } - @ems = FactoryGirl.create(:ems_azure) - allow(@ems).to receive(:to_s).and_return('ManageIQ::Providers::Azure::CloudManager') - end - - it "returns connect options for azure cloud" do - @params[:cred_type] = "default" - @ems_cloud_controller.params = @params - - expected_connect_options = ["abc", "v2:{XpADRTTI7f11hNT7AuDaKg==}", "77ecefb6-cff0-4e8d-a446-757a69cb9444", "2586c64b-38b4-4527-a140-012d49dfc444", nil, "East US", URI.parse("http://abc.test/mypath")] - expect(@ems_cloud_controller.send(:get_task_args, @ems)).to eq(expected_connect_options) - end - end - end -end diff --git a/spec/controllers/mixins/ems_common_spec.rb b/spec/controllers/mixins/ems_common_spec.rb index 876ed591026..2d5403fac87 100644 --- a/spec/controllers/mixins/ems_common_spec.rb +++ b/spec/controllers/mixins/ems_common_spec.rb @@ -1,24 +1,5 @@ describe EmsCloudController do context "::EmsCommon" do - describe "#new" do - before do - stub_user(:features => :all) - allow(controller).to receive(:drop_breadcrumb) - end - - it "assigns provider_regions" do - controller.send(:new) - - regions = { - # FIXME: (durandom) add a mock provider in order to remove this dependency on an actual provider - 'azure' => ManageIQ::Providers::Azure::Regions.all.sort_by { |r| r[:description] }.map do |r| - [r[:description], r[:name]] - end - } - expect(assigns(:provider_regions)).to include(regions) - end - end - describe "#button" do before do stub_user(:features => :all) @@ -187,107 +168,6 @@ let(:myhawkularroute) { double(:spec => double(:host => "myhawkularroute.com")) } context "::EmsCommon" do - context "adding new provider without hawkular endpoint" do - def test_creating(emstype) - raise ArgumentError, "Unsupported type [#{emstype}]" unless %w[kubernetes openshift].include?(emstype) - - @ems = ExtManagementSystem.model_from_emstype(emstype).new - controller.params = {:name => 'NimiCule', - :default_userid => '_', - :default_hostname => 'mytest.com', - :default_api_port => '8443', - :default_password => 'valid-token', - :emstype => emstype} - controller.send(:set_ems_record_vars, @ems) - expect(@flash_array).to be_nil - end - - it "doesn't probe routes for kubernetes" do - test_creating('kubernetes') - expect(@ems.connection_configurations.hawkular).to eq(nil) - end - - it "doesn't probe openshift for kubernetes" do - test_creating('openshift') - expect(@ems.connection_configurations.hawkular).to eq(nil) - end - end - - describe "#update" do - context "updates provider with new token" do - before do - stub_user(:features => :all) - session[:edit] = assigns(:edit) - end - - def test_setting_many_fields - controller.params = {:name => 'EMS 2', - :default_userid => '_', - :default_hostname => '10.10.10.11', - :default_api_port => '5000', - :default_security_protocol => 'ssl-with-validation-custom-ca', - :default_tls_ca_certs => '-----BEGIN DUMMY...', - :default_password => 'valid-token', - :metrics_selection => 'hawkular', - :metrics_hostname => '10.10.10.10', - :metrics_api_port => '8443', - :metrics_security_protocol => 'ssl-with-validation', - :emstype => @type} - controller.send(:set_ems_record_vars, @ems) - expect(@flash_array).to be_nil - cc = @ems.connection_configurations - expect(cc.default.endpoint.hostname).to eq('10.10.10.11') - expect(cc.default.endpoint.port).to eq(5000) - expect(cc.default.endpoint.security_protocol).to eq('ssl-with-validation-custom-ca') - expect(cc.default.endpoint.verify_ssl?).to eq(true) - expect(cc.default.endpoint.certificate_authority).to eq('-----BEGIN DUMMY...') - expect(cc.hawkular.endpoint.hostname).to eq('10.10.10.10') - expect(cc.hawkular.endpoint.port).to eq(8443) - expect(cc.hawkular.endpoint.security_protocol).to eq('ssl-with-validation') - expect(cc.hawkular.endpoint.verify_ssl?).to eq(true) - expect(cc.hawkular.endpoint.certificate_authority).to eq(nil) - expect(@ems.authentication_token("bearer")).to eq('valid-token') - expect(@ems.authentication_type("default")).to be_nil - expect(@ems.hostname).to eq('10.10.10.11') - end - - def test_setting_few_fields - controller.remove_instance_variable(:@_params) - controller.params = {:name => 'EMS 3', :default_userid => '_'} - controller.send(:set_ems_record_vars, @ems) - expect(@flash_array).to be_nil - expect(@ems.authentication_token("bearer")).to eq('valid-token') - expect(@ems.authentication_type("default")).to be_nil - end - - it "when editing kubernetes EMS" do - @type = 'kubernetes' - @ems = ManageIQ::Providers::Kubernetes::ContainerManager.new - test_setting_many_fields - - test_setting_few_fields - expect(@ems.connection_configurations.hawkular.endpoint.hostname).to eq('10.10.10.10') - end - - it "when editing openshift EMS" do - @type = 'openshift' - @ems = ManageIQ::Providers::Openshift::ContainerManager.new - test_setting_many_fields - - test_setting_few_fields - expect(@ems.connection_configurations.hawkular.endpoint.hostname).to eq('10.10.10.10') - end - - it 'updates provider options' do - @type = 'openshift' - @ems = ManageIQ::Providers::Openshift::ContainerManager.new - controller.params = {:provider_options_image_inspector_options_http_proxy => "example.com"} - controller.send(:set_ems_record_vars, @ems) - expect(@ems.options[:image_inspector_options][:http_proxy]).to eq("example.com") - end - end - end - describe "#button" do before do stub_user(:features => :all) diff --git a/spec/javascripts/controllers/ems_common/ems_common_form_controller_spec.js b/spec/javascripts/controllers/ems_common/ems_common_form_controller_spec.js deleted file mode 100644 index b5a7054cf18..00000000000 --- a/spec/javascripts/controllers/ems_common/ems_common_form_controller_spec.js +++ /dev/null @@ -1,999 +0,0 @@ -describe('emsCommonFormController', function() { - var $scope, $controller, $httpBackend, miqService, compile, API; - - beforeEach(module('ManageIQ')); - - beforeEach(inject(function(_$httpBackend_, $rootScope, _$controller_, _miqService_, _$compile_, _API_) { - miqService = _miqService_; - compile = _$compile_; - API = _API_; - spyOn(miqService, 'miqAjaxButton'); - spyOn(miqService, 'restAjaxButton'); - spyOn(miqService, 'sparkleOn'); - spyOn(miqService, 'sparkleOff'); - spyOn(API, 'options').and.callFake(function(url){ return Promise.resolve({}); }); - spyOn(miqService, 'validateWithREST').and.callFake(function(url){ return Promise.resolve({}); }); - $scope = $rootScope.$new(); - - var emsCommonFormResponse = { - name: '', - emstype: '', - zone: 'default', - emstype_vm: false, - openstack_infra_providers_exist: false, - api_port: '', - api_version: 'v2' - }; - $httpBackend = _$httpBackend_; - $httpBackend.whenGET('/ems_cloud/ems_cloud_form_fields/new').respond(emsCommonFormResponse); - $controller = _$controller_('emsCommonFormController', - {$scope: $scope, - $attrs: {'formFieldsUrl': '/ems_cloud/ems_cloud_form_fields/', - 'createUrl': '/ems_cloud', - 'updateUrl': '/ems_cloud/12345'}, - emsCommonFormId: 'new', - miqService: miqService, - API: API - }); - })); - - afterEach(function() { - $httpBackend.verifyNoOutstandingExpectation(); - $httpBackend.verifyNoOutstandingRequest(); - }); - - describe('when the emsCommonFormId is new', function() { - beforeEach(inject(function() { - $httpBackend.flush(); - })); - - it('sets actionUrl to createUrl', function () { - expect($scope.actionUrl).toEqual($scope.createUrl); - }); - - it('sets the name to blank', function () { - expect($scope.emsCommonModel.name).toEqual(''); - }); - - it('sets the type to blank', function () { - expect($scope.emsCommonModel.emstype).toEqual(''); - }); - - it('sets the zone to default', function() { - expect($scope.emsCommonModel.zone).toEqual('default'); - }); - - it('sets the emstype_vm to false', function() { - expect($scope.emsCommonModel.emstype_vm).toEqual(false); - }); - - it('sets the openstack_infra_providers_exist to false', function() { - expect($scope.emsCommonModel.openstack_infra_providers_exist).toEqual(false); - }); - - it('sets the default_api_port to blank', function() { - expect($scope.emsCommonModel.default_api_port).toEqual(''); - }); - - it('sets the amqp_api_port to 5672', function() { - expect($scope.emsCommonModel.amqp_api_port).toEqual('5672'); - }); - - it('sets the api_version to blank', function() { - expect($scope.emsCommonModel.api_version).toEqual(''); - }); - - it('sets the current tab to default', function() { - expect($scope.currentTab).toEqual('default'); - }); - }); - - describe('when the emsCommonFormId is an Amazon Id', function() { - var emsCommonFormResponse = { - id: 12345, - name: 'amz', - emstype: 'ec2', - zone: 'default', - emstype_vm: false, - provider_id: 111, - openstack_infra_providers_exist: false, - provider_region: "ap-southeast-2", - default_userid: "default_user", - default_url: "http://host.test/abc", - assume_role: 'arn:123', - }; - - beforeEach(inject(function(_$controller_) { - $httpBackend.whenGET('/ems_cloud/ems_cloud_form_fields/12345').respond(emsCommonFormResponse); - - $controller = _$controller_('emsCommonFormController', - {$scope: $scope, - $attrs: {'formFieldsUrl': '/ems_cloud/ems_cloud_form_fields/', - 'createUrl': '/ems_cloud', - 'updateUrl': '/ems_cloud/12345'}, - emsCommonFormId: 12345, - miqService: miqService, - API: API - }); - $httpBackend.flush(); - })); - - it('sets actionUrl to updateUrl', function () { - expect($scope.actionUrl).toEqual($scope.updateUrl); - }); - - it('sets the name to the Amazon EC2 Cloud Provider', function () { - expect($scope.emsCommonModel.name).toEqual('amz'); - }); - - it('sets the type to ec2', function () { - expect($scope.emsCommonModel.emstype).toEqual('ec2'); - }); - - it('sets the zone to default', function() { - expect($scope.emsCommonModel.zone).toEqual('default'); - }); - - it('sets the emstype_vm to false', function() { - expect($scope.emsCommonModel.emstype_vm).toEqual(false); - }); - - it('sets the openstack_infra_providers_exist to false', function() { - expect($scope.emsCommonModel.openstack_infra_providers_exist).toEqual(false); - }); - - it('sets the provider_region', function() { - expect($scope.emsCommonModel.provider_region).toEqual("ap-southeast-2"); - }); - - it('sets the default_userid', function() { - expect($scope.emsCommonModel.default_userid).toEqual("default_user"); - }); - - it('sets the default_password', function() { - expect($scope.emsCommonModel.default_password).toEqual(miqService.storedPasswordPlaceholder); - }); - - it('sets the default_url', function() { - expect($scope.emsCommonModel.default_url).toEqual("http://host.test/abc"); - }); - - it('sets default_assume_role', function() { - expect($scope.emsCommonModel.default_assume_role).toEqual("arn:123"); - }); - - it('sets the current tab to default', function() { - expect($scope.currentTab).toEqual('default'); - }); - - it('initializes $scope.postValidationModel with credential objects for only those providers that support validation', function () { - $scope.postValidationModelRegistry('default'); - expect($scope.postValidationModel).toEqual(jasmine.objectContaining({ - default: jasmine.objectContaining({provider_region: 'ap-southeast-2', default_assume_role: 'arn:123'}), - console: jasmine.objectContaining({console_userid: undefined}), - amqp: {}, - metrics: {}, - ssh_keypair: {}, - prometheus_alerts: {}})); - }); - }); - - describe('when the emsCommonFormId is an Openstack Id', function() { - var emsCommonFormResponse = { - id: 12345, - name: 'myOpenstack', - default_hostname: '10.22.33.44', - amqp_hostname: '10.20.30.40', - emstype: 'openstack', - zone: 'default', - emstype_vm: false, - provider_id: 111, - openstack_infra_providers_exist: false, - default_userid: "default_user" - }; - - beforeEach(inject(function(_$controller_) { - $httpBackend.whenGET('/ems_cloud/ems_cloud_form_fields/12345').respond(emsCommonFormResponse); - - $controller = _$controller_('emsCommonFormController', - {$scope: $scope, - $attrs: {'formFieldsUrl': '/ems_cloud/ems_cloud_form_fields/', - 'createUrl': '/ems_cloud', - 'updateUrl': '/ems_cloud/update/'}, - emsCommonFormId: 12345, - miqService: miqService, - API: API - }); - $httpBackend.flush(); - })); - - it('sets the name to the Openstack Cloud Provider', function () { - expect($scope.emsCommonModel.name).toEqual('myOpenstack'); - }); - - it('sets the type to openstack', function () { - expect($scope.emsCommonModel.emstype).toEqual('openstack'); - }); - - it('sets the default hostname', function () { - expect($scope.emsCommonModel.default_hostname).toEqual('10.22.33.44'); - }); - - it('sets the amqp hostname', function () { - expect($scope.emsCommonModel.amqp_hostname).toEqual('10.20.30.40'); - }); - - it('sets the zone to default', function() { - expect($scope.emsCommonModel.zone).toEqual('default'); - }); - - it('sets the emstype_vm to false', function() { - expect($scope.emsCommonModel.emstype_vm).toEqual(false); - }); - - it('sets the openstack_infra_providers_exist to false', function() { - expect($scope.emsCommonModel.openstack_infra_providers_exist).toEqual(false); - }); - - it('sets the default_userid', function() { - expect($scope.emsCommonModel.default_userid).toEqual("default_user"); - }); - - it('sets the default_password', function() { - expect($scope.emsCommonModel.default_password).toEqual(miqService.storedPasswordPlaceholder); - }); - - it('sets the current tab to default', function() { - expect($scope.currentTab).toEqual('default'); - }); - }); - - describe('when the emsCommonFormId is an Azure Id', function() { - var emsCommonFormResponse = { - id: 12345, - name: 'Azure', - azure_tenant_id: '10.22.33.44', - subscription: '12345659-1234-41a4-a7ad-3ce6d1091234', - emstype: 'azure', - zone: 'default', - emstype_vm: false, - provider_id: 111, - openstack_infra_providers_exist: false, - default_userid: "default_user", - default_url: "http://host.test/abc" - }; - - beforeEach(inject(function(_$controller_) { - $httpBackend.whenGET('/ems_cloud/ems_cloud_form_fields/12345').respond(emsCommonFormResponse); - - $controller = _$controller_('emsCommonFormController', - {$scope: $scope, - $attrs: {'formFieldsUrl': '/ems_cloud/ems_cloud_form_fields/', - 'createUrl': '/ems_cloud', - 'updateUrl': '/ems_cloud/update/'}, - emsCommonFormId: 12345, - miqService: miqService, - API: API - }); - $httpBackend.flush(); - })); - - it('sets the name to the Azure Cloud Provider', function () { - expect($scope.emsCommonModel.name).toEqual('Azure'); - }); - - it('sets the type to azure', function () { - expect($scope.emsCommonModel.emstype).toEqual('azure'); - }); - - it('sets the azure_tenant_id', function () { - expect($scope.emsCommonModel.azure_tenant_id).toEqual('10.22.33.44'); - }) - - it('sets the subscription', function () { - expect($scope.emsCommonModel.subscription).toEqual('12345659-1234-41a4-a7ad-3ce6d1091234'); - }); - - it('sets the zone to default', function() { - expect($scope.emsCommonModel.zone).toEqual('default'); - }); - - it('sets the emstype_vm to false', function() { - expect($scope.emsCommonModel.emstype_vm).toEqual(false); - }); - - it('sets the openstack_infra_providers_exist to false', function() { - expect($scope.emsCommonModel.openstack_infra_providers_exist).toEqual(false); - }); - - it('sets the default_userid', function() { - expect($scope.emsCommonModel.default_userid).toEqual("default_user"); - }); - - it('sets the default_password', function() { - expect($scope.emsCommonModel.default_password).toEqual(miqService.storedPasswordPlaceholder); - }); - - it('sets the current tab to default', function() { - expect($scope.currentTab).toEqual('default'); - }); - - it('sets the default_url', function() { - expect($scope.emsCommonModel.default_url).toEqual("http://host.test/abc"); - }); - }); - - describe('#providerTypeChanged', function() { - beforeEach(function() { - $httpBackend.flush(); - $scope.emsCommonModel.emstype = 'gce'; - $scope.providerTypeChanged(); - }); - - it('sets currentTab to service_account', function() { - expect($scope.currentTab).toEqual('service_account'); - }); - }); - - describe('#resetClicked', function() { - beforeEach(function() { - $httpBackend.flush(); - $scope.angularForm = { - $setPristine: function (value){}, - $setUntouched: function (value){} - }; - $scope.resetClicked(); - }); - - it('sets total spinner count to be 1', function() { - expect(miqService.sparkleOn.calls.count()).toBe(1); - }); - }); - - describe('#saveClicked', function() { - beforeEach(function() { - $httpBackend.flush(); - $scope.angularForm = { - $setPristine: function (value){} - }; - $scope.saveClicked($.Event, true); - }); - - it('turns the spinner on via the miqService', function() { - expect(miqService.sparkleOn).toHaveBeenCalled(); - }); - - it('sets total spinner count to be 2', function() { - expect(miqService.sparkleOn.calls.count()).toBe(2); - }); - - it('delegates to miqService.restAjaxButton', function() { - expect(miqService.restAjaxButton).toHaveBeenCalledWith('/ems_cloud/12345?button=save', $.Event.target); - }); - }); - - describe('#addClicked', function() { - beforeEach(function() { - $httpBackend.flush(); - $scope.angularForm = { - $setPristine: function (value){} - }; - $scope.addClicked($.Event, true); - }); - - it('turns the spinner on via the miqService', function() { - expect(miqService.sparkleOn).toHaveBeenCalled(); - }); - - it('delegates to miqService.restAjaxButton', function() { - expect(miqService.restAjaxButton).toHaveBeenCalledWith('/ems_cloud?button=add', $.Event.target); - }); - }); - - describe('#cancelClicked', function() { - beforeEach(function() { - $httpBackend.flush(); - $scope.angularForm = { - $setPristine: function (value){} - }; - $scope.cancelClicked($.Event); - }); - - it('turns the spinner on via the miqService', function() { - expect(miqService.sparkleOn).toHaveBeenCalled(); - }); - - it('delegates to miqService.restAjaxButton', function() { - expect(miqService.restAjaxButton).toHaveBeenCalledWith('/ems_cloud?button=cancel', $.Event.target); - }); - }); - - describe('#validateClicked', function() { - beforeEach(function() { - $httpBackend.flush(); - $scope.currentTab = "console"; - $scope.actionUrl = "/xyz"; - $scope.validateClicked($.Event, "default", true); - }); - - it('turns the spinner on via the miqService', function() { - expect(miqService.sparkleOn).toHaveBeenCalled(); - }); - - it('delegates to miqService.validateClicked', function() { - expect(miqService.validateWithREST).toHaveBeenCalledWith($.Event, "console", "/xyz", true); - }); - }); - - describe('Validates credential fields', function() { - beforeEach(function() { - $httpBackend.flush(); - var angularForm; - var element = angular.element( - '
' + - '' + - '' + - '' + - '
' - ); - - compile(element)($scope); - $scope.$digest(); - angularForm = $scope.angularForm; - - $scope.angularForm.hostname.$setViewValue('abchost'); - $scope.angularForm.default_userid.$setViewValue('abcuser'); - $scope.angularForm.default_password.$setViewValue('abcpassword'); - $scope.currentTab = "default"; - $scope.emsCommonModel.emstype = "ec2"; - }); - - it('returns true if all the Validation fields are filled in', function() { - expect($scope.canValidateBasicInfo()).toBe(true); - }); - }); -}); - -describe('emsCommonFormController in the context of container provider', function() { - var $scope, $controller, $httpBackend, miqService, compile, API; - - beforeEach(module('ManageIQ')); - - beforeEach(inject(function (_$httpBackend_, $rootScope, _$controller_, _miqService_, _$compile_, _API_) { - miqService = _miqService_; - API = _API_; - compile = _$compile_; - spyOn(miqService, 'miqAjaxButton'); - spyOn(miqService, 'restAjaxButton'); - spyOn(miqService, 'sparkleOn'); - spyOn(miqService, 'sparkleOff'); - spyOn(API, 'options').and.callFake(function(url){ return Promise.resolve({});}); - $scope = $rootScope.$new(); - - var emsCommonFormResponse = { - name: '', - emstype: '', - zone: 'default', - emstype_vm: false, - default_api_port: '', - api_version: 'v2' - }; - $httpBackend = _$httpBackend_; - $httpBackend.whenGET('/ems_container/ems_container_form_fields/new').respond(emsCommonFormResponse); - $controller = _$controller_('emsCommonFormController', - { - $scope: $scope, - $attrs: { - 'formFieldsUrl': '/ems_container/ems_container_form_fields/', - 'createUrl': '/ems_container', - 'updateUrl': '/ems_container/12345' - }, - emsCommonFormId: 'new', - miqService: miqService, - API: API - }); - })); - - afterEach(function () { - $httpBackend.verifyNoOutstandingExpectation(); - $httpBackend.verifyNoOutstandingRequest(); - }); - - describe('when the emsCommonFormId is new', function () { - beforeEach(inject(function () { - $httpBackend.flush(); - })); - - it('sets the name to blank', function () { - expect($scope.emsCommonModel.name).toEqual(''); - }); - - it('sets the type to kubernetes', function () { - expect($scope.emsCommonModel.emstype).toEqual(''); - }); - - it('sets the zone to default', function () { - expect($scope.emsCommonModel.zone).toEqual('default'); - }); - - it('sets the api_port to blank', function () { - expect($scope.emsCommonModel.default_api_port).toEqual(''); - }); - - it('sets the api_version to blank', function () { - expect($scope.emsCommonModel.api_version).toEqual(''); - }); - - it('sets the current tab to default', function() { - expect($scope.currentTab).toEqual('default'); - }); - }); - - describe('when the emsCommonFormId of existing provider', function () { - var basic_options_example = { - image_inspector_options: { http_proxy: 'example.com'}, - proxy_settings: { http_proxy: 'example2.com' } - }; - - var emsCommonFormResponse = { - name: 'osp1', - emstype: 'kubernetes', - zone: 'default', - emstype_vm: false, - default_api_port: '', - provider_options: basic_options_example, - api_version: 'v2' - }; - - beforeEach(inject(function (_$controller_) { - $httpBackend.whenGET('/ems_container/ems_container_form_fields/12345').respond(emsCommonFormResponse); - - $controller = _$controller_('emsCommonFormController', - { - $scope: $scope, - $attrs: { - 'formFieldsUrl': '/ems_container/ems_container_form_fields/', - 'createUrl': '/ems_container', - 'updateUrl': '/ems_container/12345' - }, - emsCommonFormId: 12345, - miqService: miqService, - API: API - }); - $httpBackend.flush(); - })); - - it('sets the name to osp1', function () { - expect($scope.emsCommonModel.name).toEqual(emsCommonFormResponse.name); - }); - - it('sets the type to kubernetes', function () { - expect($scope.emsCommonModel.emstype).toEqual(emsCommonFormResponse.emstype); - }); - - it('sets the api_version to v2', function () { - expect($scope.emsCommonModel.api_version).toEqual('v2'); - }); - - it('sets the provider options to expected value', function () { - expect($scope.emsOptionsModel.provider_options_original_values).toEqual(basic_options_example); - }); - - it('sets the current tab to default', function() { - expect($scope.currentTab).toEqual('default'); - }); - }); - - describe('#updateProviderOptionsOldValues', function () { - it('sets sourceSection options in destSection', function () { - $httpBackend.flush(); - $scope.emsOptionsModel.provider_options_original_values = { - test_settings: { - hello: "world", - }, - }; - $scope.emsOptionsModel.provider_options = { - test_settings: - { label: "test_settings", settings: { hello: {}} } - }; - $scope.emsCommonModel.provider_options = {}; - $scope.emsCommonModel.provider_options.test_settings = {}; - $scope.updateProviderOptionsOldValues($scope.emsOptionsModel.provider_options.test_settings, - $scope.emsCommonModel.provider_options.test_settings); - expect($scope.emsCommonModel.provider_options.test_settings.hello.value).toEqual("world"); - }); - }); - - describe('#setProviderOptionsDescription', function () { - beforeEach(inject(function() { - $httpBackend.flush(); - $scope.emsCommonModel.emstype = 'kubernetes'; - $scope.emsOptionsModel = { - provider_options: {}, - provider_options_original_values: {}, - }; - })); - - it ('updates options descriptions', function () { - $scope.emsCommonModel.emstype = 'kubernetes'; - response = { - data: { - provider_settings: { - kubernetes: { - advanced_settings: { - settings: { - my_settings_section: { - label: "section_name_1", - settings: { - hello: { - label: 'hello', - help_text: 'help this text' - } - } - } - } - }, - proxy_settings: { - settings: { - hello: { - label: 'hello', - help_text: 'help this text' - } - } - } - } - } - } - }; - $scope.setProviderOptionsDescription(response.data); - expect($scope.emsOptionsModel - .provider_options - .advanced_settings - .settings - .my_settings_section - .settings.hello.label).toEqual('hello'); - }); - }); -}); - -describe('emsCommonFormController in the context of ems infra provider', function() { - var $scope, $controller, $httpBackend, miqService, compile, API; - - beforeEach(module('ManageIQ')); - - beforeEach(inject(function (_$httpBackend_, $rootScope, _$controller_, _miqService_, _$compile_, _API_) { - miqService = _miqService_; - API = _API_; - compile = _$compile_; - spyOn(miqService, 'miqAjaxButton'); - spyOn(miqService, 'restAjaxButton'); - spyOn(miqService, 'sparkleOn'); - spyOn(miqService, 'sparkleOff'); - spyOn(API, 'options').and.callFake(function(url){ return Promise.resolve({});}); - $scope = $rootScope.$new(); - - var emsCommonFormResponse = { - name: '', - emstype: '', - zone: 'default', - emstype_vm: false, - openstack_infra_providers_exist: false, - default_api_port: '', - api_version: 'v2' - }; - $httpBackend = _$httpBackend_; - $httpBackend.whenGET('/ems_infra/ems_infra_form_fields/new').respond(emsCommonFormResponse); - $controller = _$controller_('emsCommonFormController', - { - $scope: $scope, - $attrs: { - 'formFieldsUrl': '/ems_infra/ems_infra_form_fields/', - 'createUrl': '/ems_infra', - 'updateUrl': '/ems_infra/12345' - }, - emsCommonFormId: 'new', - miqService: miqService, - API: API - }); - })); - - afterEach(function () { - $httpBackend.verifyNoOutstandingExpectation(); - $httpBackend.verifyNoOutstandingRequest(); - }); - - describe('when the emsCommonFormId is new', function () { - beforeEach(inject(function () { - $httpBackend.flush(); - })); - - it('sets the name to blank', function () { - expect($scope.emsCommonModel.name).toEqual(''); - }); - - it('sets the type to blank', function () { - expect($scope.emsCommonModel.emstype).toEqual(''); - }); - - it('sets the zone to default', function () { - expect($scope.emsCommonModel.zone).toEqual('default'); - }); - - it('sets the api_port to blank', function () { - expect($scope.emsCommonModel.default_api_port).toEqual(''); - }); - - it('sets the api_version to blank', function () { - expect($scope.emsCommonModel.api_version).toEqual(''); - }); - - it('sets the current tab to default', function() { - expect($scope.currentTab).toEqual('default'); - }); - }); - - describe('when the emsCommonFormId is an SCVMM Id', function () { - var emsCommonFormResponse = { - id: 12345, - name: 'msft', - emstype: 'scvmm', - zone: 'default', - security_protocol: "ssl", - default_userid: "default_user" - }; - - beforeEach(inject(function (_$controller_) { - $httpBackend.whenGET('/ems_infra/ems_infra_form_fields/12345').respond(emsCommonFormResponse); - - $controller = _$controller_('emsCommonFormController', - { - $scope: $scope, - $attrs: { - 'formFieldsUrl': '/ems_infra/ems_infra_form_fields/', - 'createUrl': '/ems_infra', - 'updateUrl': '/ems_infra/12345' - }, - emsCommonFormId: 12345, - miqService: miqService, - API: API - }); - $httpBackend.flush(); - })); - - it('sets the name to the SCVMM Infra Provider', function () { - expect($scope.emsCommonModel.name).toEqual('msft'); - }); - - it('sets the type to scvmm', function () { - expect($scope.emsCommonModel.emstype).toEqual('scvmm'); - }); - - it('sets the zone to default', function () { - expect($scope.emsCommonModel.zone).toEqual('default'); - }); - - it('sets the security protocol to ssl', function () { - expect($scope.emsCommonModel.security_protocol).toEqual('ssl'); - }); - - it('sets the default_userid', function () { - expect($scope.emsCommonModel.default_userid).toEqual("default_user"); - }); - - it('sets the default_password', function () { - expect($scope.emsCommonModel.default_password).toEqual(miqService.storedPasswordPlaceholder); - }); - - it('sets the current tab to default', function() { - expect($scope.currentTab).toEqual('default'); - }); - }); - - describe('when the emsCommonFormId is an Openstack Id', function () { - var emsCommonFormResponse = { - id: 12345, - name: 'myOpenstack', - hostname: '10.22.33.44', - emstype: 'openstack_infra', - security_protocol: 'ssl', - zone: 'default', - api_port: '5000', - api_version: 'v2', - default_userid: "default_user", - amqp_userid: "amqp_user", - ssh_keypair_userid: "ssh_keypair_user" - }; - - beforeEach(inject(function (_$controller_) { - $httpBackend.whenGET('/ems_infra/ems_infra_form_fields/12345').respond(emsCommonFormResponse); - - $controller = _$controller_('emsCommonFormController', - { - $scope: $scope, - $attrs: { - 'formFieldsUrl': '/ems_infra/ems_infra_form_fields/', - 'createUrl': '/ems_infra', - 'updateUrl': '/ems_infra/update/' - }, - emsCommonFormId: 12345, - miqService: miqService, - API: API - }); - $httpBackend.flush(); - })); - - it('sets the name to the Openstack Infra Provider', function () { - expect($scope.emsCommonModel.name).toEqual('myOpenstack'); - }); - - it('sets the type to openstack', function () { - expect($scope.emsCommonModel.emstype).toEqual('openstack_infra'); - }); - - it('sets the hostname', function () { - expect($scope.emsCommonModel.hostname).toEqual('10.22.33.44'); - }); - - it('sets the zone to default', function () { - expect($scope.emsCommonModel.zone).toEqual('default'); - }); - - it('sets the default_userid', function () { - expect($scope.emsCommonModel.default_userid).toEqual("default_user"); - }); - - it('sets the default_password', function () { - expect($scope.emsCommonModel.default_password).toEqual(miqService.storedPasswordPlaceholder); - }); - - it('sets the amqp_userid', function () { - expect($scope.emsCommonModel.amqp_userid).toEqual("amqp_user"); - }); - - it('sets the amqp_password', function () { - expect($scope.emsCommonModel.amqp_password).toEqual(miqService.storedPasswordPlaceholder); - }); - - it('sets the ssh_keypair_userid', function () { - expect($scope.emsCommonModel.ssh_keypair_userid).toEqual("ssh_keypair_user"); - }); - - it('sets the ssh_keypair_password', function () { - expect($scope.emsCommonModel.ssh_keypair_password).toEqual(miqService.storedPasswordPlaceholder); - }); - - it('sets the current tab to default', function() { - expect($scope.currentTab).toEqual('default'); - }); - }); - - describe('when the emsCommonFormId is a RHEV Id', function () { - var emsCommonFormResponse = { - id: 12345, - name: 'myRhevm', - hostname: '10.22.33.44', - emstype: 'rhevm', - zone: 'default', - api_port: '', - default_userid: "default_user", - }; - - beforeEach(inject(function (_$controller_) { - $httpBackend.whenGET('/ems_infra/ems_infra_form_fields/12345').respond(emsCommonFormResponse); - - $controller = _$controller_('emsCommonFormController', - { - $scope: $scope, - $attrs: { - 'formFieldsUrl': '/ems_infra/ems_infra_form_fields/', - 'createUrl': '/ems_infra', - 'updateUrl': '/ems_infra/update/' - }, - emsCommonFormId: 12345, - miqService: miqService, - API: API - }); - $httpBackend.flush(); - })); - - it('sets the name to the RHEVM Provider', function () { - expect($scope.emsCommonModel.name).toEqual('myRhevm'); - }); - - it('sets the type to openstack', function () { - expect($scope.emsCommonModel.emstype).toEqual('rhevm'); - }); - - it('sets the hostname', function () { - expect($scope.emsCommonModel.hostname).toEqual('10.22.33.44'); - }); - - it('sets the zone to default', function () { - expect($scope.emsCommonModel.zone).toEqual('default'); - }); - - it('sets the default_userid', function () { - expect($scope.emsCommonModel.default_userid).toEqual("default_user"); - }); - - it('sets the default_password', function () { - expect($scope.emsCommonModel.default_password).toEqual(miqService.storedPasswordPlaceholder); - }); - - it('sets the default api port', function () { - expect($scope.emsCommonModel.default_api_port).toEqual(''); - }); - - it('sets the current tab to default', function() { - expect($scope.currentTab).toEqual('default'); - }); - }); - - describe('when the emsCommonFormId is a Kubevirt Id', function () { - var emsCommonFormResponse = { - id: 12345, - name: 'myKubevirt', - kubevirt_hostname: '10.22.33.44', - emstype: 'kubevirt', - zone: 'default', - non_default_current_tab: 'kubevirt', - kubevirt_api_port: '8443', - kubevirt_password_exists: true, - kubevirt_security_protocol: 'ssl-with-validation-custom-ca', - kubevirt_tls_ca_certs: '-----BEGIN DUMMY...', - }; - - beforeEach(inject(function (_$controller_) { - $httpBackend.whenGET('/ems_infra/ems_infra_form_fields/12345').respond(emsCommonFormResponse); - - $controller = _$controller_('emsCommonFormController', - { - $scope: $scope, - $attrs: { - 'formFieldsUrl': '/ems_infra/ems_infra_form_fields/', - 'updateUrl': '/ems_infra/update/' - }, - emsCommonFormId: 12345, - miqService: miqService, - API: API - }); - $httpBackend.flush(); - })); - - it('sets the name to the Kubevirt Provider', function () { - expect($scope.emsCommonModel.name).toEqual('myKubevirt'); - }); - - it('sets the type to kubevirt', function () { - expect($scope.emsCommonModel.emstype).toEqual('kubevirt'); - }); - - it('sets the hostname', function () { - expect($scope.emsCommonModel.kubevirt_hostname).toEqual('10.22.33.44'); - }); - - it('sets the zone to default', function () { - expect($scope.emsCommonModel.zone).toEqual('default'); - }); - - it('sets the password', function () { - expect($scope.emsCommonModel.kubevirt_password).toEqual(miqService.storedPasswordPlaceholder); - }); - - it('sets the kubevirt api port', function () { - expect($scope.emsCommonModel.kubevirt_api_port).toEqual('8443'); - }); - - it('sets the kubevirt security protocol', function () { - expect($scope.emsCommonModel.kubevirt_security_protocol).toEqual('ssl-with-validation-custom-ca'); - }); - - it('sets the kubevirt certificate', function () { - expect($scope.emsCommonModel.kubevirt_tls_ca_certs).toEqual('-----BEGIN DUMMY...'); - }); - - it('sets the current tab to kubevirt', function() { - expect($scope.currentTab).toEqual('kubevirt'); - }); - }); -}); diff --git a/spec/routing/ems_cloud_routing_spec.rb b/spec/routing/ems_cloud_routing_spec.rb index 74e6623af60..f8861346e8b 100644 --- a/spec/routing/ems_cloud_routing_spec.rb +++ b/spec/routing/ems_cloud_routing_spec.rb @@ -13,7 +13,6 @@ %w( dialog_load - ems_cloud_form_fields new show_list ).each do |task| @@ -31,7 +30,6 @@ show show_list protect - update ).each do |task| describe "##{task}" do it 'routes with POST' do @@ -46,12 +44,6 @@ end end - describe "#create" do - it "routes with POST" do - expect(post("/#{controller_name}")).to route_to("#{controller_name}#create") - end - end - describe "#edit" do it "routes with GET" do expect(get("/#{controller_name}/123/edit")).to route_to("#{controller_name}#edit", :id => "123") @@ -63,10 +55,4 @@ expect(get("/#{controller_name}/123")).to route_to("#{controller_name}#show", :id => "123") end end - - describe "#update" do - it "routes with POST" do - expect(post("/#{controller_name}/update/123")).to route_to("#{controller_name}#update", :id => "123") - end - end end diff --git a/spec/routing/ems_container_routing_spec.rb b/spec/routing/ems_container_routing_spec.rb index 44087947722..9b40af1c5eb 100644 --- a/spec/routing/ems_container_routing_spec.rb +++ b/spec/routing/ems_container_routing_spec.rb @@ -9,7 +9,6 @@ show show_list protect - update ).each do |task| describe "##{task}" do it 'routes with POST' do @@ -24,12 +23,6 @@ end end - describe "#create" do - it "routes with POST" do - expect(post("/#{controller_name}")).to route_to("#{controller_name}#create") - end - end - describe "#edit" do it "routes with GET" do expect(get("/#{controller_name}/123/edit")).to route_to("#{controller_name}#edit", :id => "123") @@ -41,10 +34,4 @@ expect(get("/#{controller_name}/123")).to route_to("#{controller_name}#show", :id => "123") end end - - describe "#update" do - it "routes with POST" do - expect(post("/#{controller_name}/update/123")).to route_to("#{controller_name}#update", :id => "123") - end - end end diff --git a/spec/routing/ems_infra_routing_spec.rb b/spec/routing/ems_infra_routing_spec.rb index 588058855ca..b57e0354ddb 100644 --- a/spec/routing/ems_infra_routing_spec.rb +++ b/spec/routing/ems_infra_routing_spec.rb @@ -24,7 +24,6 @@ %w( button - create listnav_search_selected protect quick_search @@ -34,7 +33,6 @@ tagging_edit tl_chooser tree_autoload - update wait_for_task protect scaling diff --git a/spec/routing/ems_physical_infra_routing_spec.rb b/spec/routing/ems_physical_infra_routing_spec.rb index 1ba74cc3b71..b91ed5af32d 100644 --- a/spec/routing/ems_physical_infra_routing_spec.rb +++ b/spec/routing/ems_physical_infra_routing_spec.rb @@ -24,7 +24,6 @@ %w( button - create listnav_search_selected protect quick_search @@ -34,7 +33,6 @@ tagging_edit tl_chooser tree_autoload - update wait_for_task protect scaling diff --git a/spec/routing/ems_storage_routing_spec.rb b/spec/routing/ems_storage_routing_spec.rb index d9cbe72cf25..5135e69f453 100644 --- a/spec/routing/ems_storage_routing_spec.rb +++ b/spec/routing/ems_storage_routing_spec.rb @@ -11,7 +11,6 @@ %w( dialog_load - ems_storage_form_fields new show_list ).each do |task| @@ -28,7 +27,6 @@ save_default_search show show_list - update ).each do |task| describe "##{task}" do it 'routes with POST' do @@ -42,10 +40,4 @@ expect(get("/#{controller_name}")).to route_to("#{controller_name}#index") end end - - describe "#update" do - it "routes with POST" do - expect(post("/#{controller_name}/update/123")).to route_to("#{controller_name}#update", :id => "123") - end - end end diff --git a/spec/shared/controllers/shared_examples_for_ems_network_controller.rb b/spec/shared/controllers/shared_examples_for_ems_network_controller.rb index 9a8a7b80fed..3f4a3589f43 100644 --- a/spec/shared/controllers/shared_examples_for_ems_network_controller.rb +++ b/spec/shared/controllers/shared_examples_for_ems_network_controller.rb @@ -74,23 +74,6 @@ end end - describe "#ems_network_form_fields" do - it "renders ems_network_form_fields json" do - Zone.seed - get :ems_network_form_fields, :params => {:id => @ems.id} - expect(response.status).to eq(200) - expect(response.body).to_not be_empty - end - end - - describe "#create" do - it "adds a new provider" do - controller.instance_variable_set(:@breadcrumbs, []) - get :new - expect(response.status).to eq(200) - end - end - describe "#test_toolbars" do it "refresh relationships and power states" do post :button, :params => {:id => @ems.id, :pressed => "ems_network_refresh"}