Skip to content

Commit cf4c4e9

Browse files
author
Naor Livne
committed
upgrading to python3.7
1 parent 6c5d055 commit cf4c4e9

File tree

7 files changed

+58
-57
lines changed

7 files changed

+58
-57
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: python
2+
dist: xenial
23
python:
3-
- "2.7"
4+
- "3.7"
45
install:
56
- pip install -r requirements.txt
67
script:

CONTRIBUTING

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ can help
77

88
* Fork the latest branch of the component you want to contribute to
99
* Make sure you have a [GitHub account](https://github.com/signup/free)
10-
* Use virtualenv to install all requirements from the requirements.txt file, this will require having GCC compiler, python2-dev & linux-headers depending on your environment setup due to psutil requiring compilation on some OS.
10+
* Use virtualenv to install all requirements from the requirements.txt file, this will require having GCC compiler, python3-dev & linux-headers depending on your environment setup due to psutil requiring compilation on some OS.
1111
* Fix the issue you want \ add a feature
1212
* Create a pull request
1313

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# it's offical so i'm using it + alpine so damn small
2-
FROM python:2.7.15-alpine3.9
2+
FROM python:3.7.2-alpine3.9
33

44
# copy the codebase
55
COPY . /worker
66

77
# install required packages - requires build-base due to psutil GCC complier requirements
8-
RUN apk add --no-cache build-base python2-dev linux-headers
8+
RUN apk add --no-cache build-base python3-dev linux-headers
99
RUN pip install -r /worker/requirements.txt
1010

1111
#set python to be unbuffered

functions/docker_engine/docker_engine.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ def list_containers(self, app_name=""):
2525
try:
2626
return self.cli.containers(filters={"label": "orchestrator=nebula"})
2727
except Exception as e:
28-
print >> sys.stderr, e
28+
print(e, file=sys.stderr)
2929
print("failed getting list of all containers")
3030
os._exit(2)
3131
else:
3232
try:
3333
app_label = "app_name=" + app_name
3434
return self.cli.containers(filters={"label": [app_label, "orchestrator=nebula"]}, all=True)
3535
except Exception as e:
36-
print >> sys.stderr, e
36+
print(e, file=sys.stderr)
3737
print("failed getting list of containers where label is app_name=" + app_name)
3838
os._exit(2)
3939

@@ -59,7 +59,7 @@ def check_container_healthy(self, container_id):
5959
# it's health as a non existing container who's status is non existing is in the require state and therefor
6060
# can be considered healthy.
6161
except Exception as e:
62-
print >> sys.stderr, e
62+
print(e, file=sys.stderr)
6363
print("failed getting health status of container " + container_id)
6464
container_healthy = True
6565
return container_healthy
@@ -70,9 +70,9 @@ def registry_login(self, registry_user=None, registry_pass=None, registry_host="
7070
registry_pass != "skip":
7171
print("logging in to registry")
7272
try:
73-
print self.cli.login(username=registry_user, password=registry_pass, registry=registry_host)
73+
print(self.cli.login(username=registry_user, password=registry_pass, registry=registry_host))
7474
except Exception as e:
75-
print >> sys.stderr, e
75+
print(e, file=sys.stderr)
7676
print("problem logging into registry")
7777
os._exit(2)
7878
else:
@@ -82,21 +82,21 @@ def registry_login(self, registry_user=None, registry_pass=None, registry_host="
8282
def pull_image(self, image_name, version_tag="latest"):
8383
print("pulling image " + image_name + ":" + str(version_tag))
8484
try:
85-
print image_name
85+
print(image_name)
8686
for line in self.cli.pull(image_name, str(version_tag), stream=True):
8787
print(json.dumps(json.loads(line), indent=4))
8888
except Exception as e:
89-
print >> sys.stderr, e
89+
print(e, file=sys.stderr)
9090
print("problem pulling image " + image_name + ":" + str(version_tag))
9191
os._exit(2)
9292

9393
# prune unused images
9494
def prune_images(self):
9595
print("pruning unused images")
9696
try:
97-
print self.cli.prune_images()
97+
print(self.cli.prune_images())
9898
except Exception as e:
99-
print >> sys.stderr, e
99+
print(e, file=sys.stderr)
100100
print("problem pruning unused image")
101101
os._exit(2)
102102

@@ -111,16 +111,16 @@ def create_container(self, app_name, container_name, image_name, host_configurat
111111
"orchestrator": "nebula"},
112112
networking_config=self.create_networking_config(
113113
default_network))
114-
print("successfully created container " + container_name)
114+
print(("successfully created container " + container_name))
115115
return container_created
116116
except Exception as e:
117-
print >> sys.stderr, e
117+
print(e, file=sys.stderr)
118118
print("failed creating container " + container_name)
119119
os._exit(2)
120120

121121
# stop container, default timeout set to 5 seconds, will try to kill if stop failed
122122
def stop_container(self, container_name, stop_timout=5):
123-
print("stopping container " + container_name)
123+
print(("stopping container " + container_name))
124124
try:
125125
reply = self.cli.stop(container_name, stop_timout)
126126
return reply
@@ -130,46 +130,46 @@ def stop_container(self, container_name, stop_timout=5):
130130
time.sleep(3)
131131
return reply
132132
except Exception as e:
133-
print >> sys.stderr, e
133+
print(e, file=sys.stderr)
134134
print("problem stopping container " + container_name)
135135
os._exit(2)
136136

137137
# start container
138138
def start_container(self, container_name):
139-
print("starting container " + container_name)
139+
print(("starting container " + container_name))
140140
try:
141141
return self.cli.start(container_name)
142142
except "APIError" as e:
143-
print >> sys.stderr, e
143+
print(e, file=sys.stderr)
144144
print("problem starting container - most likely port bind already taken")
145145
except not "APIError" as e:
146-
print >> sys.stderr, e
146+
print(e, file=sys.stderr)
147147
print("problem starting container " + container_name)
148148
os._exit(2)
149149

150150
# restart container, default timeout set to 2 seconds
151151
def restart_container(self, container_name, stop_timout=2):
152-
print("restarting container " + container_name)
152+
print(("restarting container " + container_name))
153153
try:
154154
return self.cli.restart(container_name, stop_timout)
155155
except "APIError" as e:
156-
print >> sys.stderr, e
156+
print(e, file=sys.stderr)
157157
print("problem starting container - most likely port bind already taken")
158158
except not "APIError" as e:
159-
print >> sys.stderr, e
159+
print(e, file=sys.stderr)
160160
print("problem restarting container " + container_name)
161161
os._exit(2)
162162

163163
# remove container
164164
def remove_container(self, container_name):
165-
print("removing container " + container_name)
165+
print(("removing container " + container_name))
166166
try:
167167
return self.cli.remove_container(container_name)
168168
except:
169169
try:
170170
return self.cli.remove_container(container_name, force=True)
171171
except Exception as e:
172-
print >> sys.stderr, e
172+
print(e, file=sys.stderr)
173173
print("problem removing container " + container_name)
174174
os._exit(2)
175175

@@ -180,7 +180,7 @@ def create_container_host_config(self, port_binds, volumes, devices, privileged,
180180
binds=volumes, devices=devices, privileged=privileged,
181181
network_mode=network_mode)
182182
except Exception as e:
183-
print >> sys.stderr, e
183+
print(e, file=sys.stderr)
184184
print("problem creating host config")
185185
os._exit(2)
186186

@@ -194,7 +194,7 @@ def create_networking_config(self, starting_network=""):
194194
)
195195
return networking_config
196196
except Exception as e:
197-
print >> sys.stderr, e
197+
print(e, file=sys.stderr)
198198
print("problem creating network config")
199199
os._exit(2)
200200

@@ -203,7 +203,7 @@ def connect_to_network(self, container, net_id):
203203
try:
204204
self.cli.connect_container_to_network(container, net_id)
205205
except Exception as e:
206-
print >> sys.stderr, e
206+
print(e, file=sys.stderr)
207207
print("problem connecting to network " + net_id)
208208
os._exit(2)
209209

@@ -244,7 +244,7 @@ def run_container(self, app_name, container_name, image_name, bind_port, ports,
244244
try:
245245
self.connect_to_network(container_name, self.get_net_id(network))
246246
except Exception as e:
247-
print >> sys.stderr, e
247+
print(e, file=sys.stderr)
248248
print("problem connecting to network " + network)
249249
os._exit(2)
250250

functions/misc/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def get_number_of_cpu_cores():
77
cpu_number = multiprocessing.cpu_count()
88
return cpu_number
99
except Exception as e:
10-
print >> sys.stderr, e
10+
print(e, file=sys.stderr)
1111
print("error getting the number of cpu core")
1212
os._exit(2)
1313

@@ -19,6 +19,6 @@ def get_total_memory_size_in_mb():
1919
total_memory_in_mb = int(memory_in_bytes.total / 1024 / 1024)
2020
return total_memory_in_mb
2121
except Exception as e:
22-
print >> sys.stderr, e
22+
print(e, file=sys.stderr)
2323
print("error getting the number of cpu core")
2424
os._exit(2)

shippable.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: python
22

33
python:
4-
- 2.7
4+
- 3.7
55

66
integrations:
77
hub:

worker.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ def get_conf_setting(setting, settings_json, default_value="skip"):
1414
try:
1515
setting_value = os.getenv(setting.upper(), settings_json.get(setting, default_value))
1616
except Exception as e:
17-
print >> sys.stderr, e
18-
print >> sys.stderr, "missing " + setting + " config setting"
19-
print("missing " + setting + " config setting")
17+
print(e, file=sys.stderr)
18+
print("missing " + setting + " config setting", file=sys.stderr)
19+
print(("missing " + setting + " config setting"))
2020
os._exit(2)
2121
if setting_value == "skip":
22-
print >> sys.stderr, "missing " + setting + " config setting"
23-
print("missing " + setting + " config setting")
22+
print("missing " + setting + " config setting", file=sys.stderr)
23+
print(("missing " + setting + " config setting"))
2424
os._exit(2)
2525
return setting_value
2626

@@ -79,7 +79,7 @@ def roll_containers(app_json, force_pull=True):
7979
port_binds[x] = x + idx
8080
port_list.append(x)
8181
elif isinstance(x, dict):
82-
for host_port, container_port in x.iteritems():
82+
for host_port, container_port in x.items():
8383
port_binds[int(container_port)] = int(host_port) + idx
8484
port_list.append(container_port)
8585
else:
@@ -132,7 +132,7 @@ def start_containers(app_json, force_pull=True):
132132
port_binds[x] = x + container_number - 1
133133
port_list.append(x)
134134
elif isinstance(x, dict):
135-
for host_port, container_port in x.iteritems():
135+
for host_port, container_port in x.items():
136136
port_binds[int(container_port)] = int(host_port) + container_number - 1
137137
port_list.append(container_port)
138138
else:
@@ -153,7 +153,7 @@ def start_containers(app_json, force_pull=True):
153153

154154
# figure out how many containers are needed
155155
def containers_required(app_json):
156-
for scale_type, scale_amount in app_json["containers_per"].iteritems():
156+
for scale_type, scale_amount in app_json["containers_per"].items():
157157
if scale_type == "cpu":
158158
containers_needed = int(cpu_cores * scale_amount)
159159
elif scale_type == "memory" or scale_type == "mem":
@@ -178,7 +178,7 @@ def restart_unhealthy_containers():
178178
if docker_socket.check_container_healthy(nebula_container["Id"]) is False:
179179
docker_socket.restart_container(nebula_container["Id"])
180180
except Exception as e:
181-
print >> sys.stderr, e
181+
print(e, file=sys.stderr)
182182
print("failed checking containers health")
183183
os._exit(2)
184184

@@ -245,7 +245,7 @@ def get_device_group_info(nebula_connection_object, device_group_to_get_info):
245245
print("nebula manager initial connection check failure, dropping container")
246246
os._exit(2)
247247
except Exception as e:
248-
print >> sys.stderr, e
248+
print(e, file=sys.stderr)
249249
print("error confirming connection to nebula manager - please check connection & authentication params and "
250250
"that the manager is online")
251251
os._exit(2)
@@ -260,24 +260,24 @@ def get_device_group_info(nebula_connection_object, device_group_to_get_info):
260260
# make sure the device_group exists in the nebula cluster
261261
while local_device_group_info["status_code"] == 403 and \
262262
local_device_group_info["reply"]["device_group_exists"] is False:
263-
print("device_group " + device_group + " doesn't exist in nebula cluster, waiting for it to be created")
263+
print(("device_group " + device_group + " doesn't exist in nebula cluster, waiting for it to be created"))
264264
local_device_group_info = get_device_group_info(nebula_connection, device_group)
265265
time.sleep(nebula_manager_check_in_time)
266266

267267
# start all apps that are set to running on boot
268268
for nebula_app in local_device_group_info["reply"]["apps"]:
269269
if nebula_app["running"] is True:
270-
print("initial start of " + nebula_app["app_name"] + " app")
270+
print(("initial start of " + nebula_app["app_name"] + " app"))
271271
start_containers(nebula_app)
272-
print("completed initial start of " + nebula_app["app_name"] + " app")
272+
print(("completed initial start of " + nebula_app["app_name"] + " app"))
273273

274274
# open a thread which is in charge of restarting any containers which healthcheck shows them as unhealthy
275275
print("starting work container health checking thread")
276276
Thread(target=restart_unhealthy_containers).start()
277277

278278
# loop forever
279-
print("starting device_group " + device_group + " /info check loop, configured to check for changes every "
280-
+ str(nebula_manager_check_in_time) + " seconds")
279+
print(("starting device_group " + device_group + " /info check loop, configured to check for changes every "
280+
+ str(nebula_manager_check_in_time) + " seconds"))
281281
while True:
282282

283283
# wait the configurable time before checking the device_group info page again
@@ -296,20 +296,20 @@ def get_device_group_info(nebula_connection_object, device_group_to_get_info):
296296
if remote_nebula_app["app_id"] > local_device_group_info["reply"]["apps"][local_app_index]["app_id"]:
297297
monotonic_id_increase = True
298298
if remote_nebula_app["running"] is False:
299-
print("stopping app " + remote_nebula_app["app_name"] +
300-
" do to changes in the app configuration")
299+
print(("stopping app " + remote_nebula_app["app_name"] +
300+
" do to changes in the app configuration"))
301301
stop_containers(remote_nebula_app)
302302
elif remote_nebula_app["rolling_restart"] is True and \
303303
local_device_group_info["reply"]["apps"][local_app_index]["running"] is True:
304-
print("rolling app " + remote_nebula_app["app_name"] +
305-
" do to changes in the app configuration")
304+
print(("rolling app " + remote_nebula_app["app_name"] +
305+
" do to changes in the app configuration"))
306306
roll_containers(remote_nebula_app)
307307
else:
308-
print("restarting app " + remote_nebula_app["app_name"] +
309-
" do to changes in the app configuration")
308+
print(("restarting app " + remote_nebula_app["app_name"] +
309+
" do to changes in the app configuration"))
310310
restart_containers(remote_nebula_app)
311311
else:
312-
print("restarting app " + remote_nebula_app["app_name"] + " do to changes in the app configuration")
312+
print(("restarting app " + remote_nebula_app["app_name"] + " do to changes in the app configuration"))
313313
monotonic_id_increase = True
314314
restart_containers(remote_nebula_app)
315315

@@ -318,8 +318,8 @@ def get_device_group_info(nebula_connection_object, device_group_to_get_info):
318318
monotonic_id_increase = True
319319
for local_nebula_app in local_device_group_info["reply"]["apps"]:
320320
if local_nebula_app["app_name"] not in remote_device_group_info["reply"]["apps_list"]:
321-
print("removing app " + local_nebula_app["app_name"] +
322-
" do to changes in the app configuration")
321+
print(("removing app " + local_nebula_app["app_name"] +
322+
" do to changes in the app configuration"))
323323
stop_containers(local_nebula_app)
324324

325325
# logic that runs image pruning if prune_id increased
@@ -333,6 +333,6 @@ def get_device_group_info(nebula_connection_object, device_group_to_get_info):
333333
local_device_group_info = remote_device_group_info
334334

335335
except Exception as e:
336-
print >> sys.stderr, e
336+
print(e, file=sys.stderr)
337337
print("failed main loop - exiting")
338338
os._exit(2)

0 commit comments

Comments
 (0)