def test_config_reset(): from copy import deepcopy with mock.patch('common.PQOS_API.get_num_cores') as mock_get_num_cores,\ mock.patch('config.ConfigStore.load') as mock_load,\ mock.patch('caps.mba_supported', return_value = True) as mock_mba,\ mock.patch('caps.cat_l3_supported', return_value = True),\ mock.patch('common.PQOS_API.get_max_l3_cat_cbm', return_value = 0xFFF),\ mock.patch('common.PQOS_API.check_core', return_value = True),\ mock.patch('pid_ops.is_pid_valid', return_value = True): mock_load.return_value = deepcopy(CONFIG) mock_get_num_cores.return_value = 8 config_store = ConfigStore() config_store.from_file("/tmp/appqos_test.config") config_store.process_config() assert len(config_store.get_pool_attr('cores', None)) == 8 assert config_store.get_pool_attr('cbm', 0) == 0xFFF assert config_store.get_pool_attr('mba', 0) == 100 # test get_pool_attr assert config_store.get_pool_attr('non_exisiting_key', None) == None # reset mock and change return values # more cores this time (8 vs. 16) mock_get_num_cores.return_value = 16 mock_get_num_cores.reset_mock() # use CONFIG_NO_MBA this time, as MBA is reported as not supported mock_load.return_value = deepcopy(CONFIG_NO_MBA) mock_load.reset_mock() mock_mba.return_value = False # verify that reset reloads config from file and Default pool is # recreated with different set of cores # (get_num_cores mocked to return different values) config_store.reset() mock_load.assert_called_once_with("/tmp/appqos_test.config") mock_get_num_cores.assert_called_once() assert len(config_store.get_pool_attr('cores', None)) == 16 assert config_store.get_pool_attr('cbm', 0) == 0xFFF assert config_store.get_pool_attr('mba', 0) is None