fix coverage for hpa 19/101519/1
authorHaibin Huang <haibin.huang@intel.com>
Tue, 11 Feb 2020 08:56:34 +0000 (16:56 +0800)
committerHaibin Huang <haibin.huang@intel.com>
Tue, 11 Feb 2020 08:56:34 +0000 (16:56 +0800)
Issue-ID: MULTICLOUD-695
Signed-off-by: Haibin Huang <haibin.huang@intel.com>
Change-Id: I86c5c629308e93f8cff8f6f8b301b6bb94006077

hpa/hpa/base.py
hpa/hpa/hpa_discovery.py
hpa/requirements.txt [new file with mode: 0644]
hpa/test-requirements.txt [new file with mode: 0644]
hpa/tests/test_hpa_discovery.py
hpa/tox.ini

index 90eb643..ce99c97 100644 (file)
@@ -1,15 +1,18 @@
+"""
+base case for hpa discovery
+"""
 import abc
 
 import six
 
 
 @six.add_metaclass(abc.ABCMeta)
-class HPA_DiscoveryBase(object):
+class HPADiscoveryBase:
     """Base class for example plugin used in the tutorial.
     """
 
     def __init__(self):
-        """do nothing""" 
+        """do nothing"""
 
     @abc.abstractmethod
     def get_hpa_capabilities(self, data):
index acc10c3..f4dddbe 100644 (file)
@@ -1,3 +1,6 @@
+"""
+hpa discovery
+"""
 import traceback
 import uuid
 import json
@@ -6,6 +9,9 @@ from hpa import base
 
 
 def ignore_case_get(args, key, def_val=""):
+    """
+    get the value of key
+    """
     if not key:
         return def_val
     if key in args:
@@ -15,7 +21,7 @@ def ignore_case_get(args, key, def_val=""):
             return args[old_key]
     return def_val
 
-class HPA_Discovery(base.HPA_DiscoveryBase):
+class HPADiscovery(base.HPADiscoveryBase):
     """HPA Discovery implementation.
     """
     def __init__(self):
@@ -111,7 +117,7 @@ class HPA_Discovery(base.HPA_DiscoveryBase):
             basic_capability['hpa-feature-attributes'].append(
                 {'hpa-attribute-key':'virtualMemSize',
                  'hpa-attribute-value':
-                     '{{\"value\":\"{0}\",\"unit\":\"{1}\"}}'.format(flavor['ram'],"MB")
+                     '{{\"value\":\"{0}\",\"unit\":\"{1}\"}}'.format(flavor['ram'], "MB")
                  })
         except Exception as e:
             self._logger.error(traceback.format_exc())
@@ -209,21 +215,22 @@ class HPA_Discovery(base.HPA_DiscoveryBase):
                     hugepages_capability['hpa-feature-attributes'].append(
                         {'hpa-attribute-key': 'memoryPageSize',
                          'hpa-attribute-value':
-                             '{{\"value\":\"{0}\",\"unit\":\"{1}\"}}'.format(2,"MB")
+                             '{{\"value\":\"{0}\",\"unit\":\"{1}\"}}'.format(2, "MB")
                          })
                 elif extra_specs['hw:mem_page_size'] == 'small':
                     hugepages_capability['hpa-feature-attributes'].append(
                         {'hpa-attribute-key': 'memoryPageSize',
                          'hpa-attribute-value':
-                             '{{\"value\":\"{0}\",\"unit\":\"{1}\"}}'.format(4,"KB")
+                             '{{\"value\":\"{0}\",\"unit\":\"{1}\"}}'.format(4, "KB")
                          })
                 elif extra_specs['hw:mem_page_size'] == 'any':
-                    self._logger.info("Currently HPA feature memoryPageSize did not support 'any' page!!")
-                else :
+                    self._logger.info("Currently HPA feature did not support 'any'!!")
+                else:
                     hugepages_capability['hpa-feature-attributes'].append(
                         {'hpa-attribute-key': 'memoryPageSize',
                          'hpa-attribute-value':
-                             '{{\"value\":\"{0}\",\"unit\":\"{1}\"}}'.format(extra_specs['hw:mem_page_size'],"KB")
+                             '{{\"value\":\"{0}\",\"unit\":\"{1}\"}}'.format(
+                                 extra_specs['hw:mem_page_size'], "KB")
                          })
         except Exception:
             self._logger.error(traceback.format_exc())
@@ -264,7 +271,8 @@ class HPA_Discovery(base.HPA_DiscoveryBase):
                         numa_capability['hpa-feature-attributes'].append(
                             {'hpa-attribute-key': numamem_key,
                              'hpa-attribute-value':
-                                 '{{\"value\":\"{0}\",\"unit\":\"{1}\"}}'.format(extra_specs[numa_mem_node],"MB")
+                                 '{{\"value\":\"{0}\",\"unit\":\"{1}\"}}'.format(
+                                     extra_specs[numa_mem_node], "MB")
                              })
         except Exception:
             self._logger.error(traceback.format_exc())
@@ -362,7 +370,7 @@ class HPA_Discovery(base.HPA_DiscoveryBase):
                     {'hpa-attribute-key': 'pciDeviceId',
                      'hpa-attribute-value':
                          '{{\"value\":\"{0}\"}}'.format(value2[4])
-                                                                         })
+                     })
         except Exception:
             self._logger.error(traceback.format_exc())
 
@@ -431,14 +439,14 @@ class HPA_Discovery(base.HPA_DiscoveryBase):
                         cloud_extra_info_str = json.loads(cloud_extra_info_str)
                     except Exception as ex:
                         self._logger.error("Can not convert cloud extra info %s %s" % (
-                                     str(ex), cloud_extra_info_str))
+                            str(ex), cloud_extra_info_str))
                         return {}
-                if cloud_extra_info_str :
+                if cloud_extra_info_str:
                     cloud_dpdk_info = cloud_extra_info_str.get("ovsDpdk")
-                    if cloud_dpdk_info :
+                    if cloud_dpdk_info:
                         libname = cloud_dpdk_info.get("libname")
                         libversion = cloud_dpdk_info.get("libversion")
-            
+
             ovsdpdk_capability['hpa-feature-attributes'] = [
                 {
                     'hpa-attribute-key': str(libname),
diff --git a/hpa/requirements.txt b/hpa/requirements.txt
new file mode 100644 (file)
index 0000000..d4ff1e5
--- /dev/null
@@ -0,0 +1 @@
+onappylog>=1.0.9
diff --git a/hpa/test-requirements.txt b/hpa/test-requirements.txt
new file mode 100644 (file)
index 0000000..cc3059e
--- /dev/null
@@ -0,0 +1,6 @@
+# for unit test
+coverage==4.2
+mock==2.0.0
+unittest_xml_reporting==1.12.0
+
+pylint # GPLv2
index c63f377..9ccf4b6 100644 (file)
@@ -95,7 +95,7 @@ class TestDiscovery(unittest.TestCase):
         ]
 
         vimtype = "windriver"
-        hpa = hpa_discovery.HPA_Discovery()
+        hpa = hpa_discovery.HPADiscovery()
         for extra_spec in extra_specs:
             data = {"flavor": flavor, "extra_specs": extra_spec, "viminfo": viminfo, "vimtype": vimtype}
             results = hpa.get_hpa_capabilities(data)
index 1867049..fac628c 100644 (file)
@@ -1,11 +1,35 @@
 [tox]
-envlist = py36
+envlist = py36,cov,pylint
+skipdist = true
+
+[tox:jenkins]
+downloadcache = ~cache/pip
+
+[flake8]
+ignore = E501,E722
+exclude = ./venv-tox,./.tox
+max-complexity = 27
 
 [testenv]
-deps =
 basepython =
     py36: python3
     cov: python3
     pylint: python3
+deps =
+    -r{toxinidir}/requirements.txt
+    -r{toxinidir}/test-requirements.txt
 commands =
-    python3 -m unittest discover
+    coverage run -m unittest discover
+
+[testenv:pep8]
+deps=flake8
+commands = python3 -m flake8
+
+[testenv:cov]
+commands = coverage xml --omit="./venv-tox/*,./.tox/*,*tests*,*__init__.py,*site-packages*"
+
+[testenv:pylint]
+whitelist_externals = bash
+commands = 
+  bash -c "\
+    pylint -f parseable --reports=y hpa | tee pylint.out"