Skip to content

Commit

Permalink
Merge pull request #251 from palexster/apa/release
Browse files Browse the repository at this point in the history
Build release containers
  • Loading branch information
frisso committed Dec 12, 2019
2 parents 40a49df + d5bb3d7 commit 1309c1a
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 71 deletions.
31 changes: 31 additions & 0 deletions CI/JenkinsfileTestCleanInstance → CI/Jenkinsfile.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,37 @@ pipeline {
docker pull "polycubebot/${image_name}-pcn-k8s:${image_tag}"
docker tag "polycubebot/${image_name}-pcn-k8s:${image_tag}" "polycubenetwork/k8s-pod-network:latest"
docker push "polycubenetwork/k8s-pod-network:latest"
docker pull "polycubebot/${image_name}-pcn-iptables:${image_tag}"
docker tag "polycubebot/${image_name}-pcn-iptables:${image_tag}" "polycubenetwork/polycube-pcn-iptables:latest"
docker push "polycubenetwork/${image_name}-pcn-iptables:latest"
docker system prune --all --force
"""
}
}
}
}
stage("Release version from TAG") {
when {
buildingTag()
}
agent {
label "docker"
}
steps {
script {
var tagName = "${env.TAG_NAME}"
docker.withRegistry("", 'polycube-repo') {
sh """
export DOCKER_BUILDKIT=1
docker pull "polycubebot/${image_name}-default:${image_tag}"
docker tag "polycubebot/${image_name}-default:${image_tag}" "polycubenetwork/polycube:${env.TAG_NAME}"
docker push "polycubenetwork/polycube:${env.TAG_NAME}"
docker pull "polycubebot/${image_name}-pcn-k8s:${image_tag}"
docker tag "polycubebot/${image_name}-pcn-k8s:${image_tag}" "polycubenetwork/k8s-pod-network:${env.TAG_NAME}"
docker push "polycubenetwork/k8s-pod-network:${env.TAG_NAME}"
docker pull "polycubebot/${image_name}-pcn-iptables:${image_tag}"
docker tag "polycubebot/${image_name}-pcn-iptables:${image_tag}" "polycubenetwork/polycube-pcn-iptables:${env.TAG_NAME}"
docker push "polycubenetwork/${image_name}-pcn-iptables:${env.TAG_NAME}"
docker system prune --all --force
"""
}
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM polycubebot/base_image:latest
ARG DEFAULT_MODE=default
ENV MODE=$DEFAULT_MODE
RUN echo "The mode is $MODE"
RUN rm -rf /tmp/polycube
RUN --mount=target=/polycube cp -r /polycube /tmp/polycube && \
cd /tmp/polycube && \
SUDO="" USER="root" WORKDIR="/tmp/dev" ./scripts/install.sh $MODE && \
Expand Down
28 changes: 12 additions & 16 deletions scripts/pre-requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,7 @@ $SUDO bash -c "apt install --allow-unauthenticated -y wget gnupg2 software-prope
# golang v1.12 still not available in repos
$SUDO add-apt-repository ppa:longsleep/golang-backports -y || true

# repo for libyang-dev

# Cannot add the repository to our machine, as the GPG key expired on Aug 2019 and Ubuntu refuses to install the software in there
#$SUDO sh -c "echo 'deb http://download.opensuse.org/repositories/home:/liberouter/xUbuntu_18.04/ /' > /etc/apt/sources.list.d/home:liberouter.list"
#wget -nv https://download.opensuse.org/repositories/home:liberouter/xUbuntu_18.04/Release.key -O Release.key
#$SUDO apt-key add - < Release.key
# So, installing the required package by downloading it manually
wget -nv http://download.opensuse.org/repositories/home:/liberouter/xUbuntu_18.04/amd64/libyang_0.14.81_amd64.deb -O libyang.deb
wget -nv http://download.opensuse.org/repositories/home:/liberouter/xUbuntu_18.04/amd64/libyang-dev_0.14.81_amd64.deb -O libyang-dev.deb
$SUDO apt install -f ./libyang.deb
$SUDO apt install -y -f ./libyang-dev.deb
rm ./libyang.deb
rm ./libyang-dev.deb

$SUDO apt update


PACKAGES=""
PACKAGES+=" git" # needed to clone dependencies
PACKAGES+=" build-essential cmake" # provides compiler and other compilation tools
Expand All @@ -51,6 +35,18 @@ if [ "$MODE" == "pcn-k8s" ]; then
PACKAGES+=" iproute2" # provides bridge command that is used to add entries in vxlan device
fi

# licd $WORKDIR
set +e
if [ ! -d libyang ]; then
git clone https://github.com/CESNET/libyang.git
fi
cd libyang
git checkout v0.14-r1
mkdir -p build && cd build
cmake ..
make -j $(getconf _NPROCESSORS_ONLN)
$SUDO make install

# use non interactive to avoid blocking the install script
$SUDO bash -c "DEBIAN_FRONTEND=noninteractive apt-get install -yq $PACKAGES"

Expand Down
53 changes: 53 additions & 0 deletions tests/converter/converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import re
from junit_xml import TestSuite, TestCase
import itertools



def file_log_parser(file:str) -> dict:
with open(file) as file_log:
config = file_log.read()
test_logs_results = {}
index = ""
for line in config.split("\n"):
if "++++Starting test" in line:
index = line.split(" ")[-1][:-4]
test_logs_results[index] = ""
elif "++++TEST" in line:
index = ""
elif index:
test_logs_results[index] += line + "\n"
return test_logs_results

def create_junit_test_file(tests_file:str):
tests = []
for file in tests_file.split("\n"):
file_log = "test_log_" + "_".join(file.split("_")[2:])
test = file_log_parser(file_log)
with open(file) as file_buffer: # Use file to refer to the file object
config = file_buffer.read()
current_section = {}
lines = config.split()
date = lines[1]
is_relaunch = lines[2]
debug=lines[3]
for _,test_name,status,_,_,duration in zip(*[iter(lines[6:])]*6):
if duration == "false":
continue
else:
duration=duration[:-1]
if test_name in test:
tc = TestCase(name=test_name, elapsed_sec=int(duration),status=status.split("+")[0], stdout=test[test_name])
if status != "Passed++++":
tc.add_failure_info(output=test[test_name])
else:
tc = TestCase(name=test_name, elapsed_sec=int(duration), status=status.split("+")[0])
tests.append(tc)
return tests

def write_junit_file(output_file:str, tests:[], test_name:str) -> None:
# We create a TestSUite and we write them in a XML File
t = TestSuite(name=test_name,test_cases=tests)
with open('output.xml', 'w') as f:
TestSuite.to_file(f, [t], prettyprint=False)

Empty file modified tests/converter/requirements.txt
100644 → 100755
Empty file.
34 changes: 34 additions & 0 deletions tests/converter/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from converter import create_junit_test_file, write_junit_file
import assertpy

# content of test_sample.py

def test_count_single_file_1():
t = create_junit_test_file("test_results_1.txt")
assertpy.assert_that(len(t)).is_equal_to(10)

def test_count_single_file_2():
t = create_junit_test_file("test_results_1.txt\ntest_results_2.txt")
assertpy.assert_that(len(t)).is_equal_to(29)

def test_assert_status_1():
t = create_junit_test_file("test_results_1.txt")
for test in t:
assertpy.assert_that(test.status).is_equal_to("Failed")

def test_assert_status_2():
t = create_junit_test_file("test_results_2.txt")
for test in t:
assertpy.assert_that(test.status).is_equal_to("Passed")

def test_failure_1():
t = create_junit_test_file("test_results_1.txt")
assertpy.assert_that(len(t)).is_equal_to(10)
for test in t:
assertpy.assert_that(test.is_failure()).is_not_none()

def test_not_failure_1():
t = create_junit_test_file("test_results_2.txt")
assertpy.assert_that(len(t)).is_equal_to(19)
for test in t:
assertpy.assert_that(test.is_failure()).is_none()
2 changes: 2 additions & 0 deletions tests/converter/tests_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
assertpy==0.15
pytest==5.3.1
52 changes: 5 additions & 47 deletions tests/converter/to_junit.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,13 @@
import re
from junit_xml import TestSuite, TestCase
import itertools
import os
import argparse
import os
from converter import create_junit_test_file, write_junit_file

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

tests = []

def file_log_parser(file:str) -> dict:
with open(file) as file_log:
config = file_log.read()
test_logs_results = {}
index = ""
for line in config.split("\n"):
if "++++Starting test" in line:
index = line.split(" ")[-1][:-4]
test_logs_results[index] = ""
elif "++++TEST" in line:
index = ""
elif index:
test_logs_results[index] += line + "\n"
return test_logs_results

# For each test we generate a testCase parsing the output file
for file in TESTS_FILE.split("\n"):
file_log = "test_log_" + "_".join(file.split("_")[2:])
test = file_log_parser(file_log)
with open(file) as file_buffer: # Use file to refer to the file object
config = file_buffer.read()
current_section = {}
lines = config.split()
date = lines[1]
is_relaunch = lines[2]
debug=lines[3]
for _,test_name,status,_,_,duration in zip(*[iter(lines[6:])]*6):
if duration == "false":
continue
else:
duration=duration[:-1]
if test_name in test:
tc = TestCase(name=test_name, elapsed_sec=int(duration),status=status, stdout=test[test_name])
else:
tc = TestCase(name=test_name, elapsed_sec=int(duration),status=status)
tests.append(tc)

# We create a TestSUite and we write them in a XML File
t = TestSuite(name=args.test_suite_name,test_cases=tests)
with open('output.xml', 'w') as f:
TestSuite.to_file(f, [t], prettyprint=False)
if __name__ == "__main__":
tests = create_junit_test_file(TESTS_FILE)
write_junit_file(OUTPUT_FILE,tests,args.test_suite_name)
16 changes: 8 additions & 8 deletions tests/helpers_tests.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ function cleanup {
cat $test_results

echo ""
echo "FAILED TESTS:"
echo "Failed TESTS:"
echo ""
cat $test_results | grep FAILED -A 1
cat $test_results | grep Failed -A 1

if $failed ; then
exit 1
Expand All @@ -41,15 +41,15 @@ function log_test {
fi
test_total=$(($test_total+1))
if [ $status -ne 0 ]; then
echo "++++TEST $1 FAILED++++"
echo "++++TEST $1 FAILED++++" >> $test_results
echo "++++TEST $1 FAILED++++" >> $test_tmp
echo "++++TEST $1 Failed++++"
echo "++++TEST $1 Failed++++" >> $test_results
echo "++++TEST $1 Failed++++" >> $test_tmp
failed=true
else
test_passed=$(($test_passed+1))
echo "++++TEST $1 PASSED++++"
echo "++++TEST $1 PASSED++++" >> $test_results
echo "++++TEST $1 PASSED++++" >> $test_tmp
echo "++++TEST $1 Passed++++"
echo "++++TEST $1 Passed++++" >> $test_results
echo "++++TEST $1 Passed++++" >> $test_tmp
fi
cat $test_tmp >> $test_log
return $status
Expand Down

0 comments on commit 1309c1a

Please sign in to comment.