Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sshkey support to OpenStack Cloud #4388

Merged
merged 1 commit into from
Aug 29, 2018
Merged

Conversation

sseago
Copy link
Contributor

@sseago sseago commented Jul 31, 2018

Add sshkey support to OpenStack Cloud needed for v2v.

@@ -261,7 +261,7 @@
: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'"}
%div{"ng-show" => "emsCommonModel.emstype != '' && emsCommonModel.emstype != 'azure'"}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be the wrong solution here, but "ng-show" is what is used for the ems_infra version of this form. Before I changed from ng-if, I was getting a javascript error. It looks like what was happening was that with the partial not rendering at all with ng-if (vs. rendering and being hidden with ng-show), default_userid is left undefined when $scope.canValidateBasicInfo is called. As a result of this, the javascript on the SSH Keypair endpoint tab does not run. I don't know if there are any downsides to using ng-show here, but this partially reverses an earlier change to the validation (I'll link to the commit in another comment).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The downside to ng-show is that all the fields are there, always.

You can't have multiple ng-show statemens with different conditions including the same partial because then, the partial will always exist multiple times.

(Unless that partial supports some kind of prefix to regulate this.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

((If you really need the partial to exist and not be visible, use ng-if with a .hidden class, but ... better fix the underlying problem really.))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this specific case... this looks like isBasicInfoValid is already doing logic to determine which fields should be there.

So I'm almost sure any fix for your issue should be to isBasicInfoValid itself, not the partial.

@sseago
Copy link
Contributor Author

sseago commented Aug 10, 2018

The javascript error referenced in my comment on the commit above when I don't change the directive to "ng-show":
TypeError: $scope.angularForm.default_userid is undefined Stack trace: $scope.isBasicInfoValid@http://192.168.1.83:3000/assets/controllers/ems_common/ems_common_form_controller.self-03b2803e616dd53db1122e9cdac7bac3318a68357689230c51338c66eef9132a.js?body=1:318:1 $scope.canValidateBasicInfo@http://192.168.1.83:3000/assets/controllers/ems_common/ems_common_form_controller.self-03b2803e616dd53db1122e9cdac7bac3318a68357689230c51338c66eef9132a.js?body=1:304:12

@sseago
Copy link
Contributor Author

sseago commented Aug 10, 2018

This is the commit that is partially undone by the ng-show change above:
ManageIQ/manageiq@07e9be9#diff-ca482ed9159124886ce2c48c3e67ecc2R201

@aufi
Copy link
Member

aufi commented Aug 14, 2018

@sseago OpenStack part was merged, can the WIP be removed?

@sseago
Copy link
Contributor Author

sseago commented Aug 14, 2018

@aufi I can remove WIP now. I kept it around in case further work was needed around the potential issue I commented on above, but it's not really "in progress" anymore. It's done unless a better suggestion comes down as to how to handle the prior javascript error.

@sseago sseago changed the title [WIP] add sshkey support to OpenStack Cloud add sshkey support to OpenStack Cloud Aug 14, 2018
@miq-bot miq-bot removed the wip label Aug 14, 2018
@miq-bot
Copy link
Member

miq-bot commented Aug 22, 2018

This pull request is not mergeable. Please rebase and repush.

@blomquisg
Copy link
Member

Ping @himdel can you give this another look.

@sseago looks like miq-bot decided this was unmergeable ... take a look at the codeclimate and/or scrutinizer failures

@sseago
Copy link
Contributor Author

sseago commented Aug 23, 2018

@blomquisg The merge issue has already been resolved -- miq-bot removed the unmergeable label. Looking at the codeclimate and scrutinizer errors, those don't seem particularly relevant to my PR. For scrutinizer, it hit an npm version error, and for codeclimate, it's mostly flagging "complexity" issues that reflect the existing design of the code I'm making minor tweaks to rather than the design of the changes.

@@ -759,6 +761,11 @@ def build_credentials(ems, mode)
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::Openstack::CloudManager) &&
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)
Copy link
Contributor

@himdel himdel Aug 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need a third copy of this code?

Especially since all the other places use a openstack or openstack_infra or rhevm condition instead of 3 different ones.

Please unify the three.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated version of the PR combines the three.

@@ -309,8 +309,8 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
($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.$valid &&
$scope.emsCommonModel.default_password != '' && $scope.angularForm.default_password.$valid)) {
($scope.emsCommonModel.default_userid != '' && $scope.angularForm.default_userid !== undefined && $scope.angularForm.default_userid.$valid &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to check for ssh_keypair_userid === undefined for if the tab is correctly displayed?

Copy link
Contributor

@himdel himdel Aug 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Either looks like a bug that needs to be fixed in the other places as well, or a random change that could potentially break other places, unless there is something special about this particular pair of fields that's not happening elsewhere..)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the fix that allowed me to remove the earlier change of "ng-if" to "ng-show". Without the 'undefined' check, this code fails with a javascript error. We didn't see the error appear until adding the sshkey tab, since the other case where the sshkey tab is used (ems_infra) uses 'ng-show' instead of 'ng-if' to display the tab. I followed the example of the existing code (see below in this same method) for handling fields which may be undefined. If the prior change using 'ng-show' instead of 'ng-if' is better, I could revert back to the prior version, but I was following your suggestion here to fix this method rather than using ng-show in the view. I think this version is probably a cleaner solution than what was done before. I suspect getting rid of the problem without checking for undefined would be a much larger change to this code which would be tricky to make sure it didn't break other things (across providers, etc.). This is a pretty safe change, since it basically can't break anything -- for any case where these are undefined, the code is broken without this change already, and when these are defined, checking for undefined is safe.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, makes sense, thanks :) I was just trying to make sure this is still intended :)

@@ -63,9 +63,10 @@
};

EmsKeypairController.prototype.showValidate = function(tab) {
var openstackAndNew = (this.model.emstype === 'openstack_infra') && this.newRecord;
var openstackInfraAndNew = (this.model.emstype === 'openstack_infra') && this.newRecord;
var openstackCloud = this.model.emstype === 'openstack';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is cloud supposed to be different from openstack infra and rhevm here?

Why is validation different for non-new openstack records than for non-new openstack infra? (Any chance that's a bug?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cloud is just like rhevm here -- no validation for either 'new' or 'update' forms. Cloud is not like openstack infra because for OpenStack infra, we only validate for 'update', not for 'new'. If you look at the conditional before, we treat rhevm and cloud the same. The distinction is made for OpenStack Infra -- where we validate for update form but not new form. It's not a bug -- it's the way it's supposed to work, since we don't necessarily have an instance running at this point in which we can validate the keypair credentials -- this is the case for both rhevm and openstack cloud.

Add sshkey support to OpenStack Cloud needed for v2v.
@miq-bot
Copy link
Member

miq-bot commented Aug 28, 2018

Checked commit sseago@cdc619f with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 1 offense detected

**

  • 💣 💥 🔥 🚒 - Linter/Haml - Linter::Haml STDERR:
warning: parser/current is loading parser/ruby23, which recognizes
warning: 2.3.6-compliant syntax, but you are running 2.3.3.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.

@himdel
Copy link
Contributor

himdel commented Aug 29, 2018

OK, LGTM , thanks for the details! :)
Verified seeing no breakage in the UI 👍

(ignoring hakiri - fixed by #4563, and cc because ems_common)

@himdel himdel merged commit 3f140ac into ManageIQ:master Aug 29, 2018
@himdel himdel added this to the Sprint 94 Ending Sept 10, 2018 milestone Aug 29, 2018
@himdel himdel self-assigned this Aug 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants