Skip to content

Commit 0b15eff

Browse files
rabbahdgrove-oss
authored andcommitted
Update python runtime to include its own test artifacts. (#77)
* Remove python 2 tests, no longer maintained. * Lookup test artifacts relative to project resources. * Build test artifacts before tests. * Build action loop proxy from source to get bug fix since last release
1 parent 248efb5 commit 0b15eff

20 files changed

Lines changed: 299 additions & 331 deletions

File tree

.gitignore

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,7 @@ ansible/roles/nginx/files/*.csr
6161
ansible/roles/nginx/files/*cert.pem
6262

6363
# .zip files must be explicited whitelisted
64+
.built
6465
*.zip
65-
!tests/dat/actions/blackbox.zip
66-
!tests/dat/actions/helloSwift.zip
67-
!tests/dat/actions/python.zip
68-
!tests/dat/actions/python2_virtualenv.zip
69-
!tests/dat/actions/python3_virtualenv.zip
70-
!tests/dat/actions/python_virtualenv_dir.zip
71-
!tests/dat/actions/python_virtualenv_name.zip
72-
!tests/dat/actions/zippedaction.zip
66+
tests/**/python_virtualenv/virtualenv/
67+
tests/**/python_virtualenv_invalid_main/virtualenv/

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
sudo: required
1919
dist: xenial
2020
jdk: openjdk8
21-
language: java
21+
language:
22+
- python
23+
24+
python:
25+
- "3.7"
2226

2327
services:
2428
- docker

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ To use as a docker action using python 3
2727
```
2828
wsk action update myAction myAction.py --docker openwhisk/python3action:1.0.2
2929
```
30-
Replace `python3action` with `python2action` to use python 2.
31-
3230

3331
### To use on deployment that contains the rutime as a kind
3432
To use as a kind action using python 3
@@ -52,7 +50,6 @@ Build and Push image
5250
docker login
5351
./gradlew core:pythonAction:distDocker -PdockerImagePrefix=$prefix-user -PdockerRegistry=docker.io
5452
```
55-
Replace `core:pythonAction` with `core:python2Action` to build python 2 instead.
5653

5754
Deploy OpenWhisk using ansible environment that contains the kind `python:3` and `python:2`
5855
Assuming you have OpenWhisk already deploy locally and `OPENWHISK_HOME` pointing to root directory of OpenWhisk core repository.
@@ -86,7 +83,6 @@ Then create the action using your image from dockerhub
8683
wsk action update myAction myAction.py --docker $user_prefix/python3action
8784
```
8885
The `$user_prefix` is usually your dockerhub user id.
89-
Replace `python3action` with `python2action` to use python 2
9086

9187
### Testing
9288
Install dependencies from the root directory on $OPENWHISK_HOME repository

core/python2Action/CHANGELOG.md

Lines changed: 0 additions & 78 deletions
This file was deleted.

core/python2Action/Dockerfile

Lines changed: 0 additions & 58 deletions
This file was deleted.

core/pythonActionLoop/Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
#
17-
FROM golang:1.11 as builder
18-
ENV PROXY_SOURCE=https://github.com/apache/openwhisk-runtime-go/archive/golang1.11@1.13.0-incubating.tar.gz
19-
RUN curl -L "$PROXY_SOURCE" | tar xzf - \
20-
&& mkdir -p src/github.com/apache \
21-
&& mv openwhisk-runtime-go-golang1.11-1.13.0-incubating \
22-
src/github.com/apache/incubator-openwhisk-runtime-go \
23-
&& cd src/github.com/apache/incubator-openwhisk-runtime-go/main \
24-
&& CGO_ENABLED=0 go build -o /bin/proxy
17+
FROM golang:1.12 as builder
18+
RUN env CGO_ENABLED=0 go get github.com/apache/openwhisk-runtime-go/main && mv /go/bin/main /bin/proxy
19+
#ENV PROXY_SOURCE=https://github.com/apache/openwhisk-runtime-go/archive/golang1.11@1.13.0-incubating.tar.gz
20+
#RUN curl -L "$PROXY_SOURCE" | tar xzf - \
21+
# && mkdir -p src/github.com/apache \
22+
# && mv openwhisk-runtime-go-golang1.11-1.13.0-incubating \
23+
# src/github.com/apache/incubator-openwhisk-runtime-go \
24+
# && cd src/github.com/apache/incubator-openwhisk-runtime-go/main \
25+
# && CGO_ENABLED=0 go build -o /bin/proxy
2526

2627
FROM python:3.7-stretch
2728

tests/build.gradle

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,15 @@ tasks.withType(ScalaCompile) {
4444
}
4545

4646
task testPython3(type: Test) {
47-
exclude 'runtime/actionContainers/Python2**'
4847
}
48+
49+
task buildArtifacts(type:Exec) {
50+
workingDir 'src/test/resources'
51+
commandLine './build.sh'
52+
}
53+
54+
tasks.withType(Test) {
55+
dependsOn buildArtifacts
56+
}
57+
58+
testClasses.dependsOn(buildArtifacts)

tests/src/test/resources/build.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
set -e
20+
21+
if [ -f ".built" ]; then
22+
echo "Test zip artifacts already built, skipping"
23+
exit 0
24+
fi
25+
26+
# see what version of python is running
27+
py=$(python --version 2>&1 | awk -F' ' '{print $2}')
28+
if [[ $py == 3.7.* ]]; then
29+
echo "python version is $py (ok)"
30+
else
31+
echo "python version is $py (not ok)"
32+
echo "cannot generated test artifacts and tests will fail"
33+
exit -1
34+
fi
35+
36+
(cd python_virtualenv && ./build.sh && zip ../python_virtualenv.zip -r .)
37+
(cd python_virtualenv_invalid_main && ./build.sh && zip ../python_virtualenv_invalid_main.zip -r .)
38+
(cd python_virtualenv_invalid_venv && zip ../python_virtualenv_invalid_venv.zip -r .)
39+
40+
touch .built

core/python2Action/build.gradle renamed to tests/src/test/resources/python_virtualenv/__main__.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#!/usr/bin/env python
2+
"""Python Hello virtualenv test.
3+
14
/*
25
* Licensed to the Apache Software Foundation (ASF) under one or more
36
* contributor license agreements. See the NOTICE file distributed with
@@ -14,21 +17,12 @@
1417
* See the License for the specific language governing permissions and
1518
* limitations under the License.
1619
*/
20+
"""
1721

18-
ext.dockerImageName = 'python2action'
19-
apply from: '../../gradle/docker.gradle'
20-
distDocker.dependsOn 'copyFiles'
21-
distDocker.finalizedBy 'rmFiles'
22-
23-
def runners = files(
24-
new File(project(':core:pythonAction').projectDir, 'pythonrunner.py')
25-
)
22+
from random_useragent.random_useragent import Randomize
2623

27-
task copyFiles(type: Copy) {
28-
from runners
29-
into '.'
30-
}
24+
def main(args):
25+
return {"agent": Randomize().random_agent('desktop','linux')}
3126

32-
task rmFiles(type: Delete) {
33-
delete runners.collect { it.getName() }
34-
}
27+
def naim(args):
28+
return main(args)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
virtualenv virtualenv
20+
source virtualenv/bin/activate
21+
pip install -r requirements.txt
22+
deactivate

0 commit comments

Comments
 (0)