Skip to content

Commit d2885c2

Browse files
authored
Merge pull request #27 from cloudify-incubator/python3
Python3
2 parents c504c2e + 724a8d5 commit d2885c2

24 files changed

Lines changed: 286 additions & 118 deletions

.circleci/config.yml

Lines changed: 130 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,34 @@ checkout:
1111
1212
jobs:
1313

14-
unittests:
14+
py3_compat:
15+
docker:
16+
- image: circleci/python:2.7
17+
steps:
18+
- checkout
19+
- run:
20+
name: install futurize
21+
command: pip install future --user
22+
- run:
23+
name: find python3-incompatible code
24+
command: |
25+
FUTURIZE="futurize ."
26+
while read line; do
27+
[[ "$line" =~ ^#.* ]] && continue
28+
FUTURIZE="${FUTURIZE} ${line}"
29+
done<.circleci/py3fixers
30+
echo "Running: $FUTURIZE"
31+
$FUTURIZE>futurize_diffs
32+
- run:
33+
name: check that there is no python3-incompatible code
34+
command: |
35+
if [[ -s futurize_diffs ]]; then
36+
echo "Python-3-incompatible code found"
37+
cat futurize_diffs
38+
exit 1
39+
fi
40+
41+
unittests_py27:
1542
docker:
1643
- image: circleci/python:2.7.15-stretch
1744
steps:
@@ -38,54 +65,138 @@ jobs:
3865
name: install tox
3966
command: pip install --user tox
4067
- run: /home/circleci/.local/bin/tox -e flake8
41-
- run: /home/circleci/.local/bin/tox -e py27
68+
- run: /home/circleci/.local/bin/tox -e nosetests
4269

43-
wagon:
70+
unittests_py36:
4471
docker:
45-
- image: amd64/centos:centos7.5.1804
72+
- image: circleci/python:3.6-stretch
4673
steps:
4774
- checkout
4875
- run:
49-
name: Install dependencies
50-
command: yum -y install python-devel gcc openssl git libxslt-devel libxml2-devel openldap-devel libffi-devel openssl-devel libvirt-devel libvirt-python
76+
name: update links
77+
command: sudo apt-get update -y
78+
- run:
79+
name: install python/pip/libvirt packages
80+
command: sudo apt-get install -yq python-libvirt libvirt-dev python-dev python-pip
5181
- run:
5282
name: Download pip
5383
command: curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
5484
- run:
5585
name: Install pip
56-
command: python get-pip.py
57-
- run:
58-
name: Upgrade pip
59-
command: pip install --upgrade pip==9.0.1
86+
command: sudo python get-pip.py
6087
- run:
6188
name: Install virtualenv
62-
command: pip install virtualenv==16.7.9
89+
command: pip install --user virtualenv
6390
- run:
6491
name: Init virtualenv
6592
command: virtualenv env
6693
- run:
67-
name: Install wagon
68-
command: pip install wagon==0.3.2
94+
name: install tox
95+
command: pip install --user tox
96+
- run: /home/circleci/.local/bin/tox -e flake8
97+
- run: /home/circleci/.local/bin/tox -e nosetests
98+
99+
wagon:
100+
machine:
101+
image: ubuntu-1604:201903-01
102+
steps:
103+
- checkout
104+
- run:
105+
name: Create Workspace Build directory.
106+
command: mkdir -p workspace/build
69107
- run:
70-
name: many_linux
71-
command: echo "manylinux1_compatible = False" > "env/bin/_manylinux.py"
108+
name: Build py27py36 Wagon
109+
command: |
110+
git clone https://github.com/cloudify-cosmo/cloudify-wagon-build-containers.git
111+
docker build -t cloudify-centos-7-wagon-builder cloudify-wagon-build-containers/centos_7_py2py3
112+
docker run -v ~/project/:/packaging cloudify-centos-7-wagon-builder
72113
- run:
73-
name: make workspace
114+
name: copy wagon to workspace
115+
command: cp *.wgn workspace/build/
116+
- persist_to_workspace:
117+
root: workspace
118+
paths:
119+
- build/*
120+
121+
rhel_wagon:
122+
machine:
123+
image: ubuntu-1604:201903-01
124+
steps:
125+
- checkout
126+
- run:
127+
name: Create Workspace Build directory.
74128
command: mkdir -p workspace/build
75129
- run:
76-
name: Create wagon
77-
command: source env/bin/activate && wagon create -s . -v -o workspace/build -f -a '--no-cache-dir -c constraints.txt'
130+
name: Build RHEL py27py36 Wagon
131+
command: |
132+
git clone https://github.com/cloudify-cosmo/cloudify-wagon-build-containers.git
133+
docker build -t cloudify-redhat-7-wagon-builder cloudify-wagon-build-containers/redhat_7_py2py3 --build-arg USERNAME="$USERNAME" --build-arg PASSWORD="$PASSWORD"
134+
docker run -v ~/project/:/packaging cloudify-redhat-7-wagon-builder
135+
- run:
136+
name: copy wagon to workspace
137+
command: cp *.wgn workspace/build/
78138
- persist_to_workspace:
79139
root: workspace
80140
paths:
81141
- build/*
82142

143+
release:
144+
docker:
145+
- image: circleci/python:2.7
146+
steps:
147+
- checkout
148+
- run:
149+
name: "Pull Submodules"
150+
command: |
151+
git submodule init
152+
git submodule update --remote --recursive
153+
- run:
154+
name: Download pip
155+
command: curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
156+
- run:
157+
name: Install pip
158+
command: sudo python get-pip.py
159+
- run:
160+
name: Install virtualenv
161+
command: pip install --user virtualenv
162+
- run:
163+
name: Init virtualenv
164+
command: virtualenv env
165+
- run:
166+
name: install tox
167+
command: pip install --user pygithub pyyaml==3.10
168+
- run:
169+
name: upgrade setuptools
170+
command: pip install --upgrade setuptools
171+
- run:
172+
name: install local project
173+
command: pip install https://github.com/cloudify-incubator/cloudify-ecosystem-test/archive/latest.zip
174+
- attach_workspace:
175+
at: workspace
176+
- run: python .circleci/package_release.py
177+
178+
83179
workflows:
84180
version: 2
85181
tests:
86182
jobs:
87-
- unittests
183+
- py3_compat
184+
- unittests_py27
185+
- unittests_py36
88186
- wagon:
89187
filters:
90188
branches:
91189
only: /([0-9\.]*\-build|master|dev)/
190+
- rhel_wagon:
191+
filters:
192+
branches:
193+
only: /([0-9\.]*\-build|master|dev)/
194+
- release:
195+
filters:
196+
branches:
197+
only: /master/
198+
requires:
199+
- unittests_py27
200+
- unittests_py36
201+
- wagon
202+
- rhel_wagon

.circleci/py3fixers

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--stage1
2+
-f lib2to3.fixes.fix_getcwdu
3+
-f lib2to3.fixes.fix_long
4+
-f lib2to3.fixes.fix_nonzero
5+
-f lib2to3.fixes.fix_input
6+
-f lib2to3.fixes.fix_raw_input
7+
-f lib2to3.fixes.fix_itertools
8+
-f lib2to3.fixes.fix_itertools_imports
9+
-f lib2to3.fixes.fix_exec
10+
-f lib2to3.fixes.fix_operator
11+
-f libfuturize.fixes.fix_execfile
12+
-f libpasteurize.fixes.fix_newstyle
13+
-f lib2to3.fixes.fix_filter
14+
# fix_dict is not idempotent
15+
# -f lib2to3.fixes.fix_dict
16+
-f lib2to3.fixes.fix_map
17+
-f lib2to3.fixes.fix_zip
18+
-f lib2to3.fixes.fix_xrange
19+
-f lib2to3.fixes.fix_basestring
20+
-f libfuturize.fixes.fix_cmp
21+
-f libfuturize.fixes.fix_division_safe
22+
-f lib2to3.fixes.fix_metaclass
23+
-f libfuturize.fixes.fix_unicode_keep_u

CHANGELOG.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ releases:
4343

4444
v0.9.0:
4545
* Support download image contwent from external resource
46+
47+
v0.9.1:
48+
* Apply futurize fixes for python3
49+
* Port source code to python3

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Release history: [CHANGELOG.txt](CHANGELOG.txt)
1111

1212
* Python versions:
1313
* 2.7.x
14+
* 3.6.x
1415
* Packages versions:
1516
* libvirt-python >= 3.7.0
1617
* libvirt >= 1.3.1

cloudify_libvirt/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
from cloudify import ctx
1919
from cloudify import exceptions as cfy_exc
20-
2120
from cloudify_common_sdk import filters
21+
from cloudify_common_sdk._compat import text_type
2222

2323

2424
def get_libvirt_params(**kwargs):
@@ -40,7 +40,7 @@ def get_libvirt_params(**kwargs):
4040
if not template_params.get("name"):
4141
template_params["name"] = ctx.instance.id
4242
if not template_params.get("instance_uuid"):
43-
template_params["instance_uuid"] = str(uuid.uuid4())
43+
template_params["instance_uuid"] = text_type(uuid.uuid4())
4444

4545
# update 'resource_id', 'use_external_resource' from kwargs
4646
for field in ['resource_id', 'use_external_resource']:

cloudify_libvirt/domain_tasks.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
import time
1717

1818
from cloudify import ctx
19-
from cloudify.decorators import operation
2019
from cloudify import exceptions as cfy_exc
20+
from cloudify.decorators import operation
21+
from cloudify_common_sdk._compat import text_type
2122
import cloudify_libvirt.common as common
2223

2324

@@ -270,9 +271,9 @@ def start(**kwargs):
270271
'Failed to find the domain: {}'.format(repr(e))
271272
)
272273

273-
for i in xrange(10):
274+
for i in range(10):
274275
state, _ = dom.state()
275-
ctx.logger.info("Tring to start vm {}/10".format(i))
276+
ctx.logger.info("Trying to start vm {}/10".format(i))
276277
if wait_for_ip:
277278
ctx.logger.info("Waiting for ip.")
278279
if state == libvirt.VIR_DOMAIN_RUNNING:
@@ -333,12 +334,12 @@ def stop(**kwargs):
333334
ctx.instance.runtime_properties['ip'] = None
334335

335336
state, _ = dom.state()
336-
for i in xrange(10):
337+
for i in range(10):
337338
if state != libvirt.VIR_DOMAIN_RUNNING:
338339
ctx.logger.info("Looks as not run.")
339340
return
340341

341-
ctx.logger.info("Tring to stop vm {}/10".format(i))
342+
ctx.logger.info("Trying to stop vm {}/10".format(i))
342343
if dom.shutdown() < 0:
343344
raise cfy_exc.NonRecoverableError(
344345
'Can not shutdown guest domain.'
@@ -375,12 +376,12 @@ def resume(**kwargs):
375376
)
376377

377378
state, _ = dom.state()
378-
for i in xrange(10):
379+
for i in range(10):
379380
if state == libvirt.VIR_DOMAIN_RUNNING:
380381
ctx.logger.info("Looks as running.")
381382
return
382383

383-
ctx.logger.info("Tring to resume vm {}/10".format(i))
384+
ctx.logger.info("Trying to resume vm {}/10".format(i))
384385
if dom.resume() < 0:
385386
raise cfy_exc.NonRecoverableError(
386387
'Can not suspend guest domain.'
@@ -417,12 +418,12 @@ def suspend(**kwargs):
417418
)
418419

419420
state, _ = dom.state()
420-
for i in xrange(10):
421+
for i in range(10):
421422
if state != libvirt.VIR_DOMAIN_RUNNING:
422423
ctx.logger.info("Looks as not run.")
423424
return
424425

425-
ctx.logger.info("Tring to suspend vm {}/10".format(i))
426+
ctx.logger.info("Trying to suspend vm {}/10".format(i))
426427
if dom.suspend() < 0:
427428
raise cfy_exc.NonRecoverableError(
428429
'Can not suspend guest domain.'
@@ -437,7 +438,7 @@ def _cleanup_snapshots(ctx, dom):
437438
snapshots = dom.listAllSnapshots()
438439
snapshots_count = len(snapshots)
439440

440-
for _ in xrange(snapshots_count):
441+
for _ in range(snapshots_count):
441442
for snapshot in snapshots:
442443
# we can delete only snapshot without child
443444
if not snapshot.numChildren():
@@ -476,7 +477,7 @@ def _delete_force(dom):
476477
'Can not undefine guest domain with NVRAM.'
477478
)
478479
except AttributeError as e:
479-
ctx.logger.info("Non critical error: {}".format(str(e)))
480+
ctx.logger.info("Non critical error: {}".format(text_type(e)))
480481
if dom.undefine() < 0:
481482
raise cfy_exc.RecoverableError(
482483
'Can not undefine guest domain.'
@@ -795,7 +796,7 @@ def perfomance(**kwargs):
795796
# and after sleep for 5 seconds.
796797
ctx.logger.debug("Used: {} seconds.".format(before_usage))
797798
time.sleep(5)
798-
statistics['cpu'] = 100 * (_current_use(dom) - before_usage) / 5
799+
statistics['cpu'] = 100 * (_current_use(dom) - before_usage) // 5
799800

800801
memory = dom.memoryStats()
801802
statistics['memory'] = memory.get('actual', 0) / 1024.0

cloudify_libvirt/network_tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def link(**kwargs):
219219
)
220220

221221
MAX_RETRY = 10
222-
for i in xrange(MAX_RETRY):
222+
for i in range(MAX_RETRY):
223223
ctx.logger.info("{}: Tring to get vm ip: {}/{}"
224224
.format(vm_id, i, MAX_RETRY))
225225
for lease in network.DHCPLeases():

0 commit comments

Comments
 (0)