Skip to content

Commit d052fdc

Browse files
committed
applied black, autoflake, isort
black - for formatting autoflake - to remove unused imports isort - to sort the imports added tox file to check at the gate Signed-off-by: rakeshgm <[email protected]>
1 parent c4063c5 commit d052fdc

File tree

278 files changed

+17051
-12082
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

278 files changed

+17051
-12082
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*.idea/
33
*.xml
44
*.vscode
5+
*.tox
56

67
# Byte-compiled
78
__pycache__/

.isort.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[settings]
2+
multi_line_output = 3
3+
include_trailing_comma = True
4+
force_grid_wrap = 0
5+
use_parentheses = True
6+
ensure_newline_before_comments = True
7+
line_length = 88

calamari/api_test_cases/codify.py

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
1-
from utils.utils import get_calamari_config
2-
import argparse, os
3-
import libs.log as log
4-
import test_cli, test_config, test_crush_map, test_crush_rule, test_crush_rule_set, test_crush_type, test_event, \
5-
test_log, test_info, test_mon, test_osd, test_osd_config, test_pool, test_salt_key, test_server, test_sync, \
6-
test_user
7-
from shutil import copyfile
1+
import argparse
2+
import os
83
import sys
94
import time
5+
from shutil import copyfile
106

11-
if __name__ == '__main__':
7+
import libs.log as log
8+
import test_cli
9+
import test_config
10+
import test_crush_map
11+
import test_crush_rule
12+
import test_crush_rule_set
13+
import test_crush_type
14+
import test_event
15+
import test_info
16+
import test_log
17+
import test_mon
18+
import test_osd
19+
import test_osd_config
20+
import test_pool
21+
import test_salt_key
22+
import test_server
23+
import test_sync
24+
import test_user
25+
from utils.utils import get_calamari_config
26+
27+
if __name__ == "__main__":
1228

13-
parser = argparse.ArgumentParser(description='Calamari API Automation')
29+
parser = argparse.ArgumentParser(description="Calamari API Automation")
1430

15-
parser.add_argument('-c', dest="config", default='config.yaml',
16-
help='calamari config file: yaml file')
31+
parser.add_argument(
32+
"-c",
33+
dest="config",
34+
default="config.yaml",
35+
help="calamari config file: yaml file",
36+
)
1737

1838
args = parser.parse_args()
1939

@@ -50,25 +70,32 @@
5070

5171
all_tests_exec = [test for test in tests]
5272

53-
log.info('-------------------- Summary -------------------------')
73+
log.info("-------------------- Summary -------------------------")
5474

55-
log.info('--------- Passed ----------')
75+
log.info("--------- Passed ----------")
5676

57-
passed = [log.info('\nTest id: %s\nAPI: %s\n---------' % (passed['id'], passed['name']))
58-
for passed in all_tests_exec if passed['status']]
77+
passed = [
78+
log.info("\nTest id: %s\nAPI: %s\n---------" % (passed["id"], passed["name"]))
79+
for passed in all_tests_exec
80+
if passed["status"]
81+
]
5982

60-
log.info('--------- Failed ----------')
83+
log.info("--------- Failed ----------")
6184

62-
failed = [log.info('\nTest id: %s\nAPI: %s\n---------' % (failed['id'], failed['name']))
63-
for failed in all_tests_exec if not failed['status']]
85+
failed = [
86+
log.info("\nTest id: %s\nAPI: %s\n---------" % (failed["id"], failed["name"]))
87+
for failed in all_tests_exec
88+
if not failed["status"]
89+
]
6490

65-
log.info('--------------->Total Tests Passed: %s' % len(passed))
66-
log.info('--------------->Total Tests Failed: %s' % len(failed))
91+
log.info("--------------->Total Tests Passed: %s" % len(passed))
92+
log.info("--------------->Total Tests Failed: %s" % len(failed))
6793

68-
print 'copying the log file to the log location defined'
94+
print "copying the log file to the log location defined"
6995

70-
copyfile(log.LOG_NAME,
71-
os.path.join(calamari_config['log_copy_location'], log.LOG_NAME))
96+
copyfile(
97+
log.LOG_NAME, os.path.join(calamari_config["log_copy_location"], log.LOG_NAME)
98+
)
7299

73100
if len(failed) > 0:
74101
sys.exit(1)

calamari/api_test_cases/dry.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,50 @@
1-
import requests
21
import json
32

4-
if __name__ == '__main__':
3+
import requests
4+
5+
if __name__ == "__main__":
56
client = requests.session()
67

7-
ip = "" # ip address
8+
ip = "" # ip address
89
port = "8002" # port number
910
username = "" # calamari login username
1011
password = "" # calamari login password
1112

12-
base_url = 'https://%s:%s/api/v2/' % (ip, port)
13+
base_url = "https://%s:%s/api/v2/" % (ip, port)
1314

1415
# login
1516

16-
login_url = base_url + 'auth/login/'
17-
login_data = {'username': username, 'password': password, 'next': '/'}
17+
login_url = base_url + "auth/login/"
18+
login_data = {"username": username, "password": password, "next": "/"}
1819
response = client.post(login_url, login_data, verify=False)
19-
token = response.cookies['XSRF-TOKEN']
20-
headers = {'X-XSRF-TOKEN': token}
20+
token = response.cookies["XSRF-TOKEN"]
21+
headers = {"X-XSRF-TOKEN": token}
2122

2223
if response.status_code == 200:
2324
print "logged in"
2425

2526
# get fsid
2627

27-
url = base_url + 'cluster'
28+
url = base_url + "cluster"
2829
print url
2930
response = client.get(url, verify=False)
3031
response.raise_for_status()
31-
fsid = json.loads(response.content)[0]['id']
32+
fsid = json.loads(response.content)[0]["id"]
3233
print "got fsid"
3334

3435
# cli url
3536

3637
url = base_url + "cluster" + "/" + fsid + "/cli"
3738
print url
3839
data1 = {"command": ["ceph", "osd", "tree"]}
39-
headers['Referer'] = url
40+
headers["Referer"] = url
4041
response = client.post(url, data=data1, verify=False, headers=headers)
4142
response.raise_for_status()
4243
print response.content
4344

4445
data2 = {"command": "ceph osd tree"}
45-
headers['Referer'] = url
46+
headers["Referer"] = url
4647
response = client.post(url, data=data2, verify=False, headers=headers)
4748
response.raise_for_status()
4849

4950
print response.content
50-
51-
52-
53-

calamari/api_test_cases/generate_config.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
1-
import yaml
21
import argparse
32

3+
import yaml
4+
45
"""
56
Example arguments :
67
python generate_config.py -http https -ip 10.8.128.63 -port 8002 -u admin -p admin123 -log /tmp/logs
78
"""
89

9-
if __name__ == '__main__':
10+
if __name__ == "__main__":
1011

11-
parser = argparse.ArgumentParser(description='Calamari API Automation configuration')
12+
parser = argparse.ArgumentParser(
13+
description="Calamari API Automation configuration"
14+
)
1215

13-
parser.add_argument('-http', dest="http", default="https",
14-
help='Input type of the protocol: http or https')
16+
parser.add_argument(
17+
"-http",
18+
dest="http",
19+
default="https",
20+
help="Input type of the protocol: http or https",
21+
)
1522

16-
parser.add_argument('-ip', dest='ip', help='Enter IP address')
23+
parser.add_argument("-ip", dest="ip", help="Enter IP address")
1724

18-
parser.add_argument('-port', dest='port', help='Enter port number')
25+
parser.add_argument("-port", dest="port", help="Enter port number")
1926

20-
parser.add_argument('-u', dest='uname', help='Enter calamari username')
27+
parser.add_argument("-u", dest="uname", help="Enter calamari username")
2128

22-
parser.add_argument('-p', dest='pwd', default='8002', help='Enter calamari password')
29+
parser.add_argument(
30+
"-p", dest="pwd", default="8002", help="Enter calamari password"
31+
)
2332

24-
parser.add_argument('-log', dest='log', default='/tmp/log',
25-
help='Enter log copy location')
33+
parser.add_argument(
34+
"-log", dest="log", default="/tmp/log", help="Enter log copy location"
35+
)
2636

2737
args = parser.parse_args()
2838

@@ -33,10 +43,9 @@
3343
port=args.port,
3444
username=args.uname,
3545
password=args.pwd,
36-
log_copy_location=args.log
46+
log_copy_location=args.log,
3747
)
3848
)
3949

40-
with open('config.yaml', 'w') as outfile:
50+
with open("config.yaml", "w") as outfile:
4151
outfile.write(yaml.dump(data, default_flow_style=False))
42-

calamari/api_test_cases/http_ops.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1+
import traceback
2+
13
import libs.log as log
24
from libs.http_client import HTTPRequest
35
from libs.request import APIRequest
4-
import traceback
56
from utils.utils import check_request_id, clean_response
67

78

89
class Initialize(object):
9-
1010
def __init__(self, **config):
1111

12-
self.http_request = HTTPRequest(config['http'], config['ip'], config['port'], config['username'], config['password'])
12+
self.http_request = HTTPRequest(
13+
config["http"],
14+
config["ip"],
15+
config["port"],
16+
config["username"],
17+
config["password"],
18+
)
1319

1420
assert self.http_request.login(), "login failed"
1521

@@ -28,46 +34,46 @@ def get(self, url):
2834
return cleaned_response
2935

3036
except Exception:
31-
log.error('\n%s' % traceback.format_exc())
37+
log.error("\n%s" % traceback.format_exc())
3238
raise AssertionError
3339

3440
def post(self, url, data, request_api=True):
3541

3642
try:
3743

38-
log.info('data to post:\n%s' % data)
44+
log.info("data to post:\n%s" % data)
3945

4046
response = self.http_request.post(url, data)
4147

4248
cleaned_response = clean_response(response)
4349

4450
if request_api:
4551

46-
check_request_id(self.api_request, cleaned_response['request_id'])
52+
check_request_id(self.api_request, cleaned_response["request_id"])
4753

4854
return cleaned_response
4955

5056
except Exception:
51-
log.error('\n%s' % traceback.format_exc())
57+
log.error("\n%s" % traceback.format_exc())
5258
raise AssertionError
5359

5460
def patch(self, url, data, request_api=True):
5561

5662
try:
5763

58-
log.info('data to patch\n %s' % data)
64+
log.info("data to patch\n %s" % data)
5965

6066
response = self.http_request.patch(url, data)
6167

6268
cleaned_response = clean_response(response)
6369

6470
if request_api:
65-
check_request_id(self.api_request, cleaned_response['request_id'])
71+
check_request_id(self.api_request, cleaned_response["request_id"])
6672

6773
return cleaned_response
6874

6975
except Exception:
70-
log.error('\n%s' % traceback.format_exc())
76+
log.error("\n%s" % traceback.format_exc())
7177
raise AssertionError
7278

7379
def delete(self, url, request_api=True):
@@ -79,10 +85,10 @@ def delete(self, url, request_api=True):
7985
cleaned_response = clean_response(response)
8086

8187
if request_api:
82-
check_request_id(self.api_request, cleaned_response['request_id'])
88+
check_request_id(self.api_request, cleaned_response["request_id"])
8389

8490
return cleaned_response
8591

8692
except Exception:
87-
log.error('\n%s' % traceback.format_exc())
93+
log.error("\n%s" % traceback.format_exc())
8894
raise AssertionError

0 commit comments

Comments
 (0)