qa/cephadm.py: better check for cephadm download success
authorNathan Cutler <ncutler@suse.com>
Thu, 20 Feb 2020 11:12:56 +0000 (12:12 +0100)
committerNathan Cutler <ncutler@suse.com>
Thu, 20 Feb 2020 16:22:20 +0000 (17:22 +0100)
When the URL passed to "curl --silent ..." does not exist, the
resulting file will be populated with the string:

    404: Not Found

If that (or something similar) happens, the file size will be
suspiciously low, like < 1000 bytes. Fail the test immediately in this
case.

Signed-off-by: Nathan Cutler <ncutler@suse.com>
qa/tasks/cephadm.py

index 1dd6667526447ccc9c87ddac18cb8bc53f2640a2..f2499733165e8d1d893cec95a64f65c06ce1bac6 100644 (file)
@@ -100,12 +100,6 @@ def download_cephadm(ctx, config, ref):
                     'https://raw.githubusercontent.com/' + rest + '/' + ref + '/src/cephadm/cephadm',
                     run.Raw('>'),
                     ctx.cephadm,
-                    run.Raw('&&'),
-                    'test', '-s',
-                    ctx.cephadm,
-                    run.Raw('&&'),
-                    'chmod', '+x',
-                    ctx.cephadm,
                 ],
             )
         else:
@@ -119,14 +113,19 @@ def download_cephadm(ctx, config, ref):
                     'tar', '-xO', 'src/cephadm/cephadm',
                     run.Raw('>'),
                     ctx.cephadm,
-                    run.Raw('&&'),
-                    'test', '-s',
-                    ctx.cephadm,
-                    run.Raw('&&'),
-                    'chmod', '+x',
-                    ctx.cephadm,
                 ],
             )
+        # sanity-check the resulting file and set executable bit
+        cephadm_file_size = '$(stat -c%s {})'.format(ctx.cephadm)
+        ctx.cluster.run(
+            args=[
+                'test', '-s', ctx.cephadm,
+                run.Raw('&&'),
+                'test', run.Raw(cephadm_file_size), "-gt", run.Raw('1000'),
+                run.Raw('&&'),
+                'chmod', '+x', ctx.cephadm,
+            ],
+        )
 
     try:
         yield