Skip to content

Commit

Permalink
Fix kv import error on devserver / Sandcastle
Browse files Browse the repository at this point in the history
Summary:
Netcastle test suite uses `cit_runner.py --list-tests` to generate a list of tests. This happens at the beginning of the CIT workflow, and thus before any QEMU machine is initialized so it is expected that we run this from our repo checkout on the devserver / Sandcastle machine

This can cause problems if a unittest file has an import that is not in our local python env, as has been happening with montblanc:
```
Traceback (most recent call last):
  File "/usr/local/fbcode/platform010/lib/python3.10/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/local/fbcode/platform010/lib/python3.10/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/data/sandcastle/boxes/trunk-git-openbmc/tests2/tests/montblanc/test_kv.py", line 24, in <module>
    from kv import FPERSIST, kv_get
ModuleNotFoundError: No module named 'kv'
```

Test Plan:
Ensure that cit_runner.py no longer fails on devserver, and correctly lists kv tests
```
$ python3 tests2/cit_runner.py --platform montblanc --list-tests --start-dir tests2/tests/ --denylist tests2/qemu_denylist.txt

tests.montblanc.test_bmc_mac.BMCMacTest.test_bmc_mac
tests.montblanc.test_bmc_mac.BMCMacTest.test_bmc_mac_oui
tests.montblanc.test_busybox_syntax.BusyBoxSyntaxTest.test_busybox_usage_strings
tests.montblanc.test_cpu_utilization.CpuUtilizationTest.test_cpu_utilization
tests.montblanc.test_eeprom.CHASSISEepromTest.test_asset_tag
tests.montblanc.test_eeprom.CHASSISEepromTest.test_extended_mac_base
tests.montblanc.test_eeprom.CHASSISEepromTest.test_local_mac
tests.montblanc.test_eeprom.CHASSISEepromTest.test_location_on_fabric
tests.montblanc.test_eeprom.CHASSISEepromTest.test_odm_pcb
tests.montblanc.test_eeprom.CHASSISEepromTest.test_product_name
tests.montblanc.test_eeprom.CHASSISEepromTest.test_product_part_number
tests.montblanc.test_eeprom.CHASSISEepromTest.test_product_serial_number
tests.montblanc.test_eeprom.CHASSISEepromTest.test_system_manufacturer
tests.montblanc.test_eeprom.CHASSISEepromTest.test_version
tests.montblanc.test_eeprom.SCMEepromTest.test_asset_tag
tests.montblanc.test_eeprom.SCMEepromTest.test_extended_mac_base
tests.montblanc.test_eeprom.SCMEepromTest.test_local_mac
tests.montblanc.test_eeprom.SCMEepromTest.test_location_on_fabric
tests.montblanc.test_eeprom.SCMEepromTest.test_odm_pcb
tests.montblanc.test_eeprom.SCMEepromTest.test_product_name
tests.montblanc.test_eeprom.SCMEepromTest.test_product_part_number
tests.montblanc.test_eeprom.SCMEepromTest.test_product_serial_number
tests.montblanc.test_eeprom.SCMEepromTest.test_system_manufacturer
tests.montblanc.test_eeprom.SCMEepromTest.test_version
tests.montblanc.test_fw_env.TestFwEnv.test_fw_printenv_noheader_status
tests.montblanc.test_fw_env.TestFwEnv.test_fw_printenv_status
tests.montblanc.test_fw_env.TestFwEnv.test_fw_setenv
tests.montblanc.test_gpio.GpioTest.test_gpios
tests.montblanc.test_host_mac.HostMacTest.test_host_mac
tests.montblanc.test_host_mac.HostMacTest.test_host_mac_zero_test
tests.montblanc.test_i2c.I2cTest.test_i2c_tree
tests.montblanc.test_i2c_driver_presence.MontblancI2cDriverPresenceTest.test_i2c_driver_presence
tests.montblanc.test_interface.InterfaceTest.test_eth0_v4_interface
tests.montblanc.test_interface.InterfaceTest.test_eth0_v6_interface
tests.montblanc.test_interface.InterfaceTest.test_usb0_v6_interface
tests.montblanc.test_interface.InterfaceTest.test_usb0_v6_x86_interface
tests.montblanc.test_kernel_abi.KernelABITest.test_kernel_path_exists
tests.montblanc.test_kernel_module_presence.KernelModulePresenceTest.test_installed_kmods
tests.montblanc.test_kv.KvTest.test_kv_get_key
tests.montblanc.test_kv.KvTest.test_kv_path_exists
tests.montblanc.test_process_restart.ProcessRestartTest.test_process_restarts
tests.montblanc.test_process_running.ProcessRunningTest.test_installed_processes
tests.montblanc.test_rest_endpoint.RestEndpointTest.test_endpoint_api
tests.montblanc.test_rest_endpoint.RestEndpointTest.test_endpoint_api_sys
tests.montblanc.test_rest_endpoint.RestEndpointTest.test_endpoint_api_sys_bmc
tests.montblanc.test_rest_endpoint.RestEndpointTest.test_endpoint_api_sys_bmc_mtd
tests.montblanc.test_rest_endpoint.RestEndpointTest.test_endpoint_api_sys_bmc_secondary_boot
tests.montblanc.test_rest_endpoint.RestEndpointTest.test_endpoint_api_sys_fc_present
tests.montblanc.test_rest_endpoint.RestEndpointTest.test_endpoint_api_sys_firmware_info_all
tests.montblanc.test_rest_endpoint.RestEndpointTest.test_endpoint_api_sys_mb
tests.montblanc.test_rest_endpoint.RestEndpointTest.test_endpoint_api_sys_mb_fruid
tests.montblanc.test_rest_endpoint.RestEndpointTest.test_endpoint_api_sys_sensors
tests.montblanc.test_rest_endpoint.RestEndpointTest.test_endpoint_api_sys_server
tests.montblanc.test_rest_endpoint.RestEndpointTest.test_server_httperror_code_404
tests.montblanc.test_spi_driver_presence.SpiDriverPresenceTest.test_spi_driver_presence
tests.montblanc.test_syslog.TestSyslog.test_syslog_logs
tests.montblanc.test_syslog_restart.SyslogRestartTest.test_syslog_restart_no_duplicates
tests.montblanc.test_syslog_restart.SyslogRestartTest.test_syslog_restart_pid_changed
```

Reviewed By: williamspatrick

Differential Revision: D59679477

fbshipit-source-id: 71f799efabb997232a2c0d0e881f6bbbfaea43c2
  • Loading branch information
cjcon90 authored and facebook-github-bot committed Jul 12, 2024
1 parent 319c325 commit ccf6e83
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tests2/tests/montblanc/test_kv.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@
# 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
import os
import unittest

from common.base_kv_test import BaseKvTest

from kv import FPERSIST, kv_get
from utils.test_utils import qemu_check

# We should only expect to have kv in python env on BMC
# ignore import error for devserver / Sandcastle
try:
from kv import FPERSIST, kv_get
except ModuleNotFoundError:
if os.getuid() == 0:
raise


@unittest.skipIf(qemu_check(), "test env is QEMU, skipped")
class KvTest(BaseKvTest, unittest.TestCase):
Expand Down

0 comments on commit ccf6e83

Please sign in to comment.