summaryrefslogtreecommitdiff
path: root/cloudinit/distros/freebsd.py
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2018-01-26 13:36:30 -0700
committerChad Smith <chad.smith@canonical.com>2018-01-26 13:36:30 -0700
commit1d8c327139a8c291eeb244ee1a6a8badd83e9e72 (patch)
tree737b92f0e9d476a64e5a945fdaa0c6d7f4f2bf6f /cloudinit/distros/freebsd.py
parentbc84f5023f795c261e32cf0690b2d29e12cfaedd (diff)
downloadvyos-cloud-init-1d8c327139a8c291eeb244ee1a6a8badd83e9e72.tar.gz
vyos-cloud-init-1d8c327139a8c291eeb244ee1a6a8badd83e9e72.zip
Fix potential cases of uninitialized variables.
While addressing undeclared variable in 'cloud-init status', I also fixed the errors raised by automated code reviews against cloud-init master at https://lgtm.com/projects/g/cloud-init/cloud-init/alerts The following items are addressed:  * Fix 'cloud-init status':     * Only report 'running' state when any stage in /run/cloud-init/status.json has a start time but no finished time. Default start time to 0 if null.     * undeclared variable 'reason' now reports 'Cloud-init enabled by systemd cloud-init-generator' when systemd enables cloud-init  * cc_rh_subscription.py util.subp return values aren't set during if an exception is raised, use ProcessExecution as e instead.  * distros/freebsd.py:    * Drop repetitive looping over ipv4 and ipv6 nic lists.    * Initialize bsddev to 'NOTFOUND' in the event that no devs are discovered    * declare nics_with_addresses = set() in broader scope outside check_downable conditional  * cloudinit/util.py: Raise TypeError if mtype parameter isn't string, iterable or None. LP: #1744796
Diffstat (limited to 'cloudinit/distros/freebsd.py')
-rw-r--r--cloudinit/distros/freebsd.py11
1 files changed, 3 insertions, 8 deletions
diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py
index bad112fe..aa468bca 100644
--- a/cloudinit/distros/freebsd.py
+++ b/cloudinit/distros/freebsd.py
@@ -116,6 +116,7 @@ class Distro(distros.Distro):
(out, err) = util.subp(['ifconfig', '-a'])
ifconfigoutput = [x for x in (out.strip()).splitlines()
if len(x.split()) > 0]
+ bsddev = 'NOT_FOUND'
for line in ifconfigoutput:
m = re.match('^\w+', line)
if m:
@@ -347,15 +348,9 @@ class Distro(distros.Distro):
bymac[Distro.get_interface_mac(n)] = {
'name': n, 'up': self.is_up(n), 'downable': None}
+ nics_with_addresses = set()
if check_downable:
- nics_with_addresses = set()
- ipv6 = self.get_ipv6()
- ipv4 = self.get_ipv4()
- for bytes_out in (ipv6, ipv4):
- for i in ipv6:
- nics_with_addresses.update(i)
- for i in ipv4:
- nics_with_addresses.update(i)
+ nics_with_addresses = set(self.get_ipv4() + self.get_ipv6())
for d in bymac.values():
d['downable'] = (d['up'] is False or