示例#1
0
 def test_notify_about_aggregate_update_without_name_id(self):
     # Set empty aggregate payload
     aggregate_payload = {}
     compute_utils.notify_about_aggregate_update(self.context,
                                                 "create.start",
                                                 aggregate_payload)
     self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
示例#2
0
 def test_notify_about_aggregate_update_with_name(self):
     # Set aggregate payload
     aggregate_payload = {'name': 'fakegroup'}
     compute_utils.notify_about_aggregate_update(self.context,
                                                 "create.start",
                                                 aggregate_payload)
     self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
     msg = fake_notifier.NOTIFICATIONS[0]
     self.assertEqual(msg.priority, 'INFO')
     self.assertEqual(msg.event_type, 'aggregate.create.start')
     payload = msg.payload
     self.assertEqual(payload['name'], 'fakegroup')
示例#3
0
 def test_notify_about_aggregate_update_with_id(self):
     # Set aggregate payload
     aggregate_payload = {'aggregate_id': 1}
     compute_utils.notify_about_aggregate_update(self.context,
                                                 "create.end",
                                                 aggregate_payload)
     self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
     msg = fake_notifier.NOTIFICATIONS[0]
     self.assertEqual(msg.priority, 'INFO')
     self.assertEqual(msg.event_type, 'aggregate.create.end')
     payload = msg.payload
     self.assertEqual(payload['aggregate_id'], 1)
示例#4
0
    def save(self):
        self._assert_no_hosts('save')
        updates = self.obj_get_changes()

        payload = {'aggregate_id': self.id}
        if 'metadata' in updates:
            payload['meta_data'] = updates['metadata']
        compute_utils.notify_about_aggregate_update(self._context,
                                                    "updateprop.start",
                                                    payload)
        updates.pop('id', None)
        db_aggregate = db.aggregate_update(self._context, self.id, updates)
        compute_utils.notify_about_aggregate_update(self._context,
                                                    "updateprop.end", payload)
        self._from_db_object(self._context, self, db_aggregate)
示例#5
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)
示例#6
0
 def update_metadata(self, updates):
     payload = {'aggregate_id': self.id, 'meta_data': updates}
     compute_utils.notify_about_aggregate_update(self._context,
                                                 "updatemetadata.start",
                                                 payload)
     to_add = {}
     for key, value in updates.items():
         if value is None:
             try:
                 db.aggregate_metadata_delete(self._context, self.id, key)
             except exception.AggregateMetadataNotFound:
                 pass
             try:
                 self.metadata.pop(key)
             except KeyError:
                 pass
         else:
             to_add[key] = value
             self.metadata[key] = value
     db.aggregate_metadata_add(self._context, self.id, to_add)
     compute_utils.notify_about_aggregate_update(self._context,
                                                 "updatemetadata.end",
                                                 payload)
     self.obj_reset_changes(fields=['metadata'])