mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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.
This commit is contained in:
parent
044636ca87
commit
80a6961b5d
@ -31,7 +31,7 @@ public interface ServiceOffering extends DiskOffering, InfrastructureEntity, Int
|
|||||||
public static final String routerDefaultOffUniqueName = "Cloud.Com-SoftwareRouter";
|
public static final String routerDefaultOffUniqueName = "Cloud.Com-SoftwareRouter";
|
||||||
public static final String elbVmDefaultOffUniqueName = "Cloud.Com-ElasticLBVm";
|
public static final String elbVmDefaultOffUniqueName = "Cloud.Com-ElasticLBVm";
|
||||||
public static final String internalLbVmDefaultOffUniqueName = "Cloud.Com-InternalLBVm";
|
public static final String internalLbVmDefaultOffUniqueName = "Cloud.Com-InternalLBVm";
|
||||||
// leaving cloud.com references as these are identifyers and no real world adresses (check against DB)
|
// leaving cloud.com references as these are identifyers and no real world addresses (check against DB)
|
||||||
|
|
||||||
public enum StorageType {
|
public enum StorageType {
|
||||||
local, shared
|
local, shared
|
||||||
|
|||||||
@ -22,10 +22,10 @@ package com.cloud.agent.resource.virtualnetwork.model;
|
|||||||
public class VmDhcpConfig extends ConfigBase {
|
public class VmDhcpConfig extends ConfigBase {
|
||||||
private String hostName;
|
private String hostName;
|
||||||
private String macAddress;
|
private String macAddress;
|
||||||
private String ipv4Adress;
|
private String ipv4Address;
|
||||||
private String ipv6Address;
|
private String ipv6Address;
|
||||||
private String ipv6Duid;
|
private String ipv6Duid;
|
||||||
private String dnsAdresses;
|
private String dnsAddresses;
|
||||||
private String defaultGateway;
|
private String defaultGateway;
|
||||||
private String staticRoutes;
|
private String staticRoutes;
|
||||||
private boolean defaultEntry;
|
private boolean defaultEntry;
|
||||||
@ -34,15 +34,15 @@ public class VmDhcpConfig extends ConfigBase {
|
|||||||
super(VM_DHCP);
|
super(VM_DHCP);
|
||||||
}
|
}
|
||||||
|
|
||||||
public VmDhcpConfig(String hostName, String macAddress, String ipv4Adress, String ipv6Address, String ipv6Duid, String dnsAdresses, String defaultGateway,
|
public VmDhcpConfig(String hostName, String macAddress, String ipv4Address, String ipv6Address, String ipv6Duid, String dnsAddresses, String defaultGateway,
|
||||||
String staticRoutes, boolean defaultEntry) {
|
String staticRoutes, boolean defaultEntry) {
|
||||||
super(VM_DHCP);
|
super(VM_DHCP);
|
||||||
this.hostName = hostName;
|
this.hostName = hostName;
|
||||||
this.macAddress = macAddress;
|
this.macAddress = macAddress;
|
||||||
this.ipv4Adress = ipv4Adress;
|
this.ipv4Address = ipv4Address;
|
||||||
this.ipv6Address = ipv6Address;
|
this.ipv6Address = ipv6Address;
|
||||||
this.ipv6Duid = ipv6Duid;
|
this.ipv6Duid = ipv6Duid;
|
||||||
this.dnsAdresses = dnsAdresses;
|
this.dnsAddresses = dnsAddresses;
|
||||||
this.defaultGateway = defaultGateway;
|
this.defaultGateway = defaultGateway;
|
||||||
this.staticRoutes = staticRoutes;
|
this.staticRoutes = staticRoutes;
|
||||||
this.defaultEntry = defaultEntry;
|
this.defaultEntry = defaultEntry;
|
||||||
@ -64,12 +64,12 @@ public class VmDhcpConfig extends ConfigBase {
|
|||||||
this.macAddress = macAddress;
|
this.macAddress = macAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIpv4Adress() {
|
public String getIpv4Address() {
|
||||||
return ipv4Adress;
|
return ipv4Address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIpv4Adress(String ipv4Adress) {
|
public void setIpv4Address(String ipv4Address) {
|
||||||
this.ipv4Adress = ipv4Adress;
|
this.ipv4Address = ipv4Address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIpv6Address() {
|
public String getIpv6Address() {
|
||||||
@ -88,12 +88,12 @@ public class VmDhcpConfig extends ConfigBase {
|
|||||||
this.ipv6Duid = ipv6Duid;
|
this.ipv6Duid = ipv6Duid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDnsAdresses() {
|
public String getDnsAddresses() {
|
||||||
return dnsAdresses;
|
return dnsAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDnsAdresses(String dnsAdresses) {
|
public void setDnsAddresses(String dnsAddresses) {
|
||||||
this.dnsAdresses = dnsAdresses;
|
this.dnsAddresses = dnsAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultGateway() {
|
public String getDefaultGateway() {
|
||||||
|
|||||||
@ -641,13 +641,13 @@ public class Upgrade218to22 implements DbUpgrade {
|
|||||||
s_logger.debug("Marking " + allocatedIps.size() + " ip addresses to belong to network " + networkId);
|
s_logger.debug("Marking " + allocatedIps.size() + " ip addresses to belong to network " + networkId);
|
||||||
s_logger.debug("Updating mac addresses for data center id=" + dcId + ". Found " + allocatedIps.size() + " ip addresses to update");
|
s_logger.debug("Updating mac addresses for data center id=" + dcId + ". Found " + allocatedIps.size() + " ip addresses to update");
|
||||||
for (Object[] allocatedIp : allocatedIps) {
|
for (Object[] allocatedIp : allocatedIps) {
|
||||||
try (PreparedStatement selectMacAdresses = conn.prepareStatement("SELECT mac_address FROM data_center WHERE id = ?");) {
|
try (PreparedStatement selectMacAddresses = conn.prepareStatement("SELECT mac_address FROM data_center WHERE id = ?");) {
|
||||||
selectMacAdresses.setLong(1, dcId);
|
selectMacAddresses.setLong(1, dcId);
|
||||||
try (ResultSet selectedMacAdresses = selectMacAdresses.executeQuery();) {
|
try (ResultSet selectedMacAddresses = selectMacAddresses.executeQuery();) {
|
||||||
if (!selectedMacAdresses.next()) {
|
if (!selectedMacAddresses.next()) {
|
||||||
throw new CloudRuntimeException("Unable to get mac address for data center " + dcId);
|
throw new CloudRuntimeException("Unable to get mac address for data center " + dcId);
|
||||||
}
|
}
|
||||||
long mac = selectedMacAdresses.getLong(1);
|
long mac = selectedMacAddresses.getLong(1);
|
||||||
try (PreparedStatement updateDataCenter = conn.prepareStatement("UPDATE data_center SET mac_address=mac_address+1 WHERE id = ?");) {
|
try (PreparedStatement updateDataCenter = conn.prepareStatement("UPDATE data_center SET mac_address=mac_address+1 WHERE id = ?");) {
|
||||||
updateDataCenter.setLong(1, dcId);
|
updateDataCenter.setLong(1, dcId);
|
||||||
updateDataCenter.executeUpdate();
|
updateDataCenter.executeUpdate();
|
||||||
|
|||||||
@ -694,7 +694,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
|||||||
IPAddressVO addr = Transaction.execute(new TransactionCallbackWithException<IPAddressVO, InsufficientAddressCapacityException>() {
|
IPAddressVO addr = Transaction.execute(new TransactionCallbackWithException<IPAddressVO, InsufficientAddressCapacityException>() {
|
||||||
@Override
|
@Override
|
||||||
public IPAddressVO doInTransaction(TransactionStatus status) throws InsufficientAddressCapacityException {
|
public IPAddressVO doInTransaction(TransactionStatus status) throws InsufficientAddressCapacityException {
|
||||||
StringBuilder errorMessage = new StringBuilder("Unable to get ip adress in ");
|
StringBuilder errorMessage = new StringBuilder("Unable to get ip address in ");
|
||||||
boolean fetchFromDedicatedRange = false;
|
boolean fetchFromDedicatedRange = false;
|
||||||
List<Long> dedicatedVlanDbIds = new ArrayList<Long>();
|
List<Long> dedicatedVlanDbIds = new ArrayList<Long>();
|
||||||
List<Long> nonDedicatedVlanDbIds = new ArrayList<Long>();
|
List<Long> nonDedicatedVlanDbIds = new ArrayList<Long>();
|
||||||
|
|||||||
@ -1642,7 +1642,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
|||||||
final Long nextMac = mac + 1;
|
final Long nextMac = mac + 1;
|
||||||
dc.setMacAddress(nextMac);
|
dc.setMacAddress(nextMac);
|
||||||
|
|
||||||
s_logger.info("creating private ip adress for vpc (" + ipAddress + ", " + privateNtwk.getId() + ", " + nextMac + ", " + vpcId + ", " + isSourceNat + ")");
|
s_logger.info("creating private ip address for vpc (" + ipAddress + ", " + privateNtwk.getId() + ", " + nextMac + ", " + vpcId + ", " + isSourceNat + ")");
|
||||||
privateIp = new PrivateIpVO(ipAddress, privateNtwk.getId(), nextMac, vpcId, isSourceNat);
|
privateIp = new PrivateIpVO(ipAddress, privateNtwk.getId(), nextMac, vpcId, isSourceNat);
|
||||||
_privateIpDao.persist(privateIp);
|
_privateIpDao.persist(privateIp);
|
||||||
|
|
||||||
|
|||||||
@ -247,7 +247,7 @@ public class ConfigurationManagerTest {
|
|||||||
/*
|
/*
|
||||||
* TEST 5: given range is already allocated to a different account DedicatePublicIpRange should fail
|
* TEST 5: given range is already allocated to a different account DedicatePublicIpRange should fail
|
||||||
*/
|
*/
|
||||||
runDedicatePublicIpRangeIPAdressAllocated();
|
runDedicatePublicIpRangeIPAddressAllocated();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -373,8 +373,8 @@ public class ConfigurationManagerTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void runDedicatePublicIpRangeIPAdressAllocated() throws Exception {
|
void runDedicatePublicIpRangeIPAddressAllocated() throws Exception {
|
||||||
TransactionLegacy txn = TransactionLegacy.open("runDedicatePublicIpRangeIPAdressAllocated");
|
TransactionLegacy txn = TransactionLegacy.open("runDedicatePublicIpRangeIPAddressAllocated");
|
||||||
|
|
||||||
when(configurationMgr._vlanDao.findById(anyLong())).thenReturn(vlan);
|
when(configurationMgr._vlanDao.findById(anyLong())).thenReturn(vlan);
|
||||||
|
|
||||||
@ -397,7 +397,7 @@ public class ConfigurationManagerTest {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Assert.assertTrue(e.getMessage().contains("Public IP address in range is allocated to another account"));
|
Assert.assertTrue(e.getMessage().contains("Public IP address in range is allocated to another account"));
|
||||||
} finally {
|
} finally {
|
||||||
txn.close("runDedicatePublicIpRangeIPAdressAllocated");
|
txn.close("runDedicatePublicIpRangeIPAddressAllocated");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -972,7 +972,7 @@ def main(argv):
|
|||||||
level=config.get_level(),
|
level=config.get_level(),
|
||||||
format=config.get_format())
|
format=config.get_format())
|
||||||
try:
|
try:
|
||||||
# Load stored ip adresses from disk to CsConfig()
|
# Load stored ip addresses from disk to CsConfig()
|
||||||
config.set_address()
|
config.set_address()
|
||||||
|
|
||||||
logging.debug("Configuring ip addresses")
|
logging.debug("Configuring ip addresses")
|
||||||
|
|||||||
@ -130,28 +130,28 @@ class CsDhcp(CsDataBag):
|
|||||||
logging.debug("Hosts file unchanged")
|
logging.debug("Hosts file unchanged")
|
||||||
|
|
||||||
def add(self, entry):
|
def add(self, entry):
|
||||||
self.add_host(entry['ipv4_adress'], entry['host_name'])
|
self.add_host(entry['ipv4_address'], entry['host_name'])
|
||||||
# lease time boils down to once a month
|
# lease time boils down to once a month
|
||||||
# with a splay of 60 hours to prevent storms
|
# with a splay of 60 hours to prevent storms
|
||||||
lease = randint(700, 760)
|
lease = randint(700, 760)
|
||||||
|
|
||||||
if entry['default_entry'] == True:
|
if entry['default_entry'] == True:
|
||||||
self.cloud.add("%s,%s,%s,%sh" % (entry['mac_address'],
|
self.cloud.add("%s,%s,%s,%sh" % (entry['mac_address'],
|
||||||
entry['ipv4_adress'],
|
entry['ipv4_address'],
|
||||||
entry['host_name'],
|
entry['host_name'],
|
||||||
lease))
|
lease))
|
||||||
else:
|
else:
|
||||||
tag = entry['ipv4_adress'].replace(".","_")
|
tag = entry['ipv4_address'].replace(".","_")
|
||||||
self.cloud.add("%s,set:%s,%s,%s,%sh" % (entry['mac_address'],
|
self.cloud.add("%s,set:%s,%s,%s,%sh" % (entry['mac_address'],
|
||||||
tag,
|
tag,
|
||||||
entry['ipv4_adress'],
|
entry['ipv4_address'],
|
||||||
entry['host_name'],
|
entry['host_name'],
|
||||||
lease))
|
lease))
|
||||||
self.dhcp_opts.add("%s,%s" % (tag, 3))
|
self.dhcp_opts.add("%s,%s" % (tag, 3))
|
||||||
self.dhcp_opts.add("%s,%s" % (tag, 6))
|
self.dhcp_opts.add("%s,%s" % (tag, 6))
|
||||||
self.dhcp_opts.add("%s,%s" % (tag, 15))
|
self.dhcp_opts.add("%s,%s" % (tag, 15))
|
||||||
|
|
||||||
i = IPAddress(entry['ipv4_adress'])
|
i = IPAddress(entry['ipv4_address'])
|
||||||
# Calculate the device
|
# Calculate the device
|
||||||
for v in self.devinfo:
|
for v in self.devinfo:
|
||||||
if i > v['network'].network and i < v['network'].broadcast:
|
if i > v['network'].network and i < v['network'].broadcast:
|
||||||
@ -159,6 +159,6 @@ class CsDhcp(CsDataBag):
|
|||||||
# Virtual Router
|
# Virtual Router
|
||||||
v['gateway'] = entry['default_gateway']
|
v['gateway'] = entry['default_gateway']
|
||||||
|
|
||||||
|
|
||||||
def add_host(self, ip, hosts):
|
def add_host(self, ip, hosts):
|
||||||
self.hosts[ip] = hosts
|
self.hosts[ip] = hosts
|
||||||
|
|
||||||
|
|||||||
@ -18,17 +18,22 @@
|
|||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from netaddr import *
|
from netaddr import *
|
||||||
|
|
||||||
|
|
||||||
def merge(dbag, data):
|
def merge(dbag, data):
|
||||||
|
|
||||||
# A duplicate ip address wil clobber the old value
|
# A duplicate ip address wil clobber the old value
|
||||||
# This seems desirable ....
|
# This seems desirable ....
|
||||||
if "add" in data and data['add'] is False and \
|
if "add" in data and data['add'] is False and "ipv4_address" in data:
|
||||||
"ipv4_adress" in data:
|
if data['ipv4_address'] in dbag:
|
||||||
if data['ipv4_adress'] in dbag:
|
del(dbag[data['ipv4_address']])
|
||||||
del(dbag[data['ipv4_adress']])
|
|
||||||
return dbag
|
|
||||||
else:
|
else:
|
||||||
dbag[data['ipv4_adress']] = data
|
remove_key = None
|
||||||
return dbag
|
for key, entry in dbag.iteritems():
|
||||||
|
if key != 'id' and entry['host_name'] == data['host_name']:
|
||||||
|
remove_key = key
|
||||||
|
break
|
||||||
|
if remove_key is not None:
|
||||||
|
del(dbag[remove_key])
|
||||||
|
|
||||||
|
dbag[data['ipv4_address']] = data
|
||||||
|
|
||||||
|
return dbag
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"host_name":"VM-58976c22-0832-451e-9ab2-039e9f27e415",
|
"host_name":"VM-58976c22-0832-451e-9ab2-039e9f27e415",
|
||||||
"mac_address":"02:00:26:c3:00:02",
|
"mac_address":"02:00:26:c3:00:02",
|
||||||
"ipv4_adress":"172.16.1.102",
|
"ipv4_address":"172.16.1.102",
|
||||||
"ipv6_duid":"00:03:00:01:02:00:26:c3:00:02",
|
"ipv6_duid":"00:03:00:01:02:00:26:c3:00:02",
|
||||||
"default_gateway":"172.16.1.1",
|
"default_gateway":"172.16.1.1",
|
||||||
"default_entry":true,
|
"default_entry":true,
|
||||||
|
|||||||
@ -1765,11 +1765,11 @@ class TestNetworks_2(cloudstackTestCase):
|
|||||||
return
|
return
|
||||||
|
|
||||||
@attr(tags=["advanced"], required_hardware="true")
|
@attr(tags=["advanced"], required_hardware="true")
|
||||||
def test_14_list_public_ipadress_by_associated_networkid(self):
|
def test_14_list_public_ipaddress_by_associated_networkid(self):
|
||||||
"""
|
"""
|
||||||
@summary: Test List Public IPAddress with associatednetworkid
|
@summary: Test List Public IPAddress with associatednetworkid
|
||||||
@Steps
|
@Steps
|
||||||
Step1: Listing all the public ipadresses for a user before creating
|
Step1: Listing all the public ipaddresses for a user before creating
|
||||||
a public ipaddress
|
a public ipaddress
|
||||||
Step2: Verifying no Public ipaddress are listed
|
Step2: Verifying no Public ipaddress are listed
|
||||||
Step3: Creating a network
|
Step3: Creating a network
|
||||||
@ -1781,11 +1781,11 @@ class TestNetworks_2(cloudstackTestCase):
|
|||||||
Step8: Verifying the list public ipaddress size is 1
|
Step8: Verifying the list public ipaddress size is 1
|
||||||
Step9: Verifying the details of the public ipaddress
|
Step9: Verifying the details of the public ipaddress
|
||||||
"""
|
"""
|
||||||
# Listing all the public ipadresses for a user
|
# Listing all the public ipaddresses for a user
|
||||||
list_public_ipadress_before = PublicIPAddress.list(self.userapiclient)
|
list_public_ipaddress_before = PublicIPAddress.list(self.userapiclient)
|
||||||
# Verifying No VPCs are listed
|
# Verifying No VPCs are listed
|
||||||
self.assertIsNone(
|
self.assertIsNone(
|
||||||
list_public_ipadress_before,
|
list_public_ipaddress_before,
|
||||||
"Public ipaddresses listed for newly created user"
|
"Public ipaddresses listed for newly created user"
|
||||||
)
|
)
|
||||||
# Listing Network Offerings
|
# Listing Network Offerings
|
||||||
|
|||||||
@ -82,7 +82,7 @@ class UpdateConfigTestCase(SystemVMTestCase):
|
|||||||
basic_dhcp_entry = {
|
basic_dhcp_entry = {
|
||||||
"host_name":"VM-58976c22-0832-451e-9ab2-039e9f27e415",
|
"host_name":"VM-58976c22-0832-451e-9ab2-039e9f27e415",
|
||||||
"mac_address":"02:00:26:c3:00:02",
|
"mac_address":"02:00:26:c3:00:02",
|
||||||
"ipv4_adress":"172.16.1.102",
|
"ipv4_address":"172.16.1.102",
|
||||||
"ipv6_duid":"00:03:00:01:02:00:26:c3:00:02",
|
"ipv6_duid":"00:03:00:01:02:00:26:c3:00:02",
|
||||||
"default_gateway":"172.16.1.1",
|
"default_gateway":"172.16.1.1",
|
||||||
"default_entry":True,
|
"default_entry":True,
|
||||||
@ -372,7 +372,7 @@ class UpdateConfigTestCase(SystemVMTestCase):
|
|||||||
ipb = ".".join(octets[0:3])
|
ipb = ".".join(octets[0:3])
|
||||||
ipa = "%s.%s" % (ipb, n)
|
ipa = "%s.%s" % (ipb, n)
|
||||||
gw = "%s.1" % ipb
|
gw = "%s.1" % ipb
|
||||||
self.basic_dhcp_entry['ipv4_adress'] = ipa
|
self.basic_dhcp_entry['ipv4_address'] = ipa
|
||||||
self.basic_dhcp_entry['default_gateway'] = gw
|
self.basic_dhcp_entry['default_gateway'] = gw
|
||||||
self.basic_dhcp_entry['host_name'] = "host_%s" % (ipa)
|
self.basic_dhcp_entry['host_name'] = "host_%s" % (ipa)
|
||||||
self.update_config(self.basic_dhcp_entry)
|
self.update_config(self.basic_dhcp_entry)
|
||||||
@ -382,7 +382,7 @@ class UpdateConfigTestCase(SystemVMTestCase):
|
|||||||
assert port.is_listening(53)
|
assert port.is_listening(53)
|
||||||
assert port.is_listening(67)
|
assert port.is_listening(67)
|
||||||
for o in configs:
|
for o in configs:
|
||||||
line = "%s,%s,%s,infinite" % (o['mac_address'], o['ipv4_adress'], o['host_name'])
|
line = "%s,%s,%s,infinite" % (o['mac_address'], o['ipv4_address'], o['host_name'])
|
||||||
assert file.has_line("/etc/dhcphosts.txt", line)
|
assert file.has_line("/etc/dhcphosts.txt", line)
|
||||||
config['add'] = False
|
config['add'] = False
|
||||||
self.update_config(config)
|
self.update_config(config)
|
||||||
@ -400,7 +400,7 @@ class UpdateConfigTestCase(SystemVMTestCase):
|
|||||||
o['add'] = False
|
o['add'] = False
|
||||||
self.update_config(o)
|
self.update_config(o)
|
||||||
for o in configs:
|
for o in configs:
|
||||||
line = "%s,%s,%s,infinite" % (o['mac_address'], o['ipv4_adress'], o['host_name'])
|
line = "%s,%s,%s,infinite" % (o['mac_address'], o['ipv4_address'], o['host_name'])
|
||||||
assert file.has_line("/etc/dhcphosts.txt", line) is False
|
assert file.has_line("/etc/dhcphosts.txt", line) is False
|
||||||
# If the network gets deleted so should the vpn
|
# If the network gets deleted so should the vpn
|
||||||
assert not file.exists("/etc/ipsec.d/ipsec.vpn-%s.conf" % vpn_config['peer_gateway_ip'])
|
assert not file.exists("/etc/ipsec.d/ipsec.vpn-%s.conf" % vpn_config['peer_gateway_ip'])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user