Skip to content

Commit

Permalink
CP-6006 Futurize vSDK - Stage 1 (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrburke authored Oct 6, 2021
1 parent f0833f0 commit 5b5676e
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

from abc import ABCMeta
import six
from dlpx.virtualization.api import common_pb2, libs_pb2
from dlpx.virtualization.common.exceptions import IncorrectTypeError

Expand Down Expand Up @@ -100,19 +101,19 @@ class RemoteEnvironment(object):
"""
def __init__(self, name, reference, host):
if not isinstance(name, basestring):
if not isinstance(name, six.string_types):
raise IncorrectTypeError(
RemoteEnvironment,
'name',
type(name),
basestring)
six.string_types[0])
self.__name = name
if not isinstance(reference, basestring):
if not isinstance(reference, six.string_types):
raise IncorrectTypeError(
RemoteEnvironment,
'reference',
type(reference),
basestring)
six.string_types[0])
self.__reference = reference

if isinstance(host, RemoteHost):
Expand Down Expand Up @@ -171,33 +172,33 @@ class RemoteHost(object):
"""
def __init__(self, name, reference, binary_path, scratch_path):
if not isinstance(name, basestring):
if not isinstance(name, six.string_types):
raise IncorrectTypeError(
RemoteHost,
'name',
type(name),
basestring)
six.string_types[0])
self.__name = name
if not isinstance(reference, basestring):
if not isinstance(reference, six.string_types):
raise IncorrectTypeError(
RemoteHost,
'reference',
type(reference),
basestring)
six.string_types[0])
self.__reference = reference
if not isinstance(binary_path, basestring):
if not isinstance(binary_path, six.string_types):
raise IncorrectTypeError(
RemoteHost,
'binary_path',
type(binary_path),
basestring)
six.string_types[0])
self.__binary_path = binary_path
if not isinstance(scratch_path, basestring):
if not isinstance(scratch_path, six.string_types):
raise IncorrectTypeError(
RemoteHost,
'scratch_path',
type(scratch_path),
basestring)
six.string_types[0])
self.__scratch_path = scratch_path

@property
Expand Down Expand Up @@ -254,19 +255,19 @@ class RemoteUser(object):
reference: Reference of the RemoteUser.
"""
def __init__(self, name, reference):
if not isinstance(name, basestring):
if not isinstance(name, six.string_types):
raise IncorrectTypeError(
RemoteUser,
'name',
type(name),
basestring)
six.string_types[0])
self.__name = name
if not isinstance(reference, basestring):
if not isinstance(reference, six.string_types):
raise IncorrectTypeError(
RemoteUser,
'reference',
type(reference),
basestring)
six.string_types[0])
self.__reference = reference

@property
Expand Down Expand Up @@ -310,12 +311,12 @@ class Credentials(object):
username: User name.
"""
def __init__(self, username):
if not isinstance(username, basestring):
if not isinstance(username, six.string_types):
raise IncorrectTypeError(
Credentials,
'username',
type(username),
basestring)
six.string_types[0])
self.__username = username

__metaclass__ = ABCMeta
Expand All @@ -338,12 +339,12 @@ class PasswordCredentials(Credentials):
"""
def __init__(self, username, password):
super(PasswordCredentials, self).__init__(username)
if not isinstance(password, basestring):
if not isinstance(password, six.string_types):
raise IncorrectTypeError(
PasswordCredentials,
'password',
type(password),
basestring)
six.string_types[0])
self.__password = password

@property
Expand Down Expand Up @@ -378,19 +379,19 @@ class KeyPairCredentials(Credentials):
"""
def __init__(self, username, private_key, public_key):
super(KeyPairCredentials, self).__init__(username)
if not isinstance(private_key, basestring):
if not isinstance(private_key, six.string_types):
raise IncorrectTypeError(
KeyPairCredentials,
'private_key',
type(private_key),
basestring)
six.string_types[0])
self.__private_key = private_key
if not isinstance(public_key, basestring):
if not isinstance(public_key, six.string_types):
raise IncorrectTypeError(
KeyPairCredentials,
'public_key',
type(public_key),
basestring)
six.string_types[0])
self.__public_key = public_key

@property
Expand Down
69 changes: 35 additions & 34 deletions libs/src/main/python/dlpx/virtualization/libs/libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from google.protobuf.struct_pb2 import Struct

import logging
import six


__all__ = [
Expand Down Expand Up @@ -135,23 +136,23 @@ def run_bash(remote_connection, command, variables=None, use_login_shell=False,
'remote_connection',
type(remote_connection),
RemoteConnection)
if not isinstance(command, basestring):
raise IncorrectArgumentTypeError('command', type(command), basestring)
if not isinstance(command, six.string_types):
raise IncorrectArgumentTypeError('command', type(command), six.string_types[0])
if variables and not isinstance(variables, dict):
raise IncorrectArgumentTypeError(
'variables',
type(variables),
{basestring: basestring},
{six.string_types[0]: six.string_types[0]},
False)
if (variables and (not all(isinstance(variable, basestring)
if (variables and (not all(isinstance(variable, six.string_types)
for variable in variables.keys()) or
not all(isinstance(value, basestring)
not all(isinstance(value, six.string_types)
for value in variables.values()))):
raise IncorrectArgumentTypeError(
'variables',
{(type(variable), type(value))
for variable, value in variables.items()},
{basestring: basestring},
{six.string_types[0]: six.string_types[0]},
False)
if use_login_shell and not isinstance(use_login_shell, bool):
raise IncorrectArgumentTypeError(
Expand Down Expand Up @@ -198,40 +199,40 @@ def run_sync(remote_connection, source_directory, rsync_user=None,
'remote_connection',
type(remote_connection),
RemoteConnection)
if not isinstance(source_directory, basestring):
if not isinstance(source_directory, six.string_types):
raise IncorrectArgumentTypeError(
'source_directory', type(source_directory), basestring)
if rsync_user and not isinstance(rsync_user, basestring):
'source_directory', type(source_directory), six.string_types[0])
if rsync_user and not isinstance(rsync_user, six.string_types):
raise IncorrectArgumentTypeError(
'rsync_user',
type(rsync_user),
basestring,
six.string_types[0],
False)
if exclude_paths and not isinstance(exclude_paths, list):
raise IncorrectArgumentTypeError(
'exclude_paths',
type(exclude_paths),
[basestring],
[six.string_types[0]],
False)
if (exclude_paths and not all(isinstance(
path, basestring) for path in exclude_paths)):
path, six.string_types) for path in exclude_paths)):
raise IncorrectArgumentTypeError(
'exclude_paths',
[type(path) for path in exclude_paths],
[basestring],
[six.string_types[0]],
False)
if sym_links_to_follow and not isinstance(sym_links_to_follow, list):
raise IncorrectArgumentTypeError(
'sym_links_to_follow',
type(sym_links_to_follow),
[basestring],
[six.string_types[0]],
False)
if (sym_links_to_follow and not all(isinstance(link, basestring)
if (sym_links_to_follow and not all(isinstance(link, six.string_types)
for link in sym_links_to_follow)):
raise IncorrectArgumentTypeError(
'sym_links_to_follow',
[type(link) for link in sym_links_to_follow],
[basestring],
[six.string_types[0]],
False)

run_sync_request = libs_pb2.RunSyncRequest()
Expand Down Expand Up @@ -288,23 +289,23 @@ def run_powershell(remote_connection, command, variables=None, check=False):
'remote_connection',
type(remote_connection),
RemoteConnection)
if not isinstance(command, basestring):
raise IncorrectArgumentTypeError('command', type(command), basestring)
if not isinstance(command, six.string_types[0]):
raise IncorrectArgumentTypeError('command', type(command), six.string_types[0])
if variables and not isinstance(variables, dict):
raise IncorrectArgumentTypeError(
'variables',
type(variables),
{basestring: basestring},
{six.string_types[0]: six.string_types[0]},
False)
if (variables and (not all(isinstance(variable, basestring)
if (variables and (not all(isinstance(variable, six.string_types)
for variable in variables.keys()) or
not all(isinstance(value, basestring)
not all(isinstance(value, six.string_types)
for value in variables.values()))):
raise IncorrectArgumentTypeError(
'variables',
{(type(variable), type(value))
for variable, value in variables.items()},
{basestring: basestring},
{six.string_types[0]: six.string_types[0]},
False)

run_powershell_request = libs_pb2.RunPowerShellRequest()
Expand Down Expand Up @@ -353,23 +354,23 @@ def run_expect(remote_connection, command, variables=None, check=False):
'remote_connection',
type(remote_connection),
RemoteConnection)
if not isinstance(command, basestring):
raise IncorrectArgumentTypeError('command', type(command), basestring)
if not isinstance(command, six.string_types):
raise IncorrectArgumentTypeError('command', type(command), six.string_types[0])
if variables and not isinstance(variables, dict):
raise IncorrectArgumentTypeError(
'variables',
type(variables),
{basestring: basestring},
{six.string_types[0]: six.string_types[0]},
False)
if (variables and (not all(isinstance(variable, basestring)
if (variables and (not all(isinstance(variable, six.string_types)
for variable in variables.keys()) or
not all(isinstance(value, basestring)
not all(isinstance(value, six.string_types)
for value in variables.values()))):
raise IncorrectArgumentTypeError(
'variables',
{(type(variable), type(value))
for variable, value in variables.items()},
{basestring: basestring},
{six.string_types[0]: six.string_types[0]},
False)

run_expect_request = libs_pb2.RunExpectRequest()
Expand Down Expand Up @@ -455,17 +456,17 @@ def upgrade_password(password, username=None):
value into a more generic credentials supplier object.
Args:
password (basestring): Plain password string.
username (basestring, defaults to None): User name contained in the password credential supplier to return.
password (str): Plain password string.
username (str, defaults to None): User name contained in the password credential supplier to return.
Return:
Credentials supplier (dict) that supplies the given password and username.
"""
from dlpx.virtualization._engine import libs as internal_libs

if not isinstance(password, basestring):
raise IncorrectArgumentTypeError('password', type(password), basestring)
if username and not isinstance(username, basestring):
raise IncorrectArgumentTypeError('username', type(username), basestring, required=False)
if not isinstance(password, six.string_types):
raise IncorrectArgumentTypeError('password', type(password), six.string_types[0])
if username and not isinstance(username, six.string_types):
raise IncorrectArgumentTypeError('username', type(username), six.string_types[0], required=False)

upgrade_password_request = libs_pb2.UpgradePasswordRequest()
upgrade_password_request.password = password
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

import re
import six

from dlpx.virtualization.platform import validation_util as v
from dlpx.virtualization.platform.exceptions import (
Expand Down Expand Up @@ -142,7 +143,7 @@ def __add(self, migration_id, impl_name):
@staticmethod
def __validate_migration_id(migration_id, impl_name):
# First validate that the id is a string
if not isinstance(migration_id, basestring):
if not isinstance(migration_id, six.string_types):
raise MigrationIdIncorrectTypeError(migration_id, impl_name)

# Next check if the id is the right format
Expand Down Expand Up @@ -260,7 +261,7 @@ def add_snapshot(self, migration_id, snapshot_impl):
def __validate_lua_major_minor_version(migration_id, impl_name,
decorator_name, impl_getter):
# First validate that the major minor version is a string
if not isinstance(migration_id, basestring):
if not isinstance(migration_id, six.string_types):
raise MigrationIdIncorrectTypeError(migration_id, impl_name)

# Next check if the id already exists in this particular dictionary
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import absolute_import
#
# Copyright (c) 2019 by Delphix. All rights reserved.
#

import pytest
import conftest
from . import conftest
from dlpx.virtualization.platform import migration_helper as m
from dlpx.virtualization.platform.exceptions import (
MigrationIdAlreadyUsedError, MigrationIdIncorrectFormatError,
Expand Down
5 changes: 3 additions & 2 deletions platform/src/test/python/dlpx/virtualization/test_plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
#
# Copyright (c) 2019 by Delphix. All rights reserved.
#
Expand All @@ -13,8 +14,8 @@
OperationAlreadyDefinedError, PluginRuntimeError)
from mock import MagicMock, patch

import fake_generated_definitions
from fake_generated_definitions import (RepositoryDefinition,
from . import fake_generated_definitions
from .fake_generated_definitions import (RepositoryDefinition,
SnapshotDefinition,
SourceConfigDefinition)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import os
import shutil
import six
import subprocess

from dlpx.virtualization._internal import const, exceptions, file_util
Expand Down Expand Up @@ -97,7 +98,7 @@ def generate_python(name, source_dir, plugin_config_dir, schema_content):
def _make_url_refs_opaque(json):
if isinstance(json, dict):
for key in json:
if key == '$ref' and isinstance(json[key], basestring)\
if key == '$ref' and isinstance(json[key], six.string_types)\
and json[key].startswith('https://delphix.com/platform/api#'):
json.pop(key)
json['type'] = 'object'
Expand Down
Loading

0 comments on commit 5b5676e

Please sign in to comment.