Exemple #1
0
 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_build(self):
        configfile = self.setup_config('node_dib.yaml')
        self._useBuilder(configfile)

        self.patch_argv("-c", configfile, "image-build", "fake-dib-diskimage")
        nodepoolcmd.main()
        self.assert_listed(configfile, ['dib-image-list'], 4, 'ready', 1)
Exemple #3
0
 def test_dib_image_update(self):
     configfile = self.setup_config("node_dib.yaml")
     self._useBuilder(configfile)
     self.patch_argv("-c", configfile, "image-update",
                     "fake-dib-provider", "fake-dib-image")
     nodepoolcmd.main()
     self.assert_images_listed(configfile, 1)
Exemple #4
0
 def test_dib_image_build_pause(self):
     configfile = self.setup_config('node_diskimage_pause.yaml')
     self._useBuilder(configfile)
     self.patch_argv("-c", configfile, "image-build", "fake-image")
     with testtools.ExpectedException(Exception):
         nodepoolcmd.main()
     self.assert_listed(configfile, ['dib-image-list'], 1, 'fake-image', 0)
Exemple #5
0
    def test_delete_now(self):
        configfile = self.setup_config('node.yaml')
        pool = self.useNodepool(configfile, watermark_sleep=1)
        self.useBuilder(configfile)

        # (Shrews): This is a hack to avoid a race with the DeletedNodeWorker
        # thread where it may see that our direct call to NodeDeleter.delete()
        # has changed the node state to DELETING and lock the node during the
        # act of deletion, but *after* the lock znode child has been deleted
        # and *before* kazoo has fully removed the node znode itself. This race
        # causes the rare kazoo.exceptions.NotEmptyError in this test because
        # a new lock znode gets created (that the original delete does not see)
        # preventing the node znode from being deleted.
        pool.delete_interval = 5

        pool.start()
        self.waitForImage('fake-provider', 'fake-image')
        nodes = self.waitForNodes('fake-label')
        self.assertEqual(len(nodes), 1)

        # Assert one node exists and it is node 1 in a ready state.
        self.assert_listed(configfile, ['list'], 0, nodes[0].id, 1)
        self.assert_nodes_listed(configfile, 1, zk.READY)

        # Delete node
        self.patch_argv('-c', configfile, 'delete', '--now', nodes[0].id)
        nodepoolcmd.main()
        self.waitForNodeDeletion(nodes[0])

        # Assert the node is gone
        self.assert_listed(configfile, ['list'], 0, nodes[0].id, 0)
Exemple #6
0
    def test_image_build(self):
        configfile = self.setup_config('node_dib.yaml')
        self._useBuilder(configfile)

        self.patch_argv("-c", configfile, "image-build", "fake-dib-diskimage")
        nodepoolcmd.main()
        self.assert_listed(configfile, ['dib-image-list'], 4, 'ready', 1)
 def test_dib_snapshot_image_update_all(self):
     configfile = self.setup_config("node_dib_and_snap.yaml")
     self._useBuilder(configfile)
     self.patch_argv("-c", configfile, "image-update", "all",
                     "fake-dib-image")
     nodepoolcmd.main()
     self.assert_images_listed(configfile, 2)
Exemple #8
0
 def test_image_delete_invalid(self):
     configfile = self.setup_config("node_cmd.yaml")
     self.patch_argv("-c", configfile, "image-delete", "--provider",
                     "invalid-provider", "--image", "invalid-image",
                     "--build-id", "invalid-build-id", "--upload-id",
                     "invalid-upload-id")
     nodepoolcmd.main()
Exemple #9
0
 def test_image_update_all(self):
     configfile = self.setup_config("node_cmd.yaml")
     self._useBuilder(configfile)
     self.patch_argv("-c", configfile, "image-update",
                     "all", "fake-image1")
     nodepoolcmd.main()
     self.assert_images_listed(configfile, 1)
Exemple #10
0
 def test_dib_image_update(self):
     configfile = self.setup_config("node_dib.yaml")
     self._useBuilder(configfile)
     self.patch_argv("-c", configfile, "image-update", "fake-dib-provider",
                     "fake-dib-image")
     nodepoolcmd.main()
     self.assert_images_listed(configfile, 1)
Exemple #11
0
    def test_delete_now(self):
        configfile = self.setup_config('node.yaml')
        pool = self.useNodepool(configfile, watermark_sleep=1)
        self.useBuilder(configfile)

        # (Shrews): This is a hack to avoid a race with the DeletedNodeWorker
        # thread where it may see that our direct call to NodeDeleter.delete()
        # has changed the node state to DELETING and lock the node during the
        # act of deletion, but *after* the lock znode child has been deleted
        # and *before* kazoo has fully removed the node znode itself. This race
        # causes the rare kazoo.exceptions.NotEmptyError in this test because
        # a new lock znode gets created (that the original delete does not see)
        # preventing the node znode from being deleted.
        pool.delete_interval = 5

        pool.start()
        self.waitForImage('fake-provider', 'fake-image')
        nodes = self.waitForNodes('fake-label')
        self.assertEqual(len(nodes), 1)

        # Assert one node exists and it is node 1 in a ready state.
        self.assert_listed(configfile, ['list'], 0, nodes[0].id, 1)
        self.assert_nodes_listed(configfile, 1, zk.READY)

        # Delete node
        self.patch_argv('-c', configfile, 'delete', '--now', nodes[0].id)
        nodepoolcmd.main()
        self.waitForNodeDeletion(nodes[0])

        # Assert the node is gone
        self.assert_listed(configfile, ['list'], 0, nodes[0].id, 0)
Exemple #12
0
 def test_alien_image_list_empty(self):
     configfile = self.setup_config("node.yaml")
     self._useBuilder(configfile)
     self.waitForImage('fake-provider', 'fake-image')
     self.patch_argv("-c", configfile, "alien-image-list")
     nodepoolcmd.main()
     self.assert_alien_images_empty(configfile)
Exemple #13
0
 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)
Exemple #14
0
 def test_alien_image_list_empty(self):
     configfile = self.setup_config("node.yaml")
     self.useBuilder(configfile)
     self.waitForImage('fake-provider', 'fake-image')
     self.patch_argv("-c", configfile, "alien-image-list")
     nodepoolcmd.main()
     self.assert_alien_images_empty(configfile)
Exemple #15
0
 def test_dib_image_build_pause(self):
     configfile = self.setup_config('node_diskimage_pause.yaml')
     self.useBuilder(configfile)
     self.patch_argv("-c", configfile, "image-build", "fake-image")
     with testtools.ExpectedException(Exception):
         nodepoolcmd.main()
     self.assert_listed(configfile, ['dib-image-list'], 1, 'fake-image', 0)
Exemple #16
0
 def test_image_delete_invalid(self):
     configfile = self.setup_config("node_cmd.yaml")
     self.patch_argv("-c", configfile, "image-delete",
                     "--provider", "invalid-provider",
                     "--image", "invalid-image",
                     "--build-id", "invalid-build-id",
                     "--upload-id", "invalid-upload-id")
     nodepoolcmd.main()
Exemple #17
0
 def test_job_delete(self):
     configfile = self.setup_config('node.yaml')
     self.patch_argv("-c", configfile, "job-create", "fake-job",
                     "--hold-on-failure", "1")
     nodepoolcmd.main()
     self.assert_listed(configfile, ['job-list'], 2, 1, 1)
     self.patch_argv("-c", configfile, "job-delete", "1")
     nodepoolcmd.main()
     self.assert_listed(configfile, ['job-list'], 0, 1, 0)
 def test_dib_snapshot_image_update(self):
     configfile = self.setup_config("node_dib_and_snap.yaml")
     self.patch_argv("-c", configfile, "image-update",
                     "fake-provider1", "fake-dib-image")
     nodepoolcmd.main()
     self.patch_argv("-c", configfile, "image-update",
                     "fake-provider2", "fake-dib-image")
     nodepoolcmd.main()
     self.assert_images_listed(configfile, 2)
Exemple #19
0
    def test_alien_image_list_fail(self):
        def fail_list(self):
            raise RuntimeError('Fake list error')
        self.useFixture(fixtures.MonkeyPatch('nodepool.fakeprovider.FakeList'
                                             '.list', fail_list))

        configfile = self.setup_config("node_cmd.yaml")
        self.patch_argv("-c", configfile, "alien-image-list")
        nodepoolcmd.main()
Exemple #20
0
 def test_image_delete(self):
     configfile = self.setup_config("node.yaml")
     self.useBuilder(configfile)
     self.waitForImage('fake-provider', 'fake-image')
     image = self.zk.getMostRecentImageUpload('fake-image', 'fake-provider')
     self.patch_argv("-c", configfile, "image-delete", "--provider",
                     "fake-provider", "--image", "fake-image", "--build-id",
                     image.build_id, "--upload-id", image.id)
     nodepoolcmd.main()
     self.waitForUploadRecordDeletion('fake-provider', 'fake-image',
                                      image.build_id, image.id)
Exemple #21
0
 def assert_listed(self, configfile, cmd, col, val, count):
     self.patch_argv("-c", configfile, *cmd)
     with mock.patch('prettytable.PrettyTable.add_row') as m_add_row:
         nodepoolcmd.main()
         rows_with_val = 0
         # Find add_rows with the status were looking for
         for args, kwargs in m_add_row.call_args_list:
             row = args[0]
             if row[col] == val:
                 rows_with_val += 1
         self.assertEquals(rows_with_val, count)
Exemple #22
0
 def assert_listed(self, configfile, cmd, col, val, count):
     self.patch_argv("-c", configfile, *cmd)
     with mock.patch('prettytable.PrettyTable.add_row') as m_add_row:
         nodepoolcmd.main()
         rows_with_val = 0
         # Find add_rows with the status were looking for
         for args, kwargs in m_add_row.call_args_list:
             row = args[0]
             if row[col] == val:
                 rows_with_val += 1
         self.assertEquals(rows_with_val, count)
Exemple #23
0
 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)
Exemple #24
0
    def test_image_delete_snapshot(self):
        configfile = self.setup_config("node_cmd.yaml")
        self.patch_argv("-c", configfile, "image-update", "all", "fake-image1")
        nodepoolcmd.main()
        pool = self.useNodepool(configfile, watermark_sleep=1)
        # This gives us a nodepool with a working db but not running which
        # is important so we can control image building
        pool.updateConfig()
        self.waitForImage(pool, 'fake-provider1', 'fake-image1')

        self.patch_argv("-c", configfile, "image-delete", '1')
        nodepoolcmd.main()
        self.assert_images_listed(configfile, 0)
Exemple #25
0
 def test_image_delete(self):
     configfile = self.setup_config("node.yaml")
     self.useBuilder(configfile)
     self.waitForImage('fake-provider', 'fake-image')
     image = self.zk.getMostRecentImageUpload('fake-image', 'fake-provider')
     self.patch_argv("-c", configfile, "image-delete",
                     "--provider", "fake-provider",
                     "--image", "fake-image",
                     "--build-id", image.build_id,
                     "--upload-id", image.id)
     nodepoolcmd.main()
     self.waitForUploadRecordDeletion('fake-provider', 'fake-image',
                                      image.build_id, image.id)
Exemple #26
0
 def test_delete_now(self):
     configfile = self.setup_config('node.yaml')
     pool = self.useNodepool(configfile, watermark_sleep=1)
     pool.start()
     self.waitForImage(pool, 'fake-provider', 'fake-image')
     self.waitForNodes(pool)
     # Assert one node exists and it is node 1 in a ready state.
     self.assert_listed(configfile, ['list'], 0, 1, 1)
     self.assert_nodes_listed(configfile, 1, 'ready')
     # Delete node 1
     self.patch_argv('-c', configfile, 'delete', '--now', '1')
     nodepoolcmd.main()
     # Assert the node is gone
     self.assert_listed(configfile, ['list'], 0, 1, 0)
Exemple #27
0
    def test_image_delete_snapshot(self):
        configfile = self.setup_config("node_cmd.yaml")
        self.patch_argv("-c", configfile, "image-update",
                        "all", "fake-image1")
        nodepoolcmd.main()
        pool = self.useNodepool(configfile, watermark_sleep=1)
        # This gives us a nodepool with a working db but not running which
        # is important so we can control image building
        pool.updateConfig()
        self.waitForImage(pool, 'fake-provider1', 'fake-image1')

        self.patch_argv("-c", configfile, "image-delete", '1')
        nodepoolcmd.main()
        self.assert_images_listed(configfile, 0)
Exemple #28
0
 def test_dib_image_delete(self):
     configfile = self.setup_config('node_dib.yaml')
     pool = self.useNodepool(configfile, watermark_sleep=1)
     pool.start()
     self.waitForImage(pool, 'fake-dib-provider', 'fake-dib-image')
     self.waitForNodes(pool)
     # Check the image exists
     self.assert_listed(configfile, ['dib-image-list'], 0, 1, 1)
     self.assert_listed(configfile, ['dib-image-list'], 4, 'ready', 1)
     # Delete the image
     self.patch_argv('-c', configfile, 'dib-image-delete', '1')
     nodepoolcmd.main()
     # Check the the image is no longer listed
     self.assert_listed(configfile, ['dib-image-list'], 0, 1, 0)
Exemple #29
0
 def test_delete_now(self):
     configfile = self.setup_config('node.yaml')
     pool = self.useNodepool(configfile, watermark_sleep=1)
     pool.start()
     self.waitForImage(pool, 'fake-provider', 'fake-image')
     self.waitForNodes(pool)
     # Assert one node exists and it is node 1 in a ready state.
     self.assert_listed(configfile, ['list'], 0, 1, 1)
     self.assert_nodes_listed(configfile, 1, 'ready')
     # Delete node 1
     self.patch_argv('-c', configfile, 'delete', '--now', '1')
     nodepoolcmd.main()
     # Assert the node is gone
     self.assert_listed(configfile, ['list'], 0, 1, 0)
Exemple #30
0
 def test_hold(self):
     configfile = self.setup_config('node.yaml')
     pool = self.useNodepool(configfile, watermark_sleep=1)
     pool.start()
     self.waitForImage(pool, 'fake-provider', 'fake-image')
     self.waitForNodes(pool)
     # Assert one node exists and it is node 1 in a ready state.
     self.assert_listed(configfile, ['list'], 0, 1, 1)
     self.assert_nodes_listed(configfile, 1, 'ready')
     # Hold node 1
     self.patch_argv('-c', configfile, 'hold', '1')
     nodepoolcmd.main()
     # Assert the state changed to HOLD
     self.assert_listed(configfile, ['list'], 0, 1, 1)
     self.assert_nodes_listed(configfile, 1, 'hold')
Exemple #31
0
 def assert_listed(self, configfile, cmd, col, val, count, col_count=0):
     log = logging.getLogger("tests.PrettyTableMock")
     self.patch_argv("-c", configfile, *cmd)
     with mock.patch('prettytable.PrettyTable.add_row') as m_add_row:
         nodepoolcmd.main()
         rows_with_val = 0
         # Find add_rows with the status were looking for
         for args, kwargs in m_add_row.call_args_list:
             row = args[0]
             if col_count:
                 self.assertEquals(len(row), col_count)
             log.debug(row)
             if row[col] == val:
                 rows_with_val += 1
         self.assertEquals(rows_with_val, count)
Exemple #32
0
 def test_hold(self):
     configfile = self.setup_config('node.yaml')
     pool = self.useNodepool(configfile, watermark_sleep=1)
     pool.start()
     self.waitForImage(pool, 'fake-provider', 'fake-image')
     self.waitForNodes(pool)
     # Assert one node exists and it is node 1 in a ready state.
     self.assert_listed(configfile, ['list'], 0, 1, 1)
     self.assert_nodes_listed(configfile, 1, 'ready')
     # Hold node 1
     self.patch_argv('-c', configfile, 'hold', '1')
     nodepoolcmd.main()
     # Assert the state changed to HOLD
     self.assert_listed(configfile, ['list'], 0, 1, 1)
     self.assert_nodes_listed(configfile, 1, 'hold')
Exemple #33
0
 def test_image_upload_all(self):
     configfile = self.setup_config('node_dib.yaml')
     pool = self.useNodepool(configfile, watermark_sleep=1)
     pool.start()
     self.waitForImage(pool, 'fake-dib-provider', 'fake-dib-image')
     self.waitForNodes(pool)
     # Check dib image exists and a single upload is available for it.
     self.assert_listed(configfile, ['dib-image-list'], 4, 'ready', 1)
     self.assert_images_listed(configfile, 1)
     # Reupload the image
     self.patch_argv('-c', configfile, 'image-upload',
                     'all', 'fake-dib-image')
     nodepoolcmd.main()
     # Check that two images are ready for it now.
     self.assert_images_listed(configfile, 2)
Exemple #34
0
 def assert_listed(self, configfile, cmd, col, val, count, col_count=0):
     log = logging.getLogger("tests.PrettyTableMock")
     self.patch_argv("-c", configfile, *cmd)
     with mock.patch('prettytable.PrettyTable.add_row') as m_add_row:
         nodepoolcmd.main()
         rows_with_val = 0
         # Find add_rows with the status were looking for
         for args, kwargs in m_add_row.call_args_list:
             row = args[0]
             if col_count:
                 self.assertEquals(len(row), col_count)
             log.debug(row)
             if row[col] == val:
                 rows_with_val += 1
         self.assertEquals(rows_with_val, count)
Exemple #35
0
    def test_image_build(self):
        configfile = self.setup_config('node.yaml')
        self.useBuilder(configfile)

        # wait for the scheduled build to arrive
        self.waitForImage('fake-provider', 'fake-image')
        self.assert_listed(configfile, ['dib-image-list'], 4, zk.READY, 1)
        image = self.zk.getMostRecentImageUpload('fake-image', 'fake-provider')

        # now do the manual build request
        self.patch_argv("-c", configfile, "image-build", "fake-image")
        nodepoolcmd.main()

        self.waitForImage('fake-provider', 'fake-image', [image])
        self.assert_listed(configfile, ['dib-image-list'], 4, zk.READY, 2)
Exemple #36
0
    def test_image_build(self):
        configfile = self.setup_config('node.yaml')
        self._useBuilder(configfile)

        # wait for the scheduled build to arrive
        self.waitForImage('fake-provider', 'fake-image')
        self.assert_listed(configfile, ['dib-image-list'], 4, zk.READY, 1)
        image = self.zk.getMostRecentImageUpload('fake-image', 'fake-provider')

        # now do the manual build request
        self.patch_argv("-c", configfile, "image-build", "fake-image")
        nodepoolcmd.main()

        self.waitForImage('fake-provider', 'fake-image', [image])
        self.assert_listed(configfile, ['dib-image-list'], 4, zk.READY, 2)
Exemple #37
0
    def test_info_and_erase(self):
        configfile = self.setup_config('info_cmd_two_provider.yaml')
        pool = self.useNodepool(configfile, watermark_sleep=1)
        self.useBuilder(configfile)
        pool.start()
        p1_image = self.waitForImage('fake-provider', 'fake-image')
        p1_nodes = self.waitForNodes('fake-label')
        p2_nodes = self.waitForNodes('fake-label2')

        # Get rid of the second provider so that when we remove its
        # data from ZooKeeper, the builder and launcher don't attempt to
        # recreate the data.
        self.replace_config(configfile, 'info_cmd_two_provider_remove.yaml')

        # Verify that the second provider image is listed
        self.assert_listed(
            configfile,
            ['info', 'fake-provider2'],
            0, 'fake-image', 1)

        # Verify that the second provider node is listed.
        self.assert_listed(
            configfile,
            ['info', 'fake-provider2'],
            0, p2_nodes[0].id, 1)

        # Erase the data for the second provider
        self.patch_argv(
            "-c", configfile, 'erase', 'fake-provider2', '--force')
        nodepoolcmd.main()

        # Verify that no build or node for the second provider is listed
        # after the previous erase
        self.assert_listed(
            configfile,
            ['info', 'fake-provider2'],
            0, 'fake-image', 0)
        self.assert_listed(
            configfile,
            ['info', 'fake-provider2'],
            0, p2_nodes[0].id, 0)

        # Verify that we did not affect the first provider
        image = self.waitForImage('fake-provider', 'fake-image')
        self.assertEqual(p1_image, image)
        nodes = self.waitForNodes('fake-label')
        self.assertEqual(1, len(nodes))
        self.assertEqual(p1_nodes[0], nodes[0])
Exemple #38
0
 def test_dib_image_delete(self):
     configfile = self.setup_config('node.yaml')
     pool = self.useNodepool(configfile, watermark_sleep=1)
     self._useBuilder(configfile)
     pool.start()
     self.waitForImage('fake-provider', 'fake-image')
     self.waitForNodes(pool)
     # Check the image exists
     self.assert_listed(configfile, ['dib-image-list'], 4, zk.READY, 1)
     builds = self.zk.getMostRecentBuilds(1, 'fake-image', zk.READY)
     # Delete the image
     self.patch_argv('-c', configfile, 'dib-image-delete',
                     'fake-image-%s' % (builds[0].id))
     nodepoolcmd.main()
     self.waitForBuildDeletion('fake-image', '0000000001')
     # Check that fake-image-0000000001 doesn't exist
     self.assert_listed(
         configfile, ['dib-image-list'], 0, 'fake-image-0000000001', 0)
Exemple #39
0
    def test_delete(self):
        configfile = self.setup_config('node.yaml')
        pool = self.useNodepool(configfile, watermark_sleep=1)
        self.useBuilder(configfile)
        pool.start()
        self.waitForImage('fake-provider', 'fake-image')
        nodes = self.waitForNodes('fake-label')
        self.assertEqual(len(nodes), 1)

        # Assert one node exists and it is nodes[0].id in a ready state.
        self.assert_listed(configfile, ['list'], 0, nodes[0].id, 1)
        self.assert_nodes_listed(configfile, 1, zk.READY)

        # Delete node
        self.patch_argv('-c', configfile, 'delete', nodes[0].id)
        nodepoolcmd.main()
        self.waitForNodeDeletion(nodes[0])

        # Assert the node is gone
        self.assert_listed(configfile, ['list'], 0, nodes[0].id, 0)
Exemple #40
0
    def test_delete(self):
        configfile = self.setup_config('node.yaml')
        pool = self.useNodepool(configfile, watermark_sleep=1)
        self.useBuilder(configfile)
        pool.start()
        self.waitForImage('fake-provider', 'fake-image')
        nodes = self.waitForNodes('fake-label')
        self.assertEqual(len(nodes), 1)

        # Assert one node exists and it is nodes[0].id in a ready state.
        self.assert_listed(configfile, ['list'], 0, nodes[0].id, 1)
        self.assert_nodes_listed(configfile, 1, zk.READY)

        # Delete node
        self.patch_argv('-c', configfile, 'delete', nodes[0].id)
        nodepoolcmd.main()
        self.waitForNodeDeletion(nodes[0])

        # Assert the node is gone
        self.assert_listed(configfile, ['list'], 0, nodes[0].id, 0)
Exemple #41
0
 def assert_listed(self, configfile, cmd, col, val, count, col_count=0):
     log = logging.getLogger("tests.PrettyTableMock")
     self.patch_argv("-c", configfile, *cmd)
     for _ in iterate_timeout(10, AssertionError, 'assert listed'):
         try:
             with mock.patch('prettytable.PrettyTable.add_row') as \
                     m_add_row:
                 nodepoolcmd.main()
                 rows_with_val = 0
                 # Find add_rows with the status were looking for
                 for args, kwargs in m_add_row.call_args_list:
                     row = args[0]
                     if col_count:
                         self.assertEquals(len(row), col_count)
                     log.debug(row)
                     if row[col] == val:
                         rows_with_val += 1
                 self.assertEquals(rows_with_val, count)
             break
         except AssertionError:
             # retry
             pass
 def assert_listed(self, configfile, cmd, col, val, count, col_count=0):
     log = logging.getLogger("tests.PrettyTableMock")
     self.patch_argv("-c", configfile, *cmd)
     for _ in iterate_timeout(10, AssertionError, 'assert listed'):
         try:
             with mock.patch('prettytable.PrettyTable.add_row') as \
                     m_add_row:
                 nodepoolcmd.main()
                 rows_with_val = 0
                 # Find add_rows with the status were looking for
                 for args, kwargs in m_add_row.call_args_list:
                     row = args[0]
                     if col_count:
                         self.assertEquals(len(row), col_count)
                     log.debug(row)
                     if row[col] == val:
                         rows_with_val += 1
                 self.assertEquals(rows_with_val, count)
             break
         except AssertionError:
             # retry
             pass
Exemple #43
0
    def test_info_and_erase(self):
        configfile = self.setup_config('info_cmd_two_provider.yaml')
        pool = self.useNodepool(configfile, watermark_sleep=1)
        self.useBuilder(configfile)
        pool.start()
        p1_image = self.waitForImage('fake-provider', 'fake-image')
        p1_nodes = self.waitForNodes('fake-label')
        p2_nodes = self.waitForNodes('fake-label2')

        # Get rid of the second provider so that when we remove its
        # data from ZooKeeper, the builder and launcher don't attempt to
        # recreate the data.
        self.replace_config(configfile, 'info_cmd_two_provider_remove.yaml')

        # Verify that the second provider image is listed
        self.assert_listed(configfile, ['info', 'fake-provider2'], 0,
                           'fake-image', 1)

        # Verify that the second provider node is listed.
        self.assert_listed(configfile, ['info', 'fake-provider2'], 0,
                           p2_nodes[0].id, 1)

        # Erase the data for the second provider
        self.patch_argv("-c", configfile, 'erase', 'fake-provider2', '--force')
        nodepoolcmd.main()

        # Verify that no build or node for the second provider is listed
        # after the previous erase
        self.assert_listed(configfile, ['info', 'fake-provider2'], 0,
                           'fake-image', 0)
        self.assert_listed(configfile, ['info', 'fake-provider2'], 0,
                           p2_nodes[0].id, 0)

        # Verify that we did not affect the first provider
        image = self.waitForImage('fake-provider', 'fake-image')
        self.assertEqual(p1_image, image)
        nodes = self.waitForNodes('fake-label')
        self.assertEqual(1, len(nodes))
        self.assertEqual(p1_nodes[0], nodes[0])
Exemple #44
0
 def test_config_validate(self):
     config = os.path.join(os.path.dirname(tests.__file__),
                           'fixtures', 'config_validate', 'good.yaml')
     self.patch_argv('-c', config, 'config-validate')
     nodepoolcmd.main()
Exemple #45
0
 def test_without_argument(self):
     configfile = self.setup_config("node_cmd.yaml")
     self.patch_argv("-c", configfile)
     result = nodepoolcmd.main()
     self.assertEqual(1, result)
Exemple #46
0
 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.assert_images_listed(configfile, 1)
Exemple #47
0
 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.assert_images_listed(configfile, 1)
Exemple #48
0
 def test_without_argument(self):
     configfile = self.setup_config("node_cmd.yaml")
     self.patch_argv("-c", configfile)
     result = nodepoolcmd.main()
     self.assertEqual(1, result)
Exemple #49
0
 def test_config_validate(self):
     config = os.path.join(os.path.dirname(tests.__file__),
                           'fixtures', 'config_validate', 'good.yaml')
     self.patch_argv('-c', config, 'config-validate')
     nodepoolcmd.main()
Exemple #50
0
 def test_image_delete_invalid(self):
     configfile = self.setup_config("node_cmd.yaml")
     self.patch_argv("-c", configfile, "image-delete", "invalid-image")
     nodepoolcmd.main()
Exemple #51
0
 def test_image_delete_invalid(self):
     configfile = self.setup_config("node_cmd.yaml")
     self.patch_argv("-c", configfile, "image-delete", "invalid-image")
     nodepoolcmd.main()