Example #1
0
    def test_show_no_project(self):
        """No instances are running on the given host."""
        ctxt = context_maker.get_admin_context()
        s_ref = self._create_compute_service()

        result = self.controller.show(self.req, s_ref['host'])

        proj = ['(total)', '(used_now)', '(used_max)']
        column = ['host', 'project', 'cpu', 'memory_mb', 'disk_gb']
        self.assertEqual(len(result['host']), 3)
        for resource in result['host']:
            self.assertIn(resource['resource']['project'], proj)
            self.assertEqual(len(resource['resource']), 5)
            self.assertEqual(set(column), set(resource['resource'].keys()))
        db.service_destroy(ctxt, s_ref['id'])
Example #2
0
    def test_show_no_project(self):
        """No instances are running on the given host."""
        ctxt = context_maker.get_admin_context()
        s_ref = self._create_compute_service()

        result = self.controller.show(self.req, s_ref['host'])

        proj = ['(total)', '(used_now)', '(used_max)']
        column = ['host', 'project', 'cpu', 'memory_mb', 'disk_gb']
        self.assertEqual(len(result['host']), 3)
        for resource in result['host']:
            self.assertIn(resource['resource']['project'], proj)
            self.assertEqual(len(resource['resource']), 5)
            self.assertEqual(set(column), set(resource['resource'].keys()))
        db.service_destroy(ctxt, s_ref['id'])
Example #3
0
    def test_show_works_correctly(self):
        """show() works correctly as expected."""
        ctxt = context_maker.get_admin_context()
        s_ref = self._create_compute_service()
        i_ref1 = _create_instance(project_id='p-01', host=s_ref['host'])
        i_ref2 = _create_instance(project_id='p-02', vcpus=3,
                                       host=s_ref['host'])

        result = self.controller.show(self.req, s_ref['host'])

        proj = ['(total)', '(used_now)', '(used_max)', 'p-01', 'p-02']
        column = ['host', 'project', 'cpu', 'memory_mb', 'disk_gb']
        self.assertEqual(len(result['host']), 5)
        for resource in result['host']:
            self.assertIn(resource['resource']['project'], proj)
            self.assertEqual(len(resource['resource']), 5)
            self.assertEqual(set(column), set(resource['resource'].keys()))
        db.service_destroy(ctxt, s_ref['id'])
        db.instance_destroy(ctxt, i_ref1['uuid'])
        db.instance_destroy(ctxt, i_ref2['uuid'])
Example #4
0
    def test_show_works_correctly(self):
        """show() works correctly as expected."""
        ctxt = context_maker.get_admin_context()
        s_ref = self._create_compute_service()
        i_ref1 = _create_instance(project_id='p-01', host=s_ref['host'])
        i_ref2 = _create_instance(project_id='p-02',
                                  vcpus=3,
                                  host=s_ref['host'])

        result = self.controller.show(self.req, s_ref['host'])

        proj = ['(total)', '(used_now)', '(used_max)', 'p-01', 'p-02']
        column = ['host', 'project', 'cpu', 'memory_mb', 'disk_gb']
        self.assertEqual(len(result['host']), 5)
        for resource in result['host']:
            self.assertIn(resource['resource']['project'], proj)
            self.assertEqual(len(resource['resource']), 5)
            self.assertEqual(set(column), set(resource['resource'].keys()))
        db.service_destroy(ctxt, s_ref['id'])
        db.instance_destroy(ctxt, i_ref1['uuid'])
        db.instance_destroy(ctxt, i_ref2['uuid'])
Example #5
0
    def test_instance_list_old_deleted_service_with_no_uuid(self):
        # Create a nova-compute service record with a host that will match the
        # instance's host, with no uuid. We can't do this through the
        # Service object because it will automatically generate a uuid.
        # Use service version 9, which is too old compared to the minimum
        # version in the rest of the deployment.
        service = db.service_create(self.context, {
            'host': 'fake-host',
            'binary': 'nova-compute',
            'version': 9
        })
        self.assertIsNone(service['uuid'])

        # Now delete it.
        db.service_destroy(self.context, service['id'])

        # Create a new service with the same host name that has a UUID and a
        # current version.
        new_service = objects.Service(context=self.context,
                                      host='fake-host',
                                      binary='nova-compute')
        new_service.create()

        # Create an instance whose host will match both services, including the
        # deleted one.
        inst = objects.Instance(context=self.context,
                                project_id=self.context.project_id,
                                host='fake-host')
        inst.create()

        insts = objects.InstanceList.get_by_filters(
            self.context, {}, expected_attrs=['services'])
        self.assertEqual(1, len(insts))
        self.assertEqual(2, len(insts[0].services))
        # Deleted service should not have a UUID
        for service in insts[0].services:
            if service.deleted:
                self.assertNotIn('uuid', service)
            else:
                self.assertIsNotNone(service.uuid)
Example #6
0
 def destroy(self):
     db.service_destroy(self._context, self.id)
     self._send_notification(fields.NotificationAction.DELETE)
 def _destroy_service(self, service):
     return db.service_destroy(self.context, service['id'])
 def _destroy_service(self, service):
     return db.service_destroy(self.context, service['id'])