[lxc-devel] [nova-lxd/master] fixed unit conversions in network quotas

peter-slovak on Github lxc-bot at linuxcontainers.org
Tue May 24 17:57:08 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 560 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160524/ef0872a6/attachment.bin>
-------------- next part --------------
From a2de90637f25d09105ee270822d66031c0ae6818 Mon Sep 17 00:00:00 2001
From: Peter Slovak <peter.slovak at websupport.sk>
Date: Tue, 24 May 2016 19:51:31 +0200
Subject: [PATCH] fixed unit conversions in network quotas

---
 nova/tests/unit/virt/lxd/test_config.py | 22 ++++++++++++----------
 nova/virt/lxd/config.py                 |  7 ++++---
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/nova/tests/unit/virt/lxd/test_config.py b/nova/tests/unit/virt/lxd/test_config.py
index a97c4bd..8f32d2b 100644
--- a/nova/tests/unit/virt/lxd/test_config.py
+++ b/nova/tests/unit/virt/lxd/test_config.py
@@ -216,9 +216,11 @@ def test_disk_quota_rw_and_total_iops_and_bytes(self):
 
     def test_network_in_out_average(self):
         instance = stubs._fake_instance()
+        # We get KB/s from flavor spec, but expect Mbit/s
+        # in LXD confix
         instance.flavor.extra_specs = {
-            'quota:vif_inbound_average': 20 * units.M,
-            'quota:vif_outbound_average': 8 * units.M
+            'quota:vif_inbound_average': 20000,
+            'quota:vif_outbound_average': 8000
         }
         instance_name = 'fake_instance'
         network_info = fake_network.fake_get_instance_nw_info(self)
@@ -228,17 +230,17 @@ def test_network_in_out_average(self):
                                        'nictype': 'bridged',
                                        'parent': 'fake_br1',
                                        'type': 'nic',
-                                       'limits.ingress': '20Mbit',
-                                       'limits.egress': '8Mbit'}}, config)
+                                       'limits.ingress': '160Mbit',
+                                       'limits.egress': '64Mbit'}}, config)
 
     def test_network_in_out_average_and_peak(self):
         # Max of the two values should take precedence
         instance = stubs._fake_instance()
         instance.flavor.extra_specs = {
-            'quota:vif_inbound_average': 2 * units.M,
-            'quota:vif_outbound_average': 10 * units.M,
-            'quota:vif_inbound_peak': 10 * units.M,
-            'quota:vif_outbound_peak': 2 * units.M,
+            'quota:vif_inbound_average': 2000,
+            'quota:vif_outbound_average': 10000,
+            'quota:vif_inbound_peak': 10000,
+            'quota:vif_outbound_peak': 2000,
         }
         instance_name = 'fake_instance'
         network_info = fake_network.fake_get_instance_nw_info(self)
@@ -248,5 +250,5 @@ def test_network_in_out_average_and_peak(self):
                                        'nictype': 'bridged',
                                        'parent': 'fake_br1',
                                        'type': 'nic',
-                                       'limits.ingress': '10Mbit',
-                                       'limits.egress': '10Mbit'}}, config)
+                                       'limits.ingress': '80Mbit',
+                                       'limits.egress': '80Mbit'}}, config)
diff --git a/nova/virt/lxd/config.py b/nova/virt/lxd/config.py
index 714e813..ccf5f60 100644
--- a/nova/virt/lxd/config.py
+++ b/nova/virt/lxd/config.py
@@ -310,14 +310,15 @@ def create_network_quota_config(self, instance):
         # Since LXD does not implement average NIC IO and number of burst
         # bytes, we take the max(vif_*_average, vif_*_peak) to set the peak
         # network IO and simply ignore the burst bytes.
-        # Align values to MB/s (powers of 1000 in this case)
+        # Align values to MBit/s (8 * powers of 1000 in this case), having
+        # in mind that the values are recieved in Kilobytes/s.
         vif_inbound_limit = max(
             q.get('vif_inbound_average'),
             q.get('vif_inbound_peak')
         )
         if vif_inbound_limit:
             network_config['limits.ingress'] = \
-                ('%s' + 'Mbit') % (vif_inbound_limit / units.M)
+                ('%s' + 'Mbit') % (vif_inbound_limit * units.k * 8 / units.M)
 
         vif_outbound_limit = max(
             q.get('vif_outbound_average'),
@@ -325,7 +326,7 @@ def create_network_quota_config(self, instance):
         )
         if vif_outbound_limit:
             network_config['limits.egress'] = \
-                ('%s' + 'Mbit') % (vif_outbound_limit / units.M)
+                ('%s' + 'Mbit') % (vif_outbound_limit * units.k * 8 / units.M)
 
         return network_config
 


More information about the lxc-devel mailing list