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

Network Router: Use API; Fix fixed IPs subnet #2422

Merged
merged 32 commits into from
Jul 20, 2018
Merged

Network Router: Use API; Fix fixed IPs subnet #2422

merged 32 commits into from
Jul 20, 2018

Conversation

gildub
Copy link
Contributor

@gildub gildub commented Oct 17, 2017

Networks > Network Routers

Replaces http calls in RoR controller by API calls
See #737
Also:

  • Filtering only external network and subsequently better proper subnet (floating IPs) handling.
  • External gateway displays only when external management provider id has been selected
  • Changes source NAT field position as it depends on the network id
  • Adds administrative state field

Before:
router1

Now:
network-routers-after

@miq-bot miq-bot added the wip label Oct 17, 2017
@gildub gildub changed the title [WIP] Network Router: Use API Network Router: Use API; Fix fixed IPs subnet Oct 19, 2017
@miq-bot miq-bot removed the wip label Oct 19, 2017
@gildub
Copy link
Contributor Author

gildub commented Oct 19, 2017

@mansam, @himdel, could you please assign/review? Thanks

@mansam
Copy link
Contributor

mansam commented Oct 20, 2017

Looks like maybe the routes for network_router_form_fields and other removed controller methods should be removed as part of this PR.

@gildub
Copy link
Contributor Author

gildub commented Oct 21, 2017

@mansam, right, was on my list but forgot. Thanks

@gildub
Copy link
Contributor Author

gildub commented Oct 24, 2017

@mansam, I removed the routes, thanks.

@gildub
Copy link
Contributor Author

gildub commented Oct 24, 2017

More PRs to follow for the controller to component' and then move the rest of the http requests (create/update/delete) to API only.

@martinpovolny, @himdel, @ZitaNemeckova

@gildub
Copy link
Contributor Author

gildub commented Nov 1, 2017

@miq-bot add_label refactoring

@gildub
Copy link
Contributor Author

gildub commented Nov 3, 2017

@mansam, @himdel, @martinpovolny, could you please assign someone for review please. Thanks

@martinpovolny
Copy link
Member

@AparnaKarve, @Hyperkid123, @ZitaNemeckova : please, review

.catch(miqService.handleFailure);
API.get("/api/network_routers/" + networkRouterFormId + "?attributes=name,ems_id,admin_state_up,cloud_network_id,extra_attributes,cloud_tenant,ext_management_system,cloud_subnets").then(function(data) {
Object.assign(vm.networkRouterModel, data);
if (data.extra_attributes.external_gateway_info && data.extra_attributes.external_gateway_info !== {}) {
Copy link
Contributor

@ZitaNemeckova ZitaNemeckova Nov 6, 2017

Choose a reason for hiding this comment

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

Be careful {} === {} is always false . You can use lodash function _.isEmpty(data.extra_attributes.external_gateway_info) to find out if it is an empty hash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, using lodash, thanks

@ZitaNemeckova
Copy link
Contributor

ZitaNemeckova commented Nov 6, 2017

Before:
screen shot 2017-11-06 at 9 36 43 am
After:
screen shot 2017-11-06 at 9 38 53 am

Buttons Save and Reset shouldn't be enabled if no change was made. vm.modelCopy is not equal to vm.networkRouterModel. Will be resolved by #2637 (merged and backported to Gaprindashvili, please rebase this PR)

Edit: Resolved.

Code climate issues can be ignored.

Code wise:

Looking for values at angularForm is not good. Please save those values in controller so they can be accessed via vm.

Not sure how much it should be enforced... But there is missing init. You can see it here and here It will make component conversion easier :)


var getCloudSubnetsByNetworkID = function(id) {
if (id) {
API.get("/api/cloud_subnets?expand=resources&attributes=name,ems_ref&filter[]=cloud_network_id=" + id).then(function(data) {
Copy link
Contributor

@ZitaNemeckova ZitaNemeckova Nov 6, 2017

Choose a reason for hiding this comment

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

Same here.

Copy link
Contributor Author

@gildub gildub Nov 9, 2017

Choose a reason for hiding this comment

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

Using better vm.modelCopy after rebase.

I've started using init() in other places, done it here too.

Not using angularForm data.

Copy link
Contributor

Choose a reason for hiding this comment

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

Missing return

}

var getCloudNetworksByEms = function(id) {
if (id) {
API.get("/api/cloud_networks?expand=resources&attributes=name,ems_ref&filter[]=external_facing=true&filter[]=ems_id=" + id).then(function(data) {
Copy link
Contributor

@ZitaNemeckova ZitaNemeckova Nov 6, 2017

Choose a reason for hiding this comment

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

If you want to wait for API call to be finished before the next then is called it should return Promise like this return API.get(... and return getCloudNetworksByEms(... when you call it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using return with Promise allows to pass the value to the next then, there is not need here for passing such data which only populate fields (or select lists).

Copy link
Contributor

Choose a reason for hiding this comment

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

I wasn't clear, sorry :) It's not about the data being sent back but about having control over them and knowing that you already have them. You want to populate fields before you display form and switch off spinner. Without suggested returns there is no guarantee that all fields will be populated before user sees them and they may change under his nose. Please add returns :)

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 see what you mean with the chaining happening only if Promise is returned. Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

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

Misssing return

}
};

var getSubnetByRef = function(ref) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above too :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Missing return

}
}).then(function() {
if (vm.networkRouterModel.external_gateway) {
getSubnetByRef(vm.networkRouterModel.extra_attributes.external_gateway_info.external_fixed_ips[0].subnet_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

return getSubnetByRef(... so it waits on Promise that you should return from this function. If you want one .then to be finished before next one starts.

}).catch(miqService.handleFailure);
}
};

vm.addClicked = function() {
var url = 'create/new' + '?button=add';
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be one string. No need for +. Could you please fix it? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@gildub
Copy link
Contributor Author

gildub commented Nov 9, 2017

@ZitaNemeckova, please review all suggestions have been addressed. I can't wait to have migrated all those networks controller to components, especially from a test view point.

vm.available_tenants = data.resources;
})(id);
}
miqService.sparkleOff();
Copy link
Contributor

Choose a reason for hiding this comment

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

Also here is no use of Promise and no guarantee that all data will be set before miqService.sparkleOff().

Copy link
Contributor

Choose a reason for hiding this comment

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

var providerTenants = miqService.getProviderTenants(function(data) {
  vm.available_tenants = data.resources;
})(id);
Promise.all([getCloudNetworksByEms(id), providerTenants])
  .then(miqService.sparkleOff)

But both must return API calls.

Copy link
Contributor Author

@gildub gildub Nov 14, 2017

Choose a reason for hiding this comment

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

Yes the sparkleOn/Off flow was really bad, and this is actually quite messy in general. Since API request are already Promise I have simplified it.

Copy link
Contributor

@himdel himdel Apr 17, 2018

Choose a reason for hiding this comment

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

This sparkleOn/sparkleOff pair is still not doing anything and can be removed :)

(Or better yet, fixed to do the right thing :))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@ZitaNemeckova
Copy link
Contributor

ZitaNemeckova commented Nov 17, 2017

@gildub I cannot add new network Router. Always ends with this error:

F, [2017-11-17T14:01:19.193444 #44722] FATAL -- : Error caught: [ActiveRecord::RecordNotFound] Couldn't find ExtManagementSystem without an ID
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-5.0.6/lib/active_record/relation/finder_methods.rb:456:in `find_with_ids'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-5.0.6/lib/active_record/relation/finder_methods.rb:66:in `find'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-5.0.6/lib/active_record/querying.rb:3:in `find'
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-5.0.6/lib/active_record/core.rb:151:in `find'
/Users/zita/Desktop/ManageIQ/manageiq-ui-classic/app/controllers/network_router_controller.rb:68:in `create'

I see only difference in send data ems_id: 10000014 => ext_management_system[]: 10000014. Is this on purpose?

@ZitaNemeckova
Copy link
Contributor

@gildub There are still returns of Promises missing.

@gildub
Copy link
Contributor Author

gildub commented Nov 22, 2017

@ZitaNemeckova,

  • Added missing returns
  • Fixed id issue blocking creation
  • Placement is showing only after ems_id is provided since it depends upon it
  • Renamed getSubnetByRef -> getCloudSubnetsByRef
  • Fixed Id when Network changes

Retested create/update

@miq-bot
Copy link
Member

miq-bot commented Nov 23, 2017

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

@miq-bot
Copy link
Member

miq-bot commented Jul 9, 2018

Checked commits https://github.com/gildub/manageiq-ui-classic/compare/f7747a1a774e1b833b0b2a58ea923d2cb8f01dde~...3633a9fdc4db85921d55eadb0639062f8e7cf3d2 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 0 offenses detected
Everything looks fine. 🍰

@gildub
Copy link
Contributor Author

gildub commented Jul 9, 2018

@ZitaNemeckova,

The reason is: at creation time there are no Provider relationship yet and therefore there are no router.external_management_system object yet so we use ems_id for creation. Conversely in the update case the relation exists and we can get router.external_management_system.id.

The same approach has been used in other places.

"ng-change" => "vm.filterCloudNetworkChanged(vm.networkRouterModel.cloud_network_id)",
"pf-select" => true,
"ng-selected" => "vm.networkRouterModel.cloud_network_id",
"ng-required" => "vm.networkRouterModel.enable_snat == true",
Copy link
Contributor

Choose a reason for hiding this comment

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

@gildub Did you remove ng-required on purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ZitaNemeckova, yes the network is part of the gateway information which is optional

@Hyperkid123
Copy link
Contributor

The form works fine. I could not find anything that is not mentioned here. But i would appreciate some specs for the JavaScript side. Even though there is just a small amount of logic, i think it would be nice to cover it and make it a bit more future proof.

@gildub
Copy link
Contributor Author

gildub commented Jul 19, 2018

@Hyperkid123, the driver here is to re-factor to add API get, the next step will be to replace with controller to component conversion (such as [1] for example) where the framework for testing is much better therefore I think it might not worth the effort.

[1] #2828

@Hyperkid123
Copy link
Contributor

@gildub that sounds great

@gildub
Copy link
Contributor Author

gildub commented Jul 19, 2018

@ZitaNemeckova, @Hyperkid123, then if everybody is happy any chance we can merge? Thanks

@Hyperkid123
Copy link
Contributor

I think its fine. There some codeclimate issues that should be fixed though (the missing semicolons for example, not the similar code warnings etc.).

But i think it should be merged.

@himdel himdel merged commit 6a4c870 into ManageIQ:master Jul 20, 2018
@himdel himdel added this to the Sprint 91 Ending Jul 30, 2018 milestone Jul 20, 2018
@gildub gildub deleted the Network_Router-API branch July 24, 2018 07:59
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.

9 participants