a unit test for the most frequently used methods in the Script class
Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>
Signed-off-by: Prasanna Santhanam <tsp@apache.org>
commons-lang is already a transitive dependency of the utils project, which allows removing some duplicated functionality.
This patch replaces StringUtils.join(String, Object...) with it's commons-lang counterpart.
It also replaces calls to String join(Iterable<? extends Object>, String) in cases where an array is already exist and it is only wrapped into a List.
Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>
The new policy is:
1. Generate a random IP.
2. Find the next available IP, start from the generated IP.
3. If we cannot find an available IP after certain times(10000 by default,
network.ipv6.search.retry.max) retry, give up.
Also ass public_ipv6_address for ipv6 address management.
Extend nics and vlans for ipv6 address.
Add dependency to com.googlecode.ipv6(java-ipv6).
Modify dhcpcommand for ipv6.
Enhanced baremetal servers support on Cisco UCS
introduce an python etree like xml helper.
Ok, this is not a new wheel. Frankly speaking, all Java XML API just suc**.
there are two popular types of XML API in java, one class is for data binding, JAXB,
XStream fall into this category. Another class is tree based, like JDOM, XOM ...
for XML api call, data binding library is painful as you have to specify the schema
that how xml stream converts to java object, which means you have to pre-define all
schemas(xsd file for JAXB, java object for XStream ...). This is not productive, because you
must add new schema when XML document grows.
Tree based library shines in this case, for it's able to dynamically create an object tree
from xml stream without any knowledge of its structure. However, all tree based
XML API library fall into below convention:
Element e = root.getChildElement("child1").getChildElement("child2").getChildElement("child3")...getChildElement("childN")
anything wrong with it???
the sadness is if there is no "child2", you will get a NPE with above code, which means you have to judge
before getting.
And, why so verbose?? why not:
Element e = root.child1.child2.child3...childN ???
Ok I am joking, it's impossible in Java the world knows Java is a static language.
but you can actually do:
Element e = root.get("child1.child2.child3");
or
List<Element> e = root.getAsList("child1.child2.child3")
this is known as XPath style(though XPATH use '/'), python etree has supported it.
so I did this toy for my UCS xml api call, it's quite like etree which is easy to use, for example:
<components.xml>
<system-integrity-checker class="com.cloud.upgrade.DatabaseUpgradeChecker">
<checker name="ManagementServerNode" class="com.cloud.cluster.ManagementServerNode"/>
<checker name="EncryptionSecretKeyChecker" class="com.cloud.utils.crypt.EncryptionSecretKeyChecker"/>
<checker name="DatabaseIntegrityChecker" class="com.cloud.upgrade.DatabaseIntegrityChecker"/>
<checker name="DatabaseUpgradeChecker" class="com.cloud.upgrade.PremiumDatabaseUpgradeChecker"/>
</system-integrity-checker>
</components.xml>
XmlObject xo = XmlObjectParser.parseFromFile("~/components.xml.in");
List<XmlObject> checkers = xo.getAsList("system-integrity-checker.checker");
then you get a list of XmlObject which represent each 'checker' element:
XmlObject firstChecker = checkers.get(0);
// firstChecker.get("name") == "ManagementServerNode"
// firstChecker.get("class") == "com.cloud.cluster.ManagementServerNode"
// firstChecker.getTag() == "checker"
// firstChecker.getText() == "" if it's <checker/>xxx</checker>, then getText() == "xxx"
example 2:
<checker name="ManagementServerNode" class="com.cloud.cluster.ManagementServerNode"/>
<system-integrity-checker class="com.cloud.upgrade.DatabaseUpgradeChecker">
<checker name="ManagementServerNode" class="com.cloud.cluster.ManagementServerNode"/>
</system-integrity-checker>
</components.xml>
yout can do:
XmlObject xo = XmlObjectParser.parseFromFile("~/components.xml.in");
XmlObject checker = xo.get("system-integrity-checker.checker");
then it returns a single object as we only have one "checker" in xml stream,
or you still do
List<XmlObject> checkers = xo.getAsList("system-integrity-checker.checker");
it returns a list which only contains one element of "checker"
if you do:
XmlObject checker = xo.get("system-integrity-checker.checker.this_middle_element_doesnt_exist.some_element");
it returns a null without any exception, so you don't have to worry if a parent element is missing when getting a leaf element
again it's not a new wheel, I just hate JAVA xml api
Improve CglibThrowableRenderer test case
Log to a separate Logger instead of the default one to avoid spurious
stack traces in test run output.
Actually verify that registering CglibThrowableRenderer with the
alternative log hierarchy actually removes call trace lines that
contains the string <generated>
This was done for performance reasons.
I also refined the regex strings and added more test cases for different
string scenarios.
Signed-off-by: Chip Childers <chip.childers@gmail.com>
As noted in the bug, several of the API command in question
are async calls. I've added a simple regex-based string cleaning
function, and have the request and response strings running through
it prior to being appended to the audit log.
Unit tests added for the new cleaning function as well.
The call to skip logging the createSSHKeyPair response remains intact
for now, although it should probably be scrubbed similarly to the
password fields.
Signed-off-by: Chip Childers <chip.childers@gmail.com>