Skip to content

Commit b525255

Browse files
Netris VPN: Fix s2s vpn status update and isolated network implementation (#42)
* server: fix NPE when deploy vm on isolated network * vpn: fix s2s vpn status is not updated Prior to this fix ``` java.lang.IllegalArgumentException: Class com.cloud.agent.api.CheckS2SVpnConnectionsAnswer declares multiple JSON fields named 'details'; conflict is caused by fields com.cloud.agent.api.CheckS2SVpnConnectionsAnswer#details and com.cloud.agent.api.Answer#details at com.cloud.agent.transport.ResponseTest.testCheckS2SVpnConnectionsAnswer(ResponseTest.java:42) ``` * test: fix test_01_vpn_usage as now it is only possible to create VPN on Source NAT if it uses VR * VR: fix unable to create remote access VPN on regular isolated network the error is ``` File "/opt/cloud/bin/configure.py", line 1242, in process self.remoteaccessvpn_iptables(self.dbag['public_interface'], public_ip, self.dbag[public_ip]) ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^ KeyError: 'public_interface' ```
1 parent 610fd91 commit b525255

File tree

5 files changed

+59
-5
lines changed

5 files changed

+59
-5
lines changed

core/src/main/java/com/cloud/agent/api/CheckS2SVpnConnectionsAnswer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
public class CheckS2SVpnConnectionsAnswer extends Answer {
2626
Map<String, Boolean> ipToConnected;
2727
Map<String, String> ipToDetail;
28-
String details;
2928

3029
protected CheckS2SVpnConnectionsAnswer() {
3130
ipToConnected = new HashMap<String, Boolean>();
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.agent.transport;
21+
22+
import junit.framework.TestCase;
23+
24+
import org.apache.logging.log4j.Logger;
25+
import org.apache.logging.log4j.LogManager;
26+
import org.junit.Assert;
27+
import com.cloud.agent.api.Answer;
28+
import com.cloud.agent.api.CheckS2SVpnConnectionsAnswer;
29+
30+
import com.cloud.agent.transport.Request.Version;
31+
32+
public class ResponseTest extends TestCase {
33+
protected Logger logger = LogManager.getLogger(getClass());
34+
35+
public void testCheckS2SVpnConnectionsAnswer() {
36+
logger.info("Testing CheckS2SVpnConnectionsAnswer");
37+
String content = "[{\"com.cloud.agent.api.CheckS2SVpnConnectionsAnswer\":{\"ipToConnected\":{\"10.0.53.13\":true}," +
38+
"\"ipToDetail\":{\"10.0.53.13\":\"IPsec SA found;Site-to-site VPN have connected\"}," +
39+
"\"details\":\"10.0.53.13:0:IPsec SA found;Site-to-site VPN have connected\\u0026\\n\"," +
40+
"\"result\":true,\"contextMap\":{},\"wait\":0,\"bypassHostMaintenance\":false}}]";
41+
Response response = new Response(Version.v2, 1L, 2L, 3L, 1L, (short)1, content);
42+
Answer answer = response.getAnswer();
43+
Assert.assertTrue(answer instanceof CheckS2SVpnConnectionsAnswer);
44+
}
45+
46+
}

server/src/main/java/com/cloud/network/router/NetworkHelperImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,8 @@ public LinkedHashMap<Network, List<? extends NicProfile>> configureGuestNic(fina
780780
logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork);
781781
String defaultNetworkStartIp = null, defaultNetworkStartIpv6 = null;
782782
final Nic placeholder = _networkModel.getPlaceholderNicForRouter(guestNetwork, routerDeploymentDefinition.getPodId());
783-
if (!routerDeploymentDefinition.isPublicNetwork() || !vpcManager.isSrcNatIpRequiredForVpcVr(routerDeploymentDefinition.getVpc().getVpcOfferingId())) {
783+
if (!routerDeploymentDefinition.isPublicNetwork()
784+
|| !_networkModel.isAnyServiceSupportedInNetwork(guestNetwork.getId(), Network.Provider.VPCVirtualRouter, Network.Service.SourceNat, Network.Service.Gateway)) {
784785
if (guestNetwork.getCidr() != null) {
785786
if (placeholder != null && placeholder.getIPv4Address() != null) {
786787
logger.debug("Requesting ipv4 address " + placeholder.getIPv4Address() + " stored in placeholder nic for the network "

systemvm/debian/opt/cloud/bin/configure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ def process(self):
12391239
break
12401240
else:
12411241
self.configure_l2tpIpsec(public_ip, self.dbag[public_ip])
1242-
self.remoteaccessvpn_iptables(self.dbag['public_interface'], public_ip, self.dbag[public_ip])
1242+
self.remoteaccessvpn_iptables(self.dbag[public_ip]['public_interface'], public_ip, self.dbag[public_ip])
12431243

12441244
CsHelper.execute("ipsec update")
12451245
CsHelper.execute("systemctl start xl2tpd")

test/integration/smoke/test_usage.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,14 @@ def setUpClass(cls):
17321732
domainid=cls.virtual_machine.domainid,
17331733
services=cls.services["server"]
17341734
)
1735+
src_nat_list = PublicIPAddress.list(
1736+
cls.api_client,
1737+
accountid=cls.virtual_machine.account,
1738+
zoneid=cls.virtual_machine.zoneid,
1739+
domainid=cls.virtual_machine.domainid,
1740+
issourcenat=True
1741+
)
1742+
cls.public_ip = src_nat_list[0]
17351743
return
17361744

17371745
@classmethod
@@ -1770,11 +1778,11 @@ def test_01_vpn_usage(self):
17701778
# 4. Delete this account.
17711779

17721780
self.debug("Created VPN with public IP: %s" %
1773-
self.public_ip.ipaddress.id)
1781+
self.public_ip.ipaddress)
17741782
# Assign VPN to Public IP
17751783
vpn = Vpn.create(
17761784
self.apiclient,
1777-
self.public_ip.ipaddress.id,
1785+
self.public_ip.id,
17781786
account=self.account.name,
17791787
domainid=self.account.domainid
17801788
)

0 commit comments

Comments
 (0)