Skip to content

Commit

Permalink
Update for to avoid future flake8 errors
Browse files Browse the repository at this point in the history
Signed-off-by: Plessis <aplessis@rbbn.com>
  • Loading branch information
Plessis committed Jan 21, 2019
1 parent 36d9be9 commit 6602e0a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
4 changes: 2 additions & 2 deletions azurelinuxagent/common/future.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def get_openwrt_platform():
the version and product information is contained in the /etc/openwrt_release file.
"""
result = [None, None, None]
openwrt_version = re.compile("^DISTRIB_RELEASE=['\"](\d+\.\d+.\d+)['\"]")
openwrt_product = re.compile("^DISTRIB_ID=['\"]([\w-]+)['\"]")
openwrt_version = re.compile(r"^DISTRIB_RELEASE=['\"](\d+\.\d+.\d+)['\"]")
openwrt_product = re.compile(r"^DISTRIB_ID=['\"]([\w-]+)['\"]")

with open('/etc/openwrt_release', 'r') as fh:
content = fh.readlines()
Expand Down
13 changes: 5 additions & 8 deletions azurelinuxagent/common/osutil/openwrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ def get_nic_state(self):
"""
state = {}
status, output = shellutil.run_get_output("ip -o link", chk_err=False, log_cmd=False)
"""
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000\ link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000\ link/ether 00:0d:3a:f9:d9:c6 brd ff:ff:ff:ff:ff:ff
"""

if status != 0:
logger.verbose("Could not fetch NIC link info; status {0}, {1}".format(status, output))
return {}
Expand All @@ -93,10 +90,7 @@ def get_nic_state(self):

self._update_nic_state(state, "ip -o -f inet address", NetworkInterfaceCard.add_ipv4, "an IPv4 address")
self._update_nic_state(state, "ip -o -f inet6 address", NetworkInterfaceCard.add_ipv6, "an IPv6 address")
"""
1: lo inet6 ::1/128 scope host \ valid_lft forever preferred_lft forever
2: eth0 inet6 fe80::20d:3aff:fe30:c35a/64 scope link \ valid_lft forever preferred_lft forever
"""

return state

def _update_nic_state(self, state, ip_command, handler, description):
Expand Down Expand Up @@ -155,3 +149,6 @@ def unregister_agent_service(self):
def set_hostname(self, hostname):
fileutil.write_file('/etc/hostname', hostname)
shellutil.run("uci set system.@system[0].hostname='{0}' && uci commit system && /etc/init.d/system reload".format(hostname), chk_err=False)

def remove_rules_files(self, rules_files=""):
pass
19 changes: 9 additions & 10 deletions azurelinuxagent/daemon/resourcedisk/openwrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# Requires Python 2.6+ and Openssl 1.0+
#
import os
import errno as errno

import azurelinuxagent.common.logger as logger
import azurelinuxagent.common.utils.fileutil as fileutil
Expand All @@ -34,8 +35,9 @@ def __init__(self):
self.fs = 'ffs'

def reread_partition_table(self, device):
shellutil.run("hdparm -z {0}".format(device),
chk_err=False)
ret, output = shellutil.run_get_output("hdparm -z {0}".format(device), chk_err=False)
if ret != 0:
logger.warn("Failed refresh the partition table.")

def mount_resource_disk(self, mount_point):
device = self.osutil.device_for_ide_port(1)
Expand Down Expand Up @@ -98,22 +100,19 @@ def mount_resource_disk(self, mount_point):
if not os.path.exists(partition):
raise ResourceDiskError("Partition was not created [{0}]".format(partition))

logger.info("Mount resource disk [{0}]", mount_string)
ret, output = shellutil.run_get_output(mount_string, chk_err=False)
# if the exit code is 32, then the resource disk can be already mounted
if ret == 32 and output.find("is already mounted") != -1:
logger.warn("Could not mount resource disk: {0}", output)
elif ret != 0:
if os.path.ismount(mount_point):
logger.warn("Disk is already mounted on {0}", mount_point)
else:
# Some kernels seem to issue an async partition re-read after a
# command invocation. This causes mount to fail if the
# partition re-read is not complete by the time mount is
# attempted. Seen in CentOS 7.2. Force a sequential re-read of
# the partition and try mounting.
logger.warn("Failed to mount resource disk. "
"Retry mounting after re-reading partition info.")
logger.info("Mounting after re-reading partition info.")

self.reread_partition_table(device)

logger.info("Mount resource disk [{0}]", mount_string)
ret, output = shellutil.run_get_output(mount_string)
if ret:
logger.warn("Failed to mount resource disk. "
Expand Down

0 comments on commit 6602e0a

Please sign in to comment.