Reset cache on servce ipload and deletion

Resolve bug with wrong log in cmd.run

Change-Id: I434ec01c73d86bc5db78029a1cdfe471a61b54df
This commit is contained in:
Ekaterina Fedorova 2013-11-08 11:57:28 +04:00 committed by Gerrit Code Review
parent 0e234c1dd4
commit b46291d1e9
5 changed files with 14 additions and 31 deletions

View File

@ -3,6 +3,7 @@
host = 0.0.0.0
# Port the bind the server to
port = 8084
# Directory for cache, OS temp directory is used by default
#cache_dir =

View File

@ -17,23 +17,12 @@ import logging as log
CONF = cfg.CONF
def update_cache(data_type):
client = None
for client_type, client_data_types in CLIENTS_DICT.iteritems():
if data_type in client_data_types:
client = client_type
break
if not client:
abort(404)
cache_dir = os.path.join(CONF.cache_dir, client)
if not os.path.exists(cache_dir):
os.mkdir(cache_dir)
manifests = ManifestParser().parse()
archive_manager = Archiver()
existing_hash = archive_manager.get_existing_hash(cache_dir)
if existing_hash:
archive_manager.remove_existing_hash(cache_dir, existing_hash)
archive_manager.create(cache_dir, manifests, CLIENTS_DICT[client])
def reset_cache():
try:
shutil.rmtree(CONF.cache_dir, ignore_errors=True)
os.mkdir(CONF.cache_dir)
except:
return make_response('Unable to reset cache', 500)
def get_archive(client, hash_sum):
@ -107,7 +96,7 @@ def save_file(request, data_type, path=None, filename=None):
file_to_upload.save(path_to_file)
else:
return make_response('No file to upload', 400)
update_cache(data_type)
reset_cache()
return jsonify(result='success')
@ -192,6 +181,7 @@ def perform_deletion(files_for_deletion, manifest_for_deletion):
abort(500)
else:
release_backup(backup_dir)
reset_cache()
return jsonify(result='success')

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
import shutil
import tarfile
import tempfile
from flask import Blueprint, send_file
@ -74,10 +73,7 @@ def get_data_type_locations(data_type):
def upload_file(data_type):
api.check_data_type(data_type)
filename = request.args.get('filename')
try:
return api.save_file(request, data_type, path=None, filename=filename)
except:
abort(403)
return api.save_file(request, data_type, path=None, filename=filename)
@v1_api.route('/admin/<data_type>/<path:path>')
@ -171,6 +167,7 @@ def upload_new_service():
archive_manager = Archiver()
result = archive_manager.extract(path_to_archive)
if result:
api.reset_cache()
return jsonify(result='success')
else:
return make_response('Uploading file failed.', 400)
@ -212,9 +209,5 @@ def toggleEnabled(service_name):
@v1_api.route('/admin/reset_caches', methods=['POST'])
def reset_caches():
try:
shutil.rmtree(CONF.cache_dir, ignore_errors=True)
os.mkdir(CONF.cache_dir)
return jsonify(result='success')
except:
return make_response('Unable to perform operation', 500)
api.reset_cache()
return jsonify(result='success')

View File

@ -59,7 +59,7 @@ def main():
)
if not os.path.exists(cfg.CONF.cache_dir):
os.mkdir(cfg.CONF.cache_dir)
LOG.debug('Cache is located at: {0}'.format(cfg.CONF.cache_dir))
LOG.info('Cache is located at: {0}'.format(cfg.CONF.cache_dir))
app = server.make_app({
'auth_host': cfg.CONF.keystone.auth_host,

View File

@ -13,7 +13,6 @@
# under the License.
# List of data types should corresponds to sections in manifest files
import os
MANIFEST = 'manifests'
UI = 'ui'