def set_lshw_input_data(self): """ KvStoreFactory can not accept a dictionary as direct input and output It will support only JSON, YAML, TOML, INI, PROPERTIES files. So here we are fetching the lshw data and adding that to a file for further execution. """ input_file = None output_file = None response, err, returncode = SimpleProcess("lshw -json").run() if returncode: msg = f"Failed to capture Node support data. Error:{str(err)}" logger.error(self.log.svc_log(msg)) raise ResourceMapError(errno.EINVAL, msg) try: with open(LSHW_FILE, 'w+') as fp: json.dump(json.loads(response.decode("utf-8")), fp, indent=4) with open(MANIFEST_OUTPUT_FILE, 'w+') as fp: json.dump({}, fp, indent=4) input_file = KvStoreFactory.get_instance( f'json://{LSHW_FILE}').load() output_file = KvStoreFactory.get_instance( f'json://{MANIFEST_OUTPUT_FILE}') except Exception as e: msg = "Error in getting {0} file: {1}".format(LSHW_FILE, e) logger.error(self.log.svc_log(msg)) raise ResourceMapError(errno.EINVAL, msg) return input_file, output_file
def test_current_file(file_path): kv_store = KvStoreFactory.get_instance(file_path) data = kv_store.load() return [kv_store, data]
# For any questions about this software or licensing, # please email [email protected] or [email protected]. import os import unittest from cortx.utils import const from cortx.utils.conf_store import Conf from cortx.utils.discovery import Discovery from cortx.utils.discovery.error import DiscoveryError from cortx.utils.kv_store import KvStoreFactory # Load cortx common config store_type = "json" config_url = "%s://%s" % (store_type, const.CORTX_CONF_FILE) common_config = KvStoreFactory.get_instance(config_url) common_config.load() # Load mock data test_dir = os.path.dirname(os.path.realpath(__file__)) health_store_path = os.path.join(test_dir, 'solution/lr2/health.json') manifest_store_path = os.path.join(test_dir, 'solution/lr2/manifest.json') mock_health_data_url = "%s://%s" % (store_type, health_store_path) mock_manifest_data_url = "%s://%s" % (store_type, manifest_store_path) mock_health = "mock-health" mock_manifest = "mock-manifest" Conf.load(mock_health, mock_health_data_url) Conf.load(mock_manifest, mock_manifest_data_url) # Sample rpaths #valid_rpath = "node"
import psutil from datetime import datetime from cortx.utils import const from cortx.utils.conf_store import MappedConf from cortx.utils.kv_store import KvStoreFactory from cortx.utils.discovery.error import DiscoveryError from cortx.utils.discovery.resource import Resource, ResourceFactory # Load cortx common config store_type = "json" cluster_conf = MappedConf(const.CLUSTER_CONF) local_storage_path = cluster_conf.get('cortx>common>storage>local') config_url = "%s://%s" % ( store_type, os.path.join(local_storage_path, 'utils/conf/cortx.conf')) common_config = KvStoreFactory.get_instance(config_url) common_config.load() # Load Discovery request status tracker try: os.makedirs(common_config.get(["discovery>resource_map>location"])[0], exist_ok=True) except PermissionError as err: raise DiscoveryError(errno.EACCES, "Failed to create default store directory. %s" % err) requests_url = "%s://%s" % (store_type, os.path.join( common_config.get([ "discovery>resource_map>location" ])[0], "requests.json")) req_register = KvStoreFactory.get_instance(requests_url)
def init(url: str): """Read from stored config""" Resource._kv = KvStoreFactory.get_instance(url) Resource._kv.load()