Skip to content

Commit 20bbd34

Browse files
committed
Merge pull request apache#1020 from bvbharatk/CLOUDSTACK-9016
CLOUDSTACK-9016 Fail to create VM instance within VPCbug link https://issues.apache.org/jira/browse/CLOUDSTACK-9016. CS doe not allocate the ip of the form x.x.x.1 to a guest VM. We seem to incorrectly assume that the first ip in the subnet belongs to the gateway. * pr/1020: CLOUDSTACK-9016: Deploy vm with gateway ip address in VPC CLOUDSTACK-9016 Fail to create VM instance within VPC Signed-off-by: Remi Bergsma <github@remi.nl>
2 parents 2cd789e + 7d1dc04 commit 20bbd34

2 files changed

Lines changed: 59 additions & 5 deletions

File tree

‎server/src/com/cloud/network/IpAddressManagerImpl.java‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,11 +1684,7 @@ public String acquireGuestIpAddress(Network network, String requestedIp) {
16841684
return requestedIp;
16851685
}
16861686

1687-
String result;
1688-
do {
1689-
result = NetUtils.long2Ip(array[_rand.nextInt(array.length)]);
1690-
} while (result.split("\\.")[3].equals("1"));
1691-
return result;
1687+
return NetUtils.long2Ip(array[_rand.nextInt(array.length)]);
16921688
}
16931689

16941690
Random _rand = new Random(System.currentTimeMillis());

‎test/integration/component/test_vpc.py‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,3 +2432,61 @@ def test_20_update_vpc_name_display_text(self):
24322432
self.assertEqual(vpc_networks[0].displaytext,
24332433
new_display_text,
24342434
"Updation of VPC display text failed.")
2435+
2436+
@attr(tags=["advanced", "intervlan"], required_hardware="false")
2437+
def test_21_deploy_vm_with_gateway_ip(self):
2438+
self.services["vpc"]["cidr"] = "192.168.1.0/24"
2439+
self.debug("creating a VPC network in the account: %s" %
2440+
self.account.name)
2441+
vpc = VPC.create(
2442+
self.apiclient,
2443+
self.services["vpc"],
2444+
vpcofferingid=self.vpc_off.id,
2445+
zoneid=self.zone.id,
2446+
account=self.account.name,
2447+
domainid=self.account.domainid
2448+
)
2449+
self.validate_vpc_network(vpc)
2450+
self.network_offering = NetworkOffering.create(
2451+
self.apiclient,
2452+
self.services["network_offering"],
2453+
conservemode=False
2454+
)
2455+
# Enable Network offering
2456+
self.network_offering.update(self.apiclient, state='Enabled')
2457+
self.cleanup.append(self.network_offering)
2458+
#Instead of first ip, assigning last ip in the CIDR as the gateway ip
2459+
gateway = "192.168.1.2"
2460+
self.services["network"]["netmask"] = "255.255.255.252"
2461+
# Split the cidr to retrieve gateway
2462+
# for eg. cidr = 10.0.0.1/24
2463+
# Gateway = 10.0.0.1
2464+
2465+
# Creating network using the network offering created
2466+
self.debug("Creating network with network offering: %s" %
2467+
self.network_offering.id)
2468+
network = Network.create(
2469+
self.apiclient,
2470+
self.services["network"],
2471+
accountid=self.account.name,
2472+
domainid=self.account.domainid,
2473+
networkofferingid=self.network_offering.id,
2474+
zoneid=self.zone.id,
2475+
gateway=gateway,
2476+
vpcid=vpc.id
2477+
)
2478+
self.debug("Created network with ID: %s" % network.id)
2479+
vm = VirtualMachine.create(
2480+
self.apiclient,
2481+
self.services["virtual_machine"],
2482+
accountid=self.account.name,
2483+
domainid=self.account.domainid,
2484+
serviceofferingid=self.service_offering.id,
2485+
networkids=[str(network.id)]
2486+
)
2487+
self.debug("Deployed VM in network: %s" % network.id)
2488+
self.assertIsNotNone(
2489+
vm,
2490+
"Failed to create VM with first ip address in the CIDR as the vm ip"
2491+
)
2492+
return

0 commit comments

Comments
 (0)