From a84cbaaf620fff614a68e0cc95775c45738f14b1 Mon Sep 17 00:00:00 2001 From: Stepan Andrushko Date: Wed, 31 Oct 2018 15:58:51 +0200 Subject: [PATCH] Log VM OS version, Sample VNF branch/commit ID Added debug logs to track VM, Sample VNF details during testing: - Virtual machine OS, kernel version; - Sample VNF branch, commit ID. JIRA: YARDSTICK-1499 Change-Id: I243c435809d4541dfdb8c7c3466f50c5d524ac00 Signed-off-by: Stepan Andrushko --- .../tasks/cloudimg_modify_nsb.yml | 8 ++-- .../build_yardstick_image/tasks/post_build.yml | 11 ------ .../roles/download_samplevnfs/defaults/main.yml | 1 + ansible/roles/download_samplevnfs/tasks/main.yml | 4 ++ ansible/roles/install_samplevnf/tasks/main.yml | 32 +++++++++++++++ yardstick/benchmark/contexts/standalone/model.py | 11 ++++++ yardstick/common/utils.py | 45 ++++++++++++++++++++++ yardstick/tests/unit/common/test_utils.py | 28 ++++++++++++++ 8 files changed, 126 insertions(+), 14 deletions(-) diff --git a/ansible/roles/build_yardstick_image/tasks/cloudimg_modify_nsb.yml b/ansible/roles/build_yardstick_image/tasks/cloudimg_modify_nsb.yml index 8e2c3a623..65b9b8188 100644 --- a/ansible/roles/build_yardstick_image/tasks/cloudimg_modify_nsb.yml +++ b/ansible/roles/build_yardstick_image/tasks/cloudimg_modify_nsb.yml @@ -60,6 +60,11 @@ loop_var: role_item environment: "{{ proxy_env }}" +- include_vars: roles/install_dpdk/defaults/main.yml + when: INSTALL_BIN_PATH is undefined + +- include_vars: roles/download_samplevnfs/defaults/main.yml + - include_role: name: "{{ role_item }}" vars: @@ -72,9 +77,6 @@ loop_var: role_item environment: "{{ proxy_env }}" -- include_vars: roles/install_dpdk/defaults/main.yml - when: INSTALL_BIN_PATH is undefined - - name: Install PROX include_role: name: install_samplevnf diff --git a/ansible/roles/build_yardstick_image/tasks/post_build.yml b/ansible/roles/build_yardstick_image/tasks/post_build.yml index abbf57c03..14b7a3d17 100644 --- a/ansible/roles/build_yardstick_image/tasks/post_build.yml +++ b/ansible/roles/build_yardstick_image/tasks/post_build.yml @@ -51,17 +51,6 @@ - set_fact: imgdest: "/var/lib/libvirt/images/{{ imgfile | basename}}" - name: "{{ (imgfile | basename | splitext)[0] }}" - ext: "{{ (imgfile | basename | splitext)[1] }}" - -- name: Verify if imgfile exists in libvirt images - stat: - path: "{{ imgdest }}" - register: imgdest_stat - -- set_fact: - imgdest: "/var/lib/libvirt/images/{{ name }}_autogen{{ ext }}" - when: imgdest_stat.stat.exists - name: Copy image to libvirt images shell: "cp {{ imgfile }} {{ imgdest }}" diff --git a/ansible/roles/download_samplevnfs/defaults/main.yml b/ansible/roles/download_samplevnfs/defaults/main.yml index 5ddc9f0f9..2ae4d6159 100644 --- a/ansible/roles/download_samplevnfs/defaults/main.yml +++ b/ansible/roles/download_samplevnfs/defaults/main.yml @@ -14,3 +14,4 @@ samplevnf_url: "https://git.opnfv.org/samplevnf" samplevnf_dest: "{{ clone_dest }}/samplevnf" samplevnf_version: "47123bfc1b3c0d0b01884aebbce1a3e09ad7ddb0" +path_json: "{{ INSTALL_BIN_PATH }}/{{ inventory_hostname | basename }}_sample_vnf.json" diff --git a/ansible/roles/download_samplevnfs/tasks/main.yml b/ansible/roles/download_samplevnfs/tasks/main.yml index e9d4142c9..f98f2a42d 100644 --- a/ansible/roles/download_samplevnfs/tasks/main.yml +++ b/ansible/roles/download_samplevnfs/tasks/main.yml @@ -27,3 +27,7 @@ - set_fact: samplevnf_path: "{{ samplevnf_dest }}" + +- file: + dest: "{{ path_json }}" + state: absent diff --git a/ansible/roles/install_samplevnf/tasks/main.yml b/ansible/roles/install_samplevnf/tasks/main.yml index b5d33f668..ad147b00f 100644 --- a/ansible/roles/install_samplevnf/tasks/main.yml +++ b/ansible/roles/install_samplevnf/tasks/main.yml @@ -56,3 +56,35 @@ # make executable mode: 0755 +- set_fact: + path_vnf: "{{ INSTALL_BIN_PATH }}/{{ vnf_app_names[vnf_name]}}" + +- stat: + path: "{{ path_vnf }}" + checksum_algorithm: md5 + register: path_vnf_var + +- stat: + path: "{{ path_json }}" + register: path_json_var + +- name: Fetch from remote + fetch: + src: "{{ path_json }}" + dest: "{{ path_json }}" + flat: yes + when: path_json_var.stat.exists + +- name: Read from json + set_fact: + json_vars: "{{ lookup('file', path_json) | from_json }}" + when: path_json_var.stat.exists + +- set_fact: + json_vars: "{{ json_vars | default([]) | combine({ vnf_app_names[vnf_name]: {'branch_commit': samplevnf_version, 'path_vnf': path_vnf, 'md5': path_vnf_var.stat.checksum }}) }}" + +- name: Update json file + copy: + content: "{{ json_vars | to_nice_json }}" + dest: "{{ path_json }}" + mode: 0755 diff --git a/yardstick/benchmark/contexts/standalone/model.py b/yardstick/benchmark/contexts/standalone/model.py index aa5fdd391..a15426872 100644 --- a/yardstick/benchmark/contexts/standalone/model.py +++ b/yardstick/benchmark/contexts/standalone/model.py @@ -26,6 +26,7 @@ import xml.etree.ElementTree as ET from yardstick import ssh from yardstick.common import constants from yardstick.common import exceptions +from yardstick.common import utils as common_utils from yardstick.common import yaml_loader from yardstick.network_services.utils import PciAddress from yardstick.network_services.helpers.cpu import CpuSysCores @@ -554,6 +555,16 @@ class StandaloneContextHelper(object): ip = cls.get_mgmt_ip(connection, node["mac"], mgmtip, node) if ip: node["ip"] = ip + client = ssh.SSH.from_node(node) + LOG.debug("OS version: %s", + common_utils.get_os_version(client)) + LOG.debug("Kernel version: %s", + common_utils.get_kernel_version(client)) + vnfs_data = common_utils.get_sample_vnf_info(client) + for vnf_name, vnf_data in vnfs_data.items(): + LOG.debug("VNF name: '%s', commit ID/branch: '%s'", + vnf_name, vnf_data["branch_commit"]) + LOG.debug("%s", vnf_data["md5_result"]) return nodes @classmethod diff --git a/yardstick/common/utils.py b/yardstick/common/utils.py index 9eba896e2..7475f6991 100644 --- a/yardstick/common/utils.py +++ b/yardstick/common/utils.py @@ -19,6 +19,7 @@ import datetime import errno import importlib import ipaddress +import json import logging import os import pydoc @@ -629,3 +630,47 @@ def safe_cast(value, type_to_convert, default_value): return _type(value) except ValueError: return default_value + + +def get_os_version(ssh_client): + """Return OS version. + + :param ssh_client: SSH + :return str: Linux OS versions + """ + os_ver = ssh_client.execute("cat /etc/lsb-release")[1] + return os_ver + + +def get_kernel_version(ssh_client): + """Return kernel version. + + :param ssh_client: SSH + :return str: Linux kernel versions + """ + kernel_ver = ssh_client.execute("uname -a")[1] + return kernel_ver + + +def get_sample_vnf_info(ssh_client, + json_file='/opt/nsb_bin/yardstick_sample_vnf.json'): + """Return sample VNF data. + + :param ssh_client: SSH + :param json_file: str + :return dict: information about sample VNF + """ + rc, json_str, err = ssh_client.execute("cat %s" % json_file) + logger.debug("cat %s: %s, rc: %s, err: %s", json_file, json_str, rc, err) + + if rc: + return {} + json_data = json.loads(json_str) + for vnf_data in json_data.values(): + out = ssh_client.execute("md5sum %s" % vnf_data["path_vnf"])[1] + md5 = out.split()[0].strip() + if md5 == vnf_data["md5"]: + vnf_data["md5_result"] = "MD5 checksum is valid" + else: + vnf_data["md5_result"] = "MD5 checksum is invalid" + return json_data diff --git a/yardstick/tests/unit/common/test_utils.py b/yardstick/tests/unit/common/test_utils.py index 6b8d81907..8fed5ecf1 100644 --- a/yardstick/tests/unit/common/test_utils.py +++ b/yardstick/tests/unit/common/test_utils.py @@ -1433,3 +1433,31 @@ class SetupHugepagesTestCase(unittest.TestCase): self.assertEqual(hp_size_kb, 1024) self.assertEqual(hp_number, 10) self.assertEqual(hp_number_set, 5) + + +class GetOSSampleInfoTestCase(unittest.TestCase): + + def test_get_os_version(self, *args): + ssh = mock.Mock() + ssh.execute.return_value = (0, "18.04", "") + utils.get_os_version(ssh) + ssh.execute.assert_called_once_with("cat /etc/lsb-release") + + def test_get_kernel_version(self, *args): + ssh = mock.Mock() + ssh.execute.return_value = (0, "Linux", "") + utils.get_kernel_version(ssh) + ssh.execute.assert_called_once_with("uname -a") + + def test_get_sample_vnf_info(self, *args): + json_out = """ + {"UDP_Replay": { + "branch_commit": "47123bfc1b3c0d0b01884aebbce1a3e09ad7ddb0", + "md5": "4577702f6d6848380bd912232a1b9ca5", + "path_vnf": "/opt/nsb_bin/UDP_Replay" + } + }""" + json_file = '/opt/nsb_bin/yardstick_sample_vnf.json' + ssh = mock.Mock() + ssh.execute.return_value = (0, json_out, "") + utils.get_sample_vnf_info(ssh, json_file) -- 2.16.6