[prev in list] [next in list] [prev in thread] [next in thread]
List: virt-who-devel
Subject: [virt-who] Fix hypervisorCheckIn API and add test for it
From: Radek Novacek <rnovacek () fedoraproject ! org>
Date: 2014-07-29 7:27:09
Message-ID: 20140729072709.8CB0C610F1 () fedorahosted ! org
[Download RAW message or body]
commit e348e0328fd01abbd608f51e25a7808bd77ecbdc
Author: Radek Novacek <rnovacek@redhat.com>
Date: Tue Jul 29 09:22:09 2014 +0200
Fix hypervisorCheckIn API and add test for it
manager/satellite/satellite.py | 2 +-
manager/subscriptionmanager/subscriptionmanager.py | 4 +-
tests/test_manager.py | 155 ++++++++++++++++++++
3 files changed, 158 insertions(+), 3 deletions(-)
---
diff --git a/manager/satellite/satellite.py b/manager/satellite/satellite.py
index c1d6484..8f9360d 100644
--- a/manager/satellite/satellite.py
+++ b/manager/satellite/satellite.py
@@ -139,7 +139,7 @@ class Satellite(Manager):
def sendVirtGuests(self, domains):
raise SatelliteError("virt-who does not support sending local hypervisor \
data to satellite; use rhn-virtualization-host instead")
- def hypervisorCheckIn(self, owner, env, mapping, type=None):
+ def hypervisorCheckIn(self, config, mapping, type=None):
self._connect()
self.logger.info("Sending update in hosts-to-guests mapping: %s" % mapping)
diff --git a/manager/subscriptionmanager/subscriptionmanager.py \
b/manager/subscriptionmanager/subscriptionmanager.py index 3b6ce5a..4d35fa7 100644
--- a/manager/subscriptionmanager/subscriptionmanager.py
+++ b/manager/subscriptionmanager/subscriptionmanager.py
@@ -111,14 +111,14 @@ class SubscriptionManager(Manager):
# Send list of guest uuids to the server
self.connection.updateConsumer(self.uuid(), guest_uuids=domains)
- def hypervisorCheckIn(self, owner, env, mapping, type=None):
+ def hypervisorCheckIn(self, config, mapping, type=None):
""" Send hosts to guests mapping to subscription manager. """
self.logger.info("Sending update in hosts-to-guests mapping: %s" % mapping)
self._connect()
# Send the mapping
- return self.connection.hypervisorCheckIn(owner, env, mapping)
+ return self.connection.hypervisorCheckIn(config.owner, config.env, mapping)
def uuid(self):
""" Read consumer certificate and get consumer UUID from it. """
diff --git a/tests/test_manager.py b/tests/test_manager.py
new file mode 100644
index 0000000..f7377d7
--- /dev/null
+++ b/tests/test_manager.py
@@ -0,0 +1,155 @@
+"""
+Test of subscription managers.
+
+Copyright (C) 2014 Radek Novacek <rnovacek@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
+import logging
+import tempfile
+import subprocess
+from mock import patch, MagicMock, ANY
+
+from base import unittest
+from config import Config
+from manager import Manager, ManagerError
+
+import rhsm.config as rhsm_config
+import rhsm.certificate
+import rhsm.connection
+
+import xmlrpclib
+
+
+class TestManager(unittest.TestCase):
+ """ Test of all available subscription managers. """
+
+ guestInfo = [
+ {
+ 'guestId': '9c927368-e888-43b4-9cdb-91b10431b258',
+ 'attributes': {
+ 'hypervisorType': 'QEMU',
+ 'virtWhoType': 'libvirt',
+ 'active': 1
+ }
+ }
+ ]
+
+ mapping = {
+ '9c927368-e888-43b4-9cdb-91b10431b258': [
+ ''
+ ],
+ 'ad58b739-5288-4cbc-a984-bd771612d670': [
+ '2147647e-6f06-4ac0-982d-6902c259f9d6',
+ 'd5ffceb5-f79d-41be-a4c1-204f836e144a'
+ ]
+ }
+
+
+class TestSubscriptionManager(TestManager):
+ smType = "sam"
+
+ def prepare(self, create_from_file, connection):
+ self.logger = logging.getLogger()
+ self.options = MagicMock()
+ self.options.smType = self.smType
+
+ tempdir = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, tempdir)
+
+ config_file = os.path.join(tempdir, "config")
+ with open(config_file, "w") as f:
+ f.write("[rhsm]\nconsumerCertDir=%s\n" % tempdir)
+
+ cert_file = os.path.join(tempdir, "cert.pem")
+ with open(cert_file, "w") as f:
+ f.write("\n")
+
+ rhsm_config.DEFAULT_CONFIG_PATH = config_file
+
+ create_from_file.return_value.cert_uuid = {'CN': 'Test'}
+ connection.return_value = MagicMock()
+
+ @patch("rhsm.certificate.create_from_file")
+ @patch("rhsm.connection.UEPConnection")
+ def test_sendVirtGuests(self, create_from_file, connection):
+ self.prepare(create_from_file, connection)
+ manager = Manager.fromOptions(self.logger, self.options)
+ manager.sendVirtGuests(self.guestInfo)
+ manager.connection.updateConsumer.assert_called_with(ANY, \
guest_uuids=self.guestInfo) +
+ @patch("rhsm.certificate.create_from_file")
+ @patch("rhsm.connection.UEPConnection")
+ def test_hypervisorCheckIn(self, create_from_file, connection):
+ self.prepare(create_from_file, connection)
+ manager = Manager.fromOptions(self.logger, self.options)
+ self.options.env = "ENV"
+ self.options.owner = "OWNER"
+ manager.hypervisorCheckIn(self.options, self.mapping)
+ manager.connection.hypervisorCheckIn.assert_called_with(self.options.owner, \
self.options.env, self.mapping) +
+
+class TestSatellite(TestManager):
+ smType = "satellite"
+
+ def test_sendVirtGuests(self):
+ logger = logging.getLogger()
+ options = MagicMock()
+ options.smType = self.smType
+
+ manager = Manager.fromOptions(logger, options)
+ self.assertRaises(ManagerError, manager.sendVirtGuests, self.guestInfo)
+
+ @patch("xmlrpclib.Server")
+ def test_hypervisorCheckIn(self, server):
+ logger = logging.getLogger()
+ options = MagicMock()
+ options.smType = self.smType
+
+ manager = Manager.fromOptions(logger, options)
+ options.env = "ENV"
+ options.owner = "OWNER"
+ manager.hypervisorCheckIn(options, self.mapping)
+ manager.server.registration.virt_notify.assert_called_with(ANY, [
+ [
+ 0, 'exists', 'system', {'uuid': '0000000000000000', 'identity': \
'host'} + ], [
+ 0, 'crawl_began', 'system', {}
+ ], [
+ 0, 'exists', 'domain', {
+ 'state': 'running',
+ 'memory_size': 0,
+ 'name': 'VM from None hypervisor \
ad58b739-5288-4cbc-a984-bd771612d670', + 'virt_type': \
'fully_virtualized', + 'vcpus': 1,
+ 'uuid': '2147647e6f064ac0982d6902c259f9d6'
+ }
+ ], [
+ 0, 'exists', 'domain', {
+ 'state': 'running',
+ 'memory_size': 0,
+ 'name': 'VM from None hypervisor \
ad58b739-5288-4cbc-a984-bd771612d670', + 'virt_type': \
'fully_virtualized', + 'vcpus': 1,
+ 'uuid': 'd5ffceb5f79d41bea4c1204f836e144a'
+ }
+ ], [
+ 0, 'crawl_ended', 'system', {}
+ ]
+ ])
+
_______________________________________________
virt-who-devel mailing list
virt-who-devel@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/virt-who-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic