Skip to content

Commit 719db04

Browse files
authored
Merge pull request #1081 from Grim-lock/master
Added API for Octavia
2 parents 6287f9d + d61cafb commit 719db04

File tree

98 files changed

+6390
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+6390
-0
lines changed

core-test/src/main/java/org/openstack4j/api/AbstractTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public abstract class AbstractTest {
3838
protected enum Service {
3939
IDENTITY(5000),
4040
NETWORK(9696),
41+
OCTAVIA(9876),
4142
COMPUTE(8774),
4243
BLOCK_STORAGE(8776),
4344
METERING(8087),
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package org.openstack4j.api.octavia;
2+
3+
import org.openstack4j.api.AbstractTest;
4+
import org.openstack4j.api.Builders;
5+
import org.openstack4j.model.common.ActionResponse;
6+
import org.openstack4j.model.octavia.HealthMonitorType;
7+
import org.openstack4j.model.octavia.HealthMonitorV2;
8+
import org.openstack4j.model.octavia.HealthMonitorV2Update;
9+
import org.testng.annotations.Test;
10+
11+
import java.io.IOException;
12+
import java.util.HashMap;
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
import static org.testng.Assert.assertEquals;
17+
import static org.testng.Assert.assertNotNull;
18+
import static org.testng.Assert.assertTrue;
19+
20+
/**
21+
*
22+
* @author wei
23+
*
24+
*/
25+
@Test(suiteName="Octavia/healthMonitor", enabled = true)
26+
public class HealthMonitorV2Tests extends AbstractTest {
27+
private static final String HEALTHMONITORSV2_JSON = "/octavia/healthmonitorsv2.json";
28+
private static final String HEALTHMONITORV2_JSON = "/octavia/healthmonitorv2.json";
29+
private static final String HEALTHMONITORV2_UPDATE_JSON = "/octavia/healthmonitorv2_update.json";
30+
31+
public void testListHealthMonitorsV2() throws IOException {
32+
respondWith(HEALTHMONITORSV2_JSON);
33+
List<? extends HealthMonitorV2> list = osv3().octavia().healthMonitorV2().list();
34+
assertEquals(list.size(), 3);
35+
assertEquals("350576d8-5015-4d4e-b73f-23df2397e4c4", list.get(0).getId());
36+
}
37+
38+
public void testListHealthMonitorsV2Filter() throws IOException {
39+
respondWith(HEALTHMONITORSV2_JSON);
40+
Map<String, String> map = new HashMap<>();
41+
map.put("project_id", "6f759d84e3ca496ab77f8c0ffaa0311e");
42+
List<? extends HealthMonitorV2> list = osv3().octavia().healthMonitorV2().list(map);
43+
assertEquals(list.size(), 3);
44+
}
45+
46+
public void testGetHealthMonitorV2() throws IOException {
47+
respondWith(HEALTHMONITORV2_JSON);
48+
String id = "350576d8-5015-4d4e-b73f-23df2397e4c4";
49+
HealthMonitorV2 hm = osv3().octavia().healthMonitorV2().get(id);
50+
assertNotNull(hm);
51+
assertEquals(hm.getId(), id);
52+
}
53+
54+
public void testCreateHealthMonitorV2() throws IOException {
55+
respondWith(HEALTHMONITORV2_JSON);
56+
Integer delay = 2;
57+
Integer timeout = 3;
58+
HealthMonitorType type = HealthMonitorType.HTTP;
59+
HealthMonitorV2 create = Builders.octavia().healthMonitorV2()
60+
.adminStateUp(true)
61+
.delay(delay)
62+
.type(type)
63+
.timeout(timeout)
64+
.build();
65+
HealthMonitorV2 result = osv3().octavia().healthMonitorV2().create(create);
66+
assertEquals(result.getDelay(), delay);
67+
assertEquals(result.getTimeout(), timeout);
68+
assertEquals(result.getType(), type);
69+
assertTrue(result.isAdminStateUp());
70+
}
71+
72+
public void testUpdateHealthMonitorV2() throws IOException {
73+
respondWith(HEALTHMONITORV2_UPDATE_JSON);
74+
Integer delay = 10;
75+
Integer timeout = 5;
76+
String id = "350576d8-5015-4d4e-b73f-23df2397e4c4";
77+
HealthMonitorV2Update update = Builders.octavia().healthMonitorV2Update()
78+
.delay(delay)
79+
.timeout(timeout)
80+
.build();
81+
HealthMonitorV2 result = osv3().octavia().healthMonitorV2().update(id, update);
82+
assertEquals(result.getDelay(), delay);
83+
assertEquals(result.getTimeout(), timeout);
84+
}
85+
86+
public void testDeleteHealthMonitorV2() {
87+
respondWith(204);
88+
ActionResponse result = osv3().octavia().healthMonitorV2().delete("350576d8-5015-4d4e-b73f-23df2397e4c4");
89+
assertTrue(result.isSuccess());
90+
}
91+
92+
@Override
93+
protected Service service() {
94+
return Service.OCTAVIA;
95+
}
96+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package org.openstack4j.api.octavia;
2+
3+
import org.openstack4j.api.AbstractTest;
4+
import org.openstack4j.api.Builders;
5+
import org.openstack4j.model.common.ActionResponse;
6+
import org.openstack4j.model.octavia.LbMethod;
7+
import org.openstack4j.model.octavia.LbPoolV2;
8+
import org.openstack4j.model.octavia.LbPoolV2Update;
9+
import org.openstack4j.model.octavia.Protocol;
10+
import org.testng.annotations.Test;
11+
12+
import java.io.IOException;
13+
import java.util.HashMap;
14+
import java.util.List;
15+
import java.util.Map;
16+
17+
import static org.testng.Assert.assertEquals;
18+
import static org.testng.Assert.assertFalse;
19+
import static org.testng.Assert.assertNotNull;
20+
import static org.testng.Assert.assertTrue;
21+
22+
/**
23+
*
24+
* @author wei
25+
*
26+
*/
27+
@Test(suiteName="Octavia/lbpoolv2", enabled=true)
28+
public class LbPoolV2Tests extends AbstractTest {
29+
private static final String LBPOOLSV2_JSON = "/octavia/lbpoolsv2.json";
30+
private static final String LBPOOLV2_JSON = "/octavia/lbpoolv2.json";
31+
private static final String LBPOOLV2_UPDATE_JSON = "/octavia/lbpoolv2_update.json";
32+
33+
public void testListPoolV2() throws IOException {
34+
respondWith(LBPOOLSV2_JSON);
35+
List<? extends LbPoolV2> list = osv3().octavia().lbPoolV2().list();
36+
assertEquals(list.size(), 2);
37+
assertEquals(list.get(0).getId(), "b7f6a49f-ebd8-43c5-b792-5748366eff21");
38+
}
39+
40+
public void testListPoolV2Filter() throws IOException {
41+
respondWith(LBPOOLSV2_JSON);
42+
Map<String, String> map = new HashMap<String, String>();
43+
map.put("protocol", "HTTP");
44+
List<? extends LbPoolV2> list = osv3().octavia().lbPoolV2().list(map);
45+
assertEquals(list.size(), 2);
46+
}
47+
48+
public void testGetPoolV2() throws IOException {
49+
respondWith(LBPOOLV2_JSON);
50+
String id = "b7f6a49f-ebd8-43c5-b792-5748366eff21";
51+
LbPoolV2 pool = osv3().octavia().lbPoolV2().get(id);
52+
assertNotNull(pool);
53+
assertEquals(pool.getId(), id);
54+
}
55+
56+
public void testCreatePoolV2() throws IOException {
57+
respondWith(LBPOOLV2_JSON);
58+
String name = "testlbpool";
59+
Protocol protocol = Protocol.HTTP;
60+
String projectId = "6f759d84e3ca496ab77f8c0ffaa0311e";
61+
LbPoolV2 create = Builders.octavia().lbPoolV2()
62+
.adminStateUp(true)
63+
.description("im a swimming pool")
64+
.lbMethod(LbMethod.LEAST_CONNECTIONS)
65+
.name(name)
66+
.projectId(projectId)
67+
.protocol(protocol)
68+
.build();
69+
LbPoolV2 result = osv3().octavia().lbPoolV2().create(create);
70+
assertEquals(result.getName(), name);
71+
assertEquals(result.getLbMethod(), LbMethod.LEAST_CONNECTIONS);
72+
assertEquals(result.getProtocol(), protocol);
73+
assertEquals(result.getProjectId(), projectId);
74+
}
75+
76+
public void testUpdatePoolV2() throws IOException {
77+
respondWith(LBPOOLV2_UPDATE_JSON);
78+
String poolId = "b7f6a49f-ebd8-43c5-b792-5748366eff21";
79+
String name = "v2update";
80+
LbPoolV2Update update = Builders.octavia().lbPoolV2Update()
81+
.adminStateUp(false)
82+
.description("im a carpool")
83+
.lbMethod(LbMethod.ROUND_ROBIN)
84+
.name(name)
85+
.build();
86+
LbPoolV2 result = osv3().octavia().lbPoolV2().update(poolId, update);
87+
assertEquals(result.getName(), name);
88+
assertEquals(result.getLbMethod(), LbMethod.ROUND_ROBIN);
89+
assertFalse(result.isAdminStateUp());
90+
}
91+
92+
public void testDeletePoolV2() {
93+
respondWith(204);
94+
ActionResponse result = osv3().octavia().lbPoolV2().delete("b7f6a49f-ebd8-43c5-b792-5748366eff21");
95+
assertTrue(result.isSuccess());
96+
}
97+
98+
@Override
99+
protected Service service() {
100+
return Service.OCTAVIA;
101+
}
102+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package org.openstack4j.api.octavia;
2+
3+
4+
import org.openstack4j.api.AbstractTest;
5+
import org.openstack4j.api.Builders;
6+
import org.openstack4j.model.common.ActionResponse;
7+
import org.openstack4j.model.octavia.ListenerV2;
8+
import org.openstack4j.model.octavia.ListenerV2Update;
9+
import org.openstack4j.model.octavia.ListenerProtocol;
10+
import org.testng.annotations.Test;
11+
12+
import java.io.IOException;
13+
import java.util.HashMap;
14+
import java.util.List;
15+
import java.util.Map;
16+
17+
import static org.testng.Assert.assertEquals;
18+
import static org.testng.Assert.assertFalse;
19+
import static org.testng.Assert.assertNotNull;
20+
import static org.testng.Assert.assertTrue;
21+
22+
/**
23+
*
24+
* @author wei
25+
*
26+
*/
27+
@Test(suiteName="Octavia/listener", enabled = true)
28+
public class ListenerV2Tests extends AbstractTest {
29+
private static final String LISTENERSV2_JSON = "/octavia/listenersv2.json";
30+
private static final String LISTENERV2_JSON = "/octavia/listenerv2.json";
31+
private static final String LISTENERV2_UPDATE_JSON = "/octavia/listenerv2_update.json";
32+
33+
public void testListListenersV2() throws IOException {
34+
respondWith(LISTENERSV2_JSON);
35+
List<? extends ListenerV2> list = osv3().octavia().listenerV2().list();
36+
assertEquals(list.size(), 2);
37+
assertEquals(list.get(0).getName(), "listener1");
38+
}
39+
40+
public void testListListenersV2Filter() throws IOException {
41+
respondWith(LISTENERSV2_JSON);
42+
Map<String, String> map = new HashMap<>();
43+
map.put("tenantId", "6f759d84e3ca496ab77f8c0ffaa0311e");
44+
List<? extends ListenerV2> list = osv3().octavia().listenerV2().list(map);
45+
assertEquals(list.size(), 2);
46+
}
47+
48+
public void testGetListenerV2() throws IOException {
49+
respondWith(LISTENERV2_JSON);
50+
String id = "c07058a9-8d84-4443-b8f5-508d0facfe10";
51+
ListenerV2 listener = osv3().octavia().listenerV2().get(id);
52+
assertNotNull(listener);
53+
assertEquals(listener.getId(), id);
54+
}
55+
56+
public void testCreateListenerV2() throws IOException {
57+
respondWith(LISTENERV2_JSON);
58+
String name = "listener1";
59+
String description = "";
60+
ListenerProtocol protocol = ListenerProtocol.HTTP;
61+
String tlsContainerRef = "http://0.0.0.0:9311/v1/containers/52594300-d996-49e4-8bf1-a4e000171ad8";
62+
ListenerV2 create = Builders.octavia().listenerV2()
63+
.adminStateUp(true)
64+
.name(name)
65+
.description(description)
66+
.protocol(protocol)
67+
.defaultTlsContainerRef(tlsContainerRef)
68+
.build();
69+
ListenerV2 result = osv3().octavia().listenerV2().create(create);
70+
assertEquals(result.getName(), name);
71+
assertEquals(result.getDescription(), description);
72+
assertEquals(result.getProtocol(), protocol);
73+
assertEquals(result.getDefaultTlsContainerRef(), tlsContainerRef);
74+
assertTrue(result.isAdminStateUp());
75+
}
76+
77+
public void testUpdateListenerV2() throws IOException {
78+
respondWith(LISTENERV2_UPDATE_JSON);
79+
String name = "listener_updated";
80+
String description = "im a good listener";
81+
Integer connectionLimit = 20;
82+
String tlsContainerRef = "http://0.0.0.0:9311/v1/containers/52594300-d996-49e4-8bf1-a4e000171ad9";
83+
ListenerV2Update update = Builders.octavia().listenerV2Update()
84+
.adminStateUp(false)
85+
.description(description)
86+
.name(name)
87+
.connectionLimit(connectionLimit)
88+
.defaultTlsContainerRef(tlsContainerRef)
89+
.build();
90+
ListenerV2 result = osv3().octavia().listenerV2().update("c07058a9-8d84-4443-b8f5-508d0facfe10", update);
91+
assertFalse(result.isAdminStateUp());
92+
assertEquals(result.getName(), name);
93+
assertEquals(result.getDescription(), description);
94+
assertEquals(result.getConnectionLimit(), connectionLimit);
95+
assertEquals(result.getDefaultTlsContainerRef(), tlsContainerRef);
96+
97+
}
98+
99+
public void testDeleteListenerV2() {
100+
respondWith(204);
101+
ActionResponse result = osv3().octavia().listenerV2().delete("c07058a9-8d84-4443-b8f5-508d0facfe10");
102+
assertTrue(result.isSuccess());
103+
}
104+
105+
@Override
106+
protected Service service() {
107+
return Service.OCTAVIA;
108+
}
109+
}

0 commit comments

Comments
 (0)