Check image-list output in cmd tests

We are performing smoke tests for image update commands now. Lets
also assert their effects on the image-list command.

Change-Id: I322845e159e81315b1b5f75cbb998d4c795793c4
This commit is contained in:
Gregory Haynes 2015-03-13 21:58:19 +00:00
parent 74ef962fbe
commit b3090b525b
2 changed files with 28 additions and 0 deletions

View File

@ -16,6 +16,7 @@
import sys # noqa making sure its available for monkey patching
import fixtures
import mock
from nodepool.cmd import nodepoolcmd
from nodepool import tests
@ -27,17 +28,34 @@ class TestNodepoolCMD(tests.DBTestCase):
argv.extend(args)
self.useFixture(fixtures.MonkeyPatch('sys.argv', argv))
def assert_images_listed(self, configfile, image_cnt, status="ready"):
self.patch_argv("-c", configfile, "image-list")
with mock.patch('prettytable.PrettyTable.add_row') as m_add_row:
nodepoolcmd.main()
images_with_status = 0
# Find add_rows with the status were looking for
for args, kwargs in m_add_row.call_args_list:
row = args[0]
status_column = 7
if row[status_column] == status:
images_with_status += 1
self.assertEquals(images_with_status, image_cnt)
def test_snapshot_image_update(self):
configfile = self.setup_config("node.yaml")
self.patch_argv("-c", configfile, "image-update",
"fake-provider", "fake-image")
nodepoolcmd.main()
self.wait_for_threads()
self.assert_images_listed(configfile, 1)
def test_dib_image_update(self):
configfile = self.setup_config("node_dib.yaml")
self.patch_argv("-c", configfile, "image-update",
"fake-dib-provider", "fake-dib-image")
nodepoolcmd.main()
self.wait_for_threads()
self.assert_images_listed(configfile, 1)
def test_dib_snapshot_image_update(self):
configfile = self.setup_config("node_dib_and_snap.yaml")
@ -47,15 +65,24 @@ class TestNodepoolCMD(tests.DBTestCase):
self.patch_argv("-c", configfile, "image-update",
"fake-provider2", "fake-dib-image")
nodepoolcmd.main()
self.wait_for_threads()
self.assert_images_listed(configfile, 2)
def test_dib_snapshot_image_update_all(self):
configfile = self.setup_config("node_dib_and_snap.yaml")
self.patch_argv("-c", configfile, "image-update",
"all", "fake-dib-image")
nodepoolcmd.main()
self.wait_for_threads()
self.assert_images_listed(configfile, 2)
def test_image_update_all(self):
configfile = self.setup_config("node_cmd.yaml")
self.patch_argv("-c", configfile, "image-update",
"all", "fake-image1")
nodepoolcmd.main()
self.wait_for_threads()
self.assert_images_listed(configfile, 1)
def test_image_list_empty(self):
self.assert_images_listed(self.setup_config("node_cmd.yaml"), 0)

View File

@ -5,6 +5,7 @@ sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3
sphinxcontrib-programoutput
discover
fixtures>=0.3.12
mock>=1.0
python-subunit
testrepository>=0.0.13
testresources