Esempio n. 1
0
 def from_storage(cls, __d: progress.ProgressRecord) -> "HandlerState":
     return cls(
         started=_datetime_fromisoformat(__d.get('started')) or datetime.datetime.utcnow(),
         stopped=_datetime_fromisoformat(__d.get('stopped')),
         delayed=_datetime_fromisoformat(__d.get('delayed')),
         retries=__d.get('retries') or 0,
         success=__d.get('success') or False,
         failure=__d.get('failure') or False,
         message=__d.get('message'),
         _origin=__d,
     )
Esempio n. 2
0
 def from_storage(cls, __d: progress.ProgressRecord) -> "HandlerState":
     return cls(
         active=False,
         started=_datetime_fromisoformat(__d.get('started')) or datetime.datetime.utcnow(),
         stopped=_datetime_fromisoformat(__d.get('stopped')),
         delayed=_datetime_fromisoformat(__d.get('delayed')),
         purpose=handlers_.Reason(__d.get('purpose')) if __d.get('purpose') else None,
         retries=__d.get('retries') or 0,
         success=__d.get('success') or False,
         failure=__d.get('failure') or False,
         message=__d.get('message'),
         subrefs=__d.get('subrefs') or (),
         _origin=__d,
     )
def test_storing_to_annotations_storage_cleans_content(cls):
    storage = cls(prefix='my-operator.example.com')  # no verbose=
    patch = Patch()
    body = Body({})
    content = ProgressRecord(
        started=None,
        stopped=None,
        delayed=None,
        retries=None,
        success=None,
        failure=None,
        message=None,
    )
    storage.store(body=body, patch=patch, key=HandlerId('id1'), record=content)

    assert patch
    assert patch['metadata']['annotations'][
        'my-operator.example.com/id1'] == json.dumps({})
Esempio n. 4
0
ANNOTATIONS_POPULATING_STORAGES = [
    AnnotationsProgressStorage,
    SmartProgressStorage,
]
STORAGE_KEY_FORMING_CLASSES = [
    StorageKeyFormingConvention,
    AnnotationsProgressStorage,
    AnnotationsDiffBaseStorage,
]

CONTENT_DATA = ProgressRecord(
    started='2020-01-01T00:00:00',
    stopped='2020-12-31T23:59:59',
    delayed='3000-01-01T00:00:00',
    retries=0,
    success=False,
    failure=False,
    message=None,
)

CONTENT_JSON = json.dumps(CONTENT_DATA, separators=(',', ':'))

COMMON_KEYS = [
    # For character replacements (only those that happen in our own ids, not all of them).
    [
        'my-operator.example.com', 'a_b.c-d/e',
        'my-operator.example.com/a_b.c-d.e'
    ],
    [None, 'a_b.c-d/e', 'a_b.c-d.e'],
]
    SmartProgressStorage,
)

ALL_STORAGES = [
    AnnotationsProgressStorage, StatusProgressStorage, SmartProgressStorage
]
ANNOTATIONS_POPULATING_STORAGES = [
    AnnotationsProgressStorage, SmartProgressStorage
]
STATUS_POPULATING_STORAGES = [StatusProgressStorage, SmartProgressStorage]

CONTENT_DATA_1 = ProgressRecord(
    started='2020-01-01T00:00:00',
    stopped='2020-12-31T23:59:59',
    delayed='3000-01-01T00:00:00',
    retries=123,
    success=False,
    failure=False,
    message=None,
)

CONTENT_DATA_2 = ProgressRecord(
    started='2021-01-01T00:00:00',
    stopped='2021-12-31T23:59:59',
    delayed='3001-01-01T00:00:00',
    retries=456,
    success=False,
    failure=False,
    message="Some error.",
)