示例#1
0
	def testGetPartialKey(self):
		print "testGetPartialKey"
		pf = PropertiesFile(self.simplePropertiesFileName)
		propertyList = pf.getPartialKey("partial.key.*")
		self.assertEqual(len(propertyList), 3)
		for key, value in propertyList:
			self.assertEqual(value, pf.get(key))
		propertyList = pf.getPartialKey("*.key.*")
		self.assertEqual(len(propertyList), 3)
		for key, value in propertyList:
			self.assertEqual(value, pf.get(key))
		propertyList = pf.getPartialKey("rubbish.*")
		self.assertEqual(len(propertyList), 0)
		propertyList = pf.getPartialKey("*.rubbish.*")
		self.assertEqual(len(propertyList), 0)
		propertyList = pf.getPartialKey("module.*.name")
		self.assertEqual(len(propertyList), 2)
		propertyList = pf.getPartialKey("*.name")
		self.assertEqual(len(propertyList), 1)
示例#2
0
	def testGet(self):
		print "testGet"
		pf = PropertiesFile(self.simplePropertiesFileName)
		val = pf.get("key")
		self.assertEqual(val, "value")
		val = pf.get("rubbish")
		self.assertEqual(val, None)
		val = pf.get("space.filled.value")
		self.assertEqual(val, "valuebit nextbit")
		val = pf.get("special-characters")
		self.assertEqual(val, r"Or@c1e@pp@dm!n")
		val = pf.get("back.slash")
		self.assertEqual(val, r"back\slash")
示例#3
0
	def testCreateTokenisedProperties(self):
		print "testCreateTokenisedProperties"
		pf = PropertiesFile(self.simplePropertiesFileName)
		tokenisedFileName = pf.createTokenisedProperties("@@_", "_@@", "testtokenisedproperties.properties")
		tokenisedFile = PropertiesFile(tokenisedFileName)
		for tpk in tokenisedFile.properties.keys():
			print tpk + "=" + tokenisedFile.get(tpk)
			if not tpk == "property.file.version":
				self.assertEqual(tokenisedFile.get(tpk), pf.get(tpk[3:][:-3]).replace("\\", r"\\"))
				self.assertEqual(tpk[:3], "@@_")
				self.assertEqual(tpk[-3:], "_@@")
		for i in range(len(self.properties)):
				if self.properties[i].strip().startswith("#") or self.properties[i].strip() == "" or self.properties[i].strip().startswith("property.file.version"):
					self.assertEqual(pf.allEntries[i].strip(), tokenisedFile.allEntries[i].strip())
		
		os.remove(tokenisedFileName)
示例#4
0
	def testValidateVersionProperty(self):
		print "testValidateVersionProperty"
		pf = PropertiesFile(self.simplePropertiesFileName)
		# default key property.file.version
		version = pf.validateVersionProperty()
		self.assertEqual(version, 1)
		# default key wrong value
		version = pf.validateVersionProperty(propertyValue="false-version")
		self.assertEqual(version, 0)
		# non-existent key
		version = pf.validateVersionProperty(propertyKey="non.key")
		self.assertEqual(version, 0)
		# default key correct version
		version = pf.validateVersionProperty(propertyValue="ENV_VERSION")
		self.assertEqual(version, 1)
		# non-existent key value exists
		version = pf.validateVersionProperty(propertyKey="non.key", propertyValue="ENV_VERSION")
		self.assertEqual(version, 0)
		# specified key value correct
		version = pf.validateVersionProperty(propertyKey="property.file.version", propertyValue="ENV_VERSION")
		self.assertEqual(version, 1)
示例#5
0
""" take a list of properties files and open them
"""
import sys, os
from propertiesutils import PropertiesFile
from propertiesutils import NonEncryptedPropertiesFile
from loggingutils import SimpleReporter
from propertiesutils import XmlProperties
logger = SimpleReporter()
xpf = XmlProperties("tmp/ant-properties.xml")
xpf.transformProperties("tmp/ant-properties.properties")
pf = PropertiesFile("tmp/ant-properties.properties")
fileList = pf.get("property.files").split(",")
for file in fileList:
	logger.report("Processing %s" % (file))
	enc = NonEncryptedPropertiesFile(file)
示例#6
0
	def testGetPasswordProperty(self):
		print "TestPropertiesFile : testGetPasswordProperty"
		pf = PropertiesFile(self.simplePropertiesFileName)
		val = pf.get("my.password.test")
		self.assertEqual(val, "mypassword")
示例#7
0
	def testGetWithEqualsSign(self):
		print "testGetWithEqualsSign"
		pf = PropertiesFile(self.simplePropertiesFileName)
		val = pf.get("contains-equals")
		self.assertEqual(val, "123=4")
示例#8
0
for each domain
	list the clusters
	check that the cluster's managed servers are up
	if not, bomb
	
this is pretty crude and may benefit from some cleverness
"""
import sys
from propertiesutils import PropertiesFile
from wlstutils import ServerConnection
from propertiesutils import XmlProperties
    
try:
	tp = XmlProperties("tmp/ant-properties.xml")
	tp.transformProperties("tmp/ant-properties.properties")
	pf = PropertiesFile("tmp/ant-properties.properties")
	adminServers = pf.getPartialKey("*.domain_name")
	for k, v in adminServers:
		prefix = k.split(".")[0]
		username = pf.get(prefix + ".admin_user")
		password = pf.get(prefix + ".admin_password")
		url = pf.get(prefix + ".admin_url")
		sc = ServerConnection(url, username, password)
		sc.logOn()
		clusters = sc.listClusters()
		for cluster in clusters:
			if not sc.clusterIsUp(cluster):
				print "[ERROR] One or more managed servers is not running"
				sys.exit(1)
	print "[INFO] all managed servers are running"
except Exception, e:
import os, sys
from propertiesutils import XmlProperties
from propertiesutils import PropertiesFile
xmlProps = XmlProperties("tmp/ant-properties.xml")
antPropertiesFile = "tmp/ant-properties.properties"
xmlProps.transformProperties(antPropertiesFile)
apf = PropertiesFile(antPropertiesFile)
# add some validation of existence of config file
configFilePath = apf.get("config.file.path")
if os.path.isfile(configFilePath):
	epf = PropertiesFile(configFilePath)
else:
	print "[ERROR] configuration properties file " + configFilePath + " does not exist"
	sys.exit("missing environment configuration file")
# add some validation of version
envVersion = apf.get("config.file.version")
if epf.validateVersionProperty(propertyValue=envVersion):
	version = epf.get("property.file.version")
	config_file_name = apf.get("config.file.name")
	tpf = epf.createTokenisedProperties("{@", "@}", "configmaps/" + config_file_name + version + ".properties")
else:
	print "[ERROR] invalid configuration file version"
	sys.exit("invalid configuration file")
示例#10
0
	def testGetConfig(self):
		print "TestDatasourceConfig : testGetConfig"
		pf = PropertiesFile("modules/testdsdetails.properties")
		dsList = pf.getPartialKey("*.db.host")
		testpost24 = 0
		testpre241 = 0
		for k, v in dsList:
			tag = k.split(".")[0]
			dsConfig = DatasourceConfig(tag, pf).getConfig()
			if pf.get(tag + ".datasource.name"):
				# post 2.4.0
				self.assertEqual(pf.get(tag + ".datasource.name"), dsConfig["name"])
				jndiList = []
				for jndiName in pf.get(tag + ".jndi.name").split(","):
					jndiList.append(jndiName.strip())
				self.assertEqual(jndiList, dsConfig["jndi"])
				testpost24 = 1
			else:
				# pre 2.4.1
				self.assertEqual(tag, dsConfig["name"])
				self.assertEqual(tag, dsConfig["jndi"][0])
				testpre241 = 1
			self.assertEqual(pf.get(tag + ".db.host"), dsConfig["host"])
			self.assertEqual(pf.get(tag + ".db.port"), dsConfig["port"])
			self.assertEqual(pf.get(tag + ".db.user"), dsConfig["user"])
			self.assertEqual(pf.get(tag + ".db.password"), dsConfig["password"])
			self.assertEqual(pf.get(tag + ".db.name"), dsConfig["dbName"])
			self.assertEqual(pf.get(tag + ".db.url"), dsConfig["url"])
			self.assertEqual(pf.get(tag + ".db.driver"), dsConfig["driver"])
			targets = []
			for target in pf.get(tag + ".target").split(","):
				targets.append(target.strip())
			self.assertEqual(targets, dsConfig["target"])
		self.assertEqual(testpost24, 1)
		self.assertEqual(testpre241, 1)
示例#11
0
	def testGetConfig(self):
		print "TestJMSResourceConfig : testGetConfig"
		pf = PropertiesFile("modules/testjmsdetails.properties")
		jmsList = pf.getPartialKey("*.jms.system.module.name")
		for k, v in jmsList:
			tag = k.split(".")[0]
			jmsConfig = JMSResourceConfig(tag, pf).getConfig()
			self.assertEqual(pf.get(tag + ".jms.system.module.name"), tag)
			if pf.get(tag + ".jms.system.module.suffix"):
				self.assertEqual(jmsConfig["module.name"], tag + "_" + pf.get(tag + ".jms.system.module.suffix"))
			else:
				self.assertEqual(jmsConfig["module.name"], tag)
			self.assertEqual(jmsConfig["base.name"], tag)
			if pf.get(tag + ".target.suffix"):
				self.assertEqual(jmsConfig["target.domain"], pf.get(tag + ".target.domain") + "_" + pf.get(tag + ".target.suffix"))
			else:
				self.assertEqual(jmsConfig["target.domain"], pf.get(tag + ".target.domain"))
			self.assertEqual(jmsConfig["datasource"], pf.get(tag + ".datasource"))
			# simply test that the number of queues is the same
			self.assertEqual(len(jmsConfig["queues"]), len(pf.getPartialKey(tag + ".queue.*.name")))
			# simply test that the number of topics is the same
			self.assertEqual(len(jmsConfig["topics"]), len(pf.getPartialKey(tag + ".topic.*.name")))
示例#12
0
def importIntoDomain():
	try:
		# Declare Variables
		sessionMBean = None
		alsbConfigurationMBean = None
		xpf = XmlProperties("tmp/ant-properties.xml")
		xpf.transformProperties("tmp/ant-properties.properties")
		pf = PropertiesFile("tmp/ant-properties.properties")
		packageHome = pf.get("package.home")
		
		# Connect to Server
		print 'Connecting to server: ', pf.get("osbadm.adminUrl")
	#		connectToServer()
		connect(pf.get("osbadm.admin_user"), pf.get("osbadm.admin_password"), pf.get("osbadm.adminUrl"))
		domainRuntime()


		# Create unique session name	
		print 'Creating unique session name'
		sessionName = createSessionName()
		print 'Created session name :', sessionName

		# Create and start session
		print 'Creating SessionMBean'
		sessionMBean = getSessionMBean(sessionName)
		print 'SessionMBean started new session'

		# obtain the ALSBConfigurationMBean instance that operates
		# on the session that has just been created. Notice that
		# the name of the mbean contains the session name.
		print 'Create ALSBConfiguration'
		alsbConfigurationMBean = findService(String(ALSBConfigurationMBean.NAME + ".").concat(sessionName), ALSBConfigurationMBean.TYPE)
		print "ALSBConfiguration MBean found", alsbConfigurationMBean
		
		
		# Perform updates or read operations in the session using alsbSession
		# sys.arg[4] is the root of the package
		print 'INFO package root is ' + packageHome
		psc_list=[]
		pscProps = PropertiesFile(packageHome + "/" + 'psc_details.properties')
		print 'INFO loaded properties from ' + packageHome + "/" + 'psc_details.properties'
		pscNames = pscProps.getPartialKey("*.pscname")
		serviceProps = []
		for k, v in pscNames:
			if pscProps.get(v + ".technology") == "osb":
				serviceProps.append((k, v))
		
		for k, pscName in serviceProps:
			print 'INFO processing serviceslist entry ' + pscName
			# sys.arg[4] is the root of the package
			if len(pscName) != 0:
				service_file= packageHome + "/" + pscProps.get(pscName + ".deployable")
				print 'INFO deployable resolved to ' , service_file
				psc_list.append(pscName + ":" + pscProps.get(pscName + ".version.label"))

				print 'Starting import of:', service_file, "on to OSB Admin Server:", pf.get("osbimp.adminUrl")

				# Read import jar file
				print 'INFO Read import jar file'
				theBytes = BinaryFile(service_file).getBytes()
				print 'INFO Import file read successfully', service_file


				# Upload Jar File
				print 'INFO Uploading Jar file'
				alsbConfigurationMBean.uploadJarFile(theBytes)
				print 'INFO Jar Uploaded'

				print 'INFO ALSB Project will now get imported'
				alsbJarInfo = alsbConfigurationMBean.getImportJarInfo()

				alsbImportPlan = alsbJarInfo.getDefaultImportPlan()
				# we are currently running all WLST with the same keystore
				# if this changes we will have to get more clever here
				alsbImportPlan.setPassphrase(pf.get("oradm.keystore.passphrase"))
				operationMap=HashMap()
				operationMap = alsbImportPlan.getOperations()
				print 'INFO Default importPlan'
				printOpMap(operationMap)
				alsbImportPlan.setPreserveExistingEnvValues(false)
				alsbImportPlan.setPreserveExistingOperationalValues(false)
				print 'INFO Modified importPlan'
				printOpMap(operationMap)
				importResult = alsbConfigurationMBean.importUploaded(alsbImportPlan)
				printDiagMap(importResult.getImportDiagnostics())

				if importResult.getFailed().isEmpty() == false:
					print 'ERROR One or more resources could not be imported properly'
					raise
				
				#customize if a customization file is specified
				#affects only the created resources
				customisationFile = service_file + ".xml"
				if(os.path.exists(customisationFile)):
					print 'INFO Loading customization File', customisationFile
					iStream = FileInputStream(customisationFile)
					customizationList = Customization.fromXML(iStream)
					alsbConfigurationMBean.customize(customizationList)

		print "INFO The MBean session has been configured for the following deployments:"		
		for psc in psc_list:
			print "\t" + psc
		deployMessage = "Deployed PSC's " + "\t" + "\n\t".join(psc_list)
		try:
			sessionMBean.activateSession(sessionName, deployMessage)
		except:
			print "ERROR problem encountered activating the session"
			print "INFO this can happen if one or more of the managed servers are not running"
			raise
			
		print "INFO Deployment of : \n\t" + "\n\t".join(psc_list) + "\nsuccessful"
	except Exception, e:
		print "ERROR Unexpected error:", sys.exc_info()[0]
		print e
		if sessionMBean:
			sessionMBean.discardSession(sessionName)
		raise