Extend PATH and set -o pipefail in linux ssh
Some distributions have 'ip' utility in /sbin, and there's no link with target of /bin/ip
(CentOS7, for instance).
By this patch we
1) remove redundant specification: /bin is in PATH already
2) add /sbin to PATH, since SSH misses it by default
3) "set -eu -o pipefail" to make errors more explicit
Change-Id: I7693911e6b883a21baafe6f804564754ebaea5e0
diff --git a/tempest/common/utils/linux/remote_client.py b/tempest/common/utils/linux/remote_client.py
index 29fb493..81bb55d 100644
--- a/tempest/common/utils/linux/remote_client.py
+++ b/tempest/common/utils/linux/remote_client.py
@@ -46,6 +46,9 @@
channel_timeout=ssh_channel_timeout)
def exec_command(self, cmd):
+ # Shell options below add more clearness on failures,
+ # path is extended for some non-cirros guest oses (centos7)
+ cmd = "set -eu -o pipefail; PATH=$PATH:/sbin; " + cmd
return self.ssh_client.exec_command(cmd)
def validate_authentication(self):
@@ -95,26 +98,26 @@
return self.exec_command(cmd)
def get_mac_address(self):
- cmd = "/bin/ip addr | awk '/ether/ {print $2}'"
+ cmd = "ip addr | awk '/ether/ {print $2}'"
return self.exec_command(cmd)
def get_nic_name(self, address):
- cmd = "/bin/ip -o addr | awk '/%s/ {print $2}'" % address
+ cmd = "ip -o addr | awk '/%s/ {print $2}'" % address
return self.exec_command(cmd)
def get_ip_list(self):
- cmd = "/bin/ip address"
+ cmd = "ip address"
return self.exec_command(cmd)
def assign_static_ip(self, nic, addr):
- cmd = "sudo /bin/ip addr add {ip}/{mask} dev {nic}".format(
+ cmd = "sudo ip addr add {ip}/{mask} dev {nic}".format(
ip=addr, mask=CONF.network.tenant_network_mask_bits,
nic=nic
)
return self.exec_command(cmd)
def turn_nic_on(self, nic):
- cmd = "sudo /bin/ip link set {nic} up".format(nic=nic)
+ cmd = "sudo ip link set {nic} up".format(nic=nic)
return self.exec_command(cmd)
def get_pids(self, pr_name):
diff --git a/tempest/tests/common/utils/linux/test_remote_client.py b/tempest/tests/common/utils/linux/test_remote_client.py
index d6377e6..3506856 100644
--- a/tempest/tests/common/utils/linux/test_remote_client.py
+++ b/tempest/tests/common/utils/linux/test_remote_client.py
@@ -73,6 +73,7 @@
# the information using gnu/linux tools.
def _assert_exec_called_with(self, cmd):
+ cmd = "set -eu -o pipefail; PATH=$PATH:/sbin; " + cmd
self.ssh_mock.mock.exec_command.assert_called_with(cmd)
def test_get_number_of_vcpus(self):
@@ -119,7 +120,7 @@
self.assertEqual(self.conn.get_mac_address(), macs)
self._assert_exec_called_with(
- "/bin/ip addr | awk '/ether/ {print $2}'")
+ "ip addr | awk '/ether/ {print $2}'")
def test_get_ip_list(self):
ips = """1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
@@ -136,7 +137,7 @@
valid_lft forever preferred_lft forever"""
self.ssh_mock.mock.exec_command.return_value = ips
self.assertEqual(self.conn.get_ip_list(), ips)
- self._assert_exec_called_with('/bin/ip address')
+ self._assert_exec_called_with('ip address')
def test_assign_static_ip(self):
self.ssh_mock.mock.exec_command.return_value = ''
@@ -144,9 +145,10 @@
nic = 'eth0'
self.assertEqual(self.conn.assign_static_ip(nic, ip), '')
self._assert_exec_called_with(
- "sudo /bin/ip addr add %s/%s dev %s" % (ip, '28', nic))
+ "sudo ip addr add %s/%s dev %s" % (ip, '28', nic))
def test_turn_nic_on(self):
nic = 'eth0'
self.conn.turn_nic_on(nic)
- self._assert_exec_called_with('sudo /bin/ip link set %s up' % nic)
+ self._assert_exec_called_with(
+ 'sudo ip link set %s up' % nic)