Exemple #1
0
 def setUp(self):
     """Establish a clean test environment"""
     self.config(**S3_CONF)
     super(TestStore, self).setUp()
     self.stubs = stubout.StubOutForTesting()
     stub_out_s3(self.stubs)
     self.store = Store()
    def _option_required(self, key):
        conf = S3_CONF.copy()
        del conf[key]

        try:
            self.store = Store(test_utils.TestConfigOpts(conf))
            return self.store.add == self.store.add_disabled
        except:
            return False
        return False
    def _option_required(self, key):
        options = S3_OPTIONS.copy()
        del options[key]

        try:
            self.store = Store(options)
            return self.store.add == self.store.add_disabled
        except:
            return False
        return False
Exemple #4
0
    def _option_required(self, key):
        conf = S3_CONF.copy()
        conf[key] = None

        try:
            self.config(**conf)
            self.store = Store()
            return self.store.add == self.store.add_disabled
        except Exception:
            return False
        return False
    def test_add_host_variations(self):
        """
        Test that having http(s):// in the s3serviceurl in config
        options works as expected.
        """
        variations = [
            'http://localhost:80', 'http://localhost', 'http://localhost/v1',
            'http://localhost/v1/', 'https://localhost',
            'https://localhost:8080', 'https://localhost/v1',
            'https://localhost/v1/', 'localhost', 'localhost:8080/v1'
        ]
        i = 42
        for variation in variations:
            expected_image_id = i
            expected_s3_size = FIVE_KB
            expected_s3_contents = "*" * expected_s3_size
            expected_checksum = \
                    hashlib.md5(expected_s3_contents).hexdigest()
            new_options = S3_OPTIONS.copy()
            new_options['s3_store_host'] = variation
            expected_location = format_s3_location(
                new_options['s3_store_access_key'],
                new_options['s3_store_secret_key'],
                new_options['s3_store_host'], new_options['s3_store_bucket'],
                expected_image_id)
            image_s3 = StringIO.StringIO(expected_s3_contents)

            self.store = Store(new_options)
            location, size, checksum = self.store.add(i, image_s3,
                                                      expected_s3_size)

            self.assertEquals(expected_location, location)
            self.assertEquals(expected_s3_size, size)
            self.assertEquals(expected_checksum, checksum)

            loc = get_location_from_uri(expected_location)
            (new_image_s3, new_image_size) = self.store.get(loc)
            new_image_contents = new_image_s3.getvalue()
            new_image_s3_size = new_image_s3.len

            self.assertEquals(expected_s3_contents, new_image_contents)
            self.assertEquals(expected_s3_size, new_image_s3_size)
            i = i + 1
Exemple #6
0
    def test_add_host_variations(self):
        """
        Test that having http(s):// in the s3serviceurl in config
        options works as expected.
        """
        variations = [
            'http://localhost:80', 'http://localhost', 'http://localhost/v1',
            'http://localhost/v1/', 'https://localhost',
            'https://localhost:8080', 'https://localhost/v1',
            'https://localhost/v1/', 'localhost', 'localhost:8080/v1'
        ]
        for variation in variations:
            expected_image_id = uuidutils.generate_uuid()
            expected_s3_size = FIVE_KB
            expected_s3_contents = "*" * expected_s3_size
            expected_checksum = hashlib.md5(expected_s3_contents).hexdigest()
            new_conf = S3_CONF.copy()
            new_conf['s3_store_host'] = variation
            expected_location = format_s3_location(
                new_conf['s3_store_access_key'],
                new_conf['s3_store_secret_key'], new_conf['s3_store_host'],
                new_conf['s3_store_bucket'], expected_image_id)
            image_s3 = StringIO.StringIO(expected_s3_contents)

            self.config(**new_conf)
            self.store = Store()
            location, size, checksum, _ = self.store.add(
                expected_image_id, image_s3, expected_s3_size)

            self.assertEqual(expected_location, location)
            self.assertEqual(expected_s3_size, size)
            self.assertEqual(expected_checksum, checksum)

            loc = get_location_from_uri(expected_location)
            (new_image_s3, new_image_size) = self.store.get(loc)
            new_image_contents = new_image_s3.getvalue()
            new_image_s3_size = len(new_image_s3)

            self.assertEqual(expected_s3_contents, new_image_contents)
            self.assertEqual(expected_s3_size, new_image_s3_size)
 def setUp(self):
     """Establish a clean test environment"""
     self.stubs = stubout.StubOutForTesting()
     stub_out_s3(self.stubs)
     self.store = Store(test_utils.TestConfigOpts(S3_CONF))
 def setUp(self):
     """Establish a clean test environment"""
     self.stubs = stubout.StubOutForTesting()
     stub_out_s3(self.stubs)
     self.store = Store(S3_OPTIONS)