diff options
author | Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com> | 2018-01-16 11:03:17 +0000 |
---|---|---|
committer | Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com> | 2018-03-21 09:11:53 +0000 |
commit | 365ded3d2089fff98f4d8562fb277112b242645f (patch) | |
tree | 1bd32f1e71010a709f495f1d638291b9799ecca5 /yardstick/tests | |
parent | 49af409b0c43ec3d3f0479c21cef172e29e1cdfd (diff) |
Improve "Libvirt.virsh_create_vm" function
Read the command exit code and raise an exception in case the VM boot
process went wrong.
JIRA: YARDSTICK-941
Change-Id: Ibabaae8983213a33799ad00fa4d9541bbabea857
Signed-off-by: Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Diffstat (limited to 'yardstick/tests')
-rw-r--r-- | yardstick/tests/unit/benchmark/contexts/standalone/test_model.py | 24 |
1 files changed, 18 insertions, 6 deletions
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: |