summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhijiang Hu <hu.zhijiang@zte.com.cn>2018-04-24 06:50:26 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-04-24 06:50:26 +0000
commitafb9b05fc088fdb60168a2dd25dda90b5d3ab2d3 (patch)
tree8abb8b30725e042465170863e89291517e80bf60
parenta2bf9736427ae6e6224cf5e629313c5069982841 (diff)
parent8f2ee9b2e21fbd20e088a94f5292ffeb476d2895 (diff)
Merge "Calculate hugepage num accoding to host's memory"
-rw-r--r--deploy/tempest.py22
-rw-r--r--tests/unit/test_placeholder.py1
-rw-r--r--tests/unit/test_tempest.py16
3 files changed, 37 insertions, 2 deletions
diff --git a/deploy/tempest.py b/deploy/tempest.py
index 342a0205..93dabbe3 100644
--- a/deploy/tempest.py
+++ b/deploy/tempest.py
@@ -238,7 +238,7 @@ def update_hosts_interface(cluster_id, hosts_info, mac_address_map,
if host['os_version'] == iso_path:
print("do not have os iso file in /var/lib/daisy/kolla/.")
if enable_dpdk:
- host['hugepages'] = '80'
+ host['hugepages'] = str(get_hugepages(host))
host['hugepagesize'] = '1G'
client.hosts.update(host['id'], **host)
host_info = client.hosts.get(host['id']).to_dict()
@@ -249,6 +249,26 @@ def update_hosts_interface(cluster_id, hosts_info, mac_address_map,
add_host_role(cluster_id, host['id'], dha_host_name, vip, client)
+def get_hugepages(host):
+ total_str = str(host['memory']['total'])
+ total = int(filter(str.isdigit, total_str))
+ unit = filter(str.isalpha, total_str).lower()
+
+ if unit == 'kb':
+ total = total / 1024 / 1024
+ elif unit == 'mb':
+ total = total / 1024
+ elif unit == 'gb':
+ pass
+ elif unit == 'b' or unit == '':
+ total = total / 1024 / 1024 / 1024
+ num = total * 6 / 10
+ if num % 2 != 0:
+ num = num + 1
+
+ return num
+
+
def add_host_role(cluster_id, host_id, dha_host_name, vip, client):
role_meta = {'filters': {'cluster_id': cluster_id}}
role_list_generator = client.roles.list(**role_meta)
diff --git a/tests/unit/test_placeholder.py b/tests/unit/test_placeholder.py
index a5298e14..7fa104ff 100644
--- a/tests/unit/test_placeholder.py
+++ b/tests/unit/test_placeholder.py
@@ -7,5 +7,6 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+
def test_holder():
assert True
diff --git a/tests/unit/test_tempest.py b/tests/unit/test_tempest.py
index 3c616bcd..3e229dc9 100644
--- a/tests/unit/test_tempest.py
+++ b/tests/unit/test_tempest.py
@@ -35,6 +35,7 @@ from deploy.tempest import (
get_hosts,
get_cluster,
update_hosts_interface,
+ get_hugepages,
add_host_role,
enable_cinder_backend,
enable_opendaylight
@@ -173,7 +174,9 @@ def test_get_cluster():
@pytest.mark.parametrize('isbare', [
(False), (True)])
-def test_update_hosts_interface(isbare, tmpdir):
+@mock.patch('deploy.tempest.get_hugepages')
+def test_update_hosts_interface(mock_get_hugepages, isbare, tmpdir):
+ mock_get_hugepages.return_value = 80
res_old_val = deploy.tempest.iso_path
deploy.tempest.iso_path = os.path.join(tmpdir.dirname, tmpdir.basename) + '/'
iso_file_path = os.path.join(deploy.tempest.iso_path, 'test_os.iso')
@@ -276,6 +279,17 @@ def test_update_hosts_interface(isbare, tmpdir):
tmpdir.remove()
+@pytest.mark.parametrize('host, exp', [
+ ({'memory': {'total': ' 65938504 kB'}}, 38),
+ ({'memory': {'total': ' 131644068 kB'}}, 76),
+ ({'memory': {'total': ' 100 gB'}}, 60),
+ ({'memory': {'total': ' 102400 mB'}}, 60),
+ ({'memory': {'total': ' 107374182400 B'}}, 60),
+ ({'memory': {'total': ' 107374182400'}}, 60)])
+def test_get_hugepages(host, exp):
+ assert get_hugepages(host) == exp
+
+
@pytest.mark.parametrize('dha_host_name, cluster_id, host_id, vip, exp', [
('controller01', 1, 0x1234, '10.20.11.11', {'nodes': [0x1234], 'cluster_id': 1, 'vip': '10.20.11.11'}),
('computer01', 1, 0x2345, '10.20.11.11', {'nodes': [0x2345], 'cluster_id': 1}),