Example #1
0
 def test_create(self):
     self.mox.StubOutWithMock(db, 'aggregate_create')
     db.aggregate_create(self.context, {'name': 'foo'},
                         metadata={'one': 'two'}).AndReturn(fake_aggregate)
     self.mox.ReplayAll()
     agg = aggregate.Aggregate(context=self.context)
     agg.name = 'foo'
     agg.metadata = {'one': 'two'}
     agg.create()
     self.compare_obj(agg, fake_aggregate, subs=SUBS)
Example #2
0
 def test_recreate_fails(self):
     self.mox.StubOutWithMock(db, 'aggregate_create')
     db.aggregate_create(self.context, {'name': 'foo'},
                         metadata={'one': 'two'}).AndReturn(fake_aggregate)
     self.mox.ReplayAll()
     agg = aggregate.Aggregate(context=self.context)
     agg.name = 'foo'
     agg.metadata = {'one': 'two'}
     agg.create()
     self.assertRaises(exception.ObjectActionError, agg.create,
                       self.context)
Example #3
0
 def test_create(self):
     self.mox.StubOutWithMock(db, 'aggregate_create')
     db.aggregate_create(self.context, {
         'name': 'foo'
     },
                         metadata={
                             'one': 'two'
                         }).AndReturn(fake_aggregate)
     self.mox.ReplayAll()
     agg = aggregate.Aggregate(context=self.context)
     agg.name = 'foo'
     agg.metadata = {'one': 'two'}
     agg.create()
     self.compare_obj(agg, fake_aggregate, subs=SUBS)
Example #4
0
 def test_recreate_fails(self):
     self.mox.StubOutWithMock(db, 'aggregate_create')
     db.aggregate_create(self.context, {
         'name': 'foo'
     },
                         metadata={
                             'one': 'two'
                         }).AndReturn(fake_aggregate)
     self.mox.ReplayAll()
     agg = aggregate.Aggregate(context=self.context)
     agg.name = 'foo'
     agg.metadata = {'one': 'two'}
     agg.create()
     self.assertRaises(exception.ObjectActionError, agg.create,
                       self.context)
    def _create_instance_with_availability_zone(self, zone_name):
        def create(*args, **kwargs):
            self.assertIn('availability_zone', kwargs)
            self.assertEqual('patron', 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': "patron-compute",
                'topic': 'compute',
                'report_count': 0
            })
        agg = db.aggregate_create(admin_context, {'name': 'agg1'},
                                  {'availability_zone': 'patron'})
        db.aggregate_host_add(admin_context, agg['id'], 'host1_zones')
        return self.req, body
Example #6
0
    def _create_instance_with_availability_zone(self, zone_name):
        def create(*args, **kwargs):
            self.assertIn('availability_zone', kwargs)
            self.assertEqual('patron', 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': "patron-compute",
                                          'topic': 'compute',
                                          'report_count': 0})
        agg = db.aggregate_create(admin_context,
                {'name': 'agg1'}, {'availability_zone': 'patron'})
        db.aggregate_host_add(admin_context, agg['id'], 'host1_zones')
        return self.req, body
Example #7
0
    def _create_az(self, agg_name, az_name):
        agg_meta = {'name': agg_name}
        agg = db.aggregate_create(self.context, agg_meta)

        metadata = {'availability_zone': az_name}
        db.aggregate_metadata_add(self.context, agg['id'], metadata)

        return agg
Example #8
0
 def create(self):
     if self.obj_attr_is_set('id'):
         raise exception.ObjectActionError(action='create',
                                           reason='already created')
     self._assert_no_hosts('create')
     updates = self.obj_get_changes()
     payload = dict(updates)
     if 'metadata' in updates:
         # NOTE(danms): For some reason the notification format is weird
         payload['meta_data'] = payload.pop('metadata')
     compute_utils.notify_about_aggregate_update(self._context,
                                                 "create.start", payload)
     metadata = updates.pop('metadata', None)
     db_aggregate = db.aggregate_create(self._context,
                                        updates,
                                        metadata=metadata)
     self._from_db_object(self._context, self, db_aggregate)
     payload['aggregate_id'] = self.id
     compute_utils.notify_about_aggregate_update(self._context,
                                                 "create.end", payload)