def test_message_gets_to_manager(self): serv = service.Service('test', 'test', 'test', 'karbor.tests.unit.test_service.FakeManager') serv.start() self.assertEqual('manager', serv.test_method())
def test_service_stop_waits_for_rpcserver(self, mock_db, mock_rpc): serv = service.Service(self.host, self.binary, self.topic, 'karbor.tests.unit.test_service.FakeManager') 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()
def test_report_state_manager_not_working(self): service_ref = { 'host': self.host, 'binary': self.binary, 'topic': self.topic, 'report_count': 0, 'id': 1 } with mock.patch('karbor.db') as mock_db: mock_db.service_get.return_value = service_ref serv = service.Service( self.host, self.binary, self.topic, 'karbor.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)
def test_report_state_disconnected_DBError(self): service_ref = { 'host': self.host, 'binary': self.binary, 'topic': self.topic, 'report_count': 0, '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, 'karbor.tests.unit.test_service.FakeManager') serv.start() serv.report_state() self.assertTrue(serv.model_disconnected) self.assertFalse(mock_db.service_update.called)