Skip to content

Commit 5eba10d

Browse files
Merge pull request #92 from openvstorage/0.3.x_new_testrail_api
Refactor Testrail Api
2 parents fe41482 + 7024f84 commit 5eba10d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2580
-1005
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: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
import json
17+
from ci.api_lib.helpers.api import OVSClient
18+
19+
20+
class CIConstants(object):
21+
"""
22+
Collection of multiple constants and constant related instances
23+
"""
24+
25+
CONFIG_LOC = "/opt/OpenvStorage/ci/config/setup.json"
26+
TEST_SCENARIO_LOC = "/opt/OpenvStorage/ci/scenarios/"
27+
TESTRAIL_LOC = "/opt/OpenvStorage/ci/config/testrail.json"
28+
29+
with open(CONFIG_LOC, 'r') as JSON_CONFIG:
30+
SETUP_CFG = json.load(JSON_CONFIG)
31+
32+
HYPERVISOR_INFO = SETUP_CFG['ci'].get('hypervisor')
33+
DOMAIN_INFO = SETUP_CFG['setup']['domains']
34+
BACKEND_INFO = SETUP_CFG['setup']['backends']
35+
STORAGEROUTER_INFO = SETUP_CFG['setup']['storagerouters']
36+
37+
class classproperty(property):
38+
def __get__(self, cls, owner):
39+
return classmethod(self.fget).__get__(None, owner)()
40+
41+
@classproperty
42+
def api(cls):
43+
return OVSClient(cls.SETUP_CFG['ci']['grid_ip'],
44+
cls.SETUP_CFG['ci']['user']['api']['username'],
45+
cls.SETUP_CFG['ci']['user']['api']['password'],
46+
)
47+
48+
@classmethod
49+
def get_vpool_names(cls):
50+
names = []
51+
for sr_ip, items in cls.STORAGEROUTER_INFO.iteritems():
52+
vpools = items.get('vpools')
53+
for vp_name, vp_info in vpools.iteritems():
54+
if vp_name not in names:
55+
names.append(vp_name)
56+
return names

helpers/disk.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,10 @@ class DiskHelper(object):
2424
DiskHelper class
2525
"""
2626

27-
def __init__(self):
28-
pass
29-
3027
@staticmethod
3128
def get_diskpartitions_by_guid(diskguid):
3229
"""
3330
Fetch disk partitions by disk guid
34-
3531
:param diskguid: ip address of a storagerouter
3632
:type diskguid: str
3733
:return: list of DiskPartition Objects
@@ -41,59 +37,53 @@ def get_diskpartitions_by_guid(diskguid):
4137
return [dp for dp in DiskPartitionList.get_partitions() if dp.disk_guid == diskguid]
4238

4339
@staticmethod
44-
def get_roles_from_disks(storagerouter_ip=None):
40+
def get_roles_from_disks(storagerouter_guid=None):
4541
"""
4642
Fetch disk roles from all disks with optional storagerouter_ip
47-
48-
:param storagerouter_ip: ip address of a storage router
49-
:type storagerouter_ip: str
43+
:param storagerouter_guid: guid of a storage router
44+
:type storagerouter_guid: str
5045
:return: list of lists with roles
5146
:rtype: list > list
5247
"""
53-
if not storagerouter_ip:
48+
if not storagerouter_guid:
5449
return [partition.roles for disk in DiskList.get_disks() for partition in disk.partitions]
5550
else:
56-
storagerouter_guid = StoragerouterHelper.get_storagerouter_guid_by_ip(storagerouter_ip)
5751
return [partition.roles for disk in DiskList.get_disks()
5852
if disk.storagerouter_guid == storagerouter_guid for partition in disk.partitions]
5953

6054
@staticmethod
61-
def get_disk_by_diskname(storagerouter_ip, disk_name):
55+
def get_disk_by_diskname(storagerouter_guid, disk_name):
6256
"""
63-
Get a disk object by storagerouter ip and disk name
64-
65-
:param storagerouter_ip: ip address of a storage router
66-
:type storagerouter_ip: str
57+
Get a disk object by storagerouter guid and disk name
58+
:param storagerouter_guid: guid address of a storage router
59+
:type storagerouter_guid: str
6760
:param disk_name: name of a disk (e.g. sda)
6861
:type disk_name: str
6962
:return: disk object
7063
:rtype: ovs.dal.hybrids.Disk
7164
"""
72-
73-
storagerouter = StoragerouterHelper.get_storagerouter_by_ip(storagerouter_ip=storagerouter_ip)
65+
storagerouter = StoragerouterHelper.get_storagerouter_by_guid(storagerouter_guid=storagerouter_guid)
7466
for disk in storagerouter.disks:
7567
if disk.name == disk_name:
7668
return disk
7769

7870
@staticmethod
79-
def get_roles_from_disk(storagerouter_ip, disk_name):
71+
def get_roles_from_disk(storagerouter_guid, disk_name):
8072
"""
8173
Get the roles from a certain disk
82-
83-
:param storagerouter_ip: ip address of a storage router
84-
:type storagerouter_ip: str
74+
:param storagerouter_guid: guid address of a storage router
75+
:type storagerouter_guid: str
8576
:param disk_name: name of a disk (e.g. sda)
8677
:type disk_name: str
8778
:return: list of roles of all partitions on a certain disk
8879
:rtype: list
8980
"""
90-
91-
disk = DiskHelper.get_disk_by_diskname(storagerouter_ip, disk_name)
81+
disk = DiskHelper.get_disk_by_diskname(storagerouter_guid, disk_name)
9282
roles_on_disk = []
9383
if disk:
9484
for diskpartition in disk.partitions:
9585
for role in diskpartition.roles:
9686
roles_on_disk.append(role)
9787
return roles_on_disk
9888
else:
99-
raise RuntimeError("Disk with name `{0}` not found on storagerouter `{1}`".format(disk_name, storagerouter_ip))
89+
raise RuntimeError("Disk with name `{0}` not found on storagerouter `{1}`".format(disk_name, storagerouter_guid))

helpers/domain.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Copyright (C) 2016 iNuron NV
22
#
33
# This file is part of Open vStorage Open Source Edition (OSE),
4+
# Copyright (C) 2016 iNuron NV
5+
#
6+
# This file is part of Open vStorage Open Source Edition (OSE),
47
# as available from
58
#
69
# http://www.openvstorage.org and
@@ -109,4 +112,3 @@ def get_storagedrivers_in_same_domain(domain_guid):
109112
:rtype: list
110113
"""
111114
return [storagedriver for storagedriver in StorageDriverList.get_storagedrivers() if domain_guid in storagedriver.storagerouter.regular_domains]
112-

helpers/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@ class ImageConvertError(Exception):
8686
"""
8787
Raised when an object was queries that doesn't exist
8888
"""
89-
pass
89+
pass

helpers/hypervisor/hypervisor.py

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,74 @@
1616
Hypervisor/ManagementCenter factory module
1717
Using the module requires libvirt api to be available on the MACHINE THAT EXECUTES THE CODE
1818
"""
19-
2019
from ovs_extensions.generic.filemutex import file_mutex
20+
from ovs_extensions.generic.toolbox import ExtensionsToolbox
21+
from ovs.lib.helpers.toolbox import Toolbox
22+
from ...helpers.ci_constants import CIConstants
2123

2224

23-
class HypervisorFactory(object):
25+
class HypervisorFactory(CIConstants):
2426
"""
2527
HypervisorFactory class provides functionality to get abstracted hypervisor
2628
"""
27-
2829
hypervisors = {}
2930

30-
@staticmethod
31-
def get(ip, username, password, hvtype):
31+
@classmethod
32+
def get(cls, hv_credentials=None):
3233
"""
3334
Returns the appropriate hypervisor client class for a given PMachine
35+
:param hv_credentials: object that contains ip, user, password and hypervisor type
36+
:type hv_credentials: HypervisorCredentials object
3437
"""
35-
key = '{0}_{1}'.format(ip, username)
36-
if key not in HypervisorFactory.hypervisors:
37-
mutex = file_mutex('hypervisor_{0}'.format(key))
38-
try:
39-
mutex.acquire(30)
40-
if key not in HypervisorFactory.hypervisors:
41-
if hvtype == 'VMWARE':
42-
# Not yet tested. Needs to be rewritten
43-
raise NotImplementedError("{0} has not yet been implemented".format(hvtype))
44-
from .hypervisors.vmware import VMware
45-
hypervisor = VMware(ip, username, password)
46-
elif hvtype == 'KVM':
47-
from .hypervisors.kvm import KVM
48-
hypervisor = KVM(ip, username, password)
49-
else:
50-
raise NotImplementedError('Hypervisor {0} is not yet supported'.format(hvtype))
51-
HypervisorFactory.hypervisors[key] = hypervisor
52-
finally:
53-
mutex.release()
54-
return HypervisorFactory.hypervisors[key]
38+
if hv_credentials is None:
39+
return cls.get(HypervisorCredentials(ip=CIConstants.HYPERVISOR_INFO['ip'],
40+
user=CIConstants.HYPERVISOR_INFO['user'],
41+
password=CIConstants.HYPERVISOR_INFO['password'],
42+
type=CIConstants.HYPERVISOR_INFO['type']))
43+
if not isinstance(hv_credentials, HypervisorCredentials):
44+
raise TypeError('Credentials must be of type HypervisorCredentials')
45+
return cls.hypervisors.get(hv_credentials, cls._add_hypervisor(hv_credentials))
46+
47+
@staticmethod
48+
def _add_hypervisor(hypervisor_credentials):
49+
ip = hypervisor_credentials.ip
50+
username = hypervisor_credentials.user
51+
password = hypervisor_credentials.password
52+
hvtype = hypervisor_credentials.type
53+
mutex = file_mutex('hypervisor_{0}'.format(hash(hypervisor_credentials)))
54+
try:
55+
mutex.acquire(30)
56+
if hypervisor_credentials not in HypervisorFactory.hypervisors:
57+
if hvtype == 'VMWARE':
58+
# Not yet tested. Needs to be rewritten
59+
raise NotImplementedError("{0} has not yet been implemented".format(hvtype))
60+
from .hypervisors.vmware import VMware
61+
hypervisor = VMware(ip, username, password)
62+
elif hvtype == 'KVM':
63+
from .hypervisors.kvm import KVM
64+
hypervisor = KVM(ip, username, password)
65+
else:
66+
raise NotImplementedError('Hypervisor {0} is not yet supported'.format(hvtype))
67+
HypervisorFactory.hypervisors[hypervisor_credentials] = hypervisor
68+
return hypervisor
69+
finally:
70+
mutex.release()
71+
72+
73+
class HypervisorCredentials(object):
74+
def __init__(self, ip, user, password, type):
75+
required_params = {'ip': (str, Toolbox.regex_ip),
76+
'user': (str, None),
77+
'password': (str, None),
78+
'type': (str, ['KVM', 'VMWARE'])}
79+
ExtensionsToolbox.verify_required_params(required_params, {'ip': ip,
80+
'user': user,
81+
'password': password,
82+
'type': type})
83+
self.ip = ip
84+
self.user = user
85+
self.password = password
86+
self.type = type
87+
88+
def __str__(self):
89+
return 'hypervisor at ip {0} of type {1}'.format(self.ip, self.type)

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/storagedriver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
from ovs.dal.hybrids.storagedriver import StorageDriver
1818
from ovs.dal.lists.storagedriverlist import StorageDriverList
1919
from ovs.extensions.generic.configuration import Configuration
20+
from ovs.log.log_handler import LogHandler
2021
from ovs.extensions.generic.sshclient import SSHClient
2122
from ovs.extensions.services.servicefactory import ServiceFactory
22-
from ovs.log.log_handler import LogHandler
2323

2424

2525
class StoragedriverHelper(object):

0 commit comments

Comments
 (0)