def test_node_caching(self): ''' Test that node iteration using both cached and uncached calls produces identical results. ''' # Test new node in node set n1 = self._create_node() # uncached a1 = self.zk.nodeIterator(cached=False) self.assertEqual(n1, next(a1)) # cached a2 = self.zk.nodeIterator(cached=True) self.assertEqual(n1, next(a2)) with testtools.ExpectedException(StopIteration): next(a2) # Test modification of existing node set n1.state = zk.HOLD n1.label = "oompaloompa" self.zk.storeNode(n1) # uncached b1 = self.zk.nodeIterator(cached=False) self.assertEqual(n1, next(b1)) # cached for _ in iterate_timeout(10, Exception, "cached node equals original node"): b2 = self.zk.nodeIterator(cached=True) if n1 == next(b2): break
def waitForNodeCleanup(self, server_id, timeout=600): """Wait for a node to be cleaned up When called, this will be called after :py:meth:`~nodepool.driver.Provider.cleanupNode`. This method should return after the node has been deleted or returned to the pool. :param str node_id: The id of the node """ manager = packet.Manager(self.provider.auth_token) try: for count in iterate_timeout(timeout, packet.baseapi.Error, "server %s deletion" % server_id): self.cleanupNode(server_id) device = manager.get_device(server_id) except packet.baseapi.Error as e: if e.args[0] == 'Error 404: Not found': return if e.args[0] == 'Error 403: You are not authorized to view this device': return else: raise e
def test_node_caching(self): ''' Test that node iteration using both cached and uncached calls produces identical results. ''' # Test new node in node set n1 = self._create_node() # uncached a1 = self.zk.nodeIterator(cached=False) self.assertEqual(n1, next(a1)) # cached a2 = self.zk.nodeIterator(cached=True) self.assertEqual(n1, next(a2)) with testtools.ExpectedException(StopIteration): next(a2) # Test modification of existing node set n1.state = zk.HOLD n1.label = "oompaloompa" self.zk.storeNode(n1) # uncached b1 = self.zk.nodeIterator(cached=False) self.assertEqual(n1, next(b1)) # cached for _ in iterate_timeout(10, Exception, "cached node equals original node"): b2 = self.zk.nodeIterator(cached=True) if n1 == next(b2): break
def test_list_nodes_detail(self): configfile = self.setup_config('node.yaml') self.useBuilder(configfile) pool = self.useNodepool(configfile, watermark_sleep=1) pool.start() self.waitForImage('fake-provider', 'fake-image') self.waitForNodes('fake-label') for _ in iterate_timeout(10, Exception, "assert nodes are listed"): try: self.assert_nodes_listed(configfile, 1, detail=True, validate_col_count=True) break except AssertionError: # node is not listed yet, retry later pass
def test_list_nodes_detail(self): configfile = self.setup_config('node.yaml') self.useBuilder(configfile) pool = self.useNodepool(configfile, watermark_sleep=1) pool.start() self.waitForImage('fake-provider', 'fake-image') self.waitForNodes('fake-label') for _ in iterate_timeout(10, Exception, "assert nodes are listed"): try: self.assert_nodes_listed(configfile, 1, detail=True, validate_col_count=True) break except AssertionError: # node is not listed yet, retry later 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
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 waitForImage(self, image_id, timeout=3600): last_status = None for count in iterate_timeout( timeout, exceptions.ImageCreateException, "image creation"): try: image = self.getImage(image_id) except exceptions.NotFound: continue except ManagerStoppedException: raise except Exception: self.log.exception('Unable to list images while waiting for ' '%s will retry' % (image_id)) continue # shade returns None when not found if not image: continue status = image['status'] if (last_status != status): self.log.debug( 'Status of image in {provider} {id}: {status}'.format( provider=self.provider.name, id=image_id, status=status)) if status == 'ERROR' and 'fault' in image: self.log.debug( 'ERROR in {provider} on {id}: {resason}'.format( provider=self.provider.name, id=image_id, resason=image['fault']['message'])) last_status = status # Glance client returns lower case statuses - but let's be sure if status.lower() in ['active', 'error']: return image
def waitForImage(self, image_id, timeout=3600): last_status = None for count in iterate_timeout(timeout, exceptions.ImageCreateException, "image creation"): try: image = self.getImage(image_id) except exceptions.NotFound: continue except ManagerStoppedException: raise except Exception: self.log.exception('Unable to list images while waiting for ' '%s will retry' % (image_id)) continue # shade returns None when not found if not image: continue status = image['status'] if (last_status != status): self.log.debug( 'Status of image in {provider} {id}: {status}'.format( provider=self.provider.name, id=image_id, status=status)) if status == 'ERROR' and 'fault' in image: self.log.debug( 'ERROR in {provider} on {id}: {resason}'.format( provider=self.provider.name, id=image_id, resason=image['fault']['message'])) last_status = status # Glance client returns lower case statuses - but let's be sure if status.lower() in ['active', 'error']: return image
def waitForNodeCleanup(self, server_id, timeout=600): for count in iterate_timeout( timeout, exceptions.ServerDeleteException, "server %s deletion" % server_id): if not self.getServer(server_id): return
def waitForNodeCleanup(self, server_id, timeout=600): for count in iterate_timeout(timeout, exceptions.ServerDeleteException, "server %s deletion" % server_id): if not self.getServer(server_id): return
def waitForNodeCleanup(self, server_id, timeout=600): for count in iterate_timeout(timeout, exceptions.ServerDeleteException, "server %s deletion" % server_id): server = self.getServer(server_id) if not server or server.status == "DELETED": return