Merge "Add API for PPPoE clients statistic retrieval"
[yardstick.git] / yardstick / network_services / vnf_generic / vnf / sample_vnf.py
index a09f2a7..21719cb 100644 (file)
@@ -13,6 +13,7 @@
 # limitations under the License.
 
 import logging
+import decimal
 from multiprocessing import Queue, Value, Process
 import os
 import posixpath
@@ -499,6 +500,7 @@ class Rfc2544ResourceHelper(object):
         self._rfc2544 = None
         self._tolerance_low = None
         self._tolerance_high = None
+        self._tolerance_precision = None
 
     @property
     def rfc2544(self):
@@ -518,6 +520,12 @@ class Rfc2544ResourceHelper(object):
             self.get_rfc_tolerance()
         return self._tolerance_high
 
+    @property
+    def tolerance_precision(self):
+        if self._tolerance_precision is None:
+            self.get_rfc_tolerance()
+        return self._tolerance_precision
+
     @property
     def correlated_traffic(self):
         if self._correlated_traffic is None:
@@ -537,9 +545,13 @@ class Rfc2544ResourceHelper(object):
 
     def get_rfc_tolerance(self):
         tolerance_str = self.get_rfc2544('allowed_drop_rate', self.DEFAULT_TOLERANCE)
-        tolerance_iter = iter(sorted(float(t.strip()) for t in tolerance_str.split('-')))
-        self._tolerance_low = next(tolerance_iter)
-        self._tolerance_high = next(tolerance_iter, self.tolerance_low)
+        tolerance_iter = iter(sorted(
+            decimal.Decimal(t.strip()) for t in tolerance_str.split('-')))
+        tolerance_low = next(tolerance_iter)
+        tolerance_high = next(tolerance_iter, tolerance_low)
+        self._tolerance_precision = abs(tolerance_high.as_tuple().exponent)
+        self._tolerance_high = float(tolerance_high)
+        self._tolerance_low = float(tolerance_low)
 
 
 class SampleVNFDeployHelper(object):