Fix getSubnets calls in octavia-dashboard

The getSubnets method from the neutron API should be called with a
networkId paratemer [0]. Called without params, it returns all the
subnets that are visible to a user (subnets from the current project but
also from the other projects).
Fix this behavior by fetching only the list of the networks for the
tenant, the network objects also contain their related subnets.

[0] https://opendev.org/openstack/horizon/src/commit/\
    05473b765e293f299a3762544d8e24ec32d90353/openstack_dashboard/static/\
    app/core/openstack-service-api/neutron.service.js#L169-L170

Change-Id: I23541261cf9da208f250e7224180d9a34c66ecef
Signed-off-by: Gregory Thiemonge <gthiemon@redhat.com>
This commit is contained in:
Gregory Thiemonge committed 2026-09-30 08:49:32 +00:00
1 parent 94ef322b1a
commit 199a7af37f
2 files changed
+34 -30

No files matched your search

@@ -311,17 +311,20 @@
lbaasv2API.getFlavors().then(onGetFlavors),
lbaasv2API.getAvailabilityZones().then(onGetAvailabilityZones),
lbaasv2API.getProviders().then(onGetProviders),
neutronAPI.getSubnets().then(onGetSubnets),
neutronAPI.getPorts().then(onGetPorts),
neutronAPI.getNetworks().then(onGetNetworks),
neutronAPI.getPorts().then(onGetPorts),
novaAPI.getServers().then(onGetServers),
keymanagerPromise.then(prepareCertificates, angular.noop)
]).then(initMemberAddresses);
}
function onGetNetworks(response) {
model.subnets = [];
angular.forEach(response.data.items, function(value) {
model.networks[value.id] = value;
angular.forEach(value.subnets, function(value) {
model.subnets.push(value);
});
});
}
@@ -347,7 +350,7 @@
model.context.submit = createListener;
return $q.all([
lbaasv2API.getListeners(model.spec.loadbalancer_id).then(onGetListeners),
neutronAPI.getSubnets().then(onGetSubnets),
neutronAPI.getNetworks().then(onGetNetworks),
neutronAPI.getPorts().then(onGetPorts),
novaAPI.getServers().then(onGetServers),
keymanagerPromise.then(prepareCertificates, angular.noop)
@@ -372,13 +375,13 @@
if (model.spec.parentResourceId) {
return $q.all([
lbaasv2API.getListener(model.spec.parentResourceId).then(onGetListener),
neutronAPI.getSubnets().then(onGetSubnets),
neutronAPI.getNetworks().then(onGetNetworks),
neutronAPI.getPorts().then(onGetPorts),
novaAPI.getServers().then(onGetServers)
]).then(initMemberAddresses);
} else {
return $q.all([
neutronAPI.getSubnets().then(onGetSubnets),
neutronAPI.getNetworks().then(onGetNetworks),
neutronAPI.getPorts().then(onGetPorts),
novaAPI.getServers().then(onGetServers)
]).then(initMemberAddresses);
@@ -394,7 +397,7 @@
model.context.submit = updatePoolMemberList;
return $q.all([
lbaasv2API.getPool(model.spec.parentResourceId).then(onGetPool),
neutronAPI.getSubnets().then(onGetSubnets).then(getMembers).then(onGetMembers),
neutronAPI.getNetworks().then(onGetNetworks).then(getMembers).then(onGetMembers),
neutronAPI.getPorts().then(onGetPorts),
novaAPI.getServers().then(onGetServers)
]).then(initMemberAddresses);
@@ -407,7 +410,6 @@
lbaasv2API.getAvailabilityZones().then(onGetAvailabilityZones),
lbaasv2API.getLoadBalancer(model.context.id).then(onGetLoadBalancer),
lbaasv2API.getProviders().then(onGetProviders),
neutronAPI.getSubnets().then(onGetSubnets),
neutronAPI.getNetworks().then(onGetNetworks)
]).then(initSubnet).then(initFlavor).then(initAvailabilityZone).then(initProvider);
}
@@ -415,7 +417,7 @@
function initEditListener() {
model.context.submit = editListener;
return $q.all([
neutronAPI.getSubnets().then(onGetSubnets).then(getListener)
neutronAPI.getNetworks().then(onGetNetworks).then(getListener)
.then(onGetListener).then(getPools).then(onGetPools),
neutronAPI.getPorts().then(onGetPorts),
novaAPI.getServers().then(onGetServers)
@@ -438,7 +440,7 @@
function initEditPool() {
model.context.submit = editPool;
return $q.all([
neutronAPI.getSubnets().then(onGetSubnets).then(getPool).then(onGetPool),
neutronAPI.getNetworks().then(onGetNetworks).then(getPool).then(onGetPool),
neutronAPI.getPorts().then(onGetPorts),
novaAPI.getServers().then(onGetServers)
]).then(initMemberAddresses);
@@ -685,11 +687,6 @@
});
}
function onGetSubnets(response) {
model.subnets.length = 0;
push.apply(model.subnets, response.data.items);
}
function onGetServers(response) {
model.members.length = 0;
var members = [];
@@ -89,11 +89,19 @@
mockNetworks = {
a1: {
name: 'network_1',
id: 'a1'
id: 'a1',
subnets: [{
id: 'subnet-1',
name: 'subnet-1'
}]
},
b2: {
name: 'network_2',
id: 'b2'
id: 'b2',
subnets: [{
id: 'subnet-2',
name: 'subnet-2'
}]
}
};
mockFlavors = {
@@ -411,15 +419,6 @@
});
$provide.value('horizon.app.core.openstack-service-api.neutron', {
getSubnets: function() {
var subnets = [{id: 'subnet-1', name: 'subnet-1'},
{id: 'subnet-2', name: 'subnet-2'}];
var deferred = $q.defer();
deferred.resolve({data: {items: subnets}});
return deferred.promise;
},
getPorts: function() {
var ports = [{
device_id: '1',
@@ -440,10 +439,18 @@
getNetworks: function() {
var networks = [{
name: 'network_1',
id: 'a1'
id: 'a1',
subnets: [{
id: 'subnet-1',
name: 'subnet-1'
}]
}, {
name: 'network_2',
id: 'b2'
id: 'b2',
subnets: [{
id: 'subnet-2',
name: 'subnet-2'
}]
}];
var deferred = $q.defer();
@@ -1511,7 +1518,7 @@
beforeEach(inject(function($injector) {
var neutronAPI = $injector.get('horizon.app.core.openstack-service-api.neutron');
neutronAPI.getSubnets = function() {
neutronAPI.getNetworks = function() {
var deferred = $q.defer();
deferred.reject('Error');
return deferred.promise;
@@ -1523,11 +1530,11 @@
scope.$apply();
});
it('should fail to be initialized on subnets error', function() {
it('should fail to be initialized on networks error', function() {
expect(model.initializing).toBe(false);
expect(model.initialized).toBe(false);
expect(model.spec.loadbalancer.name).toBeNull();
expect(model.subnets).toEqual([]);
expect(model.networks).toEqual({});
});
});