Search code examples
pythonjythonsoawlst

NameError: checkDeployStatus in script


While executing the below script to deploy SOA composites and getting NameError: checkDeployStatus.The below script deploys every composite and checks the log to see if it's deployed or not.

Deploysoa.py

  from java.io import FileInputStream
  from java.util import HashMap
  from java.util import HashSet
  from java.util import ArrayList
  from java.io import File
  from java.net import URL
  import sys
  import os
  import javax
  import java
  print '++++++++starting deployment+++++++++'
  connect('weblogic', 'password', 't3://stabc:8001')
  dirList=os.listdir(sys.argv[0])
  for jarfile in dirList:
  if (jarfile.startswith("sca_") & jarfile.endswith(".jar")):
    print 'deploying ' + jarfile + ' with ' + jarfile.replace(' ', '')[:-11] + '_cfgplan' + '.xml'
    oldstdout=sys.stdout
    sys.stdout = open("/tmp/sca_deploy.out","w")
    sca_deployComposite(serverURL, sarLocation, [overwrite], [user],   [password], [forceDefault], [configplan], [partition])
    sys.stdout = oldstdout
    print '++++++++++++++++++Checking deploy Status++++++++++++++++'
    checkDeployStatus("/tmp/sca_deploy.out")
    print '+++++++++++++++++++Test passed++++++++++++++++++++++'

def checkDeployStatus(filename):
success = false
for line in open(filename):
   if "Deploying composite success" in line:
    print '++++++++++++++++++++++++++++++Composite is Alright++++++++++++++++++++++'
   success=true
   if "error" in line:
    success=false
   if success is false:
    print line
    raise Exception("Deployment Failed")

Solution

  • It's hard to tell because the indentation is off, but it appears that checkDeployStatus is defined after it is first called which would lead to the NameError.