Example #1
0
def main():
    try:
        config.parse_args()
        wsgi.set_eventlet_hub()
        log.setup('glance')

        glance_store.register_opts(config.CONF)
        glance_store.create_stores(config.CONF)
        glance_store.verify_default_store()

        if cfg.CONF.profiler.enabled:
            _notifier = osprofiler.notifier.create("Messaging",
                                                   notifier.messaging, {},
                                                   notifier.get_transport(),
                                                   "glance", "api",
                                                   cfg.CONF.bind_host)
            osprofiler.notifier.set(_notifier)
        else:
            osprofiler.web.disable()

        server = wsgi.Server()
        server.start(config.load_paste_app('glance-api'), default_port=9292)
        server.wait()
    except exception.WorkerCreationFailure as e:
        fail(2, e)
    except RuntimeError as e:
        fail(1, e)
Example #2
0
    def setUp(self):
        super(TestImportTask, self).setUp()
        self.task_factory = domain.TaskFactory()
        task_input = {
            "import_from": "http://cloud.foo/image.qcow2",
            "import_from_format": "qcow2",
            "image_properties": mock.sentinel.image_properties
        }
        task_ttl = CONF.task.task_time_to_live

        self.task_type = 'import'
        self.task = self.task_factory.new_task(self.task_type, TENANT1,
                                               task_time_to_live=task_ttl,
                                               task_input=task_input)

        self.context = mock.Mock()
        self.img_repo = mock.Mock()
        self.task_repo = mock.Mock()
        self.img_factory = mock.Mock()

        glance_store.register_opts(CONF)
        self.config(default_store='file',
                    stores=['file', 'http'],
                    filesystem_store_datadir=self.test_dir,
                    group="glance_store")
        glance_store.create_stores(CONF)
Example #3
0
def main():
    CONF.register_cli_opts(scrubber.scrubber_cmd_cli_opts)
    CONF.register_opts(scrubber.scrubber_cmd_opts)

    try:
        config.parse_args()
        log.setup('glance')

        glance_store.register_opts(config.CONF)
        glance_store.create_stores(config.CONF)
        glance_store.verify_default_store()

        app = scrubber.Scrubber(glance_store)

        if CONF.daemon:
            server = scrubber.Daemon(CONF.wakeup_time)
            server.start(app)
            systemd.notify_once()
            server.wait()
        else:
            import eventlet
            pool = eventlet.greenpool.GreenPool(1000)
            app.run(pool)
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)
Example #4
0
 def setUp(self):
     super(TestScrubber, self).setUp()
     glance_store.register_opts(CONF)
     self.config(group='glance_store', default_store='file',
                 filesystem_store_datadir=self.test_dir)
     glance_store.create_stores()
     self.mox = mox.Mox()
Example #5
0
    def setUp(self):
        super(TestImportTask, self).setUp()
        self.work_dir = os.path.join(self.test_dir, "work_dir")
        utils.safe_mkdirs(self.work_dir)
        self.config(work_dir=self.work_dir, group="task")

        self.context = mock.MagicMock()
        self.img_repo = mock.MagicMock()
        self.task_repo = mock.MagicMock()

        self.gateway = gateway.Gateway()
        self.task_factory = domain.TaskFactory()
        self.img_factory = self.gateway.get_image_factory(self.context)
        self.image = self.img_factory.new_image(image_id=UUID1, disk_format="raw", container_format="bare")

        task_input = {
            "import_from": "http://cloud.foo/image.raw",
            "import_from_format": "raw",
            "image_properties": {"disk_format": "qcow2", "container_format": "bare"},
        }
        task_ttl = CONF.task.task_time_to_live

        self.task_type = "import"
        self.task = self.task_factory.new_task(
            self.task_type, TENANT1, task_time_to_live=task_ttl, task_input=task_input
        )

        glance_store.register_opts(CONF)
        self.config(
            default_store="file", stores=["file", "http"], filesystem_store_datadir=self.test_dir, group="glance_store"
        )

        self.config(conversion_format="qcow2", group="taskflow_executor")
        glance_store.create_stores(CONF)
Example #6
0
    def __init__(self, driver_name, *args, **kwargs):
        super(Base, self).__init__(*args, **kwargs)
        self.driver_name = driver_name
        self.config = ConfigParser.RawConfigParser()
        self.config.read('functional_testing.conf')

        glance_store.register_opts(CONF)
Example #7
0
 def setUp(self):
     self.data_dir = tempfile.mkdtemp()
     self.config(scrubber_datadir=self.data_dir)
     glance_store.register_opts(CONF)
     glance_store.create_stores()
     self.config(group='glance_store', default_store='file')
     self.mox = mox.Mox()
     super(TestScrubber, self).setUp()
    def _setup_stores(self):
        glance_store.register_opts(CONF)

        image_dir = os.path.join(self.test_dir, "images")
        self.config(group='glance_store',
                    filesystem_store_datadir=image_dir)

        glance_store.create_stores()
Example #9
0
File: base.py Project: msrba/glance
    def _create_stores(self, passing_config=True):
        """Create known stores. Mock out sheepdog's subprocess dependency
        on collie.

        :param passing_config: making store driver passes basic configurations.
        :returns: the number of how many store drivers been loaded.
        """
        store.register_opts(CONF)
        store.create_stores(CONF)
Example #10
0
def main():
    # Used on Window, ensuring that a single scrubber can run at a time.
    mutex = None
    mutex_acquired = False

    try:
        if os.name == 'nt':
            # We can't rely on process names on Windows as there may be
            # wrappers with the same name.
            mutex = os_win_utilsfactory.get_mutex(
                name='Global\\glance-scrubber')
            mutex_acquired = mutex.acquire(timeout_ms=0)

        CONF.register_cli_opts(scrubber.scrubber_cmd_cli_opts)
        CONF.register_opts(scrubber.scrubber_cmd_opts)

        config.parse_args()
        logging.setup(CONF, 'glance')

        glance_store.register_opts(config.CONF)
        glance_store.create_stores(config.CONF)
        glance_store.verify_default_store()

        if CONF.restore and CONF.daemon:
            sys.exit("ERROR: The restore and daemon options should not be set "
                     "together. Please use either of them in one request.")

        app = scrubber.Scrubber(glance_store)

        if CONF.restore:
            if os.name == 'nt':
                scrubber_already_running = not mutex_acquired
            else:
                scrubber_already_running = scrubber_already_running_posix()

            if scrubber_already_running:
                already_running_msg = (
                    "ERROR: glance-scrubber is already running. "
                    "Please ensure that the daemon is stopped.")
                sys.exit(already_running_msg)

            app.revert_image_status(CONF.restore)
        elif CONF.daemon:
            server = scrubber.Daemon(CONF.wakeup_time)
            server.start(app)
            server.wait()
        else:
            app.run()
    except (exception.ImageNotFound, exception.Conflict) as e:
        sys.exit("ERROR: %s" % e)
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)
    finally:
        if mutex and mutex_acquired:
            mutex.release()
Example #11
0
    def setUp(self):
        super(StoreBaseTest, self).setUp()
        self.conf = self._CONF
        self.conf(args=[])
        store.register_opts(self.conf)

        # Ensure stores + locations cleared
        location.SCHEME_TO_CLS_MAP = {}

        store.create_stores(self.conf)
        self.addCleanup(setattr, location, 'SCHEME_TO_CLS_MAP', dict())
        self.test_dir = self.useFixture(fixtures.TempDir()).path
        self.addCleanup(self.conf.reset)
Example #12
0
def main():
    try:
        config.parse_cache_args()
        logging.setup(CONF, 'glance')

        glance_store.register_opts(config.CONF)
        glance_store.create_stores(config.CONF)
        glance_store.verify_default_store()

        app = prefetcher.Prefetcher()
        app.run()
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)
Example #13
0
    def _create_stores(self, passing_config=True):
        """Create known stores. Mock out sheepdog's subprocess dependency
        on collie.

        :param passing_config: making store driver passes basic configurations.
        :returns: the number of how many store drivers been loaded.
        """
        store.register_opts(CONF)

        self.config(default_store='filesystem',
                    filesystem_store_datadir=self.test_dir,
                    group="glance_store")

        store.create_stores(CONF)
Example #14
0
    def setUp(self):
        super(TestGlanceApiCmd, self).setUp()
        self.__argv_backup = sys.argv
        sys.argv = ['glance-api']
        self.stderr = six.StringIO()
        sys.stderr = self.stderr

        store.register_opts(CONF)

        self.mock_object(glance.common.config, 'load_paste_app',
                         self._do_nothing)
        self.mock_object(glance.common.wsgi.Server, 'start',
                         self._do_nothing)
        self.mock_object(glance.common.wsgi.Server, 'wait',
                         self._do_nothing)
 def setUp(self):
     super(TestImageMembersController, self).setUp()
     self.db = unit_test_utils.FakeDB()
     self.store = unit_test_utils.FakeStoreAPI()
     self.policy = unit_test_utils.FakePolicyEnforcer()
     self.notifier = unit_test_utils.FakeNotifier()
     self._create_images()
     self._create_image_members()
     self.controller = glance.api.v2.image_members.ImageMembersController(
         self.db,
         self.policy,
         self.notifier,
         self.store)
     glance_store.register_opts(CONF)
     glance_store.create_stores()
Example #16
0
def init_app():
    config_files = _get_config_files()
    CONF([], project='glance', default_config_files=config_files)
    logging.setup(CONF, "glance")

    if CONF.enabled_backends:
        glance_store.register_store_opts(CONF)
        glance_store.create_multi_stores(CONF)
        glance_store.verify_store()
    else:
        glance_store.register_opts(CONF)
        glance_store.create_stores(CONF)
        glance_store.verify_default_store()

    _setup_os_profiler()
    return config.load_paste_app('glance-api')
    def setUp(self):
        super(TestImageMembersController, self).setUp()
        self.db = unit_test_utils.FakeDB(initialize=False)
        self.store = unit_test_utils.FakeStoreAPI()
        self.policy = unit_test_utils.FakePolicyEnforcer()
        self.notifier = unit_test_utils.FakeNotifier()
        self._create_images()
        self._create_image_members()
        self.controller = glance.api.v2.image_members.ImageMembersController(
            self.db, self.policy, self.notifier, self.store
        )
        glance_store.register_opts(CONF)

        self.config(default_store="filesystem", filesystem_store_datadir=self.test_dir, group="glance_store")

        glance_store.create_stores()
Example #18
0
    def setUp(self):
        super(TestConvertImageTask, self).setUp()

        glance_store.register_opts(CONF)
        self.config(default_store='file',
                    stores=['file', 'http'],
                    filesystem_store_datadir=self.test_dir,
                    group="glance_store")
        self.config(output_format='qcow2',
                    group='image_conversion')
        glance_store.create_stores(CONF)

        self.work_dir = os.path.join(self.test_dir, 'work_dir')
        utils.safe_mkdirs(self.work_dir)
        self.config(work_dir=self.work_dir, group='task')

        self.context = mock.MagicMock()
        self.img_repo = mock.MagicMock()
        self.task_repo = mock.MagicMock()
        self.image_id = UUID1

        self.gateway = gateway.Gateway()
        self.task_factory = domain.TaskFactory()
        self.img_factory = self.gateway.get_image_factory(self.context)
        self.image = self.img_factory.new_image(image_id=self.image_id,
                                                disk_format='raw',
                                                container_format='bare')

        task_input = {
            "import_from": "http://cloud.foo/image.raw",
            "import_from_format": "raw",
            "image_properties": {'disk_format': 'raw',
                                 'container_format': 'bare'}
        }

        task_ttl = CONF.task.task_time_to_live

        self.task_type = 'import'
        self.task = self.task_factory.new_task(self.task_type, TENANT1,
                                               task_time_to_live=task_ttl,
                                               task_input=task_input)
Example #19
0
def main():
    CONF.register_cli_opts(scrubber.scrubber_cmd_cli_opts)
    CONF.register_opts(scrubber.scrubber_cmd_opts)

    try:
        config.parse_args()
        logging.setup(CONF, "glance")

        glance_store.register_opts(config.CONF)
        glance_store.create_stores(config.CONF)
        glance_store.verify_default_store()

        app = scrubber.Scrubber(glance_store)

        if CONF.daemon:
            server = scrubber.Daemon(CONF.wakeup_time)
            server.start(app)
            server.wait()
        else:
            app.run()
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)
    def setUp(self):
        super(TestTaskExecutor, self).setUp()

        glance_store.register_opts(CONF)
        self.config(default_store='file',
                    stores=['file', 'http'],
                    filesystem_store_datadir=self.test_dir,
                    group="glance_store")
        glance_store.create_stores(CONF)

        self.config(engine_mode='serial',
                    group='taskflow_executor')

        self.context = mock.Mock()
        self.task_repo = mock.Mock()
        self.image_repo = mock.Mock()
        self.image_factory = mock.Mock()

        task_input = {
            "import_from": "http://cloud.foo/image.qcow2",
            "import_from_format": "qcow2",
            "image_properties": {'disk_format': 'qcow2',
                                 'container_format': 'bare'}
        }
        task_ttl = CONF.task.task_time_to_live

        self.task_type = 'import'
        self.task_factory = domain.TaskFactory()
        self.task = self.task_factory.new_task(self.task_type, TENANT1,
                                               task_time_to_live=task_ttl,
                                               task_input=task_input)

        self.executor = taskflow_executor.TaskExecutor(
            self.context,
            self.task_repo,
            self.image_repo,
            self.image_factory)
Example #21
0
def main():
    CONF.register_cli_opt(
        cfg.BoolOpt(
            "daemon",
            short="D",
            default=False,
            help="Run as a long-running process. When not "
            "specified (the default) run the scrub operation "
            "once and then exits. When specified do not exit "
            "and run scrub on wakeup_time interval as "
            "specified in the config.",
        )
    )
    CONF.register_opt(cfg.IntOpt("wakeup_time", default=300))

    try:

        config.parse_args()
        log.setup("glance")

        glance_store.register_opts(config.CONF)
        glance_store.create_stores(config.CONF)
        glance_store.verify_default_store()

        app = scrubber.Scrubber(glance_store)

        if CONF.daemon:
            server = scrubber.Daemon(CONF.wakeup_time)
            server.start(app)
            server.wait()
        else:
            import eventlet

            pool = eventlet.greenpool.GreenPool(1000)
            app.run(pool)
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)
Example #22
0
def initialize_glance_store():
    """Initialize glance store."""
    glance_store.register_opts(CONF)
    glance_store.create_stores(CONF)
    glance_store.verify_default_store()
Example #23
0
    def __init__(self, driver_name, *args, **kwargs):
        super(Base, self).__init__(*args, **kwargs)
        self.driver_name = driver_name

        glance_store.register_opts(CONF)