How to use xml_attr method in autotest

Best Python code snippet using autotest_python

GLIClientConfiguration.py

Source:GLIClientConfiguration.py Github

copy

Full Screen

1"""2# Copyright 1999-2005 Gentoo Foundation3# This source code is distributed under the terms of version 2 of the GNU4# General Public License as published by the Free Software Foundation, a copy5# of which can be found in the main directory of this project.6Gentoo Linux Installer7$Id: GLIClientConfiguration.py,v 1.44 2006/04/17 05:31:53 agaffney Exp $8Copyright 2004 Gentoo Technologies Inc.9The GLIClientConfiguration module contains the ClientConfiguration class10which is a singleton class that represents configuration data that is11used by the installer client during installation. Data that is part of12the actual install is contained in GLIInstallProfile.13Usage:14 from GLIClientConfiguration import ClientConfiguration15 PROCEDURE TO ADD NEW VARIABLES: (PLEASE KEEP IN ALPHABETICAL ORDER)16 1. Add a handler to the list. If the variable has children make sure you do it right.17 Look at the existing structure to get an idea.18 2. Create a section for the two or three functions.19 3. Create the get_variable_name and set_variable_name functions.20 Ensure the set function has correct error checking.21 4. If a simple value, add to the list in the general serialize() function.22 If more complex add a serialize_variable_name to the list of special cases.23 Then add the serialize_variable_name function to the section for the variable.24"""25import string, re, GLIUtility, SimpleXMLParser, os.path26import xml.dom.minidom27from GLIException import *28class ClientConfiguration:29 ##30 # Initializes the ClientConfiguration.31 def __init__(self):32 self._architecture_template = "x86"33 self._profile_uri = ""34 35 # This is the full path to the logfile36 self._log_file = "/var/log/installer.log"37 38 # This is the root mount point39 self._root_mount_point = "/mnt/gentoo"40 # Initialize some variables so we never reference a variable that never exists.41 self._dns_servers = ()42 self._network_type = None43 self._network_interface = ""44 self._network_ip = ""45 self._network_broadcast = ""46 self._network_dhcp_options = ""47 self._network_netmask = ""48 self._network_gateway = ""49 self._enable_ssh = False50 self._root_passwd = ""51 self._interactive = True52 self._kernel_modules = ()53 self._ftp_proxy = ""54 self._http_proxy = ""55 self._rsync_proxy = ""56 self._verbose = False57 self._install_mode = "normal"58 self.data = "" # used for serialization59 self._parser = SimpleXMLParser.SimpleXMLParser()60 self._parser.addHandler('client-configuration/architecture-template', self.set_architecture_template)61 self._parser.addHandler('client-configuration/dns-servers', self.set_dns_servers)62 self._parser.addHandler('client-configuration/enable-ssh', self.set_enable_ssh)63 self._parser.addHandler('client-configuration/ftp-proxy', self.set_ftp_proxy)64 self._parser.addHandler('client-configuration/http-proxy', self.set_http_proxy)65 self._parser.addHandler('client-configuration/install-mode', self.set_install_mode)66 self._parser.addHandler('client-configuration/interactive', self.set_interactive)67 self._parser.addHandler('client-configuration/kernel-modules', self.set_kernel_modules)68 self._parser.addHandler('client-configuration/log-file', self.set_log_file)69 self._parser.addHandler('client-configuration/network-interface', self.set_network_interface)70 self._parser.addHandler('client-configuration/network-ip', self.set_network_ip)71 self._parser.addHandler('client-configuration/network-broadcast', self.set_network_broadcast)72 self._parser.addHandler('client_configuration/network-dhcp-options', self.set_network_dhcp_options)73 self._parser.addHandler('client-configuration/network-netmask', self.set_network_netmask)74 self._parser.addHandler('client-configuration/network-gateway', self.set_network_gateway)75 self._parser.addHandler('client-configuration/network-type', self.set_network_type)76 self._parser.addHandler('client-configuration/profile-uri', self.set_profile_uri)77 self._parser.addHandler('client-configuration/root-mount-point', self.set_root_mount_point)78 self._parser.addHandler('client-configuration/root-passwd', self.set_root_passwd)79 self._parser.addHandler('client-configuration/rsync-proxy', self.set_rsync_proxy)80 self._parser.addHandler('client-configuration/verbose', self.set_verbose)81 ##82 # Parses the given filename populating the client_configuration.83 # @param filename the file to be parsed. This should be a URI actually.84 def parse(self, filename):85 self._parser.parse(filename)86 ##87 # Serializes the Client Configuration into an XML format that is returned.88 def serialize(self):89 fntable ={ 'architecture-template': self.get_architecture_template,90 'enable-ssh': self.get_enable_ssh,91 'ftp-proxy': self.get_ftp_proxy,92 'http-proxy': self.get_http_proxy,93 'install-mode': self.get_install_mode,94 'interactive': self.get_interactive,95 'log-file': self.get_log_file,96 'network-broadcast': self.get_network_broadcast,97 'network-dhcp-options': self.get_network_dhcp_options,98 'network-gateway': self.get_network_gateway,99 'network-interface': self.get_network_interface,100 'network-ip': self.get_network_ip,101 'network-netmask': self.get_network_netmask,102 'network-type': self.get_network_type,103 'profile-uri': self.get_profile_uri,104 'root-mount-point': self.get_root_mount_point,105 'root-passwd': self.get_root_passwd,106 'rsync-proxy': self.get_rsync_proxy,107 'verbose': self.get_verbose,108 }109 self.data = "<client-configuration>"110 for key in fntable.keys():111 self.data += "<%s>%s</%s>" % (key, fntable[key](), key)112 # Serialize the special cases.113 self.serialize_dns_servers()114 self.serialize_kernel_modules()115 # Add closing tag116 self.data += "</client-configuration>"117 118 #Finish by putting it all in nice XML.119 dom = xml.dom.minidom.parseString(self.data)120 return dom.toprettyxml()121 122 ############################################################################123 #### Architecture Template124 125 ##126 # Sets the architecture to be used for the install.127 # @param xml_path not used here.128 # @param architecture_template the architecture to be installed129 # @param xml_attr not used here.130 def set_architecture_template(self, xml_path, architecture_template, xml_attr):131 if not architecture_template in ["x86", "amd64", "ppc", "sparc", "hppa", "alpha"]:132 raise GLIException("UnsupportedArchitectureTemplateError", 'fatal','set_architecture_template', 'Architecture Template specified is not supported!')133 self._architecture_template = architecture_template134 ##135 # Returns the architecture_template136 def get_architecture_template(self):137 return self._architecture_template138 139 # This variable has a simple serialize function.140 141 ############################################################################142 #### DNS Servers List143 ##144 # Sets the dns servers145 # @param xml_path not used here.146 # @param nameservers space-separated list of nameservers147 # @param xml_attr not used here.148 def set_dns_servers(self, xml_path, nameservers, xml_attr):149 if type(nameservers) == str:150 nameservers = nameservers.split(" ")151 dns = []152 for server in nameservers:153 dns.append(server)154 self._dns_servers = tuple(dns)155 ##156 # Returns the list of dns servers157 # @param self Parameter description158 def get_dns_servers(self):159 return self._dns_servers160 ##161 # Serialization for the DNS servers162 def serialize_dns_servers(self):163 # Special Case the kernel modules164 self.data += "<dns-servers>%s</dns-servers>" % " ".join(self.get_dns_servers())165 # This variable has a simple serialize function.166 167 ############################################################################168 #### Enable SSH Decision for livecd environment169 ##170 # Choose whether or not to enable SSH.171 # @param xml_path not used here.172 # @param enable_ssh a True/False bool value here or a string173 # @param xml_attr not used here.174 def set_enable_ssh(self, xml_path, enable_ssh, xml_attr):175 if type(enable_ssh) == str:176 enable_ssh = GLIUtility.strtobool(enable_ssh)177 self._enable_ssh = enable_ssh178 ##179 # Returns the choice of whether or not to enable SSH (True/False)180 # @param self Parameter description181 def get_enable_ssh(self):182 return self._enable_ssh183 # This variable has a simple serialize function.184 185 ############################################################################186 #### FTP Proxy Address Information for livecd environment187 ##188 # Sets the FTP proxy URI189 # @param xml_path not used here.190 # @param proxy a URI191 # @param xml_attr not used here.192 def set_ftp_proxy(self, xml_path, proxy, xml_attr):193 self._ftp_proxy = proxy194 ##195 # Returns the FTP proxy.196 # @param self Parameter description197 def get_ftp_proxy(self):198 return self._ftp_proxy199 # This variable has a simple serialize function.200 201 ############################################################################202 #### HTTP Proxy Address Information for livecd environment203 ##204 # Sets the HTTP proxy URI205 # @param xml_path not used here.206 # @param proxy a URI207 # @param xml_attr not used here.208 def set_http_proxy(self, xml_path, proxy, xml_attr):209 self._http_proxy = proxy210 ##211 # Returns the HTTP proxy212 def get_http_proxy(self):213 return self._http_proxy214 # This variable has a simple serialize function.215 216 ############################################################################217 #### Install Mode218 ##219 # Sets the install mode. (currently "normal", "stage4", or "chroot")220 # @param xml_path not used here.221 # @param install_mode Install mode222 # @param xml_attr not used here.223 def set_install_mode(self, xml_path, install_mode, xml_attr):224 self._install_mode = install_mode225 ##226 # Returns install mode227 # @param self Parameter description228 def get_install_mode(self):229 return self._install_mode230 # This variable has a simple serialize function.231 232 ############################################################################233 #### Interactive Install234 ##235 # Sets whether or not to be an interactive install. (boolean)236 # @param xml_path not used here.237 # @param interactive True/False bool value or a string.238 # @param xml_attr not used here.239 def set_interactive(self, xml_path, interactive, xml_attr):240 if type(interactive) != bool:241 interactive = GLIUtility.strtobool(interactive)242 self._interactive = interactive243 ##244 # Returns bool value on interactive install choice.245 # @param self Parameter description246 def get_interactive(self):247 return self._interactive248 # This variable has a simple serialize function.249 250 ############################################################################251 #### Set Kernel Modules to be loaded for the livecd environment252 ##253 # Sets a list of modules to load on the livecd environment.254 # @param xml_path not used here.255 # @param modules string of modules256 # @param xml_attr not used here.257 def set_kernel_modules(self, xml_path, modules, xml_attr):258 self._kernel_modules = tuple(string.split(modules))259 ##260 # Returns the list of kernel modules to load on the livecd environment.261 def get_kernel_modules(self):262 return self._kernel_modules263 ##264 # Serialization for the kernel module list. joins together the modules.265 def serialize_kernel_modules(self):266 # Special Case the kernel modules267 self.data += "<kernel-modules>%s</kernel-modules>" % " ".join(self.get_kernel_modules())268 269 ############################################################################270 #### Log File Location271 ##272 # Sets the log filename.273 # @param xml_path not used here.274 # @param log_file the name of the logfile for the CC to use.275 # @param xml_attr not used here.276 def set_log_file(self, xml_path, log_file, xml_attr):277 self._log_file = log_file278 ##279 # Returns the log filename280 def get_log_file(self):281 return self._log_file282 283 # This variable has a simple serialize function.284 285 ############################################################################286 #### Network Broadcast Address for livecd environment287 ##288 # Sets the network broadcast address for the livecd environment289 # @param xml_path not used here.290 # @param broadcast the network broadcast address291 # @param xml_attr= None292 def set_network_broadcast(self, xml_path, broadcast, xml_attr=None):293 if not GLIUtility.is_ip(broadcast):294 raise GLIException("IPAddressError", 'fatal','set_network_broadcast', 'The specified broadcast is not a valid IP Address!')295 self._network_broadcast = broadcast296 297 ##298 # Returns the network broadcast address299 def get_network_broadcast(self):300 return self._network_broadcast301 # This variable has a simple serialize function.302 303 ############################################################################304 #### Network DHCP Options for livecd environment305 ##306 # Sets the network dhcp options for the livecd environment307 # @param xml_path not used here.308 # @param broadcast the dhcp options309 # @param xml_attr= None310 def set_network_dhcp_options(self, xml_path, options, xml_attr=None):311 if not GLIUtility.is_realstring(options):312 raise GLIException("BadDHCPOptionsError", 'fatal','set_network_dhcp_options', 'The specified dhcp_optioons is not a valid string!')313 self._network_dhcp_options = options314 315 ##316 # Returns the network dhcp options317 def get_network_dhcp_options(self):318 return self._network_dhcp_options319 # This variable has a simple serialize function.320 321 ############################################################################322 #### Network Gateway Address for livecd environment323 324 ##325 # Sets the network gateway for the livecd environment326 # @param xml_path not used here.327 # @param gateway the network gateway328 # @param xml_attr= None329 def set_network_gateway(self, xml_path, gateway, xml_attr=None):330 if not GLIUtility.is_ip(gateway):331 raise GLIException("IPAddressError", 'fatal', 'set_network_gateway', "The gateway IP provided is not a valid gateway!!")332 self._network_gateway = gateway333 334 ##335 # Returns the network gateway336 def get_network_gateway(self):337 return self._network_gateway338 339 # This variable has a simple serialize function.340 341 ############################################################################342 #### Network Interface Information for livecd environment343 ##344 # Sets the network interface configuration info for the livecd environment345 # @param xml_path not used here.346 # @param interface the interface to talk over347 # @param xml_attr= None348 def set_network_interface(self, xml_path, interface, xml_attr=None):349 if not GLIUtility.is_eth_device(interface):350 raise GLIException("InterfaceError", 'fatal', 'set_network_interface', "Interface " + interface + " must be a valid device!")351 self._network_interface = interface352 353 ##354 # Returns the network interface355 def get_network_interface(self):356 return self._network_interface357 # This variable has a simple serialize function.358 359 ############################################################################360 #### Network IP Address for livecd environment361 ##362 # Sets the network ip address for the livecd environment363 # @param xml_path not used here.364 # @param ip the ip address365 # @param xml_attr= None366 def set_network_ip(self, xml_path, ip, xml_attr=None):367 if not GLIUtility.is_ip(ip):368 raise GLIException("IPAddressError", 'fatal', 'set_network_ip', 'The specified IP ' + ip + ' is not a valid IP Address!')369 self._network_ip = ip370 371 ##372 # Returns the network ip address373 def get_network_ip(self):374 return self._network_ip375 376 # This variable has a simple serialize function.377 378 ############################################################################379 #### Network Netmask Address for livecd environment380 ##381 # Sets the network netmask for the livecd environment382 # @param xml_path not used here.383 # @param netmask the network netmask384 # @param xml_attr= None385 def set_network_netmask(self, xml_path, netmask, xml_attr=None):386 if not GLIUtility.is_ip(netmask):387 raise GLIException("IPAddressError", 'fatal','set_network_netmask', 'The specified netmask is not a valid IP Address!')388 else:389 # Need to guess the netmask... just in case (probably need the gateway..)390 pass391 392 self._network_netmask = netmask393 394 ##395 # Returns the network netmask396 def get_network_netmask(self):397 return self._network_netmask398 399 # This variable has a simple serialize function.400 401 402 ############################################################################403 #### Network Type Information for livecd environment (static or dhcp)404 ##405 # Sets the network configuration info for the livecd environment406 # @param xml_path not used here.407 # @param network_type the network type, either static or dhcp408 # @param xml_attr=None409 def set_network_type(self, xml_path, network_type, xml_attr):410 if not network_type in ('static', 'dhcp', 'null', 'none'):411 raise GLIException("NoSuchTypeError", 'fatal','set_network_type',"You can only have a static or dhcp network!")412 self._network_type = network_type413 ##414 # Returns the network type415 def get_network_type(self):416 return self._network_type417 # This variable has a simple serialize function.418 419 ############################################################################420 #### Install Profile URI421 422 ##423 # Sets the profile_uri for use in non-interactive installs424 # @param xml_path not used here.425 # @param profile_uri location of the profile426 # @param xml_attr not used here.427 def set_profile_uri(self, xml_path, profile_uri, xml_attr):428 if profile_uri != None and not GLIUtility.is_uri(profile_uri):429 raise GLIException("URIError", 'fatal', 'set_profile_uri',"The URI specified is not valid!")430 self._profile_uri = profile_uri431 432 ##433 # Returns the profile_uri434 def get_profile_uri(self):435 return self._profile_uri436 # This variable has a simple serialize function.437 ############################################################################438 #### Root Mount Point For New System439 ##440 # Sets the root_mount_point for the new system to be installed to441 # @param xml_path not used here.442 # @param root_mount_point new location for the root mount point443 # @param xml_attr not used here.444 def set_root_mount_point(self, xml_path, root_mount_point, xml_attr):445 self._root_mount_point = root_mount_point446 ##447 # Returns the root_mount_point448 def get_root_mount_point(self):449 return self._root_mount_point450 # This variable has a simple serialize function.451 ############################################################################452 #### Root Password Selection for livecd environment453 ##454 # Sets the root password on the livecd. This is supposed to be given a hash.455 # @param xml_path not used here.456 # @param passwd a hashed password to be set on the livecd environment.457 # @param xml_attr not used here.458 def set_root_passwd(self, xml_path, passwd, xml_attr):459 self._root_passwd = passwd460 ##461 # Returns the hash of the root password for the livecd environment462 def get_root_passwd(self):463 return self._root_passwd464 # This variable has a simple serialize function.465 466 ############################################################################467 #### RSYNC Proxy Address Information for livecd environment468 ##469 # Sets the RSYNC proxy URI470 # @param xml_path not used here.471 # @param proxy a URI472 # @param xml_attr not used here.473 def set_rsync_proxy(self, xml_path, proxy, xml_attr):474 self._rsync_proxy = proxy475 ##476 # Returns the RSYNC proxy477 def get_rsync_proxy(self):478 return self._rsync_proxy479 ##480 # Sets the Verbose mode (DEBUG mode)481 # @param xml_path not used here.482 # @param verbose flag. boolean.483 # @param xml_attr not used here.484 def set_verbose(self, xml_path, verbose, xml_attr):485 if type(verbose) == str:486 verbose = GLIUtility.strtobool(verbose)487 self._verbose = verbose488 ##489 # Returns the verbose (DEBUG) flag490 def get_verbose(self):...

Full Screen

Full Screen

junit.py

Source:junit.py Github

copy

Full Screen

...11 else:12 return elem.find(item.src, self.ns)13def xml_text(elem):14 return elem.text15def xml_attr(name):16 def get_attr(elem):17 return elem.attrib.get(name)18 return get_attr19xml_schema = make_schema(XmlGetter())20property_t = xml_schema(21 name=item(xml_attr('name'), src='.'),22 value=item(xml_attr('value'), src='.'),23)24error_t = xml_schema(25 message=item(xml_attr('message'), src='.'),26 type=opt(xml_attr('type'), src='.'),27 content=item(xml_text, src='.'),28)29test_t = xml_schema(30 error=opt(error_t, src='error'),31 failure=opt(error_t, src='failure'),32 name=item(xml_attr('name'), src='.'),33 classname=item(xml_attr('classname'), src='.'),34 time=item(xml_attr('time'), src='.') | float,35 stdout=opt(xml_text, src='system-out'),36 stderr=opt(xml_text, src='system-err'),37 properties=item(property_t, src='properties/property', multi=True),38)39testsuite_t = xml_schema(40 name=item(xml_attr('name'), src='.'),41 package=item(xml_attr('package'), src='.'),42 testcases=item(test_t, src=('testcase'), multi=True),43 tests=item(xml_attr('tests'), src='.') | int,44 errors=item(xml_attr('errors'), src='.') | int,45 failures=item(xml_attr('failures'), src='.') | int,46 skipped=opt(xml_attr('skipped'), src='.', default=0),47 skips=opt(xml_attr('skips'), src='.', default=0),48 time=item(xml_attr('time'), src='.') | float,49)50junit_single_t = xml_schema(suites=item(testsuite_t, multi=True, src='.'))51junit_many_t = xml_schema(suites=item(testsuite_t, multi=True, src='testsuite'))52def parse(fname):53 root = ET.parse(fname)54 root_tag = root.getroot().tag55 if root_tag == 'testsuite':56 s = junit_single_t57 elif root_tag == 'testsuites':58 s = junit_many_t59 else:60 return []61 return s(root)['suites']62EMBED_TEMPLATE = '''\...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful