Ejemplo n.º 1
0
    def _create_instance_with_availability_zone(self, zone_name):
        def create(*args, **kwargs):
            self.assertIn('availability_zone', kwargs)
            self.assertEqual('nova', kwargs['availability_zone'])
            return old_create(*args, **kwargs)

        old_create = compute_api.API.create
        self.stubs.Set(compute_api.API, 'create', create)
        image_href = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
        flavor_ref = ('http://localhost' + self.base_url + 'flavors/3')
        body = {
            'server': {
                'name': 'server_test',
                'imageRef': image_href,
                'flavorRef': flavor_ref,
                'metadata': {
                    'hello': 'world',
                    'open': 'stack',
                },
                'availability_zone': zone_name,
            },
        }

        admin_context = context.get_admin_context()
        db.service_create(admin_context, {'host': 'host1_zones',
                                          'binary': "nova-compute",
                                          'topic': 'compute',
                                          'report_count': 0})
        agg = db.aggregate_create(admin_context,
                {'name': 'agg1'}, {'availability_zone': 'nova'})
        db.aggregate_host_add(admin_context, agg['id'], 'host1_zones')
        return self.req, body
Ejemplo n.º 2
0
 def test_describe_instances(self):
     """Makes sure describe_instances works and filters results."""
     inst1 = db.instance_create(self.context, {'reservation_id': 'a',
                                               'host': 'host1'})
     inst2 = db.instance_create(self.context, {'reservation_id': 'a',
                                               'host': 'host2'})
     comp1 = db.service_create(self.context, {'host': 'host1',
                                              'availability_zone': 'zone1',
                                              'topic': "compute"})
     comp2 = db.service_create(self.context, {'host': 'host2',
                                              'availability_zone': 'zone2',
                                              'topic': "compute"})
     result = self.cloud.describe_instances(self.context)
     result = result['reservationSet'][0]
     self.assertEqual(len(result['instancesSet']), 2)
     instance_id = cloud.id_to_ec2_id(inst2['id'])
     result = self.cloud.describe_instances(self.context,
                                          instance_id=[instance_id])
     result = result['reservationSet'][0]
     self.assertEqual(len(result['instancesSet']), 1)
     self.assertEqual(result['instancesSet'][0]['instanceId'],
                      instance_id)
     self.assertEqual(result['instancesSet'][0]
                      ['placement']['availabilityZone'], 'zone2')
     db.instance_destroy(self.context, inst1['id'])
     db.instance_destroy(self.context, inst2['id'])
     db.service_destroy(self.context, comp1['id'])
     db.service_destroy(self.context, comp2['id'])
Ejemplo n.º 3
0
    def _create_instance_with_availability_zone(self, zone_name):
        def create(*args, **kwargs):
            self.assertIn('availability_zone', kwargs)
            self.assertEqual('nova', kwargs['availability_zone'])
            return old_create(*args, **kwargs)

        old_create = compute_api.API.create
        self.stubs.Set(compute_api.API, 'create', create)
        image_href = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
        flavor_ref = ('http://localhost' + self.base_url + 'flavors/3')
        body = {
            'server': {
                'name': 'server_test',
                'imageRef': image_href,
                'flavorRef': flavor_ref,
                'metadata': {
                    'hello': 'world',
                    'open': 'stack',
                },
                'availability_zone': zone_name,
            },
        }

        admin_context = context.get_admin_context()
        db.service_create(
            admin_context, {
                'host': 'host1_zones',
                'binary': "nova-compute",
                'topic': 'compute',
                'report_count': 0
            })
        agg = db.aggregate_create(admin_context, {'name': 'agg1'},
                                  {'availability_zone': 'nova'})
        db.aggregate_host_add(admin_context, agg['id'], 'host1_zones')
        return self.req, body
Ejemplo n.º 4
0
def create_gridcentric_service(context):
    service = {'name': 'gridcentric-test-service',
               'topic': 'gridcentric',
               'host': create_uuid()
               }
    db.service_create(context, service)
    return service
Ejemplo n.º 5
0
    def _test_service_check_create_race(self, ex):
        self.manager_mock = self.mox.CreateMock(FakeManager)
        self.mox.StubOutWithMock(sys.modules[__name__],
                                 'FakeManager',
                                 use_mock_anything=True)
        self.mox.StubOutWithMock(self.manager_mock, 'init_host')
        self.mox.StubOutWithMock(self.manager_mock, 'pre_start_hook')
        self.mox.StubOutWithMock(self.manager_mock, 'post_start_hook')

        FakeManager(host=self.host).AndReturn(self.manager_mock)

        # init_host is called before any service record is created
        self.manager_mock.init_host()

        db.service_get_by_args(mox.IgnoreArg(), self.host,
                               self.binary).AndRaise(exception.NotFound)
        db.service_create(mox.IgnoreArg(), mox.IgnoreArg()).AndRaise(ex)

        class TestException(Exception):
            pass

        db.service_get_by_args(mox.IgnoreArg(), self.host,
                               self.binary).AndRaise(TestException)

        self.mox.ReplayAll()

        serv = service.Service(self.host, self.binary, self.topic,
                               'nova.tests.test_service.FakeManager')
        self.assertRaises(TestException, serv.start)
Ejemplo n.º 6
0
    def _test_service_check_create_race(self, ex):
        self.manager_mock = self.mox.CreateMock(FakeManager)
        self.mox.StubOutWithMock(sys.modules[__name__], 'FakeManager',
                                 use_mock_anything=True)
        self.mox.StubOutWithMock(self.manager_mock, 'init_host')
        self.mox.StubOutWithMock(self.manager_mock, 'pre_start_hook')
        self.mox.StubOutWithMock(self.manager_mock, 'post_start_hook')

        FakeManager(host=self.host).AndReturn(self.manager_mock)

        # init_host is called before any service record is created
        self.manager_mock.init_host()

        db.service_get_by_args(mox.IgnoreArg(), self.host, self.binary
                               ).AndRaise(exception.NotFound)
        db.service_create(mox.IgnoreArg(), mox.IgnoreArg()
                          ).AndRaise(ex)

        class TestException(Exception):
            pass

        db.service_get_by_args(mox.IgnoreArg(), self.host, self.binary
                               ).AndRaise(TestException)

        self.mox.ReplayAll()

        serv = service.Service(self.host,
                               self.binary,
                               self.topic,
                               'nova.tests.unit.test_service.FakeManager')
        self.assertRaises(TestException, serv.start)
Ejemplo n.º 7
0
def create_cobalt_service(context):
    service = {'name': 'cobalt-test-service',
               'topic': 'cobalt',
               'host': create_uuid()
               }
    db.service_create(context, service)
    return service
Ejemplo n.º 8
0
 def test_describe_instances(self):
     """Makes sure describe_instances works and filters results."""
     inst1 = db.instance_create(self.context, {'reservation_id': 'a',
                                               'image_id': 1,
                                               'host': 'host1'})
     inst2 = db.instance_create(self.context, {'reservation_id': 'a',
                                               'image_id': 1,
                                               'host': 'host2'})
     comp1 = db.service_create(self.context, {'host': 'host1',
                                              'availability_zone': 'zone1',
                                              'topic': "compute"})
     comp2 = db.service_create(self.context, {'host': 'host2',
                                              'availability_zone': 'zone2',
                                              'topic': "compute"})
     result = self.cloud.describe_instances(self.context)
     result = result['reservationSet'][0]
     self.assertEqual(len(result['instancesSet']), 2)
     instance_id = ec2utils.id_to_ec2_id(inst2['id'])
     result = self.cloud.describe_instances(self.context,
                                          instance_id=[instance_id])
     result = result['reservationSet'][0]
     self.assertEqual(len(result['instancesSet']), 1)
     self.assertEqual(result['instancesSet'][0]['instanceId'],
                      instance_id)
     self.assertEqual(result['instancesSet'][0]
                      ['placement']['availabilityZone'], 'zone2')
     db.instance_destroy(self.context, inst1['id'])
     db.instance_destroy(self.context, inst2['id'])
     db.service_destroy(self.context, comp1['id'])
     db.service_destroy(self.context, comp2['id'])
Ejemplo n.º 9
0
    def _service_start_mocks(self):
        service_create = {"host": self.host, "binary": self.binary, "topic": self.topic, "report_count": 0}
        service_ref = {"host": self.host, "binary": self.binary, "topic": self.topic, "report_count": 0, "id": 1}

        db.service_get_by_args(mox.IgnoreArg(), self.host, self.binary).AndRaise(exception.NotFound())
        db.service_create(mox.IgnoreArg(), service_create).AndReturn(service_ref)
        return service_ref
Ejemplo n.º 10
0
    def _create_instance_with_availability_zone(self, zone_name):
        def create(*args, **kwargs):
            self.assertIn("availability_zone", kwargs)
            self.assertEqual("nova", kwargs["availability_zone"])
            return old_create(*args, **kwargs)

        old_create = compute_api.API.create
        self.stubs.Set(compute_api.API, "create", create)
        image_href = "76fa36fc-c930-4bf3-8c8a-ea2a2420deb6"
        flavor_ref = "http://localhost" + self.base_url + "flavors/3"
        body = {
            "server": {
                "name": "server_test",
                "imageRef": image_href,
                "flavorRef": flavor_ref,
                "metadata": {"hello": "world", "open": "stack"},
                "availability_zone": zone_name,
            }
        }

        req = fakes.HTTPRequest.blank(self.base_url + "servers")
        req.method = "POST"
        req.body = jsonutils.dumps(body)
        req.headers["content-type"] = "application/json"
        admin_context = context.get_admin_context()
        db.service_create(
            admin_context, {"host": "host1_zones", "binary": "nova-compute", "topic": "compute", "report_count": 0}
        )
        agg = db.aggregate_create(admin_context, {"name": "agg1"}, {"availability_zone": "nova"})
        db.aggregate_host_add(admin_context, agg["id"], "host1_zones")
        return req, body
Ejemplo n.º 11
0
 def test_recreate_fails(self):
     self.mox.StubOutWithMock(db, "service_create")
     db.service_create(self.context, {"host": "fake-host"}).AndReturn(fake_service)
     self.mox.ReplayAll()
     service_obj = service.Service()
     service_obj.host = "fake-host"
     service_obj.create(self.context)
     self.assertRaises(exception.ObjectActionError, service_obj.create, self.context)
Ejemplo n.º 12
0
 def test_create(self):
     self.mox.StubOutWithMock(db, "service_create")
     db.service_create(self.context, {"host": "fake-host"}).AndReturn(fake_service)
     self.mox.ReplayAll()
     service_obj = service.Service()
     service_obj.host = "fake-host"
     service_obj.create(self.context)
     self.assertEqual(fake_service["id"], service_obj.id)
Ejemplo n.º 13
0
 def test_describe_hosts_volume(self):
     db.service_create(self._c, {'host': 'volume1',
         'binary': "nova-volume",
         'topic': 'volume',
         'report_count': 0,
         'availability_zone': "zone1"})
     hosts = self._ac.describe_hosts(self._c)['hosts']
     self.assertEqual('volume1', hosts[0]['hostname'])
Ejemplo n.º 14
0
def create_gridcentric_service(context):
    service = {
        'name': 'gridcentric-test-service',
        'topic': 'gridcentric',
        'host': create_uuid()
    }
    db.service_create(context, service)
    return service
Ejemplo n.º 15
0
def create_cobalt_service(context):
    service = {
        'name': 'cobalt-test-service',
        'topic': 'cobalt',
        'host': create_uuid()
    }
    db.service_create(context, service)
    return service
Ejemplo n.º 16
0
 def test_recreate_fails(self):
     self.mox.StubOutWithMock(db, 'service_create')
     db.service_create(self.context, {'host': 'fake-host'}).AndReturn(
         fake_service)
     self.mox.ReplayAll()
     service_obj = service.Service(context=self.context)
     service_obj.host = 'fake-host'
     service_obj.create()
     self.assertRaises(exception.ObjectActionError, service_obj.create)
Ejemplo n.º 17
0
 def test_recreate_fails(self):
     self.mox.StubOutWithMock(db, 'service_create')
     db.service_create(self.context, {'host': 'fake-host'}).AndReturn(
         fake_service)
     self.mox.ReplayAll()
     service_obj = service.Service(context=self.context)
     service_obj.host = 'fake-host'
     service_obj.create()
     self.assertRaises(exception.ObjectActionError, service_obj.create)
Ejemplo n.º 18
0
 def test_create(self):
     self.mox.StubOutWithMock(db, 'service_create')
     db.service_create(self.context, {'host': 'fake-host'}).AndReturn(
         fake_service)
     self.mox.ReplayAll()
     service_obj = service.Service()
     service_obj.host = 'fake-host'
     service_obj.create(self.context)
     self.assertEqual(fake_service['id'], service_obj.id)
Ejemplo n.º 19
0
 def test_describe_hosts_volume(self):
     db.service_create(
         self._c, {
             'host': 'volume1',
             'binary': "nova-volume",
             'topic': 'volume',
             'report_count': 0,
             'availability_zone': "zone1"
         })
     hosts = self._ac.describe_hosts(self._c)['hosts']
     self.assertEqual('volume1', hosts[0]['hostname'])
Ejemplo n.º 20
0
 def test_create(self):
     self.mox.StubOutWithMock(db, 'service_create')
     db.service_create(self.context, {'host': 'fake-host',
                                      'version': fake_service['version']}
                       ).AndReturn(fake_service)
     self.mox.ReplayAll()
     service_obj = service.Service(context=self.context)
     service_obj.host = 'fake-host'
     service_obj.create()
     self.assertEqual(fake_service['id'], service_obj.id)
     self.assertEqual(service.SERVICE_VERSION, service_obj.version)
Ejemplo n.º 21
0
 def test_create(self):
     self.mox.StubOutWithMock(db, 'service_create')
     db.service_create(self.context, {'host': 'fake-host',
                                      'version': fake_service['version']}
                       ).AndReturn(fake_service)
     self.mox.ReplayAll()
     service_obj = service.Service(context=self.context)
     service_obj.host = 'fake-host'
     service_obj.create()
     self.assertEqual(fake_service['id'], service_obj.id)
     self.assertEqual(service.SERVICE_VERSION, service_obj.version)
Ejemplo n.º 22
0
 def test_describe_hosts_volume(self):
     db.service_create(
         self._c,
         {
             "host": "volume1",
             "binary": "nova-volume",
             "topic": "volume",
             "report_count": 0,
             "availability_zone": "zone1",
         },
     )
     hosts = self._ac.describe_hosts(self._c)["hosts"]
     self.assertEqual("volume1", hosts[0]["hostname"])
Ejemplo n.º 23
0
    def test_live_migration_src_check_volume_node_not_alive(self):
        """Raise exception when volume node is not alive."""

        instance_id = self._create_instance()
        i_ref = db.instance_get(self.context, instance_id)
        dic = {'instance_id': instance_id, 'size': 1}
        v_ref = db.volume_create(self.context, {
            'instance_id': instance_id,
            'size': 1
        })
        t1 = utils.utcnow() - datetime.timedelta(1)
        dic = {
            'created_at': t1,
            'updated_at': t1,
            'binary': 'nova-volume',
            'topic': 'volume',
            'report_count': 0
        }
        s_ref = db.service_create(self.context, dic)

        self.assertRaises(exception.VolumeServiceUnavailable,
                          self.scheduler.driver.schedule_live_migration,
                          self.context, instance_id, i_ref['host'])

        db.instance_destroy(self.context, instance_id)
        db.service_destroy(self.context, s_ref['id'])
        db.volume_destroy(self.context, v_ref['id'])
Ejemplo n.º 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': ''
        }
        db.compute_node_create(ctxt, dic)

        return db.service_get(ctxt, s_ref['id'])
Ejemplo n.º 25
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'])
Ejemplo n.º 26
0
 def _create_service_with_topic(self, topic):
     values = {
         'binary': 'bin',
         'host': self.host,
         'topic': topic,
     }
     return db.service_create(self.context, values)
Ejemplo n.º 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()
     db_service = db.service_create(self._context, updates)
     self._from_db_object(self._context, self, db_service)
Ejemplo n.º 28
0
 def test_describe_availability_zones(self):
     """Makes sure describe_availability_zones works and filters results."""
     service1 = db.service_create(self.context, {'host': 'host1_zones',
                                      'binary': "nova-compute",
                                      'topic': 'compute',
                                      'report_count': 0,
                                      'availability_zone': "zone1"})
     service2 = db.service_create(self.context, {'host': 'host2_zones',
                                      'binary': "nova-compute",
                                      'topic': 'compute',
                                      'report_count': 0,
                                      'availability_zone': "zone2"})
     result = self.cloud.describe_availability_zones(self.context)
     self.assertEqual(len(result['availabilityZoneInfo']), 3)
     db.service_destroy(self.context, service1['id'])
     db.service_destroy(self.context, service2['id'])
Ejemplo n.º 29
0
    def _service_start_mocks(self):
        service_create = {'host': self.host,
                          'binary': self.binary,
                          'topic': self.topic,
                          'report_count': 0}
        service_ref = {'host': self.host,
                          'binary': self.binary,
                          'topic': self.topic,
                          'report_count': 0,
                          'id': 1}

        db.service_get_by_args(mox.IgnoreArg(),
                self.host, self.binary).AndRaise(exception.NotFound())
        db.service_create(mox.IgnoreArg(),
                service_create).AndReturn(service_ref)
        return service_ref
Ejemplo n.º 30
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"])
Ejemplo n.º 31
0
    def _service_start_mocks(self):
        service_create = {'host': self.host,
                          'binary': self.binary,
                          'topic': self.topic,
                          'report_count': 0}
        service_ref = {'host': self.host,
                          'binary': self.binary,
                          'topic': self.topic,
                          'report_count': 0,
                          'id': 1}

        db.service_get_by_args(mox.IgnoreArg(),
                self.host, self.binary).AndRaise(exception.NotFound())
        db.service_create(mox.IgnoreArg(),
                service_create).AndReturn(service_ref)
        return service_ref
Ejemplo n.º 32
0
    def setUp(self):
        super(CapacityTestCase, self).setUp()

        self.ctxt = context.get_admin_context()

        service_dict = dict(host="host1", binary="binary1", topic="compute", report_count=1, disabled=False)
        self.service = db.service_create(self.ctxt, 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,
        )
        # add some random stats
        stats = dict(num_instances=3, num_proj_12345=2, num_proj_23456=2, num_vm_building=3)
        self.compute_node_dict["stats"] = stats

        self.flags(reserved_host_memory_mb=0)
        self.flags(reserved_host_disk_mb=0)
Ejemplo n.º 33
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'])
Ejemplo n.º 34
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_service = db.service_create(context, updates)
     self._from_db_object(context, self, db_service)
Ejemplo n.º 35
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"])
Ejemplo n.º 36
0
 def _create_service_with_topic(self, topic):
     values = {
         'binary': 'bin',
         'host': self.host,
         'topic': topic,
     }
     return db.service_create(self.context, values)
Ejemplo n.º 37
0
    def test_create_instance_with_availability_zone(self):
        def create(*args, **kwargs):
            self.assertIn("availability_zone", kwargs)
            return old_create(*args, **kwargs)

        old_create = compute_api.API.create
        self.stubs.Set(compute_api.API, "create", create)
        image_href = "76fa36fc-c930-4bf3-8c8a-ea2a2420deb6"
        flavor_ref = "http://localhost/v3/flavors/3"
        body = {
            "server": {
                "name": "config_drive_test",
                "image_ref": image_href,
                "flavor_ref": flavor_ref,
                "metadata": {"hello": "world", "open": "stack"},
                "personality": {},
                "availability_zone": "nova",
            }
        }

        req = fakes.HTTPRequestV3.blank("/v3/servers")
        req.method = "POST"
        req.body = jsonutils.dumps(body)
        req.headers["content-type"] = "application/json"
        admin_context = context.get_admin_context()
        service1 = db.service_create(
            admin_context, {"host": "host1_zones", "binary": "nova-compute", "topic": "compute", "report_count": 0}
        )
        agg = db.aggregate_create(admin_context, {"name": "agg1"}, {"availability_zone": "nova"})
        db.aggregate_host_add(admin_context, agg["id"], "host1_zones")
        res = self.controller.create(req, body).obj
        server = res["server"]
        self.assertEqual(FAKE_UUID, server["id"])
Ejemplo n.º 38
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)
Ejemplo n.º 39
0
 def test_describe_availability_zones(self):
     """Makes sure describe_availability_zones works and filters results."""
     service1 = db.service_create(self.context, {'host': 'host1_zones',
                                      'binary': "nova-compute",
                                      'topic': 'compute',
                                      'report_count': 0,
                                      'availability_zone': "zone1"})
     service2 = db.service_create(self.context, {'host': 'host2_zones',
                                      'binary': "nova-compute",
                                      'topic': 'compute',
                                      'report_count': 0,
                                      'availability_zone': "zone2"})
     result = self.cloud.describe_availability_zones(self.context)
     self.assertEqual(len(result['availabilityZoneInfo']), 3)
     db.service_destroy(self.context, service1['id'])
     db.service_destroy(self.context, service2['id'])
Ejemplo n.º 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()
     db_service = db.service_create(context, updates)
     self._from_db_object(context, self, db_service)
Ejemplo n.º 41
0
    def setUp(self):
        super(CapacityTestCase, self).setUp()

        self.ctxt = context.get_admin_context()

        service_dict = dict(host='host1',
                            binary='binary1',
                            topic='compute',
                            report_count=1,
                            disabled=False)
        self.service = db.service_create(self.ctxt, 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,
                                      hypervisor_type="xen",
                                      hypervisor_version=1,
                                      cpu_info="",
                                      service_id=self.service.id)

        self.flags(reserved_host_memory_mb=0)
        self.flags(reserved_host_disk_mb=0)
 def create(self):
     if self.obj_attr_is_set("id"):
         raise exception.ObjectActionError(action="create", reason="already created")
     self._check_minimum_version()
     updates = self.obj_get_changes()
     db_service = db.service_create(self._context, updates)
     self._from_db_object(self._context, self, db_service)
Ejemplo n.º 43
0
 def _create_service_with_topic(self, topic, host, disabled=False):
     values = {
         'binary': 'nova-bin',
         'host': host,
         'topic': topic,
         'disabled': disabled,
     }
     return db.service_create(self.context, values)
Ejemplo n.º 44
0
    def create_service(self, **kwargs):
        service_ref = {'host': kwargs.get('host', 'dummy'),
                       'binary': 'nova-compute',
                       'topic': 'compute',
                       'report_count': 0,
                       'availability_zone': 'zone'}

        return db.service_create(context.get_admin_context(), service_ref)
Ejemplo n.º 45
0
 def _create_service_with_topic(self, topic, host, disabled=False):
     values = {
         'binary': 'bin',
         'host': host,
         'topic': topic,
         'disabled': disabled,
     }
     return db.service_create(self.context, values)
Ejemplo n.º 46
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"
Ejemplo n.º 47
0
 def _create_service_ref(self, context):
     zone = FLAGS.node_availability_zone
     service_ref = db.service_create(context,
                                     {'host': self.host,
                                      'binary': self.binary,
                                      'topic': self.topic,
                                      'report_count': 0,
                                      'availability_zone': zone})
     self.service_id = service_ref['id']
Ejemplo n.º 48
0
 def _create_service_ref(self, context):
     zone = FLAGS.node_availability_zone
     service_ref = db.service_create(context,
                                     {'host': self.host,
                                      'binary': self.binary,
                                      'topic': self.topic,
                                      'report_count': 0,
                                      'availability_zone': zone})
     self.service_id = service_ref['id']
Ejemplo n.º 49
0
    def create_service(self, **kwargs):
        service_ref = {
            'host': kwargs.get('host', 'dummy'),
            'binary': 'nova-compute',
            'topic': 'compute',
            'report_count': 0,
            'availability_zone': 'zone'
        }

        return db.service_create(context.get_admin_context(), service_ref)
Ejemplo n.º 50
0
 def _create_service_ref(self, context):
     zone = FLAGS.node_availability_zone
     host_ip = self._get_host_ip_by_ifname(FLAGS.host_ip_ifname)
     service_ref = db.service_create(context,
                                     {'host': self.host,
                                      'host_ip': host_ip,
                                      'binary': self.binary,
                                      'topic': self.topic,
                                      'report_count': 0,
                                      'availability_zone': zone})
     self.service_id = service_ref['id']
Ejemplo n.º 51
0
    def test_populate_missing_availability_zones(self):
        # create two instances once with avz set and other not set.
        inst1 = self._create_instance(host="fake-host1")
        uuid1 = inst1.uuid
        inst2 = self._create_instance(availability_zone="fake",
                                      host="fake-host2")
        # ... and one without a host (simulating failed spawn)
        self._create_instance(host=None)

        self.assertIsNone(inst1.availability_zone)
        self.assertEqual("fake", inst2.availability_zone)
        count_all, count_hit = (
            objects.instance.populate_missing_availability_zones(
                self.context, 10))
        # we get only the instance whose avz was None and where host is set
        self.assertEqual(1, count_all)
        self.assertEqual(1, count_hit)
        # since instance has no avz, avz is set by get_host_availability_zone
        # to CONF.default_availability_zone i.e 'nova' which is the default
        # zone for compute services.
        inst1 = objects.Instance.get_by_uuid(self.context, uuid1)
        self.assertEqual('nova', inst1.availability_zone)

        # create an instance with avz as None on a host that has avz.
        host = 'fake-host'
        agg_meta = {
            'name': 'az_agg',
            'uuid': uuidutils.generate_uuid(),
            'metadata': {
                'availability_zone': 'nova-test'
            }
        }
        agg = objects.Aggregate(self.context, **agg_meta)
        agg.create()
        agg = objects.Aggregate.get_by_id(self.context, agg.id)
        values = {
            'binary': 'nova-compute',
            'host': host,
            'topic': 'compute',
            'disabled': False,
        }
        service = db.service_create(self.context, values)
        agg.add_host(service['host'])
        inst3 = self._create_instance(host=host)
        uuid3 = inst3.uuid
        self.assertIsNone(inst3.availability_zone)
        count_all, count_hit = (
            objects.instance.populate_missing_availability_zones(
                self.context, 10))
        # we get only the instance whose avz was None i.e inst3.
        self.assertEqual(1, count_all)
        self.assertEqual(1, count_hit)
        inst3 = objects.Instance.get_by_uuid(self.context, uuid3)
        self.assertEqual('nova-test', inst3.availability_zone)
Ejemplo n.º 52
0
    def test_create_instance_with_availability_zone(self):
        def create(*args, **kwargs):
            self.assertIn('availability_zone', kwargs)
            self.assertEqual('nova', kwargs['availability_zone'])
            return old_create(*args, **kwargs)

        old_create = compute_api.API.create
        self.stubs.Set(compute_api.API, 'create', create)
        image_href = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
        flavor_ref = 'http://localhost/v3/flavors/3'
        body = {
            'server': {
                'name': 'config_drive_test',
                'image_ref': image_href,
                'flavor_ref': flavor_ref,
                'metadata': {
                    'hello': 'world',
                    'open': 'stack',
                },
                availability_zone.ATTRIBUTE_NAME: "nova",
            },
        }

        req = fakes.HTTPRequestV3.blank('/v3/servers')
        req.method = 'POST'
        req.body = jsonutils.dumps(body)
        req.headers["content-type"] = "application/json"
        admin_context = context.get_admin_context()
        db.service_create(
            admin_context, {
                'host': 'host1_zones',
                'binary': "nova-compute",
                'topic': 'compute',
                'report_count': 0
            })
        agg = db.aggregate_create(admin_context, {'name': 'agg1'},
                                  {'availability_zone': 'nova'})
        db.aggregate_host_add(admin_context, agg['id'], 'host1_zones')
        res = self.controller.create(req, body=body).obj
        server = res['server']
        self.assertEqual(FAKE_UUID, server['id'])
Ejemplo n.º 53
0
 def setUp(self):
     self.flags(retry_count=0, group='saver')
     super(CheckInactiveEnabledComputeHostsTest, self).setUp()
     self.stubs.Set(utils, 'spawn_n', self.fake_spawn_n)
     self.evacuated_hosts = []
     for x in range(1, 4):
         self.fake_service = db.service_create(self.context, {
             'host': 'fake-host%d' % x,
             'binary': "nova-compute",
             'topic': 'compute',
             'report_count': 0,
             'disabled': False})
Ejemplo n.º 54
0
    def create(self):
        if self.obj_attr_is_set('id'):
            raise exception.ObjectActionError(action='create',
                                              reason='already created')
        self._check_minimum_version()
        updates = self.obj_get_changes()

        if 'uuid' not in updates:
            updates['uuid'] = uuidutils.generate_uuid()
            self.uuid = updates['uuid']

        db_service = db.service_create(self._context, updates)
        self._from_db_object(self._context, self, db_service)
Ejemplo n.º 55
0
    def test_live_migration_src_check_volume_node_not_alive(self):
        """Raise exception when volume node is not alive."""

        instance_id = self._create_instance()
        i_ref = db.instance_get(self.context, instance_id)
        dic = {'instance_id': instance_id, 'size': 1}
        v_ref = db.volume_create(self.context, {'instance_id': instance_id,
                                                'size': 1})
        t1 = datetime.datetime.utcnow() - datetime.timedelta(1)
        dic = {'created_at': t1, 'updated_at': t1, 'binary': 'nova-volume',
               'topic': 'volume', 'report_count': 0}
        s_ref = db.service_create(self.context, dic)

        try:
            self.scheduler.driver.schedule_live_migration(self.context,
                                                          instance_id,
                                                          i_ref['host'])
        except exception.Invalid, e:
            c = (e.message.find('volume node is not alive') >= 0)
Ejemplo n.º 56
0
    def test_instance_list_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.
        service = db.service_create(self.context, {
            'host': 'fake-host',
            'binary': 'nova-compute'
        })
        self.assertIsNone(service['uuid'])

        # Create an instance whose host will match the service with no uuid
        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(1, len(insts[0].services))
        self.assertIsNotNone(insts[0].services[0].uuid)
Ejemplo n.º 57
0
    def test_compute_can_update_available_resource(self):
        """Confirm compute updates their record of compute-service table."""
        host = 'foo'
        binary = 'nova-compute'
        topic = 'compute'

        # Any mocks are not working without UnsetStubs() here.
        self.mox.UnsetStubs()
        ctxt = context.get_admin_context()
        service_ref = db.service_create(ctxt, {
            'host': host,
            'binary': binary,
            'topic': topic
        })
        serv = service.Service(host, binary, topic,
                               'nova.compute.manager.ComputeManager')

        # This testcase want to test calling update_available_resource.
        # No need to call periodic call, then below variable must be set 0.
        serv.report_interval = 0
        serv.periodic_interval = 0

        # Creating mocks
        self.mox.StubOutWithMock(service.rpc.Connection, 'instance')
        service.rpc.Connection.instance(new=mox.IgnoreArg())
        service.rpc.Connection.instance(new=mox.IgnoreArg())
        service.rpc.Connection.instance(new=mox.IgnoreArg())
        self.mox.StubOutWithMock(serv.manager.driver,
                                 'update_available_resource')
        serv.manager.driver.update_available_resource(mox.IgnoreArg(), host)

        # Just doing start()-stop(), not confirm new db record is created,
        # because update_available_resource() works only in
        # libvirt environment. This testcase confirms
        # update_available_resource() is called. Otherwise, mox complains.
        self.mox.ReplayAll()
        serv.start()
        serv.stop()

        db.service_destroy(ctxt, service_ref['id'])
Ejemplo n.º 58
0
 def create(self, context):
     updates = {}
     for key in self.obj_what_changed():
         updates[key] = self[key]
     db_service = db.service_create(context, updates)
     self._from_db_object(context, self, db_service)
Ejemplo n.º 59
0
 def create(self, context):
     updates = self.obj_get_changes()
     db_service = db.service_create(context, updates)
     self._from_db_object(context, self, db_service)