Calculate hugepage num accoding to host's memory 17/56117/1
authorAlex Yang <yangyang1@zte.com.cn>
Thu, 19 Apr 2018 03:11:54 +0000 (11:11 +0800)
committerAlex Yang <yangyang1@zte.com.cn>
Thu, 19 Apr 2018 03:11:54 +0000 (11:11 +0800)
Change-Id: I49cfa3265af776e3cdea5de59096ff3257f75fb0
Signed-off-by: Alex Yang <yangyang1@zte.com.cn>
deploy/tempest.py
tests/unit/test_placeholder.py
tests/unit/test_tempest.py

index 342a020..93dabbe 100644 (file)
@@ -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)
index a5298e1..7fa104f 100644 (file)
@@ -7,5 +7,6 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 
+
 def test_holder():
     assert True
index 3c616bc..3e229dc 100644 (file)
@@ -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}),