Subversion Repositories DevTools

Rev

Rev 5506 | Rev 6070 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4477 dpurdie 1
<%@LANGUAGE="VBSCRIPT"%>
2
<%
3
'=====================================================
4
'       Release Manager Admin Tests
5
'       Designed to be called via AJAX and to return
6
'       JSON formatted data to dynamic page
7
'=====================================================
8
%>
9
<%
10
Option explicit
11
' Good idea to set when using redirect
12
Response.Expires = 0   ' always load the page, dont store
5168 dpurdie 13
Response.ContentType="application/json"
4477 dpurdie 14
%>
15
<!--#include file="common/conf.asp"-->
16
<!--#include file="common/globals.asp"-->
17
<!--#include file="common/qstr.asp"-->
18
<!--#include file="common/common_subs.asp"-->
19
<!--#include file="common/formating.asp"-->
5097 dpurdie 20
<!--#include file="common/release_changed.asp"-->
4477 dpurdie 21
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="common/base64encode.vbs"></SCRIPT> 
22
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT> 
23
<%
24
'------------ Variable Definition -------------
25
Dim parOpr, newitem
26
Dim result
27
 
28
' Basic Parameters
29
parOpr = QStrPar("Opr")
30
result = -1
31
 
32
' Init the output JSON class
33
'   Operations can add data
34
'   Default data will be added at the end
35
Dim oJSON
36
Set oJSON = New aspJSON
37
 
38
'
39
'   Determine the operation to be performed
4482 dpurdie 40
'   Invoke target routine
41
'   Expect:
42
'       result                    - test result
43
'       oJSON.data("emsgSummary") - Error detail
4477 dpurdie 44
'
4482 dpurdie 45
'
4477 dpurdie 46
If (parOpr = "zipTest") Then
4482 dpurdie 47
    Call zipFile
48
ElseIf (parOpr = "eventTest") Then
49
    Call sendEvent
50
ElseIf (parOpr = "emailTest") Then
51
    Call sendEmail
5172 dpurdie 52
ElseIf (parOpr = "reportEvent") Then
53
    Call reportEvent
4482 dpurdie 54
ElseIf (parOpr = "remExecTest") Then
5172 dpurdie 55
    Call remExecTest
4482 dpurdie 56
ElseIf (parOpr = "pkgAccessTest") Then
5172 dpurdie 57
    Call pkgAccessTest
5245 dpurdie 58
ElseIf (parOpr = "lxrAccessTest") Then
59
    Call lxrAccessTest
5097 dpurdie 60
 
4482 dpurdie 61
Else
62
    oJSON.data("emsgSummary") = "Unknown operation requested:" & parOpr
63
End If
4477 dpurdie 64
 
4482 dpurdie 65
'
66
'   Create JSON data for the user
67
'   Important fields
68
'       result
69
'
70
'   Debug fields
71
'       Request (Array)
72
'
73
'Write single value
74
oJSON.data("result") = result
75
 
76
' DEBUG: An array of the user provided requests
77
Set oJSON.data("Request") = oJSON.Collection()
78
Set newitem = oJSON.AddToCollection(oJSON.data("Request"))
79
Dim variableName
80
for each variableName in Request.QueryString
81
    newitem.add variableName, Request.QueryString(variableName)
82
next
83
 
84
'Return the object
85
Response.Write oJSON.JSONoutput()
5957 dpurdie 86
Set oJSON = Nothing
87
Call Destroy_All_Objects
4482 dpurdie 88
 
89
'-------------------------------------------------
90
' Function:    zipFile
91
' Description: Test the File Zipping process
92
Sub zipFile
4477 dpurdie 93
    '
94
    ' Create a test file in a known directory
95
    '
96
    Dim objZIPObject, ZipFile
97
    Dim outFile, objFSO, LocalDir, objFile
98
    Set objFSO=CreateObject("Scripting.FileSystemObject")
99
    LocalDir = Request.ServerVariables("APPL_PHYSICAL_PATH") & "release_manager\temp\"
100
 
101
    If NOT objFSO.FolderExists( LocalDir ) Then
102
        result = 1
103
        oJSON.data("emsgSummary") = "Folder not found:" & LocalDir
104
    Else
105
        ' Create a known file to zip up
106
        '
107
        outFile = LocalDir & "zipTestFile.txt"
108
        Set objFile = objFSO.CreateTextFile(outFile,True)
109
        objFile.Write "test string" & vbCrLf
110
        objFile.Close
111
 
112
        ' Zip up a test file
113
        '
114
        ZipFile = LocalDir & "zipTest.zip"
115
        If objFSO.FileExists(ZipFile) Then
116
       	    objFSO.DeleteFile ZipFile, TRUE
117
        End If
118
 
119
        On Error Resume Next
120
    	Set objZIPObject = Server.CreateObject("XStandard.Zip")
121
        If Err.Number <> 0 then
122
            result = 1
123
            oJSON.data("emsgSummary") = "Create XStandard.Zip:" & Err.Description
124
        Else
125
            objZIPObject.Pack outFile, ZipFile
126
 
127
            If objZIPObject.ErrorCode <> 0 then
128
                    result = 1
129
                    oJSON.data("emsgSummary") = "Zip Error XStandard:" & objZIPObject.ErrorCode & ":" & objZIPObject.ErrorDescription
130
            Else
131
                ' All done - must have passed
132
                result = 0
133
 
134
            End If
135
        End If
136
 
137
        '
138
        ' Clean up
139
        If objFSO.FileExists(outFile) Then
140
       	    objFSO.DeleteFile outFile, TRUE
141
        End If
142
 
143
        If objFSO.FileExists(ZipFile) Then
144
       	    objFSO.DeleteFile ZipFile, TRUE
145
        End If
146
 
147
        objZIPObject = Nothing
148
 
149
    End If
150
    set objFSO = Nothing
4482 dpurdie 151
End Sub
4477 dpurdie 152
 
4482 dpurdie 153
'-------------------------------------------------
5168 dpurdie 154
' Function:    reportEvent
155
' Description:  Create an event in the machines event log
156
 
157
Sub reportEvent
158
    Report_Event enumEVENT_ERROR, "Admin Test", "", "Release Manager test: reportEvent" 
159
    If Err.number = 0 Then
160
        result = 0
161
    Else
162
        result = 1
163
        oJSON.data("emsgSummary") = "Error:("&Err.number&"):" & Err.description
164
    End If
165
End Sub
166
 
167
'-------------------------------------------------
4482 dpurdie 168
' Function:    sendEvent
169
' Description: Send an Event to the Windows Log
170
Sub sendEvent
5168 dpurdie 171
    Send_Event enumEVENT_ERROR, "Release Manager Test Log" 
172
    If Err.number = 0 Then
173
        result = 0
174
    Else
175
        result = 1
176
        oJSON.data("emsgSummary") = "Error:("&Err.number&"):" & err.description
177
    End If
178
End Sub
179
 
180
'-------------------------------------------------
4482 dpurdie 181
' Function:     sendEmail
182
' Description:  Send an email
183
Sub sendEmail
184
   Dim Mode, Attachment, Message
185
 
186
   Attachment = Null
187
   Message = "This is a Test Email generated by the Release Manager Test."
188
   Mode = QStrPar("Mode")
189
 
190
   If Mode = "Attach" Then
191
        Attachment = Server.MapPath("images\img_reports_admin.jpg")
192
        Message = Message & " This message should have an attachment"
193
   End If
194
 
195
    Call Send_Email ( "Release Manager Notification", _
5357 dpurdie 196
                       ADMIN_EMAIL, _
4482 dpurdie 197
                       objAccessControl.UserEmail, _
198
                       "Test Email", _
199
                       Message, _
200
                       Attachment )
201
    result = Err.Number
202
    oJSON.data("emsgSummary") = Err.Description
203
    'oJSON.data("Info1") = Mode
204
    'oJSON.data("Info2") = Attachment
205
End Sub
206
 
207
'-------------------------------------------------
5172 dpurdie 208
' Function:    remExecTest
209
' Description: Ensure that we can communicate with the package server
210
 
211
Sub remExecTest
4482 dpurdie 212
 
5172 dpurdie 213
    Dim objRC: Set objRC = New ReleaseChanged
214
    Dim rv
4482 dpurdie 215
 
5172 dpurdie 216
    Call objRC.TestAccess(request.servervariables("server_name"))
217
    rv = objRc.last_resultCode
4482 dpurdie 218
    If rv = 0 Then
219
        result = 0
220
    Else
221
        result = 1
5172 dpurdie 222
        oJSON.data("emsgSummary") = "Error:("&rv&"), " & objRc.last_errorMsg
4482 dpurdie 223
    End If
5172 dpurdie 224
    Set objRC = Nothing
4482 dpurdie 225
End Sub
226
 
227
'-------------------------------------------------
5172 dpurdie 228
' Function:    pkgAccessTest
4482 dpurdie 229
' Description: Test dpkg_archive access - can we map it
4477 dpurdie 230
'
5172 dpurdie 231
Sub pkgAccessTest
4477 dpurdie 232
 
5172 dpurdie 233
    If testArchiveAccessPkg("","") Then
4482 dpurdie 234
        result = 0
235
    Else
236
        result = 1
5172 dpurdie 237
        oJSON.data("emsgSummary") = "Archive not responding"
4482 dpurdie 238
    End If
239
End Sub
4477 dpurdie 240
 
5245 dpurdie 241
'-------------------------------------------------
242
' Function:    lxrAccessTest
243
' Description: Test dpkg_archive access - can we map it
244
'
245
Sub lxrAccessTest
246
 
247
    Dim oXMLHTTP
248
    Dim testUrl
249
    Dim testAccess
250
    testAccess = False
251
    testUrl = LXR_URL
252
    Set oXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.3.0")
253
 
254
    ' Use error handling in case dpkg_archive is not available
255
    ' Use HEAD to test existence
256
    Err.Clear
257
    On Error Resume Next
258
    oXMLHTTP.Open "HEAD", testUrl, False
259
    oXMLHTTP.Send
260
 
261
    ' Do not combine the next two If statments - it will not work
262
    If Err.Number = 0  Then
263
    If oXMLHTTP.Status = 200 Then 
264
        testAccess = True
265
    End If
266
    End If
267
    On Error Goto 0
268
 
269
    If testAccess Then
270
        result = 0
271
    Else
272
        result = 1
273
        oJSON.data("emsgSummary") = "LXR Server not responding"
274
    End If
275
End Sub
276
 
4477 dpurdie 277
%>