Skip to content

Commit

Permalink
tests: update the ftp source for integration test (#1169)
Browse files Browse the repository at this point in the history
kernel.org has just shut down the ftp server, so we need to use a different one.
To avoid this happening again, the test starts a local ftp server.

This adds python3-pyftpdlib to the autopkgtest dependencies.

LP: #1669541
  • Loading branch information
Leo Arias authored and Kyle Fazzari committed Mar 3, 2017
1 parent 71779b0 commit 0e9a20c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
1 change: 1 addition & 0 deletions debian/tests/control
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Depends: @,
python-flake8,
python3-fixtures,
python3-pexpect,
python3-pyftpdlib,
python3-testscenarios

Tests: snapstests
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/snaps/ftp-source/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ftp-source
version: 0.2.3
version: 0.1
summary: Test downloading files from ftp source
description: |
Make sure sources can be fetched from FTP servers.
Expand All @@ -9,6 +9,6 @@ grade: devel
confinement: devmode

parts:
libwnck:
ftp-part:
plugin: dump
source: ftp://ftp.kernel.org/pub/software/admin/A3Com/A3Com-0.2.3.tar.gz
source: ftp://localhost:2121/test.tar.gz
51 changes: 47 additions & 4 deletions integration_tests/test_dump_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,50 @@

import os
import fixtures
import tarfile
import threading

from pyftpdlib import (
authorizers,
handlers,
servers
)

from testtools.matchers import (
DirExists,
FileContains,
FileExists
)

import integration_tests


class FtpServerRunning(fixtures.Fixture):

def __init__(self, directory):
super().__init__()
self.directory = directory

def setUp(self):
super().setUp()
self._start_ftp_server()

def _start_ftp_server(self):
authorizer = authorizers.DummyAuthorizer()
authorizer.add_anonymous(self.directory)
handler = handlers.FTPHandler
handler.authorizer = authorizer
self.server = servers.FTPServer(('', 2121), handler)

server_thread = threading.Thread(target=self.server.serve_forever)
server_thread.start()
self.addCleanup(self._stop_ftp_server, server_thread)

def _stop_ftp_server(self, thread):
self.server.close_all()
thread.join()


class DumpPluginTestCase(integration_tests.TestCase):

def test_stage_dump_plugin(self):
Expand Down Expand Up @@ -65,10 +100,18 @@ def test_download_file_with_content_encoding_set(self):

def test_download_file_from_ftp_source(self):
"""Download a file from a FTP source, LP: #1602323"""
ftp_dir = os.path.join(self.path, 'ftp')
os.mkdir(ftp_dir)
ftp_server = FtpServerRunning(ftp_dir)
self.useFixture(ftp_server)

# This is needed since autopkgtest doesn't properly set it
if not os.getenv('ftp_proxy', None):
self.useFixture(fixtures.EnvironmentVariable(
'ftp_proxy', os.getenv('http_proxy', '')))
test_file_path = os.path.join(self.path, 'test')
with open(test_file_path, 'w') as test_file:
test_file.write('Hello ftp')
with tarfile.open(os.path.join(ftp_dir, 'test.tar.gz'), 'w:gz') as tar:
tar.add(test_file_path)

self.run_snapcraft('pull', 'ftp-source')
self.assertThat(
os.path.join(self.parts_dir, 'ftp-part', 'src', 'test'),
FileContains('Hello ftp'))
1 change: 1 addition & 0 deletions requirements-devel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ mccabe==0.5.2
requests_unixsocket==0.1.5
testscenarios==0.5.0
pexpect==4.2.0
pyftpdlib==1.4.0

0 comments on commit 0e9a20c

Please sign in to comment.