Merge "Add imageList to Openstack wrapper"
This commit is contained in:
commit
cf336dec98
|
@ -58,7 +58,8 @@ export default class Glance extends AbstractService {
|
||||||
/**
|
/**
|
||||||
* List the images available on glance.
|
* List the images available on glance.
|
||||||
*
|
*
|
||||||
* @param {String} token An authorization token, or a promise which will resolve into one.
|
* @param {(String|Promise.<T>)} token An authorization token, or a promise which will resolve
|
||||||
|
* into one.
|
||||||
* @returns {Promise.<T>} A promise which will resolve with the list of images.
|
* @returns {Promise.<T>} A promise which will resolve with the list of images.
|
||||||
*/
|
*/
|
||||||
imageList(token = null) {
|
imageList(token = null) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import Keystone from "./keystone";
|
import Keystone from "./keystone";
|
||||||
import Neutron from "./neutron";
|
import Neutron from "./neutron";
|
||||||
|
import Glance from "./glance";
|
||||||
|
|
||||||
export default class OpenStack {
|
export default class OpenStack {
|
||||||
/**
|
/**
|
||||||
|
@ -34,6 +35,16 @@ export default class OpenStack {
|
||||||
.then((neutron) => neutron.networkList(this._token));
|
.then((neutron) => neutron.networkList(this._token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List the images available on glance.
|
||||||
|
*
|
||||||
|
* @returns {Promise.<T>} A promise which will resolve with the list of images.
|
||||||
|
*/
|
||||||
|
imageList() {
|
||||||
|
return this._glance
|
||||||
|
.then((glance) => glance.imageList(this._token));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keystone component.
|
* Keystone component.
|
||||||
*
|
*
|
||||||
|
@ -62,6 +73,20 @@ export default class OpenStack {
|
||||||
return this._neutronPromise;
|
return this._neutronPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Glance component.
|
||||||
|
*
|
||||||
|
* @returns {Promise.<Glance>} A promise which will resolve with Glance instance.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
get _glance() {
|
||||||
|
if (!this._glancePromise) {
|
||||||
|
this._glancePromise = this._getComponentConfigFor('glance')
|
||||||
|
.then((componentConfig) => new Glance(componentConfig));
|
||||||
|
}
|
||||||
|
return this._glancePromise;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Token issued from Keystone.
|
* Token issued from Keystone.
|
||||||
*
|
*
|
||||||
|
|
|
@ -20,4 +20,17 @@ describe("OpenStack", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("imageList()", () => {
|
||||||
|
it("should return the images as an array.", (done) => {
|
||||||
|
const openstack = new OpenStack(devstackConfig);
|
||||||
|
|
||||||
|
openstack.imageList()
|
||||||
|
.then((images) => {
|
||||||
|
expect(images.length > 0).toBeTruthy();
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch((error) => done.fail(error));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,9 +2,11 @@ import OpenStack from "../../src/openstack";
|
||||||
import * as openStackMockData from './helpers/data/openstack';
|
import * as openStackMockData from './helpers/data/openstack';
|
||||||
import * as neutronMockData from './helpers/data/neutron';
|
import * as neutronMockData from './helpers/data/neutron';
|
||||||
import * as keystoneMockData from './helpers/data/keystone';
|
import * as keystoneMockData from './helpers/data/keystone';
|
||||||
|
import * as glanceMockData from './helpers/data/glance';
|
||||||
import fetchMock from 'fetch-mock';
|
import fetchMock from 'fetch-mock';
|
||||||
import Neutron from "../../src/neutron";
|
import Neutron from "../../src/neutron";
|
||||||
import Keystone from "../../src/keystone";
|
import Keystone from "../../src/keystone";
|
||||||
|
import Glance from "../../src/glance";
|
||||||
|
|
||||||
describe("Simple test", () => {
|
describe("Simple test", () => {
|
||||||
|
|
||||||
|
@ -47,6 +49,23 @@ describe("Simple test", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('imageList', () => {
|
||||||
|
it('should fetch imageList from glance', (done) => {
|
||||||
|
const openstack = new OpenStack(openStackMockData.config());
|
||||||
|
const glance = mockGlance(openstack);
|
||||||
|
const imagesData = glanceMockData.imageList('token').response.images;
|
||||||
|
|
||||||
|
spyOn(glance, 'imageList').and.returnValue(Promise.resolve(imagesData));
|
||||||
|
|
||||||
|
openstack.imageList()
|
||||||
|
.then((images) => {
|
||||||
|
expect(images.length).toBe(3);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch((error) => done.fail(error));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('_neutron', () => {
|
describe('_neutron', () => {
|
||||||
it('creates Neutron instance with the correct endpoint', (done) => {
|
it('creates Neutron instance with the correct endpoint', (done) => {
|
||||||
const token = 'test_token';
|
const token = 'test_token';
|
||||||
|
@ -111,6 +130,52 @@ describe("Simple test", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('_glance', () => {
|
||||||
|
it('creates Glance instance with the correct endpoint', (done) => {
|
||||||
|
const token = 'test_token';
|
||||||
|
const openstack = new OpenStack(openStackMockData.config());
|
||||||
|
const keystone = mockKeystone(openstack);
|
||||||
|
const catalogData = keystoneMockData.catalogList(token).response.catalog;
|
||||||
|
|
||||||
|
spyOn(keystone, 'tokenIssue').and.returnValue(Promise.resolve(token));
|
||||||
|
spyOn(keystone, 'catalogList').and.returnValue(Promise.resolve(catalogData));
|
||||||
|
|
||||||
|
openstack._glance
|
||||||
|
.then((glance) => {
|
||||||
|
expect(keystone.catalogList).toHaveBeenCalledWith(token);
|
||||||
|
expect(glance).toEqual(jasmine.any(Glance));
|
||||||
|
expect(glance.endpointUrl).toEqual('http://192.168.99.99:9292');
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch((error) => done.fail(error));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should cache Glance instance and Keystone token', (done) => {
|
||||||
|
const openstack = new OpenStack(openStackMockData.config());
|
||||||
|
const tokenIssueMock = keystoneMockData.tokenIssue();
|
||||||
|
const catalogListMock = keystoneMockData.catalogList('test_token');
|
||||||
|
|
||||||
|
fetchMock.mock(keystoneMockData.root());
|
||||||
|
fetchMock.mock(tokenIssueMock);
|
||||||
|
fetchMock.mock(catalogListMock);
|
||||||
|
|
||||||
|
openstack._glance
|
||||||
|
.then((glance) => {
|
||||||
|
expect(glance).toEqual(jasmine.any(Glance));
|
||||||
|
expect(fetchMock.calls(tokenIssueMock.matcher).length).toEqual(1);
|
||||||
|
expect(fetchMock.calls(catalogListMock.matcher).length).toEqual(1);
|
||||||
|
return openstack._glance;
|
||||||
|
})
|
||||||
|
.then((glance) => {
|
||||||
|
expect(glance).toEqual(jasmine.any(Glance));
|
||||||
|
expect(fetchMock.calls(tokenIssueMock.matcher).length).toEqual(1);
|
||||||
|
expect(fetchMock.calls(catalogListMock.matcher).length).toEqual(1);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch((error) => done.fail(error));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('_token', () => {
|
describe('_token', () => {
|
||||||
it('should fetch the token and cache it', (done) => {
|
it('should fetch the token and cache it', (done) => {
|
||||||
const openstack = new OpenStack(openStackMockData.config());
|
const openstack = new OpenStack(openStackMockData.config());
|
||||||
|
@ -145,4 +210,10 @@ describe("Simple test", () => {
|
||||||
return neutron;
|
return neutron;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mockGlance(openstack) {
|
||||||
|
const glance = new Glance(glanceMockData.config);
|
||||||
|
openstack._glancePromise = Promise.resolve(glance);
|
||||||
|
return glance;
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue