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)
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)
def test_aggregate_update_with_metadata(self): """Ensure an aggregate can be updated with metadata.""" ctxt = context.get_admin_context() result = _create_aggregate(context=ctxt, metadata=None) values = _get_fake_aggr_values() values['metadata'] = _get_fake_aggr_metadata() db.aggregate_update(ctxt, 1, values) expected = db.aggregate_metadata_get(ctxt, result.id) self.assertDictMatch(_get_fake_aggr_metadata(), expected)
def test_save(self): self.mox.StubOutWithMock(db, "aggregate_update") db.aggregate_update(self.context, 123, {"name": "baz"}).AndReturn(fake_aggregate) self.mox.ReplayAll() agg = aggregate.Aggregate(context=self.context) agg.id = 123 agg.name = "baz" agg.save() self.compare_obj(agg, fake_aggregate, subs=SUBS)
def test_aggregate_update_with_existing_metadata(self): """Ensure an aggregate can be updated with existing metadata.""" ctxt = context.get_admin_context() result = _create_aggregate(context=ctxt) values = _get_fake_aggr_values() values['metadata'] = _get_fake_aggr_metadata() values['metadata']['fake_key1'] = 'foo' db.aggregate_update(ctxt, 1, values) expected = db.aggregate_metadata_get(ctxt, result.id) self.assertDictMatch(values['metadata'], expected)
def test_save(self): self.mox.StubOutWithMock(db, 'aggregate_update') db.aggregate_update(self.context, 123, {'name': 'baz'}).AndReturn( fake_aggregate) self.mox.ReplayAll() agg = aggregate.Aggregate() agg.id = 123 agg.name = 'baz' agg.save(self.context) self.compare_obj(agg, fake_aggregate, subs=SUBS)
def test_save(self): self.mox.StubOutWithMock(db, 'aggregate_update') db.aggregate_update(self.context, 123, {'name': 'baz'}).AndReturn( fake_aggregate) self.mox.ReplayAll() agg = aggregate.Aggregate(context=self.context) agg.id = 123 agg.name = 'baz' agg.save() self.compare_obj(agg, fake_aggregate, subs=SUBS)
def test_aggregate_update(self): """Ensure an aggregate can be updated.""" ctxt = context.get_admin_context() result = _create_aggregate(context=ctxt, metadata=None) new_values = _get_fake_aggr_values() new_values["availability_zone"] = "different_avail_zone" updated = db.aggregate_update(ctxt, 1, new_values) self.assertNotEqual(result.availability_zone, updated.availability_zone)
def test_aggregate_update(self): """Ensure an aggregate can be updated.""" ctxt = context.get_admin_context() result = _create_aggregate(context=ctxt, metadata=None) new_values = _get_fake_aggr_values() new_values['availability_zone'] = 'different_avail_zone' updated = db.aggregate_update(ctxt, 1, new_values) self.assertNotEqual(result.availability_zone, updated.availability_zone)
def save(self, context): 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(context, "updateprop.start", payload) updates.pop("id", None) db_aggregate = db.aggregate_update(context, self.id, updates) compute_utils.notify_about_aggregate_update(context, "updateprop.end", payload) return self._from_db_object(context, self, db_aggregate)
def save(self, context): 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(context, "updateprop.start", payload) updates.pop('id', None) db_aggregate = db.aggregate_update(context, self.id, updates) compute_utils.notify_about_aggregate_update(context, "updateprop.end", payload) return self._from_db_object(context, self, db_aggregate)
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) try: db_aggregate = _aggregate_update_to_db(self._context, self.id, updates) except exception.AggregateNotFound: 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)
def _update_az(self, aggregate, az_name): metadata = {'availability_zone': az_name} db.aggregate_update(self.context, aggregate['id'], metadata)
def _update_az(self, aggregate, az_name): metadata = {"availability_zone": az_name} db.aggregate_update(self.context, aggregate["id"], metadata)