Commit Graph

23 Commits

Author SHA1 Message Date
Dan Smith 6e62b872ef Add a check on startup for staging directory
If we have import methods enabled, we must have a staging directory
in order to complete those operations. This adds a startup check
for the staging directory with a warning log message if it is not
found.

Change-Id: Iac31d7f15ec6783a59b5e314883fb58f88fe2fd1
2023-03-13 19:45:36 +01:00
Stephen Finucane 67b531b143 Replace six.BytesIO, six.StringIO usage
Change-Id: I007da2ba19b4e18f7c4f64d1503a18815a3f8ce4
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2022-01-27 14:54:05 +00:00
Cyril Roelandt 0ca2f92161 Fix typos
Change-Id: I5e7776324c01e467799b1296c35b84dc0c10cce2
2021-10-13 03:02:52 +02:00
Dan Smith 16a5431c66 Make glance-api able to do async tasks in WSGI mode
This teaches glance-api how to do async threading things when it is
running in pure-WSGI mode. In order to do that, a refactoring of things
that currently depend on eventlet is required.

It adds a [wsgi]/task_pool_threads configuration knob, which is used
in the case of pure-WSGI and native threads to constrain the number
of threads in that pool (and thus the task parallelism). This will
allow tuning by the operator, but also lets us default that to just
a single thread in the backport of these fixes so that we can avoid
introducing a new larger footprint in the backport unexpectedly.

Partial-Bug: #1888713
Depends-On: https://review.opendev.org/#/c/742047/
Change-Id: Ie15028b75fb8518ec2b0c0c0386d21782166f759
2020-07-24 11:13:45 -07:00
Sean McGinnis 94b0876429 Use unittest.mock instead of third party mock
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.

Change-Id: I44e7b6f76e2d12f620ec602afc77ce11ba6b9d9a
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-04-20 15:07:00 +00:00
Abhishek Kekane 73fefddd96 Add periodic job to prefetch images into cache
Added new periodic job which will run as per interval set using
'cache_prefetcher_interval' configuration option and fetch images
which are queued for caching in cache directory.

DocImpact
Change-Id: If2875f7a215aca10a6ed2febc89b02219f90a10d
2019-09-10 15:01:58 +00:00
Charles Short 8954959817 Introduce ''mock_object'' method to base test class
We would like to fully remove mox from the test tree. Even for tests
that don't use mox's validation, many of them are using the symbol
patching with self.stubs.Set. We can do the same thing with the
monkeypatch fixture instead.

This introduces self.stub_out to nova/test.py and an example of what a
stubs => stub_out change would look like.

The teardown function in the converted test was removed at the same
time, as those should no longer be used.

Part of the mox community goal for Rocky.

Change-Id: I8f471ff8fee600ebb4e8907bf240007b7b4fe59f
Signed-off-by: Chuck Short <chucks@redhat.com>
2018-08-09 12:40:12 -04:00
zhangbailin 4a916d215b Replace mox with mock
Replace mox testing library by mock one in the file
glance/tests/unit/api/test_cmd.py

Change-Id: I2dde0ca59c4a80bd35c6c6b74c4d3231a97eaf74
partially-implements: blueprint replace-mox-with-mock
2018-08-07 14:22:44 +08:00
jiangpch 7edf7ff66d Refactor exception handling in cmd.api
Replace the known exception tuple with a map of exception classes
to error codes to preserve backward compatibility of exit codes.
Also change the code to handle unknown members of the Exception
hierarchy without breaking.

Co-authored-by: jiangpch <jiangpengcheng@navercorp.com>
Co-authored-by: Brian Rosmaita <rosmaita.fossdev@gmail.com>

Closes-Bug: #1726213

Change-Id: Iabfc2ded45a576a18bdb30a6c3ada8b9799a3196
2018-05-20 11:56:53 -04:00
ChangBo Guo(gcb) e1155a0a46 Remove test_unsupported_default_store
Config option 'default_store' in group 'glance_store' only allows value
in [file, filesystem, http, https, swift, swift+http, swift+https,
swift+config, rbd, sheepdog, cinder, vsphere] due to the parameter
choices, oslo.config will ensure that, other value will lead ValueError.
So don't need test this case.

Related-Bug: #1517839
Change-Id: I3459a8e9f07ed9464073133931fadc77f8186602
2017-04-28 23:38:53 +08:00
Louis Taylor 0acff569e0 Move to graduated oslo.log module
This removes the log module from the oslo incubator directory.

Change-Id: Ib017cc2777e27c58b376c3138c9fba614783cc34
2015-03-12 11:48:24 +00:00
abhishekkekane ea2252b4fd Zero downtime configuration reload
Add the ability to dynamically change configuration settings of a running
glance server with no impact to service.

A running glance server consists of a parent/master process and one or
more child/worker processes.

On receipt of a SIGHUP signal the master process will:

* reload the configuration
* send a SIGHUP to the original workers
* start (a potentially different number of) new workers with the new
  configuration
* its listening socket will *not* be closed

On receipt of a SIGHUP signal each original worker process will:

* close the listening socket so as not to accept new requests
* complete any in-flight requests
* complete async requests (V1 create with copy-from option and V2 task api)
* exit

This approach is based on nginx's behaviour and avoids some of the
disadvantages of the current oslo Launcher reload:

* Race conditions: Launcher does not shutdown eventlet cleanly, existing
  requests can fail.
* If all workers are busy (likely if #workers is small) there can be a
  lengthy delay when new requests are not processed.
* Long lived pre-SIGHUP idle client connections can stall request
  processing indefinitely.
* Not all parameters can be changed, eg number of workers.
* The wsgi pipeline cannot be changed, eg to enable caching.

Change-Id: I73875c654410f207e3efdb2932147cf26d75b3f1
Partially implements: bp sighup-conf-reload
2015-03-09 05:12:25 -07:00
Louis Taylor d759a6fd1a Move from oslo.config to oslo_config
oslo_config was moved out of the oslo namespace in oslo.config>=1.6.0.

Related-to: blueprint drop-namespace-packages

Change-Id: I30ecbf8f9de77496fcb643c7ad9738d79ad359f0
2015-01-12 14:34:22 +00:00
liyingjun 2365a3fb5f Fix assertEqual arguments order
assertEqual method's arguments should be in ('expected', 'actual')
order.

Change-Id: I88b5b0558720a91236b62b6e4a3590901e817f85
Closes-bug: 1277104
2014-09-19 00:25:18 +08:00
Julien Danjou fadbef8511 hacking: upgrade to 0.9.x serie
Change-Id: I252758fd633662de9659a402c5e3d7e3ce1fae0f
2014-10-06 14:41:03 +02:00
Flavio Percoco f6e7992a68 Adopt glance.store library in Glance
This commits removes the old `store` package from glance and adopts the
usage of the new glance.store library. The library was designed to
preserve backwards compatibility as much as possible. In fact, most of
the changes in this patch are related to function args ordering and not
function renames or workflow changes.

Some changes that are worth mentioning:

1. Glance store doesn't rely on a global config object. All config
options must be explicitly registered.

2. All store operations now accepted an optional context. This is a
fallout from the context not being required in the `Store` constructor
anymore.

3. Store drivers are behind a private package called `_drivers` and
they're not suppose to be accessed directly. Instead, functions like
`get_store_from_scheme` should be used.

4. Stores are disabled by default

5. All the store specific options are under the `glance_store` group.

DocImpact:
The old store related configuration options have been moved under the
`glance_store` section. However, the old options will go through a
deprecation path. That is, they'll still be read from the `DEFAULT`
section to give deployers enough time to update their config files.

In k-2, the deprecated options will be completely obsolete.

Closes-bug: #1291848
Implements-blueprint: create-store-package

Change-Id: Iaacc70993ad5da292b93de42bbecda73d53b19fd
2014-09-08 15:48:36 +02:00
He Yongli 01903933db Use six.StringIO/BytesIO instead of StringIO.StringIO
to keep Python 3.x compatibility, use six.StringIO/BytesIO to
replace StringIO.StringIO

StringIO works for unicode
BytesIO works for bytes

Change-Id: I93e043c633e1de9e4dedcb0a313032403b6a70fb
Closes-Bug: #1280100
2014-02-26 09:06:33 +08:00
Vitaliy Kolosov 4408fa1b44 Tests added for glance/cmd/cache_pruner.py
Related to blueprint glance-cmd+unittests

Integration test test_cache_pruner_main added to cover
chain of calls between glance/cmd/cache_pruner.py and glance/image_cache
module.
Unit test test_cache_pruner_main_runtime_exception_handling added to
cover exception handling for main() method of cache_pruner.py

Change-Id: I7d7b182260a407aed1288a5d136e03cbe029523f
2014-01-21 18:24:25 +02:00
Dirk Mueller 40a70a97cf assertEquals is deprecated, use assertEqual instead
Change-Id: Ie67c4c84eb74d7ed27b3c6c253239aaa1aff4862
2013-12-11 22:18:20 +01:00
Vitaliy Kolosov 49a22971ca Tests added for glance/cmd/cache_cleaner.py
Integration test test_cache_cleaner_main added to cover
chain of calls between glance/cmd/cache_cleaner.py and glance/image_cache
module.
Unit test test_cache_cleaner_main_runtime_exception_handling added to
cover exception handling for main() method of cache_cleaner.py

Change-Id: Ic05f35dd3f0a93d4331ccb5e470cdb71d9eab605
2013-11-15 15:14:03 +02:00
Dirk Mueller 753885d3cd assertEquals is deprecated, use assertEqual
Also change to assertTrue/False where assertEqual(True,/False) was
used.

Change-Id: I9e592d9c40c3da61b5e7af7e7ad5247645249eff
2013-11-07 02:34:48 +01:00
Kui Shi de22b642f7 test failure induced by reading system config file
run run_tests.sh or tox to test the glance code, it will get
following failure:
test_get_bind_addr_default_value
test_get_path_non_exist

Analysis
--------
The root cause is resided in "glance/tests/unit/api/test_cmd.py".
In TestGlanceApiCmd.setUp, the sys.argv is overrided to ['glance-api'].
Since sys.argv is "global" variable, and this test entry it run
firstly by nosetests while running tests in "glance/tests/unit"(since
nosetests search test items alphabetically), the other test entries
will inherit the sys.argv value ['glance-api']. Finally the system
config file "/etc/glance/glance-api.conf" is read in "setUp" via
oslo.config.cfg:ConfigOpts.__call__ -> _pre_setup -> find_config_files.
CONF.bind_port and CONF.bind_host is set to the value reading from
system config file: /etc/glance/glance-api.conf.

A simplied call backtrace:
TestGlanceApiCmd.setUp -->  sys.argv = ['glance-api']
 ->JSONRequestDeserializerTest.setUp
  ->glance/common/config.py:parse_args
   ->oslo.config.cfg:ConfigOpts.__call__
    ->CONF.bind_port CONF.bind_host is set

wsgi.get_bind_addr() will read the CONF.bind_port and CONF.bind_host
to return value. if system config file is not read, CONF.bind_host
is set to "0.0.0.0", CONF.bind_port is not set. wsgi.get_bind_addr()
will return the expected value. This is the reason that individual
test of test_get_bind_addr_default_value got passed, but failed while
testing all.

The failure of test_get_path_non_exist is induced by same reason.

Test case should clear up the setting in tearDown(), especially the
"global" setting, e.g. sys.argv.

Solution
--------
The solution is simple:
In class TestGlanceApiCmd, add a private variable to backup the
sys.argv in setUp(), and restore it in tearDown().

Test method
-----------
$ ./run_tests.sh

$ tox -evenv -- nosetests \
--tests=glance.tests.unit.common.test_config:TestPasteApp

tox -evenv -- nosetests
--tests=glance.tests.unit.common.test_wsgi:JSONRequestDeserializerTest

Fixes Bug #1204186

Change-Id: I2dac8e506fa794d1faa9509258936d78e2f981d8
2013-08-24 16:23:51 +08:00
Mark J. Washenberger 2538660d79 Refactor unsupported default store testing
This change improves coverage while saving ~10 seconds per test run.

Part of bp:faster-better-stronger-functional-tests

Change-Id: Id4d68ccb223205f27bed0c1e9d3072b51310b979
2013-07-05 09:34:59 -07:00