commit 72539d5455d942b0b68ecd54f693e2a3bce29a54
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Tue Jun 3 16:42:35 2014 +0200
Add tests for common functionality
tests/base.py | 28 ++++++
tests/test_config.py | 186 +++++++++++++++++++++++++++++++++++++
tests/test_esx.py | 56 +++++++++++
tests/test_libvirtd.py | 77 +++++++++++++++
tests/test_satellite.py | 157 +++++++++++++++++++++++++++++++
tests/test_subscriptionmanager.py | 7 ++
tests/test_virtwho.py | 131 ++++++++++++++++++++++++++
7 files changed, 642 insertions(+), 0 deletions(-)
---
diff --git a/tests/base.py b/tests/base.py
new file mode 100644
index 0000000..d4edeff
--- /dev/null
+++ b/tests/base.py
@@ -0,0 +1,28 @@
+"""
+Basic module for tests,
+
+Copyright (C) 2014 Radek Novacek <rnovacek(a)redhat.com>
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+"""
+
+
+# hack to use unittest2 on python <= 2.6, unittest otherwise
+# based on python version
+import sys
+if sys.version_info[0] > 2 or sys.version_info[1] > 6:
+ import unittest
+else:
+ import unittest2 as unittest
diff --git a/tests/test_config.py b/tests/test_config.py
new file mode 100644
index 0000000..f549b1c
--- /dev/null
+++ b/tests/test_config.py
@@ -0,0 +1,186 @@
+"""
+Test reading and writing configuration files.
+
+Copyright (C) 2014 Radek Novacek <rnovacek(a)redhat.com>
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+"""
+
+
+import os
+import shutil
+from config import ConfigManager, InvalidOption
+from tempfile import mkdtemp
+from base import unittest
+
+
+class TestReadingConfigs(unittest.TestCase):
+ def setUp(self):
+ self.config_dir = mkdtemp()
+ self.addCleanup(shutil.rmtree, self.config_dir)
+
+ def testEmptyConfig(self):
+ manager = ConfigManager(self.config_dir)
+ self.assertEqual(len(manager.configs), 0)
+
+ def testBasicConfig(self):
+ with open(os.path.join(self.config_dir, "test.conf"), "w") as
f:
+ f.write("""
+[test]
+type=esx
+server=1.2.3.4
+username=admin
+password=password
+owner=root
+env=staging
+""")
+
+ manager = ConfigManager(self.config_dir)
+ self.assertEqual(len(manager.configs), 1)
+ config = manager.configs[0]
+ self.assertEqual(config.name, "test")
+ self.assertEqual(config.type, "esx")
+ self.assertEqual(config.server, "1.2.3.4")
+ self.assertEqual(config.username, "admin")
+ self.assertEqual(config.password, "password")
+ self.assertEqual(config.owner, "root")
+ self.assertEqual(config.env, "staging")
+
+ def testInvalidConfig(self):
+ with open(os.path.join(self.config_dir, "test.conf"), "w") as
f:
+ f.write("""
+Malformed configuration file
+""")
+ manager = ConfigManager(self.config_dir)
+ self.assertEqual(len(manager.configs), 0)
+
+ def testInvalidType(self):
+ filename = os.path.join(self.config_dir, "test.conf")
+ with open(filename, "w") as f:
+ f.write("""
+[test]
+type=invalid
+server=1.2.3.4
+username=test
+""")
+ self.assertRaises(InvalidOption, ConfigManager, self.config_dir)
+
+ @unittest.skipIf(os.getuid() == 0, "Can't create unreadable file when
running as root")
+ def testUnreadableConfig(self):
+ filename = os.path.join(self.config_dir, "test.conf")
+ with open(filename, "w") as f:
+ f.write("""
+[test]
+type=esx
+server=1.2.3.4
+username=admin
+password=password
+owner=root
+env=staging
+""")
+ os.chmod(filename, 0)
+ manager = ConfigManager(self.config_dir)
+ self.assertEqual(len(manager.configs), 0)
+
+ def testNoOptionsConfig(self):
+ with open(os.path.join(self.config_dir, "test.conf"), "w") as
f:
+ f.write("""
+[test]
+type=esx
+""")
+ manager = ConfigManager(self.config_dir)
+ self.assertEqual(len(manager.configs), 0)
+
+ def testMultipleConfigsInFile(self):
+ with open(os.path.join(self.config_dir, "test.conf"), "w") as
f:
+ f.write("""
+[test1]
+type=esx
+server=1.2.3.4
+username=admin
+password=password
+owner=root
+env=staging
+
+[test2]
+type=hyperv
+server=1.2.3.5
+username=admin
+password=password
+owner=root
+env=staging
+""")
+
+ manager = ConfigManager(self.config_dir)
+ self.assertEqual(len(manager.configs), 2)
+ config = manager.configs[0]
+ self.assertEqual(config.name, "test1")
+ self.assertEqual(config.type, "esx")
+ self.assertEqual(config.server, "1.2.3.4")
+ self.assertEqual(config.username, "admin")
+ self.assertEqual(config.password, "password")
+ self.assertEqual(config.owner, "root")
+ self.assertEqual(config.env, "staging")
+ config = manager.configs[1]
+ self.assertEqual(config.name, "test2")
+ self.assertEqual(config.type, "hyperv")
+ self.assertEqual(config.username, "admin")
+ self.assertEqual(config.server, "1.2.3.5")
+ self.assertEqual(config.password, "password")
+ self.assertEqual(config.owner, "root")
+ self.assertEqual(config.env, "staging")
+
+ def testMultipleConfigFiles(self):
+ with open(os.path.join(self.config_dir, "test1.conf"), "w")
as f:
+ f.write("""
+[test1]
+type=esx
+server=1.2.3.4
+username=admin
+password=password
+owner=root
+env=staging
+""")
+ with open(os.path.join(self.config_dir, "test2.conf"), "w")
as f:
+ f.write("""
+[test2]
+type=hyperv
+server=1.2.3.5
+username=admin
+password=password
+owner=root
+env=staging
+""")
+
+ manager = ConfigManager(self.config_dir)
+ self.assertEqual(len(manager.configs), 2)
+
+ config2, config1 = manager.configs
+
+ self.assertEqual(config1.name, "test1")
+ self.assertEqual(config1.type, "esx")
+ self.assertEqual(config1.server, "1.2.3.4")
+ self.assertEqual(config1.username, "admin")
+ self.assertEqual(config1.password, "password")
+ self.assertEqual(config1.owner, "root")
+ self.assertEqual(config1.env, "staging")
+
+ self.assertEqual(config2.name, "test2")
+ self.assertEqual(config2.type, "hyperv")
+ self.assertEqual(config2.server, "1.2.3.5")
+ self.assertEqual(config2.username, "admin")
+ self.assertEqual(config2.password, "password")
+ self.assertEqual(config2.owner, "root")
+ self.assertEqual(config2.env, "staging")
diff --git a/tests/test_esx.py b/tests/test_esx.py
new file mode 100644
index 0000000..8c63760
--- /dev/null
+++ b/tests/test_esx.py
@@ -0,0 +1,56 @@
+"""
+Test of ESX virtualization backend.
+
+Copyright (C) 2014 Radek Novacek <rnovacek(a)redhat.com>
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+"""
+
+import logging
+import urllib2
+import suds
+from mock import patch
+
+from base import unittest
+from config import Config
+from virt.esx import Esx
+from virt import VirtError
+
+
+class TestEsx(unittest.TestCase):
+ def setUp(self):
+ logger = logging.getLogger()
+ config = Config('test', 'esx', 'localhost',
'username', 'password', 'owner', 'env')
+ self.esx = Esx(logger, config)
+
+ @patch('suds.client.Client')
+ def test_connect(self, mock_client):
+ self.esx.getHostGuestMapping()
+
+ self.assertTrue(mock_client.called)
+
mock_client.assert_called_with("https://localhost/sdk/vimService.wsdl")
+
mock_client.return_value.set_options.assert_called_once_with(location="https://localhost/sdk")
+ mock_client.service.RetrieveServiceContent.assert_called_once()
+ mock_client.service.Login.assert_called_once()
+
+ @patch('suds.client.Client')
+ def test_connection_timeout(self, mock_client):
+ mock_client.side_effect = urllib2.URLError('timed out')
+ self.assertRaises(VirtError, self.esx.getHostGuestMapping)
+
+ @patch('suds.client.Client')
+ def test_invalid_login(self, mock_client):
+ mock_client.return_value.service.Login.side_effect =
suds.WebFault('Permission to perform this operation was denied.', '')
+ self.assertRaises(VirtError, self.esx.getHostGuestMapping)
diff --git a/tests/test_libvirtd.py b/tests/test_libvirtd.py
new file mode 100644
index 0000000..6077702
--- /dev/null
+++ b/tests/test_libvirtd.py
@@ -0,0 +1,77 @@
+"""
+Test for libvirt virtualization backend.
+
+Copyright (C) 2014 Radek Novacek <rnovacek(a)redhat.com>
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+"""
+
+import threading
+from base import unittest
+from mock import patch, Mock
+import logging
+
+from config import Config
+from virt import Virt, Domain, VirtError
+from virt.libvirtd.libvirtd import LibvirtMonitor
+
+
+def raiseLibvirtError(*args, **kwargs):
+ import libvirt
+ raise libvirt.libvirtError('')
+
+
+class TestLibvirtd(unittest.TestCase):
+ def setUp(self):
+ pass
+
+ @patch('libvirt.openReadOnly')
+ def test_read(self, libvirt):
+ logger = logging.getLogger()
+ config = Config('test', 'libvirt')
+ libvirtd = Virt.fromConfig(logger, config)
+ domains = libvirtd.listDomains()
+ libvirt.assert_called_with("")
+
+ @patch('libvirt.openReadOnly')
+ def test_read_fail(self, virt):
+ logger = logging.getLogger()
+ config = Config('test', 'libvirt')
+ libvirtd = Virt.fromConfig(logger, config)
+ virt.side_effect = raiseLibvirtError
+ self.assertRaises(VirtError, libvirtd.listDomains)
+
+ @patch('libvirt.openReadOnly')
+ def test_monitoring(self, virt):
+ event = threading.Event()
+ LibvirtMonitor().set_event(event)
+ LibvirtMonitor()._prepare()
+ LibvirtMonitor()._checkChange()
+
+ virt.assert_called_with('')
+ virt.return_value.listDomainsID.assert_called()
+ virt.return_value.listDefinedDomains.assert_called()
+ virt.return_value.closed.assert_called()
+ self.assertFalse(event.is_set())
+
+ virt.return_value.listDomainsID.return_value = [1]
+ LibvirtMonitor()._checkChange()
+ self.assertTrue(event.is_set())
+ event.clear()
+
+ virt.return_value.listDomainsID.return_value = []
+ LibvirtMonitor()._checkChange()
+ self.assertTrue(event.is_set())
+ event.clear()
diff --git a/tests/test_satellite.py b/tests/test_satellite.py
new file mode 100644
index 0000000..e3cbac9
--- /dev/null
+++ b/tests/test_satellite.py
@@ -0,0 +1,157 @@
+"""
+Test for Satellite module, part of virt-who
+
+Copyright (C) 2013 Radek Novacek <rnovacek(a)redhat.com>
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+"""
+import os
+import sys
+
+from base import unittest
+
+import logging
+import threading
+import tempfile
+import pickle
+from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
+
+from manager.satellite import Satellite, SatelliteError
+
+TEST_SYSTEM_ID = 'test-system-id'
+
+
+class RequestHandler(SimpleXMLRPCRequestHandler):
+ rpc_paths = ('/XMLRPC',)
+
+
+class FakeSatellite(SimpleXMLRPCServer):
+ def __init__(self):
+ SimpleXMLRPCServer.__init__(self, ("localhost", 8080),
requestHandler=RequestHandler)
+ self.register_function(self.new_system_user_pass,
"registration.new_system_user_pass")
+ self.register_function(self.refresh_hw_profile,
"registration.refresh_hw_profile")
+ self.register_function(self.virt_notify, "registration.virt_notify")
+
+ def new_system_user_pass(self, profile_name, os_release_name, version, arch,
username, password, options):
+ if username != "username":
+ raise Exception("Wrong username")
+ if password != "password":
+ raise Exception("Wrong password")
+ print "RPC: new_system_user_pass", profile_name, os_release_name,
version, arch, username, password, options
+ return {'system_id': TEST_SYSTEM_ID}
+
+ def refresh_hw_profile(self, system_id, profile):
+ print "RPC: refresh_hw_profile", system_id, profile
+ if system_id != TEST_SYSTEM_ID:
+ raise Exception("Wrong system id")
+ return ""
+
+ def virt_notify(self, system_id, plan):
+ print "RPC: virt_notify", system_id, plan
+ if system_id != TEST_SYSTEM_ID:
+ raise Exception("Wrong system id")
+
+ if plan[0] != [0, 'exists', 'system', {'uuid':
'0000000000000000', 'identity': 'host'}]:
+ raise Exception("Wrong value for virt_notify: invalid format of first
entry")
+ if plan[1] != [0, 'crawl_began', 'system', {}]:
+ raise Exception("Wrong value for virt_notify: invalid format of second
entry")
+ if plan[-1] != [0, 'crawl_ended', 'system', {}]:
+ raise Exception("Wrong value for virt_notify: invalid format of last
entry")
+ for item in plan[2:-1]:
+ if item[0] != 0:
+ raise Exception("Wrong value for virt_notify: invalid format first
item of an entry")
+ if item[1] != 'exists':
+ raise Exception("Wrong value for virt_notify: invalid format second
item of an entry")
+ if item[2] != 'domain':
+ raise Exception("Wrong value for virt_notify: invalid format third
item of an entry")
+ if not item[3]['uuid'].startswith("guest"):
+ raise Exception("Wrong value for virt_notify: invalid format uuid
item")
+ return 0
+
+
+class Options(object):
+ def __init__(self, server, username, password):
+ self.server = server
+ self.username = username
+ self.password = password
+
+
+class TestSatellite(unittest.TestCase):
+ @classmethod
+ def setUpClass(cls):
+ cls.logger = logging.getLogger()
+ cls.fake_server = FakeSatellite()
+ cls.thread = threading.Thread(target=cls.fake_server.serve_forever)
+ cls.thread.start()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.fake_server.shutdown()
+
+ def test_wrong_server(self):
+ options = Options("wrong_server", "abc", "def")
+ s = Satellite(self.logger, options)
+ #self.assertRaises(SatelliteError, s.connect, "wrong_server",
"abc", "def")
+ s.hypervisorCheckIn("owner", "env", {}, "test")
+ #self.assertRaises(SatelliteError, s.connect, "localhost",
"abc", "def")
+
+ def test_new_system(self):
+ options = Options("http://localhost:8080", "username",
"password")
+ options.force_register = True
+ s = Satellite(self.logger, options)
+
+ # Register with wrong username
+ #self.assertRaises(SatelliteError, s.connect, "http://localhost:8080",
"wrong", "password", force_register=True)
+
+ # Register with wrong password
+ #self.assertRaises(SatelliteError, s.connect, "http://localhost:8080",
"username", "wrong", force_register=True)
+
+ def test_hypervisorCheckIn(self):
+ options = Options("http://localhost:8080", "username",
"password")
+ options.force_register = True
+ s = Satellite(self.logger, options)
+
+ mapping = {
+ 'host-1': ['guest1-1', 'guest1-2'],
+ 'host-2': ['guest2-1', 'guest2-2',
'guest2-3']
+ }
+ result = s.hypervisorCheckIn("owner", "env", mapping,
"type")
+ self.assertTrue("failedUpdate" in result)
+ self.assertTrue("created" in result)
+ self.assertTrue("updated" in result)
+
+ def test_hypervisorCheckIn_preregistered(self):
+ temp, filename = tempfile.mkstemp(suffix=TEST_SYSTEM_ID)
+ self.addCleanup(os.unlink, filename)
+ f = os.fdopen(temp, "wb")
+ pickle.dump({'system_id': TEST_SYSTEM_ID}, f)
+ f.close()
+
+ options = Options("http://localhost:8080", "username",
"password")
+ s = Satellite(self.logger, options)
+
+ s.HYPERVISOR_SYSTEMID_FILE = filename.replace(TEST_SYSTEM_ID, '%s')
+ mapping = {
+ 'host-1': ['guest1-1', 'guest1-2'],
+ 'host-2': ['guest2-1', 'guest2-2',
'guest2-3']
+ }
+ result = s.hypervisorCheckIn("owner", "env", mapping,
"type")
+ self.assertTrue("failedUpdate" in result)
+ self.assertTrue("created" in result)
+ self.assertTrue("updated" in result)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/test_subscriptionmanager.py b/tests/test_subscriptionmanager.py
new file mode 100644
index 0000000..ea13c48
--- /dev/null
+++ b/tests/test_subscriptionmanager.py
@@ -0,0 +1,7 @@
+
+from base import unittest
+
+
+class TestSubscriptionManager(unittest.TestCase):
+ def test_(self):
+ pass
diff --git a/tests/test_virtwho.py b/tests/test_virtwho.py
new file mode 100644
index 0000000..6e717b5
--- /dev/null
+++ b/tests/test_virtwho.py
@@ -0,0 +1,131 @@
+"""
+Test for basic virt-who operations.
+
+Copyright (C) 2014 Radek Novacek <rnovacek(a)redhat.com>
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+"""
+
+import sys
+import os
+from base import unittest
+import logging
+
+from mock import patch, Mock
+
+from virtwho import parseOptions, VirtWho
+from config import Config
+from virt import VirtError
+from manager import ManagerError
+
+
+class TestOptions(unittest.TestCase):
+ def setUp(self):
+ self.clearEnv()
+
+ def clearEnv(self):
+ for key in os.environ.keys():
+ if key.startswith("VIRTWHO"):
+ del os.environ[key]
+
+ def test_default_cmdline_options(self):
+ sys.argv = ["virtwho.py"]
+ _, options = parseOptions()
+ self.assertFalse(options.debug)
+ self.assertFalse(options.background)
+ self.assertFalse(options.oneshot)
+ self.assertEqual(options.interval, 3600)
+ self.assertEqual(options.smType, 'sam')
+ self.assertEqual(options.virtType, None)
+
+ def test_options_debug(self):
+ sys.argv = ["virtwho.py", "-d"]
+ _, options = parseOptions()
+ self.assertTrue(options.debug)
+
+ sys.argv = ["virtwho.py"]
+ os.environ["VIRTWHO_DEBUG"] = "1"
+ _, options = parseOptions()
+ self.assertTrue(options.debug)
+
+ def test_options_virt(self):
+ for virt in ['esx', 'hyperv', 'rhevm']:
+ self.clearEnv()
+ sys.argv = ["virtwho.py", "--%s" % virt,
"--%s-owner=owner" % virt,
+ "--%s-env=env" % virt,
"--%s-server=localhost" % virt,
+ "--%s-username=username" % virt,
+ "--%s-password=password" % virt]
+ _, options = parseOptions()
+ self.assertEqual(options.virtType, virt)
+ self.assertEqual(options.owner, 'owner')
+ self.assertEqual(options.env, 'env')
+ self.assertEqual(options.server, 'localhost')
+ self.assertEqual(options.username, 'username')
+ self.assertEqual(options.password, 'password')
+
+ sys.argv = ["virtwho.py"]
+ virt_up = virt.upper()
+ os.environ["VIRTWHO_%s" % virt_up] = "1"
+ os.environ["VIRTWHO_%s_OWNER" % virt_up] = "xowner"
+ os.environ["VIRTWHO_%s_ENV" % virt_up] = "xenv"
+ os.environ["VIRTWHO_%s_SERVER" % virt_up] = "xlocalhost"
+ os.environ["VIRTWHO_%s_USERNAME" % virt_up] =
"xusername"
+ os.environ["VIRTWHO_%s_PASSWORD" % virt_up] =
"xpassword"
+ _, options = parseOptions()
+ self.assertEqual(options.virtType, virt)
+ self.assertEqual(options.owner, 'xowner')
+ self.assertEqual(options.env, 'xenv')
+ self.assertEqual(options.server, 'xlocalhost')
+ self.assertEqual(options.username, 'xusername')
+ self.assertEqual(options.password, 'xpassword')
+
+ @patch('virt.Virt.fromConfig')
+ @patch('manager.Manager.fromOptions')
+ def test_sending_guests(self, fromOptions, fromConfig):
+ logger = logging.getLogger()
+ options = Mock()
+ options.oneshot = True
+ virtwho = VirtWho(logger, options)
+ config = Config("test", "esx", "localhost",
"username", "password", "owner", "env")
+ virtwho.configManager.addConfig(config)
+ self.assertTrue(virtwho.send())
+
+ fromConfig.assert_called_with(logger, config)
+ self.assertTrue(fromConfig.return_value.getHostGuestMapping.called)
+ fromOptions.assert_called_with(logger, options)
+
+ @patch('virt.Virt.fromConfig')
+ @patch('manager.Manager.fromOptions')
+ def test_sending_guests_errors(self, fromOptions, fromConfig):
+ logger = logging.getLogger()
+ options = Mock()
+ options.oneshot = True
+ virtwho = VirtWho(logger, options)
+ config = Config("test", "esx", "localhost",
"username", "password", "owner", "env")
+ virtwho.configManager.addConfig(config)
+ fromConfig.return_value.getHostGuestMapping.side_effect = VirtError
+ self.assertFalse(virtwho.send())
+
+ fromConfig.assert_called_with(logger, config)
+ self.assertTrue(fromConfig.return_value.getHostGuestMapping.called)
+ fromOptions.assert_not_called()
+
+ fromConfig.return_value.getHostGuestMapping.side_effect = None
+ fromOptions.return_value.hypervisorCheckIn.side_effect = ManagerError
+ self.assertFalse(virtwho.send())
+ fromConfig.assert_called_with(logger, config)
+ self.assertTrue(fromConfig.return_value.getHostGuestMapping.called)
+ fromOptions.assert_called()
+ self.assertTrue(fromOptions.return_value.hypervisorCheckIn.called)