diff options
author | Neil Williams <neil.williams@linaro.org> | 2018-09-11 15:55:25 +0100 |
---|---|---|
committer | Neil Williams <neil.williams@linaro.org> | 2018-09-11 15:56:23 +0100 |
commit | f4948855e386791eab71b3caaebcd3b55d32f7eb (patch) | |
tree | 8c0f956877ddcf1205b1604d06df39670e7bf261 | |
parent | 0b25c71bc5a3cb5c8c11021a6d8dc05f38a4e88d (diff) |
Check for download files ending with /
It isn't possible to download a directory as part of a
LAVA URL. Fail in validate() instead of waiting for a
later failure.
Signed-off-by: Neil Williams <neil.williams@linaro.org>
-rw-r--r-- | lava_dispatcher/actions/deploy/download.py | 2 | ||||
-rw-r--r-- | lava_dispatcher/test/sample_jobs/download_dir.yaml | 58 | ||||
-rw-r--r-- | lava_dispatcher/test/test_download.py | 21 |
3 files changed, 68 insertions, 13 deletions
diff --git a/lava_dispatcher/actions/deploy/download.py b/lava_dispatcher/actions/deploy/download.py index a3502c7ab..53682dd0a 100644 --- a/lava_dispatcher/actions/deploy/download.py +++ b/lava_dispatcher/actions/deploy/download.py @@ -177,6 +177,8 @@ class DownloadHandler(Action): # pylint: disable=too-many-instance-attributes archive = self.parameters[self.key].get('archive') overlay = self.parameters.get('overlay', False) fname, _ = self._url_to_fname_suffix(self.path, compression) + if fname.endswith('/'): + self.errors = "Cannot download a directory for %s" % self.key self.set_namespace_data(action='download-action', label=self.key, key='file', value=fname) self.set_namespace_data(action='download-action', label=self.key, key='compression', value=compression) diff --git a/lava_dispatcher/test/sample_jobs/download_dir.yaml b/lava_dispatcher/test/sample_jobs/download_dir.yaml new file mode 100644 index 000000000..8171fcdb9 --- /dev/null +++ b/lava_dispatcher/test/sample_jobs/download_dir.yaml @@ -0,0 +1,58 @@ +# Sample JOB definition for a u-boot job + +device_type: beaglebone-black + +job_name: uboot-pipeline +timeouts: + job: + minutes: 15 # timeout for the whole job (default: ??h) + action: + minutes: 5 # default timeout applied for each action; can be overriden in the action itself (default: ?h) + actions: + extract-nfsrootfs: + seconds: 90 +priority: medium +visibility: public + +# example old-style job: https://staging.validation.linaro.org/scheduler/job/113682/definition + +actions: + + # needs to be a list of hashes to retain the order + - deploy: + timeout: + minutes: 2 + to: tftp + kernel: + url: http://images.validation.linaro.org/functional-test-images/bbb/zImage + type: zimage + nfsrootfs: + # deliberate test of invalid directory in URL + url: http://images.validation.linaro.org/ + compression: xz + os: debian + dtb: + url: http://images.validation.linaro.org/functional-test-images/bbb/am335x-bone.dtb + + - boot: + method: u-boot + commands: nfs + prompts: + - 'linaro-test' + - 'root@debian:~#' + + - test: + failure_retry: 3 + name: kvm-basic-singlenode # is not present, use "test $N" + # only s, m & h are supported. + timeout: + minutes: 5 # uses install:deps, so takes longer than singlenode01 + definitions: + - repository: git://git.linaro.org/lava-team/lava-functional-tests.git + from: git + path: lava-test-shell/smoke-tests-basic.yaml + name: smoke-tests + - repository: http://git.linaro.org/lava-team/lava-functional-tests.git + from: git + path: lava-test-shell/single-node/singlenode03.yaml + name: singlenode-advanced diff --git a/lava_dispatcher/test/test_download.py b/lava_dispatcher/test/test_download.py index 5f1990708..4a045e9f9 100644 --- a/lava_dispatcher/test/test_download.py +++ b/lava_dispatcher/test/test_download.py @@ -28,23 +28,12 @@ from lava_dispatcher.actions.deploy import DeployAction from lava_dispatcher.test.utils import infrastructure_error_multi_paths -class DownloadFactory(Factory): # pylint: disable=too-few-public-methods - """ - Not Model based, this is not a Django factory. - Factory objects are dispatcher based classes, independent - of any database objects. - """ - - def create_download_job(self, filename): - return self.create_job('db410c-01.jinja2', filename) - - class TestDownloadDeploy(StdoutTestCase): # pylint: disable=too-many-public-methods def setUp(self): super().setUp() - self.factory = DownloadFactory() - self.job = self.factory.create_download_job('sample_jobs/download.yaml') + self.factory = Factory() + self.job = self.factory.create_job('db410c-01.jinja2', 'sample_jobs/download.yaml') def test_deploy_job(self): self.assertEqual(self.job.pipeline.job, self.job) @@ -67,3 +56,9 @@ class TestDownloadDeploy(StdoutTestCase): # pylint: disable=too-many-public-met self.fail(exc) for action in self.job.pipeline.actions: self.assertEqual([], action.errors) + + def test_directories(self): + job = self.factory.create_job('bbb-01.jinja2', 'sample_jobs/download_dir.yaml') + with self.assertRaises(JobError): + job.validate() + |