diff --git a/neat/locals/manager.py b/neat/locals/manager.py index 47378e3..b02dfcf 100644 --- a/neat/locals/manager.py +++ b/neat/locals/manager.py @@ -210,8 +210,9 @@ def execute(config, state): :return: The updated state dictionary. :rtype: dict(str: *) """ - path = common.build_local_vm_path(config['local_data_directory']) - vm_cpu_mhz = get_local_data(path) + vm_path = common.build_local_vm_path(config['local_data_directory']) + host_path = common.build_local_host_path(config['local_data_directory']) + vm_cpu_mhz = get_local_vm_data(vm_path) vm_ram = get_ram(state['vir_connection'], vm_cpu_mhz.keys()) vm_cpu_mhz = cleanup_vm_data(vm_cpu_mhz, vm_ram.keys()) @@ -317,7 +318,7 @@ def execute(config, state): @contract -def get_local_data(path): +def get_local_vm_data(path): """ Read the data about VMs from the local storage. :param path: A path to read VM UUIDs from. @@ -333,6 +334,21 @@ def get_local_data(path): return result +@contract +def get_local_host_data(path): + """ Read the data about the host from the local storage. + + :param path: A path to read the host data from. + :type path: str + + :return: A history of the host CPU usage in MHz. + :rtype: list(int) + """ + with open(path, 'r') as f: + result = [int(x) for x in f.read().strip().splitlines()] + return result + + @contract def cleanup_vm_data(vm_data, uuids): """ Remove records for the VMs that are not in the list of UUIDs. diff --git a/tests/locals/test_manager.py b/tests/locals/test_manager.py index f0765aa..bb7280a 100644 --- a/tests/locals/test_manager.py +++ b/tests/locals/test_manager.py @@ -78,7 +78,7 @@ class LocalManager(TestCase): assert state['hashed_password'] == sha1('password').hexdigest() @qc(1) - def get_local_data( + def get_local_vm_data( data=dict_( keys=str_(of='abc123-', min_length=36, max_length=36), values=list_(of=int_(min=1, max=3000), @@ -92,9 +92,22 @@ class LocalManager(TestCase): os.mkdir(path) collector.write_vm_data_locally(path, data, 10) - assert manager.get_local_data(path) == data + assert manager.get_local_vm_data(path) == data shutil.rmtree(path) + @qc(1) + def get_local_host_data( + data=list_(of=int_(min=1, max=3000), + min_length=0, max_length=10) + ): + path = os.path.join(os.path.dirname(__file__), + '..', 'resources', 'host') + with open(path, 'w') as f: + f.write('\n'.join([str(x) + for x in data]) + '\n') + assert manager.get_local_host_data(path) == data + os.remove(path) + @qc(10) def cleanup_vm_data( data=dict_(