Skip to content

Commit c8bc003

Browse files
authored
Merge pull request #27 from silenceshell/pytest
add pytest
2 parents de91dd3 + 25fec2b commit c8bc003

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

docker_mirror.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
}
5353
}
5454

55+
5556
def get_dist():
5657
return platform.linux_distribution()[0]
5758

@@ -111,10 +112,11 @@ def set_docker_config(mirror):
111112
f.write(new_line)
112113
f.writelines(options)
113114

115+
114116
def set_docker_config_ce(mirror):
115117
dist = get_dist()
116118
docker_config = get_config_ce(dist)
117-
config_dict={}
119+
config_dict = {}
118120
if os.path.exists(docker_config) != True:
119121
# if file not exist, create it first.
120122
os.mknod(docker_config, 0o644)
@@ -127,6 +129,7 @@ def set_docker_config_ce(mirror):
127129
with open(docker_config, "w") as f:
128130
json.dump(config_dict, f)
129131

132+
130133
def restart_docker_daemon():
131134
execute_sys_cmd("systemctl restart docker")
132135

@@ -136,7 +139,7 @@ def get_speed(mirror, mirror_url):
136139
set_docker_config_ce(mirror_url)
137140
else:
138141
set_docker_config(mirror_url)
139-
142+
140143
restart_docker_daemon()
141144

142145
# try to delete busybox image in case.
@@ -155,7 +158,7 @@ def get_speed(mirror, mirror_url):
155158
execute_sys_cmd("docker rmi registry:2 -f 1> /dev/null 2>&1")
156159

157160
return cost_time
158-
#return 204800 / cost_time
161+
159162

160163
if __name__ == "__main__":
161164
print("restart docker daemon")
@@ -179,11 +182,11 @@ def get_speed(mirror, mirror_url):
179182
restart_count += 1
180183
total_time += cost_time
181184
if restart_count >= 2 and total_time < 60:
182-
#to avoid the error of docker daeom: Start request repeated too quickly
183-
print("oh.. docker daemon restart too quickly, have a rest")
184-
restart_count = 0
185-
total_time = 0
186-
time.sleep(60-total_time)
185+
# to avoid the error of docker daeom: Start request repeated too quickly
186+
print("oh.. docker daemon restart too quickly, have a rest")
187+
restart_count = 0
188+
total_time = 0
189+
time.sleep(60 - total_time)
187190

188191
print("best mirror is: {mirror}, set docker config and restart docker daemon now.".format(mirror=best_mirror))
189192
if "ce" in version:

test_docker_mirror.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import pytest
2+
from docker_mirror import execute_sys_cmd
3+
4+
5+
def test_execute_sys_cmd():
6+
assert execute_sys_cmd("date") == 0

0 commit comments

Comments
 (0)