[virt-who] tests: add vdsm test
by Radek Novacek
commit 7e0c7e344422531ff4ddea790bdb301c09e6c5c6
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Tue Sep 9 16:18:27 2014 +0200
tests: add vdsm test
tests/test_vdsm.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 60 insertions(+), 0 deletions(-)
---
diff --git a/tests/test_vdsm.py b/tests/test_vdsm.py
new file mode 100644
index 0000000..e14dfec
--- /dev/null
+++ b/tests/test_vdsm.py
@@ -0,0 +1,60 @@
+"""
+Test of VDSM 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 MagicMock
+
+from base import TestBase
+from config import Config
+from virt.vdsm import Vdsm
+from virt import VirtError
+import xmlrpclib
+
+
+class TestEsx(TestBase):
+ def setUp(self):
+ config = Config('test', 'vdsm')
+
+ def fakeSecureConnect(self):
+ return MagicMock()
+ Vdsm._secureConnect = fakeSecureConnect
+ self.vdsm = Vdsm(self.logger, config)
+
+ def test_connect(self):
+ self.vdsm.server.list = MagicMock()
+ self.vdsm.server.list.return_value = {
+ 'status': {
+ 'code': 0
+ },
+ 'vmList': [
+ {
+ 'vmId': '1'
+ }, {
+ 'vmId': '2'
+ }, {
+ 'vmId': '3'
+ }
+ ]
+ }
+ domains = self.vdsm.listDomains()
+ self.assertEquals(domains, ['1', '2', '3'])
+ self.vdsm.server.list.assert_called_once()
9 years, 8 months
[virt-who] subscriptionmanager: fix domain sorting error
by Radek Novacek
commit a0e0ad4bdd02105c23dc8aa32629e55fed139bb4
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Tue Sep 9 16:18:04 2014 +0200
subscriptionmanager: fix domain sorting error
manager/subscriptionmanager/subscriptionmanager.py | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/manager/subscriptionmanager/subscriptionmanager.py b/manager/subscriptionmanager/subscriptionmanager.py
index 4d35fa7..739a30b 100644
--- a/manager/subscriptionmanager/subscriptionmanager.py
+++ b/manager/subscriptionmanager/subscriptionmanager.py
@@ -99,9 +99,12 @@ class SubscriptionManager(Manager):
# Sort the list
key = None
if len(domains) > 0:
- if isinstance(domains[0], basestring):
+ if not isinstance(domains[0], basestring):
key = "guestId"
- domains.sort(key=key)
+ if key is None:
+ domains.sort()
+ else:
+ domains.sort(key=lambda item: item[key])
if key is not None:
self.logger.info("Sending list of uuids: %s" % [domain[key] for domain in domains])
9 years, 8 months
[virt-who] Created tag 0.11
by Radek Novacek
The signed tag '0.11' was created.
Tagger: Radek Novacek <rnovacek(a)redhat.com>
Date: Mon Sep 8 15:54:01 2014 +0200
0.11
Changes since the last tag '0.10':
Radek Novacek (16):
virt: add missing import to hyperv
libvirtd: remove import to nonexistent file
conf: add remark about quoting special characters
Add missing license header
Use libvirtd as fallback when no configrations are found
fix password test
libvirtd: use event loop instead of reconnecting all the time
Fix hypervisorCheckIn API and add test for it
Fix wrong logger usage when processing update errors
test: fix hypervisorCheckIn function parameters
libvirt: properly handle libvirt shutdown when doing background monitoring
libvirtd: use info() when state() is not implemented
esx: disable error when esx host doesn't have guests
hyperv: don't use deprecated md5 module
Fix constructor parameters in vdsm and rhevm modes
Version 0.11
9 years, 8 months
[virt-who] tests: add test for calling subscriptionmanager
by Radek Novacek
commit 616c793f204597c4aeec55c250d5a773990dd1c4
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Tue Sep 9 16:17:30 2014 +0200
tests: add test for calling subscriptionmanager
tests/test_subscriptionmanager.py | 81 +++++++++++++++++++++++++++++++++++--
1 files changed, 77 insertions(+), 4 deletions(-)
---
diff --git a/tests/test_subscriptionmanager.py b/tests/test_subscriptionmanager.py
index ea13c48..35e1665 100644
--- a/tests/test_subscriptionmanager.py
+++ b/tests/test_subscriptionmanager.py
@@ -1,7 +1,80 @@
+import os
-from base import unittest
+import shutil
+import logging
+import tempfile
+from mock import patch, Mock, DEFAULT
-class TestSubscriptionManager(unittest.TestCase):
- def test_(self):
- pass
+from base import TestBase
+
+from config import Config
+from manager.subscriptionmanager import SubscriptionManager
+
+import rhsm.config
+import rhsm.certificate
+import rhsm.connection
+
+
+class TestSubscriptionManager(TestBase):
+ @classmethod
+ @patch('rhsm.config.initConfig')
+ @patch('rhsm.certificate.create_from_file')
+ def setUpClass(cls, rhsmcert, rhsmconfig):
+ super(TestSubscriptionManager, cls).setUpClass()
+ config = Config('test', 'libvirt')
+ cls.tempdir = tempfile.mkdtemp()
+ with open(os.path.join(cls.tempdir, 'cert.pem'), 'w') as f:
+ f.write("\n")
+
+ rhsmcert.return_value.subject = {'CN': 123}
+ rhsmconfig.return_value.get.side_effect = lambda group, key: {'consumerCertDir': cls.tempdir}.get(key, DEFAULT)
+ cls.sm = SubscriptionManager(cls.logger, config)
+
+ @classmethod
+ def tearDownClass(cls):
+ shutil.rmtree(cls.tempdir)
+
+ @patch('rhsm.connection.UEPConnection')
+ def test_sendVirtGuestsList(self, rhsmconnection):
+ guestList = ['222', '111', '333']
+ self.sm.sendVirtGuests(guestList)
+ self.sm.connection.updateConsumer.assert_called_with(123, guest_uuids=guestList)
+
+ @patch('rhsm.connection.UEPConnection')
+ def test_sendVirtGuestsDict(self, rhsmconnection):
+ guestList = [
+ {
+ 'guestId': '222',
+ 'attributes': {
+ 'hypervisorType': 'qemu',
+ 'virtWhoType': 'libvirt',
+ 'active': 1
+ }
+ }, {
+ 'guestId': '111',
+ 'attributes': {
+ 'hypervisorType': 'qemu',
+ 'virtWhoType': 'libvirt',
+ 'active': 1
+ }
+ }, {
+ 'guestId': '333',
+ 'attributes': {
+ 'hypervisorType': 'qemu',
+ 'virtWhoType': 'libvirt',
+ 'active': 1
+ }
+ }
+ ]
+ self.sm.sendVirtGuests(guestList)
+ self.sm.connection.updateConsumer.assert_called_with(123, guest_uuids=guestList)
+
+ @patch('rhsm.connection.UEPConnection')
+ def test_hypervisorCheckIn(self, rhsmconnection):
+ owner = "owner"
+ env = "env"
+ config = Config("test", "esx", owner=owner, env=env)
+ mapping = {'ABC': ['222', '111', '333'], 'BCD': []}
+ self.sm.hypervisorCheckIn(config, mapping)
+ self.sm.connection.hypervisorCheckIn.assert_called_with(owner, env, mapping)
9 years, 8 months
[virt-who] tests: use common TestBase class for all tests
by Radek Novacek
commit 00250041d5210588632d0f2c79aec456163d633d
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Tue Sep 9 16:17:07 2014 +0200
tests: use common TestBase class for all tests
tests/base.py | 14 ++++++++++++++
tests/test_config.py | 4 ++--
tests/test_esx.py | 7 +++----
tests/test_libvirtd.py | 10 ++++------
tests/test_manager.py | 11 ++++-------
tests/test_password.py | 4 ++--
tests/test_satellite.py | 6 +++---
tests/test_virtwho.py | 18 ++++++++----------
8 files changed, 40 insertions(+), 34 deletions(-)
---
diff --git a/tests/base.py b/tests/base.py
index d4edeff..3b9de96 100644
--- a/tests/base.py
+++ b/tests/base.py
@@ -26,3 +26,17 @@ if sys.version_info[0] > 2 or sys.version_info[1] > 6:
import unittest
else:
import unittest2 as unittest
+
+import logging
+import log
+from mock import patch
+
+
+class TestBase(unittest.TestCase):
+ @classmethod
+ @patch('log.getLogger')
+ def setUpClass(cls, logger):
+ cls.logger = logging.getLogger("")
+ cls.logger.handlers = []
+ cls.logger.setLevel(logging.CRITICAL)
+ logger.return_value = cls.logger
diff --git a/tests/test_config.py b/tests/test_config.py
index f549b1c..59e067e 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -23,10 +23,10 @@ import os
import shutil
from config import ConfigManager, InvalidOption
from tempfile import mkdtemp
-from base import unittest
+from base import TestBase, unittest
-class TestReadingConfigs(unittest.TestCase):
+class TestReadingConfigs(TestBase):
def setUp(self):
self.config_dir = mkdtemp()
self.addCleanup(shutil.rmtree, self.config_dir)
diff --git a/tests/test_esx.py b/tests/test_esx.py
index 8c63760..ef18fe6 100644
--- a/tests/test_esx.py
+++ b/tests/test_esx.py
@@ -23,17 +23,16 @@ import urllib2
import suds
from mock import patch
-from base import unittest
+from base import TestBase
from config import Config
from virt.esx import Esx
from virt import VirtError
-class TestEsx(unittest.TestCase):
+class TestEsx(TestBase):
def setUp(self):
- logger = logging.getLogger()
config = Config('test', 'esx', 'localhost', 'username', 'password', 'owner', 'env')
- self.esx = Esx(logger, config)
+ self.esx = Esx(self.logger, config)
@patch('suds.client.Client')
def test_connect(self, mock_client):
diff --git a/tests/test_libvirtd.py b/tests/test_libvirtd.py
index 4494524..58160e2 100644
--- a/tests/test_libvirtd.py
+++ b/tests/test_libvirtd.py
@@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
import threading
-from base import unittest
+from base import TestBase
from mock import patch, Mock
import logging
@@ -34,23 +34,21 @@ def raiseLibvirtError(*args, **kwargs):
raise libvirt.libvirtError('')
-class TestLibvirtd(unittest.TestCase):
+class TestLibvirtd(TestBase):
def setUp(self):
pass
@patch('libvirt.openReadOnly')
def test_read(self, libvirt):
- logger = logging.getLogger()
config = Config('test', 'libvirt')
- libvirtd = Virt.fromConfig(logger, config)
+ libvirtd = Virt.fromConfig(self.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)
+ libvirtd = Virt.fromConfig(self.logger, config)
virt.side_effect = raiseLibvirtError
self.assertRaises(VirtError, libvirtd.listDomains)
diff --git a/tests/test_manager.py b/tests/test_manager.py
index f7377d7..8f777ae 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -25,7 +25,7 @@ import tempfile
import subprocess
from mock import patch, MagicMock, ANY
-from base import unittest
+from base import TestBase
from config import Config
from manager import Manager, ManagerError
@@ -36,7 +36,7 @@ import rhsm.connection
import xmlrpclib
-class TestManager(unittest.TestCase):
+class TestManager(TestBase):
""" Test of all available subscription managers. """
guestInfo = [
@@ -65,7 +65,6 @@ class TestSubscriptionManager(TestManager):
smType = "sam"
def prepare(self, create_from_file, connection):
- self.logger = logging.getLogger()
self.options = MagicMock()
self.options.smType = self.smType
@@ -108,20 +107,18 @@ class TestSatellite(TestManager):
smType = "satellite"
def test_sendVirtGuests(self):
- logger = logging.getLogger()
options = MagicMock()
options.smType = self.smType
- manager = Manager.fromOptions(logger, options)
+ manager = Manager.fromOptions(self.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)
+ manager = Manager.fromOptions(self.logger, options)
options.env = "ENV"
options.owner = "OWNER"
manager.hypervisorCheckIn(options, self.mapping)
diff --git a/tests/test_password.py b/tests/test_password.py
index 7396e80..090a164 100644
--- a/tests/test_password.py
+++ b/tests/test_password.py
@@ -23,12 +23,12 @@ import tempfile
from binascii import hexlify, unhexlify
from mock import MagicMock
-from base import unittest
+from base import TestBase
from password import Password
-class TestPassword(unittest.TestCase):
+class TestPassword(TestBase):
def testEncrypt(self):
self.assertEqual(hexlify(
Password._crypt(
diff --git a/tests/test_satellite.py b/tests/test_satellite.py
index d493694..bb781e7 100644
--- a/tests/test_satellite.py
+++ b/tests/test_satellite.py
@@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import os
import sys
-from base import unittest
+from base import TestBase
import logging
import threading
@@ -90,10 +90,10 @@ class Options(object):
self.password = password
-class TestSatellite(unittest.TestCase):
+class TestSatellite(TestBase):
@classmethod
def setUpClass(cls):
- cls.logger = logging.getLogger()
+ super(TestSatellite, cls).setUpClass()
cls.fake_server = FakeSatellite()
cls.thread = threading.Thread(target=cls.fake_server.serve_forever)
cls.thread.start()
diff --git a/tests/test_virtwho.py b/tests/test_virtwho.py
index 6e717b5..94cbb50 100644
--- a/tests/test_virtwho.py
+++ b/tests/test_virtwho.py
@@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import sys
import os
-from base import unittest
+from base import TestBase
import logging
from mock import patch, Mock
@@ -31,7 +31,7 @@ from virt import VirtError
from manager import ManagerError
-class TestOptions(unittest.TestCase):
+class TestOptions(TestBase):
def setUp(self):
self.clearEnv()
@@ -94,38 +94,36 @@ class TestOptions(unittest.TestCase):
@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)
+ virtwho = VirtWho(self.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)
+ fromConfig.assert_called_with(self.logger, config)
self.assertTrue(fromConfig.return_value.getHostGuestMapping.called)
- fromOptions.assert_called_with(logger, options)
+ fromOptions.assert_called_with(self.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)
+ virtwho = VirtWho(self.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)
+ fromConfig.assert_called_with(self.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)
+ fromConfig.assert_called_with(self.logger, config)
self.assertTrue(fromConfig.return_value.getHostGuestMapping.called)
fromOptions.assert_called()
self.assertTrue(fromOptions.return_value.hypervisorCheckIn.called)
9 years, 8 months
[virt-who] Version 0.11
by Radek Novacek
commit 43a1562aa12bc6412a45608829096cd945652605
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Mon Sep 8 15:53:52 2014 +0200
Version 0.11
Makefile | 2 +-
virt-who.spec | 5 ++++-
2 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/Makefile b/Makefile
index 8acb13d..340a98a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
name = virt-who
-version = 0.10
+version = 0.11
.PHONY: pack check install srpm rpm rpmlint upload
diff --git a/virt-who.spec b/virt-who.spec
index d3f51b9..4101b60 100644
--- a/virt-who.spec
+++ b/virt-who.spec
@@ -1,5 +1,5 @@
Name: virt-who
-Version: 0.10
+Version: 0.11
Release: 1%{?dist}
Summary: Agent for reporting virtual guest IDs to subscription-manager
@@ -80,6 +80,9 @@ fi
%changelog
+* Mon Sep 08 2014 Radek Novacek <rnovacek(a)redhat.com> 0.11-1
+- Version 0.11
+
* Tue May 20 2014 Radek Novacek <rnovacek(a)redhat.com> 0.10-1
- Add directory with configuration files
- Version 0.10
9 years, 8 months