Log VM OS version, Sample VNF branch/commit ID 09/64309/6
authorStepan Andrushko <stepanx.andrushko@intel.com>
Wed, 31 Oct 2018 13:58:51 +0000 (15:58 +0200)
committerStepan Andrushko <stepanx.andrushko@intel.com>
Fri, 19 Apr 2019 10:41:24 +0000 (10:41 +0000)
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 <stepanx.andrushko@intel.com>
ansible/roles/build_yardstick_image/tasks/cloudimg_modify_nsb.yml
ansible/roles/build_yardstick_image/tasks/post_build.yml
ansible/roles/download_samplevnfs/defaults/main.yml
ansible/roles/download_samplevnfs/tasks/main.yml
ansible/roles/install_samplevnf/tasks/main.yml
yardstick/benchmark/contexts/standalone/model.py
yardstick/common/utils.py
yardstick/tests/unit/common/test_utils.py

index 8e2c3a6..65b9b81 100644 (file)
     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
index abbf57c..14b7a3d 100644 (file)
 \r
 - set_fact:\r
     imgdest: "/var/lib/libvirt/images/{{ imgfile | basename}}"\r
-    name: "{{ (imgfile | basename | splitext)[0] }}"\r
-    ext: "{{ (imgfile | basename | splitext)[1] }}"\r
-\r
-- name: Verify if imgfile exists in libvirt images\r
-  stat:\r
-    path: "{{ imgdest }}"\r
-  register: imgdest_stat\r
-\r
-- set_fact:\r
-    imgdest: "/var/lib/libvirt/images/{{ name }}_autogen{{ ext }}"\r
-  when: imgdest_stat.stat.exists\r
 \r
 - name: Copy image to libvirt images\r
   shell: "cp {{ imgfile }} {{ imgdest }}"\r
index 5ddc9f0..2ae4d61 100644 (file)
@@ -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"
index e9d4142..f98f2a4 100644 (file)
@@ -27,3 +27,7 @@
 
 - set_fact:
     samplevnf_path: "{{ samplevnf_dest }}"
+
+- file:
+   dest: "{{ path_json }}"
+   state: absent
index b5d33f6..ad147b0 100644 (file)
     # 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
index aa5fdd3..a154268 100644 (file)
@@ -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
index 9eba896..7475f69 100644 (file)
@@ -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
index 6b8d819..8fed5ec 100644 (file)
@@ -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)