Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenmaelbrancke committed Aug 7, 2018
1 parent 449ad1a commit 9d19daf
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 38 deletions.
2 changes: 1 addition & 1 deletion remove/vdisk.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def remove_snapshot(cls, snapshot_guid, vdisk_name, vpool_name, timeout=REMOVE_S
vdisk_guid = VDiskHelper.get_vdisk_by_name(vdisk_name, vpool_name).guid

data = {"snapshot_id": snapshot_guid}
task_guid = api.post(
task_guid = cls.api.post(
api='/vdisks/{0}/remove_snapshot/'.format(vdisk_guid),
data=data
)
Expand Down
87 changes: 51 additions & 36 deletions setup/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
from ..helpers.backend import BackendHelper
from ..helpers.ci_constants import CIConstants
from ..helpers.exceptions import PresetNotFoundError
from ..validate.decorators import required_roles, required_backend, required_preset, check_backend, check_linked_backend, filter_osds
from ..validate.decorators import required_roles, required_backend, required_preset, check_backend, \
check_linked_backend, filter_osds


class BackendSetup(CIConstants):

LOGGER = Logger("setup-ci_backend_setup")
LOCAL_STACK_SYNC = 30
BACKEND_TIMEOUT = 15
Expand All @@ -41,7 +41,8 @@ def __init__(self):
@classmethod
@check_backend
@required_roles(['DB'])
def add_backend(cls, backend_name, scaling='LOCAL', timeout=BACKEND_TIMEOUT, max_tries=MAX_BACKEND_TRIES, *args, **kwargs):
def add_backend(cls, backend_name, scaling='LOCAL', timeout=BACKEND_TIMEOUT, max_tries=MAX_BACKEND_TRIES, *args,
**kwargs):
"""
Add a new backend
:param backend_name: Name of the Backend to add
Expand Down Expand Up @@ -91,7 +92,8 @@ def add_backend(cls, backend_name, scaling='LOCAL', timeout=BACKEND_TIMEOUT, max
time.sleep(timeout)

BackendSetup.LOGGER.error("Creation of Backend `{0}` and scaling `{1}` failed with status: {2}!"
.format(backend_name, scaling, BackendHelper.get_backend_status_by_name(backend_name)))
.format(backend_name, scaling,
BackendHelper.get_backend_status_by_name(backend_name)))
return False

@classmethod
Expand Down Expand Up @@ -144,11 +146,14 @@ def add_preset(cls, albabackend_name, preset_details, timeout=ADD_PRESET_TIMEOUT
task_result = cls.api.wait_for_task(task_id=task_guid, timeout=timeout)

if not task_result[0]:
error_msg = "Preset `{0}` has failed to create on backend `{1}`".format(preset_details['name'], albabackend_name)
error_msg = "Preset `{0}` has failed to create on backend `{1}`".format(preset_details['name'],
albabackend_name)
BackendSetup.LOGGER.error(error_msg)
raise RuntimeError(error_msg)
else:
BackendSetup.LOGGER.info("Creation of preset `{0}` should have succeeded on backend `{1}`".format(preset_details['name'], albabackend_name))
BackendSetup.LOGGER.info(
"Creation of preset `{0}` should have succeeded on backend `{1}`".format(preset_details['name'],
albabackend_name))
return True

@classmethod
Expand Down Expand Up @@ -177,7 +182,7 @@ def update_preset(cls, albabackend_name, preset_name, policies, timeout=UPDATE_P
task_result = cls.api.wait_for_task(task_id=task_guid, timeout=timeout)

if not task_result[0]:
error_msg = "Preset `{0}` has failed to update with policies `{1}` on backend `{2}`"\
error_msg = "Preset `{0}` has failed to update with policies `{1}` on backend `{2}`" \
.format(preset_name, policies, albabackend_name)
BackendSetup.LOGGER.error(error_msg)
raise RuntimeError(error_msg)
Expand Down Expand Up @@ -223,7 +228,8 @@ def add_asds(cls, target, disks, albabackend_name, claim_retries=MAX_CLAIM_RETRI
# Check if the alba_node_id has the disk
if slot_id in node_info:
slot_information = node_slot_information.get(alba_node_guid, [])
BackendSetup.LOGGER.info('Adding {0} to disk queue for providing {1} osds.'.format(slot_id, amount_of_osds))
BackendSetup.LOGGER.info(
'Adding {0} to disk queue for providing {1} osds.'.format(slot_id, amount_of_osds))
slot_information.append({'count': amount_of_osds,
'slot_id': slot_id,
'osd_type': 'ASD',
Expand All @@ -234,7 +240,8 @@ def add_asds(cls, target, disks, albabackend_name, claim_retries=MAX_CLAIM_RETRI
BackendSetup._fill_slots(alba_node_guid=alba_node_guid, slot_information=slot_information, api=cls.api)

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

# Restarting iteration to avoid too many local stack calls:
Expand All @@ -255,9 +262,13 @@ def add_asds(cls, target, disks, albabackend_name, claim_retries=MAX_CLAIM_RETRI
while osd_info['status'] not in ['available', 'ok']:
current_retry += 1
BackendSetup.LOGGER.info('ASD {0} for Alba node {1} was not available. Waiting 5 seconds '
'to retry (currently {2} retries left).'.format(osd_id, alba_node_id, claim_retries - current_retry))
'to retry (currently {2} retries left).'.format(osd_id, alba_node_id,
claim_retries - current_retry))
if current_retry >= claim_retries:
raise RuntimeError('ASD {0} for Alba node {1} did come available after {2} seconds'.format(osd_id, alba_node_id, current_retry * 5))
raise RuntimeError(
'ASD {0} for Alba node {1} did come available after {2} seconds'.format(osd_id,
alba_node_id,
current_retry * 5))
time.sleep(5)
albanode.invalidate_dynamics('stack')
osd_info = albanode.stack[slot_id][osd_id]
Expand All @@ -270,7 +281,8 @@ def add_asds(cls, target, disks, albabackend_name, claim_retries=MAX_CLAIM_RETRI
node_osds_to_claim[alba_node_guid] = osds_to_claim
for alba_node_guid, osds_to_claim in node_osds_to_claim.iteritems():
BackendSetup.LOGGER.info('Posting {0} for alba_node_guid {1}'.format(osds_to_claim, alba_node_guid))
BackendSetup._claim_osds(alba_backend_name=albabackend_name, alba_node_guid=alba_node_guid, osds=osds_to_claim, api=cls.api)
BackendSetup._claim_osds(alba_backend_name=albabackend_name, alba_node_guid=alba_node_guid,
osds=osds_to_claim)

@classmethod
def _discover_and_register_nodes(cls, *args, **kwargs):
Expand Down Expand Up @@ -322,7 +334,9 @@ def get_backend_local_stack(cls, alba_backend_name, *args, **kwargs):
options = {
'contents': 'local_stack',
}
return cls.api.get(api='/alba/backends/{0}/'.format(BackendHelper.get_alba_backend_guid_by_name(alba_backend_name)), params={'queryparams': options})
return cls.api.get(
api='/alba/backends/{0}/'.format(BackendHelper.get_alba_backend_guid_by_name(alba_backend_name)),
params={'queryparams': options})

@classmethod
def _fill_slots(cls, alba_node_guid, slot_information, timeout=INITIALIZE_DISK_TIMEOUT, *args, **kwargs):
Expand All @@ -337,7 +351,7 @@ def _fill_slots(cls, alba_node_guid, slot_information, timeout=INITIALIZE_DISK_T
"""
data = {'slot_information': slot_information}

task_guid = cls,api.post(
task_guid = cls.api.post(
api='/alba/nodes/{0}/fill_slots/'.format(alba_node_guid),
data=data
)
Expand All @@ -350,8 +364,8 @@ def _fill_slots(cls, alba_node_guid, slot_information, timeout=INITIALIZE_DISK_T
BackendSetup.LOGGER.info("Successfully initialized '{0}'".format(data))
return task_result[0]

@staticmethod
def _claim_osds(alba_backend_name, alba_node_guid, osds, api, timeout=CLAIM_ASD_TIMEOUT):
@classmethod
def _claim_osds(cls, alba_backend_name, alba_node_guid, osds, timeout=CLAIM_ASD_TIMEOUT):
"""
Claims a asd
:param alba_backend_name: backend name
Expand All @@ -360,22 +374,22 @@ def _claim_osds(alba_backend_name, alba_node_guid, osds, api, timeout=CLAIM_ASD_
:type alba_node_guid: str
:param osds: list of osds to claim
:type osds: list
:param api: specify a valid api connection to the setup
:type api: helpers.api.OVSClient
:param timeout: timeout counter in seconds
:type timeout: int
:return:
"""
data = {'alba_node_guid': alba_node_guid,
'osds': osds}
task_guid = api.post(
task_guid = cls.api.post(
api='/alba/backends/{0}/add_osds/'.format(BackendHelper.get_alba_backend_guid_by_name(alba_backend_name)),
data=data
)
task_result = api.wait_for_task(task_id=task_guid, timeout=timeout)
task_result = cls.api.wait_for_task(task_id=task_guid, timeout=timeout)

if not task_result[0]:
error_msg = "Claim ASD `{0}` for alba backend `{1}` has failed with error '{2}'".format(osds, alba_backend_name, task_result[1])
error_msg = "Claim ASD `{0}` for alba backend `{1}` has failed with error '{2}'".format(osds,
alba_backend_name,
task_result[1])
BackendSetup.LOGGER.error(error_msg)
raise RuntimeError(error_msg)
else:
Expand All @@ -386,7 +400,8 @@ def _claim_osds(alba_backend_name, alba_node_guid, osds, api, timeout=CLAIM_ASD_
@required_preset
@required_backend
@check_linked_backend
def link_backend(cls, albabackend_name, globalbackend_name, preset_name, timeout=LINK_BACKEND_TIMEOUT, *args, **kwargs):
def link_backend(cls, albabackend_name, globalbackend_name, preset_name, timeout=LINK_BACKEND_TIMEOUT, *args,
**kwargs):
"""
Link a LOCAL backend to a GLOBAL backend
Expand All @@ -404,20 +419,20 @@ def link_backend(cls, albabackend_name, globalbackend_name, preset_name, timeout
local_albabackend = BackendHelper.get_albabackend_by_name(albabackend_name)

data = {
"metadata": {
"backend_connection_info": {
"host": "",
"port": 80,
"username": "",
"password": ""
},
"backend_info": {
"linked_guid": local_albabackend.guid,
"linked_name": local_albabackend.name,
"linked_preset": preset_name,
"linked_alba_id": local_albabackend.alba_id
}
}
"metadata": {
"backend_connection_info": {
"host": "",
"port": 80,
"username": "",
"password": ""
},
"backend_info": {
"linked_guid": local_albabackend.guid,
"linked_name": local_albabackend.name,
"linked_preset": preset_name,
"linked_alba_id": local_albabackend.alba_id
}
}
}
task_guid = cls.api.post(
api='/alba/backends/{0}/link_alba_backends'
Expand Down
2 changes: 1 addition & 1 deletion setup/vdisk.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def create_snapshot(cls, snapshot_name, vdisk_name, vpool_name, consistent=True,
'sticky': sticky
}

task_guid = api.post(
task_guid = cls.api.post(
api='/vdisks/{0}/create_snapshot/'.format(vdisk_guid),
data=data
)
Expand Down

0 comments on commit 9d19daf

Please sign in to comment.