1#!/usr/bin/env python 2 3import gen_print as gp 4import gen_cmd as gc 5import collections 6 7module_names = ['Selenium2Library', 'SeleniumLibrary', 'SSHLibrary', 'requests', 8 'XvfbRobot', 'robotremoteserver', 'redfish'] 9 10import_versions = collections.OrderedDict() 11 12for module_name in module_names: 13 try: 14 cmd_buf = "import " + module_name 15 exec(cmd_buf) 16 cmd_buf = "import_versions['" + module_name + "'] = " + module_name \ 17 + ".__version__" 18 exec(cmd_buf) 19 except ImportError: 20 import_versions[module_name] = "Not installed" 21 22 23def software_versions(): 24 r""" 25 Get the versions for several of the software packages used by 26 openbmc-test-automation and return as a dictionary. 27 28 Example call: 29 ${software_versions}= Software Versions 30 Rprint Vars software_versions 31 32 Example output: 33 software_versions: 34 [python]: Python 2.7.12 35 [robot]: Robot Framework 3.1.2 (Python 3.6.8 on linux) 36 [firefox]: Mozilla Firefox 54.0 37 [google-chrome]: Not installed 38 [Selenium2Library]: 3.0.0 39 [SeleniumLibrary]: 3.3.1 40 [SSHLibrary]: 3.3.0 41 [requests]: 2.22.0 42 [XvfbRobot]: 1.2.2 43 [robotremoteserver]: 1.1 44 [redfish]: 2.1.1 45 [robotframework-angularjs]: 0.0.10 46 [robotframework-scplibrary]: 1.2.0 47 [robotframework-extendedselenium2library]: 0.9.1 48 [host OS]: Ubuntu 16.04.6 LTS 49 """ 50 51 quiet = 1 52 versions = collections.OrderedDict() 53 for package in ['python', 'robot', 'firefox', 'google-chrome']: 54 # Note: "robot --version" returns 0x00000000000000fb. 55 # Note: If package does not exist, 0x7f is returned. 56 rc, version = gc.shell_cmd(package + " --version", 57 valid_rcs=[0, 0x7f, 0xfb]) 58 versions[package] = "Not installed" if rc == 0x7f else version.rstrip('\n') 59 60 versions.update(import_versions) 61 62 for package in ['robotframework-angularjs', 'robotframework-scplibrary', 63 'robotframework-extendedselenium2library']: 64 rc, version = gc.shell_cmd("pip show " + package 65 + " | grep Version | sed -re 's/.*: //g'") 66 versions[package] = "Not installed" if not version else version.rstrip('\n') 67 68 rc, version = gc.shell_cmd("lsb_release -d -s") 69 versions["host OS"] = "Failed" if not version else version.rstrip('\n') 70 return versions 71