File size: 44,154 Bytes
5980447
1
2
{"repo": "rackerlabs/mimic", "pull_number": 538, "instance_id": "rackerlabs__mimic-538", "issue_numbers": "", "base_commit": "d3ae1a11db45e4c695f012e10762aaa0ec81941d", "patch": "diff --git a/mimic/model/clb_objects.py b/mimic/model/clb_objects.py\n--- a/mimic/model/clb_objects.py\n+++ b/mimic/model/clb_objects.py\n@@ -12,8 +12,6 @@\n \n import attr\n \n-from characteristic import attributes, Attribute\n-\n from six import text_type\n \n from toolz.dicttoolz import dissoc\n@@ -157,20 +155,40 @@ def full_json(self):\n         return result\n \n \n-@attributes([\"keys\"])\n+@attr.s\n class BadKeysError(Exception):\n     \"\"\"\n     When trying to alter the settings of a load balancer, this exception will\n     be raised if you attempt to alter an attribute which doesn't exist.\n     \"\"\"\n+    keys = attr.ib()\n+    code = attr.ib(validator=attr.validators.instance_of(int), default=400)\n+\n+    def to_json(self):\n+        \"\"\"\n+        :return: a JSON dict representation of this error.\n+        \"\"\"\n+        return {'message': 'Attempt to alter a bad attribute',\n+                'code': self.code}\n \n \n-@attributes([\"value\", \"accepted_values\"])\n+@attr.s\n class BadValueError(Exception):\n     \"\"\"\n     When trying to alter the settings of a load balancer, this exception will\n     be raised if you attempt to set a valid attribute to an invalid setting.\n     \"\"\"\n+    value = attr.ib()\n+    accepted_values = attr.ib()\n+    code = attr.ib(validator=attr.validators.instance_of(int), default=400)\n+\n+    def to_json(self):\n+        \"\"\"\n+        :return: a JSON dict representation of this error.\n+        \"\"\"\n+        return {'message': ('Unsupported status {0} not one of {1}'.format(\n+                            self.value, self.accepted_values)),\n+                'code': self.code}\n \n \n def node_feed_xml(events):\n@@ -296,7 +314,7 @@ def set_attributes(self, lb_id, kvpairs):\n             if k not in supported_keys:\n                 badKeys.append(k)\n         if len(badKeys) > 0:\n-            raise BadKeysError(\"Attempt to alter a bad attribute\", keys=badKeys)\n+            raise BadKeysError(keys=badKeys)\n \n         if \"status\" in kvpairs:\n             supported_statuses = [\n@@ -305,9 +323,6 @@ def set_attributes(self, lb_id, kvpairs):\n             s = kvpairs[\"status\"]\n             if s not in supported_statuses:\n                 raise BadValueError(\n-                    \"Unsupported status {0} not one of {1}\".format(\n-                        s, supported_statuses\n-                    ),\n                     value=s, accepted_values=supported_statuses\n                 )\n \n@@ -624,8 +639,7 @@ def del_load_balancer(self, lb_id):\n         return not_found_response(\"loadbalancer\"), 404\n \n \n-@attributes([\"clock\",\n-             Attribute(\"regional_collections\", default_factory=dict)])\n+@attr.s\n class GlobalCLBCollections(object):\n     \"\"\"\n     A :obj:`GlobalCLBCollections` is a set of all the\n@@ -633,6 +647,8 @@ class GlobalCLBCollections(object):\n     words, all the objects that a single tenant owns globally in a\n     cloud load balancer service.\n     \"\"\"\n+    clock = attr.ib()\n+    regional_collections = attr.ib(default=attr.Factory(dict))\n \n     def collection_for_region(self, region_name):\n         \"\"\"\ndiff --git a/mimic/model/customer_objects.py b/mimic/model/customer_objects.py\n--- a/mimic/model/customer_objects.py\n+++ b/mimic/model/customer_objects.py\n@@ -4,16 +4,19 @@\n \n from __future__ import absolute_import, division, unicode_literals\n \n-from characteristic import attributes, Attribute\n+import attr\n \n \n-@attributes([\"tenant_id\", \"email_address\", \"role\",\n-             Attribute(\"first_name\", default_value=\"Test FirstName\"),\n-             Attribute(\"last_name\", default_value=\"Test LastName\")])\n+@attr.s\n class Contact(object):\n     \"\"\"\n     A :obj:`Contact` is a representation for each contact for a tenant.\n     \"\"\"\n+    tenant_id = attr.ib()\n+    email_address = attr.ib()\n+    role = attr.ib()\n+    first_name = attr.ib(default=\"Test FirstName\")\n+    last_name = attr.ib(default=\"Test LastName\")\n \n     static_defaults = {\n         \"firstName\": \"Pat\",\n@@ -72,11 +75,12 @@ def generate_contacts(self):\n         return template\n \n \n-@attributes([Attribute(\"contacts_store\", default_factory=dict)])\n+@attr.s\n class ContactsStore(object):\n     \"\"\"\n     A collection of contact objects for a tenant.\n     \"\"\"\n+    contacts_store = attr.ib(default=attr.Factory(dict))\n \n     def add_to_contacts_store(self, tenant_id, contact_list):\n         \"\"\"\ndiff --git a/mimic/model/flavor_collections.py b/mimic/model/flavor_collections.py\n--- a/mimic/model/flavor_collections.py\n+++ b/mimic/model/flavor_collections.py\n@@ -6,7 +6,7 @@\n \n from six import iteritems\n \n-from characteristic import attributes, Attribute\n+import attr\n from json import dumps\n from mimic.model.flavors import (\n     RackspaceStandardFlavor, RackspaceComputeFlavor, RackspaceMemoryFlavor,\n@@ -16,14 +16,16 @@\n from mimic.model.nova_objects import not_found\n \n \n-@attributes(\n-    [\"tenant_id\", \"region_name\", \"clock\",\n-     Attribute(\"flavors_store\", default_factory=list)]\n-)\n+@attr.s\n class RegionalFlavorCollection(object):\n     \"\"\"\n     A collection of flavors, in a given region, for a given tenant.\n     \"\"\"\n+    tenant_id = attr.ib()\n+    region_name = attr.ib()\n+    clock = attr.ib()\n+    flavors_store = attr.ib(default=attr.Factory(list))\n+\n     def flavor_by_id(self, flavor_id):\n         \"\"\"\n         Retrieve a :obj:`Flavor` object by its ID.\n@@ -87,14 +89,16 @@ def get_flavor(self, http_get_request, flavor_id, absolutize_url):\n         return dumps({\"flavor\": flavor.detailed_json(absolutize_url)})\n \n \n-@attributes([\"tenant_id\", \"clock\",\n-             Attribute(\"regional_collections\", default_factory=dict)])\n+@attr.s\n class GlobalFlavorCollection(object):\n     \"\"\"\n     A :obj:`GlobalFlavorCollection` is a set of all the\n     :obj:`RegionalFlavorCollection` objects owned by a given tenant.  In other\n     words, all the flavor objects that a single tenant owns globally.\n     \"\"\"\n+    tenant_id = attr.ib()\n+    clock = attr.ib()\n+    regional_collections = attr.ib(default=attr.Factory(dict))\n \n     def collection_for_region(self, region_name):\n         \"\"\"\ndiff --git a/mimic/model/flavors.py b/mimic/model/flavors.py\n--- a/mimic/model/flavors.py\n+++ b/mimic/model/flavors.py\n@@ -4,14 +4,21 @@\n \n from __future__ import absolute_import, division, unicode_literals\n \n-from characteristic import attributes\n+import attr\n \n \n-@attributes(['flavor_id', 'tenant_id', 'name', 'ram', 'vcpus', 'rxtx', 'disk'])\n+@attr.s\n class Flavor(object):\n     \"\"\"\n     A Flavor object\n     \"\"\"\n+    flavor_id = attr.ib()\n+    tenant_id = attr.ib()\n+    name = attr.ib()\n+    ram = attr.ib()\n+    vcpus = attr.ib()\n+    rxtx = attr.ib()\n+    disk = attr.ib()\n \n     static_defaults = {\n         \"swap\": \"\",\ndiff --git a/mimic/model/heat_objects.py b/mimic/model/heat_objects.py\n--- a/mimic/model/heat_objects.py\n+++ b/mimic/model/heat_objects.py\n@@ -2,23 +2,24 @@\n Model objects for the Heat mimic.\n \"\"\"\n \n-from characteristic import attributes, Attribute\n+import attr\n import json\n from random import randrange\n \n from mimic.model.behaviors import BehaviorRegistryCollection, EventDescription\n \n \n-@attributes(['collection', 'stack_name',\n-             Attribute('stack_id',\n-                       default_factory=lambda: Stack.generate_stack_id()),\n-             Attribute('action', default_factory=lambda: Stack.CREATE),\n-             Attribute('status', default_factory=lambda: Stack.COMPLETE),\n-             Attribute('tags', default_factory=list)])\n+@attr.s\n class Stack(object):\n     \"\"\"\n     A :obj:`Stack` is a representation of a Heat stack.\n     \"\"\"\n+    collection = attr.ib()\n+    stack_name = attr.ib()\n+    stack_id = attr.ib(default=attr.Factory(lambda: Stack.generate_stack_id()))\n+    action = attr.ib(default=attr.Factory(lambda: Stack.CREATE))\n+    status = attr.ib(default=attr.Factory(lambda: Stack.COMPLETE))\n+    tags = attr.ib(default=attr.Factory(list))\n \n     ACTIONS = (\n         CREATE, DELETE, UPDATE, ROLLBACK, SUSPEND, RESUME, ADOPT,\n@@ -199,17 +200,17 @@ def default_delete_behavior(collection, request, stack_name, stack_id):\n     return b''\n \n \n-@attributes(\n-    [\"tenant_id\", \"region_name\",\n-     Attribute(\"stacks\", default_factory=list),\n-     Attribute(\n-         \"behavior_registry_collection\",\n-         default_factory=lambda: BehaviorRegistryCollection())]\n-)\n+@attr.s\n class RegionalStackCollection(object):\n     \"\"\"\n     A collection of :obj:`Stack` objects for a region.\n     \"\"\"\n+    tenant_id = attr.ib()\n+    region_name = attr.ib()\n+    stacks = attr.ib(default=attr.Factory(list))\n+    behavior_registry_collection = attr.ib(default=attr.Factory(\n+        lambda: BehaviorRegistryCollection()))\n+\n     def stack_by_id(self, stack_id):\n         \"\"\"\n         Retrieves a stack by its ID\n@@ -302,12 +303,14 @@ def request_deletion(self, request, stack_name, stack_id):\n                         stack_id=stack_id)\n \n \n-@attributes([\"tenant_id\",\n-             Attribute(\"regional_collections\", default_factory=dict)])\n+@attr.s\n class GlobalStackCollections(object):\n     \"\"\"\n     A set of :obj:`RegionalStackCollection` objects owned by a tenant.\n     \"\"\"\n+    tenant_id = attr.ib()\n+    regional_collections = attr.ib(default=attr.Factory(dict))\n+\n     def collection_for_region(self, region_name):\n         \"\"\"\n         Retrieves a :obj:`RegionalStackCollection` for a region.\ndiff --git a/mimic/model/ironic_objects.py b/mimic/model/ironic_objects.py\n--- a/mimic/model/ironic_objects.py\n+++ b/mimic/model/ironic_objects.py\n@@ -4,7 +4,7 @@\n \n from __future__ import absolute_import, division, unicode_literals\n \n-from characteristic import attributes, Attribute\n+import attr\n from uuid import uuid4\n from json import dumps\n \n@@ -12,26 +12,26 @@\n from mimic.util.helper import random_hex_generator\n \n \n-@attributes([\"node_id\",\n-             Attribute(\"chassis_uuid\", default_value=None),\n-             Attribute(\"driver\", default_value=None),\n-             Attribute(\"driver_info\", default_value=None),\n-             Attribute(\"properties\", default_value=None),\n-             Attribute(\"flavor_id\", default_value=\"onmetal-io1\"),\n-             Attribute(\"power_state\", default_value=\"power on\"),\n-             Attribute(\"provision_state\", default_value=\"available\"),\n-             Attribute(\"instance_uuid\", default_value=None),\n-             Attribute(\"maintenance\", default_value=False),\n-             Attribute(\"cache_image_id\", default_value=None),\n-             Attribute(\"memory_mb\", default_value=None),\n-             Attribute(\"name\", default_value=None)\n-             ])\n+@attr.s\n class Node(object):\n     \"\"\"\n     A :obj:`Node` is a representation of all the state associated with a ironic\n     node.  It can produce JSON-serializable objects for various pieces of\n     state that are required for API responses.\n     \"\"\"\n+    node_id = attr.ib()\n+    chassis_uuid = attr.ib(default=None)\n+    driver = attr.ib(default=None)\n+    driver_info = attr.ib(default=None)\n+    properties = attr.ib(default=None)\n+    flavor_id = attr.ib(default=\"onmetal-io1\")\n+    power_state = attr.ib(default=\"power on\")\n+    provision_state = attr.ib(default=\"available\")\n+    instance_uuid = attr.ib(default=None)\n+    maintenance = attr.ib(default=False)\n+    cache_image_id = attr.ib(default=None)\n+    memory_mb = attr.ib(default=None)\n+    name = attr.ib(default=None)\n \n     static_defaults = {\n         \"target_power_state\": None,\n@@ -178,11 +178,12 @@ def detail_json(self):\n         return template\n \n \n-@attributes([Attribute(\"ironic_node_store\", default_factory=list)])\n+@attr.s\n class IronicNodeStore(object):\n     \"\"\"\n     A collection of ironic :obj:`Node` objects.\n     \"\"\"\n+    ironic_node_store = attr.ib(default=attr.Factory(list))\n \n     memory_to_flavor_map = {131072: \"onmetal-io1\",\n                             32768: \"onmetal-compute1\",\ndiff --git a/mimic/model/keypair_objects.py b/mimic/model/keypair_objects.py\n--- a/mimic/model/keypair_objects.py\n+++ b/mimic/model/keypair_objects.py\n@@ -6,14 +6,17 @@\n \n import json\n \n-from characteristic import attributes, Attribute\n+import attr\n \n \n-@attributes(['name', 'public_key'])\n+@attr.s\n class KeyPair(object):\n     \"\"\"\n     A KeyPair object\n     \"\"\"\n+    name = attr.ib()\n+    public_key = attr.ib()\n+\n     fingerprint = \"aa:aa:aa:aa:aa:aa:aa:aa:aa:aa:aa:aa:aa:aa:aa:aa\"\n     user_id = \"fake\"\n \n@@ -31,15 +34,16 @@ def key_json(self):\n         }\n \n \n-@attributes(\n-    [\"tenant_id\", \"region_name\", \"clock\",\n-     Attribute(\"keypairs\", default_factory=list)]\n-)\n+@attr.s\n class RegionalKeyPairCollection(object):\n     \"\"\"\n     A :obj:`ReionalKeyPairCollection` is a collection of\n     :obj:`KeyPair` objects owned by a given tenant for a region.\n     \"\"\"\n+    tenant_id = attr.ib()\n+    region_name = attr.ib()\n+    clock = attr.ib()\n+    keypairs = attr.ib(default=attr.Factory(list))\n \n     def create_keypair(self, keypair):\n         \"\"\"\n@@ -82,14 +86,16 @@ def remove_keypair(self, name):\n         self.keypairs.remove(kp_to_remove)\n \n \n-@attributes([\"tenant_id\", \"clock\",\n-             Attribute(\"regional_collections\", default_factory=dict)])\n+@attr.s\n class GlobalKeyPairCollections(object):\n     \"\"\"\n     A :obj:`GlobalKeyPairCollections` is a set of all the\n     :obj:`RegionalKeyPairCollection` objects owned by a given tenant.  In other\n     words, all the objects that a single tenant owns globally.\n     \"\"\"\n+    tenant_id = attr.ib()\n+    clock = attr.ib()\n+    regional_collections = attr.ib(default=attr.Factory(dict))\n \n     def collection_for_region(self, region_name):\n         \"\"\"\ndiff --git a/mimic/model/mailgun_objects.py b/mimic/model/mailgun_objects.py\n--- a/mimic/model/mailgun_objects.py\n+++ b/mimic/model/mailgun_objects.py\n@@ -4,18 +4,23 @@\n \n from __future__ import absolute_import, division, unicode_literals\n \n+import attr\n import time\n-from characteristic import attributes, Attribute\n \n \n-@attributes([\"message_id\", \"to\", \"msg_from\", \"subject\", \"body\",\n-             Attribute(\"custom_headers\", default_factory=dict)])\n+@attr.s\n class Message(object):\n     \"\"\"\n     A :obj:`Message` is a representation of an email in Mailgun.\n     It can produce JSON-serializable objects for various pieces of\n     state that are required for API responses.\n     \"\"\"\n+    message_id = attr.ib()\n+    to = attr.ib()\n+    msg_from = attr.ib()\n+    subject = attr.ib()\n+    body = attr.ib()\n+    custom_headers = attr.ib(default=attr.Factory(dict))\n \n     static_defaults = {\n         \"tags\": [],\n@@ -76,11 +81,12 @@ def generate_events(self):\n         return template\n \n \n-@attributes([Attribute(\"message_store\", default_factory=list)])\n+@attr.s\n class MessageStore(object):\n     \"\"\"\n     A collection of message objects.\n     \"\"\"\n+    message_store = attr.ib(default=attr.Factory(list))\n \n     def add_to_message_store(self, **attributes):\n         \"\"\"\ndiff --git a/mimic/model/nova_image_collection.py b/mimic/model/nova_image_collection.py\n--- a/mimic/model/nova_image_collection.py\n+++ b/mimic/model/nova_image_collection.py\n@@ -4,7 +4,7 @@\n \n from __future__ import absolute_import, division, unicode_literals\n \n-from characteristic import attributes, Attribute\n+import attr\n from json import dumps\n from mimic.model.rackspace_images import OnMetalImage\n \n@@ -12,12 +12,16 @@\n from mimic.canned_responses.mimic_presets import get_presets\n \n \n-@attributes(\n-    [\"tenant_id\", \"region_name\", \"clock\", \"image_store\"])\n+@attr.s\n class RegionalNovaImageCollection(object):\n     \"\"\"\n     A collection of nova images, in a given region, for a given tenant.\n     \"\"\"\n+    tenant_id = attr.ib()\n+    region_name = attr.ib()\n+    clock = attr.ib()\n+    image_store = attr.ib()\n+\n     def list_images(self, include_details, absolutize_url):\n         \"\"\"\n         Return a list of images.\n@@ -49,14 +53,16 @@ def get_image(self, http_get_request, image_id, absolutize_url):\n         return dumps({\"image\": image.detailed_json(absolutize_url)})\n \n \n-@attributes([\"tenant_id\", \"clock\",\n-             Attribute(\"regional_collections\", default_factory=dict)])\n+@attr.s\n class GlobalNovaImageCollection(object):\n     \"\"\"\n     A :obj:`GlobalNovaImageCollection` is a set of all the\n     :obj:`RegionalNovaImageCollection` objects owned by a given tenant.  In other\n     words, all the image objects that a single tenant owns globally.\n     \"\"\"\n+    tenant_id = attr.ib()\n+    clock = attr.ib()\n+    regional_collections = attr.ib(default=attr.Factory(dict))\n \n     def collection_for_region(self, region_name, image_store):\n         \"\"\"\ndiff --git a/mimic/model/nova_objects.py b/mimic/model/nova_objects.py\n--- a/mimic/model/nova_objects.py\n+++ b/mimic/model/nova_objects.py\n@@ -6,7 +6,7 @@\n \n import re\n import uuid\n-from characteristic import attributes, Attribute\n+import attr\n from random import randrange\n from json import loads, dumps\n from six.moves.urllib.parse import urlencode\n@@ -28,18 +28,20 @@\n from mimic.model.rackspace_images import RackspaceSavedImage\n \n \n-@attributes(['nova_message'])\n+@attr.s\n class LimitError(Exception):\n     \"\"\"\n     Error to be raised when a limit has been exceeded.\n     \"\"\"\n+    nova_message = attr.ib()\n \n \n-@attributes(['nova_message'])\n+@attr.s\n class BadRequestError(Exception):\n     \"\"\"\n     Error to be raised when bad input has been received to Nova.\n     \"\"\"\n+    nova_message = attr.ib()\n \n \n def _nova_error_message(msg_type, message, status_code, request):\n@@ -115,18 +117,29 @@ def conflicting(message, request):\n     return _nova_error_message(\"conflictingRequest\", message, CONFLICT, request)\n \n \n-@attributes([\"collection\", \"server_id\", \"server_name\", \"metadata\",\n-             \"creation_time\", \"update_time\", \"public_ips\", \"private_ips\",\n-             \"status\", \"flavor_ref\", \"image_ref\", \"disk_config\", \"key_name\",\n-             \"admin_password\", \"creation_request_json\",\n-             Attribute('max_metadata_items', instance_of=int,\n-                       default_value=40)])\n+@attr.s\n class Server(object):\n     \"\"\"\n     A :obj:`Server` is a representation of all the state associated with a nova\n     server.  It can produce JSON-serializable objects for various pieces of\n     state that are required for API responses.\n     \"\"\"\n+    admin_password = attr.ib()\n+    collection = attr.ib()\n+    creation_request_json = attr.ib()\n+    creation_time = attr.ib()\n+    disk_config = attr.ib()\n+    flavor_ref = attr.ib()\n+    image_ref = attr.ib()\n+    key_name = attr.ib()\n+    metadata = attr.ib()\n+    private_ips = attr.ib()\n+    public_ips = attr.ib()\n+    server_id = attr.ib()\n+    server_name = attr.ib()\n+    status = attr.ib()\n+    update_time = attr.ib()\n+    max_metadata_items = attr.ib(validator=attr.validators.instance_of(int), default=40)\n \n     static_defaults = {\n         \"OS-EXT-STS:power_state\": 1,\n@@ -339,11 +352,12 @@ def from_creation_request_json(cls, collection, creation_json,\n         return self\n \n \n-@attributes([\"address\"])\n+@attr.s\n class IPv4Address(object):\n     \"\"\"\n     An IPv4 address for a server.\n     \"\"\"\n+    address = attr.ib()\n \n     def json(self):\n         \"\"\"\n@@ -352,11 +366,12 @@ def json(self):\n         return {\"addr\": self.address, \"version\": 4}\n \n \n-@attributes([\"address\"])\n+@attr.s\n class IPv6Address(object):\n     \"\"\"\n     An IPv6 address for a server.\n     \"\"\"\n+    address = attr.ib()\n \n     def json(self):\n         \"\"\"\n@@ -650,17 +665,17 @@ def metadata_to_creation_behavior(metadata):\n     return None\n \n \n-@attributes(\n-    [\"tenant_id\", \"region_name\", \"clock\",\n-     Attribute(\"servers\", default_factory=list),\n-     Attribute(\n-         \"behavior_registry_collection\",\n-         default_factory=lambda: BehaviorRegistryCollection())]\n-)\n+@attr.s\n class RegionalServerCollection(object):\n     \"\"\"\n     A collection of servers, in a given region, for a given tenant.\n     \"\"\"\n+    tenant_id = attr.ib()\n+    region_name = attr.ib()\n+    clock = attr.ib()\n+    servers = attr.ib(default=attr.Factory(list))\n+    behavior_registry_collection = attr.ib(default=attr.Factory(\n+        lambda: BehaviorRegistryCollection()))\n \n     def server_by_id(self, server_id):\n         \"\"\"\n@@ -973,8 +988,7 @@ def request_action(self, http_action_request, server_id, absolutize_url,\n             return dumps(bad_request(\"There is no such action currently supported\", http_action_request))\n \n \n-@attributes([\"tenant_id\", \"clock\",\n-             Attribute(\"regional_collections\", default_factory=dict)])\n+@attr.s\n class GlobalServerCollections(object):\n     \"\"\"\n     A :obj:`GlobalServerCollections` is a set of all the\n@@ -982,6 +996,9 @@ class GlobalServerCollections(object):\n     words, all the objects that a single tenant owns globally in a Nova\n     service.\n     \"\"\"\n+    tenant_id = attr.ib()\n+    clock = attr.ib()\n+    regional_collections = attr.ib(default=attr.Factory(dict))\n \n     def collection_for_region(self, region_name):\n         \"\"\"\ndiff --git a/mimic/model/rackspace_image_store.py b/mimic/model/rackspace_image_store.py\n--- a/mimic/model/rackspace_image_store.py\n+++ b/mimic/model/rackspace_image_store.py\n@@ -2,7 +2,7 @@\n An image store representing Rackspace specific images\n \"\"\"\n from __future__ import absolute_import, division, unicode_literals\n-from characteristic import attributes, Attribute\n+import attr\n from six import iteritems\n from mimic.model.rackspace_images import (RackspaceWindowsImage,\n                                           RackspaceCentOSPVImage, RackspaceCentOSPVHMImage,\n@@ -19,12 +19,14 @@\n from mimic.model.rackspace_images import create_rackspace_images\n \n \n-@attributes([Attribute(\"image_list\", default_factory=list)])\n+@attr.s\n class RackspaceImageStore(object):\n     \"\"\"\n     A store for images to share between nova_api and glance_api\n     :var image_list: list of Rackspace images\n     \"\"\"\n+    image_list = attr.ib(default=attr.Factory(list))\n+\n     def create_image_store(self, tenant_id):\n         \"\"\"\n         Generates the data for each image in each image class\ndiff --git a/mimic/model/rackspace_images.py b/mimic/model/rackspace_images.py\n--- a/mimic/model/rackspace_images.py\n+++ b/mimic/model/rackspace_images.py\n@@ -4,7 +4,7 @@\n \n from __future__ import absolute_import, division, unicode_literals\n \n-from characteristic import attributes, Attribute\n+import attr\n import uuid\n import random\n \n@@ -23,18 +23,7 @@ def random_image_size():\n     return random.randint(250000, 80000000000)\n \n \n-@attributes([\n-    # Prior to refactor; no default value\n-    'image_id', 'tenant_id', 'name', 'minDisk', 'minRam', 'image_size',\n-    # Post-refactor; all have default values, but these should be slowly\n-    # removed.\n-    Attribute('flavor_classes', default_value=\"*\"),\n-    Attribute('image_type', default_value=\"base\"),\n-    Attribute('os_type', default_value=\"linux\"),\n-    Attribute('os_distro', default_value=\"\"),\n-    Attribute('vm_mode', default_value=\"hvm\"),\n-    Attribute('auto_disk_config', default_value=\"disabled\"),\n-])\n+@attr.s\n class Image(object):\n     \"\"\"\n     A Image object\n@@ -54,6 +43,22 @@ class Image(object):\n         with this image; possible values: \"True\", \"disabled\", and \"False\".\n         (TODO: what does \"False\" mean?)\n     \"\"\"\n+    # Prior to refactor; no default value\n+    image_id = attr.ib()\n+    tenant_id = attr.ib()\n+    name = attr.ib()\n+    minDisk = attr.ib()\n+    minRam = attr.ib()\n+    image_size = attr.ib()\n+\n+    # Post-refactor; all have default values, but these should be slowly\n+    # removed.\n+    flavor_classes = attr.ib(default=\"*\")\n+    image_type = attr.ib(default=\"base\")\n+    os_type = attr.ib(default=\"linux\")\n+    os_distro = attr.ib(default=\"\")\n+    vm_mode = attr.ib(default=\"hvm\")\n+    auto_disk_config = attr.ib(default=\"disabled\")\n \n     is_default = False\n \n@@ -138,12 +143,25 @@ def detailed_json(self, absolutize_url):\n         return template\n \n \n-@attributes(['image_id', 'tenant_id', 'name', 'minDisk', 'minRam', 'image_size', 'server_id', 'links',\n-             'flavor_classes', 'os_type', 'os_distro', 'vm_mode', 'disk_config'])\n+@attr.s\n class RackspaceSavedImage(object):\n     \"\"\"\n     A Rackspace saved image object representation\n     \"\"\"\n+    image_id = attr.ib()\n+    tenant_id = attr.ib()\n+    name = attr.ib()\n+    minDisk = attr.ib()\n+    minRam = attr.ib()\n+    image_size = attr.ib()\n+    server_id = attr.ib()\n+    links = attr.ib()\n+    flavor_classes = attr.ib()\n+    os_type = attr.ib()\n+    os_distro = attr.ib()\n+    vm_mode = attr.ib()\n+    disk_config = attr.ib()\n+\n     is_default = False\n \n     def metadata_json(self):\n@@ -654,11 +672,17 @@ def metadata_json(self):\n         }\n \n \n-@attributes(['image_id', 'tenant_id', 'name', 'minDisk', 'minRam', 'image_size'])\n+@attr.s\n class OnMetalImage(object):\n     \"\"\"\n     A Image object\n     \"\"\"\n+    image_id = attr.ib()\n+    tenant_id = attr.ib()\n+    name = attr.ib()\n+    minDisk = attr.ib()\n+    minRam = attr.ib()\n+    image_size = attr.ib()\n \n     is_default = False\n \ndiff --git a/mimic/model/valkyrie_objects.py b/mimic/model/valkyrie_objects.py\n--- a/mimic/model/valkyrie_objects.py\n+++ b/mimic/model/valkyrie_objects.py\n@@ -4,7 +4,7 @@\n \n from __future__ import absolute_import, division, unicode_literals\n \n-from characteristic import attributes, Attribute\n+import attr\n from json import dumps\n \n from mimic.util.helper import random_hex_generator\n@@ -67,7 +67,7 @@ def json(self):\n         }\n \n \n-@attributes([Attribute(\"valkyrie_store\", default_factory=list)])\n+@attr.s\n class ValkyrieStore(object):\n     \"\"\"\n \n@@ -85,6 +85,7 @@ class ValkyrieStore(object):\n         http://localhost:8900/valkyrie/v2/account/123456/permissions/contacts/devices/by_contact/56/effective\n \n     \"\"\"\n+    valkyrie_store = attr.ib(default=attr.Factory(list))\n \n     permissions = []\n     # Arguments are: account, contact, (direct) permission, item, item_type (1=account or 2=device)\ndiff --git a/mimic/rest/cloudfeeds.py b/mimic/rest/cloudfeeds.py\n--- a/mimic/rest/cloudfeeds.py\n+++ b/mimic/rest/cloudfeeds.py\n@@ -14,7 +14,7 @@\n from mimic.rest.mimicapp import MimicApp\n \n \n-from characteristic import attributes\n+import attr\n \n \n @implementer(IAPIMock, IPlugin)\n@@ -57,12 +57,14 @@ def resource_for_region(self, region, uri_prefix, session_store):\n \n \n @implementer(IAPIMock, IPlugin)\n-@attributes([\"cf_api\"])\n+@attr.s\n class CloudFeedsControlApi(object):\n     \"\"\"\n     This class registers the load balancer controller API in the service\n     catalog.\n     \"\"\"\n+    cf_api = attr.ib()\n+\n     def catalog_entries(self, tenant_id):\n         \"\"\"\n         Cloud feeds controller endpoints.\n@@ -89,11 +91,15 @@ def resource_for_region(self, region, uri_prefix, session_store):\n         return cfc_region.app.resource()\n \n \n-@attributes([\"api_mock\", \"uri_prefix\", \"session_store\", \"region\"])\n+@attr.s\n class CloudFeedsControlRegion(object):\n     \"\"\"\n     Klein routes for cloud feed's control API within a particular region.\n     \"\"\"\n+    api_mock = attr.ib()\n+    uri_prefix = attr.ib()\n+    session_store = attr.ib()\n+    region = attr.ib()\n \n     app = MimicApp()\n \ndiff --git a/mimic/rest/loadbalancer_api.py b/mimic/rest/loadbalancer_api.py\n--- a/mimic/rest/loadbalancer_api.py\n+++ b/mimic/rest/loadbalancer_api.py\n@@ -23,7 +23,7 @@\n \n from mimic.util.helper import invalid_resource, json_dump\n from mimic.util.helper import json_from_request\n-from characteristic import attributes\n+import attr\n \n \n @implementer(IAPIMock, IPlugin)\n@@ -78,12 +78,14 @@ def _get_session(self, session_store, tenant_id):\n \n \n @implementer(IAPIMock, IPlugin)\n-@attributes([\"lb_api\"])\n+@attr.s\n class LoadBalancerControlApi(object):\n     \"\"\"\n     This class registers the load balancer controller API in the service\n     catalog.\n     \"\"\"\n+    lb_api = attr.ib()\n+\n     def catalog_entries(self, tenant_id):\n         \"\"\"\n         Cloud load balancer controller endpoints.\n@@ -108,11 +110,15 @@ def resource_for_region(self, region, uri_prefix, session_store):\n         return lbc_region.app.resource()\n \n \n-@attributes([\"api_mock\", \"uri_prefix\", \"session_store\", \"region\"])\n+@attr.s\n class LoadBalancerControlRegion(object):\n     \"\"\"\n     Klein routes for load balancer's control API within a particular region.\n     \"\"\"\n+    api_mock = attr.ib()\n+    uri_prefix = attr.ib()\n+    session_store = attr.ib()\n+    region = attr.ib()\n \n     app = MimicApp()\n \n@@ -151,18 +157,9 @@ def set_attributes(self, request, tenant_id, clb_id):\n \n         try:\n             regional_lbs.set_attributes(clb_id, content)\n-        except BadKeysError as bke:\n-            request.setResponseCode(400)\n-            return json.dumps({\n-                \"message\": str(bke),\n-                \"code\": 400,\n-            })\n-        except BadValueError as bve:\n-            request.setResponseCode(400)\n-            return json.dumps({\n-                \"message\": str(bve),\n-                \"code\": 400,\n-            })\n+        except (BadKeysError, BadValueError) as err:\n+            request.setResponseCode(err.code)\n+            return json.dumps(err.to_json())\n         else:\n             request.setResponseCode(204)\n             return b''\ndiff --git a/mimic/rest/maas_api.py b/mimic/rest/maas_api.py\n--- a/mimic/rest/maas_api.py\n+++ b/mimic/rest/maas_api.py\n@@ -14,7 +14,6 @@\n import attr\n from six import text_type\n \n-from characteristic import attributes\n from zope.interface import implementer\n \n from twisted.plugin import IPlugin\n@@ -1662,11 +1661,13 @@ def latest_alarm_states(self, request, tenant_id):\n \n \n @implementer(IAPIMock, IPlugin)\n-@attributes([\"maas_api\"])\n+@attr.s\n class MaasControlApi(object):\n     \"\"\"\n     This class registers the MaaS controller API in the service catalog.\n     \"\"\"\n+    maas_api = attr.ib()\n+\n     def catalog_entries(self, tenant_id):\n         \"\"\"\n         List catalog entries for the MaaS API.\n@@ -1693,11 +1694,14 @@ def resource_for_region(self, region, uri_prefix, session_store):\n         return maas_controller.app.resource()\n \n \n-@attributes([\"api_mock\", \"session_store\", \"region\"])\n+@attr.s\n class MaasController(object):\n     \"\"\"\n     Klein routes for MaaS control API.\n     \"\"\"\n+    api_mock = attr.ib()\n+    session_store = attr.ib()\n+    region = attr.ib()\n \n     def _entity_cache_for_tenant(self, tenant_id):\n         \"\"\"\ndiff --git a/mimic/rest/nova_api.py b/mimic/rest/nova_api.py\n--- a/mimic/rest/nova_api.py\n+++ b/mimic/rest/nova_api.py\n@@ -8,7 +8,7 @@\n from uuid import uuid4\n import json\n \n-from characteristic import attributes\n+import attr\n from six import text_type\n \n from zope.interface import implementer\n@@ -87,11 +87,12 @@ def _get_session(self, session_store, tenant_id):\n \n \n @implementer(IAPIMock, IPlugin)\n-@attributes([\"nova_api\"])\n+@attr.s\n class NovaControlApi(object):\n     \"\"\"\n     Rest endpoints for the Nova Control Api.\n     \"\"\"\n+    nova_api = attr.ib()\n \n     def catalog_entries(self, tenant_id):\n         \"\"\"\n@@ -128,11 +129,16 @@ def resource_for_region(self, region, uri_prefix, session_store):\n \"\"\"\n \n \n-@attributes([\"api_mock\", \"uri_prefix\", \"session_store\", \"region\"])\n+@attr.s\n class NovaControlApiRegion(object):\n     \"\"\"\n     Klein resources for the Nova Control plane API\n     \"\"\"\n+    api_mock = attr.ib()\n+    uri_prefix = attr.ib()\n+    session_store = attr.ib()\n+    region = attr.ib()\n+\n     app = MimicApp()\n \n     @app.route('/v2/<string:tenant_id>/behaviors', branch=True)\ndiff --git a/mimic/rest/rackconnect_v3_api.py b/mimic/rest/rackconnect_v3_api.py\n--- a/mimic/rest/rackconnect_v3_api.py\n+++ b/mimic/rest/rackconnect_v3_api.py\n@@ -11,7 +11,7 @@\n import json\n from uuid import uuid4, UUID\n \n-from characteristic import attributes, Attribute\n+import attr\n from six import text_type\n \n from twisted.plugin import IPlugin\n@@ -72,17 +72,7 @@ def resource_for_region(self, region, uri_prefix, session_store):\n             default_pools=self.default_pools).app.resource()\n \n \n-@attributes(\n-    [Attribute(\"id\", default_factory=lambda: text_type(uuid4()),\n-               instance_of=text_type),\n-     Attribute(\"name\", default_value=u\"default\", instance_of=text_type),\n-     Attribute(\"port\", default_value=80, instance_of=int),\n-     Attribute(\"status\", default_value=u\"ACTIVE\", instance_of=text_type),\n-     Attribute(\"status_detail\", default_value=None),\n-     Attribute(\"virtual_ip\", default_factory=random_ipv4,\n-               instance_of=text_type),\n-     Attribute('nodes', default_factory=list, instance_of=list)],\n-    apply_with_cmp=False)\n+@attr.s(hash=False)\n class LoadBalancerPool(object):\n     \"\"\"\n     Represents a RackConnecvt v3 Load Balancer Pool.\n@@ -102,17 +92,25 @@ class LoadBalancerPool(object):\n     :param text_type virtual_ip: The IP of the load balancer pool\n     :param list nodes: :class:`LoadBalancerPoolNode`s\n     \"\"\"\n+    id = attr.ib(default=attr.Factory(lambda: text_type(uuid4())),\n+                 validator=attr.validators.instance_of(text_type))\n+    name = attr.ib(default=\"default\", validator=attr.validators.instance_of(text_type))\n+    port = attr.ib(default=80, validator=attr.validators.instance_of(int))\n+    status = attr.ib(default=\"ACTIVE\", validator=attr.validators.instance_of(text_type))\n+    status_detail = attr.ib(default=None)\n+    virtual_ip = attr.ib(default=attr.Factory(random_ipv4),\n+                         validator=attr.validators.instance_of(text_type))\n+    nodes = attr.ib(default=attr.Factory(list), validator=attr.validators.instance_of(list))\n+\n     def as_json(self):\n         \"\"\"\n         Create a JSON-serializable representation of the contents of this\n         object, which can be used in a REST response for a request for the\n         details of this particular object\n         \"\"\"\n-        # no dictionary comprehensions in py2.6\n-        response = dict([\n-            (attr.name, getattr(self, attr.name))\n-            for attr in LoadBalancerPool.characteristic_attributes\n-            if attr.name != \"nodes\"])\n+        response = {aa.name: getattr(self, aa.name)\n+                    for aa in attr.fields(LoadBalancerPool)\n+                    if aa.name != \"nodes\"}\n         response['node_counts'] = {\n             \"cloud_servers\": len(self.nodes),\n             \"external\": 0,\n@@ -141,13 +139,7 @@ def node_by_id(self, node_id):\n         return next((node for node in self.nodes if node.id == node_id), None)\n \n \n-@attributes([\"created\", \"load_balancer_pool\", \"cloud_server\",\n-             Attribute(\"id\", default_factory=lambda: text_type(uuid4()),\n-                       instance_of=text_type),\n-             Attribute(\"updated\", default_value=None),\n-             Attribute(\"status\", default_value=text_type(\"ACTIVE\"),\n-                       instance_of=text_type),\n-             Attribute(\"status_detail\", default_value=None)])\n+@attr.s\n class LoadBalancerPoolNode(object):\n     \"\"\"\n     Represents a Load Balancer Pool Node.\n@@ -173,6 +165,15 @@ class LoadBalancerPoolNode(object):\n         in theory can also be some external (not a cloud server) resource,\n         but that is not supported yet on the API.\n     \"\"\"\n+    created = attr.ib()\n+    load_balancer_pool = attr.ib()\n+    cloud_server = attr.ib()\n+    id = attr.ib(default=attr.Factory(lambda: text_type(uuid4())),\n+                 validator=attr.validators.instance_of(text_type))\n+    updated = attr.ib(default=None)\n+    status = attr.ib(default=\"ACTIVE\", validator=attr.validators.instance_of(text_type))\n+    status_detail = attr.ib(default=None)\n+\n     def short_json(self):\n         \"\"\"\n         Create a short JSON-serializable representation of the contents of\n@@ -184,11 +185,9 @@ def short_json(self):\n         GET /v3/{tenant_id}/load_balancer_pools/{load_balancer_pool_id}/nodes\n         (list load balancer pool nodes)\n         \"\"\"\n-        # no dictionary comprehensions in py2.6\n-        response = dict([\n-            (attr.name, getattr(self, attr.name))\n-            for attr in LoadBalancerPoolNode.characteristic_attributes\n-            if attr.name not in ('load_balancer_pool', 'cloud_server')])\n+        response = {aa.name: getattr(self, aa.name)\n+                    for aa in attr.fields(LoadBalancerPoolNode)\n+                    if aa.name not in ('load_balancer_pool', 'cloud_server')}\n         response['load_balancer_pool'] = {'id': self.load_balancer_pool.id}\n         response['cloud_server'] = {'id': self.cloud_server}\n         return response\n@@ -202,12 +201,17 @@ def update(self, now, status, status_detail=None):\n         self.status_detail = status_detail\n \n \n-@attributes([\"iapi\", \"uri_prefix\", \"session_store\", \"region_name\",\n-             \"default_pools\"])\n+@attr.s\n class RackConnectV3Region(object):\n     \"\"\"\n     A set of ``klein`` routes representing a RackConnect V3 endpoint.\n     \"\"\"\n+    iapi = attr.ib()\n+    uri_prefix = attr.ib()\n+    session_store = attr.ib()\n+    region_name = attr.ib()\n+    default_pools = attr.ib()\n+\n     app = MimicApp()\n \n     @app.route(\"/v3/<string:tenant_id>/load_balancer_pools\", branch=True)\n@@ -232,12 +236,15 @@ def get_tenant_lb_pools(self, request, tenant_id):\n # exclude all the attributes from comparison so that equality has to be\n # determined by identity, since lbpools is mutable and we don't want to\n # compare clocks\n-@attributes([\"lbpools\", \"clock\"], apply_with_cmp=False)\n+@attr.s(hash=False)\n class LoadBalancerPoolsInRegion(object):\n     \"\"\"\n     A set of ``klein`` routes handling RackConnect V3 Load Balancer Pools\n     collections.\n     \"\"\"\n+    lbpools = attr.ib()\n+    clock = attr.ib()\n+\n     app = MimicApp()\n \n     def _pool_by_id(self, id):\n@@ -389,12 +396,14 @@ def delegate_to_one_pool_handler(self, request, id):\n         return \"Load Balancer Pool {0} does not exist\".format(id)\n \n \n-@attributes([\"pool\"])\n+@attr.s\n class OneLoadBalancerPool(object):\n     \"\"\"\n     A set of ``klein`` routes handling the RackConnect V3 API for a single\n     load balancer pool\n     \"\"\"\n+    pool = attr.ib()\n+\n     app = MimicApp()\n \n     @app.route(\"/\", methods=[\"GET\"])\ndiff --git a/mimic/rest/swift_api.py b/mimic/rest/swift_api.py\n--- a/mimic/rest/swift_api.py\n+++ b/mimic/rest/swift_api.py\n@@ -9,7 +9,7 @@\n from uuid import uuid4, uuid5, NAMESPACE_URL\n from six import text_type\n \n-from characteristic import attributes, Attribute\n+import attr\n from json import dumps\n \n from mimic.imimic import IAPIMock\n@@ -79,12 +79,15 @@ def resource_for_region(self, region, uri_prefix, session_store):\n             session_store=session_store).app.resource()\n \n \n-@attributes(\"api uri_prefix session_store\".split())\n+@attr.s\n class SwiftRegion(object):\n     \"\"\"\n     :obj:`SwiftRegion` is a set of klein routes and application representing a\n     Swift endpoint.\n     \"\"\"\n+    api = attr.ib()\n+    uri_prefix = attr.ib()\n+    session_store = attr.ib()\n \n     app = MimicApp()\n \n@@ -99,12 +102,15 @@ def get_one_tenant_resource(self, request, tenant_id):\n                               SwiftTenantInRegion().app.resource()))\n \n \n-@attributes([\"name\", \"content_type\", \"data\"])\n+@attr.s\n class Object(object):\n     \"\"\"\n     A Python object (i.e. instance) representing a Swift object (i.e. bag of\n     octets).\n     \"\"\"\n+    name = attr.ib()\n+    content_type = attr.ib()\n+    data = attr.ib()\n \n     def as_json(self):\n         \"\"\"\n@@ -118,11 +124,13 @@ def as_json(self):\n         }\n \n \n-@attributes([\"name\", Attribute(\"objects\", default_factory=dict)])\n+@attr.s\n class Container(object):\n     \"\"\"\n     A Swift container (collection of :obj:`Object`.)\n     \"\"\"\n+    name = attr.ib()\n+    objects = attr.ib(default=attr.Factory(dict))\n \n \n class SwiftTenantInRegion(object):\ndiff --git a/mimic/session.py b/mimic/session.py\n--- a/mimic/session.py\n+++ b/mimic/session.py\n@@ -10,17 +10,21 @@\n from uuid import uuid4\n from datetime import datetime, timedelta\n \n-from characteristic import attributes, Attribute\n+import attr\n \n \n-@attributes(['username', 'token', 'tenant_id', 'expires',\n-             Attribute('impersonator_session_map', default_factory=dict),\n-             Attribute('_api_objects', default_factory=dict)])\n+@attr.s\n class Session(object):\n     \"\"\"\n     A mimic Session is a record of an authentication token for a particular\n     username and tenant_id.\n     \"\"\"\n+    username = attr.ib()\n+    token = attr.ib()\n+    tenant_id = attr.ib()\n+    expires = attr.ib()\n+    impersonator_session_map = attr.ib(default=attr.Factory(dict))\n+    _api_objects = attr.ib(default=attr.Factory(dict))\n \n     @property\n     def user_id(self):\n@@ -46,12 +50,13 @@ def data_for_api(self, api_mock, data_factory):\n         return self._api_objects[api_mock]\n \n \n-@attributes([Attribute('session', instance_of=Session),\n-             'desired_tenant'])\n+@attr.s\n class NonMatchingTenantError(Exception):\n     \"\"\"\n     A session's tenant ID does not match the desired tenant ID.\n     \"\"\"\n+    session = attr.ib(validator=attr.validators.instance_of(Session))\n+    desired_tenant = attr.ib()\n \n \n class SessionStore(object):\n", "test_patch": "diff --git a/mimic/test/test_rackconnect_v3.py b/mimic/test/test_rackconnect_v3.py\n--- a/mimic/test/test_rackconnect_v3.py\n+++ b/mimic/test/test_rackconnect_v3.py\n@@ -4,6 +4,7 @@\n \n from __future__ import absolute_import, division, unicode_literals\n \n+import attr\n import json\n from random import randint\n from uuid import uuid4\n@@ -201,14 +202,14 @@ def test_list_pools_default_one(self):\n         pool_json = response_json[0]\n         # has the right JSON\n         self.assertTrue(all(\n-            attr.name in pool_json\n-            for attr in LoadBalancerPool.characteristic_attributes\n-            if attr.name != \"nodes\"))\n+            aa.name in pool_json\n+            for aa in attr.fields(LoadBalancerPool)\n+            if aa.name != \"nodes\"))\n         # Generated values\n         self.assertTrue(all(\n-            pool_json.get(attr.name)\n-            for attr in LoadBalancerPool.characteristic_attributes\n-            if attr.name not in (\"nodes\", \"status_detail\")))\n+            pool_json.get(aa.name)\n+            for aa in attr.fields(LoadBalancerPool)\n+            if aa.name not in (\"nodes\", \"status_detail\")))\n \n         self.assertEqual(\n             {\n", "problem_statement": "", "hints_text": "", "created_at": "2016-02-17T07:33:08Z"}