def check()

in StatusCheck.py [0:0]


def check(launchtype, session, headers, endpoint, HOST, projectname, configfile):
    if launchtype == "test" or launchtype == "cutover":
       with open(os.path.join(sys.path[0], configfile), 'r') as ymlfile:
            config = yaml.load(ymlfile)

    r = requests.get(HOST + endpoint.format('projects'), headers=headers, cookies=session)
    if r.status_code != 200:
        print("ERROR: Failed to fetch the project....")
        sys.exit(1)
    try:
        # Get Project ID
        projects = json.loads(r.text)["items"]
        project_exist = False
        for project in projects:
            if project["name"] == projectname:
               project_id = project["id"]
               project_exist = True
        if project_exist == False:
            print("ERROR: Project Name does not exist....")
            sys.exit(2)
    except:
        print(sys.exc_info())
        sys.exit(6)

    machine_status = 0
    m = requests.get(HOST + endpoint.format('projects/{}/machines').format(project_id), headers=headers, cookies=session)
    for i in range(1, config["project"]["machinecount"]+1):
        index = "machine" + str(i)
        machine_exist = False
        for machine in json.loads(m.text)["items"]:
           if config[index]["machineName"] == machine['sourceProperties']['name']:
              machine_exist = True
              if 'lastConsistencyDateTime' not in machine['replicationInfo']:
                  print("Machine: " + machine['sourceProperties']['name'] + " replication in progress, please wait for a few minutes....")
              else:
                  if launchtype == "test":
                     if 'lastTestLaunchDateTime' in machine["lifeCycle"]:
                        machine_status += 1
                        print("Machine: " + machine['sourceProperties']['name'] + " has been migrated to the TEST environment....")
                     else:
                        print("Machine: " + machine['sourceProperties']['name'] + " has NOT been migrated to the TEST environment, please wait....")
                  elif launchtype == "cutover":
                     if 'lastCutoverDateTime' in machine["lifeCycle"]:
                        machine_status += 1
                        print("Machine: " + machine['sourceProperties']['name'] + " has been migrated to the PROD environment....")
                     else:
                        print("Machine: " + machine['sourceProperties']['name'] + " has NOT been migrated to the PROD environment....")
        if machine_exist == False:
               print("ERROR: Machine: " + config[index]["machineName"] + " does not exist....")

    if machine_status == config["project"]["machinecount"]:
       if launchtype == "test":
           print("All Machines in the config file have been migrated to the TEST environment....")
       if launchtype == "cutover":
           print("All Machines in the config file have been migrated to the PROD environment....")
    else:
       if launchtype == "test":
          print("*WARNING*: Some machines in the config file have NOT been migrated to the TEST environment....")
       if launchtype == "cutover":
          print("*WARNING*: Some machines in the config file have NOT been migrated to the PROD environment....")