Add data model entities for OrderRetryTask
Change-Id: I108dca2d6e1ef5be5bafd54e307836d66d789958
This commit is contained in:
parent
5ad9232ef0
commit
906a89f61d
@ -0,0 +1,34 @@
|
||||
"""Add OrderRetryTask
|
||||
|
||||
Revision ID: aa2cf96a1d5
|
||||
Revises: 256da65e0c5f
|
||||
Create Date: 2015-01-19 10:27:19.179196
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "aa2cf96a1d5"
|
||||
down_revision = "256da65e0c5f"
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_table(
|
||||
"order_retry_tasks",
|
||||
sa.Column("id", sa.String(length=36), nullable=False),
|
||||
sa.Column("order_id", sa.String(length=36), nullable=False),
|
||||
sa.Column("retry_task", sa.Text(), nullable=False),
|
||||
sa.Column("retry_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("retry_args", sa.Text(), nullable=False),
|
||||
sa.Column("retry_kwargs", sa.Text(), nullable=False),
|
||||
sa.Column("retry_count", sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["order_id"], ["orders.id"]),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
mysql_engine="InnoDB"
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table("order_retry_tasks")
|
@ -548,6 +548,28 @@ class OrderPluginMetadatum(BASE, ModelBase):
|
||||
'value': self.value}
|
||||
|
||||
|
||||
class OrderRetryTask(BASE):
|
||||
|
||||
__tablename__ = "order_retry_tasks"
|
||||
__table_args__ = {"mysql_engine": "InnoDB"}
|
||||
__table_initialized__ = False
|
||||
|
||||
id = sa.Column(
|
||||
sa.String(36), primary_key=True, default=utils.generate_uuid,
|
||||
)
|
||||
order_id = sa.Column(
|
||||
sa.String(36), sa.ForeignKey("orders.id"), nullable=False,
|
||||
)
|
||||
retry_task = sa.Column(sa.Text, nullable=False)
|
||||
retry_at = sa.Column(sa.DateTime, default=None, nullable=False)
|
||||
retry_args = sa.Column(sa.Text, nullable=False)
|
||||
retry_kwargs = sa.Column(sa.Text, nullable=False)
|
||||
retry_count = sa.Column(sa.Integer, nullable=False, default=0)
|
||||
|
||||
def get_retry_params(self):
|
||||
return json.loads(self.retry_args), json.loads(self.retry_kwargs)
|
||||
|
||||
|
||||
class Container(BASE, ModelBase):
|
||||
"""Represents a Container for Secrets in the datastore.
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
import datetime
|
||||
|
||||
from barbican.model import models
|
||||
from barbican.openstack.common import jsonutils as json
|
||||
from barbican.tests import utils
|
||||
|
||||
|
||||
@ -175,3 +176,47 @@ class WhenProcessingJsonBlob(utils.BaseTestCase):
|
||||
def test_process_result_value_w_json_str(self):
|
||||
res = self.json_blob.process_result_value('{"test": true}', None)
|
||||
self.assertTrue(res.get('test'))
|
||||
|
||||
|
||||
class WhenCreatingOrderRetryTask(utils.BaseTestCase):
|
||||
|
||||
def test_create_new_order_task(self):
|
||||
order = models.Order({
|
||||
'type': 'certificate',
|
||||
'meta': {
|
||||
'email': 'email@email.com'
|
||||
},
|
||||
'sub_status': 'Pending',
|
||||
'sub_status_message': 'Waiting for instructions...'
|
||||
})
|
||||
at = datetime.datetime.utcnow()
|
||||
order_retry_task = models.OrderRetryTask(
|
||||
order_id=order.id,
|
||||
retry_task="foobar",
|
||||
retry_at=at,
|
||||
retry_args=json.dumps(["one", "two"]),
|
||||
retry_kwargs=json.dumps({"three": "four"}),
|
||||
)
|
||||
|
||||
self.assertEqual(order_retry_task.order_id, order.id)
|
||||
self.assertEqual(order_retry_task.retry_task, "foobar")
|
||||
self.assertEqual(order_retry_task.retry_at, at)
|
||||
self.assertEqual(
|
||||
order_retry_task.retry_args,
|
||||
json.dumps(["one", "two"]),
|
||||
)
|
||||
self.assertEqual(
|
||||
order_retry_task.retry_kwargs,
|
||||
json.dumps({"three": "four"}),
|
||||
)
|
||||
|
||||
def test_get_retry_params(self):
|
||||
order_retry_task = models.OrderRetryTask(
|
||||
retry_args=json.dumps(["one", "two"]),
|
||||
retry_kwargs=json.dumps({"three": "four"}),
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
order_retry_task.get_retry_params(),
|
||||
(["one", "two"], {"three": "four"}),
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user