Merge "Refactoring remote client to use new ping methods"
This commit is contained in:
commit
5806c187a0
|
@ -1,10 +1,7 @@
|
|||
import abc
|
||||
import time
|
||||
|
||||
from cafe.engine.clients.base import BaseClient
|
||||
|
||||
from cloudcafe.compute.common.clients.ping import PingClient
|
||||
|
||||
|
||||
class RemoteInstanceClient(BaseClient):
|
||||
__metaclass__ = abc.ABCMeta
|
||||
|
@ -60,16 +57,3 @@ class RemoteInstanceClient(BaseClient):
|
|||
def can_authenticate(self):
|
||||
"""Verifies a remote connection can be made to the server."""
|
||||
raise NotImplementedError
|
||||
|
||||
@staticmethod
|
||||
def _is_instance_reachable(ip_address, retry_interval, timeout):
|
||||
"""Verify the server can be pinged."""
|
||||
start = int(time.time())
|
||||
reachable = False
|
||||
while not reachable:
|
||||
reachable = PingClient.ping(ip_address)
|
||||
if reachable:
|
||||
return True
|
||||
time.sleep(retry_interval)
|
||||
if int(time.time()) - start >= timeout:
|
||||
return False
|
||||
|
|
|
@ -18,8 +18,7 @@ import os
|
|||
import re
|
||||
import time
|
||||
|
||||
from cloudcafe.common.tools import datagen
|
||||
|
||||
from IPy import IP
|
||||
from cafe.common.reporting import cclogging
|
||||
from cafe.engine.clients.remote_instance.exceptions \
|
||||
import DirectoryNotFoundException
|
||||
|
@ -28,11 +27,12 @@ from cafe.engine.clients.remote_instance.models.dir_details \
|
|||
from cafe.engine.clients.remote_instance.models.file_details \
|
||||
import FileDetails
|
||||
from cafe.engine.ssh.client import SSHAuthStrategy, SSHClient
|
||||
from cloudcafe.common.tools import datagen
|
||||
from cloudcafe.compute.common.clients.ping import PingClient
|
||||
from cloudcafe.compute.common.clients.remote_instance.base_client import \
|
||||
RemoteInstanceClient
|
||||
from cloudcafe.compute.common.exceptions import FileNotFoundException, \
|
||||
ServerUnreachable, SshConnectionException
|
||||
SshConnectionException, InvalidAddressFormat
|
||||
from cloudcafe.common.tools.md5hash import get_md5_hash
|
||||
|
||||
|
||||
|
@ -43,25 +43,21 @@ class LinuxClient(RemoteInstanceClient):
|
|||
self.client_log = cclogging.getLogger(
|
||||
cclogging.get_object_namespace(self.__class__))
|
||||
|
||||
if ip_address is None:
|
||||
raise ServerUnreachable("None")
|
||||
self.ip_address = ip_address
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.connection_timeout = connection_timeout
|
||||
|
||||
# Verify the IP address has a valid format
|
||||
try:
|
||||
IP(ip_address)
|
||||
except ValueError:
|
||||
raise InvalidAddressFormat(ip_address)
|
||||
|
||||
# Verify the server can be pinged before attempting to connect
|
||||
start = int(time.time())
|
||||
reachable = False
|
||||
while not reachable:
|
||||
reachable = PingClient.ping(ip_address)
|
||||
if reachable:
|
||||
break
|
||||
time.sleep(retry_interval)
|
||||
if int(time.time()) - start >= connection_timeout:
|
||||
raise ServerUnreachable(
|
||||
'Could not reach the server at {ip_address}'.format(
|
||||
ip_address=ip_address))
|
||||
PingClient.ping_until_reachable(ip_address,
|
||||
timeout=connection_timeout,
|
||||
interval_time=retry_interval)
|
||||
|
||||
if key is not None:
|
||||
auth_strategy = SSHAuthStrategy.KEY_STRING
|
||||
|
|
|
@ -18,17 +18,18 @@ from dateutil.parser import parse
|
|||
import re
|
||||
|
||||
from IPy import IP
|
||||
|
||||
from cafe.engine.clients.winrm_client import WinRMClient
|
||||
from cafe.common.reporting import cclogging
|
||||
from cafe.engine.clients.remote_instance.models.dir_details \
|
||||
import DirectoryDetails
|
||||
from cafe.engine.clients.remote_instance.models.file_details \
|
||||
import FileDetails
|
||||
|
||||
from cloudcafe.compute.common.clients.ping import PingClient
|
||||
from cloudcafe.compute.common.clients.remote_instance.base_client import \
|
||||
RemoteInstanceClient
|
||||
from cloudcafe.compute.common.exceptions import ServerUnreachable, \
|
||||
WinRMConnectionException
|
||||
from cloudcafe.compute.common.exceptions import WinRMConnectionException, \
|
||||
InvalidAddressFormat
|
||||
|
||||
|
||||
class WindowsClient(RemoteInstanceClient):
|
||||
|
@ -45,14 +46,12 @@ class WindowsClient(RemoteInstanceClient):
|
|||
try:
|
||||
IP(ip_address)
|
||||
except ValueError:
|
||||
raise ServerUnreachable(ip_address)
|
||||
raise InvalidAddressFormat(ip_address)
|
||||
|
||||
if not self._is_instance_reachable(
|
||||
ip_address=ip_address, retry_interval=retry_interval,
|
||||
timeout=connection_timeout):
|
||||
raise ServerUnreachable(
|
||||
'Could not reach the server at {ip_address}'.format(
|
||||
ip_address=ip_address))
|
||||
# Verify the server can be pinged before attempting to connect
|
||||
PingClient.ping_until_reachable(ip_address,
|
||||
timeout=connection_timeout,
|
||||
interval_time=retry_interval)
|
||||
|
||||
self.ip_address = ip_address
|
||||
self.username = username
|
||||
|
|
|
@ -180,6 +180,16 @@ class ServerUnreachable(Exception):
|
|||
return repr(self.message)
|
||||
|
||||
|
||||
class InvalidAddressFormat(Exception):
|
||||
def __init__(self, ip_address):
|
||||
self.message = (
|
||||
'Invalid IP address provided: {ip_address}').format(
|
||||
ip_address=ip_address)
|
||||
|
||||
def __str__(self):
|
||||
return repr(self.message)
|
||||
|
||||
|
||||
class InvalidJSON(Exception):
|
||||
def __init__(self, message, expected_response):
|
||||
self.message = ('Unexpected JSON response. '
|
||||
|
|
Loading…
Reference in New Issue