summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorentin Ardeois <cardeois@internap.com>2016-11-21 14:09:00 -0500
committerCorentin Ardeois <cardeois@internap.com>2016-11-21 15:17:44 -0500
commit0ba0ea9668847d39c356021034f7ee708c2406d5 (patch)
tree4fddd370215a308070bc43b3ffdb6117c2304289
parentcffe4a7c94aa579f4211b9b134d2d8bb5c5345a0 (diff)
Add imageList to Openstack wrapper
This patch integrated glance into Openstack wrapper, allowing imageList to be used Change-Id: I64e5d432224aa673ab1e6ace3e927af2f8b3a13f
Notes
Notes (review): Code-Review+1: Dong Ma <winterma.dong@gmail.com> Code-Review+2: Vitaly Kramskikh <vkramskikh@mirantis.com> Workflow+1: Vitaly Kramskikh <vkramskikh@mirantis.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Fri, 02 Dec 2016 21:55:05 +0000 Reviewed-on: https://review.openstack.org/400377 Project: openstack/js-openstack-lib Branch: refs/heads/master
-rw-r--r--src/glance.js3
-rw-r--r--src/openstack.js25
-rw-r--r--test/functional/openstackTest.js13
-rw-r--r--test/unit/openstackTest.js71
4 files changed, 111 insertions, 1 deletions
diff --git a/src/glance.js b/src/glance.js
index 33521e2..3dfc80f 100644
--- a/src/glance.js
+++ b/src/glance.js
@@ -58,7 +58,8 @@ export default class Glance extends AbstractService {
58 /** 58 /**
59 * List the images available on glance. 59 * List the images available on glance.
60 * 60 *
61 * @param {String} token An authorization token, or a promise which will resolve into one. 61 * @param {(String|Promise.<T>)} token An authorization token, or a promise which will resolve
62 * into one.
62 * @returns {Promise.<T>} A promise which will resolve with the list of images. 63 * @returns {Promise.<T>} A promise which will resolve with the list of images.
63 */ 64 */
64 imageList(token = null) { 65 imageList(token = null) {
diff --git a/src/openstack.js b/src/openstack.js
index b1e9bb4..46109d1 100644
--- a/src/openstack.js
+++ b/src/openstack.js
@@ -1,5 +1,6 @@
1import Keystone from "./keystone"; 1import Keystone from "./keystone";
2import Neutron from "./neutron"; 2import Neutron from "./neutron";
3import Glance from "./glance";
3 4
4export default class OpenStack { 5export default class OpenStack {
5 /** 6 /**
@@ -35,6 +36,16 @@ export default class OpenStack {
35 } 36 }
36 37
37 /** 38 /**
39 * List the images available on glance.
40 *
41 * @returns {Promise.<T>} A promise which will resolve with the list of images.
42 */
43 imageList() {
44 return this._glance
45 .then((glance) => glance.imageList(this._token));
46 }
47
48 /**
38 * Keystone component. 49 * Keystone component.
39 * 50 *
40 * @returns {Promise.<Keystone>} A promise which will resolve with Keystone instance. 51 * @returns {Promise.<Keystone>} A promise which will resolve with Keystone instance.
@@ -63,6 +74,20 @@ export default class OpenStack {
63 } 74 }
64 75
65 /** 76 /**
77 * Glance component.
78 *
79 * @returns {Promise.<Glance>} A promise which will resolve with Glance instance.
80 * @private
81 */
82 get _glance() {
83 if (!this._glancePromise) {
84 this._glancePromise = this._getComponentConfigFor('glance')
85 .then((componentConfig) => new Glance(componentConfig));
86 }
87 return this._glancePromise;
88 }
89
90 /**
66 * Token issued from Keystone. 91 * Token issued from Keystone.
67 * 92 *
68 * @returns {Promise.<T>} A promise which will resolve with the token. 93 * @returns {Promise.<T>} A promise which will resolve with the token.
diff --git a/test/functional/openstackTest.js b/test/functional/openstackTest.js
index c1ac912..4ccd7ba 100644
--- a/test/functional/openstackTest.js
+++ b/test/functional/openstackTest.js
@@ -20,4 +20,17 @@ describe("OpenStack", () => {
20 }); 20 });
21 }); 21 });
22 22
23 describe("imageList()", () => {
24 it("should return the images as an array.", (done) => {
25 const openstack = new OpenStack(devstackConfig);
26
27 openstack.imageList()
28 .then((images) => {
29 expect(images.length > 0).toBeTruthy();
30 done();
31 })
32 .catch((error) => done.fail(error));
33 });
34 });
35
23}); 36});
diff --git a/test/unit/openstackTest.js b/test/unit/openstackTest.js
index 832db55..1b2b82b 100644
--- a/test/unit/openstackTest.js
+++ b/test/unit/openstackTest.js
@@ -2,9 +2,11 @@ import OpenStack from "../../src/openstack";
2import * as openStackMockData from './helpers/data/openstack'; 2import * as openStackMockData from './helpers/data/openstack';
3import * as neutronMockData from './helpers/data/neutron'; 3import * as neutronMockData from './helpers/data/neutron';
4import * as keystoneMockData from './helpers/data/keystone'; 4import * as keystoneMockData from './helpers/data/keystone';
5import * as glanceMockData from './helpers/data/glance';
5import fetchMock from 'fetch-mock'; 6import fetchMock from 'fetch-mock';
6import Neutron from "../../src/neutron"; 7import Neutron from "../../src/neutron";
7import Keystone from "../../src/keystone"; 8import Keystone from "../../src/keystone";
9import Glance from "../../src/glance";
8 10
9describe("Simple test", () => { 11describe("Simple test", () => {
10 12
@@ -47,6 +49,23 @@ describe("Simple test", () => {
47 }); 49 });
48 }); 50 });
49 51
52 describe('imageList', () => {
53 it('should fetch imageList from glance', (done) => {
54 const openstack = new OpenStack(openStackMockData.config());
55 const glance = mockGlance(openstack);
56 const imagesData = glanceMockData.imageList('token').response.images;
57
58 spyOn(glance, 'imageList').and.returnValue(Promise.resolve(imagesData));
59
60 openstack.imageList()
61 .then((images) => {
62 expect(images.length).toBe(3);
63 done();
64 })
65 .catch((error) => done.fail(error));
66 });
67 });
68
50 describe('_neutron', () => { 69 describe('_neutron', () => {
51 it('creates Neutron instance with the correct endpoint', (done) => { 70 it('creates Neutron instance with the correct endpoint', (done) => {
52 const token = 'test_token'; 71 const token = 'test_token';
@@ -111,6 +130,52 @@ describe("Simple test", () => {
111 }); 130 });
112 }); 131 });
113 132
133 describe('_glance', () => {
134 it('creates Glance instance with the correct endpoint', (done) => {
135 const token = 'test_token';
136 const openstack = new OpenStack(openStackMockData.config());
137 const keystone = mockKeystone(openstack);
138 const catalogData = keystoneMockData.catalogList(token).response.catalog;
139
140 spyOn(keystone, 'tokenIssue').and.returnValue(Promise.resolve(token));
141 spyOn(keystone, 'catalogList').and.returnValue(Promise.resolve(catalogData));
142
143 openstack._glance
144 .then((glance) => {
145 expect(keystone.catalogList).toHaveBeenCalledWith(token);
146 expect(glance).toEqual(jasmine.any(Glance));
147 expect(glance.endpointUrl).toEqual('http://192.168.99.99:9292');
148 done();
149 })
150 .catch((error) => done.fail(error));
151 });
152
153 it('should cache Glance instance and Keystone token', (done) => {
154 const openstack = new OpenStack(openStackMockData.config());
155 const tokenIssueMock = keystoneMockData.tokenIssue();
156 const catalogListMock = keystoneMockData.catalogList('test_token');
157
158 fetchMock.mock(keystoneMockData.root());
159 fetchMock.mock(tokenIssueMock);
160 fetchMock.mock(catalogListMock);
161
162 openstack._glance
163 .then((glance) => {
164 expect(glance).toEqual(jasmine.any(Glance));
165 expect(fetchMock.calls(tokenIssueMock.matcher).length).toEqual(1);
166 expect(fetchMock.calls(catalogListMock.matcher).length).toEqual(1);
167 return openstack._glance;
168 })
169 .then((glance) => {
170 expect(glance).toEqual(jasmine.any(Glance));
171 expect(fetchMock.calls(tokenIssueMock.matcher).length).toEqual(1);
172 expect(fetchMock.calls(catalogListMock.matcher).length).toEqual(1);
173 done();
174 })
175 .catch((error) => done.fail(error));
176 });
177 });
178
114 describe('_token', () => { 179 describe('_token', () => {
115 it('should fetch the token and cache it', (done) => { 180 it('should fetch the token and cache it', (done) => {
116 const openstack = new OpenStack(openStackMockData.config()); 181 const openstack = new OpenStack(openStackMockData.config());
@@ -145,4 +210,10 @@ describe("Simple test", () => {
145 return neutron; 210 return neutron;
146 } 211 }
147 212
213 function mockGlance(openstack) {
214 const glance = new Glance(glanceMockData.config);
215 openstack._glancePromise = Promise.resolve(glance);
216 return glance;
217 }
218
148}); 219});