def test_patch_pool(self, params): """Create a pool. Issue a patch command, make sure command was successful. Check details to be sure. """ doc = helpers.create_pool_body( weight=params.get('weight', 10), uri=params.get('uri', "mongodb://127.0.0.1:27017") ) pool_name = params.get('name', "newpool") self.addCleanup(self.client.delete, url='/'+pool_name) result = self.client.put('/'+pool_name, data=doc) self.assertEqual(result.status_code, 201) # Update that pool patchdoc = helpers.create_pool_body( weight=5, uri="mongodb://127.0.0.1:27017" ) result = self.client.patch('/'+pool_name, data=patchdoc) self.assertEqual(result.status_code, 200) # Get the pool, check update# result = self.client.get('/'+pool_name) self.assertEqual(result.status_code, 200) self.assertEqual(result.json()["weight"], 5)
def test_patch_pool_non_exist(self, params): """Issue patch command to pool that doesn't exist. Assert 404.""" doc = helpers.create_pool_body(weight=5, uri=params.get( 'uri', "mongodb://127.0.0.1:27018")) result = self.client.patch('/nonexistpool', data=doc) self.assertEqual(result.status_code, 404)
def test_patch_pool_non_exist(self, params): """Issue patch command to pool that doesn't exist. Assert 404.""" doc = helpers.create_pool_body( weight=5, uri=params.get('uri', "mongodb://127.0.0.1:27018") ) result = self.client.patch('/nonexistpool', data=doc) self.assertEqual(result.status_code, 404)
def test_patch_pool_non_exist(self, params): """Issue patch command to pool that doesn't exist. Assert 404.""" doc = helpers.create_pool_body( weight=5, uri=self.mongodb_url ) result = self.client.patch('/nonexistpool', data=doc) self.assertEqual(404, result.status_code)
def test_insert_pool_bad_data(self, params): """Create pools with invalid names and weights. Assert 400.""" doc = helpers.create_pool_body(weight=params.get('weight', 10), uri=params.get( 'uri', "mongodb://127.0.0.1:27017")) pool_name = params.get('name', "newpool") self.addCleanup(self.client.delete, url='/' + pool_name) result = self.client.put('/' + pool_name, data=doc) self.assertEqual(result.status_code, 400)
def test_insert_pool_bad_data(self, params): """Create pools with invalid names and weights. Assert 400.""" self.skip("FIXME: https://bugs.launchpad.net/zaqar/+bug/1373486") doc = helpers.create_pool_body(weight=params.get('weight', 10), uri=self.mongodb_url) pool_name = params.get('name', "newpool") self.addCleanup(self.client.delete, url='/' + pool_name) result = self.client.put('/' + pool_name, data=doc) self.assertEqual(400, result.status_code)
def test_insert_pool_bad_data(self, params): """Create pools with invalid names and weights. Assert 400.""" doc = helpers.create_pool_body( weight=params.get('weight', 10), uri=params.get('uri', "mongodb://127.0.0.1:27017") ) pool_name = params.get('name', "newpool") self.addCleanup(self.client.delete, url='/'+pool_name) result = self.client.put('/'+pool_name, data=doc) self.assertEqual(result.status_code, 400)
def test_insert_pool_bad_data(self, params): """Create pools with invalid names and weights. Assert 400.""" self.skip("FIXME: https://bugs.launchpad.net/zaqar/+bug/1373486") doc = helpers.create_pool_body( weight=params.get("weight", 10), uri=params.get("uri", "mongodb://127.0.0.1:27017") ) pool_name = params.get("name", "newpool") self.addCleanup(self.client.delete, url="/" + pool_name) result = self.client.put("/" + pool_name, data=doc) self.assertEqual(result.status_code, 400)
def test_health_with_pool(self): # FIXME(flwang): Please use mongodb after the sqlalchemy is disabled # as pool node and the mongodb is working on gate successfully. doc = helpers.create_pool_body( weight=10, uri=self.mconf['drivers:management_store:mongodb'].uri, options=dict(database='zaqar_test_pooled_1')) pool_name = "pool_1" self.addCleanup(self.client.delete, url='/pools/' + pool_name) result = self.client.put('/pools/' + pool_name, data=doc) self.assertEqual(result.status_code, 201) queue_name = 'fake_queue' self.addCleanup(self.client.delete, url='/queues/' + queue_name) result = self.client.put('/queues/' + queue_name) self.assertEqual(result.status_code, 201) sample_messages = { 'messages': [{ 'body': 239, 'ttl': 999 }, { 'body': { 'key': 'value' }, 'ttl': 888 }] } result = self.client.post('/queues/%s/messages' % queue_name, data=sample_messages) self.assertEqual(result.status_code, 201) claim_metadata = {'ttl': 100, 'grace': 300} result = self.client.post('/queues/%s/claims' % queue_name, data=claim_metadata) self.assertEqual(result.status_code, 201) response = self.client.get('/health') self.assertEqual(response.status_code, 200) health = response.json() self.assertEqual(health['catalog_reachable'], True) self.assertEqual(health[pool_name]['storage_reachable'], True) op_status = health[pool_name]['operation_status'] for op in op_status.keys(): self.assertTrue(op_status[op]['succeeded']) message_volume = health[pool_name]['message_volume'] self.assertEqual(message_volume['claimed'], 2) self.assertEqual(message_volume['free'], 0) self.assertEqual(message_volume['total'], 2)
def test_insert_pool_bad_data(self, params): """Create pools with invalid names and weights. Assert 400.""" self.skip("FIXME: https://bugs.launchpad.net/zaqar/+bug/1373486") doc = helpers.create_pool_body( weight=params.get('weight', 10), uri=self.mongodb_url ) pool_name = params.get('name', "newpool") self.addCleanup(self.client.delete, url='/'+pool_name) result = self.client.put('/'+pool_name, data=doc) self.assertEqual(400, result.status_code)
def test_patch_pool_bad_data(self, params): """Issue a patch command without a body. Assert 400.""" # create a pool doc = helpers.create_pool_body(weight=params.get('weight', 10), uri=self.mongodb_url) pool_name = params.get('name', "newpool") self.addCleanup(self.client.delete, url='/' + pool_name) result = self.client.put('/' + pool_name, data=doc) self.assertEqual(201, result.status_code) # Update pool with bad post data. Ensure 400 result = self.client.patch('/' + pool_name) self.assertEqual(400, result.status_code)
def test_insert_pool(self, params): """Test the registering of one pool.""" doc = helpers.create_pool_body(weight=params.get('weight', 10), uri=self.mongodb_url) pool_name = params.get('name', "newpool") self.addCleanup(self.client.delete, url='/' + pool_name) result = self.client.put('/' + pool_name, data=doc) self.assertEqual(201, result.status_code) # Test existence result = self.client.get('/' + pool_name) self.assertEqual(200, result.status_code)
def test_pool_details(self, params): """Get the details of a pool. Assert the respective schema.""" doc = helpers.create_pool_body(weight=params.get('weight', 10), uri=self.mongodb_url) pool_name = params.get('name', "newpool") self.addCleanup(self.client.delete, url='/' + pool_name) result = self.client.put('/' + pool_name, data=doc) self.assertEqual(201, result.status_code) # Test existence result = self.client.get('/' + pool_name + '?detailed=true') self.assertEqual(200, result.status_code) self.assertSchema(result.json(), 'pool_get_detail')
def test_patch_pool_bad_data(self, params): """Issue a patch command without a body. Assert 400.""" # create a pool doc = helpers.create_pool_body( weight=params.get("weight", 10), uri=params.get("uri", "mongodb://127.0.0.1:27017") ) pool_name = params.get("name", "newpool") self.addCleanup(self.client.delete, url="/" + pool_name) result = self.client.put("/" + pool_name, data=doc) self.assertEqual(result.status_code, 201) # Update pool with bad post data. Ensure 400 result = self.client.patch("/" + pool_name) self.assertEqual(result.status_code, 400)
def test_health_with_pool(self): # FIXME(flwang): Please use mongodb after the sqlalchemy is disabled # as pool node and the mongodb is working on gate successfully. doc = helpers.create_pool_body( weight=10, uri="mongodb://localhost:27017", options=dict(database='zaqar_test_pooled_1') ) pool_name = "pool_1" self.addCleanup(self.client.delete, url='/pools/' + pool_name) result = self.client.put('/pools/' + pool_name, data=doc) self.assertEqual(result.status_code, 201) queue_name = 'fake_queue' self.addCleanup(self.client.delete, url='/queues/' + queue_name) result = self.client.put('/queues/' + queue_name) self.assertEqual(result.status_code, 201) sample_messages = {'messages': [ {'body': 239, 'ttl': 999}, {'body': {'key': 'value'}, 'ttl': 888} ]} result = self.client.post('/queues/%s/messages' % queue_name, data=sample_messages) self.assertEqual(result.status_code, 201) claim_metadata = {'ttl': 100, 'grace': 300} result = self.client.post('/queues/%s/claims' % queue_name, data=claim_metadata) self.assertEqual(result.status_code, 201) response = self.client.get('/health') self.assertEqual(response.status_code, 200) health = response.json() self.assertEqual(health['catalog_reachable'], True) self.assertEqual(health[pool_name]['storage_reachable'], True) op_status = health[pool_name]['operation_status'] for op in op_status.keys(): self.assertTrue(op_status[op]['succeeded']) message_volume = health[pool_name]['message_volume'] self.assertEqual(message_volume['claimed'], 2) self.assertEqual(message_volume['free'], 0) self.assertEqual(message_volume['total'], 2)
def test_list_pools(self, params): """Add a pool. Get the list of all the pools. Assert respective schema """ doc = helpers.create_pool_body(weight=params.get('weight', 10), uri=self.mongodb_url) pool_name = params.get('name', "newpool") self.addCleanup(self.client.delete, url='/' + pool_name) result = self.client.put('/' + pool_name, data=doc) self.assertEqual(201, result.status_code) result = self.client.get() self.assertEqual(200, result.status_code) self.assertSchema(result.json(), 'pool_list')
def test_patch_pool_bad_data(self, params): """Issue a patch command without a body. Assert 400.""" # create a pool doc = helpers.create_pool_body( weight=params.get('weight', 10), uri=self.mongodb_url ) pool_name = params.get('name', "newpool") self.addCleanup(self.client.delete, url='/'+pool_name) result = self.client.put('/'+pool_name, data=doc) self.assertEqual(201, result.status_code) # Update pool with bad post data. Ensure 400 result = self.client.patch('/'+pool_name) self.assertEqual(400, result.status_code)
def test_pool_details(self, params): """Get the details of a pool. Assert the respective schema.""" doc = helpers.create_pool_body( weight=params.get("weight", 10), uri=params.get("uri", "mongodb://127.0.0.1:27017") ) pool_name = params.get("name", "newpool") self.addCleanup(self.client.delete, url="/" + pool_name) result = self.client.put("/" + pool_name, data=doc) self.assertEqual(result.status_code, 201) # Test existence result = self.client.get("/" + pool_name + "?detailed=true") self.assertEqual(result.status_code, 200) self.assertSchema(result.json(), "pool_detail")
def test_insert_pool(self, params): """Test the registering of one pool.""" doc = helpers.create_pool_body( weight=params.get("weight", 10), uri=params.get("uri", "mongodb://127.0.0.1:27017") ) pool_name = params.get("name", "newpool") self.addCleanup(self.client.delete, url="/" + pool_name) result = self.client.put("/" + pool_name, data=doc) self.assertEqual(result.status_code, 201) # Test existence result = self.client.get("/" + pool_name) self.assertEqual(result.status_code, 200)
def test_insert_pool(self, params): """Test the registering of one pool.""" doc = helpers.create_pool_body( weight=params.get('weight', 10), uri=self.mongodb_url ) pool_name = params.get('name', "newpool") self.addCleanup(self.client.delete, url='/'+pool_name) result = self.client.put('/'+pool_name, data=doc) self.assertEqual(201, result.status_code) # Test existence result = self.client.get('/'+pool_name) self.assertEqual(200, result.status_code)
def test_pool_details(self, params): """Get the details of a pool. Assert the respective schema.""" doc = helpers.create_pool_body( weight=params.get('weight', 10), uri=self.mongodb_url ) pool_name = params.get('name', "newpool") self.addCleanup(self.client.delete, url='/'+pool_name) result = self.client.put('/'+pool_name, data=doc) self.assertEqual(201, result.status_code) # Test existence result = self.client.get('/'+pool_name+'?detailed=true') self.assertEqual(200, result.status_code) self.assertSchema(result.json(), 'pool_get_detail')
def test_list_pools(self, params): """Add a pool. Get the list of all the pools. Assert respective schema """ doc = helpers.create_pool_body( weight=params.get("weight", 10), uri=params.get("uri", "mongodb://127.0.0.1:27017") ) pool_name = params.get("name", "newpool") self.addCleanup(self.client.delete, url="/" + pool_name) result = self.client.put("/" + pool_name, data=doc) self.assertEqual(result.status_code, 201) result = self.client.get() self.assertEqual(result.status_code, 200) self.assertSchema(result.json(), "pool_list")
def test_list_pools(self, params): """Add a pool. Get the list of all the pools. Assert respective schema """ doc = helpers.create_pool_body( weight=params.get('weight', 10), uri=self.mongodb_url ) pool_name = params.get('name', "newpool") self.addCleanup(self.client.delete, url='/'+pool_name) result = self.client.put('/'+pool_name, data=doc) self.assertEqual(201, result.status_code) result = self.client.get() self.assertEqual(200, result.status_code) self.assertSchema(result.json(), 'pool_list')
def test_delete_pool(self, params): """Create a pool, then delete it. Make sure operation is successful. """ # Create the pool doc = helpers.create_pool_body(weight=params.get('weight', 10), uri=self.mongodb_url) pool_name = params.get('name', "newpool") result = self.client.put('/' + pool_name, data=doc) self.assertEqual(201, result.status_code) # Make sure it exists result = self.client.get('/' + pool_name) self.assertEqual(200, result.status_code) # Delete it result = self.client.delete('/' + pool_name) self.assertEqual(204, result.status_code)
def test_delete_pool(self, params): """Create a pool, then delete it. Make sure operation is successful. """ # Create the pool doc = helpers.create_pool_body( weight=params.get("weight", 10), uri=params.get("uri", "mongodb://127.0.0.1:27017") ) pool_name = params.get("name", "newpool") result = self.client.put("/" + pool_name, data=doc) self.assertEqual(result.status_code, 201) # Make sure it exists result = self.client.get("/" + pool_name) self.assertEqual(result.status_code, 200) # Delete it result = self.client.delete("/" + pool_name) self.assertEqual(result.status_code, 204)
def test_delete_pool(self, params): """Create a pool, then delete it. Make sure operation is successful. """ # Create the pool doc = helpers.create_pool_body( weight=params.get('weight', 10), uri=self.mongodb_url ) pool_name = params.get('name', "newpool") result = self.client.put('/'+pool_name, data=doc) self.assertEqual(201, result.status_code) # Make sure it exists result = self.client.get('/'+pool_name) self.assertEqual(200, result.status_code) # Delete it result = self.client.delete('/'+pool_name) self.assertEqual(204, result.status_code)