Author: aconway
Date: Fri Jun 13 19:08:23 2014
New Revision: 1602495
URL: http://svn.apache.org/r1602495
Log:
DISPATCH-56: Simplify and cleanup of qpid_dispatch_internal.management module.
Added:
qpid/dispatch/trunk/python/qpid_dispatch_internal/management/node.py
- copied, changed from r1602494,
qpid/dispatch/trunk/python/qpid_dispatch_internal/management/amqp.py
qpid/dispatch/trunk/tests/management/node.py
- copied, changed from r1602494,
qpid/dispatch/trunk/tests/management/amqp.py
Removed:
qpid/dispatch/trunk/python/qpid_dispatch_internal/management/amqp.py
qpid/dispatch/trunk/tests/management/amqp.py
Modified:
qpid/dispatch/trunk/doc/man/qdrouterd_man.py
qpid/dispatch/trunk/python/qpid_dispatch_internal/management/__init__.py
qpid/dispatch/trunk/python/qpid_dispatch_internal/management/entity.py
qpid/dispatch/trunk/python/qpid_dispatch_internal/management/qdrouter.json
qpid/dispatch/trunk/python/qpid_dispatch_internal/management/qdrouter.py
qpid/dispatch/trunk/python/qpid_dispatch_internal/management/schema.py
qpid/dispatch/trunk/tests/management/__init__.py
qpid/dispatch/trunk/tests/management/entity.py
qpid/dispatch/trunk/tests/management/qdrouter.py
qpid/dispatch/trunk/tests/management/schema.py
qpid/dispatch/trunk/tests/system_test.py
qpid/dispatch/trunk/tests/system_tests_broker.py
qpid/dispatch/trunk/tests/system_tests_management.py
qpid/dispatch/trunk/tools/qdstat
Modified: qpid/dispatch/trunk/doc/man/qdrouterd_man.py
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/doc/man/qdrouterd_man.py?rev=1602495&r1=1602494&r2=1602495&view=diff
==============================================================================
--- qpid/dispatch/trunk/doc/man/qdrouterd_man.py (original)
+++ qpid/dispatch/trunk/doc/man/qdrouterd_man.py Fri Jun 13 19:08:23 2014
@@ -21,10 +21,10 @@
Generate the qdrouterd.conf man page from the qdrouterd management schema."""
import sys
-from qpid_dispatch_internal.management.qdrouter import Schema
+from qpid_dispatch_internal.management import QdSchema
def make_man_page(filename):
- """Generate a man page for the configuration file from L{Schema}
descriptions"""
+ """Generate a man page for the configuration file from L{QdSchema}
descriptions"""
with open(filename, 'w') as f:
f.write(
@@ -99,7 +99,7 @@ the attributes associated with each type
for attr in attrs.attributes.itervalues():
write_attribute(attr, attrs)
- schema = Schema()
+ schema = QdSchema()
for include in schema.includes.itervalues():
f.write('.SS "\'%s\' include group"\n'% include.name)
write_attributes(include)
Modified:
qpid/dispatch/trunk/python/qpid_dispatch_internal/management/__init__.py
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/python/qpid_dispatch_internal/management/__init__.py?rev=1602495&r1=1602494&r2=1602495&view=diff
==============================================================================
--- qpid/dispatch/trunk/python/qpid_dispatch_internal/management/__init__.py
(original)
+++ qpid/dispatch/trunk/python/qpid_dispatch_internal/management/__init__.py
Fri Jun 13 19:08:23 2014
@@ -17,3 +17,8 @@
# under the License.
#
"""Management package"""
+
+from .entity import Entity, EntityList
+from .node import Url, Node, ManagementError
+from .qdrouter import QdSchema, QdConfig
+from .schema import Type, BooleanType, EnumType, AttributeType,
AttributeTypeHolder, IncludeType, EntityType, Schema, schema_file
Modified: qpid/dispatch/trunk/python/qpid_dispatch_internal/management/entity.py
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/python/qpid_dispatch_internal/management/entity.py?rev=1602495&r1=1602494&r2=1602495&view=diff
==============================================================================
--- qpid/dispatch/trunk/python/qpid_dispatch_internal/management/entity.py
(original)
+++ qpid/dispatch/trunk/python/qpid_dispatch_internal/management/entity.py Fri
Jun 13 19:08:23 2014
@@ -18,149 +18,53 @@
##
"""
-Representation of AMQP management entities.
-
-An entity has a set of named attributes and an L{EntityType} defined by a
L{Schema}.
+Representation of management entities. An entity is a set of named attributes.
"""
-from schema import EntityType
-from copy import copy
+try:
+ from collections import OrderedDict
+except:
+ from qpid_dispatch_internal.ordereddict import OrderedDict # For python <=
2.6
-class Entity(object):
- """
- A management entity: a set of attributes with an associated entity-type.
- @ivar entity_type: The type of the entity.
- @type entitytype: L{EntityType}
- @ivar attributes: The attribute values.
- @type attribute: dict.
- @ivar I{attribute-name}: Access an entity attribute as a python attribute.
+class Entity(OrderedDict):
+ """
+ A dict mapping attribute names to attribute value.
+ Given e = Entity(), attribute 'a' can be accessed as e['a'] or e.a
"""
-
- def __init__(self, entity_type=None, attributes=None, schema=None,
**kw_attributes):
- """
- @param entity_type: An L{EntityType} or the name of an entity type in
the schema.
- @param attributes: An attribute mapping.
- @param schema: The L{Schema} defining entity_type.
- @param kw_attributes: Attributes as keyword arguments.
- """
- super(Entity, self).__init__()
- if schema and entity_type in schema.entity_types:
- self.entity_type = schema.entity_types[entity_type]
- else:
- assert entity_type is None or \
- isinstance(entity_type, EntityType), "'%s' is not an entity
type"%entity_type
- self.entity_type = entity_type
- self.attributes = attributes or {}
- self.attributes.update(kw_attributes)
-
- def validate(self, **kwargs):
- """
- Calls self.entity_type.validate(self). See L{Schema.validate}
- """
- self.entity_type.validate(self.attributes, **kwargs)
def __getattr__(self, name):
- if not name in self.attributes:
+ if not name in self:
raise AttributeError("'%s' object has no attribute
'%s'"%(self.__class__.__name__, name))
- return self.attributes[name]
-
- def dump(self, as_map=False):
- """
- Dump as a json-friendly tuple or map.
- @keyword as_map:
- If true dump as a map: { "entity_type":"<type>",
"attributes":{"<name>":"<value>", ...}}
- Otherwise dump as a tuple: ("<type>", {"<name>":"<value", ...})
- """
- if as_map:
- return {'entity_type':self.entity_type.name,
'attributes':self.attributes}
- else:
- return (self.entity_type.name, self.attributes)
-
- def __str__(self):
- return str(self.dump)
+ return self[name]
class EntityList(list):
"""
A list of entities with some convenience methods for finding entities
by type or attribute value.
-
- @ivar schema: The ${schema.Schema}
- @ivar <singleton-entity>: Python attribute shortcut to
- self.get(entity_type=<singleton-entity>, single=True)
"""
- def __init__(self, schema, contents=None):
- """
- @param schema: The L{Schema} for this entity list.
- @param contents: A list of L{Entity} or tuple (entity-type-name, {
attributes...})
- """
- self.schema = schema
- super(EntityList, self).__init__()
- self.replace(contents or [])
-
- def entity(self, entity):
- """
- Make an L{Entity}. If entity is already an L{Entity} return it
unchanged.
- Otherwise entity should be a tuple (entity-type-name, { attributes...})
- @param entity: An L{Entity} or a tuple
- """
- if isinstance(entity, Entity):
- return entity
- else:
- return Entity(entity[0], entity[1], self.schema)
-
- def validate(self):
- """
- Calls self.schema.validate(self). See L{Schema.validate}.
- """
- self.schema.validate(self)
-
- def get(self, single=False, entity_type=None, **kwargs):
+ def get(self, **kwargs):
"""
Get a list of entities matching the criteria defined by keyword
arguments.
- @keyword single: If True return a single value. Raise an exception if
the result is not a single value.
- @keyword entity_type: An entity type name, return instances of that
type.
- @param kwargs: Set of attribute-name:value keywords. Return instances
of entities where all the attributes match.
- @return: a list of entities or a single entity if single=True.
+ @param kwargs: Set of attribute-name:value keywords.
+ Return instances of entities where all the attributes match.
+ @return: a list of entities.
"""
- result = self
def match(e):
"""True if e matches the criteria"""
- if entity_type and e.entity_type.name != entity_type:
- return False
for name, value in kwargs.iteritems():
- if name not in e.attributes or e.attributes[name] != value:
+ if name not in e or e[name] != value:
return False
return True
- result = [e for e in self if match(e)]
- if single:
- if len(result) != 1:
- criteria = copy(kwargs)
- if entity_type: criteria['entity_type'] = entity_type
- raise ValueError("Expecting single value for %s, got
%s"%(criteria, result))
- return result[0]
- return result
+ return [e for e in self if match(e)]
- def __getattr__(self, name):
- if name in self.schema.entity_types:
- return self.get(entity_type=name,
single=self.schema.entity_types[name].singleton)
- raise AttributeError("'%s' object has no attribute
'%s'"%(self.__class__.__name__, name))
-
- def dump(self, as_map=False):
- """
- Dump as a json-friendly list of entities. See L{Entity.dump}
- @keyword as_map: If true dump entities as maps, else as tuples.
- """
- return [e.dump(as_map) for e in self]
+ def validate(self, schema):
+ """Validate against a schema"""
+ schema.validate(self)
- def __str__(self):
- return str(self.dump())
+ def __getattr__(self, name):
+ return self.get(type=name)
- def replace(self, contents):
- """
- Replace the contents of the list.
- @param contents: A list of L{Entity} or tuple (entity-type-name, {
attributes...})
- """
- self[:] = [self.entity(c) for c in contents]
+__all__ = [ Entity, EntityList ]
Copied: qpid/dispatch/trunk/python/qpid_dispatch_internal/management/node.py
(from r1602494,
qpid/dispatch/trunk/python/qpid_dispatch_internal/management/amqp.py)
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/python/qpid_dispatch_internal/management/node.py?p2=qpid/dispatch/trunk/python/qpid_dispatch_internal/management/node.py&p1=qpid/dispatch/trunk/python/qpid_dispatch_internal/management/amqp.py&r1=1602494&r2=1602495&rev=1602495&view=diff
==============================================================================
--- qpid/dispatch/trunk/python/qpid_dispatch_internal/management/amqp.py
(original)
+++ qpid/dispatch/trunk/python/qpid_dispatch_internal/management/node.py Fri
Jun 13 19:08:23 2014
@@ -23,9 +23,7 @@ AMQP management tools for Qpid dispatch.
import proton, re, threading, httplib
from collections import namedtuple
-from entity import Entity
-
-class Error(Exception): pass
+from entity import Entity, EntityList
class ManagementError(Exception):
"""An AMQP management error. str() gives a string with status code and
text.
@@ -235,9 +233,9 @@ class Node(object):
self.check_response(response)
return response
- class QueryResponse(list):
+ class QueryResponse(EntityList):
"""
- Result returned by L{query}. Behaves as a list of L{Entity}.
+ Result returned by L{query}.
@ivar attribute_names: List of attribute names for the results.
"""
def __init__(self, response):
@@ -246,7 +244,7 @@ class Node(object):
"""
self.attribute_names = response.body['attributeNames']
for r in response.body['results']:
- self.append(Entity(attributes=dict(zip(self.attribute_names,
r))))
+ self.append(Entity(zip(self.attribute_names, r)))
def query(self, entity_type=None, attribute_names=None, offset=None,
count=None):
"""
@@ -256,7 +254,7 @@ class Node(object):
@keyword attribute_names: A list of attribute names to query.
@keyword offset: An integer offset into the list of results to return.
@keyword count: A count of the maximum number of results to return.
- @return: A L{QueryResponse}
+ @return: An L{EntityList}
"""
attribute_names = attribute_names or []
response = self.call(self.node_request(
Modified:
qpid/dispatch/trunk/python/qpid_dispatch_internal/management/qdrouter.json
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/python/qpid_dispatch_internal/management/qdrouter.json?rev=1602495&r1=1602494&r2=1602495&view=diff
==============================================================================
--- qpid/dispatch/trunk/python/qpid_dispatch_internal/management/qdrouter.json
(original)
+++ qpid/dispatch/trunk/python/qpid_dispatch_internal/management/qdrouter.json
Fri Jun 13 19:08:23 2014
@@ -2,7 +2,7 @@
"prefix": "org.apache.qpid.dispatch",
"includes": {
"entity-id": {
- "description":"Name and identity attributes common to all entity types",
+ "description":"Name and identity attributes are common to all entity
types",
"attributes": {
"name": {
"type": "String",
@@ -203,7 +203,8 @@
"agent",
"container",
"config",
- "default"
+ "default",
+ "error"
],
"description": "Module to configure logging level. The special module
'default' specifies logging for modules that don't have explicit log sections."
},
Modified:
qpid/dispatch/trunk/python/qpid_dispatch_internal/management/qdrouter.py
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/python/qpid_dispatch_internal/management/qdrouter.py?rev=1602495&r1=1602494&r2=1602495&view=diff
==============================================================================
--- qpid/dispatch/trunk/python/qpid_dispatch_internal/management/qdrouter.py
(original)
+++ qpid/dispatch/trunk/python/qpid_dispatch_internal/management/qdrouter.py
Fri Jun 13 19:08:23 2014
@@ -21,11 +21,12 @@
Qpid Dispatch Router management schema and config file parsing.
"""
-import schema, json, re
-from entity import EntityList
+import json, re
+import schema
+from entity import EntityList, Entity
from copy import copy
-class Schema(schema.Schema):
+class QdSchema(schema.Schema):
"""
Qpid Dispatch Router management schema.
"""
@@ -34,7 +35,7 @@ class Schema(schema.Schema):
def __init__(self):
"""Load schema."""
with open(self.SCHEMA_FILE) as f:
- schema.Schema.__init__(self, **json.load(f))
+ super(QdSchema, self).__init__(**json.load(f))
def validate(self, entities, **kwargs):
"""
@@ -46,18 +47,18 @@ class Schema(schema.Schema):
@param entities: An L{EntityList}
@param kwargs: See L{schema.Schema.validate}
"""
- schema.Schema.validate(self, entities, **kwargs)
+ super(QdSchema, self).validate(entities, **kwargs)
- if entities.router.mode != 'interior':
+ if entities.router[0].mode != 'interior':
for connect in entities.get(entity_type='listeners') +
entities.get(entity_type='connector'):
if connect['role'] != 'normal':
raise schema.SchemaError("Role '%s' for entity '%s' only
permitted with 'interior' mode % (entity['role'], connect.name)")
-class Configuration(EntityList):
- """An L{EntityList} loaded from a qdrouterd.conf and validated against
L{Schema}."""
+class QdConfig(EntityList):
+ """An L{EntityList} loaded from a qdrouterd.conf and validated against
L{QdSchema}."""
- def __init__(self, schema=Schema()):
- super(Configuration, self).__init__(schema)
+ def __init__(self, schema=QdSchema()):
+ self.schema = schema
@staticmethod
def _parse(lines):
@@ -82,6 +83,7 @@ class Configuration(EntityList):
"""
Find include sections (defined by schema) in the content,
expand references and remove the include sections.
+ @param content: ((section-name:{name:value...}))
"""
def _expand_section(section, includes):
"""Expand one section"""
@@ -126,5 +128,6 @@ class Configuration(EntityList):
Load a configuration file.
@param lines: A list of lines, or an open file object.
"""
- self.replace(self._default_ids(self._expand(self._parse(lines))))
- self.validate()
+ sections = self._default_ids(self._expand(self._parse(lines)))
+ self[:] = [Entity(type=s[0], **s[1]) for s in sections]
+ self.validate(self.schema)
Modified: qpid/dispatch/trunk/python/qpid_dispatch_internal/management/schema.py
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/python/qpid_dispatch_internal/management/schema.py?rev=1602495&r1=1602494&r2=1602495&view=diff
==============================================================================
--- qpid/dispatch/trunk/python/qpid_dispatch_internal/management/schema.py
(original)
+++ qpid/dispatch/trunk/python/qpid_dispatch_internal/management/schema.py Fri
Jun 13 19:08:23 2014
@@ -27,19 +27,13 @@ A Schema can be loaded/dumped to a json
"""
import os
-try:
- from collections import OrderedDict
-except:
- from qpid_dispatch_internal.ordereddict import OrderedDict # For python <=
2.6
-
-class SchemaError(Exception):
- """Class for schema errors"""
- pass
+from entity import OrderedDict
def schema_file(name):
"""Return a file name relative to the directory from which this module was
loaded."""
return os.path.join(os.path.dirname(__file__), name)
+
class Type(object):
"""Base class for schema types.
@@ -151,7 +145,7 @@ def get_type(rep):
return EnumType(rep)
if rep in BUILTIN_TYPES:
return BUILTIN_TYPES[rep]
- raise SchemaError("No such schema type: %s"%rep)
+ raise TypeError("No such schema type: %s"%rep)
def _dump_dict(items):
"""
@@ -225,12 +219,12 @@ class AttributeType(object):
value = self.default
if value is None:
if self.required and check_required:
- raise SchemaError("Missing value for attribute '%s'"%self.name)
+ raise ValueError("Missing value for attribute '%s'"%self.name)
else:
return None
else:
if self.unique and not _is_unique(check_unique, self.name, value):
- raise SchemaError("Multiple instances of unique attribute
'%s'"%self.name)
+ raise ValueError("Multiple instances of unique attribute
'%s'"%self.name)
return self.atype.validate(value, **kwargs)
def dump(self):
@@ -254,6 +248,7 @@ class AttributeTypeHolder(object):
def __init__(self, name, schema, attributes=None, description=""):
self.name, self.schema, self.description = name, schema, description
self.attributes = OrderedDict()
+ self.attributes['type'] = AttributeType('type', type='String',
default=name, required=True)
if attributes:
self.add_attributes(attributes)
@@ -264,13 +259,14 @@ class AttributeTypeHolder(object):
"""
for k, v in attributes.iteritems():
if k in self.attributes:
- raise SchemaError("Attribute '%s' duplicated in '%s'"%(k,
self.name))
+ raise TypeError("Duplicate attribute in '%s':
'%s'"%(self.name, k))
self.attributes[k] = AttributeType(k, **v)
def dump(self):
"""Json friendly representation"""
return _dump_dict([
- ('attributes', OrderedDict((k, v.dump()) for k, v in
self.attributes.iteritems())),
+ ('attributes', OrderedDict((k, v.dump()) for k, v in
self.attributes.iteritems()
+ if k != 'type')), # Don't dump special
'type' attribute
('description', self.description or None)
])
@@ -326,7 +322,7 @@ class EntityType(AttributeTypeHolder):
@param kwargs: See L{Schema.validate}
"""
if self.singleton and not _is_unique(check_singleton, self.name, True):
- raise SchemaError("Found multiple instances of singleton entity
type '%s'"%self.name)
+ raise ValueError("Found multiple instances of singleton entity
type '%s'"%self.name)
# Validate
for name, value in attributes.iteritems():
attributes[name] = self.attributes[name].validate(value, **kwargs)
@@ -399,16 +395,15 @@ class Schema(object):
@keyword add_default: Add defaults for missing attributes.
@keyword check_unique: Raise exception if unique attributes are
duplicated.
@keyword check_singleton: Raise exception if singleton entities are
duplicated.
-
"""
if check_singleton: check_singleton = {}
if check_unique: check_unique = {}
for e in entities:
- assert e.entity_type.schema is self, "Entity '%s' from wrong
schema"%e
- e.validate(
- enum_as_int=enum_as_int,
- check_required=check_required,
- add_default=add_default,
- check_unique=check_unique,
- check_singleton=check_singleton)
+ et = self.entity_types[e.type]
+ et.validate(e,
+ enum_as_int=enum_as_int,
+ check_required=check_required,
+ add_default=add_default,
+ check_unique=check_unique,
+ check_singleton=check_singleton)
return entities
Modified: qpid/dispatch/trunk/tests/management/__init__.py
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/management/__init__.py?rev=1602495&r1=1602494&r2=1602495&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/management/__init__.py (original)
+++ qpid/dispatch/trunk/tests/management/__init__.py Fri Jun 13 19:08:23 2014
@@ -20,4 +20,5 @@
#pylint: disable=wildcard-import,missing-docstring
from entity import *
from schema import *
+from node import *
from qdrouter import *
Modified: qpid/dispatch/trunk/tests/management/entity.py
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/management/entity.py?rev=1602495&r1=1602494&r2=1602495&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/management/entity.py (original)
+++ qpid/dispatch/trunk/tests/management/entity.py Fri Jun 13 19:08:23 2014
@@ -20,41 +20,29 @@
#pylint: disable=wildcard-import,missing-docstring,too-many-public-methods
import unittest
-from qpid_dispatch_internal.management.schema import Schema
-from qpid_dispatch_internal.management.entity import Entity, EntityList
-from schema import SCHEMA_1
+from qpid_dispatch_internal.management import Entity, EntityList
class EntityTest(unittest.TestCase):
def test_entity(self):
- s = Schema(**SCHEMA_1)
- e = Entity('container', name='x', schema=s)
+ e = Entity(type='container', name='x')
self.assertEqual(e.name, 'x')
- self.assertEqual(e.attributes, {'name':'x'})
- e.validate()
- attrs = {'name':'x', 'worker-threads':1}
- self.assertEqual(e.attributes, attrs)
- self.assertEqual(e.dump(as_map=True), {'entity_type':'container',
'attributes':attrs})
- self.assertEqual(e.dump(), ('container', attrs))
+ self.assertEqual(e, {'type': 'container', 'name':'x'})
def test_entity_list(self):
- s = Schema(**SCHEMA_1)
- contents = [('container', {'name':'x'}),
- ('listener', {'name':'y', 'addr':'1'}),
- ('listener', {'name':'z', 'addr':'2'}),
- ('listener', {'name':'q', 'addr':'2'}),
- ('connector', {'name':'c1', 'addr':'1'})]
- l = EntityList(s, contents)
-
- self.assertEqual(l.dump(), contents)
- self.assertEqual([e.name for e in l.get(entity_type='listener')],
['y', 'z', 'q'])
- self.assertEqual([e.name for e in l.get(entity_type='listener',
addr='1')], ['y'])
+ contents = [
+ Entity(type='container', name='x'),
+ Entity(type='listener', name='y', addr='1'),
+ Entity(type='listener', name='z', addr='2'),
+ Entity(type='connector', name='c1', addr='1')]
+ l = EntityList(contents)
+
+ self.assertEqual(l, contents)
+ self.assertEqual([e.name for e in l.get(type='listener')], ['y', 'z'])
+ self.assertEqual([e.name for e in l.get(type='listener', addr='1')],
['y'])
self.assertEqual([e.name for e in l.get(addr='1')], ['y', 'c1'])
- self.assertEqual(l.get(name='x', single=True).name, 'x')
-
- self.assertRaises(ValueError, l.get, entity_type='listener',
single=True)
- self.assertRaises(ValueError, l.get, name='nosuch', single=True)
+ self.assertEqual(l.get(name='x')[0].name, 'x')
if __name__ == '__main__':
unittest.main()
Copied: qpid/dispatch/trunk/tests/management/node.py (from r1602494,
qpid/dispatch/trunk/tests/management/amqp.py)
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/management/node.py?p2=qpid/dispatch/trunk/tests/management/node.py&p1=qpid/dispatch/trunk/tests/management/amqp.py&r1=1602494&r2=1602495&rev=1602495&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/management/amqp.py (original)
+++ qpid/dispatch/trunk/tests/management/node.py Fri Jun 13 19:08:23 2014
@@ -25,10 +25,10 @@ from qpid_dispatch_internal.management.a
class UrlTest(unittest.TestCase):
def test_url(self):
- url = Url(scheme='amqp', user='me', password='secret', host='myhost',
port=1234, name='foobar')
+ url = Url(scheme='amqp', user='me', password='secret', host='myhost',
port=1234, path='foobar')
self.assertEqual(str(url), "amqp://me:secret@myhost:1234/foobar")
self.assertEqual(
- [url.scheme, url.user, url.password, url.host, url.port, url.name],
+ [url.scheme, url.user, url.password, url.host, url.port, url.path],
['amqp', 'me', 'secret', 'myhost', 1234, 'foobar']
)
@@ -42,10 +42,10 @@ class UrlTest(unittest.TestCase):
self.assertNotEqual(str(url), "amqp://me:secret@myhost:5555/foobar")
# Check that we allow None for scheme, port
- url = Url(user='me', password='secret', host='myhost', name='foobar')
+ url = Url(user='me', password='secret', host='myhost', path='foobar')
self.assertEqual(str(url), "me:secret@myhost/foobar")
self.assertEqual(
- [url.scheme, url.user, url.password, url.host, url.port, url.name],
+ [url.scheme, url.user, url.password, url.host, url.port, url.path],
[None, 'me', 'secret', 'myhost', None, 'foobar']
)
@@ -58,6 +58,6 @@ class UrlTest(unittest.TestCase):
self.assertEqual(str(Url("amqp://me:secret@myhost/foobar").defaults()),
"amqp://me:secret@myhost:5672/foobar")
- # Empty string for name
- self.assertEqual(Url("myhost/").name, "")
- self.assertIsNone(Url("myhost").name)
+ # Empty string for path
+ self.assertEqual(Url("myhost/").path, "")
+ self.assertIsNone(Url("myhost").path)
Modified: qpid/dispatch/trunk/tests/management/qdrouter.py
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/management/qdrouter.py?rev=1602495&r1=1602494&r2=1602495&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/management/qdrouter.py (original)
+++ qpid/dispatch/trunk/tests/management/qdrouter.py Fri Jun 13 19:08:23 2014
@@ -20,13 +20,13 @@
#pylint:
disable=wildcard-import,unused-wildcard-import,missing-docstring,too-many-public-methods
import unittest
-from qpid_dispatch_internal.management.qdrouter import *
+from qpid_dispatch_internal.management import QdSchema, QdConfig
class QdrouterTest(unittest.TestCase):
"""Tests for qpid_dispatch_internal.config.qdrouter"""
def test_qdrouter_parse(self):
- conf = Configuration()
+ conf = QdConfig()
conf_text = """
# Line comment
router {
@@ -80,8 +80,8 @@ listener {
])
conf.load(conf_text.split("\n"))
- self.assertEqual(conf.router.name, 'router0')
- self.assertEqual(conf.router.identity, 'router0')
+ self.assertEqual(conf.router[0].name, 'router0')
+ self.assertEqual(conf.router[0].identity, 'router0')
self.assertEqual(len(conf.listener), 3)
self.assertEqual(conf.listener[0].name, 'l0')
self.assertEqual(conf.listener[2].name, 'listener2')
Modified: qpid/dispatch/trunk/tests/management/schema.py
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/management/schema.py?rev=1602495&r1=1602494&r2=1602495&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/management/schema.py (original)
+++ qpid/dispatch/trunk/tests/management/schema.py Fri Jun 13 19:08:23 2014
@@ -21,8 +21,7 @@
#pylint: disable=wildcard-import,missing-docstring,too-many-public-methods
import unittest, json
-from qpid_dispatch_internal.management.schema import Schema, EntityType,
BooleanType, EnumType, AttributeType, SchemaError, schema_file
-from qpid_dispatch_internal.management.entity import Entity
+from qpid_dispatch_internal.management import Schema, Entity, EntityType,
BooleanType, EnumType, AttributeType, schema_file
import collections
def replace_od(thing):
@@ -37,7 +36,7 @@ SCHEMA_1 = {
"includes": {
"entity-id": {
"attributes": {
- "name": {"type":"String", "required": True, "unique":True}
+ "name": {"type":"String", "required": True, "unique":True},
}
}
},
@@ -90,7 +89,7 @@ class SchemaTest(unittest.TestCase):
a = AttributeType('foo', 'String', 'FOO', True)
self.assertEqual('FOO', a.validate(None))
a = AttributeType('foo', 'Integer', None, True)
- self.assertRaises(SchemaError, a.validate, None) # Missing default
+ self.assertRaises(ValueError, a.validate, None) # Missing default
def test_entity_type(self):
s = Schema(includes={
@@ -101,11 +100,11 @@ class SchemaTest(unittest.TestCase):
'foo': {'type':'String', 'default':'FOO'},
'req': {'type':'Integer', 'required':True},
'e': {'type':['x', 'y']}})
- self.assertRaises(SchemaError, e.validate, {}) # Missing required 'req'
- self.assertEqual(e.validate({'req':42, 'e':None}), {'foo': 'FOO',
'req': 42})
+ self.assertRaises(ValueError, e.validate, {}) # Missing required 'req'
+ self.assertEqual(e.validate({'req':42, 'e':None}), {'foo': 'FOO',
'req': 42, 'type': 'MyEntity'})
# Try with an include
e = EntityType('e2', s, attributes={'x':{'type':'Integer'}},
include=['i1', 'i2'])
- self.assertEqual(e.validate({'x':1}), {'x':1, 'foo1': 'FOO1', 'foo2':
'FOO2'})
+ self.assertEqual(e.validate({'x':1}), {'x':1, 'foo1': 'FOO1', 'foo2':
'FOO2', 'type': 'i2'})
qdrouter_json = schema_file('qdrouter.json')
@@ -158,7 +157,7 @@ class SchemaTest(unittest.TestCase):
def jsontof(j,fname):
with open(fname,'w') as f:
json.dump(j, f, indent=4)
- self.assertDictEqual(replace_od(s.dump()), expect)
+ self.assertDictEqual(expect, replace_od(s.dump()))
s2 = Schema(**s.dump())
self.assertEqual(s.dump(), s2.dump())
@@ -166,16 +165,16 @@ class SchemaTest(unittest.TestCase):
def test_schema_validate(self):
s = Schema(**SCHEMA_1)
# Duplicate unique attribute 'name'
- m = [Entity('listener', {'name':'x'}, s),
- Entity('listener', {'name':'x'}, s)]
- self.assertRaises(SchemaError, s.validate, m)
+ m = [Entity({'type': 'listener', 'name':'x'}),
+ Entity({'type': 'listener', 'name':'x'})]
+ self.assertRaises(ValueError, s.validate, m)
# Duplicate singleton entity 'container'
- m = [Entity('container', {'name':'x'}, s),
- Entity('container', {'name':'y'}, s)]
- self.assertRaises(SchemaError, s.validate, m)
+ m = [Entity({'type': 'container', 'name':'x'}),
+ Entity({'type': 'container', 'name':'y'})]
+ self.assertRaises(ValueError, s.validate, m)
# Valid model
- m = [Entity('container', {'name':'x'}, s),
- Entity('listener', {'name':'y'}, s)]
+ m = [Entity({'type': 'container', 'name':'x'}),
+ Entity({'type': 'listener', 'name':'y'})]
s.validate(m)
if __name__ == '__main__':
Modified: qpid/dispatch/trunk/tests/system_test.py
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/system_test.py?rev=1602495&r1=1602494&r2=1602495&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/system_test.py (original)
+++ qpid/dispatch/trunk/tests/system_test.py Fri Jun 13 19:08:23 2014
@@ -56,7 +56,7 @@ import os, time, socket, random, subproc
from copy import copy
import proton
from proton import Message
-from qpid_dispatch_internal.management import amqp
+from qpid_dispatch_internal.management import Node
# Optional modules
MISSING_MODULES = []
@@ -314,7 +314,7 @@ class Qdrouterd(Process):
def agent(self):
"""Return an management Agent for this router"""
if not self._agent:
- self._agent = amqp.Node(self.addresses[0])
+ self._agent = Node(self.addresses[0])
return self._agent
def teardown(self):
Modified: qpid/dispatch/trunk/tests/system_tests_broker.py
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/system_tests_broker.py?rev=1602495&r1=1602494&r2=1602495&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/system_tests_broker.py (original)
+++ qpid/dispatch/trunk/tests/system_tests_broker.py Fri Jun 13 19:08:23 2014
@@ -22,7 +22,7 @@ System tests involving one or more broke
with waypoints.
"""
import unittest, system_test
-from system_test import wait_port, Qdrouterd, message, MISSING_REQUIREMENTS
+from system_test import Qdrouterd, message, MISSING_REQUIREMENTS
from itertools import cycle
class DistributedQueueTest(system_test.TestCase): # pylint:
disable=too-many-public-methods
Modified: qpid/dispatch/trunk/tests/system_tests_management.py
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/system_tests_management.py?rev=1602495&r1=1602494&r2=1602495&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/system_tests_management.py (original)
+++ qpid/dispatch/trunk/tests/system_tests_management.py Fri Jun 13 19:08:23
2014
@@ -20,7 +20,7 @@
"""System tests for management of qdrouter"""
import unittest, system_test, re
-from qpid_dispatch_internal.management import amqp
+from qpid_dispatch_internal.management import Node, ManagementError
from system_test import Qdrouterd, MISSING_REQUIREMENTS
from httplib import BAD_REQUEST, NOT_IMPLEMENTED
@@ -40,7 +40,7 @@ class ManagementTest(system_test.TestCas
def setUp(self):
super(ManagementTest, self).setUp()
- self.node = self.cleanup(amqp.Node(self.router.addresses[0]))
+ self.node = self.cleanup(Node(self.router.addresses[0]))
def assertRaisesManagement(self, status, pattern, call, *args, **kwargs):
"""Assert that call(*args, **kwargs) raises a ManagementError
@@ -48,7 +48,7 @@ class ManagementTest(system_test.TestCas
try:
call(*args, **kwargs)
self.fail("Expected ManagementError with %s, %s"%(status, pattern))
- except amqp.ManagementError, e:
+ except ManagementError, e:
self.assertEqual(e.status, status)
assert re.search("(?i)"+pattern, e.description), "No match for %s
in %s"%(pattern, e.description)
Modified: qpid/dispatch/trunk/tools/qdstat
URL:
http://svn.apache.org/viewvc/qpid/dispatch/trunk/tools/qdstat?rev=1602495&r1=1602494&r2=1602495&view=diff
==============================================================================
--- qpid/dispatch/trunk/tools/qdstat (original)
+++ qpid/dispatch/trunk/tools/qdstat Fri Jun 13 19:08:23 2014
@@ -26,8 +26,7 @@ import locale
import socket
import re
from proton import Messenger, Message, Timeout
-from qpid_dispatch_internal.management.amqp import Url, Node
-from qpid_dispatch_internal.management.entity import Entity
+from qpid_dispatch_internal.management import Url, Node, Entity
home = os.environ.get("QPID_DISPATCH_HOME",
os.path.normpath(os.path.dirname(__file__)))
sys.path.append(os.path.join(home, "python"))
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]