Skip to content

Commit 7024f84

Browse files
Implemented bug fixes + added new tests (create 500 vdisks from a template)
1 parent 62c832f commit 7024f84

File tree

11 files changed

+158
-91
lines changed

11 files changed

+158
-91
lines changed

helpers/backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def get_preset_by_albabackend(preset_name, albabackend_name):
183183
"""
184184
Fetches preset by albabackend_guid
185185
186-
:param preset_name: name of a existing preset
186+
:param preset_name: name of an existing preset
187187
:type preset_name: str
188188
:param albabackend_name: name of a existing alba backend
189189
:type albabackend_name: str

helpers/ci_constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def __get__(self, cls, owner):
4242
def api(cls):
4343
return OVSClient(cls.SETUP_CFG['ci']['grid_ip'],
4444
cls.SETUP_CFG['ci']['user']['api']['username'],
45-
cls.SETUP_CFG['ci']['user']['api']['password'])
45+
cls.SETUP_CFG['ci']['user']['api']['password'],
46+
)
4647

4748
@classmethod
4849
def get_vpool_names(cls):

helpers/service.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (C) 2016 iNuron NV
2+
#
3+
# This file is part of Open vStorage Open Source Edition (OSE),
4+
# as available from
5+
#
6+
# http://www.openvstorage.org and
7+
# http://www.openvstorage.com.
8+
#
9+
# This file is free software; you can redistribute it and/or modify it
10+
# under the terms of the GNU Affero General Public License v3 (GNU AGPLv3)
11+
# as published by the Free Software Foundation, in version 3 as it comes
12+
# in the LICENSE.txt file of the Open vStorage OSE distribution.
13+
#
14+
# Open vStorage is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY of any kind.
16+
17+
from ovs.dal.hybrids.service import Service
18+
from ovs.extensions.generic.sshclient import SSHClient
19+
from ovs.extensions.services.servicefactory import ServiceFactory
20+
from ovs.log.log_handler import LogHandler
21+
from ..helpers.ci_constants import CIConstants
22+
23+
24+
class ServiceHelper(CIConstants):
25+
"""
26+
ServiceHelper class
27+
"""
28+
29+
LOGGER = LogHandler.get(source="setup", name="ci_service_setup")
30+
SERVICE_MANAGER = ServiceFactory.get_manager()
31+
32+
@staticmethod
33+
def get_service(guid):
34+
"""
35+
Fetch Service object by service guid
36+
:param guid: guid of the service
37+
:return: a Service object
38+
"""
39+
return Service(guid)
40+
41+
@staticmethod
42+
def restart_service(guid, storagerouter):
43+
"""
44+
Restart a service based on the guid located on storagerouter
45+
:param guid: guid of the service
46+
:param storagerouter: storagerouter where the service is running
47+
:type storagerouter: StorageRouter
48+
:return:
49+
"""
50+
client = SSHClient(storagerouter, username='root')
51+
service = ServiceHelper.get_service(guid)
52+
return ServiceHelper.SERVICE_MANAGER.restart_service(service.name, client=client)

helpers/vdisk.py

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313
#
1414
# Open vStorage is distributed in the hope that it will be useful,
1515
# but WITHOUT ANY WARRANTY of any kind.
16-
from ovs.log.log_handler import LogHandler
16+
1717
from ovs.dal.hybrids.vdisk import VDisk
1818
from ovs.dal.lists.vdisklist import VDiskList
1919
from ovs.dal.lists.vpoollist import VPoolList
20+
from ovs.log.log_handler import LogHandler
21+
from ..helpers.ci_constants import CIConstants
2022
from ..helpers.exceptions import VPoolNotFoundError, VDiskNotFoundError
2123

2224

23-
class VDiskHelper(object):
25+
class VDiskHelper(CIConstants):
2426
"""
2527
vDiskHelper class
2628
"""
@@ -105,8 +107,8 @@ def get_snapshot_by_guid(snapshot_guid, vdisk_name, vpool_name):
105107
raise RuntimeError("Did not find snapshot with guid `{0}` on vdisk `{1}` on vpool `{2}`"
106108
.format(snapshot_guid, vdisk_name, vpool_name))
107109

108-
@staticmethod
109-
def get_config_params(vdisk_name, vpool_name, api, timeout=GET_CONFIG_PARAMS_TIMEOUT):
110+
@classmethod
111+
def get_config_params(cls, vdisk_name, vpool_name, timeout=GET_CONFIG_PARAMS_TIMEOUT, *args, **kwargs):
110112
"""
111113
Fetch the config parameters of a vDisk
112114
@@ -115,8 +117,6 @@ def get_config_params(vdisk_name, vpool_name, api, timeout=GET_CONFIG_PARAMS_TIM
115117
:type vdisk_name: str
116118
:param vpool_name: name of a existing vpool
117119
:type vpool_name: str
118-
:param api: specify a valid api connection to the setup
119-
:type api: ci.helpers.api.OVSClient
120120
:param timeout: time to wait for the task to complete
121121
:type timeout: int
122122
:return: a dict with config parameters, e.g.
@@ -133,8 +133,8 @@ def get_config_params(vdisk_name, vpool_name, api, timeout=GET_CONFIG_PARAMS_TIM
133133
"""
134134

135135
vdisk = VDiskHelper.get_vdisk_by_name(vdisk_name=vdisk_name, vpool_name=vpool_name)
136-
task_guid = api.get(api='/vdisks/{0}/get_config_params'.format(vdisk.guid))
137-
task_result = api.wait_for_task(task_id=task_guid, timeout=timeout)
136+
task_guid = cls.api.get(api='/vdisks/{0}/get_config_params'.format(vdisk.guid))
137+
task_result = cls.api.wait_for_task(task_id=task_guid, timeout=timeout)
138138

139139
if not task_result[0]:
140140
error_msg = "Setting config vDisk `{0}` has failed with error {1}".format(vdisk_name, task_result[1])
@@ -144,23 +144,21 @@ def get_config_params(vdisk_name, vpool_name, api, timeout=GET_CONFIG_PARAMS_TIM
144144
VDiskHelper.LOGGER.info("Setting config vDisk `{0}` should have succeeded".format(vdisk_name))
145145
return task_result[1]
146146

147-
@staticmethod
148-
def scrub_vdisk(vdisk_guid, api, timeout=15 * 60, wait=True):
147+
@classmethod
148+
def scrub_vdisk(cls, vdisk_guid, timeout=15 * 60, wait=True, *args, **kwargs):
149149
"""
150150
Scrub a specific vdisk
151151
:param vdisk_guid: guid of the vdisk to scrub
152152
:type vdisk_guid: str
153-
:param api: specify a valid api connection to the setup
154-
:type api: ci.helpers.api.OVSClient
155153
:param timeout: time to wait for the task to complete
156154
:type timeout: int
157155
:param wait: wait for task to finish or not
158156
:type wait: bool
159-
:return:
157+
:return:
160158
"""
161-
task_guid = api.post(api='/vdisks/{0}/scrub/'.format(vdisk_guid), data={})
159+
task_guid = cls.api.post(api='/vdisks/{0}/scrub/'.format(vdisk_guid), data={})
162160
if wait is True:
163-
task_result = api.wait_for_task(task_id=task_guid, timeout=timeout)
161+
task_result = cls.api.wait_for_task(task_id=task_guid, timeout=timeout)
164162
if not task_result[0]:
165163
error_msg = "Scrubbing vDisk `{0}` has failed with error {1}".format(vdisk_guid, task_result[1])
166164
VDiskHelper.LOGGER.error(error_msg)
@@ -170,3 +168,24 @@ def scrub_vdisk(vdisk_guid, api, timeout=15 * 60, wait=True):
170168
return task_result[1]
171169
else:
172170
return task_guid
171+
172+
@classmethod
173+
def delete_vdisk(cls, vdisk_guid, timeout=GET_CONFIG_PARAMS_TIMEOUT):
174+
"""
175+
Delete a specific vdisk
176+
:param vdisk_guid: guid of the vdisk to delete
177+
:type vdisk_guid: str
178+
:param timeout: time to wait for the task to complete
179+
:type timeout: int
180+
:return: bool
181+
"""
182+
task_guid = cls.api.delete(api='/vdisks/{0}'.format(vdisk_guid))
183+
task_result = cls.api.wait_for_task(task_id=task_guid, timeout=timeout)
184+
185+
if not task_result[0]:
186+
error_msg = "Deleting of vDisk `{0}` has failed with error {1}".format(vdisk_guid, task_result[1])
187+
VDiskHelper.LOGGER.error(error_msg)
188+
raise RuntimeError(error_msg)
189+
else:
190+
VDiskHelper.LOGGER.info("Deleting of vDisk `{0}` should have succeeded".format(vdisk_guid))
191+
return True

remove/vdisk.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def remove_snapshot(cls, snapshot_guid, vdisk_name, vpool_name, timeout=REMOVE_S
7575
task_result = cls.api.wait_for_task(task_id=task_guid, timeout=timeout)
7676

7777
if not task_result[0]:
78-
error_msg = "Deleting snapshot `{0}` for vdisk `{1}` has failed".format(snapshot_guid, vdisk_name)
78+
error_msg = "Task `{0}`: deleting snapshot `{1}` for vdisk `{2}` has failed".format(task_guid, snapshot_guid, vdisk_name)
7979
VDiskRemover.LOGGER.error(error_msg)
8080
raise RuntimeError(error_msg)
8181
else:
@@ -97,11 +97,11 @@ def remove_vdisk(cls, vdisk_guid, timeout=REMOVE_VDISK_TIMEOUT, *args, **kwargs)
9797
task_guid = cls.api.post(api='vdisks/{0}/delete'.format(vdisk_guid))
9898
task_result = cls.api.wait_for_task(task_id=task_guid, timeout=timeout)
9999
if not task_result[0]:
100-
error_msg = "Deleting vDisk `{0}` has failed".format(vdisk_guid)
100+
error_msg = "Task `{0}`: deleting vDisk `{1}` has failed".format(task_guid, vdisk_guid)
101101
VDiskRemover.LOGGER.error(error_msg)
102102
raise RuntimeError(error_msg)
103103
else:
104-
VDiskRemover.LOGGER.info("Deleting vDisk `{0}` should have succeeded".format(vdisk_guid))
104+
VDiskRemover.LOGGER.info("Task `{0}`: deleting vDisk `{1}` should have succeeded".format(task_guid, vdisk_guid))
105105
return True
106106

107107
@classmethod
@@ -139,7 +139,7 @@ def remove_vtemplate_by_name(cls, vdisk_name, vpool_name, timeout=REMOVE_VTEMPLA
139139
task_result = cls.api.wait_for_task(task_id=task_guid, timeout=timeout)
140140

141141
if not task_result[0]:
142-
error_msg = "Deleting vTemplate `{0}` has failed".format(vdisk_name)
142+
error_msg = "Task `{0}`: deleting vTemplate `{1}` has failed".format(task_guid, vdisk_name)
143143
VDiskRemover.LOGGER.error(error_msg)
144144
raise RuntimeError(error_msg)
145145
else:

setup/arakoon.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ def add_arakoon(cluster_name, storagerouter_ip, cluster_basedir,
7777
base_dir=cluster_basedir,
7878
plugins=plugins,
7979
locked=False,
80-
internal=False)
80+
internal=False,
81+
log_sinks=LogHandler.get_sink_path('automation_lib_arakoon_server'),
82+
crash_log_sinks=LogHandler.get_sink_path('automation_lib_arakoon_server_crash')
83+
)
8184
if service_type == ServiceType.ARAKOON_CLUSTER_TYPES.ABM:
8285
client.run(['ln', '-s', '/usr/lib/alba/albamgr_plugin.cmxs', '{0}/arakoon/{1}/db'.format(cluster_basedir, cluster_name)])
8386
elif service_type == ServiceType.ARAKOON_CLUSTER_TYPES.NSM:
@@ -128,7 +131,9 @@ def extend_arakoon(cluster_name, master_storagerouter_ip, storagerouter_ip, clus
128131
arakoon_installer.load()
129132
arakoon_installer.extend_cluster(new_ip=storagerouter_ip,
130133
base_dir=cluster_basedir,
131-
locked=False)
134+
locked=False,
135+
log_sinks=LogHandler.get_sink_path('automation_lib_arakoon_server'),
136+
crash_log_sinks=LogHandler.get_sink_path('automation_lib_arakoon_server_crash'))
132137
if service_type == ServiceType.ARAKOON_CLUSTER_TYPES.ABM:
133138
client.run(['ln', '-s', '/usr/lib/alba/albamgr_plugin.cmxs', '{0}/arakoon/{1}/db'.format(cluster_basedir, cluster_name)])
134139
elif service_type == ServiceType.ARAKOON_CLUSTER_TYPES.NSM:
@@ -194,6 +199,5 @@ def setup_external_arakoons(backend):
194199
clustered_nodes=external_arakoon_mapping[arakoon_name]['all'])
195200
return external_arakoon_mapping
196201
else:
197-
ArakoonSetup.LOGGER.info("Skipping external arakoon creation because backend `{0}` already exists"
198-
.format(backend['name']))
202+
ArakoonSetup.LOGGER.info("Skipping external arakoon creation because backend `{0}` already exists".format(backend['name']))
199203
return

setup/backend.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
from ..helpers.albanode import AlbaNodeHelper
1919
from ..helpers.backend import BackendHelper
2020
from ..helpers.ci_constants import CIConstants
21-
from ..validate.decorators import required_roles, required_backend, required_preset, check_backend, check_preset, \
22-
check_linked_backend, filter_osds
21+
from ..helpers.exceptions import PresetNotFoundError
22+
from ..validate.decorators import required_roles, required_backend, required_preset, check_backend, check_linked_backend, filter_osds
2323

2424

2525
class BackendSetup(CIConstants):
@@ -95,7 +95,6 @@ def add_backend(cls, backend_name, scaling='LOCAL', timeout=BACKEND_TIMEOUT, max
9595
return False
9696

9797
@classmethod
98-
@check_preset
9998
@required_backend
10099
def add_preset(cls, albabackend_name, preset_details, timeout=ADD_PRESET_TIMEOUT, *args, **kwargs):
101100
"""
@@ -120,6 +119,15 @@ def add_preset(cls, albabackend_name, preset_details, timeout=ADD_PRESET_TIMEOUT
120119
:return: success or not
121120
:rtype: bool
122121
"""
122+
123+
# CHECK PRESET
124+
try:
125+
BackendHelper.get_preset_by_albabackend(preset_details['name'], albabackend_name)
126+
BackendSetup.LOGGER.info("Preset `{0}` already exists.".format(preset_details['name']))
127+
return True
128+
except PresetNotFoundError:
129+
pass
130+
123131
# BUILD_PRESET
124132
preset = {'name': preset_details['name'],
125133
'policies': preset_details['policies'],

setup/vdisk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,11 @@ def create_from_template(cls, vdisk_name, vpool_name, new_vdisk_name, storagerou
290290
task_result = cls.api.wait_for_task(task_id=task_guid, timeout=timeout)
291291

292292
if not task_result[0]:
293-
error_msg = "Creating vTemplate `{0}` has failed with error {1}".format(vdisk_name, task_result[1])
293+
error_msg = "Creating `{0}` from vTemplate `{1}` has failed with error {2}".format(official_new_vdisk_name, vdisk_name, task_result[1])
294294
VDiskSetup.LOGGER.error(error_msg)
295295
raise RuntimeError(error_msg)
296296
else:
297-
VDiskSetup.LOGGER.info("Creating vTemplate `{0}` should have succeeded".format(vdisk_name))
297+
VDiskSetup.LOGGER.info("Creating `{0}` from vTemplate `{1}` should have succeeded".format(official_new_vdisk_name, vdisk_name))
298298
return task_result[1]
299299

300300
@classmethod

0 commit comments

Comments
 (0)