Skip to content
Snippets Groups Projects

Remove RHEL landb logic, it's no longer needed

Merged Ben Morrice requested to merge rmrhellandb into master
Files
4
+ 0
70
#!/usr/bin/python3
# Example of using the Python SUDS library to access the LANDB SOAP interface
# In Python 3, the suds-jurko port can be used: https://bitbucket.org/jurko/suds
import os
import sys
import logging
import argparse
import time
from suds.client import Client
from suds.sax.element import Element
from suds.xsd.doctor import ImportDoctor, Import
from pprint import pprint
# Client setup
url = 'https://network.cern.ch/sc/soap/soap.fcgi?v=6&WSDL'
imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
doc = ImportDoctor(imp)
client = Client(url, doctor=doc, cache=None)
# Force logger to print through stderr and add default format to messages
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stderr)
ch.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
# Get hostname
parser = argparse.ArgumentParser()
parser.add_argument('-hn', '--host_name', required=True)
args = parser.parse_args()
# Authentication
USERNAME = os.environ['IMAGECI_USER']
PASSWORD = os.environ['IMAGECI_PWD']
TEST_NODE_NAME = args.host_name
# Max number of tries against LANDB
max_num_try = 20
token = client.service.getAuthToken(USERNAME, PASSWORD, 'CERN')
authenticationHeader = Element('Auth').insert(Element('token').setText(token))
client.set_options(soapheaders=authenticationHeader)
success = False
num_try = 0
while success is False:
if num_try >= max_num_try:
logging.error("Device could not be found in LANDB after %d tries." % max_num_try)
sys.exit(1)
try:
criteria = client.factory.create("types:DeviceSearch")
criteria.Name = TEST_NODE_NAME
# Yes, this Location is mandatory, otherwise you get 'INVPATTERN#Invalid search pattern:-BADLOCATION'
criteria.Location = None
result = client.service.searchDevice(criteria)
if result:
success = True
else:
# List is empty
num_try += 1
# Wait 30 sec before trying again
time.sleep(30)
except Exception as e:
num_try += 1
# Wait 30 sec before trying again
time.sleep(30)
logging.info('Node is present in LANDB, continue with tests.')
\ No newline at end of file
Loading