Change fullstack dhclient lease file to tmp folder

Each cases are sharing the common lease path for dhclient,
for instance, in CentOS it is: /var/lib/dhclient/dhclient.leases.
That means all fullstack cases will use this file to store
fake VM's NIC DHCP lease information.

After run several times of fullstack cases, the dhclient will
get failed to set the test fake VM port's IP due to the mess
settings in this file.

This patch sets each fake VM's NIC lease file path to the
tmp folder with it's port id.

This may fix some cases that cannot set the IP addr to the test
device properly via DHCP.

Closes-Bug: #1934646
Change-Id: Ia87fa7c08df473acbcf1600035d99a83ed4b4375
This commit is contained in:
LIU Yulong 2021-07-05 15:19:54 +08:00
parent 97618b0876
commit 3b46df4847
1 changed files with 11 additions and 6 deletions

View File

@ -92,7 +92,7 @@ class FakeFullstackMachine(machine_fixtures.FakeMachineBase):
self.neutron_port['id'], hybrid_plug)).port
for fixed_ip in self.neutron_port['fixed_ips']:
self._configure_ipaddress(fixed_ip)
self._configure_ipaddress(self.neutron_port['id'], fixed_ip)
def bind_port_if_needed(self):
if self.neutron_port[pbs.VIF_TYPE] == pbs.VIF_TYPE_UNBOUND:
@ -116,7 +116,7 @@ class FakeFullstackMachine(machine_fixtures.FakeMachineBase):
return new_bridge
def _configure_ipaddress(self, fixed_ip):
def _configure_ipaddress(self, port_id, fixed_ip):
subnet_id = fixed_ip['subnet_id']
subnet = self.safe_client.client.show_subnet(subnet_id)
if (netaddr.IPAddress(fixed_ip['ip_address']).version ==
@ -126,6 +126,7 @@ class FakeFullstackMachine(machine_fixtures.FakeMachineBase):
self.gateway_ipv6 = subnet['subnet']['gateway_ip']
if self.use_dhcp6:
self._configure_ipaddress_via_dhcp(
port_id,
version=constants.IP_VERSION_6)
else:
self._ip = fixed_ip['ip_address']
@ -134,7 +135,7 @@ class FakeFullstackMachine(machine_fixtures.FakeMachineBase):
self.gateway_ip = subnet['subnet']['gateway_ip']
if self.use_dhcp:
self._configure_ipaddress_via_dhcp()
self._configure_ipaddress_via_dhcp(port_id)
else:
self._configure_static_ipaddress()
@ -146,12 +147,16 @@ class FakeFullstackMachine(machine_fixtures.FakeMachineBase):
if gateway_ip in net:
net_helpers.set_namespace_gateway(self.port, self.gateway_ip)
def _configure_ipaddress_via_dhcp(self, version=constants.IP_VERSION_4):
self._start_async_dhclient(version)
def _configure_ipaddress_via_dhcp(self, port_id,
version=constants.IP_VERSION_4):
self._start_async_dhclient(port_id, version)
self.addCleanup(self._stop_async_dhclient)
def _start_async_dhclient(self, version=constants.IP_VERSION_4):
def _start_async_dhclient(self, port_id, version=constants.IP_VERSION_4):
cmd = ["dhclient", '-%s' % version,
'-lf',
'%s/%s.lease' % (self.host.neutron_config.temp_dir,
port_id),
'-sf', self.NO_RESOLV_CONF_DHCLIENT_SCRIPT_PATH,
'--no-pid', '-d', self.port.name]
self.dhclient_async = async_process.AsyncProcess(