Change way how second NIC in guest OS is configured
In case of RHEL based operating system used in guest vm in
test_network_v6 module, there is need to prepare
/etc/sysconfig/network-scripts/ifcfg-%(nic)s
file with "IPV6INIT=yes" to enable IPv6 on it.
Otherwise IPv6 will not be configured on this NIC when:
ip link set up dev %(nic)s
will be executed and tests with dualnet=False will fail.
This isn't necessary on systems like Ubuntu or Cirros.
Related-Prod:PROD-25391
Change-Id: I397b1c3584a045f9ca4f47b4e691385628d35efa
Closes-Bug: #1795891
(cherry picked from commit c5c7ba997eb194e8428bfcb802bfabfdfb5ef5fe)
diff --git a/tempest/scenario/test_network_v6.py b/tempest/scenario/test_network_v6.py
index 9f4e62b..5bdd89f 100644
--- a/tempest/scenario/test_network_v6.py
+++ b/tempest/scenario/test_network_v6.py
@@ -12,13 +12,18 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
+
+from oslo_log import log as logging
+
from tempest.common import utils
from tempest import config
from tempest.lib.common.utils import test_utils
from tempest.lib import decorators
+from tempest.lib import exceptions
from tempest.scenario import manager
CONF = config.CONF
+LOG = logging.getLogger(__name__)
class TestGettingAddress(manager.NetworkScenarioTest):
@@ -154,8 +159,31 @@
% (network_id, ports))
mac6 = ports[0]
nic = ssh.get_nic_name_by_mac(mac6)
+ # NOTE(slaweq): on RHEL based OS ifcfg file for new interface is
+ # needed to make IPv6 working on it, so if
+ # /etc/sysconfig/network-scripts directory exists ifcfg-%(nic)s file
+ # should be added in it
+ if self._sysconfig_network_scripts_dir_exists(ssh):
+ try:
+ ssh.exec_command(
+ 'echo -e "DEVICE=%(nic)s\\nIPV6INIT=yes" | '
+ 'sudo tee /etc/sysconfig/network-scripts/ifcfg-%(nic)s; '
+ 'sudo /sbin/service network restart' % {'nic': nic})
+ except exceptions.SSHExecCommandFailed as e:
+ # NOTE(slaweq): Sometimes it can happen that this SSH command
+ # will fail because of some error from network manager in
+ # guest os.
+ # But even then doing ip link set up below is fine and
+ # IP address should be configured properly.
+ LOG.debug("Error during restarting %(nic)s interface on "
+ "instance. Error message: %(error)s",
+ {'nic': nic, 'error': e})
ssh.exec_command("sudo ip link set %s up" % nic)
+ def _sysconfig_network_scripts_dir_exists(self, ssh):
+ return "False" not in ssh.exec_command(
+ 'test -d /etc/sysconfig/network-scripts/ || echo "False"')
+
def _prepare_and_test(self, address6_mode, n_subnets6=1, dualnet=False):
net_list = self.prepare_network(address6_mode=address6_mode,
n_subnets6=n_subnets6,