def test_create_services_from_json_out(): s_list = Service.create_services_from_json(json_file_name=Path( __file__).parent.joinpath("service_example.json").absolute(), ipv4=IPv4Address("127.0.0.1")) assert isinstance(s_list, list), "" assert all([isinstance(s, Service) for s in s_list]), "" assert all([s.get_node_list() for s in s_list]), ""
def test_refresh_measurements(): s = Service(id="APP001") s.add_node(ipv4=IPv4Address("192.168.64.123")) s.refresh_measurements() node_list = s.get_node_list() sn = node_list[0] metrics_list = sn.get_metrics_list() assert isinstance(metrics_list, list), "" assert len(metrics_list) == len(MetricType), "" # assert False, str(s) # def test_metric_json(): # # TODO G: verify that it is possible to create a Metric object from a JSON that represent it. Do the same for ServiceNode and Service classes. # pass
def test_create_single_service(): s = Service(id="APP001") assert isinstance(s, Service), "" assert s.get_id() == "APP001", "" assert is_orchestrator(), "" s.add_node(ipv4=IPv4Address("192.168.64.123")) node_list = s.get_node_list() assert isinstance(node_list, list), "" assert len(node_list) == 1, "" sn = node_list[0] # assert sn.get_id() == "192.168.64.123" assert sn.get_ip() == IPv4Address("192.168.64.123")
def test_refresh(): # SA MAIN sa = SLPFactory.create_SA() srv_list = Service.create_services_from_json(json_file_name=str( Path(__file__).parent.joinpath("service_example.json").absolute()), ipv4=IPv4Address("127.0.0.1")) for srv in srv_list: sa.register_service(srv) #Service cache MAIN sc = ServiceCache() sc.refresh() fnd = sc.get_list() assert all([ ann.__dict__ == fnd[fnd.index(ann)].__dict__ for ann in srv_list ]), "Some found service is different from the registered one" # Run this to catch eventual exceptions for srv in fnd: sa.deregister_service(srv)
def test_SA_and_UA(): # SA MAIN sa = SLPFactory.create_SA() srv_list = Service.create_services_from_json(json_file_name=Path( __file__).parent.joinpath("service_example.json").absolute(), ipv4=IPv4Address("127.0.0.1")) for srv in srv_list: sa.register_service(srv) #UA MAIN ua = SLPFactory.create_UA() fnd = ua.find_all_services() assert all( [ann.__dict__ == fnd[fnd.index(ann)].__dict__ for ann in srv_list]), "" # Run this to catch eventual exceptions for srv in fnd: sa.deregister_service(srv) # Test DA agent # if __name__ == "__main__": # da = SLPFactory.create_DA() # asyncio.get_event_loop().run_forever()
import sys from pathlib import Path sys.path.append(str(Path(__file__).parent.parent.parent.absolute())) # print(sys.path) # Path(__file__) is the path to the current file, .parent is the file's directory, .parent again for the parent directory from src.forch.fo_service import Service from src.forch.fo_slp import SLPFactory from src.forch.fo_zabbix import ZabbixAdapter from ipaddress import IPv4Address import asyncio # SA MAIN sa = SLPFactory.create_SA() srv_list = Service.create_services_from_json(json_file_name=str( Path(__file__).parent.joinpath("service_example.json").absolute()), ipv4=IPv4Address("127.0.0.1")) # GIANLUCAAAAAAAAAAAAAA NON ANDAVA NULLA PERCHé NESSUNO REGISTRAVA I SERVIZI HAHAHAHAHAHA!!! for srv in srv_list: sa.register_service(srv) ua = SLPFactory.create_UA() fnd = ua.find_all_services() print(fnd) print([ann.__dict__ == fnd[fnd.index(ann)].__dict__ for ann in srv_list]) asyncio.get_event_loop().run_forever()
iface_list = ni.interfaces() #ipv4 = ni.ifaddresses('lo')[ni.AF_INET][0]['addr'] for iface in iface_list: for ip in ni.ifaddresses(str(iface))[ni.AF_INET]: ip_list.append(ip['addr']) ip_list = list(set(ip_list)) # parse json files srv_list = [] for json in args.files: for ip in ip_list: srv_list.extend( Service.create_services_from_json(json_file_name=str( Path(__file__).parent.joinpath(json).absolute()), ipv4=ip)) srv_list = Service.aggregate_nodes_of_equal_services(srv_list) da = SLPFactory.create_DA(new_handler=True) input('DA started. Press enter to find services...') sc = ServiceCache(refresh=True) fnd = sc.get_list() # Check found services correctness # passed: bool = True # for ann in srv_list: # try: # fnd_dict = fnd[fnd.index(ann)].__dict__ # except: # print(1)