Selaa lähdekoodia

Add imageList to Openstack wrapper

This patch integrated glance into Openstack wrapper, allowing
imageList to be  used

Change-Id: I64e5d432224aa673ab1e6ace3e927af2f8b3a13f
changes/77/400377/2
Corentin Ardeois 3 vuotta sitten
vanhempi
commit
0ba0ea9668
4 muutettua tiedostoa jossa 111 lisäystä ja 1 poistoa
  1. 2
    1
      src/glance.js
  2. 25
    0
      src/openstack.js
  3. 13
    0
      test/functional/openstackTest.js
  4. 71
    0
      test/unit/openstackTest.js

+ 2
- 1
src/glance.js Näytä tiedosto

@@ -58,7 +58,8 @@ export default class Glance extends AbstractService {
/**
* 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.
*/
imageList(token = null) {

+ 25
- 0
src/openstack.js Näytä tiedosto

@@ -1,5 +1,6 @@
import Keystone from "./keystone";
import Neutron from "./neutron";
import Glance from "./glance";

export default class OpenStack {
/**
@@ -34,6 +35,16 @@ export default class OpenStack {
.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.
*
@@ -62,6 +73,20 @@ export default class OpenStack {
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.
*

+ 13
- 0
test/functional/openstackTest.js Näytä tiedosto

@@ -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));
});
});

});

+ 71
- 0
test/unit/openstackTest.js Näytä tiedosto

@@ -2,9 +2,11 @@ import OpenStack from "../../src/openstack";
import * as openStackMockData from './helpers/data/openstack';
import * as neutronMockData from './helpers/data/neutron';
import * as keystoneMockData from './helpers/data/keystone';
import * as glanceMockData from './helpers/data/glance';
import fetchMock from 'fetch-mock';
import Neutron from "../../src/neutron";
import Keystone from "../../src/keystone";
import Glance from "../../src/glance";

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', () => {
it('creates Neutron instance with the correct endpoint', (done) => {
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', () => {
it('should fetch the token and cache it', (done) => {
const openstack = new OpenStack(openStackMockData.config());
@@ -145,4 +210,10 @@ describe("Simple test", () => {
return neutron;
}

function mockGlance(openstack) {
const glance = new Glance(glanceMockData.config);
openstack._glancePromise = Promise.resolve(glance);
return glance;
}

});

Loading…
Peruuta
Tallenna