Exemplo n.º 1
0
    def setUp(self):
        """
        Test to see if the pre-requisites for the image cache
        are working (python-sqlite3 installed)
        """
        if getattr(self, 'disable', False):
            return

        if not getattr(self, 'inited', False):
            try:
                import sqlite3
            except ImportError:
                self.inited = True
                self.disabled = True
                self.disabled_message = ("python-sqlite3 not installed.")
                return

        self.inited = True
        self.disabled = False
        self.cache_dir = os.path.join(
            "/", "tmp", "test.cache.%d" % random.randint(0, 1000000))
        self.conf = test_utils.TestConfigOpts({
            'image_cache_dir': self.cache_dir,
            'image_cache_driver': 'sqlite',
            'image_cache_max_size': 1024 * 5,
            'registry_host': '0.0.0.0',
            'registry_port': 9191
        })
        self.cache = image_cache.ImageCache(self.conf)
Exemplo n.º 2
0
 def setUp(self):
     """Establish a clean test environment"""
     self.stubs = stubout.StubOutForTesting()
     stubs.stub_out_filesystem_backend()
     self.orig_chunksize = ChunkedFile.CHUNKSIZE
     ChunkedFile.CHUNKSIZE = 10
     self.store = Store(test_utils.TestConfigOpts(FILESYSTEM_CONF))
Exemplo n.º 3
0
        def getresponse(self):
            conf = utils.TestConfigOpts({
                'verbose':
                VERBOSE,
                'debug':
                DEBUG,
                'bind_host':
                '0.0.0.0',
                'bind_port':
                '9999999',
                'registry_host':
                '0.0.0.0',
                'registry_port':
                '9191',
                'default_store':
                'file',
                'filesystem_store_datadir':
                FAKE_FILESYSTEM_ROOTDIR
            })
            api = version_negotiation.VersionNegotiationFilter(
                context.ContextMiddleware(router.API(conf), conf), conf)
            res = self.req.get_response(api)

            # httplib.Response has a read() method...fake it out
            def fake_reader():
                return res.body

            setattr(res, 'read', fake_reader)
            return res
Exemplo n.º 4
0
 def test_get_version_list(self):
     req = webob.Request.blank('/')
     req.accept = "application/json"
     conf = utils.TestConfigOpts({
         'bind_host': '0.0.0.0',
         'bind_port': 9292
     })
     res = req.get_response(versions.Controller(conf))
     self.assertEqual(res.status_int, 300)
     self.assertEqual(res.content_type, "application/json")
     results = json.loads(res.body)["versions"]
     expected = [{
         "id":
         "v1.1",
         "status":
         "CURRENT",
         "links": [{
             "rel": "self",
             "href": "http://0.0.0.0:9292/v1/"
         }]
     }, {
         "id":
         "v1.0",
         "status":
         "SUPPORTED",
         "links": [{
             "rel": "self",
             "href": "http://0.0.0.0:9292/v1/"
         }]
     }]
     self.assertEqual(results, expected)
Exemplo n.º 5
0
 def setUp(self):
     notify_kombu = common_utils.import_object(
                                     "tank.notifier.notify_kombu")
     notify_kombu.RabbitStrategy._send_message = self._send_message
     notify_kombu.RabbitStrategy.connect = lambda s: None
     self.called = False
     conf = utils.TestConfigOpts({"notifier_strategy": "rabbit"})
     self.notifier = notifier.Notifier(conf)
Exemplo n.º 6
0
    def test_http_delete_raise_error(self):
        uri = "https://netloc/path/to/file.tar.gz"
        loc = get_location_from_uri(uri)
        self.assertRaises(NotImplementedError, self.store.delete, loc)

        create_stores(utils.TestConfigOpts({}))
        self.assertRaises(exception.StoreDeleteNotSupported,
                          delete_from_backend, uri)
Exemplo n.º 7
0
 def setUp(self):
     super(TestClientRedirects, self).setUp()
     self.port_one = utils.get_unused_port()
     self.port_two = utils.get_unused_port()
     server_one = wsgi.Server()
     server_two = wsgi.Server()
     conf = utils.TestConfigOpts({'bind_host': '127.0.0.1'})
     server_one.start(RedirectTestApp("one"), conf, self.port_one)
     server_two.start(RedirectTestApp("two"), conf, self.port_two)
     self.client = client.BaseClient("127.0.0.1", self.port_one)
Exemplo n.º 8
0
 def test_walk_versions(self):
     """
     Walks all version scripts for each tested database, ensuring
     that there are no errors in the version scripts for each engine
     """
     for key, engine in self.engines.items():
         conf = utils.TestConfigOpts(
             {'sql_connection': TestMigrations.TEST_DATABASES[key]})
         conf.register_opt(cfg.StrOpt('sql_connection'))
         self._walk_versions(conf)
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
 def setUp(self):
     """Establish a clean test environment"""
     self.stubs = stubout.StubOutForTesting()
     stubs.stub_out_registry_and_store_server(self.stubs)
     stubs.stub_out_filesystem_backend()
     conf = test_utils.TestConfigOpts(CONF)
     self.adm_context = rcontext.RequestContext(is_admin=True)
     self.context = rcontext.RequestContext(is_admin=False)
     db_api.configure_db(conf)
     self.destroy_fixtures()
     self.create_fixtures()
Exemplo n.º 11
0
 def test_no_data_loss_2_to_3_to_2(self):
     """
     Here, we test that in the case when we moved a column "type" from the
     base images table to be records in the image_properties table, that
     we don't lose any data during the migration. Similarly, we test that
     on downgrade, we don't lose any data, as the records are moved from
     the image_properties table back into the base image table.
     """
     for key, engine in self.engines.items():
         conf = utils.TestConfigOpts(
             {'sql_connection': TestMigrations.TEST_DATABASES[key]})
         conf.register_opt(cfg.StrOpt('sql_connection'))
         self._no_data_loss_2_to_3_to_2(engine, conf)
Exemplo n.º 12
0
        def getresponse(self):
            sql_connection = os.environ.get('TANK_SQL_CONNECTION', "sqlite://")
            context_class = 'tank.registry.context.RequestContext'
            conf = utils.TestConfigOpts({
                'sql_connection': sql_connection,
                'verbose': VERBOSE,
                'debug': DEBUG
            })
            api = context.ContextMiddleware(rserver.API(conf),
                                            conf,
                                            context_class=context_class)
            res = self.req.get_response(api)

            # httplib.Response has a read() method...fake it out
            def fake_reader():
                return res.body

            setattr(res, 'read', fake_reader)
            return res
Exemplo n.º 13
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 = utils.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.store = Store(test_utils.TestConfigOpts(new_conf))
            location, size, checksum = self.store.add(expected_image_id,
                                                      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)
Exemplo n.º 14
0
    def setUp(self):
        """
        Test to see if the pre-requisites for the image cache
        are working (python-xattr installed and xattr support on the
        filesystem)
        """
        if getattr(self, 'disable', False):
            return

        self.cache_dir = os.path.join(
            "/", "tmp", "test.cache.%d" % random.randint(0, 1000000))
        utils.safe_mkdirs(self.cache_dir)

        if not getattr(self, 'inited', False):
            try:
                import xattr
            except ImportError:
                self.inited = True
                self.disabled = True
                self.disabled_message = ("python-xattr not installed.")
                return

        self.inited = True
        self.disabled = False
        self.conf = test_utils.TestConfigOpts({
            'image_cache_dir': self.cache_dir,
            'image_cache_driver': 'xattr',
            'image_cache_max_size': 1024 * 5,
            'registry_host': '0.0.0.0',
            'registry_port': 9191
        })
        self.cache = image_cache.ImageCache(self.conf)

        if not xattr_writes_supported(self.cache_dir):
            self.inited = True
            self.disabled = True
            self.disabled_message = ("filesystem does not support xattr")
            return
Exemplo n.º 15
0
 def test_cannot_create(self):
     conf = utils.TestConfigOpts({"notifier_strategy": "invalid_notifier"})
     self.assertRaises(exception.InvalidNotifierStrategy,
                       notifier.Notifier,
                       conf)
Exemplo n.º 16
0
 def setUp(self):
     conf = utils.TestConfigOpts({"notifier_strategy": "noop"})
     self.notifier = notifier.Notifier(conf)
Exemplo n.º 17
0
 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))
Exemplo n.º 18
0
 def setUp(self):
     conf = utils.TestConfigOpts({"notifier_strategy": "logging"})
     self.called = False
     self.logger = logging.getLogger("tank.notifier.logging_notifier")
     self.notifier = notifier.Notifier(conf)
Exemplo n.º 19
0
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import unittest

from tank.common import exception
import tank.store
import tank.store.location as location
import tank.store.http
import tank.store.filesystem
import tank.store.chase
import tank.store.s3
from tank.tests import utils

tank.store.create_stores(utils.TestConfigOpts({}))


class TestStoreLocation(unittest.TestCase):
    def test_get_location_from_uri_back_to_uri(self):
        """
        Test that for various URIs, the correct Location
        object can be contructed and then the original URI
        returned via the get_store_uri() method.
        """
        good_store_uris = [
            'https://*****:*****@example.com:80/images/some-id',
            'http://images.oracle.com/123456',
            'chase://*****:*****@authurl.com/container/obj-id',
            'chase+https://account:user:[email protected]/container/obj-id',
            's3://accesskey:[email protected]/bucket/key-id',