示例#1
0
 def test_destroy(self):
     self.mox.StubOutWithMock(db, 'aggregate_delete')
     db.aggregate_delete(self.context, 123)
     self.mox.ReplayAll()
     agg = aggregate.Aggregate(context=self.context)
     agg.id = 123
     agg.destroy()
示例#2
0
    def test_aggregate_host_add(self):
        aggregate_ref = self._setup_aggregate_with_host()

        self.assertTrue(any([host == 'bar'
                             for host in aggregate_ref['hosts']]))

        db.aggregate_delete(self.context.elevated(), aggregate_ref['id'])
示例#3
0
def migrate_aggregates(ctxt, count):
    main_db_ids = _get_main_db_aggregate_ids(ctxt, count)
    if not main_db_ids:
        return 0, 0

    count_all = len(main_db_ids)
    count_hit = 0

    for aggregate_id in main_db_ids:
        try:
            aggregate = Aggregate.get_by_id(ctxt, aggregate_id)
            remove = ['metadata', 'hosts']
            values = {field: getattr(aggregate, field)
                      for field in aggregate.fields if field not in remove}
            _aggregate_create_in_db(ctxt, values, metadata=aggregate.metadata)
            for host in aggregate.hosts:
                _host_add_to_db(ctxt, aggregate_id, host)
            count_hit += 1
            db.aggregate_delete(ctxt, aggregate.id)
        except exception.AggregateNotFound:
            LOG.warning(
                _LW('Aggregate id %(id)i disappeared during migration'),
                {'id': aggregate_id})
        except (exception.AggregateNameExists) as e:
            LOG.error(str(e))

    return count_all, count_hit
示例#4
0
    def test_aggregate_host_add(self):
        aggregate_ref = self._setup_aggregate_with_host()

        self.assertTrue(any([host == 'bar'
                             for host in aggregate_ref['hosts']]))

        db.aggregate_delete(self.context.elevated(), aggregate_ref['id'])
示例#5
0
 def test_destroy(self):
     self.mox.StubOutWithMock(db, 'aggregate_delete')
     db.aggregate_delete(self.context, 123)
     self.mox.ReplayAll()
     agg = aggregate.Aggregate()
     agg.id = 123
     agg.destroy(self.context)
示例#6
0
def migrate_aggregates(ctxt, count):
    main_db_ids = _get_main_db_aggregate_ids(ctxt, count)
    if not main_db_ids:
        return 0, 0

    count_all = len(main_db_ids)
    count_hit = 0

    for aggregate_id in main_db_ids:
        try:
            aggregate = Aggregate.get_by_id(ctxt, aggregate_id)
            remove = ['metadata', 'hosts']
            values = {
                field: getattr(aggregate, field)
                for field in aggregate.fields if field not in remove
            }
            _aggregate_create_in_db(ctxt, values, metadata=aggregate.metadata)
            for host in aggregate.hosts:
                _host_add_to_db(ctxt, aggregate_id, host)
            count_hit += 1
            db.aggregate_delete(ctxt, aggregate.id)
        except exception.AggregateNotFound:
            LOG.warning(
                _LW('Aggregate id %(id)i disappeared during migration'),
                {'id': aggregate_id})
        except (exception.AggregateNameExists) as e:
            LOG.error(six.text_type(e))

    return count_all, count_hit
示例#7
0
 def test_aggregate_delete(self):
     """Ensure we can delete an aggregate."""
     ctxt = context.get_admin_context()
     result = _create_aggregate(context=ctxt, metadata=None)
     db.aggregate_delete(ctxt, result['id'])
     expected = db.aggregate_get_all(ctxt, read_deleted='no')
     self.assertEqual(0, len(expected))
示例#8
0
 def test_aggregate_create_avoid_name_conflict(self):
     """Test we can avoid conflict on deleted aggregates."""
     r1 = _create_aggregate(metadata=None)
     db.aggregate_delete(context.get_admin_context(), r1.id)
     values = {'name': r1.name, 'availability_zone': 'new_zone'}
     r2 = _create_aggregate(values=values)
     self.assertEqual(r2.name, values['name'])
     self.assertEqual(r2.availability_zone, values['availability_zone'])
示例#9
0
 def test_aggregate_delete(self):
     """Ensure we can delete an aggregate."""
     ctxt = context.get_admin_context()
     result = _create_aggregate(context=ctxt, metadata=None)
     db.aggregate_delete(ctxt, result['id'])
     expected = db.aggregate_get_all(ctxt, read_deleted='no')
     self.assertEqual(0, len(expected))
     aggregate = db.aggregate_get(ctxt, result['id'], read_deleted='yes')
     self.assertEqual(aggregate["operational_state"], "dismissed")
示例#10
0
 def test_aggregate_create_avoid_name_conflict(self):
     """Test we can avoid conflict on deleted aggregates."""
     r1 = _create_aggregate(metadata=None)
     db.aggregate_delete(context.get_admin_context(), r1.id)
     values = {"name": r1.name, "availability_zone": "new_zone"}
     r2 = _create_aggregate(values=values)
     self.assertEqual(r2.name, values["name"])
     self.assertEqual(r2.availability_zone, values["availability_zone"])
     self.assertEqual(r2.operational_state, "created")
示例#11
0
文件: test_db_api.py 项目: altai/nova
 def test_aggregate_delete(self):
     """Ensure we can delete an aggregate."""
     ctxt = context.get_admin_context()
     result = _create_aggregate(context=ctxt, metadata=None)
     db.aggregate_delete(ctxt, result['id'])
     expected = db.aggregate_get_all(ctxt, read_deleted='no')
     self.assertEqual(0, len(expected))
     aggregate = db.aggregate_get(ctxt, result['id'], read_deleted='yes')
     self.assertEqual(aggregate["operational_state"], "dismissed")
示例#12
0
 def test_aggregate_delete(self):
     """Ensure we can delete an aggregate."""
     ctxt = context.get_admin_context()
     result = _create_aggregate(context=ctxt, metadata=None)
     db.aggregate_delete(ctxt, result["id"])
     expected = db.aggregate_get_all(ctxt)
     self.assertEqual(0, len(expected))
     aggregate = db.aggregate_get(ctxt.elevated(read_deleted="yes"), result["id"])
     self.assertEqual(aggregate.deleted, True)
示例#13
0
    def test_aggregate_host_delete(self):
        aggregate_ref = self._setup_aggregate_with_host()

        self.conductor.aggregate_host_delete(self.context, aggregate_ref, "bar")

        aggregate_ref = db.aggregate_get(self.context.elevated(), aggregate_ref["id"])

        self.assertFalse(any([host == "bar" for host in aggregate_ref["hosts"]]))

        db.aggregate_delete(self.context.elevated(), aggregate_ref["id"])
示例#14
0
文件: test_db_api.py 项目: hadib/nova
 def test_aggregate_create_delete_create_with_metadata(self):
     """Ensure aggregate metadata is deleted bug 1052479."""
     ctxt = context.get_admin_context()
     result = _create_aggregate(context=ctxt)
     expected_metadata = db.aggregate_metadata_get(ctxt, result['id'])
     self.assertDictMatch(expected_metadata, _get_fake_aggr_metadata())
     db.aggregate_delete(ctxt, result['id'])
     result = _create_aggregate(metadata=None)
     expected_metadata = db.aggregate_metadata_get(ctxt, result['id'])
     self.assertEqual(expected_metadata, {})
示例#15
0
    def test_aggregate_host_delete(self):
        aggregate_ref = self._setup_aggregate_with_host()

        self.conductor.aggregate_host_delete(self.context, aggregate_ref,
                                             'bar')

        aggregate_ref = db.aggregate_get(self.context.elevated(),
                                         aggregate_ref['id'])

        self.assertFalse(
            any([host == 'bar' for host in aggregate_ref['hosts']]))

        db.aggregate_delete(self.context.elevated(), aggregate_ref['id'])
示例#16
0
    def test_aggregate_host_delete(self):
        aggregate_ref = self._setup_aggregate_with_host()

        self.conductor.aggregate_host_delete(self.context, aggregate_ref,
                'bar')

        aggregate_ref = db.aggregate_get(self.context.elevated(),
                aggregate_ref['id'])

        self.assertFalse(any([host == 'bar'
                              for host in aggregate_ref['hosts']]))

        db.aggregate_delete(self.context.elevated(), aggregate_ref['id'])
示例#17
0
 def test_aggregate_get_all_non_deleted(self):
     """Ensure we get only non-deleted aggregates."""
     ctxt = context.get_admin_context()
     add_counter = 5
     remove_counter = 2
     aggregates = []
     for c in xrange(1, add_counter):
         values = {"name": "fake_aggregate_%d" % c, "availability_zone": "fake_avail_zone"}
         aggregates.append(_create_aggregate(context=ctxt, values=values, metadata=None))
     for c in xrange(1, remove_counter):
         db.aggregate_delete(ctxt, aggregates[c - 1].id)
     results = db.aggregate_get_all(ctxt)
     self.assertEqual(len(results), add_counter - remove_counter)
示例#18
0
 def test_aggregate_get_all_non_deleted(self):
     """Ensure we get only non-deleted aggregates."""
     ctxt = context.get_admin_context()
     add_counter = 5
     remove_counter = 2
     aggregates = []
     for c in xrange(1, add_counter):
         values = {'name': 'fake_aggregate_%d' % c,
                   'availability_zone': 'fake_avail_zone'}
         aggregates.append(_create_aggregate(context=ctxt,
                                             values=values, metadata=None))
     for c in xrange(1, remove_counter):
         db.aggregate_delete(ctxt, aggregates[c - 1].id)
     results = db.aggregate_get_all(ctxt, read_deleted='no')
     self.assertEqual(len(results), add_counter - remove_counter)
示例#19
0
    def test_aggregate_host_add(self):
        aggregate_ref = self._setup_aggregate_with_host()

        self.assertTrue(any([host == "bar" for host in aggregate_ref["hosts"]]))

        db.aggregate_delete(self.context.elevated(), aggregate_ref["id"])
示例#20
0
 def destroy(self, context):
     db.aggregate_delete(context, self.id)
示例#21
0
 def tearDown(self):
     db.aggregate_delete(self.context, self.agg['id'])
     super(AvailabilityZoneTestCases, self).tearDown()
示例#22
0
 def destroy(self):
     db.aggregate_delete(self._context, self.id)
示例#23
0
 def test_aggregate_get(self):
     aggregate_ref = self._setup_aggregate_with_host()
     aggregate = self.conductor.aggregate_get(self.context,
                                              aggregate_ref['id'])
     self.assertEqual(jsonutils.to_primitive(aggregate_ref), aggregate)
     db.aggregate_delete(self.context.elevated(), aggregate_ref['id'])
示例#24
0
文件: aggregate.py 项目: gilmeir/nova
 def destroy(self, context):
     db.aggregate_delete(context, self.id)
示例#25
0
 def destroy(self):
     try:
         _aggregate_delete_from_db(self._context, self.id)
     except exception.AggregateNotFound:
         db.aggregate_delete(self._context, self.id)
示例#26
0
 def test_aggregate_get(self):
     aggregate_ref = self._setup_aggregate_with_host()
     aggregate = self.conductor.aggregate_get(self.context, aggregate_ref["id"])
     self.assertEqual(jsonutils.to_primitive(aggregate_ref), aggregate)
     db.aggregate_delete(self.context.elevated(), aggregate_ref["id"])
示例#27
0
文件: aggregate.py 项目: suneelb/nova
 def destroy(self):
     db.aggregate_delete(self._context, self.id)
示例#28
0
 def tearDown(self):
     db.aggregate_delete(self.context, self.agg['id'])
     super(AvailabilityZoneTestCases, self).tearDown()
示例#29
0
 def destroy(self):
     try:
         _aggregate_delete_from_db(self._context, self.id)
     except exception.AggregateNotFound:
         db.aggregate_delete(self._context, self.id)