Commit 31d3b918 authored by Santi Raffa's avatar Santi Raffa Committed by Jose A. Lopes
Browse files

Fix compatibility issues



* Fix GenericInstanceCreate
* Fix pylint disable annotation
* Change some assert methods to assertTrue()
Signed-off-by: default avatarSanti Raffa <rsanti@google.com>
Reviewed-by: default avatarJose A. Lopes <jabolopes@google.com>
parent fcc27323
......@@ -2778,6 +2778,9 @@ def GenericInstanceCreate(mode, opts, args):
else:
raise errors.ProgrammerError("Invalid creation mode %s" % mode)
osparams_private = opts.osparams_private or serializer.PrivateDict()
osparams_secret = opts.osparams_private or serializer.PrivateDict()
op = opcodes.OpInstanceCreate(instance_name=instance,
disks=disks,
disk_template=opts.disk_template,
......@@ -2794,8 +2797,8 @@ def GenericInstanceCreate(mode, opts, args):
hvparams=hvparams,
beparams=opts.beparams,
osparams=opts.osparams,
osparams_private=opts.osparams_private,
osparams_secret=opts.osparams_secret,
osparams_private=osparams_private,
osparams_secret=osparams_secret,
mode=mode,
start=start,
os_type=os_type,
......
......@@ -244,10 +244,10 @@ class Private(object):
return self._item
def __str__(self):
return "<{._descr}>".format(self)
return "<%s>" % self._descr
def __repr__(self):
return "Private(?, descr='{._descr}')".format(self)
return "Private(?, descr=%r)".format(self._descr)
# pylint: disable=W0212
# If it doesn't access _item directly, the call will go through __getattr__
......
......@@ -95,7 +95,8 @@ def FindDuplicates(seq):
return list(dup)
#pylint: disable=W0142 (use of *-magic in argument list)
#pylint: disable=W0142
# (use of *-magic in argument list)
def GetRepeatedKeys(*dicts):
"""Return the set of keys defined multiple times in the given dicts.
......
......@@ -182,32 +182,32 @@ class TestPrivate(unittest.TestCase):
def testLeak(self):
pDict = serializer.PrivateDict()
pDict["bar"] = "egg"
self.assertNotIn("egg", str(pDict), "Value leaked in str(PrivateDict)")
self.assertNotIn("egg", repr(pDict), "Value leaked in repr(PrivateDict)")
self.assertNotIn("egg", "{0}".format(pDict),
self.assertTrue("egg" not in str(pDict), "Value leaked in str(PrivateDict)")
self.assertTrue("egg" not in repr(pDict), "Value leak in repr(PrivateDict)")
self.assertTrue("egg" not in "{0}".format(pDict),
"Value leaked in PrivateDict.__format__")
self.assertNotIn("egg", serializer.Dump(pDict),
self.assertTrue("egg" not in serializer.Dump(pDict),
"Value leaked in serializer.Dump(PrivateDict)")
def testProperAccess(self):
pDict = serializer.PrivateDict()
pDict["bar"] = "egg"
self.assertIs("egg", pDict["bar"].Get(),
"Value not returned by Private.Get()")
self.assertIs("egg", pDict.GetPrivate("bar"),
"Value not returned by Private.GetPrivate()")
self.assertIs("egg", pDict.Unprivate()["bar"],
"Value not returned by PrivateDict.Unprivate()")
self.assertIn(
"egg",
serializer.Dump(pDict,
private_encoder=serializer.EncodeWithPrivateFields)
)
self.assertTrue("egg" is pDict["bar"].Get(),
"Value not returned by Private.Get()")
self.assertTrue("egg" is pDict.GetPrivate("bar"),
"Value not returned by Private.GetPrivate()")
self.assertTrue("egg" is pDict.Unprivate()["bar"],
"Value not returned by PrivateDict.Unprivate()")
json = serializer.Dump(pDict,
private_encoder=serializer.EncodeWithPrivateFields)
self.assertTrue("egg" in json)
def testDictGet(self):
self.assertIs("tar", serializer.PrivateDict().GetPrivate("bar", "tar"),
"Private.GetPrivate() did not handle the default case")
result = serializer.PrivateDict().GetPrivate("bar", "tar")
self.assertTrue("tar" is result,
"Private.GetPrivate() did not handle the default case")
def testZeronessPrivate(self):
self.assertTrue(serializer.Private("foo"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment