|
8 | 8 |
|
9 | 9 | def get_token(nifi_host, username, password): |
10 | 10 | nifi_headers = { |
11 | | - 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', |
| 11 | + "content-type": "application/x-www-form-urlencoded; charset=UTF-8", |
12 | 12 | } |
13 | | - data = {'username': username, 'password': password} |
| 13 | + data = {"username": username, "password": password} |
14 | 14 |
|
15 | 15 | # TODO: handle actual errors when connecting properly |
16 | | - nifi_url = nifi_host + '/nifi-api/access/token' |
17 | | - response = requests.post(nifi_url, headers=nifi_headers, data=data, verify=False) # , cert='./tmp/cacert.pem') |
| 16 | + nifi_url = nifi_host + "/nifi-api/access/token" |
| 17 | + response = requests.post( |
| 18 | + nifi_url, headers=nifi_headers, data=data, verify=False |
| 19 | + ) # , cert='./tmp/cacert.pem') |
18 | 20 |
|
19 | 21 | if response.ok: |
20 | | - nifi_token = response.content.decode('utf-8') |
| 22 | + nifi_token = response.content.decode("utf-8") |
21 | 23 | return "Bearer " + nifi_token |
22 | 24 | else: |
23 | 25 | print(f"Failed to get token: {response.status_code}: {response.content}") |
24 | 26 | exit(-1) |
25 | 27 |
|
26 | 28 |
|
27 | | -if __name__ == '__main__': |
| 29 | +if __name__ == "__main__": |
28 | 30 | # Construct an argument parser |
29 | 31 | all_args = argparse.ArgumentParser() |
30 | 32 |
|
31 | 33 | # Add arguments to the parser |
32 | | - all_args.add_argument("-u", "--user", required=True, |
33 | | - help="Username to connect as") |
34 | | - all_args.add_argument("-p", "--password", required=True, |
35 | | - help="Password for the user") |
36 | | - all_args.add_argument("-n", "--namespace", required=True, |
37 | | - help="Namespace the test is running in") |
38 | | - all_args.add_argument("-c", "--count", required=True, |
39 | | - help="The expected number of Nodes") |
| 34 | + all_args.add_argument("-u", "--user", required=True, help="Username to connect as") |
| 35 | + all_args.add_argument( |
| 36 | + "-p", "--password", required=True, help="Password for the user" |
| 37 | + ) |
| 38 | + all_args.add_argument( |
| 39 | + "-n", "--namespace", required=True, help="Namespace the test is running in" |
| 40 | + ) |
| 41 | + all_args.add_argument( |
| 42 | + "-c", "--count", required=True, help="The expected number of Nodes" |
| 43 | + ) |
40 | 44 | args = vars(all_args.parse_args()) |
41 | 45 |
|
42 | 46 | # disable warnings as we have specified non-verified https connections |
43 | 47 | urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) |
44 | 48 |
|
45 | | - host = f"https://test-nifi-node-default-1.test-nifi-node-default.{args['namespace']}.svc.cluster.local:8443" |
46 | | - token = get_token(host, args['user'], args['password']) |
47 | | - headers = {'Authorization': token} |
48 | | - node_count = int(args['count']) |
| 49 | + host = f"https://test-nifi-node-default-1.test-nifi-node-default-metrics.{args['namespace']}.svc.cluster.local:8443" |
| 50 | + token = get_token(host, args["user"], args["password"]) |
| 51 | + headers = {"Authorization": token} |
| 52 | + node_count = int(args["count"]) |
49 | 53 |
|
50 | 54 | x = 0 |
51 | 55 | while x < 15: |
52 | | - url = host + '/nifi-api/controller/cluster' |
53 | | - cluster = requests.get(url, headers=headers, verify=False) # , cert='/tmp/cacert.pem') |
| 56 | + url = host + "/nifi-api/controller/cluster" |
| 57 | + cluster = requests.get( |
| 58 | + url, headers=headers, verify=False |
| 59 | + ) # , cert='/tmp/cacert.pem') |
54 | 60 | if cluster.status_code != 200: |
55 | 61 | print("Waiting for cluster...") |
56 | 62 | else: |
57 | | - cluster_data = json.loads(cluster.content.decode('utf-8')) |
58 | | - nodes = cluster_data['cluster']['nodes'] |
| 63 | + cluster_data = json.loads(cluster.content.decode("utf-8")) |
| 64 | + nodes = cluster_data["cluster"]["nodes"] |
59 | 65 | if len(nodes) != node_count: |
60 | | - print(f"Cluster should have {node_count} nodes at this stage, but has: {len(nodes)}") |
| 66 | + print( |
| 67 | + f"Cluster should have {node_count} nodes at this stage, but has: {len(nodes)}" |
| 68 | + ) |
61 | 69 | else: |
62 | 70 | connected = True |
63 | 71 | for node in nodes: |
64 | | - if node['status'] != "CONNECTED": |
65 | | - print(f"Node {node['nodeId']} is in state {node['status']} but should have been CONNECTED") |
| 72 | + if node["status"] != "CONNECTED": |
| 73 | + print( |
| 74 | + f"Node {node['nodeId']} is in state {node['status']} but should have been CONNECTED" |
| 75 | + ) |
66 | 76 | connected = False |
67 | 77 | if connected: |
68 | 78 | print("Test succeeded!") |
|
0 commit comments