Skip to content

Commit f19cbc9

Browse files
Kashyap Jhajyothisaroja
authored andcommitted
Added Trunk API
Add listAllVolumes api
1 parent 44c7ae1 commit f19cbc9

35 files changed

+2040
-645
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ after_success:
3636
# infrastructure. This should prevent the buffer overflow from
3737
# https://github.com/travis-ci/travis-ci/issues/5227
3838
sudo: false
39+
dist: trusty
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
package org.openstack4j.api.network;
2+
3+
import static org.testng.Assert.assertEquals;
4+
import static org.testng.Assert.assertNotNull;
5+
import static org.testng.Assert.assertTrue;
6+
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
10+
import org.openstack4j.api.AbstractTest;
11+
import org.openstack4j.api.Builders;
12+
import org.openstack4j.model.common.ActionResponse;
13+
import org.openstack4j.model.network.Port;
14+
import org.openstack4j.model.network.SubPort;
15+
import org.openstack4j.model.network.Trunk;
16+
import org.openstack4j.openstack.networking.domain.NeutronSubPort;
17+
import org.testng.annotations.Test;
18+
19+
/**
20+
* Rewrote the entire API and so had to re-write tests
21+
*
22+
* @author Kashyap Jha
23+
*/
24+
@Test(suiteName = "Network")
25+
public class TrunkTests extends AbstractTest {
26+
27+
private static final String JSON_CREATE_TRUNK_RESPONSE = "/network/createTrunkResponse.json";
28+
private static final String JSON_ADD_SUBPORT_RESPONSE = "/network/addSubPortResponse.json";
29+
private static final String JSON_REMOVE_SUBPORT_RESPONSE = "/network/removeSubPortResponse.json";
30+
private static final String JSON_GET_TRUNK_RESPONSE = "/network/getTrunkResponse.json";
31+
private static final String JSON_UPDATE_TRUNK_RESPONSE = "/network/updateTrunkResponse.json";
32+
private static final String JSON_LIST_SUBPORTS_RESPONSE = "/network/listSubPortsResponse.json";
33+
private static final String JSON_LIST_TRUNKS_RESPONSE = "/network/listTrunksResponse.json";
34+
private static final String JSON_PORT_CREATE_RESPONSE = "/network/portCreateResponse.json";
35+
36+
@Override
37+
protected Service service() {
38+
return Service.NETWORK;
39+
}
40+
41+
@Test(enabled = true)
42+
public void createTrunk() throws Exception {
43+
respondWith(JSON_PORT_CREATE_RESPONSE);
44+
45+
String network1Id = "466e612-73a3-45df-96b6-4c084dfe1fc7";
46+
String port1Name = "port1";
47+
String trunk1Name = "trunk1";
48+
49+
Port toBuild = Builders.port().networkId(network1Id).name(port1Name).build();
50+
Port builtPort = osv3().networking().port().create(toBuild);
51+
52+
respondWith(JSON_CREATE_TRUNK_RESPONSE);
53+
Trunk builtTrunk = osv3.networking().trunk()
54+
.createTrunk(Builders.trunk().name(trunk1Name).parentPort(builtPort.getId()).build());
55+
56+
assertNotNull(builtTrunk);
57+
assertEquals(builtTrunk.getParentPort(), builtPort.getId());
58+
assertEquals(builtTrunk.getName(), trunk1Name);
59+
}
60+
61+
@Test(enabled = true)
62+
public void deleteTrunk() throws Exception {
63+
respondWith(204);
64+
String trunkId = "8a2ea42d-06b5-42c2-a54d-97105420f2bb";
65+
ActionResponse delete = osv3().networking().trunk().deleteTrunk(trunkId);
66+
assertTrue(delete.isSuccess());
67+
}
68+
69+
@Test(enabled = true)
70+
public void listTrunks() throws Exception {
71+
respondWith(JSON_LIST_TRUNKS_RESPONSE);
72+
73+
String trunk1Id = "cf15956d-4391-4ebf-a9cb-0f7e27b24073";
74+
String trunk2Id = "f98559e9-8e92-4100-96ac-a805e0340abd";
75+
List<String> trunkIds = new ArrayList<>();
76+
assertNotNull(trunkIds);
77+
for (Trunk t : osv3().networking().trunk().list()) {
78+
assertNotNull(t);
79+
trunkIds.add(t.getId());
80+
}
81+
assertTrue(trunkIds.contains(trunk1Id));
82+
assertTrue(trunkIds.contains(trunk2Id));
83+
}
84+
85+
@Test(enabled = true)
86+
public void updateTrunk() throws Exception {
87+
respondWith(JSON_UPDATE_TRUNK_RESPONSE);
88+
89+
String trunkId = "f98559e9-8e92-4100-96ac-a805e0340abd";
90+
String updatedName = "changedName";
91+
Trunk updatedTrunk = osv3().networking().trunk().updateTrunk(Builders.trunk().name(updatedName).build(),
92+
trunkId);
93+
assertNotNull(updatedTrunk);
94+
assertEquals(updatedTrunk.getName(), updatedName);
95+
assertEquals(updatedTrunk.getId(), trunkId);
96+
}
97+
98+
@Test(enabled = true)
99+
public void addSubPort() throws Exception {
100+
respondWith(JSON_ADD_SUBPORT_RESPONSE);
101+
102+
String trunkId = "f98559e9-8e92-4100-96ac-a805e0340abd";
103+
String subPortId = "9d30c4d8-3bb6-4b59-99ab-5eaa22e55037";
104+
int segmentationId = 101;
105+
String segmentationType = "vlan";
106+
SubPort subPort = NeutronSubPort.builder().portId(subPortId).segmentationId(segmentationId)
107+
.segmentationType("vlan").build();
108+
Trunk withSubPort = osv3().networking().trunk().addSubPort(trunkId, subPort);
109+
assertNotNull(withSubPort);
110+
assertEquals(subPortId, withSubPort.getSubPorts().get(0).getPortId());
111+
assertEquals(segmentationId, withSubPort.getSubPorts().get(0).getSegmentationId());
112+
assertEquals(segmentationType, withSubPort.getSubPorts().get(0).getSegmentationType());
113+
}
114+
115+
@Test(enabled = true)
116+
public void removeSubPort() throws Exception {
117+
respondWith(JSON_REMOVE_SUBPORT_RESPONSE);
118+
119+
String trunkId = "f98559e9-8e92-4100-96ac-a805e0340abd";
120+
String subPortId = "9d30c4d8-3bb6-4b59-99ab-5eaa22e55037";
121+
Trunk withoutSubport = osv3().networking().trunk().removeSubPort(trunkId, subPortId);
122+
assertNotNull(withoutSubport);
123+
assertTrue(withoutSubport.getSubPorts().isEmpty());
124+
}
125+
126+
@Test(enabled = true)
127+
public void listSubPorts() throws Exception {
128+
respondWith(JSON_LIST_SUBPORTS_RESPONSE);
129+
130+
String trunkId = "f98559e9-8e92-4100-96ac-a805e0340abd";
131+
List<String> ids = new ArrayList<>();
132+
List<NeutronSubPort> subPorts = osv3().networking().trunk().listSubPorts(trunkId);
133+
assertNotNull(subPorts);
134+
for (SubPort subPort : subPorts) {
135+
assertNotNull(subPort);
136+
ids.add(subPort.getId());
137+
}
138+
assertEquals(ids.size(), 2);
139+
}
140+
141+
@Test(enabled = true)
142+
public void getTrunk() throws Exception {
143+
respondWith(JSON_GET_TRUNK_RESPONSE);
144+
145+
String trunkId = "cf15956d-4391-4ebf-a9cb-0f7e27b24073";
146+
String portId = "e2d70799-b1e3-4737-9298-23cfb5c94416";
147+
Trunk trunk = osv3().networking().trunk().get(trunkId);
148+
assertNotNull(trunk);
149+
assertEquals(trunkId, trunk.getId());
150+
assertEquals(portId, trunk.getParentPort());
151+
}
152+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"status": "DOWN",
3+
"sub_ports": [{
4+
"segmentation_type": "vlan",
5+
"port_id": "9d30c4d8-3bb6-4b59-99ab-5eaa22e55037",
6+
"segmentation_id": 101
7+
}],
8+
"name": "changedName",
9+
"admin_state_up": true,
10+
"tenant_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
11+
"created_at": "2019-03-28T10:16:40Z",
12+
"tags": [],
13+
"updated_at": "2019-03-28T10:34:18Z",
14+
"revision_number": 2,
15+
"project_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
16+
"port_id": "e88917ca-039d-4758-ad0c-5e0e03dc75ae",
17+
"id": "f98559e9-8e92-4100-96ac-a805e0340abd",
18+
"description": ""
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"trunk":{
3+
"status":"DOWN",
4+
"sub_ports":[],
5+
"name":"trunk1",
6+
"admin_state_up":true,
7+
"tenant_id":"1b9ef7f7ec0c41ac83e3ea0df5257f60",
8+
"created_at":"2019-03-28T05:41:32Z",
9+
"tags":[],
10+
"updated_at":"2019-03-28T05:41:32Z",
11+
"revision_number":0,
12+
"project_id":"1b9ef7f7ec0c41ac83e3ea0df5257f60",
13+
"port_id":"0908f280-d0e8-45c6-acec-85714181ddb1",
14+
"id":"8fc625a7-d9a9-415f-83b3-87e9926990fd",
15+
"description":""
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"trunk": {
3+
"status": "DOWN",
4+
"sub_ports": [],
5+
"name": "t2",
6+
"admin_state_up": true,
7+
"tenant_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
8+
"created_at": "2019-03-28T10:16:50Z",
9+
"tags": [],
10+
"updated_at": "2019-03-28T10:16:50Z",
11+
"revision_number": 0,
12+
"project_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
13+
"port_id": "e2d70799-b1e3-4737-9298-23cfb5c94416",
14+
"id": "cf15956d-4391-4ebf-a9cb-0f7e27b24073",
15+
"description": ""
16+
}
17+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"sub_ports": [{
3+
"segmentation_type": "vlan",
4+
"port_id": "43f18cd3-10ce-44f3-9bc5-6e01d5e6f901",
5+
"segmentation_id": 101
6+
}, {
7+
"segmentation_type": "vlan",
8+
"port_id": "a5a2be85-d401-4bfc-a646-b4bbd3d1019e",
9+
"segmentation_id": 102
10+
}]
11+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"trunks": [{
3+
"status": "DOWN",
4+
"sub_ports": [],
5+
"name": "t2",
6+
"admin_state_up": true,
7+
"tenant_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
8+
"created_at": "2019-03-28T10:16:50Z",
9+
"tags": [],
10+
"updated_at": "2019-03-28T10:16:50Z",
11+
"revision_number": 0,
12+
"project_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
13+
"port_id": "e2d70799-b1e3-4737-9298-23cfb5c94416",
14+
"id": "cf15956d-4391-4ebf-a9cb-0f7e27b24073",
15+
"description": ""
16+
}, {
17+
"status": "DOWN",
18+
"sub_ports": [],
19+
"name": "t1",
20+
"admin_state_up": true,
21+
"tenant_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
22+
"created_at": "2019-03-28T10:16:40Z",
23+
"tags": [],
24+
"updated_at": "2019-03-28T10:16:40Z",
25+
"revision_number": 0,
26+
"project_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
27+
"port_id": "e88917ca-039d-4758-ad0c-5e0e03dc75ae",
28+
"id": "f98559e9-8e92-4100-96ac-a805e0340abd",
29+
"description": ""
30+
}]
31+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"port": {
3+
"allowed_address_pairs": [],
4+
"extra_dhcp_opts": [],
5+
"updated_at": "2019-03-28T11:39:07Z",
6+
"device_owner": "",
7+
"revision_number": 2,
8+
"binding:profile": {},
9+
"port_security_enabled": true,
10+
"fixed_ips": [],
11+
"id": "0908f280-d0e8-45c6-acec-85714181ddb1",
12+
"security_groups": ["942bf27c-1282-4ab8-8fdc-01518bf54e11"],
13+
"binding:vif_details": {},
14+
"binding:vif_type": "unbound",
15+
"mac_address": "fa:16:3e:05:ef:74",
16+
"project_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
17+
"status": "DOWN",
18+
"binding:host_id": "",
19+
"description": "",
20+
"tags": [],
21+
"device_id": "",
22+
"name": "port1",
23+
"admin_state_up": true,
24+
"network_id": "3466e612-73a3-45df-96b6-4c084dfe1fc7",
25+
"tenant_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
26+
"created_at": "2019-03-28T11:39:07Z",
27+
"binding:vnic_type": "normal"
28+
}
29+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"status": "DOWN",
3+
"sub_ports": [],
4+
"name": "changedName",
5+
"admin_state_up": true,
6+
"tenant_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
7+
"created_at": "2019-03-28T10:16:40Z",
8+
"tags": [],
9+
"updated_at": "2019-03-28T10:42:03Z",
10+
"revision_number": 3,
11+
"project_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
12+
"port_id": "e88917ca-039d-4758-ad0c-5e0e03dc75ae",
13+
"id": "f98559e9-8e92-4100-96ac-a805e0340abd",
14+
"description": ""
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"trunk": {
3+
"status": "DOWN",
4+
"sub_ports": [],
5+
"name": "changedName",
6+
"admin_state_up": true,
7+
"tenant_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
8+
"created_at": "2019-03-28T10:16:40Z",
9+
"tags": [],
10+
"updated_at": "2019-03-28T10:24:32Z",
11+
"revision_number": 1,
12+
"project_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
13+
"port_id": "e88917ca-039d-4758-ad0c-5e0e03dc75ae",
14+
"id": "f98559e9-8e92-4100-96ac-a805e0340abd",
15+
"description": ""
16+
}
17+
}

0 commit comments

Comments
 (0)