def test_get_host_stats(self):
     memory = {
         'total': 4 * units.Mi,
         'used': 1 * units.Mi
     }
     self.mox.StubOutWithMock(socket, 'gethostname')
     self.mox.StubOutWithMock(hostinfo, 'get_memory_usage')
     socket.gethostname().AndReturn('foo')
     hostinfo.get_memory_usage().AndReturn(memory)
     socket.gethostname().AndReturn('bar')
     hostinfo.get_memory_usage().AndReturn(memory)
     self.mox.ReplayAll()
     self.assertEqual('foo',
                      self.connection.get_host_stats()['host_hostname'])
     self.assertEqual('foo',
                      self.connection.get_host_stats()['host_hostname'])
Exemple #2
0
    def get_available_resource(self, nodename):
        if not hasattr(self, '_nodename'):
            self._nodename = nodename
        if nodename != self._nodename:
            LOG.error(_('Hostname has changed from %(old)s to %(new)s. '
                        'A restart is required to take effect.'
                        ), {'old': self._nodename,
                            'new': nodename})

        memory = hostinfo.get_memory_usage()
        disk = hostinfo.get_disk_usage()
        stats = {
            'vcpus': 1,
            'vcpus_used': 0,
            'memory_mb': memory['total'] / units.Mi,
            'memory_mb_used': memory['used'] / units.Mi,
            'local_gb': disk['total'] / units.Gi,
            'local_gb_used': disk['used'] / units.Gi,
            'disk_available_least': disk['available'] / units.Gi,
            'hypervisor_type': 'docker',
            'hypervisor_version': utils.convert_version_to_int('1.0'),
            'hypervisor_hostname': self._nodename,
            'cpu_info': '?',
            'supported_instances': jsonutils.dumps([
                ('i686', 'docker', 'lxc'),
                ('x86_64', 'docker', 'lxc')
            ])
        }
        return stats
Exemple #3
0
    def get_available_resource(self, nodename):
        if not hasattr(self, '_nodename'):
            self._nodename = nodename
        if nodename != self._nodename:
            LOG.error(_('Hostname has changed from %(old)s to %(new)s. '
                        'A restart is required to take effect.'
                        ), {'old': self._nodename,
                            'new': nodename})

        memory = hostinfo.get_memory_usage()
        disk = hostinfo.get_disk_usage()
        stats = {
            'vcpus': hostinfo.get_total_vcpus(),
            'vcpus_used': hostinfo.get_vcpus_used(self.list_instances(True)),
            'memory_mb': memory['total'] / units.Mi,
            'memory_mb_used': memory['used'] / units.Mi,
            'local_gb': disk['total'] / units.Gi,
            'local_gb_used': disk['used'] / units.Gi,
            'disk_available_least': disk['available'] / units.Gi,
            'hypervisor_type': 'docker',
            'hypervisor_version': versionutils.convert_version_to_int('1.0'),
            'hypervisor_hostname': self._nodename,
            'cpu_info': '?',
            'numa_topology': None,
            'supported_instances': [
                (arch.I686, hv_type.DOCKER, vm_mode.EXE),
                (arch.X86_64, hv_type.DOCKER, vm_mode.EXE)
            ]
        }
        return stats
Exemple #4
0
    def get_available_resource(self, nodename):
        if not hasattr(self, '_nodename'):
            self._nodename = nodename
        if nodename != self._nodename:
            LOG.error(_('Hostname has changed from %(old)s to %(new)s. '
                        'A restart is required to take effect.'
                        ) % {'old': self._nodename,
                             'new': nodename})

        memory = hostinfo.get_memory_usage()
        disk = hostinfo.get_disk_usage()
        stats = {
            'vcpus': 1,
            'vcpus_used': 0,
            'memory_mb': memory['total'] / units.Mi,
            'memory_mb_used': memory['used'] / units.Mi,
            'local_gb': disk['total'] / units.Gi,
            'local_gb_used': disk['used'] / units.Gi,
            'disk_available_least': disk['available'] / units.Gi,
            'hypervisor_type': 'docker',
            'hypervisor_version': utils.convert_version_to_int('1.0'),
            'hypervisor_hostname': self._nodename,
            'cpu_info': '?',
            'supported_instances': jsonutils.dumps([
                ('i686', 'docker', 'lxc'),
                ('x86_64', 'docker', 'lxc')
            ])
        }
        return stats
Exemple #5
0
 def get_host_stats(self, refresh=False):
     hostname = socket.gethostname()
     memory = hostinfo.get_memory_usage()
     disk = hostinfo.get_disk_usage()
     stats = self.get_available_resource(hostname)
     stats['hypervisor_hostname'] = stats['hypervisor_hostname']
     stats['host_hostname'] = stats['hypervisor_hostname']
     stats['host_name_label'] = stats['hypervisor_hostname']
     return stats
Exemple #6
0
 def get_host_stats(self, refresh=False):
     hostname = socket.gethostname()
     memory = hostinfo.get_memory_usage()
     disk = hostinfo.get_disk_usage()
     stats = self.get_available_resource(hostname)
     stats['hypervisor_hostname'] = stats['hypervisor_hostname']
     stats['host_hostname'] = stats['hypervisor_hostname']
     stats['host_name_label'] = stats['hypervisor_hostname']
     return stats
    def test_get_memory_usage(self):
        fake_total_memory = 4096
        fake_used_memory = 2048

        with mock.patch.object(psutil,
                               'virtual_memory') as mock_virtual_memory:
            mock_virtual_memory.return_value.total = fake_total_memory
            mock_virtual_memory.return_value.used = fake_used_memory

            usage = hostinfo.get_memory_usage()

            self.assertEqual(fake_total_memory, usage['total'])
            self.assertEqual(fake_used_memory, usage['used'])
Exemple #8
0
    def get_available_resource(self, nodename):
        if not hasattr(self, '_nodename'):
            self._nodename = nodename
        if nodename != self._nodename:
            LOG.error(
                _('Hostname has changed from %(old)s to %(new)s. '
                  'A restart is required to take effect.'), {
                      'old': self._nodename,
                      'new': nodename
                  })

        memory = hostinfo.get_memory_usage()
        disk = hostinfo.get_disk_usage()
        stats = {
            'vcpus':
            hostinfo.get_total_vcpus(),
            'vcpus_used':
            hostinfo.get_vcpus_used(self.list_instances(True)),
            'memory_mb':
            memory['total'] / units.Mi,
            'memory_mb_used':
            memory['used'] / units.Mi,
            'local_gb':
            disk['total'] / units.Gi,
            'local_gb_used':
            disk['used'] / units.Gi,
            'disk_available_least':
            disk['available'] / units.Gi,
            'hypervisor_type':
            'docker',
            'hypervisor_version':
            versionutils.convert_version_to_int('1.0'),
            'hypervisor_hostname':
            self._nodename,
            'cpu_info':
            '?',
            'numa_topology':
            None,
            # zy: pay attention that if you do not define supported_instance,you won't start an container from this node
            # zy: add new architectures
            'supported_instances':
            [(arch.I686, hv_type.DOCKER, vm_mode.EXE),
             (arch.X86_64, hv_type.DOCKER, vm_mode.EXE),
             (arch.ARMV7, hv_type.DOCKER, vm_mode.EXE),
             (arch.AARCH64, hv_type.DOCKER, vm_mode.EXE),
             (arch.PPC64LE, hv_type.DOCKER, vm_mode.EXE)]
        }
        return stats
    def test_get_memory_usage(self):
        meminfo_str = """MemTotal:        1018784 kB
MemFree:         220060 kB
Buffers:           21640 kB
Cached:           63364 kB
SwapCached:            0 kB
Active:           13988 kB
Inactive:         50616 kB
"""
        with mock.patch('__builtin__.open',
                        mock.mock_open(read_data=meminfo_str),
                        create=True) as m:

            usage = hostinfo.get_memory_usage()
            m.assert_called_once_with('/proc/meminfo')
            self.assertEqual(usage['total'], 1043234816)
            self.assertEqual(usage['used'], 730849280)
    def test_get_memory_usage(self):
        meminfo_str = """MemTotal:        1018784 kB
MemFree:         220060 kB
Buffers:           21640 kB
Cached:           63364 kB
SwapCached:            0 kB
Active:           13988 kB
Inactive:         50616 kB
"""
        with mock.patch('__builtin__.open',
                        mock.mock_open(read_data=meminfo_str),
                        create=True) as m:

            usage = hostinfo.get_memory_usage()
            m.assert_called_once_with('/proc/meminfo')
            self.assertEqual(usage['total'], 1043234816)
            self.assertEqual(usage['used'], 730849280)
 def test_get_memory_usage(self):
     usage = hostinfo.get_memory_usage()
     self.assertEqual(usage['total'], 1043234816)
     self.assertEqual(usage['used'], 730849280)
     self.assertEqual(usage['free'], 312385536)