Skip to content

Commit 1309c1a

Browse files
authored
Merge pull request #251 from palexster/apa/release
Build release containers
2 parents 40a49df + d5bb3d7 commit 1309c1a

File tree

9 files changed

+146
-71
lines changed

9 files changed

+146
-71
lines changed

CI/JenkinsfileTestCleanInstance renamed to CI/Jenkinsfile.groovy

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,37 @@ pipeline {
461461
docker pull "polycubebot/${image_name}-pcn-k8s:${image_tag}"
462462
docker tag "polycubebot/${image_name}-pcn-k8s:${image_tag}" "polycubenetwork/k8s-pod-network:latest"
463463
docker push "polycubenetwork/k8s-pod-network:latest"
464+
docker pull "polycubebot/${image_name}-pcn-iptables:${image_tag}"
465+
docker tag "polycubebot/${image_name}-pcn-iptables:${image_tag}" "polycubenetwork/polycube-pcn-iptables:latest"
466+
docker push "polycubenetwork/${image_name}-pcn-iptables:latest"
467+
docker system prune --all --force
468+
"""
469+
}
470+
}
471+
}
472+
}
473+
stage("Release version from TAG") {
474+
when {
475+
buildingTag()
476+
}
477+
agent {
478+
label "docker"
479+
}
480+
steps {
481+
script {
482+
var tagName = "${env.TAG_NAME}"
483+
docker.withRegistry("", 'polycube-repo') {
484+
sh """
485+
export DOCKER_BUILDKIT=1
486+
docker pull "polycubebot/${image_name}-default:${image_tag}"
487+
docker tag "polycubebot/${image_name}-default:${image_tag}" "polycubenetwork/polycube:${env.TAG_NAME}"
488+
docker push "polycubenetwork/polycube:${env.TAG_NAME}"
489+
docker pull "polycubebot/${image_name}-pcn-k8s:${image_tag}"
490+
docker tag "polycubebot/${image_name}-pcn-k8s:${image_tag}" "polycubenetwork/k8s-pod-network:${env.TAG_NAME}"
491+
docker push "polycubenetwork/k8s-pod-network:${env.TAG_NAME}"
492+
docker pull "polycubebot/${image_name}-pcn-iptables:${image_tag}"
493+
docker tag "polycubebot/${image_name}-pcn-iptables:${image_tag}" "polycubenetwork/polycube-pcn-iptables:${env.TAG_NAME}"
494+
docker push "polycubenetwork/${image_name}-pcn-iptables:${env.TAG_NAME}"
464495
docker system prune --all --force
465496
"""
466497
}

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ FROM polycubebot/base_image:latest
33
ARG DEFAULT_MODE=default
44
ENV MODE=$DEFAULT_MODE
55
RUN echo "The mode is $MODE"
6+
RUN rm -rf /tmp/polycube
67
RUN --mount=target=/polycube cp -r /polycube /tmp/polycube && \
78
cd /tmp/polycube && \
89
SUDO="" USER="root" WORKDIR="/tmp/dev" ./scripts/install.sh $MODE && \

scripts/pre-requirements.sh

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,7 @@ $SUDO bash -c "apt install --allow-unauthenticated -y wget gnupg2 software-prope
1111
# golang v1.12 still not available in repos
1212
$SUDO add-apt-repository ppa:longsleep/golang-backports -y || true
1313

14-
# repo for libyang-dev
15-
16-
# Cannot add the repository to our machine, as the GPG key expired on Aug 2019 and Ubuntu refuses to install the software in there
17-
#$SUDO sh -c "echo 'deb http://download.opensuse.org/repositories/home:/liberouter/xUbuntu_18.04/ /' > /etc/apt/sources.list.d/home:liberouter.list"
18-
#wget -nv https://download.opensuse.org/repositories/home:liberouter/xUbuntu_18.04/Release.key -O Release.key
19-
#$SUDO apt-key add - < Release.key
20-
# So, installing the required package by downloading it manually
21-
wget -nv http://download.opensuse.org/repositories/home:/liberouter/xUbuntu_18.04/amd64/libyang_0.14.81_amd64.deb -O libyang.deb
22-
wget -nv http://download.opensuse.org/repositories/home:/liberouter/xUbuntu_18.04/amd64/libyang-dev_0.14.81_amd64.deb -O libyang-dev.deb
23-
$SUDO apt install -f ./libyang.deb
24-
$SUDO apt install -y -f ./libyang-dev.deb
25-
rm ./libyang.deb
26-
rm ./libyang-dev.deb
27-
2814
$SUDO apt update
29-
30-
3115
PACKAGES=""
3216
PACKAGES+=" git" # needed to clone dependencies
3317
PACKAGES+=" build-essential cmake" # provides compiler and other compilation tools
@@ -51,6 +35,18 @@ if [ "$MODE" == "pcn-k8s" ]; then
5135
PACKAGES+=" iproute2" # provides bridge command that is used to add entries in vxlan device
5236
fi
5337

38+
# licd $WORKDIR
39+
set +e
40+
if [ ! -d libyang ]; then
41+
git clone https://github.com/CESNET/libyang.git
42+
fi
43+
cd libyang
44+
git checkout v0.14-r1
45+
mkdir -p build && cd build
46+
cmake ..
47+
make -j $(getconf _NPROCESSORS_ONLN)
48+
$SUDO make install
49+
5450
# use non interactive to avoid blocking the install script
5551
$SUDO bash -c "DEBIAN_FRONTEND=noninteractive apt-get install -yq $PACKAGES"
5652

tests/converter/converter.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import re
2+
from junit_xml import TestSuite, TestCase
3+
import itertools
4+
5+
6+
7+
def file_log_parser(file:str) -> dict:
8+
with open(file) as file_log:
9+
config = file_log.read()
10+
test_logs_results = {}
11+
index = ""
12+
for line in config.split("\n"):
13+
if "++++Starting test" in line:
14+
index = line.split(" ")[-1][:-4]
15+
test_logs_results[index] = ""
16+
elif "++++TEST" in line:
17+
index = ""
18+
elif index:
19+
test_logs_results[index] += line + "\n"
20+
return test_logs_results
21+
22+
def create_junit_test_file(tests_file:str):
23+
tests = []
24+
for file in tests_file.split("\n"):
25+
file_log = "test_log_" + "_".join(file.split("_")[2:])
26+
test = file_log_parser(file_log)
27+
with open(file) as file_buffer: # Use file to refer to the file object
28+
config = file_buffer.read()
29+
current_section = {}
30+
lines = config.split()
31+
date = lines[1]
32+
is_relaunch = lines[2]
33+
debug=lines[3]
34+
for _,test_name,status,_,_,duration in zip(*[iter(lines[6:])]*6):
35+
if duration == "false":
36+
continue
37+
else:
38+
duration=duration[:-1]
39+
if test_name in test:
40+
tc = TestCase(name=test_name, elapsed_sec=int(duration),status=status.split("+")[0], stdout=test[test_name])
41+
if status != "Passed++++":
42+
tc.add_failure_info(output=test[test_name])
43+
else:
44+
tc = TestCase(name=test_name, elapsed_sec=int(duration), status=status.split("+")[0])
45+
tests.append(tc)
46+
return tests
47+
48+
def write_junit_file(output_file:str, tests:[], test_name:str) -> None:
49+
# We create a TestSUite and we write them in a XML File
50+
t = TestSuite(name=test_name,test_cases=tests)
51+
with open('output.xml', 'w') as f:
52+
TestSuite.to_file(f, [t], prettyprint=False)
53+

tests/converter/requirements.txt

100644100755
File mode changed.

tests/converter/tests.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from converter import create_junit_test_file, write_junit_file
2+
import assertpy
3+
4+
# content of test_sample.py
5+
6+
def test_count_single_file_1():
7+
t = create_junit_test_file("test_results_1.txt")
8+
assertpy.assert_that(len(t)).is_equal_to(10)
9+
10+
def test_count_single_file_2():
11+
t = create_junit_test_file("test_results_1.txt\ntest_results_2.txt")
12+
assertpy.assert_that(len(t)).is_equal_to(29)
13+
14+
def test_assert_status_1():
15+
t = create_junit_test_file("test_results_1.txt")
16+
for test in t:
17+
assertpy.assert_that(test.status).is_equal_to("Failed")
18+
19+
def test_assert_status_2():
20+
t = create_junit_test_file("test_results_2.txt")
21+
for test in t:
22+
assertpy.assert_that(test.status).is_equal_to("Passed")
23+
24+
def test_failure_1():
25+
t = create_junit_test_file("test_results_1.txt")
26+
assertpy.assert_that(len(t)).is_equal_to(10)
27+
for test in t:
28+
assertpy.assert_that(test.is_failure()).is_not_none()
29+
30+
def test_not_failure_1():
31+
t = create_junit_test_file("test_results_2.txt")
32+
assertpy.assert_that(len(t)).is_equal_to(19)
33+
for test in t:
34+
assertpy.assert_that(test.is_failure()).is_none()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
assertpy==0.15
2+
pytest==5.3.1

tests/converter/to_junit.py

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,13 @@
1-
import re
2-
from junit_xml import TestSuite, TestCase
3-
import itertools
41
import os
52
import argparse
6-
import os
3+
from converter import create_junit_test_file, write_junit_file
74

85
parser = argparse.ArgumentParser(description='Test File')
96
parser.add_argument('test_suite_name', type=str, help='Class of tests to parse')
107
args = parser.parse_args()
8+
OUTPUT_FILE = 'output.xml'
119
TESTS_FILE = os.environ['TEST_RESULTS']
1210

13-
tests = []
14-
15-
def file_log_parser(file:str) -> dict:
16-
with open(file) as file_log:
17-
config = file_log.read()
18-
test_logs_results = {}
19-
index = ""
20-
for line in config.split("\n"):
21-
if "++++Starting test" in line:
22-
index = line.split(" ")[-1][:-4]
23-
test_logs_results[index] = ""
24-
elif "++++TEST" in line:
25-
index = ""
26-
elif index:
27-
test_logs_results[index] += line + "\n"
28-
return test_logs_results
29-
30-
# For each test we generate a testCase parsing the output file
31-
for file in TESTS_FILE.split("\n"):
32-
file_log = "test_log_" + "_".join(file.split("_")[2:])
33-
test = file_log_parser(file_log)
34-
with open(file) as file_buffer: # Use file to refer to the file object
35-
config = file_buffer.read()
36-
current_section = {}
37-
lines = config.split()
38-
date = lines[1]
39-
is_relaunch = lines[2]
40-
debug=lines[3]
41-
for _,test_name,status,_,_,duration in zip(*[iter(lines[6:])]*6):
42-
if duration == "false":
43-
continue
44-
else:
45-
duration=duration[:-1]
46-
if test_name in test:
47-
tc = TestCase(name=test_name, elapsed_sec=int(duration),status=status, stdout=test[test_name])
48-
else:
49-
tc = TestCase(name=test_name, elapsed_sec=int(duration),status=status)
50-
tests.append(tc)
51-
52-
# We create a TestSUite and we write them in a XML File
53-
t = TestSuite(name=args.test_suite_name,test_cases=tests)
54-
with open('output.xml', 'w') as f:
55-
TestSuite.to_file(f, [t], prettyprint=False)
11+
if __name__ == "__main__":
12+
tests = create_junit_test_file(TESTS_FILE)
13+
write_junit_file(OUTPUT_FILE,tests,args.test_suite_name)

tests/helpers_tests.bash

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ function cleanup {
1717
cat $test_results
1818

1919
echo ""
20-
echo "FAILED TESTS:"
20+
echo "Failed TESTS:"
2121
echo ""
22-
cat $test_results | grep FAILED -A 1
22+
cat $test_results | grep Failed -A 1
2323

2424
if $failed ; then
2525
exit 1
@@ -41,15 +41,15 @@ function log_test {
4141
fi
4242
test_total=$(($test_total+1))
4343
if [ $status -ne 0 ]; then
44-
echo "++++TEST $1 FAILED++++"
45-
echo "++++TEST $1 FAILED++++" >> $test_results
46-
echo "++++TEST $1 FAILED++++" >> $test_tmp
44+
echo "++++TEST $1 Failed++++"
45+
echo "++++TEST $1 Failed++++" >> $test_results
46+
echo "++++TEST $1 Failed++++" >> $test_tmp
4747
failed=true
4848
else
4949
test_passed=$(($test_passed+1))
50-
echo "++++TEST $1 PASSED++++"
51-
echo "++++TEST $1 PASSED++++" >> $test_results
52-
echo "++++TEST $1 PASSED++++" >> $test_tmp
50+
echo "++++TEST $1 Passed++++"
51+
echo "++++TEST $1 Passed++++" >> $test_results
52+
echo "++++TEST $1 Passed++++" >> $test_tmp
5353
fi
5454
cat $test_tmp >> $test_log
5555
return $status

0 commit comments

Comments
 (0)