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

[FINE] Lazy load StorageManagers upon volume creation #4600

Merged

Conversation

miha-plesko
Copy link
Contributor

Same as #4549 but with merge conflicts resolved.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1625250

@miq-bot add_label bug,fine/yes,gaprindashvili/no
@miq-bot assign @himdel

/cc @AparnaKarve @simaishi

When creating a new volume user has to pick what StorageManager is volume
supposed to be created with, hence we perform API request to fetch those.
Problem is we share angular controller with other volume operations (attach,
detach) that don't need this list of all managers and fetching those
anyway results in permission denied error due to fine-grained permission
setting.

For example if we give user only permission to attach/detach volume, but
not to view StorageManagers, then we must not perform the API call as it
results in 403 with red popup.

With this commit we refactor controller so that it now only performs the
API calls that are really needed.

BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1571224

Signed-off-by: Miha Pleško <[email protected]>
@@ -57,4 +57,5 @@
:javascript
ManageIQ.angular.app.value('cloudVolumeFormId', '#{@volume.id}');
ManageIQ.angular.app.value('storageManagerId', #{@volume.ext_management_system.id});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@himdel in Fine the IDs seem to be integers so we don't need to change to string as on the original PR.

Copy link
Contributor

@himdel himdel Sep 5, 2018

Choose a reason for hiding this comment

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

We definitely do, the same issue with too big integers is also present in fine (but more places where it's not fixed)

(Furthermore, you may need to do the from_cid / to_cid trasnformation - you need to use a region other than 0 in your database in order to make sure this works.)

Copy link
Contributor

Choose a reason for hiding this comment

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

(IIRC in regions other than 0, the ids will come in the 10r256 format from the API too)

@miha-plesko
Copy link
Contributor Author

@miq-bot add_label blocker,storage

vm.storageManagerChanged(vm.cloudVolumeModel.storage_manager_id);
}
// Can handle list of all managers or a single manager.
vm.storageManagers = data.resources ? data.resources : [data];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@himdel this is where we store value "as is" - and it's integer. If I convert storageManagerId into a string (in the haml) then nothing gets selected in the drop-down. Is it possible that API returns integers? Or you think controller somehow parses it wrong?

I say we do separate PR for this as it's not related to this BZ. Will check it a bit later when I checkout fine branch again.

Copy link
Contributor

@himdel himdel Sep 5, 2018

Choose a reason for hiding this comment

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

The API will most likely return compressed ids, in the format like "1r23". You can use miqUncompressedId to convert to '1000000000023' in JS, or you can use to_cid ruby-side to convert to that format.

(again, you'll need to be in a db region other than 0 to be able to tell)

@miha-plesko
Copy link
Contributor Author

@himdel sorry it took me so long to respond, but eventually I resolved the ID issue by grabbing the ID from href where it's always stored as a string and always in fullblown version. I don't dare to modify the provider renderer on the API as many things could break.

Looking forward to your opinion.

It's unsafe to interpret IDs as integers as they may be too large.
But since API returns them as integers, we rather do a workaround
and override them with string equivalents obtained by parsing the
href string:

```
"href":"http://172.16.117.189:3000/api/providers/123000000000001"
                                                |--- the ID ---|
```

Signed-off-by: Miha Pleško <[email protected]>
@miha-plesko miha-plesko force-pushed the fine-lazy-fetch-storage-managers branch from 328d169 to a25207a Compare September 6, 2018 13:04
// Parse ID from href, e.g. http://172.16.117.189:3000/api/providers/123000000000001.
return href.toString().replace(/\/$/, '').split('/').slice(-1)[0];
};

Copy link
Contributor Author

@miha-plesko miha-plesko Sep 6, 2018

Choose a reason for hiding this comment

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

@himdel I added some more checks to prevent crash on strange inputs like undefined or integer value. It's better if we don't crash and return invalid value because we're just filling the drop-down after all...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just tested cloud volume creation (the only operation where user can actually modify drop-down value for manager) and it passes on correct value with valid payload like:

name=miha-volume&aws_encryption=false&incremental=false&force=false&storage_manager_id=123000000000003&emstype=...

In other words, it seems to work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, looks about right :)

slice with negative indexes seems to be supported everywhere, not seeing any issues 👍

@miq-bot
Copy link
Member

miq-bot commented Sep 6, 2018

Checked commits miha-plesko/manageiq-ui-classic@12f5a03~...a25207a with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
0 files checked, 0 offenses detected
Everything looks fine. 🍪

Copy link
Contributor

@himdel himdel left a comment

Choose a reason for hiding this comment

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

👍 LGTM

(the spec failure doesn't seem to be related...)

@miha-plesko miha-plesko closed this Sep 6, 2018
@miha-plesko miha-plesko reopened this Sep 6, 2018
@miha-plesko miha-plesko closed this Sep 6, 2018
@miha-plesko miha-plesko reopened this Sep 6, 2018
@simaishi simaishi merged commit 01bda87 into ManageIQ:fine Sep 6, 2018
@simaishi simaishi added this to the Sprint 94 Ending Sep 10, 2018 milestone Sep 6, 2018
@miha-plesko miha-plesko deleted the fine-lazy-fetch-storage-managers branch January 7, 2019 08:25
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.

4 participants