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
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"])
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
def _create_aggregate_with_hosts(context=context.get_admin_context(), values=_get_fake_aggr_values(), metadata=_get_fake_aggr_metadata(), hosts=_get_fake_aggr_hosts()): result = _create_aggregate(context=context, values=values, metadata=metadata) for host in hosts: db.aggregate_host_add(context, result.id, host) return result
def create_availability_zone(context, hosts): az = create_uuid() # Create a new host aggregate aggregate = db.aggregate_create(context, {'name': az}, metadata={'availability_zone': az}) for host in hosts: db.aggregate_host_add(context, aggregate['id'], host) return az
def test_aggregate_host_add_deleted(self): """Ensure we can add a host that was previously deleted.""" ctxt = context.get_admin_context() result = _create_aggregate_with_hosts(context=ctxt, metadata=None) host = _get_fake_aggr_hosts()[0] db.aggregate_host_delete(ctxt, result.id, host) db.aggregate_host_add(ctxt, result.id, host) expected = db.aggregate_host_get_all(ctxt, result.id) self.assertEqual(len(expected), 1)
def _create_aggregate_with_host(self, name='fake_aggregate', metadata=None, hosts=['host1']): values = {'name': name, 'availability_zone': 'fake_avail_zone', } result = db.aggregate_create(self.context.elevated(), values, metadata) for host in hosts: db.aggregate_host_add(self.context.elevated(), result.id, host) return result
def test_add_host(self): self.mox.StubOutWithMock(db, "aggregate_host_add") db.aggregate_host_add(self.context, 123, "bar").AndReturn({"host": "bar"}) self.mox.ReplayAll() agg = aggregate.Aggregate() agg.id = 123 agg.hosts = ["foo"] agg._context = self.context agg.add_host("bar") self.assertEqual(agg.hosts, ["foo", "bar"])
def add_host(self, host): if self.in_api: _host_add_to_db(self._context, self.id, host) else: db.aggregate_host_add(self._context, self.id, host) if self.hosts is None: self.hosts = [] self.hosts.append(host) self.obj_reset_changes(fields=['hosts'])
def test_add_host(self): self.mox.StubOutWithMock(db, 'aggregate_host_add') db.aggregate_host_add(self.context, 123, 'bar' ).AndReturn({'host': 'bar'}) self.mox.ReplayAll() agg = aggregate.Aggregate() agg.id = 123 agg.hosts = ['foo'] agg._context = self.context agg.add_host('bar') self.assertEqual(agg.hosts, ['foo', 'bar'])
def create_aggregate(context, db_id, in_api=True): if in_api: fake_aggregate = _get_fake_aggregate(db_id, in_api=False, result=False) aggregate_obj._aggregate_create_in_db(context, fake_aggregate, metadata=_get_fake_metadata(db_id)) for host in _get_fake_hosts(db_id): aggregate_obj._host_add_to_db(context, fake_aggregate['id'], host) else: fake_aggregate = _get_fake_aggregate(db_id, in_api=False, result=False) db.aggregate_create(context, fake_aggregate, metadata=_get_fake_metadata(db_id)) for host in _get_fake_hosts(db_id): db.aggregate_host_add(context, fake_aggregate['id'], host)
def test_create_instance_with_availability_zone(self): self.ext_mgr.extensions = {'os-availability-zone': 'fake'} 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/v2/fake/flavors/3' body = { 'server': { 'name': 'config_drive_test', 'imageRef': image_href, 'flavorRef': flavor_ref, 'metadata': { 'hello': 'world', 'open': 'stack', }, 'availability_zone': 'nova', }, } req = fakes.HTTPRequest.blank('/v2/fake/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(fakes.FAKE_UUID, server['id'])
def add_host(self, context, host): db.aggregate_host_add(context, self.id, host) if self.hosts is None: self.hosts = [] self.hosts.append(host) self.obj_reset_changes(fields=["hosts"])
def _add_to_aggregate(self, service, aggregate): return db.aggregate_host_add(self.context, aggregate["id"], service["host"])
def _add_to_aggregate(self, service, aggregate): return db.aggregate_host_add(self.context, aggregate['id'], service['host'])
def add_host(self, context, host): db.aggregate_host_add(context, self.id, host) if self.hosts is None: self.hosts = [] self.hosts.append(host) self.obj_reset_changes(fields=['hosts'])