Rev 4482 | Blame | Last modification | View Log | RSS feed
<%@LANGUAGE="VBSCRIPT"%><%'=====================================================' Release Manager Admin Tests' Designed to be called via AJAX and to return' JSON formatted data to dynamic page'=====================================================%><%Option explicit' Good idea to set when using redirectResponse.Expires = 0 ' always load the page, dont store%><!--#include file="common/conf.asp"--><!--#include file="common/globals.asp"--><!--#include file="common/qstr.asp"--><!--#include file="common/common_subs.asp"--><!--#include file="common/formating.asp"--><!--#include file="common/release_changed.asp"--><SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="common/base64encode.vbs"></SCRIPT><SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT><%'------------ Variable Definition -------------Dim parOpr, newitemDim result' Basic ParametersparOpr = QStrPar("Opr")result = -1' Init the output JSON class' Operations can add data' Default data will be added at the endDim oJSONSet oJSON = New aspJSON'' Determine the operation to be performed' Invoke target routine' Expect:' result - test result' oJSON.data("emsgSummary") - Error detail''If (parOpr = "zipTest") ThenCall zipFileElseIf (parOpr = "eventTest") ThenCall sendEventElseIf (parOpr = "emailTest") ThenCall sendEmailElseIf (parOpr = "emailWshTest") ThenCall sendWshEmailElseIf (parOpr = "remExecTest") ThenCall remExecElseIf (parOpr = "pkgAccessTest") ThenCall pkgAccessElseIf (parOpr = "ddpTest") ThenCall ddpTestElseoJSON.data("emsgSummary") = "Unknown operation requested:" & parOprEnd If'' Create JSON data for the user' Important fields' result'' Debug fields' Request (Array)''Write single valueoJSON.data("result") = result' DEBUG: An array of the user provided requestsSet oJSON.data("Request") = oJSON.Collection()Set newitem = oJSON.AddToCollection(oJSON.data("Request"))Dim variableNamefor each variableName in Request.QueryStringnewitem.add variableName, Request.QueryString(variableName)next'Return the objectResponse.Write oJSON.JSONoutput()Sub ddpTestDim rvDim objRC: Set objRC = New ReleaseChangedCall objRC.Run_ReleaseChanged(62884,1042919,enumRELEASE_CHANGE_MODE_PKG_ADDED, true)rv = objRC.last_resultCodeSet objRC = NothingIf rv = 0 Thenresult = 0Elseresult = 1oJSON.data("emsgSummary") = "Error:("&rv&")"End IfEnd Sub'-------------------------------------------------' Function: ddpTest' Description:' C:\WINDOWS\system32\cmd.exe" /c C:\clearcase\dpurdie_manager_suite\Release_Manager\scripts\bin\plink.exe -ssh -batch releasem@auperaarc01.vix.local -pw releasem "sudo ~/sbin/make_test_access;"Sub ddpTest1Dim objWSH, rv, wCmdLineDim plinkPath, plinkCmd, archiveServer, uname, upasswd, sudoCmdDim sqry: sqry = "SELECT * FROM BUILD_SERVICE_CONFIG WHERE SERVICE='ARCHIVE SERVER'"Dim rsTempSet rsTemp = OraDatabase.DbCreateDynaset( sqry , cint(0) )archiveServer = rsTemp("config")rsTemp.Close()Set rsTemp = NothingDim pArchive_Path : pArchive_Path = "dpkg_archive"Dim apkg_name : apkg_name = "pkg_name"Dim apkg_version : apkg_version = "pkg_version"Dim artag_id : artag_id = "rtag_id"Dim apkg_id : apkg_id = "pkg_id"Dim apv_id : apv_id = "pv_id"Dim aproj_id : aproj_id = "proj_id"Dim amode_id : amode_id = "mode_id"sudoCmd = "~/sbin/make_release_changed" &_" archive=" & pArchive_Path &_" pkg_name='\""" & apkg_name & "\""'" &_" pkg_version='\"""& apkg_version &"\""'" &_" rtag_id="& artag_id &_" pkg_id=" & apkg_id &_" pv_id="& apv_id &_" proj_id="& aproj_id &_" mode_id="& amode_iduname = "releasem"upasswd = "releasem"plinkPath = Request.ServerVariables("APPL_PHYSICAL_PATH") & "Release_Manager\scripts\bin\plink.exe"plinkCmd = "-ssh -batch " & uname & "@" & archiveServer & " -pw " & upasswd & " ""sudo " & sudoCmd & ";"""wCmdLine = plinkPath & " " & plinkCmdSet objWSH = Server.CreateObject("WScript.Shell")rv = objWSH.Run (wCmdLine, 0, TRUE)Set objWSH = NothingIf rv = 105 Thenresult = 0Elseresult = 1oJSON.data("emsgSummary") = "Error:("&rv&")" & wCmdLineEnd IfEnd Sub'-------------------------------------------------' Function: zipFile' Description: Test the File Zipping processSub zipFile'' Create a test file in a known directory'Dim objZIPObject, ZipFileDim outFile, objFSO, LocalDir, objFileSet objFSO=CreateObject("Scripting.FileSystemObject")LocalDir = Request.ServerVariables("APPL_PHYSICAL_PATH") & "release_manager\temp\"If NOT objFSO.FolderExists( LocalDir ) Thenresult = 1oJSON.data("emsgSummary") = "Folder not found:" & LocalDirElse' Create a known file to zip up'outFile = LocalDir & "zipTestFile.txt"Set objFile = objFSO.CreateTextFile(outFile,True)objFile.Write "test string" & vbCrLfobjFile.Close' Zip up a test file'ZipFile = LocalDir & "zipTest.zip"If objFSO.FileExists(ZipFile) ThenobjFSO.DeleteFile ZipFile, TRUEEnd IfOn Error Resume NextSet objZIPObject = Server.CreateObject("XStandard.Zip")If Err.Number <> 0 thenresult = 1oJSON.data("emsgSummary") = "Create XStandard.Zip:" & Err.DescriptionElseobjZIPObject.Pack outFile, ZipFileIf objZIPObject.ErrorCode <> 0 thenresult = 1oJSON.data("emsgSummary") = "Zip Error XStandard:" & objZIPObject.ErrorCode & ":" & objZIPObject.ErrorDescriptionElse' All done - must have passedresult = 0End IfEnd If'' Clean upIf objFSO.FileExists(outFile) ThenobjFSO.DeleteFile outFile, TRUEEnd IfIf objFSO.FileExists(ZipFile) ThenobjFSO.DeleteFile ZipFile, TRUEEnd IfobjZIPObject = NothingEnd Ifset objFSO = NothingEnd Sub'-------------------------------------------------' Function: sendEvent' Description: Send an Event to the Windows LogSub sendEventDim objWSH, rvSet objWSH = Server.CreateObject("WScript.Shell")rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onRaiseEvent", 0, TRUE)Set objWSH = NothingIf rv = 0 Thenresult = 0Elseresult = 1oJSON.data("emsgSummary") = "Error:("&rv&")"End IfEnd Sub'-------------------------------------------------' Function: sendEmail' Description: Send an emailSub sendEmailDim Mode, Attachment, MessageAttachment = NullMessage = "This is a Test Email generated by the Release Manager Test."Mode = QStrPar("Mode")If Mode = "Attach" ThenAttachment = Server.MapPath("images\img_reports_admin.jpg")Message = Message & " This message should have an attachment"End IfCall Send_Email ( "Release Manager Notification", _adminEmail, _objAccessControl.UserEmail, _"Test Email", _Message, _Attachment )result = Err.NumberoJSON.data("emsgSummary") = Err.Description'oJSON.data("Info1") = Mode'oJSON.data("Info2") = AttachmentEnd Sub'-------------------------------------------------' Function: sendWshEmail' Description: Send an email from a Wsh ScriptSub sendWshEmailDim objWSH, rvSet objWSH = Server.CreateObject("WScript.Shell")rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onTestMail", 0, TRUE)Set objWSH = NothingIf rv = 0 Thenresult = 0Elseresult = 1oJSON.data("emsgSummary") = "Error:("&rv&")"End IfEnd Sub'-------------------------------------------------' Function: remExec' Description: Test Release Manager Remote cmd ExecutionSub remExecDim objWSH, rvSet objWSH = Server.CreateObject("WScript.Shell")rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onTestArchiveAccess", 0, TRUE)Set objWSH = NothingIf rv = 0 Thenresult = 0Elseresult = 1oJSON.data("emsgSummary") = "Error:("&rv&")"End IfEnd Sub'-------------------------------------------------' Function: pkgAccess' Description: Test dpkg_archive access - can we map it'Sub pkgAccessDim objWSH, rvSet objWSH = Server.CreateObject("WScript.Shell")rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onTestMapArchive", 0, TRUE)Set objWSH = NothingIf rv = 0 Thenresult = 0Elseresult = 1oJSON.data("emsgSummary") = "Error:("&rv&")"End IfEnd Sub%>