Added networkList() method to neutron API

This patch adds the networkList() method to the network API.

Change-Id: Ie0878787169988253a93dd6d67b07a97bd005587
This commit is contained in:
Corentin Ardeois 2016-09-26 13:51:03 -04:00
parent 08aa4981f1
commit 70a98fb10c
5 changed files with 122 additions and 1 deletions

View File

@ -53,4 +53,18 @@ export default class Neutron extends AbstractService {
super(endpointConfig.url, supportedNeutronVersions);
}
/**
* List the networks available on neutron.
*
* @param {String} token An authorization token, or a promise which will resolve into one.
* @returns {Promise.<T>} A promise which will resolve with the list of networks.
*/
networkList(token = null) {
return this
._requestComponents(token)
.then(([url, headers]) => this.http.httpRequest('GET', `${url}/networks`, headers))
.then((response) => response.json())
.then((body) => body.networks);
}
}

View File

@ -80,4 +80,17 @@ describe("neutron", () => {
});
});
describe("networkList()", () => {
it("should return the networks as an array.", (done) => {
configPromise
.then((config) => new Neutron(config))
.then((neutron) => neutron.networkList(tokenPromise))
.then((networks) => {
expect(networks.length > 0).toBeTruthy();
done();
})
.catch((error) => done.fail(error));
});
});
});

View File

@ -58,7 +58,56 @@ function rootResponse() {
};
}
function networkList(token) {
return {
method: 'GET',
matcher: 'http://192.168.99.99:9696/v2.0/networks',
headers: {
'X-Auth-Token': token
},
response: {
networks: [
{
status: 'ACTIVE',
subnets: [
'54d6f61d-db07-451c-9ab3-b9609b6b6f0b'
],
name: 'private-network',
'provider:physical_network': null,
admin_state_up: true,
tenant_id: '4fd44f30292945e481c7b8a0c8908869',
qos_policy_id: '6a8454ade84346f59e8d40665f878b2e',
'provider:network_type': 'local',
'router:external': true,
mtu: 0,
shared: true,
id: 'd32019d3-bc6e-4319-9c1d-6722fc136a22',
'provider:segmentation_id': null
},
{
status: 'ACTIVE',
subnets: [
'08eae331-0402-425a-923c-34f7cfe39c1b'
],
name: 'private',
'provider:physical_network': null,
admin_state_up: true,
tenant_id: '26a7980765d0414dbc1fc1f88cdb7e6e',
qos_policy_id: 'bfdb6c39f71e4d44b1dfbda245c50819',
'provider:network_type': 'local',
'router:external': true,
mtu: 0,
shared: true,
id: 'db193ab3-96e3-4cb3-8fc5-05f4296d0324',
'provider:segmentation_id': null
}
]
}
};
}
export {
neutronConfig as config,
rootResponse as root
rootResponse as root,
networkList
};

View File

@ -51,4 +51,45 @@ describe('neutron', () => {
.catch((error) => done.fail(error));
});
});
describe("networkList()", () => {
let neutron = null;
beforeEach(() => {
fetchMock.mock(mockData.root());
neutron = new Neutron(mockData.config);
});
it("should return the networks as an array.", (done) => {
const token = 'test_token';
fetchMock.mock(mockData.networkList(token));
neutron
.networkList(token)
.then((networks) => {
expect(networks.length).toBe(2);
done();
})
.catch((error) => done.fail(error));
});
it("Should not cache its results", (done) => {
const token = 'test_token';
let mockOptions = mockData.networkList(token);
fetchMock.mock(mockOptions);
neutron
.networkList(token)
.then(() => {
expect(fetchMock.calls(mockOptions.matcher).length).toEqual(1);
return neutron.networkList(token);
})
.then(() => {
expect(fetchMock.calls(mockOptions.matcher).length).toEqual(2);
done();
})
.catch((error) => done.fail(error));
});
});
});

View File

@ -50,6 +50,10 @@ allowed_origin=http://localhost:9876
[[post-config|\$GLANCE_API_CONF]]
[cors]
allowed_origin=http://localhost:9876
[[post-config|\$NEUTRON_CONF]]
[cors]
allowed_origin=http://localhost:9876
EOL
# Start devstack.