summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2016-12-21 23:08:44 +0100
committerDaniil Baturin <daniil@baturin.org>2016-12-21 23:08:44 +0100
commitece88fcafb45dd683a0cad3801c79537cd411d44 (patch)
tree5e6241b5bb1e007fd3159367961dcd3cc4681692
parent71989c2918185c52e4346126dc2b6d7249819458 (diff)
downloadvyatta-op-ece88fcafb45dd683a0cad3801c79537cd411d44.tar.gz
vyatta-op-ece88fcafb45dd683a0cad3801c79537cd411d44.zip
T156: return "Unknown" for /sys/class/dmi/* files that don't exist.
-rw-r--r--scripts/vyos-show-version19
-rw-r--r--templates/show/version/all/node.def2
-rw-r--r--templates/show/version/funny/node.def2
-rw-r--r--templates/show/version/node.def2
4 files changed, 15 insertions, 10 deletions
diff --git a/scripts/vyos-show-version b/scripts/vyos-show-version
index c0609ca..438f365 100644
--- a/scripts/vyos-show-version
+++ b/scripts/vyos-show-version
@@ -28,9 +28,14 @@ import pystache
def read_file(name):
- with open (name, "r") as f:
- data = f.read()
- return data.strip()
+ try:
+ with open (name, "r") as f:
+ data = f.read()
+ return data.strip()
+ except:
+ # This works since we only read /sys/class/* stuff
+ # with this function
+ return "Unknown"
version_file = '/opt/vyatta/etc/version.json'
version_data = None
@@ -95,10 +100,10 @@ version_data['boot_via'] = boot_via
# Get hardware details from DMI
version_data['hardware_vendor'] = read_file('/sys/class/dmi/id/sys_vendor')
version_data['hardware_model'] = read_file('/sys/class/dmi/id/product_name')
-# XXX: serial and uuid files are only readable for root, so we cannot just read them
-# when script is ran by a normal user, hence this ugly fixup
-version_data['hardware_serial'] = subprocess.check_output('sudo cat /sys/class/dmi/id/subsystem/id/product_serial', shell=True).strip()
-version_data['hardware_uuid'] = subprocess.check_output('sudo cat /sys/class/dmi/id/subsystem/id/product_uuid', shell=True).strip()
+
+# These two assume script is run as root, normal users can't access those files
+version_data['hardware_serial'] = read_file('/sys/class/dmi/id/subsystem/id/product_serial')
+version_data['hardware_uuid'] = read_file('/sys/class/dmi/id/subsystem/id/product_uuid')
output = pystache.render(version_output_tmpl, version_data).strip()
diff --git a/templates/show/version/all/node.def b/templates/show/version/all/node.def
index 8344124..e98a16d 100644
--- a/templates/show/version/all/node.def
+++ b/templates/show/version/all/node.def
@@ -1,5 +1,5 @@
help: Show VyOS version information plus all packages changes
-run: ${vyatta_bindir}/vyos-show-version
+run: sudo ${vyatta_bindir}/vyos-show-version
echo ""
echo "Package versions:"
dpkg -l
diff --git a/templates/show/version/funny/node.def b/templates/show/version/funny/node.def
index e6544f9..cb1b6b0 100644
--- a/templates/show/version/funny/node.def
+++ b/templates/show/version/funny/node.def
@@ -1,5 +1,5 @@
help: Show VyOS version information plus a funny poem
run:
- ${vyatta_bindir}/vyos-show-version
+ sudo ${vyatta_bindir}/vyos-show-version
${vyatta_bindir}/limericks.py
diff --git a/templates/show/version/node.def b/templates/show/version/node.def
index e2bfc1f..a3fd8af 100644
--- a/templates/show/version/node.def
+++ b/templates/show/version/node.def
@@ -1,2 +1,2 @@
help: Show VyOS version information
-run: ${vyatta_bindir}/vyos-show-version
+run: sudo ${vyatta_bindir}/vyos-show-version