def test_get_servers(self): # Fetch the default pool pool = self.storage.get_pool(self.admin_context, default_pool_id) # Fetch the list of servers response = self.get('servers') self.assertIn('servers', response.json) self.assertEqual(len(pool.ns_records), len(response.json['servers'])) # Add a new NS record to the pool pool.ns_records.append( objects.PoolNsRecord(priority=0, hostname='new-ns1.example.org.')) # Save the pool to add a new nameserver self.storage.update_pool(self.admin_context, pool) # Fetch the list of servers response = self.get('servers') self.assertIn('servers', response.json) self.assertEqual(len(pool.ns_records), len(response.json['servers'])) # Add a new NS record to the pool pool.ns_records.append( objects.PoolNsRecord(priority=0, hostname='new-ns2.example.org.')) # Save the pool to add a new nameserver self.storage.update_pool(self.admin_context, pool) response = self.get('servers') self.assertIn('servers', response.json) self.assertEqual(len(pool.ns_records), len(response.json['servers']))
def _setup_default_pool(self): # Fetch the default pool pool = self.storage.get_pool(self.admin_context, default_pool_id) # Add a NS record to it pool.ns_records.append( objects.PoolNsRecord(priority=0, hostname='ns1.example.org.')) # Save the default pool self.storage.update_pool(self.admin_context, pool)
def load(self, context, request, body): """Extract a "central" compatible dict from an API call""" valid_keys = ('name', 'attributes', 'ns_records', 'description') result = self._load(context, request, body, valid_keys) if 'ns_records' in result: result['ns_records'] = objects.PoolNsRecordList( objects=[objects.PoolNsRecord(priority=r['priority'], hostname=r['hostname']) for r in result['ns_records']]) if 'attributes' in result: result['attributes'] = objects.PoolAttributeList( objects=[objects.PoolAttribute( key=r, value=result['attributes'][r]) for r in result['attributes']]) return result
def test_delete_server(self): # Fetch the default pool pool = self.storage.get_pool(self.admin_context, default_pool_id) # Create a second server so that we can delete the first # because the last remaining server is not allowed to be deleted # Add a new NS record to the pool pool.ns_records.append( objects.PoolNsRecord(priority=0, hostname='new-ns2.example.org.')) # Save the pool to add a new nameserver self.storage.update_pool(self.admin_context, pool) # Now delete the server self.delete('servers/%s' % pool.ns_records[1].id) # Ensure we can no longer fetch the deleted server self.get('servers/%s' % pool.ns_records[1].id, status_code=404) # Also, verify we cannot delete last remaining server self.delete('servers/%s' % pool.ns_records[0].id, status_code=400)
def get_server(server_id): context = flask.request.environ.get('context') central_api = central_rpcapi.CentralAPI.get_instance() # Get the default pool pool = central_api.get_pool(context, default_pool_id) # Create an empty PoolNsRecord object nameserver = objects.PoolNsRecord() # Get the desired nameserver from the pool for ns in pool.ns_records: if ns.id == server_id: nameserver = ns break # If the nameserver wasn't found, raise an exception if nameserver.id != server_id: raise exceptions.ServerNotFound server = _pool_ns_record_to_server(nameserver) return flask.jsonify(server_schema.filter(server))