Esempio n. 1
0
    def test_get_minimum_version(self, service_get_all):
        services_update = [
            {
                'rpc_current_version': '1.0',
                'object_current_version': '1.3'
            },
            {
                'rpc_current_version': '1.1',
                'object_current_version': '1.2'
            },
            {
                'rpc_current_version': '2.0',
                'object_current_version': '2.5'
            },
        ]
        expected = ('1.0', '1.2')
        services = [fake_service.fake_db_service(**s) for s in services_update]
        service_get_all.return_value = services

        min_rpc = objects.Service.get_minimum_rpc_version(self.context, 'foo')
        self.assertEqual(expected[0], min_rpc)
        min_obj = objects.Service.get_minimum_obj_version(self.context, 'foo')
        self.assertEqual(expected[1], min_obj)
        service_get_all.assert_has_calls(
            [mock.call(self.context, binary='foo', disabled=None)] * 2)
Esempio n. 2
0
 def test_create(self, service_create):
     db_service = fake_service.fake_db_service()
     service_create.return_value = db_service
     service = objects.Service(context=self.context)
     service.create()
     self.assertEqual(db_service['id'], service.id)
     service_create.assert_called_once_with(self.context, {})
Esempio n. 3
0
 def test_create(self, service_create):
     db_service = fake_service.fake_db_service()
     service_create.return_value = db_service
     service = objects.Service(context=self.context)
     service.create()
     self.assertEqual(db_service['id'], service.id)
     service_create.assert_called_once_with(self.context, {})
Esempio n. 4
0
 def test_destroy(self, service_destroy):
     db_service = fake_service.fake_db_service()
     service = objects.Service._from_db_object(
         self.context, objects.Service(), db_service)
     with mock.patch.object(service._context, 'elevated') as elevated_ctx:
         service.destroy()
         service_destroy.assert_called_once_with(elevated_ctx(), 123)
Esempio n. 5
0
 def test_get_by_args(self, service_get_by_args):
     db_service = fake_service.fake_db_service()
     service_get_by_args.return_value = db_service
     service = objects.Service.get_by_args(self.context, 'fake-host',
                                           'fake-key')
     self._compare(self, db_service, service)
     service_get_by_args.assert_called_once_with(self.context, 'fake-host',
                                                 'fake-key')
Esempio n. 6
0
    def test_get_all_by_binary(self, service_get_all):
        db_service = fake_service.fake_db_service()
        service_get_all.return_value = [db_service]

        services = objects.ServiceList.get_all_by_binary(self.context, "foo", "bar")
        service_get_all.assert_called_once_with(self.context, binary="foo", disabled="bar")
        self.assertEqual(1, len(services))
        TestService._compare(self, db_service, services[0])
Esempio n. 7
0
    def test_get_all(self, service_get_all):
        db_service = fake_service.fake_db_service()
        service_get_all.return_value = [db_service]

        services = objects.ServiceList.get_all(self.context, 'foo')
        service_get_all.assert_called_once_with(self.context, 'foo')
        self.assertEqual(1, len(services))
        TestService._compare(self, db_service, services[0])
Esempio n. 8
0
 def test_get_by_host_and_topic(self, service_get):
     db_service = fake_service.fake_db_service()
     service_get.return_value = db_service
     service = objects.Service.get_by_host_and_topic(
         self.context, 'fake-host', 'fake-topic')
     self._compare(self, db_service, service)
     service_get.assert_called_once_with(
         self.context, disabled=False, host='fake-host', topic='fake-topic')
Esempio n. 9
0
    def test_get_all(self, service_get_all):
        db_service = fake_service.fake_db_service()
        service_get_all.return_value = [db_service]

        services = objects.ServiceList.get_all(self.context, 'foo')
        service_get_all.assert_called_once_with(self.context, 'foo')
        self.assertEqual(1, len(services))
        TestService._compare(self, db_service, services[0])
Esempio n. 10
0
 def test_get_by_args(self, service_get):
     db_service = fake_service.fake_db_service()
     service_get.return_value = db_service
     service = objects.Service.get_by_args(
         self.context, 'fake-host', 'fake-key')
     self._compare(self, db_service, service)
     service_get.assert_called_once_with(
         self.context, host='fake-host', binary='fake-key')
Esempio n. 11
0
 def test_save(self, service_update):
     db_service = fake_service.fake_db_service()
     service = objects.Service._from_db_object(
         self.context, objects.Service(), db_service)
     service.topic = 'foobar'
     service.save()
     service_update.assert_called_once_with(self.context, service.id,
                                            {'topic': 'foobar'})
 def test_save(self, service_update):
     db_service = fake_service.fake_db_service()
     service = objects.Service._from_db_object(
         self.context, objects.Service(), db_service)
     service.topic = 'foobar'
     service.save()
     service_update.assert_called_once_with(self.context, service.id,
                                            {'topic': 'foobar'})
Esempio n. 13
0
 def test_get_by_host_and_topic(self, service_get_by_host_and_topic):
     db_service = fake_service.fake_db_service()
     service_get_by_host_and_topic.return_value = db_service
     service = objects.Service.get_by_host_and_topic(
         self.context, 'fake-host', 'fake-topic')
     self._compare(self, db_service, service)
     service_get_by_host_and_topic.assert_called_once_with(
         self.context, 'fake-host', 'fake-topic')
Esempio n. 14
0
 def test_destroy(self, service_destroy):
     db_service = fake_service.fake_db_service()
     service = objects.Service._from_db_object(self.context,
                                               objects.Service(),
                                               db_service)
     with mock.patch.object(service._context, 'elevated') as elevated_ctx:
         service.destroy()
         service_destroy.assert_called_once_with(elevated_ctx(), 123)
Esempio n. 15
0
    def _test_get_minimum_version(self, services_update, expected, service_get_all):
        services = [fake_service.fake_db_service(**s) for s in services_update]
        service_get_all.return_value = services

        min_rpc = objects.Service.get_minimum_rpc_version(self.context, "foo")
        self.assertEqual(expected[0], min_rpc)
        min_obj = objects.Service.get_minimum_obj_version(self.context, "foo")
        self.assertEqual(expected[1], min_obj)
        service_get_all.assert_has_calls([mock.call(self.context, binary="foo", disabled=None)] * 2)
Esempio n. 16
0
    def test_get_all(self, service_get_all):
        db_service = fake_service.fake_db_service()
        service_get_all.return_value = [db_service]

        filters = {'host': 'host', 'binary': 'foo', 'disabled': False}
        services = objects.ServiceList.get_all(self.context, filters)
        service_get_all.assert_called_once_with(self.context, **filters)
        self.assertEqual(1, len(services))
        TestService._compare(self, db_service, services[0])
Esempio n. 17
0
    def test_get_all(self, service_get_all):
        db_service = fake_service.fake_db_service()
        service_get_all.return_value = [db_service]

        filters = {'host': 'host', 'binary': 'foo', 'disabled': False}
        services = objects.ServiceList.get_all(self.context, filters)
        service_get_all.assert_called_once_with(self.context, **filters)
        self.assertEqual(1, len(services))
        TestService._compare(self, db_service, services[0])
Esempio n. 18
0
 def test_destroy(self, service_destroy, utcnow_mock):
     service_destroy.return_value = {"deleted": True, "deleted_at": utcnow_mock.return_value}
     db_service = fake_service.fake_db_service()
     service = objects.Service._from_db_object(self.context, objects.Service(), db_service)
     with mock.patch.object(service._context, "elevated") as elevated_ctx:
         service.destroy()
         service_destroy.assert_called_once_with(elevated_ctx(), 123)
     self.assertTrue(service.deleted)
     self.assertEqual(utcnow_mock.return_value.replace(tzinfo=pytz.UTC), service.deleted_at)
Esempio n. 19
0
    def test_get_all_by_topic(self, service_get_all_by_topic):
        db_service = fake_service.fake_db_service()
        service_get_all_by_topic.return_value = [db_service]

        services = objects.ServiceList.get_all_by_topic(
            self.context, 'foo', 'bar')
        service_get_all_by_topic.assert_called_once_with(
            self.context, 'foo', disabled='bar')
        self.assertEqual(1, len(services))
        TestService._compare(self, db_service, services[0])
Esempio n. 20
0
    def _test_get_minimum_version(self, services_update, expected,
                                  service_get_all_by_binary):
        services = [fake_service.fake_db_service(**s) for s in services_update]
        service_get_all_by_binary.return_value = services

        min_rpc = objects.Service.get_minimum_rpc_version(self.context, 'foo')
        self.assertEqual(expected[0], min_rpc)
        min_obj = objects.Service.get_minimum_obj_version(self.context, 'foo')
        self.assertEqual(expected[1], min_obj)
        service_get_all_by_binary.assert_has_calls(
            [mock.call(self.context, 'foo', disabled=None)] * 2)
Esempio n. 21
0
    def test_get_all_by_topic(self, service_get_all_by_topic):
        db_service = fake_service.fake_db_service()
        service_get_all_by_topic.return_value = [db_service]

        services = objects.ServiceList.get_all_by_topic(
            self.context, 'foo', 'bar')
        service_get_all_by_topic.assert_called_once_with(self.context,
                                                         'foo',
                                                         disabled='bar')
        self.assertEqual(1, len(services))
        TestService._compare(self, db_service, services[0])
Esempio n. 22
0
 def test_get_by_host_and_topic(self, show_disabled, service_get):
     db_service = fake_service.fake_db_service()
     service_get.return_value = db_service
     service = objects.Service.get_by_host_and_topic(self.context,
                                                     'fake-host',
                                                     'fake-topic',
                                                     disabled=show_disabled)
     self._compare(self, db_service, service)
     service_get.assert_called_once_with(self.context,
                                         disabled=show_disabled,
                                         host='fake-host',
                                         topic='fake-topic')
    def test_get_minimum_version_no_binary(self, service_get_all):
        services_update = [
            {'rpc_current_version': '1.0', 'object_current_version': '1.3'},
            {'rpc_current_version': '1.1', 'object_current_version': '1.2'},
            {'rpc_current_version': '2.0', 'object_current_version': '2.5'},
        ]
        services = [fake_service.fake_db_service(**s) for s in services_update]
        service_get_all.return_value = services

        min_obj = objects.Service.get_minimum_obj_version(self.context)
        self.assertEqual('1.2', min_obj)
        service_get_all.assert_called_once_with(self.context, binary=None,
                                                disabled=None)
Esempio n. 24
0
    def test_get_minimum_version_no_binary(self, service_get_all):
        services_update = [
            {'rpc_current_version': '1.0', 'object_current_version': '1.3'},
            {'rpc_current_version': '1.1', 'object_current_version': '1.2'},
            {'rpc_current_version': '2.0', 'object_current_version': '2.5'},
        ]
        services = [fake_service.fake_db_service(**s) for s in services_update]
        service_get_all.return_value = services

        min_obj = objects.Service.get_minimum_obj_version(self.context)
        self.assertEqual('1.2', min_obj)
        service_get_all.assert_called_once_with(self.context, binary=None,
                                                disabled=None)
 def test_destroy(self, service_destroy, utcnow_mock):
     service_destroy.return_value = {
         'deleted': True,
         'deleted_at': utcnow_mock.return_value}
     db_service = fake_service.fake_db_service()
     service = objects.Service._from_db_object(
         self.context, objects.Service(), db_service)
     with mock.patch.object(service._context, 'elevated') as elevated_ctx:
         service.destroy()
         service_destroy.assert_called_once_with(elevated_ctx(), 123)
     self.assertTrue(service.deleted)
     self.assertEqual(utcnow_mock.return_value.replace(tzinfo=pytz.UTC),
                      service.deleted_at)
    def test_get_minimum_version_liberty(self, service_get_all):
        services_update = [
            {'rpc_current_version': '1.0', 'object_current_version': '1.3'},
            {'rpc_current_version': '1.1', 'object_current_version': None},
            {'rpc_current_version': None, 'object_current_version': '2.5'},
        ]
        services = [fake_service.fake_db_service(**s) for s in services_update]
        service_get_all.return_value = services

        self.assertRaises(exception.ServiceTooOld,
                          objects.Service.get_minimum_rpc_version,
                          self.context, 'foo')
        self.assertRaises(exception.ServiceTooOld,
                          objects.Service.get_minimum_obj_version,
                          self.context, 'foo')
Esempio n. 27
0
    def test_get_minimum_version_liberty(self, service_get_all):
        services_update = [
            {'rpc_current_version': '1.0', 'object_current_version': '1.3'},
            {'rpc_current_version': '1.1', 'object_current_version': None},
            {'rpc_current_version': None, 'object_current_version': '2.5'},
        ]
        services = [fake_service.fake_db_service(**s) for s in services_update]
        service_get_all.return_value = services

        self.assertRaises(exception.ServiceTooOld,
                          objects.Service.get_minimum_rpc_version,
                          self.context, 'foo')
        self.assertRaises(exception.ServiceTooOld,
                          objects.Service.get_minimum_obj_version,
                          self.context, 'foo')
Esempio n. 28
0
    def test_get_minimum_version(self, service_get_all):
        services_update = [
            {'rpc_current_version': '1.0', 'object_current_version': '1.3'},
            {'rpc_current_version': '1.1', 'object_current_version': '1.2'},
            {'rpc_current_version': '2.0', 'object_current_version': '2.5'},
        ]
        expected = ('1.0', '1.2')
        services = [fake_service.fake_db_service(**s) for s in services_update]
        service_get_all.return_value = services

        min_rpc = objects.Service.get_minimum_rpc_version(self.context, 'foo')
        self.assertEqual(expected[0], min_rpc)
        min_obj = objects.Service.get_minimum_obj_version(self.context, 'foo')
        self.assertEqual(expected[1], min_obj)
        service_get_all.assert_has_calls(
            [mock.call(self.context, binary='foo', disabled=None)] * 2)
    def test_refresh(self, service_get):
        db_service1 = fake_service.fake_db_service()
        db_service2 = db_service1.copy()
        db_service2['availability_zone'] = 'foobar'

        # On the second service_get, return the service with an updated
        # availability_zone
        service_get.side_effect = [db_service1, db_service2]
        service = objects.Service.get_by_id(self.context, 123)
        self._compare(self, db_service1, service)

        # availability_zone was updated, so a service refresh should have a
        # new value for that field
        service.refresh()
        self._compare(self, db_service2, service)
        service_get.assert_has_calls([mock.call(self.context, 123),
                                      mock.call.__nonzero__(),
                                      mock.call(self.context, 123)])
Esempio n. 30
0
    def test_refresh(self, service_get):
        db_service1 = fake_service.fake_db_service()
        db_service2 = db_service1.copy()
        db_service2['availability_zone'] = 'foobar'

        # On the second service_get, return the service with an updated
        # availability_zone
        service_get.side_effect = [db_service1, db_service2]
        service = objects.Service.get_by_id(self.context, 123)
        self._compare(self, db_service1, service)

        # availability_zone was updated, so a service refresh should have a
        # new value for that field
        service.refresh()
        self._compare(self, db_service2, service)
        service_get.assert_has_calls([
            mock.call(self.context, 123),
            mock.call.__nonzero__(),
            mock.call(self.context, 123)
        ])
Esempio n. 31
0
 def test_get_by_id(self, service_get):
     db_service = fake_service.fake_db_service()
     service_get.return_value = db_service
     service = objects.Service.get_by_id(self.context, 1)
     self._compare(self, db_service, service)
     service_get.assert_called_once_with(self.context, 1)
Esempio n. 32
0
 def test_get_by_id(self, service_get):
     db_service = fake_service.fake_db_service()
     service_get.return_value = db_service
     service = objects.Service.get_by_id(self.context, 1)
     self._compare(self, db_service, service)
     service_get.assert_called_once_with(self.context, 1)