From a78ee43852874dd4d135f42a50618e34db4e2d5c Mon Sep 17 00:00:00 2001 From: Maykel Moya Date: Wed, 13 Feb 2013 02:01:58 +0100 Subject: [PATCH 1/2] Prevent traceback when /etc/mtab is not available * get_file_contents returns None when file is not available. When /etc/mtab is pointing to /proc/mounts and /proc is not mounted, mtab.split will traceback. --- setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup b/setup index fab87244c28..2080631ab3a 100644 --- a/setup +++ b/setup @@ -388,7 +388,7 @@ class LinuxHardware(Hardware): def get_mount_facts(self): self.facts['mounts'] = [] - mtab = get_file_content('/etc/mtab') + mtab = get_file_content('/etc/mtab', '') for line in mtab.split('\n'): if line.startswith('/'): fields = line.rstrip('\n').split() From f93543978e6b3f3d8d97a3543609bfe2e1b2c199 Mon Sep 17 00:00:00 2001 From: Maykel Moya Date: Wed, 13 Feb 2013 02:24:19 +0100 Subject: [PATCH 2/2] Check presence of files under /proc before opening them --- setup | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/setup b/setup index 2080631ab3a..6daca214f55 100644 --- a/setup +++ b/setup @@ -967,31 +967,33 @@ class LinuxVirtual(Virtual): self.facts['virtualization_role'] = 'guest' return - for line in open('/proc/self/status').readlines(): - if re.match('^VxID: \d+', line): - self.facts['virtualization_type'] = 'linux_vserver' - if re.match('^VxID: 0', line): - self.facts['virtualization_role'] = 'host' + if os.path.exists('/proc/self/status'): + for line in open('/proc/self/status').readlines(): + if re.match('^VxID: \d+', line): + self.facts['virtualization_type'] = 'linux_vserver' + if re.match('^VxID: 0', line): + self.facts['virtualization_role'] = 'host' + else: + self.facts['virtualization_role'] = 'guest' + return + + if os.path.exists('/proc/cpuinfo'): + for line in open('/proc/cpuinfo').readlines(): + if re.match('^model name.*QEMU Virtual CPU', line): + self.facts['virtualization_type'] = 'kvm' + elif re.match('^vendor_id.*User Mode Linux', line): + self.facts['virtualization_type'] = 'uml' + elif re.match('^model name.*UML', line): + self.facts['virtualization_type'] = 'uml' + elif re.match('^vendor_id.*PowerVM Lx86', line): + self.facts['virtualization_type'] = 'powervm_lx86' + elif re.match('^vendor_id.*IBM/S390', line): + self.facts['virtualization_type'] = 'ibm_systemz' else: - self.facts['virtualization_role'] = 'guest' + continue + self.facts['virtualization_role'] = 'guest' return - for line in open('/proc/cpuinfo').readlines(): - if re.match('^model name.*QEMU Virtual CPU', line): - self.facts['virtualization_type'] = 'kvm' - elif re.match('^vendor_id.*User Mode Linux', line): - self.facts['virtualization_type'] = 'uml' - elif re.match('^model name.*UML', line): - self.facts['virtualization_type'] = 'uml' - elif re.match('^vendor_id.*PowerVM Lx86', line): - self.facts['virtualization_type'] = 'powervm_lx86' - elif re.match('^vendor_id.*IBM/S390', line): - self.facts['virtualization_type'] = 'ibm_systemz' - else: - continue - self.facts['virtualization_role'] = 'guest' - return - # Beware that we can have both kvm and virtualbox running on a single system if os.path.exists("/proc/modules"): modules = []