George Keishing | e7e9171 | 2021-09-03 11:28:44 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Anusha Dathatri | aad48f2 | 2019-08-23 02:01:15 -0500 | [diff] [blame] | 2 | |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 3 | import gen_print as gp |
| 4 | import gen_cmd as gc |
Anusha Dathatri | aad48f2 | 2019-08-23 02:01:15 -0500 | [diff] [blame] | 5 | import collections |
| 6 | |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 7 | module_names = ['Selenium2Library', 'SeleniumLibrary', 'SSHLibrary', 'requests', |
| 8 | 'XvfbRobot', 'robotremoteserver', 'redfish'] |
Anusha Dathatri | aad48f2 | 2019-08-23 02:01:15 -0500 | [diff] [blame] | 9 | |
| 10 | import_versions = collections.OrderedDict() |
| 11 | |
| 12 | for module_name in module_names: |
| 13 | try: |
| 14 | cmd_buf = "import " + module_name |
| 15 | exec(cmd_buf) |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 16 | cmd_buf = "import_versions['" + module_name + "'] = " + module_name \ |
| 17 | + ".__version__" |
Anusha Dathatri | aad48f2 | 2019-08-23 02:01:15 -0500 | [diff] [blame] | 18 | exec(cmd_buf) |
| 19 | except ImportError: |
| 20 | import_versions[module_name] = "Not installed" |
| 21 | |
| 22 | |
| 23 | def 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() |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 53 | for package in ['python', 'python3', 'robot', 'firefox', 'google-chrome']: |
Anusha Dathatri | aad48f2 | 2019-08-23 02:01:15 -0500 | [diff] [blame] | 54 | # Note: "robot --version" returns 0x00000000000000fb. |
| 55 | # Note: If package does not exist, 0x7f is returned. |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 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') |
Anusha Dathatri | aad48f2 | 2019-08-23 02:01:15 -0500 | [diff] [blame] | 59 | |
| 60 | versions.update(import_versions) |
| 61 | |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 62 | for package in ['robotframework-angularjs', 'robotframework-scplibrary', |
| 63 | 'robotframework-extendedselenium2library']: |
| 64 | rc, version = gc.shell_cmd("pip3 show " + package |
| 65 | + " | grep Version | sed -re 's/.*: //g'") |
| 66 | versions[package] = "Not installed" if not version else version.rstrip('\n') |
Anusha Dathatri | aad48f2 | 2019-08-23 02:01:15 -0500 | [diff] [blame] | 67 | |
| 68 | rc, version = gc.shell_cmd("lsb_release -d -s") |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 69 | versions["host OS"] = "Failed" if not version else version.rstrip('\n') |
Anusha Dathatri | aad48f2 | 2019-08-23 02:01:15 -0500 | [diff] [blame] | 70 | return versions |