diff --git a/nodepool/tests/test_commands.py b/nodepool/tests/test_commands.py index 50cf3671a..f9892b12c 100644 --- a/nodepool/tests/test_commands.py +++ b/nodepool/tests/test_commands.py @@ -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) diff --git a/test-requirements.txt b/test-requirements.txt index 9947c78b1..7bdd815a6 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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