Skip to content

Commit 80a6961

Browse files
bwswyadvr
authored andcommitted
CLOUDSTACK-10168: VR duplicate entries in /etc/hosts when reusing VM name (#2366)
Bug is fixed. Fixed typo 'adress' to 'address' everywhere which leads to correct generation for agent communication json dhcp command.
1 parent 044636c commit 80a6961

File tree

12 files changed

+56
-51
lines changed

12 files changed

+56
-51
lines changed

api/src/com/cloud/offering/ServiceOffering.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public interface ServiceOffering extends DiskOffering, InfrastructureEntity, Int
3131
public static final String routerDefaultOffUniqueName = "Cloud.Com-SoftwareRouter";
3232
public static final String elbVmDefaultOffUniqueName = "Cloud.Com-ElasticLBVm";
3333
public static final String internalLbVmDefaultOffUniqueName = "Cloud.Com-InternalLBVm";
34-
// leaving cloud.com references as these are identifyers and no real world adresses (check against DB)
34+
// leaving cloud.com references as these are identifyers and no real world addresses (check against DB)
3535

3636
public enum StorageType {
3737
local, shared

core/src/com/cloud/agent/resource/virtualnetwork/model/VmDhcpConfig.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
public class VmDhcpConfig extends ConfigBase {
2323
private String hostName;
2424
private String macAddress;
25-
private String ipv4Adress;
25+
private String ipv4Address;
2626
private String ipv6Address;
2727
private String ipv6Duid;
28-
private String dnsAdresses;
28+
private String dnsAddresses;
2929
private String defaultGateway;
3030
private String staticRoutes;
3131
private boolean defaultEntry;
@@ -34,15 +34,15 @@ public VmDhcpConfig() {
3434
super(VM_DHCP);
3535
}
3636

37-
public VmDhcpConfig(String hostName, String macAddress, String ipv4Adress, String ipv6Address, String ipv6Duid, String dnsAdresses, String defaultGateway,
37+
public VmDhcpConfig(String hostName, String macAddress, String ipv4Address, String ipv6Address, String ipv6Duid, String dnsAddresses, String defaultGateway,
3838
String staticRoutes, boolean defaultEntry) {
3939
super(VM_DHCP);
4040
this.hostName = hostName;
4141
this.macAddress = macAddress;
42-
this.ipv4Adress = ipv4Adress;
42+
this.ipv4Address = ipv4Address;
4343
this.ipv6Address = ipv6Address;
4444
this.ipv6Duid = ipv6Duid;
45-
this.dnsAdresses = dnsAdresses;
45+
this.dnsAddresses = dnsAddresses;
4646
this.defaultGateway = defaultGateway;
4747
this.staticRoutes = staticRoutes;
4848
this.defaultEntry = defaultEntry;
@@ -64,12 +64,12 @@ public void setMacAddress(String macAddress) {
6464
this.macAddress = macAddress;
6565
}
6666

67-
public String getIpv4Adress() {
68-
return ipv4Adress;
67+
public String getIpv4Address() {
68+
return ipv4Address;
6969
}
7070

71-
public void setIpv4Adress(String ipv4Adress) {
72-
this.ipv4Adress = ipv4Adress;
71+
public void setIpv4Address(String ipv4Address) {
72+
this.ipv4Address = ipv4Address;
7373
}
7474

7575
public String getIpv6Address() {
@@ -88,12 +88,12 @@ public void setIpv6Duid(String ipv6Duid) {
8888
this.ipv6Duid = ipv6Duid;
8989
}
9090

91-
public String getDnsAdresses() {
92-
return dnsAdresses;
91+
public String getDnsAddresses() {
92+
return dnsAddresses;
9393
}
9494

95-
public void setDnsAdresses(String dnsAdresses) {
96-
this.dnsAdresses = dnsAdresses;
95+
public void setDnsAddresses(String dnsAddresses) {
96+
this.dnsAddresses = dnsAddresses;
9797
}
9898

9999
public String getDefaultGateway() {

engine/schema/src/com/cloud/upgrade/dao/Upgrade218to22.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,13 @@ protected void upgradeDirectUserIpAddress(Connection conn, long dcId, long netwo
641641
s_logger.debug("Marking " + allocatedIps.size() + " ip addresses to belong to network " + networkId);
642642
s_logger.debug("Updating mac addresses for data center id=" + dcId + ". Found " + allocatedIps.size() + " ip addresses to update");
643643
for (Object[] allocatedIp : allocatedIps) {
644-
try (PreparedStatement selectMacAdresses = conn.prepareStatement("SELECT mac_address FROM data_center WHERE id = ?");) {
645-
selectMacAdresses.setLong(1, dcId);
646-
try (ResultSet selectedMacAdresses = selectMacAdresses.executeQuery();) {
647-
if (!selectedMacAdresses.next()) {
644+
try (PreparedStatement selectMacAddresses = conn.prepareStatement("SELECT mac_address FROM data_center WHERE id = ?");) {
645+
selectMacAddresses.setLong(1, dcId);
646+
try (ResultSet selectedMacAddresses = selectMacAddresses.executeQuery();) {
647+
if (!selectedMacAddresses.next()) {
648648
throw new CloudRuntimeException("Unable to get mac address for data center " + dcId);
649649
}
650-
long mac = selectedMacAdresses.getLong(1);
650+
long mac = selectedMacAddresses.getLong(1);
651651
try (PreparedStatement updateDataCenter = conn.prepareStatement("UPDATE data_center SET mac_address=mac_address+1 WHERE id = ?");) {
652652
updateDataCenter.setLong(1, dcId);
653653
updateDataCenter.executeUpdate();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ public PublicIp fetchNewPublicIp(final long dcId, final Long podId, final List<L
694694
IPAddressVO addr = Transaction.execute(new TransactionCallbackWithException<IPAddressVO, InsufficientAddressCapacityException>() {
695695
@Override
696696
public IPAddressVO doInTransaction(TransactionStatus status) throws InsufficientAddressCapacityException {
697-
StringBuilder errorMessage = new StringBuilder("Unable to get ip adress in ");
697+
StringBuilder errorMessage = new StringBuilder("Unable to get ip address in ");
698698
boolean fetchFromDedicatedRange = false;
699699
List<Long> dedicatedVlanDbIds = new ArrayList<Long>();
700700
List<Long> nonDedicatedVlanDbIds = new ArrayList<Long>();

server/src/com/cloud/network/vpc/VpcManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ public VpcGatewayVO doInTransaction(final TransactionStatus status) throws Resou
16421642
final Long nextMac = mac + 1;
16431643
dc.setMacAddress(nextMac);
16441644

1645-
s_logger.info("creating private ip adress for vpc (" + ipAddress + ", " + privateNtwk.getId() + ", " + nextMac + ", " + vpcId + ", " + isSourceNat + ")");
1645+
s_logger.info("creating private ip address for vpc (" + ipAddress + ", " + privateNtwk.getId() + ", " + nextMac + ", " + vpcId + ", " + isSourceNat + ")");
16461646
privateIp = new PrivateIpVO(ipAddress, privateNtwk.getId(), nextMac, vpcId, isSourceNat);
16471647
_privateIpDao.persist(privateIp);
16481648

server/test/com/cloud/configuration/ConfigurationManagerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public void testDedicatePublicIpRange() throws Exception {
247247
/*
248248
* TEST 5: given range is already allocated to a different account DedicatePublicIpRange should fail
249249
*/
250-
runDedicatePublicIpRangeIPAdressAllocated();
250+
runDedicatePublicIpRangeIPAddressAllocated();
251251
}
252252

253253
@Test
@@ -373,8 +373,8 @@ void runDedicatePublicIpRangeInvalidZone() throws Exception {
373373
}
374374
}
375375

376-
void runDedicatePublicIpRangeIPAdressAllocated() throws Exception {
377-
TransactionLegacy txn = TransactionLegacy.open("runDedicatePublicIpRangeIPAdressAllocated");
376+
void runDedicatePublicIpRangeIPAddressAllocated() throws Exception {
377+
TransactionLegacy txn = TransactionLegacy.open("runDedicatePublicIpRangeIPAddressAllocated");
378378

379379
when(configurationMgr._vlanDao.findById(anyLong())).thenReturn(vlan);
380380

@@ -397,7 +397,7 @@ void runDedicatePublicIpRangeIPAdressAllocated() throws Exception {
397397
} catch (Exception e) {
398398
Assert.assertTrue(e.getMessage().contains("Public IP address in range is allocated to another account"));
399399
} finally {
400-
txn.close("runDedicatePublicIpRangeIPAdressAllocated");
400+
txn.close("runDedicatePublicIpRangeIPAddressAllocated");
401401
}
402402
}
403403

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ def main(argv):
972972
level=config.get_level(),
973973
format=config.get_format())
974974
try:
975-
# Load stored ip adresses from disk to CsConfig()
975+
# Load stored ip addresses from disk to CsConfig()
976976
config.set_address()
977977

978978
logging.debug("Configuring ip addresses")

systemvm/patches/debian/config/opt/cloud/bin/cs/CsDhcp.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,35 +130,35 @@ def write_hosts(self):
130130
logging.debug("Hosts file unchanged")
131131

132132
def add(self, entry):
133-
self.add_host(entry['ipv4_adress'], entry['host_name'])
133+
self.add_host(entry['ipv4_address'], entry['host_name'])
134134
# lease time boils down to once a month
135135
# with a splay of 60 hours to prevent storms
136136
lease = randint(700, 760)
137137

138138
if entry['default_entry'] == True:
139139
self.cloud.add("%s,%s,%s,%sh" % (entry['mac_address'],
140-
entry['ipv4_adress'],
140+
entry['ipv4_address'],
141141
entry['host_name'],
142142
lease))
143143
else:
144-
tag = entry['ipv4_adress'].replace(".","_")
144+
tag = entry['ipv4_address'].replace(".","_")
145145
self.cloud.add("%s,set:%s,%s,%s,%sh" % (entry['mac_address'],
146146
tag,
147-
entry['ipv4_adress'],
147+
entry['ipv4_address'],
148148
entry['host_name'],
149149
lease))
150150
self.dhcp_opts.add("%s,%s" % (tag, 3))
151151
self.dhcp_opts.add("%s,%s" % (tag, 6))
152152
self.dhcp_opts.add("%s,%s" % (tag, 15))
153153

154-
i = IPAddress(entry['ipv4_adress'])
154+
i = IPAddress(entry['ipv4_address'])
155155
# Calculate the device
156156
for v in self.devinfo:
157157
if i > v['network'].network and i < v['network'].broadcast:
158158
v['dnsmasq'] = True
159159
# Virtual Router
160160
v['gateway'] = entry['default_gateway']
161161

162-
163162
def add_host(self, ip, hosts):
164163
self.hosts[ip] = hosts
164+

systemvm/patches/debian/config/opt/cloud/bin/cs_dhcp.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,22 @@
1818
from pprint import pprint
1919
from netaddr import *
2020

21-
2221
def merge(dbag, data):
23-
2422
# A duplicate ip address wil clobber the old value
2523
# This seems desirable ....
26-
if "add" in data and data['add'] is False and \
27-
"ipv4_adress" in data:
28-
if data['ipv4_adress'] in dbag:
29-
del(dbag[data['ipv4_adress']])
30-
return dbag
24+
if "add" in data and data['add'] is False and "ipv4_address" in data:
25+
if data['ipv4_address'] in dbag:
26+
del(dbag[data['ipv4_address']])
3127
else:
32-
dbag[data['ipv4_adress']] = data
33-
return dbag
28+
remove_key = None
29+
for key, entry in dbag.iteritems():
30+
if key != 'id' and entry['host_name'] == data['host_name']:
31+
remove_key = key
32+
break
33+
if remove_key is not None:
34+
del(dbag[remove_key])
35+
36+
dbag[data['ipv4_address']] = data
3437

38+
return dbag
39+

systemvm/patches/debian/config/opt/cloud/testdata/dhcp0001.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"host_name":"VM-58976c22-0832-451e-9ab2-039e9f27e415",
33
"mac_address":"02:00:26:c3:00:02",
4-
"ipv4_adress":"172.16.1.102",
4+
"ipv4_address":"172.16.1.102",
55
"ipv6_duid":"00:03:00:01:02:00:26:c3:00:02",
66
"default_gateway":"172.16.1.1",
77
"default_entry":true,

0 commit comments

Comments
 (0)