aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick
diff options
context:
space:
mode:
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>2018-03-27 16:47:50 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-03-27 16:47:50 +0000
commit79da68a8d4529bbc132228785f0e4c40506fa3ab (patch)
tree536d1b6a1f5879f478428e10374d0542f118a9b7 /yardstick
parent052a13ab65063c2f50468161e278d348a403c660 (diff)
parent365ded3d2089fff98f4d8562fb277112b242645f (diff)
Merge "Improve "Libvirt.virsh_create_vm" function"
Diffstat (limited to 'yardstick')
-rw-r--r--yardstick/benchmark/contexts/standalone/model.py6
-rw-r--r--yardstick/common/exceptions.py4
-rw-r--r--yardstick/tests/unit/benchmark/contexts/standalone/test_model.py24
3 files changed, 26 insertions, 8 deletions
diff --git a/yardstick/benchmark/contexts/standalone/model.py b/yardstick/benchmark/contexts/standalone/model.py
index 7eab1c9c8..ffa37fd37 100644
--- a/yardstick/benchmark/contexts/standalone/model.py
+++ b/yardstick/benchmark/contexts/standalone/model.py
@@ -106,8 +106,10 @@ class Libvirt(object):
@staticmethod
def virsh_create_vm(connection, cfg):
- err = connection.execute("virsh create %s" % cfg)[0]
- LOG.info("VM create status: %s", err)
+ LOG.info('VM create, XML config: %s', cfg)
+ status, _, error = connection.execute('virsh create %s' % cfg)
+ if status:
+ raise exceptions.LibvirtCreateError(error=error)
@staticmethod
def virsh_destroy_vm(vm_name, connection):
diff --git a/yardstick/common/exceptions.py b/yardstick/common/exceptions.py
index 9ae2c68cd..439b9cb1b 100644
--- a/yardstick/common/exceptions.py
+++ b/yardstick/common/exceptions.py
@@ -108,6 +108,10 @@ class OVSSetupError(YardstickException):
message = 'OVS setup error. Command: %(command)s. Error: %(error)s.'
+class LibvirtCreateError(YardstickException):
+ message = 'Error creating the virtual machine. Error: %(error)s.'
+
+
class ScenarioConfigContextNameNotFound(YardstickException):
message = 'Context name "%(context_name)s" not found'
diff --git a/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py b/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py
index 005deb88f..d6f563498 100644
--- a/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py
+++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py
@@ -22,6 +22,7 @@ from xml.etree import ElementTree
from yardstick import ssh
from yardstick.benchmark.contexts.standalone import model
+from yardstick.common import exceptions
from yardstick import constants
from yardstick.network_services import utils
@@ -49,6 +50,12 @@ class ModelLibvirtTestCase(unittest.TestCase):
self.pci_address_str = '0001:04:03.2'
self.pci_address = utils.PciAddress(self.pci_address_str)
self.mac = '00:00:00:00:00:01'
+ self._mock_ssh = mock.Mock()
+ self.mock_ssh = self._mock_ssh.start()
+ self.addCleanup(self._cleanup)
+
+ def _cleanup(self):
+ self._mock_ssh.stop()
# TODO: Remove mocking of yardstick.ssh.SSH (here and elsewhere)
# In this case, we are mocking a param to be passed into other methods
@@ -62,12 +69,17 @@ class ModelLibvirtTestCase(unittest.TestCase):
model.Libvirt.check_if_vm_exists_and_delete("vm_0", ssh_mock)
def test_virsh_create_vm(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = mock.Mock(return_value=(0, "a", ""))
- ssh.return_value = ssh_mock
- # NOTE(ralonsoh): this test doesn't cover function execution.
- model.Libvirt.virsh_create_vm(ssh_mock, "vm_0")
+ self.mock_ssh.execute = mock.Mock(return_value=(0, 0, 0))
+ model.Libvirt.virsh_create_vm(self.mock_ssh, 'vm_0')
+ self.mock_ssh.execute.assert_called_once_with('virsh create vm_0')
+
+ def test_virsh_create_vm_error(self):
+ self.mock_ssh.execute = mock.Mock(return_value=(1, 0, 'error_create'))
+ with self.assertRaises(exceptions.LibvirtCreateError) as exc:
+ model.Libvirt.virsh_create_vm(self.mock_ssh, 'vm_0')
+ self.assertEqual('Error creating the virtual machine. Error: '
+ 'error_create.', str(exc.exception))
+ self.mock_ssh.execute.assert_called_once_with('virsh create vm_0')
def test_virsh_destroy_vm(self):
with mock.patch("yardstick.ssh.SSH") as ssh: