diff options
author | Matt Riedemann <mriedem@us.ibm.com> | 2015-01-28 13:17:29 -0800 |
---|---|---|
committer | Matt Riedemann <mriedem@us.ibm.com> | 2015-02-11 12:08:09 -0800 |
commit | 174c98887cae9cb5765a205e4d72987b2baaf41a (patch) | |
tree | 21fbee0382c94700e53eb398f86369249623eadb /nova/tests/unit/test_nova_manage.py | |
parent | ede75c15637acb3a8d8899620f71087796bd1c3f (diff) | |
download | nova-174c98887cae9cb5765a205e4d72987b2baaf41a.tar.gz |
Add tests for nova-manage vm list
There were no existing unit tests for this nova-manage command and since
we just converted it to use objects we should probably make sure there
are unit tests for it.
Also fixes a little bug where instance.launch_index could technically be
None which would cause a NoneType error. The data model defines
launch_index as nullable but in practice the compute API will never
leave it as None, but we might as well fix this while adding tests.
Change-Id: Idc1ce6d11d7f6cba52cc6d8cd668b4386d1071ba
Diffstat (limited to 'nova/tests/unit/test_nova_manage.py')
-rw-r--r-- | nova/tests/unit/test_nova_manage.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/nova/tests/unit/test_nova_manage.py b/nova/tests/unit/test_nova_manage.py index d1ec80ac4a..8662261508 100644 --- a/nova/tests/unit/test_nova_manage.py +++ b/nova/tests/unit/test_nova_manage.py @@ -24,9 +24,12 @@ from nova import context from nova import db from nova.db import migration from nova import exception +from nova import objects from nova import test from nova.tests.unit.db import fakes as db_fakes +from nova.tests.unit import fake_instance from nova.tests.unit.objects import test_network +from nova.tests.unit import test_flavors class FixedIpCommandsTestCase(test.TestCase): @@ -328,6 +331,49 @@ class ProjectCommandsTestCase(test.TestCase): self.assertEqual(2, self.commands.quota('admin', 'volumes1', '10')) +class VmCommandsTestCase(test.TestCase): + def setUp(self): + super(VmCommandsTestCase, self).setUp() + self.commands = manage.VmCommands() + self.fake_flavor = objects.Flavor(**test_flavors.DEFAULT_FLAVORS[0]) + + def test_list_without_host(self): + output = StringIO.StringIO() + sys.stdout = output + with mock.patch.object(objects.InstanceList, 'get_by_filters') as get: + get.return_value = objects.InstanceList( + objects=[fake_instance.fake_instance_obj( + context.get_admin_context(), host='foo-host', + instance_type=self.fake_flavor, + expected_attrs=('flavor'))]) + self.commands.list() + + sys.stdout = sys.__stdout__ + result = output.getvalue() + + self.assertIn('node', result) # check the header line + self.assertIn('m1.tiny', result) # flavor.name + self.assertIn('foo-host', result) + + def test_list_with_host(self): + output = StringIO.StringIO() + sys.stdout = output + with mock.patch.object(objects.InstanceList, 'get_by_host') as get: + get.return_value = objects.InstanceList( + objects=[fake_instance.fake_instance_obj( + context.get_admin_context(), + instance_type=self.fake_flavor, + expected_attrs=('flavor'))]) + self.commands.list(host='fake-host') + + sys.stdout = sys.__stdout__ + result = output.getvalue() + + self.assertIn('node', result) # check the header line + self.assertIn('m1.tiny', result) # flavor.name + self.assertIn('fake-host', result) + + class DBCommandsTestCase(test.TestCase): def setUp(self): super(DBCommandsTestCase, self).setUp() |