def test_glancing_metadata_bad_but_force(self): # Size & checksum mismatch: 375 MB -> 492 MB market_id = 'ME4iRTemHRwhABKV5AgrkQfDerA' mdfile = get_local_path('..', 'stratuslab', market_id + '.json') self.assertTrue(glancing.main(['-vf', '-n', test_name(), mdfile])) self.assertTrue(glance.glance_delete(test_name())) self.assertFalse(glancing.main(['-vf', '-n', test_name(), market_id]))
def test_glancing_metadata_bad_but_force(self): # Size & checksum mismatch: 375 MB -> 492 MB market_id = 'ME4iRTemHRwhABKV5AgrkQfDerA' mdfile = get_local_path('..', 'stratuslab', market_id + '.json') self.assertTrue(glancing.main(['-vf', '-n', test_name(), mdfile])) self.assertTrue(glance.glance_delete(test_name())) self.assertFalse(glancing.main(['-vf', '-n', test_name(), market_id]))
def test_glancing_file_dryrun_good_sum(self): self.assertTrue( glancing.main([ '-d', '-n', test_name(), self._CIRROS_FILE, '-S', self._CIRROS_MD5 ])) self.assertTrue( glancing.main([ '-d', '-n', test_name(), self._CIRROS_FILE, '-S', self._CIRROS_SHA1 ])) self.assertTrue( glancing.main([ '-d', '-n', test_name(), self._CIRROS_FILE, '-S', self._CIRROS_SHA1, '-S', self._CIRROS_MD5 ])) self.assertTrue( glancing.main([ '-d', '-n', test_name(), self._CIRROS_FILE, '-S', self._CIRROS_MD5, '-s', self._CIRROS_CHK ])) self.assertTrue( glancing.main([ '-d', '-n', test_name(), self._CIRROS_FILE, '-s', self._CIRROS_CHK, '-S', self._CIRROS_SHA1 ]))
def test_glancing_image_ttylinux(self): md5 = self._TTYLINUX_MD5 sha1 = '1b5229d5dad92bc7952553be01608af2180eafbe' sha512 = ('79556bc3a25e4555a6cd71afba8eae80eb6d5f23f16a84e6' + '017a54469034cf77ee7bcd74ac285c6ec42c25547b6963c1' + 'e7232d4fcca388a326f0ec3e7afb838e') self.assertTrue(glancing.main(['-d', self._TTYLINUX_FILE])) checksums_true = [ '', ':', ':::::', sha512, sha1 + ':' + md5, md5 + ':', ':' + md5 ] for chks in checksums_true: self.assertTrue( glancing.main(['-d', self._TTYLINUX_FILE, '-s', chks]), chks) checksums_false = [ 'a' + md5, 'a' + md5 + ':' + md5, md5[:12] + '0' + md5[13:], md5 + ':' + md5[:12] + '0' + md5[13:] ] for chks in checksums_false: self.assertFalse( glancing.main(['-d', self._TTYLINUX_FILE, '-s', chks]), chks)
def test_glancing_file_dryrun_good_sum(self): self.assertTrue(glancing.main(['-d', '-n', test_name(), self._CIRROS_FILE, '-S', self._CIRROS_MD5])) self.assertTrue(glancing.main(['-d', '-n', test_name(), self._CIRROS_FILE, '-S', self._CIRROS_SHA1])) self.assertTrue(glancing.main(['-d', '-n', test_name(), self._CIRROS_FILE, '-S', self._CIRROS_SHA1, '-S', self._CIRROS_MD5])) self.assertTrue(glancing.main(['-d', '-n', test_name(), self._CIRROS_FILE, '-S', self._CIRROS_MD5, '-s', self._CIRROS_CHK])) self.assertTrue(glancing.main(['-d', '-n', test_name(), self._CIRROS_FILE, '-s', self._CIRROS_CHK, '-S', self._CIRROS_SHA1]))
def test_glancing_metadata_cirros_import_no_cksum(self): # 12 MB mdfile = get_local_path('..', 'stratuslab', 'cirros_no_cksum.json') with devnull('stderr'): self.assertTrue( glancing.main(['-v', '-n', test_name(), mdfile, '-k']))
def test_glancing_image_devnull_sum_bad(self): sums = [ '### BAD CHECKSUM ###', '0' * 32, self._DEVNULL_MD5 + ':' + '0' * 32 ] for asum in sums: self.assertFalse(glancing.main(['-d', os.devnull, '-s', asum]))
def test_glancing_image_coreos(self): fn = 'coreos_production_qemu_image.img' imgfile = get_local_path('..', 'images', fn) chksumfile = get_local_path('..', 'images', 'coreos-MD5SUMS') with open(chksumfile, 'rb') as fin: md5 = fin.read(multihash.hash2len('md5')) self.assertTrue(glancing.main(['-v', '-d', imgfile, '-s', md5 + ':' + md5]))
def test_glancing_image_coreos(self): fn = 'coreos_production_qemu_image.img' imgfile = get_local_path('..', 'images', fn) chksumfile = get_local_path('..', 'images', 'coreos-MD5SUMS') with open(chksumfile, 'rb') as fin: md5 = fin.read(multihash.hash2len('md5')) self.assertTrue( glancing.main(['-v', '-d', imgfile, '-s', md5 + ':' + md5]))
def test_glancing_metadata_cern_cirros_import(self): # 12 MB mdfile = get_local_path('..', 'CERN', 'test_image_list') self.assertTrue( glancing.main([ '-v', '-n', test_name(), '-c', mdfile, '-k', "deadbabe-f00d-beef-cafe-b1ab1ab1a666" ]))
def upload_image(mpid, name, meta_file): '''Upload new image into glance registry, using metadata file content ''' vprint("Uploading new image: %s (%s)" % (mpid, name)) ret = glancing.main(['-v', '-n', name, meta_file]) # Invalidate glance image cache # TODO: maybe just add the new one global _GLANCE_IMAGES _GLANCE_IMAGES = None return ret
def upload_image(mpid, name, meta_file): '''Upload new image into glance registry, using metadata file content ''' vprint("Uploading new image: %s (%s)" % (mpid, name)) ret = glancing.main(['-v', '-n', name, meta_file]) # Invalidate glance image cache # TODO: maybe just add the new one global _GLANCE_IMAGES _GLANCE_IMAGES = None return ret
def test_glancing_metadata_heavies(self): market_ids = ( # 98 MB, size & checksum mismatch: 4 B -> 98 MB ('JcqGhHxmTRAEpHMmRF-xhSTM3TO', False, False, False), # 102 MB, does not exists any more on SL marketplace ('BtSKdXa2SvHlSVTvgFgivIYDq--', True, False, False), # 872 MB ('IzEOzeHK8-zpgSyAkhNiZujL4nZ', True, True, True), # Size & checksum mismatch: 375 MB -> 492 MB ('ME4iRTemHRwhABKV5AgrkQfDerA', False, False, False), ) for market_id, status_json, status_xml, status_market in market_ids: mdfile_base = get_local_path('..', 'stratuslab', market_id) self.assertEqual(status_json, glancing.main(['-d', mdfile_base + '.json']), mdfile_base + '.json') self.assertEqual(status_xml, glancing.main(['-d', mdfile_base + '.xml']), mdfile_base + '.xml') self.assertEqual(status_market, glancing.main(['-d', market_id]), market_id)
def test_glancing_metadata_heavies(self): market_ids = ( # 98 MB, size & checksum mismatch: 4 B -> 98 MB ('JcqGhHxmTRAEpHMmRF-xhSTM3TO', False, False, False), # 102 MB, does not exists any more on SL marketplace ('BtSKdXa2SvHlSVTvgFgivIYDq--', True, False, False), # 872 MB ('IzEOzeHK8-zpgSyAkhNiZujL4nZ', True, True, True), # Size & checksum mismatch: 375 MB -> 492 MB ('ME4iRTemHRwhABKV5AgrkQfDerA', False, False, False), ) for market_id, status_json, status_xml, status_market in market_ids: mdfile_base = get_local_path('..', 'stratuslab', market_id) self.assertEqual(status_json, glancing.main(['-d', mdfile_base + '.json']), mdfile_base + '.json') self.assertEqual(status_xml, glancing.main(['-d', mdfile_base + '.xml']), mdfile_base + '.xml') self.assertEqual(status_market, glancing.main(['-d', market_id]), market_id)
def test_glancing_image_ttylinux(self): md5 = self._TTYLINUX_MD5 sha1 = '1b5229d5dad92bc7952553be01608af2180eafbe' sha512 = ('79556bc3a25e4555a6cd71afba8eae80eb6d5f23f16a84e6' + '017a54469034cf77ee7bcd74ac285c6ec42c25547b6963c1' + 'e7232d4fcca388a326f0ec3e7afb838e') self.assertTrue(glancing.main(['-d', self._TTYLINUX_FILE])) checksums_true = ['', ':', ':::::', sha512, sha1 + ':' + md5, md5 + ':', ':' + md5] for chks in checksums_true: self.assertTrue(glancing.main(['-d', self._TTYLINUX_FILE, '-s', chks]), chks) checksums_false = ['a' + md5, 'a' + md5 + ':' + md5, md5[:12] + '0' + md5[13:], md5 + ':' + md5[:12] + '0' + md5[13:]] for chks in checksums_false: self.assertFalse(glancing.main(['-d', self._TTYLINUX_FILE, '-s', chks]), chks)
def test_glancing_url_notexistent(self): url = 'http://nulle.part.fr/nonexistent_file.txt' self.assertFalse(glancing.main(['-d', url]))
def test_glancing_url_md5(self): self.assertTrue(glancing.main(['-d', self._CIRROS_URL, '-s', self._CIRROS_MD5])) self.assertTrue(glancing.main(['-d', self._CIRROS_URL, '-S', self._CIRROS_SUM]))
def test_glancing_metadata_cirros_import_no_cksum(self): # 12 MB mdfile = get_local_path('..', 'stratuslab', 'cirros_no_cksum.json') with devnull('stderr'): self.assertTrue(glancing.main(['-v', '-n', test_name(), mdfile, '-k']))
def test_glancing_metadata_big(self): market_id = 'PIDt94ySjKEHKKvWrYijsZtclxU' mdfile = get_local_path('..', 'stratuslab', market_id + '.json') self.assertTrue(glancing.main(['-d', mdfile])) self.assertTrue(glancing.main(['-d', market_id]))
def test_glancing_image_devnull_sum_bad(self): sums = ['### BAD CHECKSUM ###', '0' * 32, self._DEVNULL_MD5 + ':' + '0' * 32] for asum in sums: self.assertFalse(glancing.main(['-d', os.devnull, '-s', asum]))
def test_glancing_url_notexistent(self): url = 'http://nulle.part.fr/nonexistent_file.txt' self.assertFalse(glancing.main(['-d', url]))
def test_glancing_main_glance_availabilityFail(self): with environ('PATH'): self.assertFalse(glancing.main([os.devnull]))
def test_glancing_url_import_good_sum(self): self.assertTrue(glancing.main(['-n', test_name(), self._CIRROS_URL, '-S', self._CIRROS_SUM]))
def test_glancing_url_import_good_md5(self): self.assertTrue( glancing.main( ['-n', test_name(), self._CIRROS_URL, '-s', self._CIRROS_MD5]))
def test_glancing_url_import_good_sum(self): self.assertTrue( glancing.main( ['-n', test_name(), self._CIRROS_URL, '-S', self._CIRROS_SUM]))
def test_glancing_url_import_no_md5(self): self.assertTrue(glancing.main(['-n', test_name(), self._CIRROS_URL]))
def test_glancing_url_import_bad_md5_but_force(self): self.assertTrue( glancing.main( ['-f', '-n', test_name(), self._CIRROS_URL, '-s', '0' * 32]))
def test_glancing_url_import_bad_md5(self): self.assertFalse( glancing.main( ['-n', test_name(), self._CIRROS_URL, '-s', '0' * 32]))
def test_glancing_url_import_bad_md5(self): self.assertFalse(glancing.main(['-n', test_name(), self._CIRROS_URL, '-s', '0' * 32]))
def test_glancing_main_glance_availabilityOK(self): self.assertTrue(glancing.main([os.devnull]))
def test_glancing_url_import_no_md5(self): self.assertTrue(glancing.main(['-n', test_name(), self._CIRROS_URL]))
def test_glancing_empty_cli_param(self): self.assertFalse(glancing.main([''])) self.assertFalse(glancing.main(['-d', '']))
def test_glancing_url_import_no_name(self): name, _ = os.path.splitext(os.path.basename(self._CIRROS_URL)) with cleanup(glance.glance_delete, name): self.assertTrue(glancing.main([self._CIRROS_URL]))
def test_glancing_image_notexistent(self): self.assertFalse(glancing.main(['-d', '/notexistent.txt']))
def test_glancing_url_notenough_param(self): with devnull('stderr'): with self.assertRaises(SystemExit): url = 'http://nulle.part.fr/nonexistent_file.txt' glancing.main(['-d', url, '-s'])
def test_glancing_image_notexistent_sum(self): self.assertFalse( glancing.main(['-d', '/notexistent.txt', '-s', '0' * 32]))
def test_glancing_image_import_name_bad_md5(self): self.assertFalse( glancing.main( ['-n', test_name(), self._TTYLINUX_FILE, '-s', '0' * 32]))
def test_glancing_image_devnull(self): self.assertTrue(glancing.main(['-d', os.devnull]))
def test_glancing_metadata_cirros_import_bad_size(self): # 12 MB mdfile = get_local_path('..', 'stratuslab', 'cirros_bad_size.json') with devnull('stderr'): self.assertFalse(glancing.main(['-v', '-n', test_name(), mdfile])) self.assertTrue(glancing.main(['-f', '-n', test_name(), mdfile]))
def test_glancing_image_notenough_param(self): with devnull('stderr'): with self.assertRaises(SystemExit): glancing.main(['-d', os.devnull, '-s'])
def test_glancing_url_notenough_param(self): with devnull('stderr'): with self.assertRaises(SystemExit): url = 'http://nulle.part.fr/nonexistent_file.txt' glancing.main(['-d', url, '-s'])
def test_glancing_url(self): self.assertTrue(glancing.main(['-d', self._CIRROS_URL]))
def test_glancing_url(self): self.assertTrue(glancing.main(['-d', self._CIRROS_URL]))
def test_glancing_metadata_cirros_import_bad_size(self): # 12 MB mdfile = get_local_path('..', 'stratuslab', 'cirros_bad_size.json') with devnull('stderr'): self.assertFalse(glancing.main(['-v', '-n', test_name(), mdfile])) self.assertTrue(glancing.main(['-f', '-n', test_name(), mdfile]))
def test_glancing_url_import_no_name(self): name, _ = os.path.splitext(os.path.basename(self._CIRROS_URL)) with cleanup(glance.glance_delete, name): self.assertTrue(glancing.main([self._CIRROS_URL]))
def test_glancing_main_glance_availabilityOK(self): self.assertTrue(glancing.main([os.devnull]))
def test_glancing_url_import_bad_md5_but_force(self): self.assertTrue(glancing.main(['-f', '-n', test_name(), self._CIRROS_URL, '-s', '0' * 32]))
def test_glancing_image_notexistent(self): self.assertFalse(glancing.main(['-d', '/notexistent.txt']))
def test_glancing_url_import_good_md5(self): self.assertTrue(glancing.main(['-n', test_name(), self._CIRROS_URL, '-s', self._CIRROS_MD5]))
def test_glancing_image_devnull(self): self.assertTrue(glancing.main(['-d', os.devnull]))
def test_glancing_main_glance_availabilityFail(self): with environ('PATH'): self.assertFalse(glancing.main([os.devnull]))
def test_glancing_url_md5(self): self.assertTrue( glancing.main(['-d', self._CIRROS_URL, '-s', self._CIRROS_MD5])) self.assertTrue( glancing.main(['-d', self._CIRROS_URL, '-S', self._CIRROS_SUM]))
def test_glancing_empty_cli_param(self): self.assertFalse(glancing.main([''])) self.assertFalse(glancing.main(['-d', '']))
def test_glancing_image_import_name_force(self): self.assertTrue( glancing.main( ['-f', '-n', test_name(), self._TTYLINUX_FILE, '-s', '0' * 32]))
def test_glancing_image_notexistent_sum(self): self.assertFalse(glancing.main(['-d', '/notexistent.txt', '-s', '0' * 32]))
def test_glancing_image_import_name_bad_md5(self): self.assertFalse(glancing.main(['-n', test_name(), self._TTYLINUX_FILE, '-s', '0' * 32]))
def test_glancing_image_notenough_param(self): with devnull('stderr'): with self.assertRaises(SystemExit): glancing.main(['-d', os.devnull, '-s'])
def test_glancing_image_import_name_force(self): self.assertTrue(glancing.main(['-f', '-n', test_name(), self._TTYLINUX_FILE, '-s', '0' * 32]))
def test_glancing_metadata_cern_cirros_import(self): # 12 MB mdfile = get_local_path('..', 'CERN', 'test_image_list') self.assertTrue(glancing.main(['-v', '-n', test_name(), '-c', mdfile, '-k', "deadbabe-f00d-beef-cafe-b1ab1ab1a666"]))
def test_glancing_metadata_big(self): market_id = 'PIDt94ySjKEHKKvWrYijsZtclxU' mdfile = get_local_path('..', 'stratuslab', market_id + '.json') self.assertTrue(glancing.main(['-d', mdfile])) self.assertTrue(glancing.main(['-d', market_id]))