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 | |
Anusha Dathatri | aad48f2 | 2019-08-23 02:01:15 -0500 | [diff] [blame] | 3 | import collections |
| 4 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 5 | import gen_cmd as gc |
| 6 | import gen_print as gp |
| 7 | |
| 8 | module_names = [ |
| 9 | "Selenium2Library", |
| 10 | "SeleniumLibrary", |
| 11 | "SSHLibrary", |
| 12 | "requests", |
| 13 | "XvfbRobot", |
| 14 | "robotremoteserver", |
| 15 | "redfish", |
| 16 | ] |
Anusha Dathatri | aad48f2 | 2019-08-23 02:01:15 -0500 | [diff] [blame] | 17 | |
| 18 | import_versions = collections.OrderedDict() |
| 19 | |
| 20 | for module_name in module_names: |
| 21 | try: |
| 22 | cmd_buf = "import " + module_name |
| 23 | exec(cmd_buf) |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 24 | cmd_buf = ( |
| 25 | "import_versions['" |
| 26 | + module_name |
| 27 | + "'] = " |
| 28 | + module_name |
| 29 | + ".__version__" |
| 30 | ) |
Anusha Dathatri | aad48f2 | 2019-08-23 02:01:15 -0500 | [diff] [blame] | 31 | exec(cmd_buf) |
| 32 | except ImportError: |
| 33 | import_versions[module_name] = "Not installed" |
| 34 | |
| 35 | |
| 36 | def software_versions(): |
| 37 | r""" |
| 38 | Get the versions for several of the software packages used by |
| 39 | openbmc-test-automation and return as a dictionary. |
| 40 | |
| 41 | Example call: |
| 42 | ${software_versions}= Software Versions |
| 43 | Rprint Vars software_versions |
| 44 | |
| 45 | Example output: |
| 46 | software_versions: |
| 47 | [python]: Python 2.7.12 |
| 48 | [robot]: Robot Framework 3.1.2 (Python 3.6.8 on linux) |
| 49 | [firefox]: Mozilla Firefox 54.0 |
| 50 | [google-chrome]: Not installed |
| 51 | [Selenium2Library]: 3.0.0 |
| 52 | [SeleniumLibrary]: 3.3.1 |
| 53 | [SSHLibrary]: 3.3.0 |
| 54 | [requests]: 2.22.0 |
| 55 | [XvfbRobot]: 1.2.2 |
| 56 | [robotremoteserver]: 1.1 |
| 57 | [redfish]: 2.1.1 |
| 58 | [robotframework-angularjs]: 0.0.10 |
| 59 | [robotframework-scplibrary]: 1.2.0 |
| 60 | [robotframework-extendedselenium2library]: 0.9.1 |
| 61 | [host OS]: Ubuntu 16.04.6 LTS |
| 62 | """ |
| 63 | |
| 64 | quiet = 1 |
| 65 | versions = collections.OrderedDict() |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 66 | for package in ["python", "python3", "robot", "firefox", "google-chrome"]: |
Anusha Dathatri | aad48f2 | 2019-08-23 02:01:15 -0500 | [diff] [blame] | 67 | # Note: "robot --version" returns 0x00000000000000fb. |
| 68 | # Note: If package does not exist, 0x7f is returned. |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 69 | rc, version = gc.shell_cmd( |
| 70 | package + " --version", valid_rcs=[0, 0x7F, 0xFB] |
| 71 | ) |
| 72 | versions[package] = ( |
| 73 | "Not installed" if rc == 0x7F else version.rstrip("\n") |
| 74 | ) |
Anusha Dathatri | aad48f2 | 2019-08-23 02:01:15 -0500 | [diff] [blame] | 75 | |
| 76 | versions.update(import_versions) |
| 77 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 78 | for package in [ |
| 79 | "robotframework-angularjs", |
| 80 | "robotframework-scplibrary", |
| 81 | "robotframework-extendedselenium2library", |
| 82 | ]: |
| 83 | rc, version = gc.shell_cmd( |
| 84 | "pip3 show " + package + " | grep Version | sed -re 's/.*: //g'" |
| 85 | ) |
| 86 | versions[package] = ( |
| 87 | "Not installed" if not version else version.rstrip("\n") |
| 88 | ) |
Anusha Dathatri | aad48f2 | 2019-08-23 02:01:15 -0500 | [diff] [blame] | 89 | |
| 90 | rc, version = gc.shell_cmd("lsb_release -d -s") |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 91 | versions["host OS"] = "Failed" if not version else version.rstrip("\n") |
Anusha Dathatri | aad48f2 | 2019-08-23 02:01:15 -0500 | [diff] [blame] | 92 | return versions |