def get_fan_speed(self, fan_id=None): self.assertNotEqual(self.read_fans_cmd, None, "Get Fan cmd not set") cmd = self.read_fans_cmd if fan_id: cmd = self.read_fans_cmd + " " + str(fan_id) Logger.debug("Executing: {}".format(cmd)) return run_shell_cmd(cmd)
def get_ipv6_address(self): """ Get IPv6 address of a given interface """ ipv6 = self.get_ip_addr_output_inet6()[1].split("/")[0] Logger.debug("Got ip address for " + str(self.ifname)) return ipv6
def check_i2c_device(self, i2c_path, i2c_info): Logger.debug("checking i2c device %s" % i2c_path) dev_dir = I2cSysfsUtils.i2c_device_abspath(i2c_path) self.assertTrue( os.path.isdir(dev_dir), "%s (name=%s, driver=%s) is missing" % (i2c_path, i2c_info["name"], i2c_info["driver"]), ) err_str = "" # Verify device name/type is correct. name = I2cSysfsUtils.i2c_device_get_name(i2c_path) if name != i2c_info["name"]: err_str += "name mismatch: expect %s, actual %s; " % ( i2c_info["name"], name, ) # Make sure correct driver is binded to the device. driver = I2cSysfsUtils.i2c_device_get_driver(i2c_path) if driver != i2c_info["driver"]: err_str += "driver mismatch: expect %s, actual %s;" % ( i2c_info["driver"], driver, ) self.assertEqual(err_str, "", "%s: %s" % (i2c_path, err_str))
def get_ipv6_address(self): """ Get IPv6 address of a given interface """ f = subprocess.Popen( ["ip", "addr", "show", self.ifname.encode("utf-8")], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) out, err = f.communicate() self.assertNotEqual( len(out), 0, "Device " + str(self.ifname) + " does not exist [FAILED]") self.assertEqual( len(err), 0, "Device " + str(self.ifname) + " does not exist [FAILED]") if len(out) == 0 or len(err) != 0: Logger.error("Device " + str(self.ifname) + " does not exist [FAILED]") return 1 # raise Exception("Device " + self.ifname.encode('utf-8') + " does not exist [FAILED]") out = out.decode("utf-8") ipv6 = out.split("inet6 ")[1].split("/")[0] Logger.debug("Got ip address for " + str(self.ifname)) return ipv6
def set_all_fans_speed(self, pwm): """ Helper function to set fan speed """ cmd = "/usr/local/bin/fan-util --set " + str(pwm) Logger.debug("Executing: {}".format(cmd)) run_shell_cmd(cmd) time.sleep(10) # allow time for fans to be properly set
def set_fan_speed(self, fan_id, pwm): ''' Helper function to set fan speed ''' cmd = '/usr/local/bin/fan-util --set ' + str(pwm) + ' ' + str(fan_id) Logger.debug("Executing: {}".format(cmd)) run_shell_cmd(cmd) time.sleep(10) # allow time for fans to be properly set
def set_fan_speed(self, fan_id, pwm): """ Helper function to set fan speed """ self.assertNotEqual(self.write_fans_cmd, None, "Set Fan cmd not set") cmd = self.write_fans_cmd + " " + str(pwm) + " " + str(fan_id) Logger.debug("Executing: {}".format(cmd)) run_shell_cmd(cmd) time.sleep(10) # allow time for fans to be properly set
def get_fan_speed(self, fan_id=None): """ Helper function to get fan speed """ cmd = "/usr/local/bin/fan-util --get" if fan_id is not None: cmd = cmd + " " + str(fan_id) Logger.debug("Executing: {}".format(cmd)) ret = run_shell_cmd(cmd) return ret
def run_ping(self, cmd): self.assertNotEqual(cmd, None, "run_ping cmd not set") if cmd != "": Logger.debug("Executing: " + str(cmd)) f = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) err = f.communicate()[1] if len(err) > 0: raise Exception(err) return f.returncode return -1
def read_data_from_filepath(path): ''' Helper method to read file from a file ''' try: handle = open(path, "r") data = handle.readline().rstrip() handle.close() Logger.debug("Reading path={} data={}".format(path, data)) return data except Exception: raise ("Failed to read path={}".format(path))
def get_ipv4_address(self): """ Get IPv4 address of a given interface """ f = subprocess.Popen(['ip', 'addr', 'show', self.ifname.encode('utf-8')], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = f.communicate() if (len(out) == 0 or len(err) != 0): raise Exception("Device " + self.ifname.encode('utf-8') + " does not exist [FAILED]") out = out.decode('utf-8') ipv4 = out.split("inet ")[1].split("/")[0] Logger.debug("Got ip address for " + str(self.ifname)) return ipv4
def get_ipv6_address(self): """ Get inet6 address with highest length of a given interface overriding this method of BaseInterfaceTest class because we want to have inet6 address with highest length """ out = self.get_ip_addr_output_inet6() # trying to find inet6 address with highest length ipv6 = "" for value in out[1:]: if len(value.split("/")[0]) > len(ipv6): ipv6 = value.split("/")[0] Logger.debug("Got ip address for " + str(self.ifname)) return ipv6.lower()
def get_ipv4_address(self): """ Get IPv4 address of a given interface """ f = subprocess.Popen( ["ip", "addr", "show", self.ifname.encode("utf-8")], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) out, err = f.communicate() if len(out) == 0 or len(err) != 0: raise Exception("Device " + str(self.ifname) + " does not exist [FAILED]") out = out.decode("utf-8") if "inet " not in out: raise Exception( "Device " + str(self.ifname) + " does not have an IPv4 address [FAILED]\ncommand output:" + out) ipv4 = out.split("inet ")[1].split("/")[0] Logger.debug("Got ip address for " + str(self.ifname)) return ipv4