Added cleanup_all_local_data, updated start
This commit is contained in:
parent
d9098f660a
commit
c05c49ae64
@ -124,6 +124,8 @@ def start():
|
||||
if not os.access(vm_path, os.F_OK):
|
||||
os.makedirs(vm_path)
|
||||
log.info('Created a local VM data directory: ' + vm_path)
|
||||
else:
|
||||
cleanup_all_local_data(vm_path)
|
||||
|
||||
log.info('Starting the data collector')
|
||||
return common.start(
|
||||
@ -330,6 +332,16 @@ def cleanup_local_data(path, vms):
|
||||
os.remove(os.path.join(path, vm))
|
||||
|
||||
|
||||
@contract
|
||||
def cleanup_all_local_data(path):
|
||||
""" Delete all the local data about VMs.
|
||||
|
||||
:param path: A path to removed VM data from.
|
||||
:type path: str
|
||||
"""
|
||||
cleanup_local_data(path, os.listdir(path))
|
||||
|
||||
|
||||
@contract
|
||||
def fetch_remote_data(db, data_length, uuids):
|
||||
""" Fetch VM data from the central DB.
|
||||
|
@ -179,6 +179,31 @@ class Collector(TestCase):
|
||||
|
||||
os.rmdir(local_data_directory_tmp)
|
||||
|
||||
@qc(1)
|
||||
def cleanup_all_local_data():
|
||||
local_data_directory = os.path.join(
|
||||
os.path.dirname(__file__), '..', 'resources', 'vms')
|
||||
local_data_directory_tmp = os.path.join(
|
||||
local_data_directory, 'tmp')
|
||||
shutil.rmtree(local_data_directory_tmp, True)
|
||||
os.mkdir(local_data_directory_tmp)
|
||||
vm1 = 'ec452be0-e5d0-11e1-aff1-0800200c9a66'
|
||||
vm2 = 'e615c450-e5d0-11e1-aff1-0800200c9a66'
|
||||
vm3 = 'f3e142d0-e5d0-11e1-aff1-0800200c9a66'
|
||||
|
||||
shutil.copy(os.path.join(local_data_directory, vm1),
|
||||
local_data_directory_tmp)
|
||||
shutil.copy(os.path.join(local_data_directory, vm2),
|
||||
local_data_directory_tmp)
|
||||
shutil.copy(os.path.join(local_data_directory, vm3),
|
||||
local_data_directory_tmp)
|
||||
|
||||
assert len(os.listdir(local_data_directory_tmp)) == 3
|
||||
collector.cleanup_all_local_data(local_data_directory_tmp)
|
||||
assert len(os.listdir(local_data_directory_tmp)) == 0
|
||||
|
||||
os.rmdir(local_data_directory_tmp)
|
||||
|
||||
@qc
|
||||
def fetch_remote_data(
|
||||
x=dict_(
|
||||
|
Loading…
x
Reference in New Issue
Block a user