1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00

python3: utils.exec_command now returns str and not bytes

Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
This commit is contained in:
Julien Fortin
2019-12-10 17:39:45 +01:00
parent 166bc29384
commit e36ad206ac
6 changed files with 14 additions and 16 deletions

View File

@@ -115,7 +115,7 @@ class vrf(Addon, moduleBase):
try:
ip_rules = utils.exec_command('%s rule show'
%utils.ip_cmd).splitlines()
self.ip_rule_cache = [b' '.join(r.split()) for r in ip_rules]
self.ip_rule_cache = [' '.join(r.split()) for r in ip_rules]
except Exception as e:
self.ip_rule_cache = []
self.logger.warning('vrf: cache v4: %s' % str(e))
@@ -123,7 +123,7 @@ class vrf(Addon, moduleBase):
try:
ip_rules = utils.exec_command('%s -6 rule show'
%utils.ip_cmd).splitlines()
self.ip6_rule_cache = [b' '.join(r.split()) for r in ip_rules]
self.ip6_rule_cache = [' '.join(r.split()) for r in ip_rules]
except Exception as e:
self.ip6_rule_cache = []
self.logger.warning('vrf: cache v6: %s' % str(e))
@@ -558,7 +558,7 @@ class vrf(Addon, moduleBase):
def _l3mdev_rule(self, ip_rules):
for rule in ip_rules:
if not re.search(r"\d.*from\s+all\s+lookup\s+\W?l3mdev-table\W?",
rule.decode("ascii")):
rule):
continue
return True
return False

View File

@@ -768,9 +768,7 @@ class iface():
else:
outbuf += ifaceline + '\n'
if self.status == ifaceStatus.NOTFOUND:
outbuf = (outbuf.encode('utf8')
if isinstance(outbuf, str) else outbuf)
print(outbuf.decode() + '\n')
print(outbuf + '\n')
return
else:
outbuf += ifaceline + '\n'
@@ -795,10 +793,7 @@ class iface():
if cv:
outbuf += indent + '%s %s\n' % (cname, cv)
idx += 1
if with_status:
outbuf = (outbuf.encode('utf8')
if isinstance(outbuf, str) else outbuf)
print(outbuf.decode())
print(outbuf)
def dump_pretty(self, with_status=False, use_realname=False):
if not self.addr_family:

View File

@@ -418,12 +418,15 @@ class utils():
raise Exception('cmd \'%s\' failed (%s)' % (' '.join(cmd), str(e)))
finally:
utils.disable_subprocess_signal_forwarding(signal.SIGINT)
cmd_output_string = cmd_output.decode() if cmd_output else cmd_output
if cmd_returncode != 0:
raise Exception(cls._format_error(cmd,
cmd_returncode,
cmd_output,
cmd_output_string,
stdin))
return cmd_output.decode() if cmd_output else None
return cmd_output_string
@classmethod
def exec_user_command(cls, cmd, close_fds=False, stdout=True,

View File

@@ -315,7 +315,7 @@ class moduleBase(object):
""" get value of sysctl variable """
output = utils.exec_command('%s %s' %
(utils.sysctl_cmd, variable))
split = output.split(b'=')
split = output.split('=')
if len(split) > 1:
return split[1].strip()
return None

View File

@@ -142,7 +142,7 @@ class mstpctlutil(utilsBase):
return mstpctl_bridgeport_attrs_dict
portname = bridgename # assigning portname to avoid an exception, in the exception handler
try:
mstpctl_bridge_cache = json.loads(output.strip(b'\n'))
mstpctl_bridge_cache = json.loads(output.strip("\n"))
for portname in list(mstpctl_bridge_cache.keys()):
for portid in list(mstpctl_bridge_cache[portname].keys()):
mstpctl_bridgeport_attrs_dict[portname] = {}
@@ -165,7 +165,7 @@ class mstpctlutil(utilsBase):
self.logger.info(str(e))
return mstpctl_bridge_attrs_dict
try:
mstpctl_bridge_cache = json.loads(output.strip(b'\n'))
mstpctl_bridge_cache = json.loads(output.strip('\n'))
for jsonAttr in list(mstpctl_bridge_cache[bridgename].keys()):
mstpctl_bridge_attrs_dict[jsonAttr] = (
str(mstpctl_bridge_cache[bridgename][jsonAttr]))

View File

@@ -310,7 +310,7 @@ class IPRoute2(Cache, Requirements):
try:
ps = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, close_fds=False)
utils.enable_subprocess_signal_forwarding(ps, signal.SIGINT)
output = subprocess.check_output(("grep", "00:00:00:00:00:00"), stdin=ps.stdout)
output = subprocess.check_output(("grep", "00:00:00:00:00:00"), stdin=ps.stdout).decode()
ps.wait()
utils.disable_subprocess_signal_forwarding(signal.SIGINT)
try: