def _create_compute_service(self, **kwargs):
        """Create a compute service."""

        dic = {"binary": "nova-compute", "topic": "compute", "report_count": 0, "availability_zone": "dummyzone"}
        dic["host"] = kwargs.get("host", "dummy")
        s_ref = db.service_create(self.context, dic)
        if "created_at" in kwargs.keys() or "updated_at" in kwargs.keys():
            t = utils.utcnow() - datetime.timedelta(0)
            dic["created_at"] = kwargs.get("created_at", t)
            dic["updated_at"] = kwargs.get("updated_at", t)
            db.service_update(self.context, s_ref["id"], dic)

        dic = {
            "service_id": s_ref["id"],
            "vcpus": 16,
            "memory_mb": 32,
            "local_gb": 100,
            "vcpus_used": 16,
            "local_gb_used": 10,
            "hypervisor_type": "qemu",
            "hypervisor_version": 12003,
            "cpu_info": "",
        }
        dic["memory_mb_used"] = kwargs.get("memory_mb_used", 32)
        dic["hypervisor_type"] = kwargs.get("hypervisor_type", "qemu")
        dic["hypervisor_version"] = kwargs.get("hypervisor_version", 12003)
        db.compute_node_create(self.context, dic)
        return db.service_get(self.context, s_ref["id"])
Beispiel #2
0
 def test_create(self, mock_get):
     self.mox.StubOutWithMock(db, 'compute_node_create')
     db.compute_node_create(
         self.context,
         {
             'service_id': 456,
             'stats': fake_stats_db_format,
             'host_ip': fake_host_ip,
             'supported_instances': fake_supported_hv_specs_db_format,
             'uuid': uuidsentinel.fake_compute_node,
         }).AndReturn(fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode(context=self.context)
     compute.service_id = 456
     compute.uuid = uuidsentinel.fake_compute_node
     compute.stats = fake_stats
     # NOTE (pmurray): host_ip is coerced to an IPAddress
     compute.host_ip = fake_host_ip
     compute.supported_hv_specs = fake_supported_hv_specs
     with mock.patch('oslo_utils.uuidutils.generate_uuid') as mock_gu:
         compute.create()
         self.assertFalse(mock_gu.called)
     self.compare_obj(compute, fake_compute_node,
                      subs=self.subs(),
                      comparators=self.comparators())
    def update_available_resource(self, ctxt, host):
        """Updates compute manager resource info on ComputeNode table.

        This method is called when nova-coompute launches, and
        whenever admin executes "nova-manage service update_resource".

        :param ctxt: security context
        :param host: hostname that compute manager is currently running

        """

        dic = self._max_phy_resouces(ctxt)
        #dic = self._sum_phy_hosts(ctxt)
        dic['hypervisor_type'] = 'physical'
        dic['hypervisor_version'] = 1
        dic['cpu_info'] = 'physical cpu'
        
        try:
            service_ref = db.service_get_all_compute_by_host(ctxt, host)[0]
        except exception.NotFound:
            raise exception.ComputeServiceUnavailable(host=host)

        dic['service_id'] = service_ref['id']

        compute_node_ref = service_ref['compute_node']
        if not compute_node_ref:
            LOG.info(_('Compute_service record created for %s ') % host)
            db.compute_node_create(ctxt, dic)
        else:
            LOG.info(_('Compute_service record updated for %s ') % host)
            db.compute_node_update(ctxt, compute_node_ref[0]['id'], dic)
Beispiel #4
0
    def _create_compute_service(self):
        """Create compute-manager(ComputeNode and Service record)."""
        ctxt = context.get_admin_context()
        dic = {
            "host": "dummy",
            "binary": "nova-compute",
            "topic": "compute",
            "report_count": 0,
            "availability_zone": "dummyzone",
        }
        s_ref = db.service_create(ctxt, dic)

        dic = {
            "service_id": s_ref["id"],
            "vcpus": 16,
            "memory_mb": 32,
            "local_gb": 100,
            "vcpus_used": 16,
            "memory_mb_used": 32,
            "local_gb_used": 10,
            "hypervisor_type": "qemu",
            "hypervisor_version": 12003,
            "cpu_info": "",
        }
        db.compute_node_create(ctxt, dic)

        return db.service_get(ctxt, s_ref["id"])
 def test_create(self, mock_get):
     self.mox.StubOutWithMock(db, 'compute_node_create')
     db.compute_node_create(
         self.context, {
             'service_id': 456,
             'stats': fake_stats_db_format,
             'host_ip': fake_host_ip,
             'supported_instances': fake_supported_hv_specs_db_format,
             'uuid': uuidsentinel.fake_compute_node,
         }).AndReturn(fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode(context=self.context)
     compute.service_id = 456
     compute.uuid = uuidsentinel.fake_compute_node
     compute.stats = fake_stats
     # NOTE (pmurray): host_ip is coerced to an IPAddress
     compute.host_ip = fake_host_ip
     compute.supported_hv_specs = fake_supported_hv_specs
     with mock.patch('oslo_utils.uuidutils.generate_uuid') as mock_gu:
         compute.create()
         self.assertFalse(mock_gu.called)
     self.compare_obj(compute,
                      fake_compute_node,
                      subs=self.subs(),
                      comparators=self.comparators())
Beispiel #6
0
    def update_available_resource(self, ctxt, host):
        """Updates compute manager resource info on ComputeNode table.

        This method is called when nova-coompute launches, and
        whenever admin executes "nova-manage service update_resource".

        :param ctxt: security context
        :param host: hostname that compute manager is currently running

        """

        dic = self._max_baremetal_resources(ctxt)
        #dic = self._sum_baremetal_resources(ctxt)
        dic['hypervisor_type'] = self.get_hypervisor_type()
        dic['hypervisor_version'] = self.get_hypervisor_version()
        dic['cpu_info'] = 'baremetal cpu'

        try:
            service_ref = db.service_get_all_compute_by_host(ctxt, host)[0]
        except exception.NotFound:
            raise exception.ComputeServiceUnavailable(host=host)

        dic['service_id'] = service_ref['id']

        compute_node_ref = service_ref['compute_node']
        if not compute_node_ref:
            LOG.info(_('Compute_service record created for %s ') % host)
            db.compute_node_create(ctxt, dic)
        else:
            LOG.info(_('Compute_service record updated for %s ') % host)
            db.compute_node_update(ctxt, compute_node_ref[0]['id'], dic)
Beispiel #7
0
    def update_available_resource(self, ctxt, host):
        """Updates compute manager resource info on ComputeNode table.

           Since we don't have a real hypervisor, pretend we have lots of
           disk and ram.
        """

        try:
            service_ref = db.service_get_all_compute_by_host(ctxt, host)[0]
        except exception.NotFound:
            raise exception.ComputeServiceUnavailable(host=host)

        # Updating host information
        dic = {'vcpus': 1,
               'memory_mb': 4096,
               'local_gb': 1028,
               'vcpus_used': 0,
               'memory_mb_used': 0,
               'local_gb_used': 0,
               'hypervisor_type': 'fake',
               'hypervisor_version': '1.0',
                  'service_id': service_ref['id'],
                 'cpu_info': '?'}

        compute_node_ref = service_ref['compute_node']
        if not compute_node_ref:
            LOG.info(_('Compute_service record created for %s ') % host)
            db.compute_node_create(ctxt, dic)
        else:
            LOG.info(_('Compute_service record updated for %s ') % host)
            db.compute_node_update(ctxt, compute_node_ref[0]['id'], dic)
Beispiel #8
0
    def update_available_resource(self, ctxt, host):
        """Updates compute manager resource info on ComputeNode table.

           Since we don't have a real hypervisor, pretend we have lots of
           disk and ram.
        """

        try:
            service_ref = db.service_get_all_compute_by_host(ctxt, host)[0]
        except exception.NotFound:
            raise exception.ComputeServiceUnavailable(host=host)

        # Updating host information
        dic = {
            "vcpus": 1,
            "memory_mb": 4096,
            "local_gb": 1028,
            "vcpus_used": 0,
            "memory_mb_used": 0,
            "local_gb_used": 0,
            "hypervisor_type": "fake",
            "hypervisor_version": "1.0",
            "service_id": service_ref["id"],
            "cpu_info": "?",
        }

        compute_node_ref = service_ref["compute_node"]
        if not compute_node_ref:
            LOG.info(_("Compute_service record created for %s ") % host)
            db.compute_node_create(ctxt, dic)
        else:
            LOG.info(_("Compute_service record updated for %s ") % host)
            db.compute_node_update(ctxt, compute_node_ref[0]["id"], dic)
Beispiel #9
0
    def _create_compute_service(self):
        """Create compute-manager(ComputeNode and Service record)."""
        ctxt = self.req.environ["nova.context"]
        dic = {
            'host': 'dummy',
            'binary': 'nova-compute',
            'topic': 'compute',
            'report_count': 0
        }
        s_ref = db.service_create(ctxt, dic)

        dic = {
            'service_id': s_ref['id'],
            'vcpus': 16,
            'memory_mb': 32,
            'local_gb': 100,
            'vcpus_used': 16,
            'memory_mb_used': 32,
            'local_gb_used': 10,
            'hypervisor_type': 'qemu',
            'hypervisor_version': 12003,
            'cpu_info': '',
            'stats': {}
        }
        db.compute_node_create(ctxt, dic)

        return db.service_get(ctxt, s_ref['id'])
Beispiel #10
0
    def _create_compute_service(self, **kwargs):
        """Create a compute service."""

        dic = {
            'binary': 'nova-compute',
            'topic': 'compute',
            'report_count': 0,
            'availability_zone': 'dummyzone'
        }
        dic['host'] = kwargs.get('host', 'dummy')
        s_ref = db.service_create(self.context, dic)
        if 'created_at' in kwargs.keys() or 'updated_at' in kwargs.keys():
            t = utils.utcnow() - datetime.timedelta(0)
            dic['created_at'] = kwargs.get('created_at', t)
            dic['updated_at'] = kwargs.get('updated_at', t)
            db.service_update(self.context, s_ref['id'], dic)

        dic = {
            'service_id': s_ref['id'],
            'vcpus': 16,
            'memory_mb': 32,
            'local_gb': 100,
            'vcpus_used': 16,
            'local_gb_used': 10,
            'hypervisor_type': 'qemu',
            'hypervisor_version': 12003,
            'cpu_info': ''
        }
        dic['memory_mb_used'] = kwargs.get('memory_mb_used', 32)
        dic['hypervisor_type'] = kwargs.get('hypervisor_type', 'qemu')
        dic['hypervisor_version'] = kwargs.get('hypervisor_version', 12003)
        db.compute_node_create(self.context, dic)
        return db.service_get(self.context, s_ref['id'])
Beispiel #11
0
    def _create_compute_service(self):
        """Create compute-manager(ComputeNode and Service record)."""
        ctxt = context.get_admin_context()
        dic = {
            'host': 'dummy',
            'binary': 'nova-compute',
            'topic': 'compute',
            'report_count': 0,
            'availability_zone': 'dummyzone'
        }
        s_ref = db.service_create(ctxt, dic)

        dic = {
            'service_id': s_ref['id'],
            'vcpus': 16,
            'memory_mb': 32,
            'local_gb': 100,
            'vcpus_used': 16,
            'memory_mb_used': 32,
            'local_gb_used': 10,
            'hypervisor_type': 'qemu',
            'hypervisor_version': 12003,
            'cpu_info': ''
        }
        db.compute_node_create(ctxt, dic)

        return db.service_get(ctxt, s_ref['id'])
Beispiel #12
0
    def update_available_resource(self, ctxt, host):
        """Updates compute manager resource info on ComputeNode table.

           Since we don't have a real hypervisor, pretend we have lots of
           disk and ram.
        """

        try:
            service_ref = db.service_get_all_compute_by_host(ctxt, host)[0]
        except exception.NotFound:
            raise exception.ComputeServiceUnavailable(host=host)

        # Updating host information
        dic = {
            'vcpus': 1,
            'memory_mb': 4096,
            'local_gb': 1028,
            'vcpus_used': 0,
            'memory_mb_used': 0,
            'local_gb_used': 0,
            'hypervisor_type': 'fake',
            'hypervisor_version': '1.0',
            'service_id': service_ref['id'],
            'cpu_info': '?'
        }

        compute_node_ref = service_ref['compute_node']
        if not compute_node_ref:
            LOG.info(_('Compute_service record created for %s ') % host)
            db.compute_node_create(ctxt, dic)
        else:
            LOG.info(_('Compute_service record updated for %s ') % host)
            db.compute_node_update(ctxt, compute_node_ref[0]['id'], dic)
Beispiel #13
0
 def test_compute_node_create(self):
     self.mox.StubOutWithMock(db, 'compute_node_create')
     db.compute_node_create(self.context, 'fake-values').AndReturn(
         'fake-result')
     self.mox.ReplayAll()
     result = self.conductor.compute_node_create(self.context,
                                                 'fake-values')
     self.assertEqual(result, 'fake-result')
Beispiel #14
0
 def test_compute_node_create(self):
     self.mox.StubOutWithMock(db, 'compute_node_create')
     db.compute_node_create(self.context,
                            'fake-values').AndReturn('fake-result')
     self.mox.ReplayAll()
     result = self.conductor.compute_node_create(self.context,
                                                 'fake-values')
     self.assertEqual(result, 'fake-result')
Beispiel #15
0
 def test_recreate_fails(self):
     self.mox.StubOutWithMock(db, "compute_node_create")
     db.compute_node_create(self.context, {"service_id": 456}).AndReturn(fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode(context=self.context)
     compute.service_id = 456
     compute.create()
     self.assertRaises(exception.ObjectActionError, compute.create, self.context)
Beispiel #16
0
 def test_recreate_fails(self):
     self.mox.StubOutWithMock(db, 'compute_node_create')
     db.compute_node_create(self.context, {'service_id': 456}).AndReturn(
         fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode(context=self.context)
     compute.service_id = 456
     compute.create()
     self.assertRaises(exception.ObjectActionError, compute.create)
Beispiel #17
0
 def test_create(self):
     self.mox.StubOutWithMock(db, 'compute_node_create')
     db.compute_node_create(self.context, {'service_id': 456}).AndReturn(
         fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode()
     compute.service_id = 456
     compute.create(self.context)
     self.compare_obj(compute, fake_compute_node)
Beispiel #18
0
 def test_create(self):
     self.mox.StubOutWithMock(db, 'compute_node_create')
     db.compute_node_create(self.context, {'service_id': 456}).AndReturn(
         fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode()
     compute.service_id = 456
     compute.create(self.context)
     self._compare(compute, fake_compute_node)
Beispiel #19
0
 def test_recreate_fails(self, mock_get):
     self.mox.StubOutWithMock(db, 'compute_node_create')
     db.compute_node_create(
         self.context, {'service_id': 456,
                        'uuid': uuidsentinel.fake_compute_node}).AndReturn(
         fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode(context=self.context)
     compute.service_id = 456
     compute.uuid = uuidsentinel.fake_compute_node
     compute.create()
     self.assertRaises(exception.ObjectActionError, compute.create)
Beispiel #20
0
 def test_query_allocates_uuid(self):
     fake = dict(fake_compute_node)
     fake.pop('uuid')
     db.compute_node_create(self.context, fake)
     with mock.patch('oslo_utils.uuidutils.generate_uuid') as mock_gu:
         mock_gu.return_value = uuidsentinel.fake_compute_node
         obj = objects.ComputeNode.get_by_id(self.context, fake['id'])
         mock_gu.assert_called_once_with()
         self.assertEqual(uuidsentinel.fake_compute_node, obj.uuid)
         self.assertNotIn('uuid', obj.obj_get_changes())
     with mock.patch('oslo_utils.uuidutils.generate_uuid') as mock_gu:
         obj = objects.ComputeNode.get_by_id(self.context, fake['id'])
         self.assertEqual(uuidsentinel.fake_compute_node, obj.uuid)
         self.assertFalse(mock_gu.called)
 def test_query_allocates_uuid(self):
     fake = dict(fake_compute_node)
     fake.pop('uuid')
     db.compute_node_create(self.context, fake)
     with mock.patch('oslo_utils.uuidutils.generate_uuid') as mock_gu:
         mock_gu.return_value = uuidsentinel.fake_compute_node
         obj = objects.ComputeNode.get_by_id(self.context, fake['id'])
         mock_gu.assert_called_once_with()
         self.assertEqual(uuidsentinel.fake_compute_node, obj.uuid)
         self.assertNotIn('uuid', obj.obj_get_changes())
     with mock.patch('oslo_utils.uuidutils.generate_uuid') as mock_gu:
         obj = objects.ComputeNode.get_by_id(self.context, fake['id'])
         self.assertEqual(uuidsentinel.fake_compute_node, obj.uuid)
         self.assertFalse(mock_gu.called)
Beispiel #22
0
 def test_create(self):
     self.mox.StubOutWithMock(db, 'compute_node_create')
     db.compute_node_create(self.context, {
         'service_id': 456,
         'stats': fake_stats_db_format
     }).AndReturn(fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode()
     compute.service_id = 456
     compute.stats = fake_stats
     compute.create(self.context)
     self.compare_obj(compute,
                      fake_compute_node,
                      comparators={'stats': self.json_comparator})
Beispiel #23
0
 def test_create(self):
     self.mox.StubOutWithMock(db, 'compute_node_create')
     db.compute_node_create(
         self.context,
         {
             'service_id': 456,
             'stats': fake_stats_db_format
         }).AndReturn(fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode()
     compute.service_id = 456
     compute.stats = fake_stats
     compute.create(self.context)
     self.compare_obj(compute, fake_compute_node,
                      comparators={'stats': self.json_comparator})
Beispiel #24
0
    def _create_compute_service(self):
        """Create compute-manager(ComputeNode and Service record)."""
        ctxt = context.get_admin_context()
        dic = {'host': 'dummy', 'binary': 'nova-compute', 'topic': 'compute',
               'report_count': 0, 'availability_zone': 'dummyzone'}
        s_ref = db.service_create(ctxt, dic)

        dic = {'service_id': s_ref['id'],
               'vcpus': 16, 'memory_mb': 32, 'local_gb': 100,
               'vcpus_used': 16, 'memory_mb_used': 32, 'local_gb_used': 10,
               'hypervisor_type': 'qemu', 'hypervisor_version': 12003,
               'cpu_info': '', 'stats': {}}
        db.compute_node_create(ctxt, dic)

        return db.service_get(ctxt, s_ref['id'])
Beispiel #25
0
    def create(self):
        if self.obj_attr_is_set('id'):
            raise exception.ObjectActionError(action='create',
                                              reason='already created')
        updates = self.obj_get_changes()
        if 'uuid' not in updates:
            updates['uuid'] = uuidutils.generate_uuid()
            self.uuid = updates['uuid']

        self._convert_stats_to_db_format(updates)
        self._convert_host_ip_to_db_format(updates)
        self._convert_supported_instances_to_db_format(updates)
        self._convert_pci_stats_to_db_format(updates)

        if self._should_manage_inventory():
            self._create_inventory(updates)

        db_compute = db.compute_node_create(self._context, updates)
        # NOTE(danms): compute_node_create() operates on (and returns) the
        # compute node model only. We need to get the full inventory-based
        # result in order to satisfy _from_db_object(). So, we do a double
        # query here. This can be removed in Newton once we're sure that all
        # compute nodes are inventory-based
        db_compute = db.compute_node_get(self._context, db_compute['id'])
        self._from_db_object(self._context, self, db_compute)
Beispiel #26
0
 def setUp(self):
     map(lambda x: x.delete(), Query(models.Service).all())
     map(lambda x: x.delete(), Query(models.ComputeNode).all())
     super(ComputeNodeTestCase, self).setUp()
     self.ctxt = context.get_admin_context()
     self.service_dict = dict(host='host1', binary='nova-compute',
                         topic=CONF.compute_topic, report_count=1,
                         disabled=False)
     self.service = db.service_create(self.ctxt, self.service_dict)
     self.compute_node_dict = dict(vcpus=2, memory_mb=1024, local_gb=2048,
                              vcpus_used=0, memory_mb_used=0,
                              local_gb_used=0, free_ram_mb=1024,
                              free_disk_gb=2048, hypervisor_type="xen",
                              hypervisor_version=1, cpu_info="",
                              running_vms=0, current_workload=0,
                              service_id=self.service['id'],
                              disk_available_least=100,
                              hypervisor_hostname='abracadabra104',
                              host_ip='127.0.0.1',
                              supported_instances='',
                              pci_stats='',
                              metrics='',
                              extra_resources='',
                              stats='', numa_topology='')
     # add some random stats
     self.stats = dict(num_instances=3, num_proj_12345=2,
                  num_proj_23456=2, num_vm_building=3)
     self.compute_node_dict['stats'] = jsonutils.dumps(self.stats)
     # self.flags(reserved_host_memory_mb=0)
     # self.flags(reserved_host_disk_mb=0)
     self.item = db.compute_node_create(self.ctxt, self.compute_node_dict)
Beispiel #27
0
    def create(self):
        if self.obj_attr_is_set('id'):
            raise exception.ObjectActionError(action='create',
                                              reason='already created')
        updates = self.obj_get_changes()
        if 'uuid' not in updates:
            updates['uuid'] = uuidutils.generate_uuid()
            self.uuid = updates['uuid']

        self._convert_stats_to_db_format(updates)
        self._convert_host_ip_to_db_format(updates)
        self._convert_supported_instances_to_db_format(updates)
        self._convert_pci_stats_to_db_format(updates)

        if self._should_manage_inventory():
            self._create_inventory(updates)

        db_compute = db.compute_node_create(self._context, updates)
        # NOTE(danms): compute_node_create() operates on (and returns) the
        # compute node model only. We need to get the full inventory-based
        # result in order to satisfy _from_db_object(). So, we do a double
        # query here. This can be removed in Newton once we're sure that all
        # compute nodes are inventory-based
        db_compute = db.compute_node_get(self._context, db_compute['id'])
        self._from_db_object(self._context, self, db_compute)
Beispiel #28
0
    def _create_compute_service(self):
        """Create compute-manager(ComputeNode and Service record)."""
        ctxt = self.req.environ["nova.context"]
        dic = {'host': 'dummy', 'binary': 'nova-compute', 'topic': 'compute',
               'report_count': 0}
        s_ref = db.service_create(ctxt, dic)

        dic = {'service_id': s_ref['id'],
               'host': s_ref['host'],
               'uuid': uuidsentinel.compute_node,
               'vcpus': 16, 'memory_mb': 32, 'local_gb': 100,
               'vcpus_used': 16, 'memory_mb_used': 32, 'local_gb_used': 10,
               'hypervisor_type': 'qemu', 'hypervisor_version': 12003,
               'cpu_info': '', 'stats': ''}
        db.compute_node_create(ctxt, dic)

        return db.service_get(ctxt, s_ref['id'])
Beispiel #29
0
 def create(self, context):
     if self.obj_attr_is_set('id'):
         raise exception.ObjectActionError(action='create',
                                           reason='already created')
     updates = self.obj_get_changes()
     updates.pop('id', None)
     db_compute = db.compute_node_create(context, updates)
     self._from_db_object(context, self, db_compute)
Beispiel #30
0
 def create(self, context):
     if self.obj_attr_is_set('id'):
         raise exception.ObjectActionError(action='create',
                                           reason='already created')
     updates = self.obj_get_changes()
     updates.pop('id', None)
     db_compute = db.compute_node_create(context, updates)
     self._from_db_object(context, self, db_compute)
Beispiel #31
0
    def update_available_resource(self, ctxt, host):
        """Updates compute manager resource info on ComputeNode table.

        This method is called when nova-coompute launches, and
        whenever admin executes "nova-manage service update_resource".

        :param ctxt: security context
        :param host: hostname that compute manager is currently running

        """

        try:
            service_ref = db.service_get_all_compute_by_host(ctxt, host)[0]
        except exception.NotFound:
            raise exception.ComputeServiceUnavailable(host=host)

        # Updating host information
        dic = {
            "vcpus": self.get_vcpu_total(),
            "memory_mb": self.get_memory_mb_total(),
            "local_gb": self.get_local_gb_total(),
            "vcpus_used": self.get_vcpu_used(),
            "memory_mb_used": self.get_memory_mb_used(),
            "local_gb_used": self.get_local_gb_used(),
            "hypervisor_type": self.get_hypervisor_type(),
            "hypervisor_version": self.get_hypervisor_version(),
            "cpu_info": self.get_cpu_info(),
            "cpu_arch": FLAGS.cpu_arch,
            "xpu_arch": FLAGS.xpu_arch,
            "xpus": FLAGS.xpus,
            "xpu_info": FLAGS.xpu_info,
            "net_arch": FLAGS.net_arch,
            "net_info": FLAGS.net_info,
            "net_mbps": FLAGS.net_mbps,
            "service_id": service_ref["id"],
        }

        compute_node_ref = service_ref["compute_node"]
        LOG.info(_("#### RLK: cpu_arch = %s ") % FLAGS.cpu_arch)
        if not compute_node_ref:
            LOG.info(_("Compute_service record created for %s ") % host)
            dic["service_id"] = service_ref["id"]
            db.compute_node_create(ctxt, dic)
        else:
            LOG.info(_("Compute_service record updated for %s ") % host)
            db.compute_node_update(ctxt, compute_node_ref[0]["id"], dic)
Beispiel #32
0
    def update_available_resource(self, ctxt, host):
        """Updates compute manager resource info on ComputeNode table.

        This method is called when nova-coompute launches, and
        whenever admin executes "nova-manage service update_resource".

        :param ctxt: security context
        :param host: hostname that compute manager is currently running

        """

        try:
            service_ref = db.service_get_all_compute_by_host(ctxt, host)[0]
        except exception.NotFound:
            raise exception.ComputeServiceUnavailable(host=host)

        # Updating host information
        dic = {
            'vcpus': self.get_vcpu_total(),
            'memory_mb': self.get_memory_mb_total(),
            'local_gb': self.get_local_gb_total(),
            'vcpus_used': self.get_vcpu_used(),
            'memory_mb_used': self.get_memory_mb_used(),
            'local_gb_used': self.get_local_gb_used(),
            'hypervisor_type': self.get_hypervisor_type(),
            'hypervisor_version': self.get_hypervisor_version(),
            'cpu_info': self.get_cpu_info(),
            'cpu_arch': FLAGS.cpu_arch,
            'xpu_arch': FLAGS.xpu_arch,
            'xpus': FLAGS.xpus,
            'xpu_info': FLAGS.xpu_info,
            'net_arch': FLAGS.net_arch,
            'net_info': FLAGS.net_info,
            'net_mbps': FLAGS.net_mbps,
            'service_id': service_ref['id']
        }

        compute_node_ref = service_ref['compute_node']
        LOG.info(_('#### RLK: cpu_arch = %s ') % FLAGS.cpu_arch)
        if not compute_node_ref:
            LOG.info(_('Compute_service record created for %s ') % host)
            dic['service_id'] = service_ref['id']
            db.compute_node_create(ctxt, dic)
        else:
            LOG.info(_('Compute_service record updated for %s ') % host)
            db.compute_node_update(ctxt, compute_node_ref[0]['id'], dic)
Beispiel #33
0
def generate_data():
    def _generate_stats(id_num):
        stats = {}
        i = 0
        while i < CONF.num_stat:
            key = 'key%d' % i
            stats[key] = id_num + i
            i = i + 1
        return stats

    print "Starting prepare data in DB"
    ctx = context.get_admin_context()
    for i in range(CONF.num_comp):
        if  i *100.0 % CONF.num_comp == 0:
            sys.stdout.write("prepared %d%% data\r" % (i * 100.0 / CONF.num_comp))
            sys.stdout.flush()
        svc_values = {
            'host': 'host-%d' % i,
            'binary': 'novadbtest',
            'topic': 'novadbtest',
            'report_count': 0,
        }
        #created service record
        service_ref = jsonutils.to_primitive(
                           db.service_get_by_host_and_topic(ctx, 
                                                            svc_values['host'],
                                                            svc_values['topic']))
        if not service_ref:
            service_ref = jsonutils.to_primitive(
                               db.service_create(ctx, svc_values))
        LOG.info('Service record created for id %d', service_ref['id'])
        #create/update compute node record
        comp_values = {
            'service_id': service_ref['id'],
            'vcpus': i,
            'memory_mb': i,
            'local_gb': i,
            'vcpus_used': i,
            'memory_mb_used': i,
            'local_gb_used': i,
            'hypervisor_type': 'qemu',
            'hypervisor_version': 1,
            'hypervisor_hostname': 'test',
            'free_ram_mb': i,
            'free_disk_gb': i,
            'current_workload': i,
            'running_vms': i,
            'disk_available_least': i,
            }
        comp_values['cpu_info'] = jsonutils.dumps(_generate_stats(i))
        if hasattr(ComputeNode, 'metrics'):
            comp_values['metrics'] = jsonutils.dumps(_generate_stats(i))
        if CONF.join_stats:
            comp_values['stats'] = _generate_stats(i)
        compute_ref = jsonutils.to_primitive(
                        db.compute_node_create(ctx, comp_values))
        LOG.info('Compute node record created for id %d', compute_ref['id'])
    print "Finish preparing data in DB"
Beispiel #34
0
    def update_available_resource(self, ctxt, host):
        """Updates compute manager resource info on ComputeNode table.

        This method is called when nova-coompute launches, and
        whenever admin executes "nova-manage service update_resource".

        :param ctxt: security context
        :param host: hostname that compute manager is currently running

        """

        try:
            service_ref = db.service_get_all_compute_by_host(ctxt, host)[0]
        except exception.NotFound:
            raise exception.ComputeServiceUnavailable(host=host)

        # Updating host information
        dic = {'vcpus': self.get_vcpu_total(),
               'memory_mb': self.get_memory_mb_total(),
               'local_gb': self.get_local_gb_total(),
               'vcpus_used': self.get_vcpu_used(),
               'memory_mb_used': self.get_memory_mb_used(),
               'local_gb_used': self.get_local_gb_used(),
               'hypervisor_type': self.get_hypervisor_type(),
               'hypervisor_version': self.get_hypervisor_version(),
               'cpu_info': self.get_cpu_info(),
               'cpu_arch': FLAGS.cpu_arch,
               'xpu_arch': FLAGS.xpu_arch,
               'xpus': FLAGS.xpus,
               'xpu_info': FLAGS.xpu_info,
               'net_arch': FLAGS.net_arch,
               'net_info': FLAGS.net_info,
               'net_mbps': FLAGS.net_mbps,
               'service_id': service_ref['id']}

        compute_node_ref = service_ref['compute_node']
        LOG.info(_('#### RLK: cpu_arch = %s ') % FLAGS.cpu_arch)
        if not compute_node_ref:
            LOG.info(_('Compute_service record created for %s ') % host)
            dic['service_id'] = service_ref['id']
            db.compute_node_create(ctxt, dic)
        else:
            LOG.info(_('Compute_service record updated for %s ') % host)
            db.compute_node_update(ctxt, compute_node_ref[0]['id'], dic)
Beispiel #35
0
    def update_available_resource(self, ctxt, host):
        """Updates compute manager resource info on ComputeNode table.

        This method is called when nova-compute launches, and
        whenever admin executes "nova-manage service update_resource".

        :param ctxt: security context
        :param host: hostname that compute manager is currently running

        """

        try:
            service_ref = db.service_get_all_compute_by_host(ctxt, host)[0]
        except exception.NotFound:
            raise exception.ComputeServiceUnavailable(host=host)

        host_stats = self.get_host_stats(refresh=True)

        # Updating host information
        total_ram_mb = host_stats['host_memory_total'] / (1024 * 1024)
        free_ram_mb = host_stats['host_memory_free'] / (1024 * 1024)
        total_disk_gb = host_stats['disk_total'] / (1024 * 1024 * 1024)
        used_disk_gb = host_stats['disk_used'] / (1024 * 1024 * 1024)

        dic = {
            'vcpus': 0,
            'memory_mb': total_ram_mb,
            'local_gb': total_disk_gb,
            'vcpus_used': 0,
            'memory_mb_used': total_ram_mb - free_ram_mb,
            'local_gb_used': used_disk_gb,
            'hypervisor_type': 'xen',
            'hypervisor_version': 0,
            'cpu_info': host_stats['host_cpu_info']['cpu_count']
        }

        compute_node_ref = service_ref['compute_node']
        if not compute_node_ref:
            LOG.info(_('Compute_service record created for %s ') % host)
            dic['service_id'] = service_ref['id']
            db.compute_node_create(ctxt, dic)
        else:
            LOG.info(_('Compute_service record updated for %s ') % host)
            db.compute_node_update(ctxt, compute_node_ref[0]['id'], dic)
Beispiel #36
0
    def update_available_resource(self, ctxt, host):
        """Updates compute manager resource info on ComputeNode table.

        This method is called when nova-compute launches, and
        whenever admin executes "nova-manage service update_resource".

        :param ctxt: security context
        :param host: hostname that compute manager is currently running

        """
        try:
            service_ref = db.service_get_all_compute_by_host(ctxt, host)[0]
        except exception.NotFound:
            raise exception.ComputeServiceUnavailable(host=host)

        host_stats = self.get_host_stats(refresh=True)

        # Updating host information
        total_ram_mb = host_stats["host_memory_total"] / (1024 * 1024)
        free_ram_mb = host_stats["host_memory_free"] / (1024 * 1024)
        total_disk_gb = host_stats["disk_total"] / (1024 * 1024 * 1024)
        used_disk_gb = host_stats["disk_used"] / (1024 * 1024 * 1024)

        dic = {
            "vcpus": 0,
            "memory_mb": total_ram_mb,
            "local_gb": total_disk_gb,
            "vcpus_used": 0,
            "memory_mb_used": total_ram_mb - free_ram_mb,
            "local_gb_used": used_disk_gb,
            "hypervisor_type": "xen",
            "hypervisor_version": 0,
            "hypervisor_hostname": host_stats["host_hostname"],
            "service_id": service_ref["id"],
            "cpu_info": host_stats["host_cpu_info"]["cpu_count"],
        }

        compute_node_ref = service_ref["compute_node"]
        if not compute_node_ref:
            LOG.info(_("Compute_service record created for %s ") % host)
            db.compute_node_create(ctxt, dic)
        else:
            LOG.info(_("Compute_service record updated for %s ") % host)
            db.compute_node_update(ctxt, compute_node_ref[0]["id"], dic)
Beispiel #37
0
 def test_create(self):
     self.mox.StubOutWithMock(db, 'compute_node_create')
     db.compute_node_create(
         self.context,
         {
             'service_id': 456,
             'stats': fake_stats_db_format,
             'host_ip': fake_host_ip,
         }).AndReturn(fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode()
     compute.service_id = 456
     compute.stats = fake_stats
     # NOTE (pmurray): host_ip is coerced to an IPAddress
     compute.host_ip = fake_host_ip
     compute.create(self.context)
     self.compare_obj(compute, fake_compute_node,
                      comparators={'stats': self.json_comparator,
                                   'host_ip': self.str_comparator})
Beispiel #38
0
    def create(self, context):
        if self.obj_attr_is_set('id'):
            raise exception.ObjectActionError(action='create',
                                              reason='already created')
        updates = self.obj_get_changes()
        self._convert_stats_to_db_format(updates)
        self._convert_host_ip_to_db_format(updates)

        db_compute = db.compute_node_create(context, updates)
        self._from_db_object(context, self, db_compute)
Beispiel #39
0
 def test_create(self):
     self.mox.StubOutWithMock(db, 'compute_node_create')
     db.compute_node_create(
         self.context,
         {
             'service_id': 456,
             'stats': fake_stats_db_format,
             'host_ip': fake_host_ip,
         }).AndReturn(fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode()
     compute.service_id = 456
     compute.stats = fake_stats
     # NOTE (pmurray): host_ip is coerced to an IPAddress
     compute.host_ip = fake_host_ip
     compute.create(self.context)
     self.compare_obj(compute, fake_compute_node,
                      comparators={'stats': self.json_comparator,
                                   'host_ip': self.str_comparator})
Beispiel #40
0
    def create(self, context):
        if self.obj_attr_is_set('id'):
            raise exception.ObjectActionError(action='create',
                                              reason='already created')
        updates = self.obj_get_changes()
        self._convert_stats_to_db_format(updates)
        self._convert_host_ip_to_db_format(updates)

        db_compute = db.compute_node_create(context, updates)
        self._from_db_object(context, self, db_compute)
Beispiel #41
0
    def update_available_resource(self, ctxt, host):
        """Updates compute manager resource info on ComputeNode table.

        This method is called when nova-compute launches, and
        whenever admin executes "nova-manage service update_resource".

        :param ctxt: security context
        :param host: hostname that compute manager is currently running

        """
        try:
            service_ref = db.service_get_all_compute_by_host(ctxt, host)[0]
        except exception.NotFound:
            raise exception.ComputeServiceUnavailable(host=host)

        host_stats = self.get_host_stats(refresh=True)

        # Updating host information
        total_ram_mb = host_stats['host_memory_total'] / (1024 * 1024)
        free_ram_mb = host_stats['host_memory_free'] / (1024 * 1024)
        total_disk_gb = host_stats['disk_total'] / (1024 * 1024 * 1024)
        used_disk_gb = host_stats['disk_used'] / (1024 * 1024 * 1024)

        dic = {'vcpus': 0,
               'memory_mb': total_ram_mb,
               'local_gb': total_disk_gb,
               'vcpus_used': 0,
               'memory_mb_used': total_ram_mb - free_ram_mb,
               'local_gb_used': used_disk_gb,
               'hypervisor_type': 'xen',
               'hypervisor_version': 0,
               'hypervisor_hostname': host_stats['host_hostname'],
               'service_id': service_ref['id'],
               'cpu_info': host_stats['host_cpu_info']['cpu_count']}

        compute_node_ref = service_ref['compute_node']
        if not compute_node_ref:
            LOG.info(_('Compute_service record created for %s ') % host)
            db.compute_node_create(ctxt, dic)
        else:
            LOG.info(_('Compute_service record updated for %s ') % host)
            db.compute_node_update(ctxt, compute_node_ref[0]['id'], dic)
Beispiel #42
0
 def test_create(self):
     self.mox.StubOutWithMock(db, "compute_node_create")
     db.compute_node_create(
         self.context,
         {
             "service_id": 456,
             "stats": fake_stats_db_format,
             "host_ip": fake_host_ip,
             "supported_instances": fake_supported_hv_specs_db_format,
         },
     ).AndReturn(fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode(context=self.context)
     compute.service_id = 456
     compute.stats = fake_stats
     # NOTE (pmurray): host_ip is coerced to an IPAddress
     compute.host_ip = fake_host_ip
     compute.supported_hv_specs = fake_supported_hv_specs
     compute.create()
     self.compare_obj(compute, fake_compute_node, subs=self.subs(), comparators=self.comparators())
Beispiel #43
0
    def create(self):
        if self.obj_attr_is_set("id"):
            raise exception.ObjectActionError(action="create", reason="already created")
        updates = self.obj_get_changes()
        self._convert_stats_to_db_format(updates)
        self._convert_host_ip_to_db_format(updates)
        self._convert_supported_instances_to_db_format(updates)
        self._convert_pci_stats_to_db_format(updates)

        db_compute = db.compute_node_create(self._context, updates)
        self._from_db_object(self._context, self, db_compute)
Beispiel #44
0
 def test_create(self):
     self.mox.StubOutWithMock(db, 'compute_node_create')
     db.compute_node_create(
         self.context, {
             'service_id': 456,
             'stats': fake_stats_db_format,
             'host_ip': fake_host_ip,
             'supported_instances': fake_supported_hv_specs_db_format,
         }).AndReturn(fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode(context=self.context)
     compute.service_id = 456
     compute.stats = fake_stats
     # NOTE (pmurray): host_ip is coerced to an IPAddress
     compute.host_ip = fake_host_ip
     compute.supported_hv_specs = fake_supported_hv_specs
     compute.create()
     self.compare_obj(compute,
                      fake_compute_node,
                      subs=self.subs(),
                      comparators=self.comparators())
Beispiel #45
0
    def update_available_resource(self, context, host):
        """Updates compute manager resource info on ComputeNode table.

        This method is called as an periodic tasks and is used only
        in live migration currently.

        :param ctxt: security context
        :param host: hostname that compute manager is currently running

        """

        try:
            service_ref = db.service_get_all_compute_by_host(context, host)[0]
        except exception.NotFound:
            raise exception.ComputeServiceUnavailable(host=host)

        # Updating host information
        # TODO(alexpilotti) implemented cpu_info
        dic = {
            'vcpus': self._get_vcpu_total(),
            'memory_mb': self._get_memory_mb_total(),
            'local_gb': self._get_local_gb_total(),
            'vcpus_used': self._get_vcpu_used(),
            'memory_mb_used': self._get_memory_mb_used(),
            'local_gb_used': self._get_local_gb_used(),
            'hypervisor_type': "hyperv",
            'hypervisor_version': self._get_hypervisor_version(),
            'cpu_info': "unknown",
            'service_id': service_ref['id'],
            'disk_available_least': 1
        }

        compute_node_ref = service_ref['compute_node']
        if not compute_node_ref:
            LOG.info(_('Compute_service record created for %s ') % host)
            db.compute_node_create(context, dic)
        else:
            LOG.info(_('Compute_service record updated for %s ') % host)
            db.compute_node_update(context, compute_node_ref[0]['id'], dic)
Beispiel #46
0
    def _create_compute_service(self):
        """Create compute-manager(ComputeNode and Service record)."""
        ctxt = self.req.environ["nova.context"]
        dic = {"host": "dummy", "binary": "nova-compute", "topic": "compute", "report_count": 0}
        s_ref = db.service_create(ctxt, dic)

        dic = {
            "service_id": s_ref["id"],
            "vcpus": 16,
            "memory_mb": 32,
            "local_gb": 100,
            "vcpus_used": 16,
            "memory_mb_used": 32,
            "local_gb_used": 10,
            "hypervisor_type": "qemu",
            "hypervisor_version": 12003,
            "cpu_info": "",
            "stats": {},
        }
        db.compute_node_create(ctxt, dic)

        return db.service_get(ctxt, s_ref["id"])
Beispiel #47
0
    def _create_compute_service(self, **kwargs):
        """Create a compute service."""

        dic = {'binary': 'nova-compute', 'topic': 'compute',
               'report_count': 0, 'availability_zone': 'dummyzone'}
        dic['host'] = kwargs.get('host', 'dummy')
        s_ref = db.service_create(self.context, dic)
        if 'created_at' in kwargs.keys() or 'updated_at' in kwargs.keys():
            t = datetime.datetime.utcnow() - datetime.timedelta(0)
            dic['created_at'] = kwargs.get('created_at', t)
            dic['updated_at'] = kwargs.get('updated_at', t)
            db.service_update(self.context, s_ref['id'], dic)

        dic = {'service_id': s_ref['id'],
               'vcpus': 16, 'memory_mb': 32, 'local_gb': 100,
               'vcpus_used': 16, 'local_gb_used': 10,
               'hypervisor_type': 'qemu', 'hypervisor_version': 12003,
               'cpu_info': ''}
        dic['memory_mb_used'] = kwargs.get('memory_mb_used', 32)
        dic['hypervisor_type'] = kwargs.get('hypervisor_type', 'qemu')
        dic['hypervisor_version'] = kwargs.get('hypervisor_version', 12003)
        db.compute_node_create(self.context, dic)
        return db.service_get(self.context, s_ref['id'])
Beispiel #48
0
    def update_available_resource(self, context, host):
        """Updates compute manager resource info on ComputeNode table.

        This method is called as an periodic tasks and is used only
        in live migration currently.

        :param ctxt: security context
        :param host: hostname that compute manager is currently running

        """

        try:
            service_ref = db.service_get_all_compute_by_host(context, host)[0]
        except exception.NotFound:
            raise exception.ComputeServiceUnavailable(host=host)

        # Updating host information
        # TODO(alexpilotti) implemented cpu_info
        dic = {'vcpus': self._get_vcpu_total(),
               'memory_mb': self._get_memory_mb_total(),
               'local_gb': self._get_local_gb_total(),
               'vcpus_used': self._get_vcpu_used(),
               'memory_mb_used': self._get_memory_mb_used(),
               'local_gb_used': self._get_local_gb_used(),
               'hypervisor_type': "hyperv",
               'hypervisor_version': self._get_hypervisor_version(),
               'cpu_info': "unknown",
               'service_id': service_ref['id'],
               'disk_available_least': 1}

        compute_node_ref = service_ref['compute_node']
        if not compute_node_ref:
            LOG.info(_('Compute_service record created for %s ') % host)
            db.compute_node_create(context, dic)
        else:
            LOG.info(_('Compute_service record updated for %s ') % host)
            db.compute_node_update(context, compute_node_ref[0]['id'], dic)
Beispiel #49
0
    def create(self):
        if self.obj_attr_is_set('id'):
            raise exception.ObjectActionError(action='create',
                                              reason='already created')
        updates = self.obj_get_changes()
        if 'uuid' not in updates:
            updates['uuid'] = uuidutils.generate_uuid()

        self._convert_stats_to_db_format(updates)
        self._convert_host_ip_to_db_format(updates)
        self._convert_supported_instances_to_db_format(updates)
        self._convert_pci_stats_to_db_format(updates)

        db_compute = db.compute_node_create(self._context, updates)
        self._from_db_object(self._context, self, db_compute)
Beispiel #50
0
    def create(self):
        if self.obj_attr_is_set('id'):
            raise exception.ObjectActionError(action='create',
                                              reason='already created')
        updates = self.obj_get_changes()
        if 'uuid' not in updates:
            updates['uuid'] = uuidutils.generate_uuid()

        self._convert_stats_to_db_format(updates)
        self._convert_host_ip_to_db_format(updates)
        self._convert_supported_instances_to_db_format(updates)
        self._convert_pci_stats_to_db_format(updates)

        db_compute = db.compute_node_create(self._context, updates)
        self._from_db_object(self._context, self, db_compute)
Beispiel #51
0
 def test_compute_node_create(self):
     self.mox.StubOutWithMock(db, "compute_node_create")
     db.compute_node_create(self.context, "fake-values").AndReturn("fake-result")
     self.mox.ReplayAll()
     result = self.conductor.compute_node_create(self.context, "fake-values")
     self.assertEqual(result, "fake-result")
Beispiel #52
0
 def create(self, context):
     updates = {}
     for key in self.obj_what_changed():
         updates[key] = self[key]
     db_compute = db.compute_node_create(context, updates)
     self._from_db_object(context, self, db_compute)
Beispiel #53
0
 def _create_helper(self, host):
     self.compute_node_dict['host'] = host
     return db.compute_node_create(self.ctxt, self.compute_node_dict)
Beispiel #54
0
 def create(self, context):
     updates = self.obj_get_changes()
     db_compute = db.compute_node_create(context, updates)
     self._from_db_object(context, self, db_compute)
Beispiel #55
0
 def _create(self, context, values):
     """Create the compute node in the DB"""
     # initialize load stats from existing instances:
     compute_node = db.compute_node_create(context, values)
     self.compute_node = dict(compute_node)