示例#1
0
 def test_delete_host(self):
     self.mox.StubOutWithMock(db, 'aggregate_host_delete')
     db.aggregate_host_delete(self.context, 123, 'foo')
     self.mox.ReplayAll()
     agg = aggregate.Aggregate()
     agg.id = 123
     agg.hosts = ['foo', 'bar']
     agg._context = self.context
     agg.delete_host('foo')
     self.assertEqual(agg.hosts, ['bar'])
示例#2
0
 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)
示例#3
0
 def test_create(self):
     self.mox.StubOutWithMock(db, 'aggregate_create')
     db.aggregate_create(self.context, {'name': 'foo'},
                         metadata={'one': 'two'}).AndReturn(fake_aggregate)
     self.mox.ReplayAll()
     agg = aggregate.Aggregate()
     agg.name = 'foo'
     agg.metadata = {'one': 'two'}
     agg.create(self.context)
     self.compare_obj(agg, fake_aggregate, subs=SUBS)
示例#4
0
 def test_recreate_fails(self):
     self.mox.StubOutWithMock(db, 'aggregate_create')
     db.aggregate_create(self.context, {'name': 'foo'},
                         metadata={'one': 'two'}).AndReturn(fake_aggregate)
     self.mox.ReplayAll()
     agg = aggregate.Aggregate(context=self.context)
     agg.name = 'foo'
     agg.metadata = {'one': 'two'}
     agg.create()
     self.assertRaises(exception.ObjectActionError, agg.create,
                       self.context)
示例#5
0
 def test_delete_host_api(self, mock_in_api, mock_host_delete_api,
                          mock_host_delete):
     mock_in_api.return_value = True
     agg = aggregate.Aggregate()
     agg.id = 123
     agg.hosts = ['foo', 'bar']
     agg._context = self.context
     agg.delete_host('foo')
     self.assertEqual(agg.hosts, ['bar'])
     mock_host_delete_api.assert_called_once_with(self.context, 123, 'foo')
     self.assertFalse(mock_host_delete.called)
示例#6
0
 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'])
示例#7
0
    def test_add_host(self, mock_host_add):
        mock_host_add.return_value = {'host': 'bar'}

        agg = aggregate.Aggregate()
        agg.id = 123
        agg.hosts = ['foo']
        agg._context = self.context
        agg.add_host('bar')
        self.assertEqual(agg.hosts, ['foo', 'bar'])

        mock_host_add.assert_called_once_with(self.context, 123, 'bar')
示例#8
0
    def test_save(self, mock_aggregate_update):
        mock_aggregate_update.return_value = fake_aggregate

        agg = aggregate.Aggregate(context=self.context)
        agg.id = 123
        agg.name = 'baz'
        agg.save()
        self.compare_obj(agg, fake_aggregate, subs=SUBS)

        mock_aggregate_update.aasert_called_once_with(self.context, 123,
                                                      {'name': 'baz'})
示例#9
0
 def test_save_to_cell(self, update_mock, api_update_mock):
     api_update_mock.side_effect = exception.AggregateNotFound(
         aggregate_id='foo')
     update_mock.return_value = fake_aggregate
     agg = aggregate.Aggregate(context=self.context)
     agg.id = 123
     agg.name = 'fake-aggregate'
     agg.save()
     self.compare_obj(agg, fake_aggregate, subs=SUBS)
     update_mock.assert_called_once_with(self.context, 123,
                                         {'name': 'fake-aggregate'})
     self.assertTrue(api_update_mock.called)
示例#10
0
    def test_recreate_fails(self, api_create_mock):
        api_create_mock.return_value = fake_aggregate
        agg = aggregate.Aggregate(context=self.context)
        agg.name = 'foo'
        agg.metadata = {'one': 'two'}
        agg.uuid = uuidsentinel.fake_agg
        agg.create()
        self.assertRaises(exception.ObjectActionError, agg.create)

        api_create_mock.assert_called_once_with(self.context,
            {'name': 'foo', 'uuid': uuidsentinel.fake_agg},
            metadata={'one': 'two'})
示例#11
0
    def test_save_to_api(self, api_update_mock):
        api_update_mock.return_value = fake_aggregate
        agg = aggregate.Aggregate(context=self.context)
        agg.id = 123
        agg.name = 'fake-api-aggregate'
        agg.save()
        self.compare_obj(agg, fake_aggregate, subs=SUBS)
        api_update_mock.assert_called_once_with(self.context, 123,
                                                {'name': 'fake-api-aggregate'})

        api_update_mock.assert_called_once_with(self.context, 123,
                                                {'name': 'fake-api-aggregate'})
示例#12
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)
示例#13
0
 def test_get_all_with_az(self, mock_get_by_key, mock_get_all):
     agg = aggregate.Aggregate(context=self.context)
     agg.name = 'foo'
     agg.metadata = {'availability_zone': 'test-az'}
     agg.create()
     agg.hosts = [fake_service['host']]
     mock_get_by_key.return_value = [agg]
     mock_get_all.return_value = [dict(fake_service, topic='compute')]
     services = service.ServiceList.get_all(self.context, set_zones=True)
     self.assertEqual(1, len(services))
     self.assertEqual('test-az', services[0].availability_zone)
     mock_get_all.assert_called_once_with(self.context, disabled=None)
     mock_get_by_key.assert_called_once_with(self.context,
                      'availability_zone', hosts=set(agg.hosts))
示例#14
0
    def test_create(self, api_create_mock):
        api_create_mock.return_value = fake_aggregate
        agg = aggregate.Aggregate(context=self.context)
        agg.name = 'foo'
        agg.metadata = {'one': 'two'}
        agg.uuid = uuidsentinel.fake_agg
        agg.create()
        api_create_mock.assert_called_once_with(
                self.context,
                {'name': 'foo', 'uuid': uuidsentinel.fake_agg},
                metadata={'one': 'two'})
        self.compare_obj(agg, fake_aggregate, subs=SUBS)

        api_create_mock.assert_called_once_with(self.context,
            {'name': 'foo', 'uuid': uuidsentinel.fake_agg},
            metadata={'one': 'two'})
示例#15
0
 def test_get_all_with_az(self):
     self.mox.StubOutWithMock(db, 'service_get_all')
     self.mox.StubOutWithMock(aggregate.AggregateList,
                              'get_by_metadata_key')
     db.service_get_all(self.context, disabled=None).AndReturn(
         [dict(fake_service, topic='compute')])
     agg = aggregate.Aggregate()
     agg.name = 'foo'
     agg.metadata = {'availability_zone': 'test-az'}
     agg.create(self.context)
     agg.hosts = [fake_service['host']]
     aggregate.AggregateList.get_by_metadata_key(self.context,
         'availability_zone', hosts=set(agg.hosts)).AndReturn([agg])
     self.mox.ReplayAll()
     services = service.ServiceList.get_all(self.context, set_zones=True)
     self.assertEqual(1, len(services))
     self.assertEqual('test-az', services[0].availability_zone)
示例#16
0
    def test_update_metadata_api(self, mock_obj_from_primitive, mock_notify,
                                 mock_api_metadata_add,
                                 mock_api_metadata_delete):
        fake_notifier.NOTIFICATIONS = []
        agg = aggregate.Aggregate()
        agg._context = self.context
        agg.id = 123
        agg.metadata = {'foo': 'bar'}
        agg.obj_reset_changes()
        mock_obj_from_primitive.return_value = agg

        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)
        mock_notify.assert_has_calls([
            mock.call(context=self.context,
                      aggregate=agg,
                      action='update_metadata',
                      phase='start'),
            mock.call(context=self.context,
                      aggregate=agg,
                      action='update_metadata',
                      phase='end')
        ])
        self.assertEqual({
            'todelete': None,
            'toadd': 'myval'
        }, msg.payload['meta_data'])
        self.assertEqual({'foo': 'bar', 'toadd': 'myval'}, agg.metadata)
        mock_api_metadata_delete.assert_called_once_with(
            self.context, 123, 'todelete')
        mock_api_metadata_add.assert_called_once_with(self.context, 123,
                                                      {'toadd': 'myval'})
        mock_api_metadata_delete.assert_called_once_with(
            self.context, 123, 'todelete')
        mock_api_metadata_add.assert_called_once_with(self.context, 123,
                                                      {'toadd': 'myval'})
示例#17
0
    def test_save_to_api(self, api_update_mock, mock_notify):
        api_update_mock.return_value = fake_aggregate
        agg = aggregate.Aggregate(context=self.context)
        agg.id = 123
        agg.name = 'fake-api-aggregate'
        agg.save()
        self.compare_obj(agg, fake_aggregate, subs=SUBS)
        api_update_mock.assert_called_once_with(self.context,
                                                123,
                                                {'name': 'fake-api-aggregate'})

        api_update_mock.assert_called_once_with(self.context,
            123, {'name': 'fake-api-aggregate'})

        mock_notify.assert_has_calls([
            mock.call(context=self.context,
                      aggregate=test.MatchType(aggregate.Aggregate),
                      action='update_prop', phase='start'),
            mock.call(context=self.context,
                      aggregate=test.MatchType(aggregate.Aggregate),
                      action='update_prop', phase='end')])
        self.assertEqual(2, mock_notify.call_count)
示例#18
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)
示例#19
0
    def test_update_metadata_api(self, mock_metadata_add, mock_metadata_delete,
                                 mock_api_metadata_add,
                                 mock_api_metadata_delete, mock_in_api):
        mock_in_api.return_value = True
        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)
        mock_api_metadata_delete.assert_called_once_with(
            self.context, 123, 'todelete')
        mock_api_metadata_add.assert_called_once_with(self.context, 123,
                                                      {'toadd': 'myval'})
        self.assertFalse(mock_metadata_add.called)
        self.assertFalse(mock_metadata_delete.called)

        mock_api_metadata_delete.assert_called_once_with(
            self.context, 123, 'todelete')
        mock_api_metadata_add.assert_called_once_with(self.context, 123,
                                                      {'toadd': 'myval'})
示例#20
0
 def test_create(self):
     new_agg = aggregate_obj.Aggregate(self.context)
     new_agg.name = 'new-aggregate'
     self.assertRaises(exception.ObjectActionError, new_agg.create)
示例#21
0
 def test_availability_zone(self):
     agg = aggregate.Aggregate()
     agg.metadata = {'availability_zone': 'foo'}
     self.assertEqual('foo', agg.availability_zone)
示例#22
0
 def test_create(self):
     new_agg = aggregate_obj.Aggregate(self.context)
     new_agg.name = 'new-aggregate'
     new_agg.create()
     result = aggregate_obj.Aggregate.get_by_id(self.context, new_agg.id)
     self.assertEqual(new_agg.name, result.name)
示例#23
0
 def test_save_and_create_no_hosts(self):
     agg = aggregate.Aggregate(context=self.context)
     agg.id = 123
     agg.hosts = ['foo', 'bar']
     self.assertRaises(exception.ObjectActionError, agg.create)
     self.assertRaises(exception.ObjectActionError, agg.save)
示例#24
0
 def test_destroy(self, api_delete_mock):
     agg = aggregate.Aggregate(context=self.context)
     agg.id = 123
     agg.destroy()
     api_delete_mock.assert_called_with(self.context, 123)
示例#25
0
    def test_destroy(self, mock_aggregate_delete):
        agg = aggregate.Aggregate(context=self.context)
        agg.id = 123
        agg.destroy()

        mock_aggregate_delete.assert_called_once_with(self.context, 123)