Skip to content

Commit 745c14a

Browse files
Merge pull request #25 from openvstorage/develop
Develop
2 parents af0f6d4 + bd4d84d commit 745c14a

File tree

12 files changed

+85
-40
lines changed

12 files changed

+85
-40
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
syntax: regexp
1111
\._.*
1212
.orig$
13+
*.iml

helpers/api.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
import time
2222
import urllib
2323
import hashlib
24+
import logging
2425
import requests
2526
from requests.packages.urllib3 import disable_warnings
2627
from requests.packages.urllib3.exceptions import InsecurePlatformWarning
2728
from requests.packages.urllib3.exceptions import InsecureRequestWarning
2829
from requests.packages.urllib3.exceptions import SNIMissingWarning
30+
from ovs.log.log_handler import LogHandler
31+
logging.getLogger('urllib3').setLevel(logging.WARNING)
2932

3033

3134
class HttpException(RuntimeError):
@@ -53,10 +56,19 @@ def __init__(self, *args, **kwargs):
5356
super(NotFoundException, self).__init__(404, *args, **kwargs)
5457

5558

59+
class TimeOutError(RuntimeError):
60+
"""
61+
Custom tineout class
62+
"""
63+
def __init__(self, status_code, *args, **kwargs):
64+
super(TimeOutError, self).__init__(*args, **kwargs)
65+
66+
5667
class OVSClient(object):
5768
"""
5869
Represents the OVS client
5970
"""
71+
_logger = LogHandler.get('helpers', name='api')
6072

6173
disable_warnings(InsecurePlatformWarning)
6274
disable_warnings(InsecureRequestWarning)
@@ -249,15 +261,21 @@ def wait_for_task(self, task_id, timeout=None):
249261
"""
250262
start = time.time()
251263
finished = False
264+
previous_metadata = None
252265
while finished is False:
253266
if timeout is not None and timeout < (time.time() - start):
254-
raise RuntimeError('Waiting for task {0} has timed out.'.format(task_id))
267+
raise TimeOutError('Waiting for task {0} has timed out.'.format(task_id))
255268
task_metadata = self.get('/tasks/{0}/'.format(task_id))
256269
finished = task_metadata['status'] in ('FAILURE', 'SUCCESS')
257270
if finished is False:
258-
# print task_metadata
271+
if task_metadata != previous_metadata:
272+
OVSClient._logger.debug('Waiting for task {0}, got: {1}'.format(task_id, task_metadata))
273+
previous_metadata = task_metadata
274+
else:
275+
OVSClient._logger.debug('Still waiting for task {0}...'.format(task_id))
259276
time.sleep(1)
260277
else:
278+
OVSClient._logger.debug('Task {0} finished, got: {1}'.format(task_id, task_metadata))
261279
return task_metadata['successful'], task_metadata['result']
262280

263281
@staticmethod

helpers/disk.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,4 @@ def get_roles_from_disk(storagerouter_ip, disk_name):
9696
roles_on_disk.append(role)
9797
return roles_on_disk
9898
else:
99-
raise RuntimeError("Disk with name `{0}` not found on storagerouter `{1}`".format(disk_name,
100-
storagerouter_ip))
99+
raise RuntimeError("Disk with name `{0}` not found on storagerouter `{1}`".format(disk_name, storagerouter_ip))

helpers/domain.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,5 @@ def get_storagedrivers_in_same_domain(domain_guid):
114114
:rtype: list
115115
"""
116116

117-
return [storagedriver for storagedriver in StorageDriverList.get_storagedrivers()
118-
if domain_guid in storagedriver.storagerouter.regular_domains]
117+
return [storagedriver for storagedriver in StorageDriverList.get_storagedrivers() if domain_guid in storagedriver.storagerouter.regular_domains]
119118

helpers/hypervisor/apis/kvm/sdk.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,8 @@ def revert_to_snapshot(self, vmid, snapshot_name, flags=0):
805805
"""
806806
if not isinstance(vmid, libvirt.virDomain):
807807
vmid = self.get_vm_object(vmid)
808-
vmid.revertToSnapshot(snapshot_name, flags)
808+
snapshot = vmid.snapshotLookupByName(snapshot_name)
809+
vmid.revertToSnapshot(snapshot, flags)
809810

810811
@staticmethod
811812
def shell_safe(argument):

helpers/init_manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from ..helpers.exceptions import UnsupportedInitManager
2121

2222

23-
2423
class InitManagerSupported(object):
2524

2625
INIT = "init"

helpers/network.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
# Open vStorage is distributed in the hope that it will be useful,
1515
# but WITHOUT ANY WARRANTY of any kind.
1616
import re
17+
import socket
18+
from ovs.extensions.generic.remote import remote
19+
from ovs.log.log_handler import LogHandler
1720

1821

1922
class NetworkHelper(object):
2023
"""
2124
NetworkHelper class
2225
"""
26+
LOGGER = LogHandler.get(source="helpers", name="ci_network_helper")
2327

2428
def __init__(self):
2529
pass
@@ -29,3 +33,27 @@ def validate_ip(ip):
2933
pattern = re.compile(r"^(?<!\S)((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\b|\.\b){7}(?!\S)$")
3034
if not pattern.match(ip):
3135
raise ValueError('Not a valid IP address')
36+
37+
@staticmethod
38+
def get_free_port(listener_ip, logger=LOGGER):
39+
"""
40+
Returns a free port
41+
:param listener_ip: ip to listen on
42+
:type listener_ip: str
43+
:param logger: logging instance
44+
:type logger: ovs.log.log_handler.LogHandler
45+
:return: port number
46+
:rtype: int
47+
"""
48+
with remote(listener_ip, [socket]) as rem:
49+
listening_socket = rem.socket.socket(socket.AF_INET, socket.SOCK_STREAM)
50+
try:
51+
# Bind to first available port
52+
listening_socket.bind(('', 0))
53+
port = listening_socket.getsockname()[1]
54+
return port
55+
except socket.error as ex:
56+
logger.error('Could not bind the socket. Got {0}'.format(str(ex)))
57+
raise
58+
finally:
59+
listening_socket.close()

helpers/thread.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ThreadHelper(object):
2323
LOGGER = LogHandler.get(source='helpers', name='ci.threading')
2424

2525
@staticmethod
26-
def start_thread_with_event(target, name, args=(), kwargs={}):
26+
def start_thread_with_event(target, name, args=(), kwargs=None):
2727
"""
2828
Starts a thread and an event to it
2929
:param target: target - usually a method
@@ -35,6 +35,8 @@ def start_thread_with_event(target, name, args=(), kwargs={}):
3535
:return: a tuple with the thread and event
3636
:rtype: tuple(threading.Thread, threading.Event)
3737
"""
38+
if kwargs is None:
39+
kwargs = {}
3840
ThreadHelper.LOGGER.info('Starting thread with target {0}'.format(target))
3941
event = threading.Event()
4042
args = args + (event,)
@@ -44,13 +46,30 @@ def start_thread_with_event(target, name, args=(), kwargs={}):
4446
return thread, event
4547

4648
@staticmethod
47-
def start_thread(target, name, args=(), kwargs={}):
49+
def start_thread(target, name, args=(), kwargs=None):
50+
if kwargs is None:
51+
kwargs = {}
4852
ThreadHelper.LOGGER.info('Starting thread with target {0}'.format(target))
4953
thread = threading.Thread(target=target, args=tuple(args), kwargs=kwargs)
5054
thread.setName(str(name))
5155
thread.start()
5256
return thread
5357

58+
@staticmethod
59+
def stop_evented_threads(thread_pairs, r_semaphore=None, logger=LOGGER):
60+
for thread_pair in thread_pairs:
61+
if thread_pair[0].isAlive():
62+
thread_pair[1].set()
63+
# Wait again to sync
64+
logger.info('Syncing threads')
65+
if r_semaphore is not None:
66+
while r_semaphore.get_counter() < len(thread_pairs): # Wait for the number of threads we currently have.
67+
time.sleep(0.05)
68+
r_semaphore.wait() # Unlock them to let them stop (the object is set -> wont loop)
69+
# Wait for threads to die
70+
for thread_pair in thread_pairs:
71+
thread_pair[0].join()
72+
5473

5574
# @todo import from -> from ovs.extensions.generic.threadhelpers import Waiter instead of this when PR (https://github.com/openvstorage/framework/pull/1467) is in Fargo n unstable
5675
class Waiter(object):

packaging/debian/debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ Build-Depends: python-all (>= 2.7.2), debhelper (>= 9)
88
Package: openvstorage-automation-lib
99
Architecture: amd64
1010
Pre-Depends: python (>= 2.7.2)
11-
Depends: python-libvirt (>= 1.3.1-0), virtinst (>= 1:1.3.2), openvstorage (>= 2.8), openvstorage (<< 2.9)
11+
Depends: python-libvirt (>= 1.3.1-0), virtinst (>= 1:1.3.2), openvstorage (>= 2.8), openvstorage (<< 2.10)
1212
Description: Automation library for OpenvStorage. Contains API wrapper.

packaging/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"source_contents": "--transform 's,^,{0}-{1}/,' helpers remove setup validate __init__.py *.txt",
66
"version": {
77
"major": 0,
8-
"minor": 1
8+
"minor": 2
99
}
1010
}

0 commit comments

Comments
 (0)