Пример #1
0
    def test_read_stored_checksum(self):
        with utils.tempdir() as tmpdir:
            fname = os.path.join(tmpdir, 'aaa')

            csum_input = 'fdghkfhkgjjksfdgjksjkghsdf'
            f = open('%s.sha1' % fname, 'w')
            f.write('%s\n' % csum_input)
            f.close()

            csum_output = imagecache.read_stored_checksum(fname)

            self.assertEquals(csum_input, csum_output)
Пример #2
0
    def test_read_stored_checksum(self):
        with utils.tempdir() as tmpdir:
            fname = os.path.join(tmpdir, 'aaa')

            csum_input = 'fdghkfhkgjjksfdgjksjkghsdf'
            f = open('%s.sha1' % fname, 'w')
            f.write('%s\n' % csum_input)
            f.close()

            csum_output = imagecache.read_stored_checksum(fname)

            self.assertEquals(csum_input, csum_output)
Пример #3
0
    def test_read_stored_checksum(self):
        with utils.tempdir() as tmpdir:
            self.flags(instances_path=tmpdir)
            self.flags(image_info_filename_pattern=("$instances_path/" "%(image)s.info"), group="libvirt")

            csum_input = '{"sha1": "fdghkfhkgjjksfdgjksjkghsdf"}\n'
            fname = os.path.join(tmpdir, "aaa")
            info_fname = imagecache.get_info_filename(fname)
            f = open(info_fname, "w")
            f.write(csum_input)
            f.close()

            csum_output = imagecache.read_stored_checksum(fname, timestamped=False)
            self.assertEqual(csum_input.rstrip(), '{"sha1": "%s"}' % csum_output)
Пример #4
0
    def test_read_stored_checksum_legacy_essex(self):
        with utils.tempdir() as tmpdir:
            self.flags(instances_path=tmpdir)
            self.flags(image_info_filename_pattern=('$instances_path/'
                                                    '%(image)s.info'))

            fname = os.path.join(tmpdir, 'aaa')
            old_fname = fname + '.sha1'
            f = open(old_fname, 'w')
            f.write('fdghkfhkgjjksfdgjksjkghsdf')
            f.close()

            csum_output = imagecache.read_stored_checksum(fname)
            self.assertEquals(csum_output, 'fdghkfhkgjjksfdgjksjkghsdf')
            self.assertFalse(os.path.exists(old_fname))
            self.assertTrue(os.path.exists(virtutils.get_info_filename(fname)))
Пример #5
0
    def test_read_stored_checksum(self):
        with utils.tempdir() as tmpdir:
            self.flags(instances_path=tmpdir)
            self.flags(image_info_filename_pattern=('$instances_path/'
                                                    '%(image)s.info'))

            csum_input = '{"sha1": "fdghkfhkgjjksfdgjksjkghsdf"}\n'
            fname = os.path.join(tmpdir, 'aaa')
            info_fname = virtutils.get_info_filename(fname)
            f = open(info_fname, 'w')
            f.write(csum_input)
            f.close()

            csum_output = imagecache.read_stored_checksum(fname)
            self.assertEquals(csum_input.rstrip(),
                              '{"sha1": "%s"}' % csum_output)
Пример #6
0
    def test_read_stored_checksum_legacy_essex(self):
        with utils.tempdir() as tmpdir:
            self.flags(instances_path=tmpdir)
            self.flags(image_info_filename_pattern=("$instances_path/" "%(image)s.info"), group="libvirt")

            fname = os.path.join(tmpdir, "aaa")
            old_fname = fname + ".sha1"
            f = open(old_fname, "w")
            f.write("fdghkfhkgjjksfdgjksjkghsdf")
            f.close()

            csum_output = imagecache.read_stored_checksum(fname, timestamped=False)
            self.assertEqual(csum_output, "fdghkfhkgjjksfdgjksjkghsdf")
            self.assertFalse(os.path.exists(old_fname))
            info_fname = imagecache.get_info_filename(fname)
            self.assertTrue(os.path.exists(info_fname))
Пример #7
0
    def test_read_stored_checksum(self):
        try:
            dirname = tempfile.mkdtemp()
            fname = os.path.join(dirname, 'aaa')

            csum_input = 'fdghkfhkgjjksfdgjksjkghsdf'
            f = open('%s.sha1' % fname, 'w')
            f.write('%s\n' % csum_input)
            f.close()

            csum_output = imagecache.read_stored_checksum(fname)

            self.assertEquals(csum_input, csum_output)

        finally:
            shutil.rmtree(dirname)
    def test_read_stored_checksum(self):
        with utils.tempdir() as tmpdir:
            self.flags(instances_path=tmpdir)
            self.flags(image_info_filename_pattern=('$instances_path/'
                                                    '%(image)s.sha1'))

            fname = os.path.join(tmpdir, 'aaa')

            csum_input = 'fdghkfhkgjjksfdgjksjkghsdf'
            f = open('%s.sha1' % fname, 'w')
            f.write('%s\n' % csum_input)
            f.close()

            csum_output = imagecache.read_stored_checksum(fname)

            self.assertEquals(csum_input, csum_output)
Пример #9
0
    def test_read_stored_checksum(self):
        with utils.tempdir() as tmpdir:
            self.flags(instances_path=tmpdir)
            self.flags(image_info_filename_pattern=('$instances_path/'
                                                    '%(image)s.info'))

            csum_input = '{"sha1": "fdghkfhkgjjksfdgjksjkghsdf"}\n'
            fname = os.path.join(tmpdir, 'aaa')
            info_fname = virtutils.get_info_filename(fname)
            f = open(info_fname, 'w')
            f.write(csum_input)
            f.close()

            csum_output = imagecache.read_stored_checksum(fname)
            self.assertEquals(csum_input.rstrip(),
                              '{"sha1": "%s"}' % csum_output)
Пример #10
0
    def test_read_stored_checksum_legacy_essex(self):
        with utils.tempdir() as tmpdir:
            self.flags(instances_path=tmpdir)
            self.flags(image_info_filename_pattern=('$instances_path/'
                                                    '%(image)s.info'))

            fname = os.path.join(tmpdir, 'aaa')
            old_fname = fname + '.sha1'
            f = open(old_fname, 'w')
            f.write('fdghkfhkgjjksfdgjksjkghsdf')
            f.close()

            csum_output = imagecache.read_stored_checksum(fname)
            self.assertEquals(csum_output, 'fdghkfhkgjjksfdgjksjkghsdf')
            self.assertFalse(os.path.exists(old_fname))
            self.assertTrue(os.path.exists(virtutils.get_info_filename(fname)))
Пример #11
0
    def test_read_stored_checksum(self):
        try:
            dirname = tempfile.mkdtemp()
            fname = os.path.join(dirname, "aaa")

            csum_input = "fdghkfhkgjjksfdgjksjkghsdf"
            f = open("%s.sha1" % fname, "w")
            f.write("%s\n" % csum_input)
            f.close()

            csum_output = imagecache.read_stored_checksum(fname)

            self.assertEquals(csum_input, csum_output)

        finally:
            shutil.rmtree(dirname)
Пример #12
0
    def test_read_stored_checksum(self):
        try:
            dirname = tempfile.mkdtemp()
            fname = os.path.join(dirname, 'aaa')

            csum_input = 'fdghkfhkgjjksfdgjksjkghsdf'
            f = open('%s.sha1' % fname, 'w')
            f.write('%s\n' % csum_input)
            f.close()

            csum_output = imagecache.read_stored_checksum(fname)

            self.assertEquals(csum_input, csum_output)

        finally:
            shutil.rmtree(dirname)
Пример #13
0
    def test_read_stored_checksum(self):
        with utils.tempdir() as tmpdir:
            self.flags(instances_path=tmpdir)
            self.flags(image_info_filename_pattern=('$instances_path/'
                                                    '%(image)s.info'),
                       group='libvirt')

            csum_input = '{"sha1": "fdghkfhkgjjksfdgjksjkghsdf"}\n'
            fname = os.path.join(tmpdir, 'aaa')
            info_fname = imagecache.get_info_filename(fname)
            f = open(info_fname, 'w')
            f.write(csum_input)
            f.close()

            csum_output = imagecache.read_stored_checksum(fname,
                                                          timestamped=False)
            self.assertEqual(csum_input.rstrip(),
                             '{{"sha1": "{0!s}"}}'.format(csum_output))
Пример #14
0
    def test_read_stored_checksum_missing(self):
        self.stubs.Set(os.path, 'exists', lambda x: False)

        csum = imagecache.read_stored_checksum('/tmp/foo')
        self.assertEquals(csum, None)
Пример #15
0
 def test_read_stored_checksum_missing(self):
     self.stubs.Set(os.path, 'exists', lambda x: False)
     csum = imagecache.read_stored_checksum('/tmp/foo', timestamped=False)
     self.assertIsNone(csum)
Пример #16
0
 def test_read_stored_checksum_missing(self):
     self.stubs.Set(os.path, 'exists', lambda x: False)
     csum = imagecache.read_stored_checksum('/tmp/foo', timestamped=False)
     self.assertEquals(csum, None)
Пример #17
0
    def test_read_stored_checksum_missing(self):
        self.stubs.Set(os.path, "exists", lambda x: False)

        csum = imagecache.read_stored_checksum("/tmp/foo")
        self.assertEquals(csum, None)
Пример #18
0
 def test_read_stored_checksum_missing(self):
     self.stubs.Set(os.path, "exists", lambda x: False)
     csum = imagecache.read_stored_checksum("/tmp/foo", timestamped=False)
     self.assertIsNone(csum)
Пример #19
0
 def test_read_stored_checksum_missing(self):
     self.stub_out('os.path.exists', lambda x: False)
     csum = imagecache.read_stored_checksum('/tmp/foo', timestamped=False)
     self.assertIsNone(csum)