def test_is_task_in_smartstack(self): service = 'foo' nerve_ns = 'bar' fake_task = mock.Mock(host='foo', ports=[123456]) fake_backend = { "svname": "foo_256.256.256.256:123456", "status": "UP", } with mock.patch( 'paasta_tools.smartstack_tools.get_multiple_backends', autospec=True, return_value=[fake_backend], ): with mock.patch('socket.gethostbyname', autospec=True, return_value='256.256.256.256'): assert bounce_lib.is_task_in_smartstack(fake_task, service, nerve_ns, self.fake_system_paasta_config()) with mock.patch('paasta_tools.smartstack_tools.get_multiple_backends', autospec=True, return_value=[]): with mock.patch('socket.gethostbyname', autospec=True, return_value='256.256.256.256'): assert not bounce_lib.is_task_in_smartstack( fake_task, service, nerve_ns, self.fake_system_paasta_config(), ) with mock.patch( 'paasta_tools.bounce_lib.get_registered_marathon_tasks', autospec=True, side_effect=[[fake_task], [ConnectionError], [RequestException]], ): assert bounce_lib.is_task_in_smartstack(fake_task, service, nerve_ns, self.fake_system_paasta_config()) assert not bounce_lib.is_task_in_smartstack(fake_task, service, nerve_ns, self.fake_system_paasta_config()) assert not bounce_lib.is_task_in_smartstack(fake_task, service, nerve_ns, self.fake_system_paasta_config())
def test_is_task_in_smartstack(self): service = 'foo' nerve_ns = 'bar' fake_task = mock.Mock(host='foo', ports=[123456]) fake_backend = { "svname": "foo_256.256.256.256:123456", "status": "UP", } with mock.patch('paasta_tools.smartstack_tools.get_multiple_backends', autospec=True, return_value=[fake_backend]): with mock.patch('socket.gethostbyname', autospec=True, return_value='256.256.256.256'): assert bounce_lib.is_task_in_smartstack( fake_task, service, nerve_ns, self.fake_system_paasta_config()) with mock.patch('paasta_tools.smartstack_tools.get_multiple_backends', autospec=True, return_value=[]): with mock.patch('socket.gethostbyname', autospec=True, return_value='256.256.256.256'): assert not bounce_lib.is_task_in_smartstack( fake_task, service, nerve_ns, self.fake_system_paasta_config())