summaryrefslogtreecommitdiffstats
path: root/hpa
diff options
context:
space:
mode:
Diffstat (limited to 'hpa')
-rw-r--r--hpa/hpa/base.py7
-rw-r--r--hpa/hpa/hpa_discovery.py34
-rw-r--r--hpa/requirements.txt1
-rw-r--r--hpa/test-requirements.txt6
-rw-r--r--hpa/tests/test_hpa_discovery.py2
-rw-r--r--hpa/tox.ini30
6 files changed, 61 insertions, 19 deletions
diff --git a/hpa/hpa/base.py b/hpa/hpa/base.py
index 90eb6432..ce99c970 100644
--- a/hpa/hpa/base.py
+++ b/hpa/hpa/base.py
@@ -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):
diff --git a/hpa/hpa/hpa_discovery.py b/hpa/hpa/hpa_discovery.py
index acc10c3c..f4dddbe6 100644
--- a/hpa/hpa/hpa_discovery.py
+++ b/hpa/hpa/hpa_discovery.py
@@ -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
index 00000000..d4ff1e59
--- /dev/null
+++ b/hpa/requirements.txt
@@ -0,0 +1 @@
+onappylog>=1.0.9
diff --git a/hpa/test-requirements.txt b/hpa/test-requirements.txt
new file mode 100644
index 00000000..cc3059e2
--- /dev/null
+++ b/hpa/test-requirements.txt
@@ -0,0 +1,6 @@
+# for unit test
+coverage==4.2
+mock==2.0.0
+unittest_xml_reporting==1.12.0
+
+pylint # GPLv2
diff --git a/hpa/tests/test_hpa_discovery.py b/hpa/tests/test_hpa_discovery.py
index c63f377f..9ccf4b66 100644
--- a/hpa/tests/test_hpa_discovery.py
+++ b/hpa/tests/test_hpa_discovery.py
@@ -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)
diff --git a/hpa/tox.ini b/hpa/tox.ini
index 18670499..fac628cb 100644
--- a/hpa/tox.ini
+++ b/hpa/tox.ini
@@ -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"