mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Check existence without an exception
Related to saltstack/salt#27089 Saltcloud virtualbox provider
This commit is contained in:
parent
5b9f99a3fc
commit
3a27c9bbf6
@ -329,3 +329,21 @@ def vb_xpcom_to_attribute_dict(xpcom
|
||||
]
|
||||
|
||||
return dict(attribute_tuples)
|
||||
|
||||
|
||||
def vb_machine_exists(name):
|
||||
try:
|
||||
vbox = vb_get_manager()
|
||||
vbox.findMachine(name)
|
||||
return True
|
||||
except Exception as e:
|
||||
if isinstance(e.message, str):
|
||||
message = e.message
|
||||
elif isinstance(e.msg, str):
|
||||
message = e.msg
|
||||
else:
|
||||
message = ""
|
||||
if 0 > message.find("Could not find a registered machine named"):
|
||||
log.error(message)
|
||||
|
||||
return False
|
||||
|
@ -167,7 +167,8 @@ class VirtualboxProviderTest(integration.ShellCase):
|
||||
# # if test instance is still present, delete it
|
||||
# if ret in query:
|
||||
# # self.run_cloud('-d {0} --assume-yes'.format(INSTANCE_NAME))
|
||||
virtualbox.vb_destroy_machine(INSTANCE_NAME)
|
||||
if virtualbox.vb_machine_exists(INSTANCE_NAME):
|
||||
virtualbox.vb_destroy_machine(INSTANCE_NAME)
|
||||
|
||||
|
||||
class BaseVirtualboxTests(unittest.TestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user