Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new module DataMigration #4298

Merged
merged 23 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4434f5c
Adding initial settings to module
ashutoshsuman99 Jan 5, 2022
c7e0a66
Working on Linter, License and Cred scan errors
ashutoshsuman99 Jan 6, 2022
0a872ea
Working on Static analysis error
ashutoshsuman99 Jan 6, 2022
8f81634
Hiding Register-ir commands for now
ashutoshsuman99 Jan 6, 2022
7ec01a5
Lint and Integration Tests solving
ashutoshsuman99 Jan 6, 2022
56c1c53
Unhiding register-ir command and adding windows test to assessment co…
ashutoshsuman99 Jan 6, 2022
bccfbc4
Making error messages proper
ashutoshsuman99 Jan 6, 2022
3a219d5
Nit changes from comments
ashutoshsuman99 Jan 10, 2022
08453c2
MultiServer support for Assessment and nit changes
ashutoshsuman99 Jan 11, 2022
9b78ff2
Adding Proper Json format, lower case for access, seperate util for W…
ashutoshsuman99 Jan 13, 2022
61c2443
Correcting Lint and Static errors
ashutoshsuman99 Jan 13, 2022
b93ced7
Removing to-* from command names
ashutoshsuman99 Jan 14, 2022
353e310
Adding correct error formats
ashutoshsuman99 Jan 14, 2022
224c703
Removing Update operation from DatabaseMigration
ashutoshsuman99 Jan 17, 2022
0fda2bb
Updating readme and help
ashutoshsuman99 Jan 17, 2022
cff3ee7
Nit: Readme corrections
ashutoshsuman99 Jan 17, 2022
330453f
Added CLI Test Cases
sagangwar Jan 18, 2022
8acf3a7
Removed IR AuthKeys and Unused Imports
sagangwar Jan 18, 2022
699a966
Adding Default IR Program files path for 32-bit error
ashutoshsuman99 Jan 24, 2022
ac73167
Nit and Static analysis fix
ashutoshsuman99 Jan 24, 2022
5794c5a
Added File Extension Validation
sagangwar Jan 24, 2022
5d3366c
Removed unnecessary spaces and fixed static analysis Issues
sagangwar Jan 24, 2022
75edbf6
Deferred IR path and MSI Extension validations
sagangwar Jan 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Unhiding register-ir command and adding windows test to assessment co…
…mmand
  • Loading branch information
ashutoshsuman99 committed Jan 6, 2022
commit 56c1c53800c291bd090c49fdc728d6b70faf1f5f
22 changes: 11 additions & 11 deletions src/datamigration/azext_datamigration/manual/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
az datamigration get-assessment --config-file-path "C:\\Users\\user\\document\\config.json"
"""

# helps['datamigration register-integration-runtime'] = """
# type: command
# short-summary: Register Sql Migration Service on Integration Runtime
# examples:
# - name: Register Sql Migration Service on Self Hosted Integration Runtime.
# text: |-
# az datamigration register-integration-runtime --auth-key "IR@00000-0000000-000000-aaaaa-bbbb-cccc"
# - name: Install Integration Runtime and register a Sql Migration Service on it.
# text: |-
# az datamigration register-integration-runtime --auth-key "IR@00000-0000000-000000-aaaaa-bbbb-cccc" --ir-path "C:\\Users\\user\\Downloads\\IntegrationRuntime.msi"
# """
helps['datamigration register-integration-runtime'] = """
type: command
short-summary: Register Sql Migration Service on Integration Runtime
examples:
- name: Register Sql Migration Service on Self Hosted Integration Runtime.
text: |-
az datamigration register-integration-runtime --auth-key "IR@00000-0000000-000000-aaaaa-bbbb-cccc"
- name: Install Integration Runtime and register a Sql Migration Service on it.
text: |-
az datamigration register-integration-runtime --auth-key "IR@00000-0000000-000000-aaaaa-bbbb-cccc" --ir-path "C:\\Users\\user\\Downloads\\IntegrationRuntime.msi"
"""
6 changes: 3 additions & 3 deletions src/datamigration/azext_datamigration/manual/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ def load_arguments(self, _):
c.argument('config_file_path', type=str, help='Path of the ConfigFile')
c.argument('overwrite', help='Enable this parameter to overwrite the existing assessment report')

# with self.argument_context('datamigration register-integration-runtime') as c:
# c.argument('auth_key', type=str, help='AuthKey of Sql Migration Service')
# c.argument('ir_path', type=str, help='Path of Integration Runtime MSI')
with self.argument_context('datamigration register-integration-runtime') as c:
c.argument('auth_key', type=str, help='AuthKey of Sql Migration Service')
c.argument('ir_path', type=str, help='Path of Integration Runtime MSI')
8 changes: 4 additions & 4 deletions src/datamigration/azext_datamigration/manual/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def load_command_table(self, _):
) as g:
g.custom_command('', 'datamigration_assessment')

# with self.command_group(
# 'datamigration register-integration-runtime'
# ) as g:
# g.custom_command('', 'datamigration_register_ir')
with self.command_group(
'datamigration register-integration-runtime'
) as g:
g.custom_command('', 'datamigration_register_ir')
185 changes: 96 additions & 89 deletions src/datamigration/azext_datamigration/manual/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import subprocess
import time
import urllib.request
# import winreg
from zipfile import ZipFile


Expand All @@ -32,6 +31,10 @@ def datamigration_assessment(connection_string=None,
config_file_path=None):

try:

if not platform.system().__contains__('Windows'):
ashutoshsuman99 marked this conversation as resolved.
Show resolved Hide resolved
raise Exception("This command cannot be run in non-windows environment")

defaultOutputFolder = get_default_output_folder()

# Assigning base folder path
Expand Down Expand Up @@ -114,124 +117,128 @@ def get_default_output_folder():
return defaultOutputPath


# # -----------------------------------------------------------------------------------------------------------------
# # Register Sql Migration Service on IR command Implementation.
# # -----------------------------------------------------------------------------------------------------------------
# def datamigration_register_ir(auth_key,
# ir_path=None):
# -----------------------------------------------------------------------------------------------------------------
# Register Sql Migration Service on IR command Implementation.
# -----------------------------------------------------------------------------------------------------------------
def datamigration_register_ir(auth_key,
ir_path=None):

# osPlatform = platform.system()
osPlatform = platform.system()

# if not osPlatform.__contains__('Windows'):
# raise Exception("This command cannot be run in non-windows environment")
if not osPlatform.__contains__('Windows'):
raise Exception("This command cannot be run in non-windows environment")

# if not is_user_admin():
# raise Exception("Failed: You do not have Administrator rights to run this command! Please re-run this command as an Administrator!")
# validate_input(auth_key)
# if ir_path is not None:
# if not os.path.exists(ir_path):
# raise Exception(f"Invalid gateway path : {ir_path}")
# install_gateway(ir_path)
if not is_user_admin():
raise Exception("Failed: You do not have Administrator rights to run this command! Please re-run this command as an Administrator!")
validate_input(auth_key)
if ir_path is not None:
if not os.path.exists(ir_path):
raise Exception(f"Invalid gateway path : {ir_path}")
install_gateway(ir_path)

# register_ir(auth_key)
register_ir(auth_key)
ashutoshsuman99 marked this conversation as resolved.
Show resolved Hide resolved


# # -----------------------------------------------------------------------------------------------------------------
# # Helper function to check whether the command is run as admin.
# # -----------------------------------------------------------------------------------------------------------------
# def is_user_admin():
# try:
# isAdmin = os.getuid() == 0
# except AttributeError:
# isAdmin = ctypes.windll.shell32.IsUserAnAdmin() != 0
# -----------------------------------------------------------------------------------------------------------------
# Helper function to check whether the command is run as admin.
# -----------------------------------------------------------------------------------------------------------------
def is_user_admin():

try:
isAdmin = os.getuid() == 0
except AttributeError:
isAdmin = ctypes.windll.shell32.IsUserAnAdmin() != 0

# return isAdmin
return isAdmin


# # -----------------------------------------------------------------------------------------------------------------
# # Helper function to validate key input.
# # -----------------------------------------------------------------------------------------------------------------
# def validate_input(key):
# if key == "":
# raise Exception("Failed: IR Auth key is empty")
# -----------------------------------------------------------------------------------------------------------------
# Helper function to validate key input.
# -----------------------------------------------------------------------------------------------------------------
def validate_input(key):
if key == "":
ashutoshsuman99 marked this conversation as resolved.
Show resolved Hide resolved
raise Exception("Failed: IR Auth key is empty")


# -----------------------------------------------------------------------------------------------------------------
# Helper function to check whether SHIR is installed or not.
# -----------------------------------------------------------------------------------------------------------------
def check_whether_gateway_installed(name):

# # -----------------------------------------------------------------------------------------------------------------
# # Helper function to check whether SHIR is installed or not.
# # -----------------------------------------------------------------------------------------------------------------
# def check_whether_gateway_installed(name):
import winreg
kairu-ms marked this conversation as resolved.
Show resolved Hide resolved
# Connecting to key in registry
accessRegistry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)

# # Connecting to key in registry
# accessRegistry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
# Get the path of Installed softwares
accessKey = winreg.OpenKey(accessRegistry, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")

# # Get the path of Installed softwares
# accessKey = winreg.OpenKey(accessRegistry, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
for i in range(0, winreg.QueryInfoKey(accessKey)[0]):

ashutoshsuman99 marked this conversation as resolved.
Show resolved Hide resolved
# for i in range(0, winreg.QueryInfoKey(accessKey)[0]):
installedSoftware = winreg.EnumKey(accessKey, i)
installedSoftwareKey = winreg.OpenKey(accessKey, installedSoftware)
try:
displayName = winreg.QueryValueEx(installedSoftwareKey, r"DisplayName")[0]
if name in displayName:
ashutoshsuman99 marked this conversation as resolved.
Show resolved Hide resolved
return True
except:
pass

# installedSoftware = winreg.EnumKey(accessKey, i)
# installedSoftwareKey = winreg.OpenKey(accessKey, installedSoftware)
# try:
# displayName = winreg.QueryValueEx(installedSoftwareKey, r"DisplayName")[0]
# if name in displayName:
# return True
# except:
# pass
return False

# return False

# -----------------------------------------------------------------------------------------------------------------
# Helper function to install SHIR
# -----------------------------------------------------------------------------------------------------------------
def install_gateway(path):

# # -----------------------------------------------------------------------------------------------------------------
# # Helper function to install SHIR
# # -----------------------------------------------------------------------------------------------------------------
# def install_gateway(path):
if check_whether_gateway_installed("Microsoft Integration Runtime"):
print("Microsoft Integration Runtime is alreasy installed")
ashutoshsuman99 marked this conversation as resolved.
Show resolved Hide resolved
return

# if check_whether_gateway_installed("Microsoft Integration Runtime"):
# print("Microsoft Integration Runtime is alreasy installed")
# return
print("Start Gateway installation")

# print("Start Gateway installation")
installCmd = f'msiexec.exe /i "{path}" /quiet /passive'
subprocess.call(installCmd, shell=False)
time.sleep(30)

# installCmd = f'msiexec.exe /i "{path}" /quiet /passive'
# subprocess.call(installCmd, shell=False)
# time.sleep(30)
print("Succeed to install gateway")
ashutoshsuman99 marked this conversation as resolved.
Show resolved Hide resolved

# print("Succeed to install gateway")

# -----------------------------------------------------------------------------------------------------------------
# Helper function to register Sql Migration Service on IR
# -----------------------------------------------------------------------------------------------------------------
def register_ir(key):
print(f"Start to register IR with key: {key}")

# # -----------------------------------------------------------------------------------------------------------------
# # Helper function to register Sql Migration Service on IR
# # -----------------------------------------------------------------------------------------------------------------
# def register_ir(key):
# print(f"Start to register IR with key: {key}")
cmdFilePath = get_cmd_file_path()

# cmdFilePath = get_cmd_file_path()
directoryPath = os.path.dirname(cmdFilePath)
parentDirPath = os.path.dirname(directoryPath)

# directoryPath = os.path.dirname(cmdFilePath)
# parentDirPath = os.path.dirname(directoryPath)
dmgCmdPath = os.path.join(directoryPath, "dmgcmd.exe")
regIRScriptPath = os.path.join(parentDirPath, "PowerShellScript", "RegisterIntegrationRuntime.ps1")

# dmgCmdPath = os.path.join(directoryPath, "dmgcmd.exe")
# regIRScriptPath = os.path.join(parentDirPath, "PowerShellScript", "RegisterIntegrationRuntime.ps1")
portCmd = f'{dmgCmdPath} -EnableRemoteAccess 8060'
irCmd = f'powershell -command "& \'{regIRScriptPath}\' -gatewayKey {key}"'

# portCmd = f'{dmgCmdPath} -EnableRemoteAccess 8060'
# irCmd = f'powershell -command "& \'{regIRScriptPath}\' -gatewayKey {key}"'
subprocess.call(portCmd, shell=False)
subprocess.call(irCmd, shell=False)

# subprocess.call(portCmd, shell=False)
# subprocess.call(irCmd, shell=False)

# -----------------------------------------------------------------------------------------------------------------
# Helper function to get SHIR script path
# -----------------------------------------------------------------------------------------------------------------
def get_cmd_file_path():

# # -----------------------------------------------------------------------------------------------------------------
# # Helper function to get SHIR script path
# # -----------------------------------------------------------------------------------------------------------------
# def get_cmd_file_path():
# try:
# # Connecting to key in registry
# accessRegistry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
import winreg
try:
# Connecting to key in registry
accessRegistry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)

# # Get the path of Integration Runtime
# accessKey = winreg.OpenKey(accessRegistry, r"SOFTWARE\Microsoft\DataTransfer\DataManagementGateway\ConfigurationManager")
# accessValue = winreg.QueryValueEx(accessKey, r"DiacmdPath")[0]
# Get the path of Integration Runtime
accessKey = winreg.OpenKey(accessRegistry, r"SOFTWARE\Microsoft\DataTransfer\DataManagementGateway\ConfigurationManager")
accessValue = winreg.QueryValueEx(accessKey, r"DiacmdPath")[0]

# return accessValue
# except Exception as e:
# raise Exception("Failed: No installed IR found!") from e
return accessValue
except Exception as e:
raise Exception("Failed: No installed IR found!") from e