CSIT-841 Optimize creating of vnf-agent docker image Part I 78/8778/16
authorPeter Mikus <pmikus@cisco.com>
Thu, 12 Oct 2017 09:06:58 +0000 (09:06 +0000)
committerPeter Mikus <pmikus@cisco.com>
Mon, 16 Oct 2017 08:55:52 +0000 (08:55 +0000)
- Optimize building of prod_vpp_agent docker image by using
  dev_vpp_agent docker image pulled from dockerhub/ligato instead of
  building on slave.
- Add detailed logs from every POD deployed in namespace.
- Hardening condition for considering PODs Running.

Change-Id: I9f771d6365d38fef2ec2e00ab642853e6a44ad03
Signed-off-by: Peter Mikus <pmikus@cisco.com>
LIGATO_STABLE_VER [deleted file]
VPP_AGENT_STABLE_VER [new file with mode: 0644]
bootstrap-verify-perf-ligato.sh
resources/libraries/python/KubernetesUtils.py
resources/tools/scripts/topo_container_copy.py
tests/ligato/perf/l2/10ge2p1x520-eth-l2bdbase-eth-2memif-1vnf-ndrpdrdisc.robot
tests/ligato/perf/l2/10ge2p1x520-eth-l2xcbase-eth-2memif-1vnf-ndrpdrdisc.robot

diff --git a/LIGATO_STABLE_VER b/LIGATO_STABLE_VER
deleted file mode 100644 (file)
index ce15bd9..0000000
+++ /dev/null
@@ -1 +0,0 @@
-8b61778490fa4a22df294b0682c13e39b8f51869
diff --git a/VPP_AGENT_STABLE_VER b/VPP_AGENT_STABLE_VER
new file mode 100644 (file)
index 0000000..849f17f
--- /dev/null
@@ -0,0 +1 @@
+v1.0.5-2-g0c0f202
index 7c4c6d3..f00183f 100644 (file)
@@ -29,10 +29,65 @@ PYBOT_ARGS="-W 150 -L TRACE"
 
 ARCHIVE_ARTIFACTS=(log.html output.xml report.html output_perf_data.xml)
 
+# If we run this script from CSIT jobs we want to use stable vpp version
+if [[ ${JOB_NAME} == csit-* ]] ;
+then
+    mkdir -p vpp/build-root
+    cd vpp/build-root
+
+    if [[ ${TEST_TAG} == *NIGHTLY ]] || \
+       [[ ${TEST_TAG} == *DAILY ]] || \
+       [[ ${TEST_TAG} == *WEEKLY ]];
+    then
+        # Download the latest VPP build .deb install packages
+        echo Downloading VPP packages...
+        bash ${SCRIPT_DIR}/resources/tools/scripts/download_install_vpp_pkgs.sh --skip-install
+
+        VPP_DEBS="$( readlink -f *.deb | tr '\n' ' ' )"
+        # Take vpp package and get the vpp version
+        VPP_STABLE_VER="$( expr match $(ls *.deb | head -n 1) 'vpp-\(.*\)-deb.deb' )"
+    else
+        DPDK_STABLE_VER=$(cat ${SCRIPT_DIR}/DPDK_STABLE_VER)_amd64
+        VPP_REPO_URL=$(cat ${SCRIPT_DIR}/VPP_REPO_URL_UBUNTU)
+        VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER_UBUNTU)
+        VPP_CLASSIFIER="-deb"
+        # Download vpp build from nexus and set VPP_DEBS variable
+        wget -q "${VPP_REPO_URL}/vpp/${VPP_STABLE_VER}/vpp-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
+        wget -q "${VPP_REPO_URL}/vpp-dbg/${VPP_STABLE_VER}/vpp-dbg-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
+        wget -q "${VPP_REPO_URL}/vpp-dev/${VPP_STABLE_VER}/vpp-dev-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
+        # Temporary disable using dpdk
+        # wget -q "${VPP_REPO_URL}/vpp-dpdk-dkms/${DPDK_STABLE_VER}/vpp-dpdk-dkms-${DPDK_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
+        wget -q "${VPP_REPO_URL}/vpp-lib/${VPP_STABLE_VER}/vpp-lib-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
+        wget -q "${VPP_REPO_URL}/vpp-plugins/${VPP_STABLE_VER}/vpp-plugins-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit
+        VPP_DEBS="$( readlink -f *.deb | tr '\n' ' ' )"
+    fi
+
+    # Temporary workaround as ligato docker file requires specific file name
+    rename -v 's/^(.*)-(\d.*)-deb.deb/$1_$2.deb/' *.deb
+    cd ${SCRIPT_DIR}
+
+# If we run this script from vpp project we want to use local build
+elif [[ ${JOB_NAME} == vpp-* ]] ;
+then
+    mkdir -p vpp/build-root
+    # Use local packages provided as argument list
+    # Jenkins VPP deb paths (convert to full path)
+    VPP_DEBS="$( readlink -f $@ | tr '\n' ' ' )"
+    # Take vpp package and get the vpp version
+    VPP_STABLE_VER="$( expr match $1 'vpp-\(.*\)-deb.deb' )"
+    # Move files to build-root for packing
+    for deb in ${VPP_DEBS}; do mv ${deb} vpp/build-root/; done
+else
+    echo "Unable to identify job type based on JOB_NAME variable: ${JOB_NAME}"
+    exit 1
+fi
+
+# Compress all VPP debs and remove temporary directory
+tar -zcvf ${SCRIPT_DIR}/vpp.tar.gz vpp/*  && rm -R vpp
+
 LIGATO_REPO_URL=$(cat ${SCRIPT_DIR}/LIGATO_REPO_URL)
-LIGATO_STABLE_VER=$(cat ${SCRIPT_DIR}/LIGATO_STABLE_VER)
-VPP_COMMIT=$1
-VPP_BUILD=$1
+VPP_AGENT_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_AGENT_STABLE_VER)
+VPP_AGENT_STABLE_COMMIT="$( expr match `cat VPP_AGENT_STABLE_VER` '.*g\(.*\)' )"
 DOCKER_DEB="docker-ce_17.06.2~ce-0~ubuntu_amd64.deb"
 
 # Clone & checkout stable vnf-agent
@@ -42,10 +97,10 @@ if [ $? != 0 ]; then
     echo "Failed to run: git clone --depth 1 ${LIGATO_REPO_URL}/vpp-agent"
     exit 1
 fi
-cd vpp-agent && git checkout ${LIGATO_STABLE_VER}
+cd vpp-agent && git checkout ${VPP_AGENT_STABLE_COMMIT}
 # If the git checkout fails, complain clearly and exit
 if [ $? != 0 ]; then
-    echo "Failed to run: git checkout ${LIGATO_STABLE_VER}"
+    echo "Failed to run: git checkout ${VPP_AGENT_STABLE_VER}"
     exit 1
 fi
 
@@ -58,12 +113,17 @@ if [ $? != 0 ]; then
     exit 1
 fi
 
-# Compile vnf-agent docker image
-cd ${SCRIPT_DIR}/../vpp-agent/docker/dev_vpp_agent/ &&\
-    ./build.sh --agent ${LIGATO_STABLE_VER} --vpp ${VPP_COMMIT} &&\
-    ./shrink.sh
+# Pull ligato/dev_vpp_agent docker image and re-tag as local
+sudo docker pull ligato/dev-vpp-agent:${VPP_AGENT_STABLE_VER}
+sudo docker tag ligato/dev-vpp-agent:${VPP_AGENT_STABLE_VER}\
+    dev_vpp_agent:latest
+sudo docker images
+
+# Build prod_vpp_agent docker image
 cd ${SCRIPT_DIR}/../vpp-agent/docker/prod_vpp_agent/ &&\
-    ./build.sh &&\
+    mv ${SCRIPT_DIR}/vpp.tar.gz . &&\
+    ./extract_agent_files.sh &&\
+    sudo docker build -t prod_vpp_agent --no-cache . &&\
     ./shrink.sh
 # Export Docker image
 sudo docker save prod_vpp_agent_shrink | gzip > prod_vpp_agent_shrink.tar.gz
@@ -347,7 +407,7 @@ echo Post-processing test data...
 python ${SCRIPT_DIR}/resources/tools/scripts/robot_output_parser.py \
        -i ${SCRIPT_DIR}/output.xml \
        -o ${SCRIPT_DIR}/output_perf_data.xml \
-       -v ${VPP_BUILD}
+       -v ${VPP_STABLE_VER}
 if [ ! $? -eq 0 ]; then
     echo "Parsing ${SCRIPT_DIR}/output.xml failed"
 fi
index 5faa056..77628b6 100644 (file)
@@ -243,6 +243,36 @@ class KubernetesUtils(object):
                 KubernetesUtils.describe_kubernetes_resource_on_node(node,
                                                                      rtype)
 
+    @staticmethod
+    def get_kubernetes_logs_on_node(node, namespace='csit'):
+        """Get Kubernetes logs on node.
+
+        :param node: DUT node.
+        :param namespace: Kubernetes namespace.
+        :type node: dict
+        :type namespace: str
+        """
+        ssh = SSH()
+        ssh.connect(node)
+
+        cmd = "for p in $(kubectl get pods -n {namespace} --no-headers"\
+            " | cut -f 1 -d ' '); do echo $p; kubectl logs -n {namespace} $p; "\
+            "done".format(namespace=namespace)
+        ssh.exec_command(cmd, timeout=120)
+
+    @staticmethod
+    def get_kubernetes_logs_on_all_duts(nodes, namespace='csit'):
+        """Get Kubernetes logs on all DUTs.
+
+        :param nodes: Topology nodes.
+        :param namespace: Kubernetes namespace.
+        :type nodes: dict
+        :type namespace: str
+        """
+        for node in nodes.values():
+            if node['type'] == NodeType.DUT:
+                KubernetesUtils.get_kubernetes_logs_on_node(node, namespace)
+
     @staticmethod
     def reset_kubernetes_on_node(node):
         """Reset Kubernetes on node.
@@ -288,7 +318,9 @@ class KubernetesUtils(object):
             if int(ret_code) == 0:
                 ready = True
                 for line in stdout.splitlines():
-                    if 'Running' not in line:
+                    if 'Running' in line and '1/1' in line:
+                        ready = True
+                    else:
                         ready = False
                 if ready:
                     break
index d243182..088b7a4 100644 (file)
@@ -122,11 +122,16 @@ def main():
                     ssh.scp(local_path=image, remote_path=directory)
 
                 # Load image to Docker.
-                cmd = "for f in {directory}/*.tar.gz; do zcat $f | "\
-                    "sudo docker load; done".format(directory=directory)
+                cmd = "for f in {directory}/*.tar.gz; do "\
+                    "sudo docker load -i $f; done".format(directory=directory)
                 stdout = ssh_no_error(ssh, cmd)
                 print("###TI {}".format(stdout))
 
+                # Remove <none> images from Docker.
+                cmd = "docker rmi $(sudo docker images -f 'dangling=true' -q)"
+                stdout = ssh_no_error(ssh, cmd, sudo=True)
+                print("###TI {}".format(stdout))
+
 
 if __name__ == "__main__":
     sys.exit(main())
index 277c3ab..cfc74c3 100644 (file)
@@ -28,6 +28,7 @@
 | Suite Teardown | Tear down 3-node performance topology
 | ...
 | Test Teardown | Run Keywords
+| ... | Get Kubernetes logs on all DUTs | ${nodes} | AND
 | ... | Describe Kubernetes resource on all DUTs | ${nodes} | AND
 | ... | Delete Kubernetes resource on all duts | ${nodes}
 | ...
index 6dba66f..759065b 100644 (file)
@@ -28,6 +28,7 @@
 | Suite Teardown | Tear down 3-node performance topology
 | ...
 | Test Teardown | Run Keywords
+| ... | Get Kubernetes logs on all DUTs | ${nodes} | AND
 | ... | Describe Kubernetes resource on all DUTs | ${nodes} | AND
 | ... | Delete Kubernetes resource on all duts | ${nodes}
 | ...