Exemplo n.º 1
0
    def test_report_state_newly_disconnected(self):
        host = 'foo'
        binary = 'bar'
        topic = 'test'
        service_create = {
            'host': host,
            'binary': binary,
            'topic': topic,
            'report_count': 0,
            'availability_zone': 'nova'
        }
        service_ref = {
            'host': host,
            'binary': binary,
            'topic': topic,
            'report_count': 0,
            'availability_zone': 'nova',
            'id': 1
        }

        service.db.service_get_by_args(mox.IgnoreArg(), host,
                                       binary).AndRaise(exception.NotFound())
        service.db.service_create(mox.IgnoreArg(),
                                  service_create).AndReturn(service_ref)
        service.db.service_get(mox.IgnoreArg(),
                               mox.IgnoreArg()).AndRaise(Exception())

        self.mox.ReplayAll()
        serv = service.Service(host, binary, topic,
                               'cinder.tests.test_service.FakeManager')
        serv.start()
        serv.report_state()
        self.assert_(serv.model_disconnected)
Exemplo n.º 2
0
    def test_service_stop_waits_for_timers(self, mock_db, mock_rpc,
                                           mock_loopcall, mock_periodic,
                                           mock_report):
        """Test that we wait for loopcalls only if stop succeeds."""
        serv = service.Service(
            self.host,
            self.binary,
            self.topic,
            'cinder.tests.unit.test_service.FakeManager',
            report_interval=5,
            periodic_interval=10,
        )

        # One of the loopcalls will raise an exception on stop
        mock_loopcall.side_effect = (
            mock.Mock(**{'stop.side_effect': Exception}),
            mock.Mock())

        serv.start()
        serv.stop()

        self.assertEqual(serv.timers, [])
        serv.wait()

        serv.rpcserver.start.assert_called_once_with()
        serv.rpcserver.stop.assert_called_once_with()
        serv.rpcserver.wait.assert_called_once_with()

        self.assertEqual(serv.timers, [])
Exemplo n.º 3
0
 def test_message_gets_to_manager(self):
     serv = service.Service('test',
                            'test',
                            'test',
                            'cinder.tests.unit.test_service.FakeManager')
     serv.start()
     self.assertEqual('manager', serv.test_method())
Exemplo n.º 4
0
    def test_service_stop_waits_for_timers(self, mock_db, mock_rpc,
                                           mock_loopcall, mock_periodic,
                                           mock_report):
        """Test that we wait for loopcalls only if stop succeeds."""
        serv = service.Service(
            self.host,
            self.binary,
            self.topic,
            'cinder.tests.unit.test_service.FakeManager',
            report_interval=5,
            periodic_interval=10,
        )

        # One of the loopcalls will raise an exception on stop
        mock_loopcall.side_effect = (mock.Mock(
            **{'stop.side_effect': Exception}), mock.Mock())

        serv.start()
        serv.stop()
        serv.wait()
        serv.rpcserver.start.assert_called_once_with()
        serv.rpcserver.stop.assert_called_once_with()
        serv.rpcserver.wait.assert_called_once_with()

        # The first loopcall will have failed on the stop call, so we will not
        # have waited for it to stop
        self.assertEqual(1, serv.timers[0].start.call_count)
        self.assertEqual(1, serv.timers[0].stop.call_count)
        self.assertFalse(serv.timers[0].wait.called)

        # We will wait for the second loopcall
        self.assertEqual(1, serv.timers[1].start.call_count)
        self.assertEqual(1, serv.timers[1].stop.call_count)
        self.assertEqual(1, serv.timers[1].wait.call_count)
Exemplo n.º 5
0
 def test_reset(self):
     serv = service.Service('test', 'test', 'test',
                            'cinder.tests.unit.test_service.FakeManager')
     serv.start()
     serv.reset()
     self.assertEqual({}, rpc.LAST_OBJ_VERSIONS)
     self.assertEqual({}, rpc.LAST_RPC_VERSIONS)
Exemplo n.º 6
0
    def test_report_state_newly_connected(self):
        service_ref = {'host': self.host,
                       'binary': self.binary,
                       'topic': self.topic,
                       'report_count': 0,
                       'availability_zone': 'nova',
                       'id': 1}
        with mock.patch.object(objects.service, 'db') as mock_db,\
                mock.patch('cinder.db.sqlalchemy.api.get_by_id') as get_by_id:
            mock_db.service_get_by_args.side_effect = exception.NotFound()
            mock_db.service_create.return_value = service_ref
            get_by_id.return_value = service_ref

            serv = service.Service(
                self.host,
                self.binary,
                self.topic,
                'cinder.tests.unit.test_service.FakeManager'
            )
            serv.start()
            serv.model_disconnected = True
            serv.report_state()

            self.assertFalse(serv.model_disconnected)
            self.assertTrue(mock_db.service_update.called)
Exemplo n.º 7
0
 def test_service_stop_waits_for_rpcserver(self, mock_db, mock_rpc):
     serv = service.Service(self.host, self.binary, self.topic,
                            'cinder.tests.unit.test_service.FakeManager')
     serv.start()
     serv.stop()
     serv.rpcserver.start.assert_called_once_with()
     serv.rpcserver.stop.assert_called_once_with()
     serv.rpcserver.wait.assert_called_once_with()
Exemplo n.º 8
0
    def test_report_state_newly_connected(self, get_by_id, service_update):
        get_by_id.return_value = self.service_ref

        serv = service.Service(self.host, self.binary, self.topic,
                               'cinder.tests.unit.test_service.FakeManager')
        serv.start()
        serv.model_disconnected = True
        serv.report_state()

        self.assertFalse(serv.model_disconnected)
        self.assertTrue(service_update.called)
Exemplo n.º 9
0
    def test_report_state_manager_not_working(self):
        with mock.patch('cinder.db') as mock_db:
            mock_db.service_get.return_value = self.service_ref

            serv = service.Service(
                self.host, self.binary, self.topic,
                'cinder.tests.unit.test_service.FakeManager')
            serv.manager.is_working = mock.Mock(return_value=False)
            serv.start()
            serv.report_state()

            serv.manager.is_working.assert_called_once_with()
            self.assertFalse(mock_db.service_update.called)
Exemplo n.º 10
0
    def test_report_state_disconnected_DBError(self, get_by_id, get_by_args):
        get_by_args.side_effect = exception.NotFound()
        get_by_id.side_effect = db_exc.DBError()
        with mock.patch.object(objects.service, 'db') as mock_db:
            mock_db.service_create.return_value = self.service_ref

            serv = service.Service(
                self.host, self.binary, self.topic,
                'cinder.tests.unit.test_service.FakeManager')
            serv.start()
            serv.report_state()
            self.assertTrue(serv.model_disconnected)
            self.assertFalse(mock_db.service_update.called)
Exemplo n.º 11
0
 def test_start_refresh_serivce_id(self):
     serv = service.Service('test', 'test', 'test',
                            'cinder.tests.unit.test_service.FakeManager')
     # records the original service id
     serv_id = serv.service_id
     self.assertEqual(serv.origin_service_id, service.Service.service_id)
     # update service id to other value
     service.Service.service_id = serv_id + 1
     # make sure the class attr service_id have been changed
     self.assertNotEqual(serv.origin_service_id, service.Service.service_id)
     # call start method
     serv.start()
     # After start, the service id is refreshed to original service_id
     self.assertEqual(serv_id, service.Service.service_id)
Exemplo n.º 12
0
    def test_service_stop_wait(self, mock_db, mock_rpc, mock_periodic,
                               mock_report):
        """Test that we wait for loopcalls only if stop succeeds."""
        serv = service.Service(
            self.host,
            self.binary,
            self.topic,
            'cinder.tests.unit.test_service.FakeManager',
            report_interval=5,
            periodic_interval=10,
        )

        serv.start()
        serv.stop()
        serv.wait()
        serv.rpcserver.start.assert_called_once_with()
        serv.rpcserver.stop.assert_called_once_with()
        serv.rpcserver.wait.assert_called_once_with()
Exemplo n.º 13
0
    def test_report_state_manager_not_working(self):
        service_ref = {
            'host': self.host,
            'binary': self.binary,
            'topic': self.topic,
            'report_count': 0,
            'availability_zone': 'nova',
            'id': 1
        }
        with mock.patch.object(service, 'db') as mock_db:
            mock_db.service_get.return_value = service_ref

            serv = service.Service(
                self.host, self.binary, self.topic,
                'cinder.tests.unit.test_service.FakeManager')
            serv.manager.is_working = mock.Mock(return_value=False)
            serv.start()
            serv.report_state()

            serv.manager.is_working.assert_called_once_with()
            self.assertFalse(mock_db.service_update.called)
Exemplo n.º 14
0
    def test_report_state_disconnected_DBError(self):
        service_ref = {
            'host': self.host,
            'binary': self.binary,
            'topic': self.topic,
            'report_count': 0,
            'availability_zone': 'nova',
            'id': 1
        }
        with mock.patch.object(service, 'db') as mock_db:
            mock_db.service_get_by_args.side_effect = exception.NotFound()
            mock_db.service_create.return_value = service_ref
            mock_db.service_get.side_effect = db_exc.DBError()

            serv = service.Service(
                self.host, self.binary, self.topic,
                'cinder.tests.unit.test_service.FakeManager')
            serv.start()
            serv.report_state()
            self.assertTrue(serv.model_disconnected)
            self.assertFalse(mock_db.service_update.called)