예제 #1
0
파일: aggregate.py 프로젝트: allinhtml/nova
 def update_metadata(self, context, updates):
     payload = {'aggregate_id': self.id, 'meta_data': updates}
     compute_utils.notify_about_aggregate_update(context,
                                                 "updatemetadata.start",
                                                 payload)
     to_add = {}
     for key, value in updates.items():
         if value is None:
             try:
                 db.aggregate_metadata_delete(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(context, self.id, to_add)
     payload['meta_data'] = to_add
     compute_utils.notify_about_aggregate_update(context,
                                                 "updatemetadata.end",
                                                 payload)
     self.obj_reset_changes(fields=['metadata'])
예제 #2
0
파일: pool.py 프로젝트: justinsb/nova
 def add_to_aggregate(self, context, aggregate, host, **kwargs):
     """Add a compute host to an aggregate."""
     if len(aggregate.hosts) == 1:
         # this is the first host of the pool -> make it master
         self._init_pool(aggregate.id, aggregate.name)
         # save metadata so that we can find the master again
         values = {
             'operational_state': aggregate_states.ACTIVE,
             'metadata': {
                 'master_compute': host,
                 host: self._host_uuid
             },
         }
         db.aggregate_update(context, aggregate.id, values)
     else:
         # the pool is already up and running, we need to figure out
         # whether we can serve the request from this host or not.
         master_compute = aggregate.metadetails['master_compute']
         if master_compute == FLAGS.host and master_compute != host:
             # this is the master ->  do a pool-join
             # To this aim, nova compute on the slave has to go down.
             # NOTE: it is assumed that ONLY nova compute is running now
             self._join_slave(aggregate.id, host,
                              kwargs.get('compute_uuid'), kwargs.get('url'),
                              kwargs.get('user'), kwargs.get('passwd'))
             metadata = {
                 host: kwargs.get('xenhost_uuid'),
             }
             db.aggregate_metadata_add(context, aggregate.id, metadata)
         elif master_compute and master_compute != host:
             # send rpc cast to master, asking to add the following
             # host with specified credentials.
             forward_request(context, "add_aggregate_host", master_compute,
                             aggregate.id, host, self._host_addr,
                             self._host_uuid)
예제 #3
0
파일: aggregate.py 프로젝트: B-Rich/nova-1
 def update_metadata(self, context, updates):
     payload = {'aggregate_id': self.id,
                'meta_data': updates}
     compute_utils.notify_about_aggregate_update(context,
                                                 "updatemetadata.start",
                                                 payload)
     to_add = {}
     for key, value in updates.items():
         if value is None:
             try:
                 db.aggregate_metadata_delete(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(context, self.id, to_add)
     compute_utils.notify_about_aggregate_update(context,
                                                 "updatemetadata.end",
                                                 payload)
     self.obj_reset_changes(fields=['metadata'])
예제 #4
0
 def add_to_aggregate(self, context, aggregate, host, **kwargs):
     """Add a compute host to an aggregate."""
     if len(aggregate.hosts) == 1:
         # this is the first host of the pool -> make it master
         self._init_pool(aggregate.id, aggregate.name)
         # save metadata so that we can find the master again
         values = {
             'operational_state': aggregate_states.ACTIVE,
             'metadata': {'master_compute': host,
                          host: self._host_uuid},
             }
         db.aggregate_update(context, aggregate.id, values)
     else:
         # the pool is already up and running, we need to figure out
         # whether we can serve the request from this host or not.
         master_compute = aggregate.metadetails['master_compute']
         if master_compute == FLAGS.host and master_compute != host:
             # this is the master ->  do a pool-join
             # To this aim, nova compute on the slave has to go down.
             # NOTE: it is assumed that ONLY nova compute is running now
             self._join_slave(aggregate.id, host,
                              kwargs.get('compute_uuid'),
                              kwargs.get('url'), kwargs.get('user'),
                              kwargs.get('passwd'))
             metadata = {host: kwargs.get('xenhost_uuid'), }
             db.aggregate_metadata_add(context, aggregate.id, metadata)
         elif master_compute and master_compute != host:
             # send rpc cast to master, asking to add the following
             # host with specified credentials.
             forward_request(context, "add_aggregate_host", master_compute,
                             aggregate.id, host,
                             self._host_addr, self._host_uuid)
예제 #5
0
 def test_update_metadata(self):
     self.mox.StubOutWithMock(db, 'aggregate_metadata_delete')
     self.mox.StubOutWithMock(db, 'aggregate_metadata_add')
     db.aggregate_metadata_delete(self.context, 123, 'todelete')
     db.aggregate_metadata_add(self.context, 123, {'toadd': 'myval'})
     self.mox.ReplayAll()
     fake_notifier.NOTIFICATIONS = []
     agg = aggregate.Aggregate()
     agg._context = self.context
     agg.id = 123
     agg.metadata = {'foo': 'bar'}
     agg.obj_reset_changes()
     agg.update_metadata({'todelete': None, 'toadd': 'myval'})
     self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
     msg = fake_notifier.NOTIFICATIONS[0]
     self.assertEqual('aggregate.updatemetadata.start', msg.event_type)
     self.assertEqual({
         'todelete': None,
         'toadd': 'myval'
     }, msg.payload['meta_data'])
     msg = fake_notifier.NOTIFICATIONS[1]
     self.assertEqual('aggregate.updatemetadata.end', msg.event_type)
     self.assertEqual({
         'todelete': None,
         'toadd': 'myval'
     }, msg.payload['meta_data'])
     self.assertEqual({'foo': 'bar', 'toadd': 'myval'}, agg.metadata)
예제 #6
0
 def test_aggregate_metadata_add(self):
     aggregate = {"name": "fake aggregate", "id": "fake-id"}
     metadata = {"foo": "bar"}
     self.mox.StubOutWithMock(db, "aggregate_metadata_add")
     db.aggregate_metadata_add(mox.IgnoreArg(), aggregate["id"], metadata, False).AndReturn(metadata)
     self.mox.ReplayAll()
     result = self.conductor.aggregate_metadata_add(self.context, aggregate, metadata)
     self.assertEqual(result, metadata)
예제 #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
예제 #8
0
 def test_aggregate_metadata_add(self):
     """Ensure we can add metadata for the aggregate."""
     ctxt = context.get_admin_context()
     result = _create_aggregate(context=ctxt, metadata=None)
     metadata = _get_fake_aggr_metadata()
     db.aggregate_metadata_add(ctxt, result.id, metadata)
     expected = db.aggregate_metadata_get(ctxt, result.id)
     self.assertDictMatch(metadata, expected)
예제 #9
0
    def _create_az(self, agg_name, az_name):
        agg_meta = {'name': agg_name, 'uuid': uuidsentinel.agg_uuid}
        agg = db.aggregate_create(self.context, agg_meta)

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

        return agg
예제 #10
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
예제 #11
0
파일: test_db_api.py 프로젝트: matiu2/nova
 def test_aggregate_metadata_add(self):
     """Ensure we can add metadata for the aggregate."""
     ctxt = context.get_admin_context()
     result = _create_aggregate(context=ctxt, metadata=None)
     metadata = _get_fake_aggr_metadata()
     db.aggregate_metadata_add(ctxt, result.id, metadata)
     expected = db.aggregate_metadata_get(ctxt, result.id)
     self.assertDictMatch(metadata, expected)
예제 #12
0
 def test_aggregate_metadata_add(self):
     aggregate = {'name': 'fake aggregate', 'id': 'fake-id'}
     metadata = {'foo': 'bar'}
     self.mox.StubOutWithMock(db, 'aggregate_metadata_add')
     db.aggregate_metadata_add(mox.IgnoreArg(), aggregate['id'], metadata,
                               False).AndReturn(metadata)
     self.mox.ReplayAll()
     result = self.conductor.aggregate_metadata_add(self.context, aggregate,
                                                    metadata)
     self.assertEqual(result, metadata)
예제 #13
0
 def test_aggregate_metadata_delete(self):
     """Ensure we can delete metadata for the aggregate."""
     ctxt = context.get_admin_context()
     result = _create_aggregate(context=ctxt, metadata=None)
     metadata = _get_fake_aggr_metadata()
     db.aggregate_metadata_add(ctxt, result.id, metadata)
     db.aggregate_metadata_delete(ctxt, result.id, metadata.keys()[0])
     expected = db.aggregate_metadata_get(ctxt, result.id)
     del metadata[metadata.keys()[0]]
     self.assertThat(metadata, matchers.DictMatches(expected))
예제 #14
0
 def undo_aggregate_operation(self, context, op, aggregate_id,
                               host, set_error):
     """Undo aggregate operation when pool error raised"""
     try:
         if set_error:
             metadata = {pool_states.KEY: pool_states.ERROR}
             db.aggregate_metadata_add(context, aggregate_id, metadata)
         op(context, aggregate_id, host)
     except Exception:
         LOG.exception(_('Aggregate %(aggregate_id)s: unrecoverable state '
                         'during operation on %(host)s') % locals())
예제 #15
0
파일: pool.py 프로젝트: aantonov/nova
 def undo_aggregate_operation(self, context, op, aggregate_id,
                               host, set_error):
     """Undo aggregate operation when pool error raised"""
     try:
         if set_error:
             metadata = {pool_states.KEY: pool_states.ERROR}
             db.aggregate_metadata_add(context, aggregate_id, metadata)
         op(context, aggregate_id, host)
     except Exception:
         LOG.exception(_('Aggregate %(aggregate_id)s: unrecoverable state '
                         'during operation on %(host)s') % locals())
예제 #16
0
 def test_aggregate_metadata_add(self):
     aggregate = {'name': 'fake aggregate', 'id': 'fake-id'}
     metadata = {'foo': 'bar'}
     self.mox.StubOutWithMock(db, 'aggregate_metadata_add')
     db.aggregate_metadata_add(
         mox.IgnoreArg(), aggregate['id'], metadata, False).AndReturn(
             metadata)
     self.mox.ReplayAll()
     result = self.conductor.aggregate_metadata_add(self.context,
                                                    aggregate,
                                                    metadata)
     self.assertEqual(result, metadata)
예제 #17
0
 def test_aggregate_metadata_update(self):
     """Ensure we can update metadata for the aggregate."""
     ctxt = context.get_admin_context()
     result = _create_aggregate(context=ctxt)
     metadata = _get_fake_aggr_metadata()
     key = metadata.keys()[0]
     db.aggregate_metadata_delete(ctxt, result.id, key)
     new_metadata = {key: 'foo'}
     db.aggregate_metadata_add(ctxt, result.id, new_metadata)
     expected = db.aggregate_metadata_get(ctxt, result.id)
     metadata[key] = 'foo'
     self.assertDictMatch(metadata, expected)
예제 #18
0
파일: test_db_api.py 프로젝트: matiu2/nova
 def test_aggregate_metadata_update(self):
     """Ensure we can update metadata for the aggregate."""
     ctxt = context.get_admin_context()
     result = _create_aggregate(context=ctxt)
     metadata = _get_fake_aggr_metadata()
     key = metadata.keys()[0]
     db.aggregate_metadata_delete(ctxt, result.id, key)
     new_metadata = {key: 'foo'}
     db.aggregate_metadata_add(ctxt, result.id, new_metadata)
     expected = db.aggregate_metadata_get(ctxt, result.id)
     metadata[key] = 'foo'
     self.assertDictMatch(metadata, expected)
예제 #19
0
 def test_update_metadata(self):
     self.mox.StubOutWithMock(db, "aggregate_metadata_delete")
     self.mox.StubOutWithMock(db, "aggregate_metadata_add")
     db.aggregate_metadata_delete(self.context, 123, "todelete")
     db.aggregate_metadata_add(self.context, 123, {"toadd": "myval"})
     self.mox.ReplayAll()
     agg = aggregate.Aggregate()
     agg._context = self.context
     agg.id = 123
     agg.metadata = {"foo": "bar"}
     agg.obj_reset_changes()
     agg.update_metadata({"todelete": None, "toadd": "myval"})
     self.assertEqual({"foo": "bar", "toadd": "myval"}, agg.metadata)
예제 #20
0
    def setUp(self):
        super(AvailabilityZoneTestCases, self).setUp()
        self.host = 'me'
        self.availability_zone = 'nova-test'
        self.default_az = CONF.default_availability_zone
        self.default_in_az = CONF.internal_service_availability_zone
        self.context = context.get_admin_context()

        agg = {'name': 'agg1'}
        self.agg = db.aggregate_create(self.context, agg)

        metadata = {'availability_zone': self.availability_zone}
        db.aggregate_metadata_add(self.context, self.agg['id'], metadata)
예제 #21
0
    def setUp(self):
        super(AvailabilityZoneTestCases, self).setUp()
        self.host = 'me'
        self.availability_zone = 'nova-test'
        self.default_az = CONF.default_availability_zone
        self.default_in_az = CONF.internal_service_availability_zone
        self.context = context.get_admin_context()

        agg = {'name': 'agg1'}
        self.agg = db.aggregate_create(self.context, agg)

        metadata = {'availability_zone': self.availability_zone}
        db.aggregate_metadata_add(self.context, self.agg['id'], metadata)
예제 #22
0
 def test_update_metadata(self):
     self.mox.StubOutWithMock(db, 'aggregate_metadata_delete')
     self.mox.StubOutWithMock(db, 'aggregate_metadata_add')
     db.aggregate_metadata_delete(self.context, 123, 'todelete')
     db.aggregate_metadata_add(self.context, 123, {'toadd': 'myval'})
     self.mox.ReplayAll()
     agg = aggregate.Aggregate()
     agg._context = self.context
     agg.id = 123
     agg.metadata = {'foo': 'bar'}
     agg.obj_reset_changes()
     agg.update_metadata({'todelete': None, 'toadd': 'myval'})
     self.assertEqual({'foo': 'bar', 'toadd': 'myval'}, agg.metadata)
예제 #23
0
 def test_update_metadata(self):
     self.mox.StubOutWithMock(db, 'aggregate_metadata_delete')
     self.mox.StubOutWithMock(db, 'aggregate_metadata_add')
     db.aggregate_metadata_delete(self.context, 123, 'todelete')
     db.aggregate_metadata_add(self.context, 123, {'toadd': 'myval'})
     self.mox.ReplayAll()
     agg = aggregate.Aggregate()
     agg._context = self.context
     agg.id = 123
     agg.metadata = {'foo': 'bar'}
     agg.obj_reset_changes()
     agg.update_metadata({'todelete': None, 'toadd': 'myval'})
     self.assertEqual({'foo': 'bar', 'toadd': 'myval'}, agg.metadata)
예제 #24
0
파일: fake.py 프로젝트: EE-NovRain/nova
 def aggregate_metadata_add(self,
                            context,
                            aggregate_id,
                            metadata,
                            set_delete=False):
     return db.aggregate_metadata_add(context, aggregate_id, metadata,
                                      set_delete)
예제 #25
0
 def test_update_metadata(self):
     self.mox.StubOutWithMock(db, "aggregate_metadata_delete")
     self.mox.StubOutWithMock(db, "aggregate_metadata_add")
     db.aggregate_metadata_delete(self.context, 123, "todelete")
     db.aggregate_metadata_add(self.context, 123, {"toadd": "myval"})
     self.mox.ReplayAll()
     fake_notifier.NOTIFICATIONS = []
     agg = aggregate.Aggregate()
     agg._context = self.context
     agg.id = 123
     agg.metadata = {"foo": "bar"}
     agg.obj_reset_changes()
     agg.update_metadata({"todelete": None, "toadd": "myval"})
     self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
     msg = fake_notifier.NOTIFICATIONS[0]
     self.assertEqual("aggregate.updatemetadata.start", msg.event_type)
     self.assertEqual({"todelete": None, "toadd": "myval"}, msg.payload["meta_data"])
     msg = fake_notifier.NOTIFICATIONS[1]
     self.assertEqual("aggregate.updatemetadata.end", msg.event_type)
     self.assertEqual({"todelete": None, "toadd": "myval"}, msg.payload["meta_data"])
     self.assertEqual({"foo": "bar", "toadd": "myval"}, agg.metadata)
예제 #26
0
 def test_update_metadata(self):
     self.mox.StubOutWithMock(db, 'aggregate_metadata_delete')
     self.mox.StubOutWithMock(db, 'aggregate_metadata_add')
     db.aggregate_metadata_delete(self.context, 123, 'todelete')
     db.aggregate_metadata_add(self.context, 123, {'toadd': 'myval'})
     self.mox.ReplayAll()
     fake_notifier.NOTIFICATIONS = []
     agg = aggregate.Aggregate()
     agg._context = self.context
     agg.id = 123
     agg.metadata = {'foo': 'bar'}
     agg.obj_reset_changes()
     agg.update_metadata({'todelete': None, 'toadd': 'myval'})
     self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
     msg = fake_notifier.NOTIFICATIONS[0]
     self.assertEqual('aggregate.updatemetadata.start', msg.event_type)
     self.assertEqual({'todelete': None, 'toadd': 'myval'},
                      msg.payload['meta_data'])
     msg = fake_notifier.NOTIFICATIONS[1]
     self.assertEqual('aggregate.updatemetadata.end', msg.event_type)
     self.assertEqual({'todelete': None, 'toadd': 'myval'},
                      msg.payload['meta_data'])
     self.assertEqual({'foo': 'bar', 'toadd': 'myval'}, agg.metadata)
예제 #27
0
파일: pool.py 프로젝트: vishvananda/nova
    def add_to_aggregate(self, context, aggregate, host, **kwargs):
        """Add a compute host to an aggregate."""
        if not pool_states.is_hv_pool(context, aggregate.id):
            return

        invalid = {
            pool_states.CHANGING: 'setup in progress',
            pool_states.DISMISSED: 'aggregate deleted',
            pool_states.ERROR: 'aggregate in error'
        }

        if (db.aggregate_metadata_get(context, aggregate.id)[pool_states.KEY]
                in invalid.keys()):
            raise exception.InvalidAggregateAction(
                action='add host',
                aggregate_id=aggregate.id,
                reason=invalid[db.aggregate_metadata_get(
                    context, aggregate.id)[pool_states.KEY]])

        if (db.aggregate_metadata_get(
                context,
                aggregate.id)[pool_states.KEY] == pool_states.CREATED):
            db.aggregate_metadata_add(context, aggregate.id,
                                      {pool_states.KEY: pool_states.CHANGING})
        if len(aggregate.hosts) == 1:
            # this is the first host of the pool -> make it master
            self._init_pool(aggregate.id, aggregate.name)
            # save metadata so that we can find the master again
            metadata = {
                'master_compute': host,
                host: self._host_uuid,
                pool_states.KEY: pool_states.ACTIVE
            }
            db.aggregate_metadata_add(context, aggregate.id, metadata)
        else:
            # the pool is already up and running, we need to figure out
            # whether we can serve the request from this host or not.
            master_compute = db.aggregate_metadata_get(
                context, aggregate.id)['master_compute']
            if master_compute == FLAGS.host and master_compute != host:
                # this is the master ->  do a pool-join
                # To this aim, nova compute on the slave has to go down.
                # NOTE: it is assumed that ONLY nova compute is running now
                self._join_slave(aggregate.id, host,
                                 kwargs.get('compute_uuid'), kwargs.get('url'),
                                 kwargs.get('user'), kwargs.get('passwd'))
                metadata = {
                    host: kwargs.get('xenhost_uuid'),
                }
                db.aggregate_metadata_add(context, aggregate.id, metadata)
            elif master_compute and master_compute != host:
                # send rpc cast to master, asking to add the following
                # host with specified credentials.
                forward_request(context, "add_aggregate_host", master_compute,
                                aggregate.id, host, self._host_addr,
                                self._host_uuid)
예제 #28
0
파일: pool.py 프로젝트: Cerberus98/nova
    def add_to_aggregate(self, context, aggregate, host, slave_info=None):
        """Add a compute host to an aggregate."""
        if not self._is_hv_pool(context, aggregate.id):
            return

        invalid = {pool_states.CHANGING: 'setup in progress',
                   pool_states.DISMISSED: 'aggregate deleted',
                   pool_states.ERROR: 'aggregate in error'}

        if (self._get_metadata(context, aggregate.id)[pool_states.KEY]
                in invalid.keys()):
            raise exception.InvalidAggregateAction(
                    action='add host',
                    aggregate_id=aggregate.id,
                    reason=invalid[self._get_metadata(context,
                            aggregate.id)
                    [pool_states.KEY]])

        if (self._get_metadata(context, aggregate.id)[pool_states.KEY]
                == pool_states.CREATED):
            db.aggregate_metadata_add(context, aggregate.id,
                    {pool_states.KEY: pool_states.CHANGING})
        if len(aggregate.hosts) == 1:
            # this is the first host of the pool -> make it master
            self._init_pool(aggregate.id, aggregate.name)
            # save metadata so that we can find the master again
            metadata = {'master_compute': host,
                        host: self._host_uuid,
                        pool_states.KEY: pool_states.ACTIVE}
            db.aggregate_metadata_add(context, aggregate.id, metadata)
        else:
            # the pool is already up and running, we need to figure out
            # whether we can serve the request from this host or not.
            master_compute = self._get_metadata(context,
                    aggregate.id)['master_compute']
            if master_compute == FLAGS.host and master_compute != host:
                # this is the master ->  do a pool-join
                # To this aim, nova compute on the slave has to go down.
                # NOTE: it is assumed that ONLY nova compute is running now
                self._join_slave(aggregate.id, host,
                                 slave_info.get('compute_uuid'),
                                 slave_info.get('url'), slave_info.get('user'),
                                 slave_info.get('passwd'))
                metadata = {host: slave_info.get('xenhost_uuid'), }
                db.aggregate_metadata_add(context, aggregate.id, metadata)
            elif master_compute and master_compute != host:
                # send rpc cast to master, asking to add the following
                # host with specified credentials.
                slave_info = self._create_slave_info()

                self.compute_rpcapi.add_aggregate_host(
                    context, aggregate.id, host, master_compute, slave_info)
예제 #29
0
파일: fake.py 프로젝트: gajen/nova
 def aggregate_metadata_add(self, context, aggregate_id, metadata,
                            set_delete=False):
     return db.aggregate_metadata_add(context, aggregate_id, metadata,
                                      set_delete)