Browse Source

Added networkList() method to neutron API

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

Change-Id: Ie0878787169988253a93dd6d67b07a97bd005587
Corentin Ardeois 2 years ago
parent
commit
70a98fb10c
5 changed files with 122 additions and 1 deletions
  1. 14
    0
      src/neutron.js
  2. 13
    0
      test/functional/neutronTest.js
  3. 50
    1
      test/unit/helpers/data/neutron.js
  4. 41
    0
      test/unit/neutronTest.js
  5. 4
    0
      vagrant.sh

+ 14
- 0
src/neutron.js View File

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

+ 13
- 0
test/functional/neutronTest.js View File

@@ -80,4 +80,17 @@ describe("neutron", () => {
80 80
     });
81 81
   });
82 82
 
83
+  describe("networkList()", () => {
84
+    it("should return the networks as an array.", (done) => {
85
+      configPromise
86
+        .then((config) => new Neutron(config))
87
+        .then((neutron) => neutron.networkList(tokenPromise))
88
+        .then((networks) => {
89
+          expect(networks.length > 0).toBeTruthy();
90
+          done();
91
+        })
92
+        .catch((error) => done.fail(error));
93
+    });
94
+  });
95
+
83 96
 });

+ 50
- 1
test/unit/helpers/data/neutron.js View File

@@ -58,7 +58,56 @@ function rootResponse() {
58 58
   };
59 59
 }
60 60
 
61
+function networkList(token) {
62
+  return {
63
+    method: 'GET',
64
+    matcher: 'http://192.168.99.99:9696/v2.0/networks',
65
+    headers: {
66
+      'X-Auth-Token': token
67
+    },
68
+    response: {
69
+      networks: [
70
+        {
71
+          status: 'ACTIVE',
72
+          subnets: [
73
+            '54d6f61d-db07-451c-9ab3-b9609b6b6f0b'
74
+          ],
75
+          name: 'private-network',
76
+          'provider:physical_network': null,
77
+          admin_state_up: true,
78
+          tenant_id: '4fd44f30292945e481c7b8a0c8908869',
79
+          qos_policy_id: '6a8454ade84346f59e8d40665f878b2e',
80
+          'provider:network_type': 'local',
81
+          'router:external': true,
82
+          mtu: 0,
83
+          shared: true,
84
+          id: 'd32019d3-bc6e-4319-9c1d-6722fc136a22',
85
+          'provider:segmentation_id': null
86
+        },
87
+        {
88
+          status: 'ACTIVE',
89
+          subnets: [
90
+            '08eae331-0402-425a-923c-34f7cfe39c1b'
91
+          ],
92
+          name: 'private',
93
+          'provider:physical_network': null,
94
+          admin_state_up: true,
95
+          tenant_id: '26a7980765d0414dbc1fc1f88cdb7e6e',
96
+          qos_policy_id: 'bfdb6c39f71e4d44b1dfbda245c50819',
97
+          'provider:network_type': 'local',
98
+          'router:external': true,
99
+          mtu: 0,
100
+          shared: true,
101
+          id: 'db193ab3-96e3-4cb3-8fc5-05f4296d0324',
102
+          'provider:segmentation_id': null
103
+        }
104
+      ]
105
+    }
106
+  };
107
+}
108
+
61 109
 export {
62 110
   neutronConfig as config,
63
-  rootResponse as root
111
+  rootResponse as root,
112
+  networkList
64 113
 };

+ 41
- 0
test/unit/neutronTest.js View File

@@ -51,4 +51,45 @@ describe('neutron', () => {
51 51
         .catch((error) => done.fail(error));
52 52
     });
53 53
   });
54
+
55
+  describe("networkList()", () => {
56
+    let neutron = null;
57
+
58
+    beforeEach(() => {
59
+      fetchMock.mock(mockData.root());
60
+      neutron = new Neutron(mockData.config);
61
+    });
62
+
63
+    it("should return the networks as an array.", (done) => {
64
+      const token = 'test_token';
65
+
66
+      fetchMock.mock(mockData.networkList(token));
67
+      neutron
68
+        .networkList(token)
69
+        .then((networks) => {
70
+          expect(networks.length).toBe(2);
71
+          done();
72
+        })
73
+        .catch((error) => done.fail(error));
74
+    });
75
+
76
+    it("Should not cache its results", (done) => {
77
+      const token = 'test_token';
78
+
79
+      let mockOptions = mockData.networkList(token);
80
+      fetchMock.mock(mockOptions);
81
+
82
+      neutron
83
+        .networkList(token)
84
+        .then(() => {
85
+          expect(fetchMock.calls(mockOptions.matcher).length).toEqual(1);
86
+          return neutron.networkList(token);
87
+        })
88
+        .then(() => {
89
+          expect(fetchMock.calls(mockOptions.matcher).length).toEqual(2);
90
+          done();
91
+        })
92
+        .catch((error) => done.fail(error));
93
+    });
94
+  });
54 95
 });

+ 4
- 0
vagrant.sh View File

@@ -50,6 +50,10 @@ allowed_origin=http://localhost:9876
50 50
 [[post-config|\$GLANCE_API_CONF]]
51 51
 [cors]
52 52
 allowed_origin=http://localhost:9876
53
+
54
+[[post-config|\$NEUTRON_CONF]]
55
+[cors]
56
+allowed_origin=http://localhost:9876
53 57
 EOL
54 58
 
55 59
 # Start devstack.

Loading…
Cancel
Save