Skip to content

Commit 98599cd

Browse files
Merge pull request #94 from openvstorage/0.3.x
Bug fixed for claiming/initializing asds
2 parents e21b98d + 871ed27 commit 98599cd

File tree

3 files changed

+85
-71
lines changed

3 files changed

+85
-71
lines changed

setup/backend.py

Lines changed: 81 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -192,82 +192,89 @@ def update_preset(cls, albabackend_name, preset_name, policies, timeout=UPDATE_P
192192
def add_asds(cls, target, disks, albabackend_name, claim_retries=MAX_CLAIM_RETRIES, *args, **kwargs):
193193
"""
194194
Initialize and claim a new asds on given disks
195+
195196
:param target: target to add asds too
196197
:type target: str
197198
:param disks: dict with diskname as key and amount of osds as value
198199
:type disks: dict
199-
:param albabackend_name: Name of the AlbaBackend to configure
200-
:type albabackend_name: str
201200
:param claim_retries: Maximum amount of claim retries
202201
:type claim_retries: int
202+
:param albabackend_name: Name of the AlbaBackend to configure
203+
:type albabackend_name: str
203204
:return: preset_name
204205
:rtype: str
205206
"""
206-
BackendSetup._discover_and_register_nodes() # Make sure all backends are registered
207-
node_mapping = AlbaNodeHelper._map_alba_nodes() # target is a node
208-
alba_backend_guid = BackendHelper.get_alba_backend_guid_by_name(albabackend_name)
207+
# Make sure all backends are registered
208+
BackendSetup._discover_and_register_nodes(cls.api)
209+
# target is a node
210+
node_mapping = AlbaNodeHelper._map_alba_nodes(cls.api)
209211

210-
backend_info = BackendHelper.get_backend_local_stack(albabackend_name=albabackend_name)
211-
local_stack = backend_info['local_stack']
212-
node_slot_information = {}
212+
local_stack = BackendHelper.get_backend_local_stack(albabackend_name=albabackend_name, api=cls.api)
213+
disk_queue = {}
213214
for disk, amount_of_osds in disks.iteritems():
214215
disk_object = AlbaNodeHelper.get_disk_by_ip(ip=target, diskname=disk)
215216
# Get the name of the disk out of the path, only expecting one with ata-
216-
slot_id = BackendHelper.get_local_stack_alias(disk_object)
217+
disk_path = BackendHelper.get_local_stack_alias(disk_object)
217218
for alba_node_id, alba_node_guid in node_mapping.iteritems():
218-
node_info = local_stack[alba_node_id]
219219
# Check if the alba_node_id has the disk
220-
if slot_id in node_info:
221-
slot_information = node_slot_information.get(alba_node_guid, [])
222-
BackendSetup.LOGGER.info('Adding {0} to disk queue for providing {1} osds.'.format(slot_id, amount_of_osds))
223-
slot_information.append({'count': amount_of_osds,
224-
'slot_id': slot_id,
225-
'osd_type': 'ASD',
226-
'alba_backend_guid': alba_backend_guid})
227-
228-
node_slot_information[alba_node_guid] = slot_information
229-
for alba_node_guid, slot_information in node_slot_information.iteritems():
230-
BackendSetup.LOGGER.info('Posting {0} for alba_node_guid {1}'.format(slot_information, alba_node_guid))
231-
BackendSetup._fill_slots(alba_node_guid=alba_node_guid, slot_information=slot_information)
220+
if disk_path in local_stack['local_stack'][alba_node_id]:
221+
if alba_node_guid not in disk_queue:
222+
disk_queue[alba_node_guid] = {}
223+
# Initialize disk:
224+
BackendSetup.LOGGER.info(
225+
'Adding {0} to disk queue for providing {1} asds.'.format(disk_path, amount_of_osds))
226+
disk_queue[alba_node_guid][disk_path] = amount_of_osds
227+
for alba_node_guid, queue in disk_queue.iteritems():
228+
BackendSetup.LOGGER.info(
229+
'Posting disk queue {0} for alba_node_guid {1}'.format(disk_queue[alba_node_guid], alba_node_guid))
230+
result = BackendSetup._fill_slots(
231+
alba_node_guid=alba_node_guid,
232+
slot_information=disk_queue[alba_node_guid])
233+
BackendSetup.LOGGER.info('Claiming disks was succesfull. Result = {0}'.format(result))
232234

233235
# Local stack should sync with the new disks
234236
BackendSetup.LOGGER.info('Sleeping for {0} seconds to let local stack sync.'.format(BackendSetup.LOCAL_STACK_SYNC))
235237
time.sleep(BackendSetup.LOCAL_STACK_SYNC)
236238

237239
# Restarting iteration to avoid too many local stack calls:
238-
node_osds_to_claim = {}
240+
local_stack = BackendHelper.get_backend_local_stack(albabackend_name=albabackend_name, api=cls.api)
241+
asd_queue = {}
239242
for disk, amount_of_osds in disks.iteritems():
240243
disk_object = AlbaNodeHelper.get_disk_by_ip(ip=target, diskname=disk)
241244
# Get the name of the disk out of the path
242-
slot_id = BackendHelper.get_local_stack_alias(disk_object)
245+
disk_path = BackendHelper.get_local_stack_alias(disk_object)
243246
for alba_node_id, alba_node_guid in node_mapping.iteritems():
244-
albanode = AlbaNodeHelper.get_albanode(alba_node_guid)
245-
# Claim asds
246-
if slot_id not in albanode.stack:
247-
continue
248-
osds = albanode.stack[slot_id]['osds']
249-
for osd_id, osd_info in osds.iteritems():
250-
# If the asd is not available, fetch local_stack again after 5s to wait for albamgr to claim it
251-
current_retry = 0
252-
while osd_info['status'] not in ['available', 'ok']:
253-
current_retry += 1
254-
BackendSetup.LOGGER.info('ASD {0} for Alba node {1} was not available. Waiting 5 seconds '
255-
'to retry (currently {2} retries left).'.format(osd_id, alba_node_id, claim_retries - current_retry))
256-
if current_retry >= claim_retries:
257-
raise RuntimeError('ASD {0} for Alba node {1} did come available after {2} seconds'.format(osd_id, alba_node_id, current_retry * 5))
258-
time.sleep(5)
259-
albanode.invalidate_dynamics('stack')
260-
osd_info = albanode.stack[slot_id][osd_id]
261-
BackendSetup.LOGGER.info('Adding asd {0} for slot {1} to claim queue'.format(osd_id, slot_id))
262-
osds_to_claim = node_osds_to_claim.get(alba_node_guid, [])
263-
osds_to_claim.append({'osd_type': 'ASD',
264-
'ips': osd_info['ips'],
265-
'port': osd_info['port'],
266-
'slot_id': slot_id})
267-
node_osds_to_claim[alba_node_guid] = osds_to_claim
268-
for alba_node_guid, osds_to_claim in node_osds_to_claim.iteritems():
269-
BackendSetup.LOGGER.info('Posting {0} for alba_node_guid {1}'.format(osds_to_claim, alba_node_guid))
270-
BackendSetup._claim_osds(alba_backend_name=albabackend_name, alba_node_guid=alba_node_guid, osds=osds_to_claim)
247+
# Check if the alba_node_id has the disk
248+
if disk_path in local_stack['local_stack'][alba_node_id]:
249+
# Claim asds
250+
for asd_id, asd_info in local_stack['local_stack'][alba_node_id][disk_path]['asds'].iteritems():
251+
# If the asd is not available, fetch local_stack again after 5s to wait for albamgr to claim it
252+
current_retry = 0
253+
while asd_info['status'] != 'available':
254+
current_retry += 1
255+
BackendSetup.LOGGER.info('ASD {0} for Alba node {1} was not available. Waiting 5 seconds'
256+
' to retry (currently {2} retries left).'.format(asd_id, alba_node_id, claim_retries - current_retry))
257+
if current_retry >= claim_retries:
258+
raise RuntimeError('ASD {0} for Alba node {1} did come available after {2} seconds'.format(asd_id, alba_node_id, current_retry * 5))
259+
time.sleep(5)
260+
local_stack = BackendHelper.get_backend_local_stack(albabackend_name=albabackend_name, api=cls.api)
261+
asd_info = local_stack['local_stack'][alba_node_id][disk_path]['asds'][asd_id]
262+
BackendSetup.LOGGER.info('Adding asd {0} for disk {1} to claim queue'.format(asd_id,
263+
local_stack[
264+
'local_stack'][
265+
alba_node_id][
266+
disk_path][
267+
'guid']))
268+
asd_queue[asd_id] = local_stack['local_stack'][alba_node_id][disk_path]['guid']
269+
if len(asd_queue.keys()) != 0:
270+
BackendSetup.LOGGER.info('Posting asd queue {0}'.format(asd_queue))
271+
BackendSetup._claim_asd(
272+
alba_backend_name=albabackend_name,
273+
api=cls.api,
274+
queue=asd_queue
275+
)
276+
else:
277+
BackendSetup.LOGGER.info('No asds have to claimed for {0}'.format(albabackend_name))
271278

272279
@classmethod
273280
def _discover_and_register_nodes(cls, *args, **kwargs):
@@ -319,9 +326,7 @@ def get_backend_local_stack(cls, alba_backend_name, *args, **kwargs):
319326
options = {
320327
'contents': 'local_stack',
321328
}
322-
return cls.api.get(api='/alba/backends/{0}/'.format(BackendHelper.get_alba_backend_guid_by_name(alba_backend_name)),
323-
params={'queryparams': options}
324-
)
329+
return cls.api.get(api='/alba/backends/{0}/'.format(BackendHelper.get_alba_backend_guid_by_name(alba_backend_name)), params={'queryparams': options})
325330

326331
@classmethod
327332
def _fill_slots(cls, alba_node_guid, slot_information, timeout=INITIALIZE_DISK_TIMEOUT, *args, **kwargs):
@@ -334,9 +339,9 @@ def _fill_slots(cls, alba_node_guid, slot_information, timeout=INITIALIZE_DISK_T
334339
:type timeout: int
335340
:return:
336341
"""
337-
data = {'slot_information': slot_information}
342+
data = {'disks': slot_information}
338343
task_guid = cls.api.post(
339-
api='/alba/nodes/{0}/fill_slots/'.format(alba_node_guid),
344+
api='/alba/nodes/{0}/initialize_disks/'.format(alba_node_guid),
340345
data=data
341346
)
342347
task_result = cls.api.wait_for_task(task_id=task_guid, timeout=timeout)
@@ -348,34 +353,41 @@ def _fill_slots(cls, alba_node_guid, slot_information, timeout=INITIALIZE_DISK_T
348353
BackendSetup.LOGGER.info("Successfully initialized '{0}'".format(data))
349354
return task_result[0]
350355

351-
@classmethod
352-
def _claim_osds(cls, alba_backend_name, alba_node_guid, osds, timeout=CLAIM_ASD_TIMEOUT, *args, **kwargs):
356+
@staticmethod
357+
def _claim_asd(alba_backend_name, api, timeout=CLAIM_ASD_TIMEOUT, asd_id=None, disk_guid=None, queue=None):
353358
"""
354359
Claims a asd
355360
:param alba_backend_name: backend name
356361
:type alba_backend_name: str
357-
:param alba_node_guid: guid of the alba node on which the osds are available
358-
:type alba_node_guid: str
359-
:param osds: list of osds to claim
360-
:type osds: list
362+
:param asd_id: id of the asd
363+
:type asd_id: str
364+
:param disk_guid: guid of the disk
365+
:type disk_guid: str
366+
:param api: specify a valid api connection to the setup
367+
:type api: helpers.api.OVSClient
361368
:param timeout: timeout counter in seconds
362369
:type timeout: int
370+
:param queue: queue of asds
371+
:type queue: dict
363372
:return:
364373
"""
365-
data = {'alba_node_guid': alba_node_guid,
366-
'osds': osds}
367-
task_guid = cls.api.post(
368-
api='/alba/backends/{0}/add_osds/'.format(BackendHelper.get_alba_backend_guid_by_name(alba_backend_name)),
374+
if queue is None and (asd_id and disk_guid is not None):
375+
queue = {asd_id: disk_guid}
376+
data = {'osds': queue}
377+
task_guid = api.post(
378+
api='/alba/backends/{0}/add_units/'.format(BackendHelper.get_alba_backend_guid_by_name(alba_backend_name)),
369379
data=data
370380
)
371-
task_result = cls.api.wait_for_task(task_id=task_guid, timeout=timeout)
381+
task_result = api.wait_for_task(task_id=task_guid, timeout=timeout)
372382

373383
if not task_result[0]:
374-
error_msg = "Claim ASD `{0}` for alba backend `{1}` has failed with error '{2}'".format(osds, alba_backend_name, task_result[1])
384+
error_msg = "Claim ASD `{0}` for alba backend `{1}` has failed with error '{2}'".format(queue,
385+
alba_backend_name,
386+
task_result[1])
375387
BackendSetup.LOGGER.error(error_msg)
376388
raise RuntimeError(error_msg)
377389
else:
378-
BackendSetup.LOGGER.info("Succesfully claimed '{0}'".format(osds))
390+
BackendSetup.LOGGER.info("Succesfully claimed '{0}'".format(queue))
379391
return task_result[0]
380392

381393
@classmethod

validate/backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def check_available_osds_on_asdmanager(ip, disks):
116116
BackendValidation.LOGGER.error(error_msg)
117117
raise AlbaNodeNotFoundError(error_msg)
118118
# compare requested disks with available disks
119-
fetched_slots = albanode.client.get_stack().values()
119+
fetched_slots = albanode.client.get_disks().values()
120120
slot_map = {}
121121
for fetched_disk in fetched_slots:
122122
# Ignore other slots than disks

validate/roles.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,6 @@ def check_role_on_disk(roles, storagerouter_ip, disk_name):
8484
:return: if available on disk
8585
:rtype: bool
8686
"""
87-
return len(set(roles).difference(set(DiskHelper.get_roles_from_disk(storagerouter_ip, disk_name)))) == 0
87+
88+
storagerouter_guid = StoragerouterHelper.get_storagerouter_by_ip(storagerouter_ip).guid
89+
return len(set(roles).difference(set(DiskHelper.get_roles_from_disk(storagerouter_guid, disk_name)))) == 0

0 commit comments

Comments
 (0)