def test_FP(): res = FFun(NornirObj, FP="192.168.1.0/24, 192.168.2.144/31") res_dict = res.dict() hosts_dict = res_dict.get("inventory", {}).get("hosts") # pprint.pprint(hosts_dict) assert hosts_dict == {'R1': {'connection_options': {}, 'data': {'role': 'core', 'site': 'B1'}, 'groups': ['lab'], 'hostname': '192.168.1.151', 'name': 'R1', 'password': '******', 'platform': 'ios', 'port': None, 'username': '******'}, 'R2': {'connection_options': {}, 'data': {'role': 'agg', 'site': 'B2'}, 'groups': ['lab'], 'hostname': '192.168.1.153', 'name': 'R2', 'password': '******', 'platform': 'ios', 'port': None, 'username': '******'}, 'SW1': {'connection_options': {}, 'data': {'role': 'access', 'site': 'B3'}, 'groups': ['lab', 'pod1'], 'hostname': '192.168.2.144', 'name': 'SW1', 'password': '******', 'platform': 'nxos_ssh', 'port': None, 'username': '******'}}
def test_FB(): res = FFun(NornirObj, FB="R[12]") res_dict = res.dict() hosts_dict = res_dict.get("inventory", {}).get("hosts") pprint.pprint(hosts_dict) assert hosts_dict == { "R1": { "connection_options": {}, "data": {"role": "core", "site": "B1"}, "groups": ["lab"], "hostname": "192.168.1.151", "name": "R1", "password": None, "platform": "ios", "port": None, "username": None, }, "R2": { "connection_options": {}, "data": {"role": "agg", "site": "B2"}, "groups": ["lab"], "hostname": "192.168.1.153", "name": "R2", "password": None, "platform": "ios", "port": None, "username": None, }, }
def test_FL(): res = FFun(NornirObj, FL="R1, SW1") res_dict = res.dict() hosts_dict = res_dict.get("inventory", {}).get("hosts") # pprint.pprint(hosts_dict) assert hosts_dict == { "R1": { "connection_options": {}, "data": {"role": "core", "site": "B1"}, "groups": ["lab"], "hostname": "192.168.1.151", "name": "R1", "password": None, "platform": "ios", "port": None, "username": None, }, "SW1": { "connection_options": {}, "data": {"role": "access", "site": "B3"}, "groups": ["lab", "pod1"], "hostname": "192.168.2.144", "name": "SW1", "password": None, "platform": "nxos_ssh", "port": None, "username": None, }, }
def test_FO_list_of_dict(): res = FFun(NornirObj, FO=[{"role": "agg", "platform": "ios"}, {"site": "B3"}]) res_dict = res.dict() hosts_dict = res_dict.get("inventory", {}).get("hosts") # pprint.pprint(hosts_dict) assert hosts_dict == {'R2': {'connection_options': {}, 'data': {'role': 'agg', 'site': 'B2'}, 'groups': ['lab'], 'hostname': '192.168.1.153', 'name': 'R2', 'password': '******', 'platform': 'ios', 'port': None, 'username': '******'}, 'R3': {'connection_options': {}, 'data': {'role': 'agg', 'site': 'B3'}, 'groups': ['lab'], 'hostname': '192.168.2.154', 'name': 'R3', 'password': '******', 'platform': 'ios', 'port': None, 'username': '******'}, 'SW1': {'connection_options': {}, 'data': {'role': 'access', 'site': 'B3'}, 'groups': ['lab', 'pod1'], 'hostname': '192.168.2.144', 'name': 'SW1', 'password': '******', 'platform': 'nxos_ssh', 'port': None, 'username': '******'}}
def test_FG(): res = FFun(NornirObj, FG="pod1") res_dict = res.dict() hosts_dict = res_dict.get("inventory", {}).get("hosts") # pprint.pprint(hosts_dict) assert hosts_dict == {'SW1': {'connection_options': {}, 'data': {'role': 'access', 'site': 'B3'}, 'groups': ['lab', 'pod1'], 'hostname': '192.168.2.144', 'name': 'SW1', 'password': '******', 'platform': 'nxos_ssh', 'port': None, 'username': '******'}}
def test_FB_FG_FP_FO(): res = FFun(NornirObj, FB="R*", FG="lab", FP="192.168.1.0/24", FO={"role": "core"}) res_dict = res.dict() hosts_dict = res_dict.get("inventory", {}).get("hosts") # pprint.pprint(hosts_dict) assert hosts_dict == {'R1': {'connection_options': {}, 'data': {'role': 'core', 'site': 'B1'}, 'groups': ['lab'], 'hostname': '192.168.1.151', 'name': 'R1', 'password': '******', 'platform': 'ios', 'port': None, 'username': '******'}} # test_FB_FG_FP_FO()
def test_FB_FG_FP_FO(): res = FFun(NornirObj, FB="R*", FG="lab", FP="192.168.1.0/24", FO={"role": "core"}) res_dict = res.dict() hosts_dict = res_dict.get("inventory", {}).get("hosts") # pprint.pprint(hosts_dict) assert hosts_dict == { "R1": { "connection_options": {}, "data": {"role": "core", "site": "B1"}, "groups": ["lab"], "hostname": "192.168.1.151", "name": "R1", "password": None, "platform": "ios", "port": None, "username": None, } }
def test_FO_list_of_dict(): res = FFun(NornirObj, FO=[{"role": "agg", "platform": "ios"}, {"site": "B3"}]) res_dict = res.dict() hosts_dict = res_dict.get("inventory", {}).get("hosts") # pprint.pprint(hosts_dict) assert hosts_dict == { "R2": { "connection_options": {}, "data": {"role": "agg", "site": "B2"}, "groups": ["lab"], "hostname": "192.168.1.153", "name": "R2", "password": None, "platform": "ios", "port": None, "username": None, }, "R3": { "connection_options": {}, "data": {"role": "agg", "site": "B3"}, "groups": ["lab"], "hostname": "192.168.2.154", "name": "R3", "password": None, "platform": "ios", "port": None, "username": None, }, "SW1": { "connection_options": {}, "data": {"role": "access", "site": "B3"}, "groups": ["lab", "pod1"], "hostname": "192.168.2.144", "name": "SW1", "password": None, "platform": "nxos_ssh", "port": None, "username": None, }, }
def test_FB(): res = FFun(NornirObj, FB="R[12]") res_dict = res.dict() hosts_dict = res_dict.get("inventory", {}).get("hosts") # pprint.pprint(hosts_dict) assert hosts_dict == {'R1': {'connection_options': {}, 'data': {'role': 'core', 'site': 'B1'}, 'groups': ['lab'], 'hostname': '192.168.1.151', 'name': 'R1', 'password': '******', 'platform': 'ios', 'port': None, 'username': '******'}, 'R2': {'connection_options': {}, 'data': {'role': 'agg', 'site': 'B2'}, 'groups': ['lab'], 'hostname': '192.168.1.153', 'name': 'R2', 'password': '******', 'platform': 'ios', 'port': None, 'username': '******'}}