Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement listAllVolumes() #1285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ after_success:
# infrastructure. This should prevent the buffer overflow from
# https://github.com/travis-ci/travis-ci/issues/5227
sudo: false
dist: trusty
152 changes: 152 additions & 0 deletions core-test/src/main/java/org/openstack4j/api/network/TrunkTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package org.openstack4j.api.network;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

import java.util.ArrayList;
import java.util.List;

import org.openstack4j.api.AbstractTest;
import org.openstack4j.api.Builders;
import org.openstack4j.model.common.ActionResponse;
import org.openstack4j.model.network.Port;
import org.openstack4j.model.network.SubPort;
import org.openstack4j.model.network.Trunk;
import org.openstack4j.openstack.networking.domain.NeutronSubPort;
import org.testng.annotations.Test;

/**
* Rewrote the entire API and so had to re-write tests
*
* @author Kashyap Jha
*/
@Test(suiteName = "Network")
public class TrunkTests extends AbstractTest {

private static final String JSON_CREATE_TRUNK_RESPONSE = "/network/createTrunkResponse.json";
private static final String JSON_ADD_SUBPORT_RESPONSE = "/network/addSubPortResponse.json";
private static final String JSON_REMOVE_SUBPORT_RESPONSE = "/network/removeSubPortResponse.json";
private static final String JSON_GET_TRUNK_RESPONSE = "/network/getTrunkResponse.json";
private static final String JSON_UPDATE_TRUNK_RESPONSE = "/network/updateTrunkResponse.json";
private static final String JSON_LIST_SUBPORTS_RESPONSE = "/network/listSubPortsResponse.json";
private static final String JSON_LIST_TRUNKS_RESPONSE = "/network/listTrunksResponse.json";
private static final String JSON_PORT_CREATE_RESPONSE = "/network/portCreateResponse.json";

@Override
protected Service service() {
return Service.NETWORK;
}

@Test(enabled = true)
public void createTrunk() throws Exception {
respondWith(JSON_PORT_CREATE_RESPONSE);

String network1Id = "466e612-73a3-45df-96b6-4c084dfe1fc7";
String port1Name = "port1";
String trunk1Name = "trunk1";

Port toBuild = Builders.port().networkId(network1Id).name(port1Name).build();
Port builtPort = osv3().networking().port().create(toBuild);

respondWith(JSON_CREATE_TRUNK_RESPONSE);
Trunk builtTrunk = osv3.networking().trunk()
.createTrunk(Builders.trunk().name(trunk1Name).parentPort(builtPort.getId()).build());

assertNotNull(builtTrunk);
assertEquals(builtTrunk.getParentPort(), builtPort.getId());
assertEquals(builtTrunk.getName(), trunk1Name);
}

@Test(enabled = true)
public void deleteTrunk() throws Exception {
respondWith(204);
String trunkId = "8a2ea42d-06b5-42c2-a54d-97105420f2bb";
ActionResponse delete = osv3().networking().trunk().deleteTrunk(trunkId);
assertTrue(delete.isSuccess());
}

@Test(enabled = true)
public void listTrunks() throws Exception {
respondWith(JSON_LIST_TRUNKS_RESPONSE);

String trunk1Id = "cf15956d-4391-4ebf-a9cb-0f7e27b24073";
String trunk2Id = "f98559e9-8e92-4100-96ac-a805e0340abd";
List<String> trunkIds = new ArrayList<>();
assertNotNull(trunkIds);
for (Trunk t : osv3().networking().trunk().list()) {
assertNotNull(t);
trunkIds.add(t.getId());
}
assertTrue(trunkIds.contains(trunk1Id));
assertTrue(trunkIds.contains(trunk2Id));
}

@Test(enabled = true)
public void updateTrunk() throws Exception {
respondWith(JSON_UPDATE_TRUNK_RESPONSE);

String trunkId = "f98559e9-8e92-4100-96ac-a805e0340abd";
String updatedName = "changedName";
Trunk updatedTrunk = osv3().networking().trunk().updateTrunk(Builders.trunk().name(updatedName).build(),
trunkId);
assertNotNull(updatedTrunk);
assertEquals(updatedTrunk.getName(), updatedName);
assertEquals(updatedTrunk.getId(), trunkId);
}

@Test(enabled = true)
public void addSubPort() throws Exception {
respondWith(JSON_ADD_SUBPORT_RESPONSE);

String trunkId = "f98559e9-8e92-4100-96ac-a805e0340abd";
String subPortId = "9d30c4d8-3bb6-4b59-99ab-5eaa22e55037";
int segmentationId = 101;
String segmentationType = "vlan";
SubPort subPort = NeutronSubPort.builder().portId(subPortId).segmentationId(segmentationId)
.segmentationType("vlan").build();
Trunk withSubPort = osv3().networking().trunk().addSubPort(trunkId, subPort);
assertNotNull(withSubPort);
assertEquals(subPortId, withSubPort.getSubPorts().get(0).getPortId());
assertEquals(segmentationId, withSubPort.getSubPorts().get(0).getSegmentationId());
assertEquals(segmentationType, withSubPort.getSubPorts().get(0).getSegmentationType());
}

@Test(enabled = true)
public void removeSubPort() throws Exception {
respondWith(JSON_REMOVE_SUBPORT_RESPONSE);

String trunkId = "f98559e9-8e92-4100-96ac-a805e0340abd";
String subPortId = "9d30c4d8-3bb6-4b59-99ab-5eaa22e55037";
Trunk withoutSubport = osv3().networking().trunk().removeSubPort(trunkId, subPortId);
assertNotNull(withoutSubport);
assertTrue(withoutSubport.getSubPorts().isEmpty());
}

@Test(enabled = true)
public void listSubPorts() throws Exception {
respondWith(JSON_LIST_SUBPORTS_RESPONSE);

String trunkId = "f98559e9-8e92-4100-96ac-a805e0340abd";
List<String> ids = new ArrayList<>();
List<NeutronSubPort> subPorts = osv3().networking().trunk().listSubPorts(trunkId);
assertNotNull(subPorts);
for (SubPort subPort : subPorts) {
assertNotNull(subPort);
ids.add(subPort.getId());
}
assertEquals(ids.size(), 2);
}

@Test(enabled = true)
public void getTrunk() throws Exception {
respondWith(JSON_GET_TRUNK_RESPONSE);

String trunkId = "cf15956d-4391-4ebf-a9cb-0f7e27b24073";
String portId = "e2d70799-b1e3-4737-9298-23cfb5c94416";
Trunk trunk = osv3().networking().trunk().get(trunkId);
assertNotNull(trunk);
assertEquals(trunkId, trunk.getId());
assertEquals(portId, trunk.getParentPort());
}
}
19 changes: 19 additions & 0 deletions core-test/src/main/resources/network/addSubPortResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"status": "DOWN",
"sub_ports": [{
"segmentation_type": "vlan",
"port_id": "9d30c4d8-3bb6-4b59-99ab-5eaa22e55037",
"segmentation_id": 101
}],
"name": "changedName",
"admin_state_up": true,
"tenant_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
"created_at": "2019-03-28T10:16:40Z",
"tags": [],
"updated_at": "2019-03-28T10:34:18Z",
"revision_number": 2,
"project_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
"port_id": "e88917ca-039d-4758-ad0c-5e0e03dc75ae",
"id": "f98559e9-8e92-4100-96ac-a805e0340abd",
"description": ""
}
17 changes: 17 additions & 0 deletions core-test/src/main/resources/network/createTrunkResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"trunk":{
"status":"DOWN",
"sub_ports":[],
"name":"trunk1",
"admin_state_up":true,
"tenant_id":"1b9ef7f7ec0c41ac83e3ea0df5257f60",
"created_at":"2019-03-28T05:41:32Z",
"tags":[],
"updated_at":"2019-03-28T05:41:32Z",
"revision_number":0,
"project_id":"1b9ef7f7ec0c41ac83e3ea0df5257f60",
"port_id":"0908f280-d0e8-45c6-acec-85714181ddb1",
"id":"8fc625a7-d9a9-415f-83b3-87e9926990fd",
"description":""
}
}
17 changes: 17 additions & 0 deletions core-test/src/main/resources/network/getTrunkResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"trunk": {
"status": "DOWN",
"sub_ports": [],
"name": "t2",
"admin_state_up": true,
"tenant_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
"created_at": "2019-03-28T10:16:50Z",
"tags": [],
"updated_at": "2019-03-28T10:16:50Z",
"revision_number": 0,
"project_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
"port_id": "e2d70799-b1e3-4737-9298-23cfb5c94416",
"id": "cf15956d-4391-4ebf-a9cb-0f7e27b24073",
"description": ""
}
}
11 changes: 11 additions & 0 deletions core-test/src/main/resources/network/listSubPortsResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"sub_ports": [{
"segmentation_type": "vlan",
"port_id": "43f18cd3-10ce-44f3-9bc5-6e01d5e6f901",
"segmentation_id": 101
}, {
"segmentation_type": "vlan",
"port_id": "a5a2be85-d401-4bfc-a646-b4bbd3d1019e",
"segmentation_id": 102
}]
}
31 changes: 31 additions & 0 deletions core-test/src/main/resources/network/listTrunksResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"trunks": [{
"status": "DOWN",
"sub_ports": [],
"name": "t2",
"admin_state_up": true,
"tenant_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
"created_at": "2019-03-28T10:16:50Z",
"tags": [],
"updated_at": "2019-03-28T10:16:50Z",
"revision_number": 0,
"project_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
"port_id": "e2d70799-b1e3-4737-9298-23cfb5c94416",
"id": "cf15956d-4391-4ebf-a9cb-0f7e27b24073",
"description": ""
}, {
"status": "DOWN",
"sub_ports": [],
"name": "t1",
"admin_state_up": true,
"tenant_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
"created_at": "2019-03-28T10:16:40Z",
"tags": [],
"updated_at": "2019-03-28T10:16:40Z",
"revision_number": 0,
"project_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
"port_id": "e88917ca-039d-4758-ad0c-5e0e03dc75ae",
"id": "f98559e9-8e92-4100-96ac-a805e0340abd",
"description": ""
}]
}
29 changes: 29 additions & 0 deletions core-test/src/main/resources/network/portCreateResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"port": {
"allowed_address_pairs": [],
"extra_dhcp_opts": [],
"updated_at": "2019-03-28T11:39:07Z",
"device_owner": "",
"revision_number": 2,
"binding:profile": {},
"port_security_enabled": true,
"fixed_ips": [],
"id": "0908f280-d0e8-45c6-acec-85714181ddb1",
"security_groups": ["942bf27c-1282-4ab8-8fdc-01518bf54e11"],
"binding:vif_details": {},
"binding:vif_type": "unbound",
"mac_address": "fa:16:3e:05:ef:74",
"project_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
"status": "DOWN",
"binding:host_id": "",
"description": "",
"tags": [],
"device_id": "",
"name": "port1",
"admin_state_up": true,
"network_id": "3466e612-73a3-45df-96b6-4c084dfe1fc7",
"tenant_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
"created_at": "2019-03-28T11:39:07Z",
"binding:vnic_type": "normal"
}
}
15 changes: 15 additions & 0 deletions core-test/src/main/resources/network/removeSubPortResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"status": "DOWN",
"sub_ports": [],
"name": "changedName",
"admin_state_up": true,
"tenant_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
"created_at": "2019-03-28T10:16:40Z",
"tags": [],
"updated_at": "2019-03-28T10:42:03Z",
"revision_number": 3,
"project_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
"port_id": "e88917ca-039d-4758-ad0c-5e0e03dc75ae",
"id": "f98559e9-8e92-4100-96ac-a805e0340abd",
"description": ""
}
17 changes: 17 additions & 0 deletions core-test/src/main/resources/network/updateTrunkResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"trunk": {
"status": "DOWN",
"sub_ports": [],
"name": "changedName",
"admin_state_up": true,
"tenant_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
"created_at": "2019-03-28T10:16:40Z",
"tags": [],
"updated_at": "2019-03-28T10:24:32Z",
"revision_number": 1,
"project_id": "1b9ef7f7ec0c41ac83e3ea0df5257f60",
"port_id": "e88917ca-039d-4758-ad0c-5e0e03dc75ae",
"id": "f98559e9-8e92-4100-96ac-a805e0340abd",
"description": ""
}
}
9 changes: 9 additions & 0 deletions core/src/main/java/org/openstack4j/api/Builders.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,15 @@ public static PortBuilder port() {
return NeutronPort.builder();
}

/**
* The builder to create a Trunk
*
* @return the trunk builder
*/
public static TrunkBuilder trunk() {
return NeutronTrunk.builder();
}

/**
* The builder to create a Router
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/**
* OpenStack (Glance) Image V2 support
* @author emjburns
* @author zdagjyo - 2018-11-26 - Add method listCachedImages
*/
public interface ImageService extends RestService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* OpenStack Networking Operations API
*
*
* @author Jeremy Unruh
*/
public interface NetworkingService extends RestService {
Expand Down Expand Up @@ -55,14 +55,14 @@ public interface NetworkingService extends RestService {
* @return the network quota service
*/
NetQuotaService quotas();

/**
* @return the LBaaS service
*/
LoadBalancerService loadbalancers();

/**
*
*
* @return the Neutron agent API
*/
AgentService agent();
Expand All @@ -73,14 +73,22 @@ public interface NetworkingService extends RestService {
LbaasV2Service lbaasV2();

/**
* <p>OpenStack Firewall As a Service <code>(FwaaS) : Firewall</code> Operations API</p>
*
* <p>
* OpenStack Firewall As a Service <code>(FwaaS) : Firewall</code> Operations
* API
* </p>
*
* @return the FwaaS service
*/
FirewallAsService firewalls();

/**
* @return the Availability Zone Service API
*/
AvailabilityZoneService availabilityzone();

/**
* @return the Trunk API
*/
TrunkService trunk();
}
Loading