Ejemplo n.º 1
0
 def test_get_memory_mb_total_not_running_on_linux(self):
     self.mox.StubOutWithMock(ovz_utils, 'sys')
     self.mox.StubOutWithMock(ovz_utils.sys, 'platform')
     self.mox.StubOutWithMock(ovz_utils.sys.platform, 'upper')
     ovz_utils.sys.platform.upper().AndReturn('DARWIN')
     self.mox.ReplayAll()
     result = ovz_utils.get_memory_mb_total()
     self.assertEqual(result, 1)
Ejemplo n.º 2
0
    def _percent_of_resource(self, instance_memory):
        """
        In order to evenly distribute resources this method will calculate a
        multiplier based on memory consumption for the allocated container and
        the overall host memory. This can then be applied to the cpuunits in
        self.utility to be passed as an argument to the self._set_cpuunits
        method to limit cpu usage of the container to an accurate percentage of
        the host.  This is only done on self.spawn so that later, should
        someone choose to do so, they can adjust the container's cpu usage
        up or down.
        """
        cont_mem_mb = (
            float(instance_memory) / float(ovz_utils.get_memory_mb_total()))

        # We shouldn't ever have more than 100% but if for some unforseen
        # reason we do, lets limit it to 1 to make all of the other
        # calculations come out clean.
        if cont_mem_mb > 1:
            LOG.error(_('_percent_of_resource came up with more than 100%'))
            return 1.0
        else:
            return cont_mem_mb