Skip to content

Commit 4dabd13

Browse files
committed
Merge pull request apache#1328 from borisroman/nullpointer_nicprofilehelperimpl
NicProfileHelperImpl NullpointerException when ipVO is nullWhen a VPC has a private gateway, and one would like to restart the VPC with **cleanup** it would fail. This PR adds a NullPointer check and verifies it with an integration test. ``` test_01_vpc_privategw_acl (integration.smoke.test_privategw_acl.TestPrivateGwACL) ... === TestName: test_01_vpc_privategw_acl | Status : SUCCESS === ok test_02_vpc_privategw_static_routes (integration.smoke.test_privategw_acl.TestPrivateGwACL) ... === TestName: test_02_vpc_privategw_static_routes | Status : SUCCESS === ok test_03_vpc_privategw_restart_vpc_cleanup (integration.smoke.test_privategw_acl.TestPrivateGwACL) ... === TestName: test_03_vpc_privategw_restart_vpc_cleanup | Status : SUCCESS === ok test_04_rvpc_privategw_static_routes (integration.smoke.test_privategw_acl.TestPrivateGwACL) ... === TestName: test_04_rvpc_privategw_static_routes | Status : SUCCESS === ok ---------------------------------------------------------------------- Ran 4 tests in 2945.055s OK ``` * pr/1328: Add integration test for restartVPC with cleanup, and Private Gateway enabled. Nullpointer Exception in NicProfileHelperImpl Signed-off-by: Remi Bergsma <github@remi.nl>
2 parents c13c554 + de11b73 commit 4dabd13

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

server/src/com/cloud/network/router/NicProfileHelperImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class NicProfileHelperImpl implements NicProfileHelper {
6363
@DB
6464
public NicProfile createPrivateNicProfileForGateway(final VpcGateway privateGateway, final VirtualRouter router) {
6565
final Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
66+
6667
PrivateIpVO ipVO = _privateIpDao.allocateIpAddress(privateNetwork.getDataCenterId(), privateNetwork.getId(), privateGateway.getIp4Address());
6768

6869
final Long vpcId = privateGateway.getVpcId();
@@ -71,7 +72,11 @@ public NicProfile createPrivateNicProfileForGateway(final VpcGateway privateGate
7172
ipVO = _privateIpDao.findByIpAndVpcId(vpcId, privateGateway.getIp4Address());
7273
}
7374

74-
final Nic privateNic = _nicDao.findByIp4AddressAndNetworkId(ipVO.getIpAddress(), privateNetwork.getId());
75+
Nic privateNic = null;
76+
77+
if (ipVO != null) {
78+
privateNic = _nicDao.findByIp4AddressAndNetworkId(ipVO.getIpAddress(), privateNetwork.getId());
79+
}
7580

7681
NicProfile privateNicProfile = new NicProfile();
7782

test/integration/smoke/test_privategw_acl.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,19 @@ def test_02_vpc_privategw_static_routes(self):
253253
self.performVPCTests(vpc_off)
254254

255255
@attr(tags=["advanced"], required_hardware="true")
256-
def test_03_rvpc_privategw_static_routes(self):
256+
def test_03_vpc_privategw_restart_vpc_cleanup(self):
257+
self.logger.debug("Creating a VPC offering..")
258+
vpc_off = VpcOffering.create(
259+
self.apiclient,
260+
self.services["vpc_offering"])
261+
262+
self.logger.debug("Enabling the VPC offering created")
263+
vpc_off.update(self.apiclient, state='Enabled')
264+
265+
self.performVPCTests(vpc_off, True)
266+
267+
@attr(tags=["advanced"], required_hardware="true")
268+
def test_04_rvpc_privategw_static_routes(self):
257269
self.logger.debug("Creating a Redundant VPC offering..")
258270
vpc_off = VpcOffering.create(
259271
self.apiclient,
@@ -264,7 +276,7 @@ def test_03_rvpc_privategw_static_routes(self):
264276

265277
self.performVPCTests(vpc_off)
266278

267-
def performVPCTests(self, vpc_off):
279+
def performVPCTests(self, vpc_off, restart_with_cleanup = False):
268280
self.logger.debug("Creating VPCs with offering ID %s" % vpc_off.id)
269281
vpc_1 = self.createVPC(vpc_off, cidr = '10.0.1.0/24')
270282
vpc_2 = self.createVPC(vpc_off, cidr = '10.0.2.0/24')
@@ -312,6 +324,13 @@ def performVPCTests(self, vpc_off):
312324
self.check_pvt_gw_connectivity(vm1, public_ip_1, vm2.nic[0].ipaddress)
313325
self.check_pvt_gw_connectivity(vm2, public_ip_2, vm1.nic[0].ipaddress)
314326

327+
if restart_with_cleanup:
328+
self.reboot_vpc_with_cleanup(vpc_1, True)
329+
self.reboot_vpc_with_cleanup(vpc_2, True)
330+
331+
self.check_pvt_gw_connectivity(vm1, public_ip_1, vm2.nic[0].ipaddress)
332+
self.check_pvt_gw_connectivity(vm2, public_ip_2, vm1.nic[0].ipaddress)
333+
315334
def createVPC(self, vpc_offering, cidr = '10.1.1.1/16'):
316335
try:
317336
self.logger.debug("Creating a VPC network in the account: %s" % self.account.name)
@@ -539,3 +558,14 @@ def check_pvt_gw_connectivity(self, virtual_machine, public_ip, vm_ip):
539558
1,
540559
"Ping to outside world from VM should be successful"
541560
)
561+
562+
def reboot_vpc_with_cleanup(self, vpc, cleanup = True):
563+
self.logger.debug("Restarting VPC %s with cleanup" % vpc.id)
564+
565+
# Reboot the router
566+
cmd = restartVPC.restartVPCCmd()
567+
cmd.id = vpc.id
568+
cmd.cleanup = cleanup
569+
cmd.makeredundant = False
570+
self.api_client.restartVPC(cmd)
571+

0 commit comments

Comments
 (0)