diff --git a/api/staleness.py b/api/staleness.py index 48454333d..b4f75027a 100644 --- a/api/staleness.py +++ b/api/staleness.py @@ -36,12 +36,12 @@ def _get_return_data(): "id": "1ba078bb-8461-474c-8498-1e50a1975cfb", "account_id": "0123456789", "org_id": "123", - "conventional_staleness_delta": "1", - "conventional_stale_warning_delta": "7", - "conventional_culling_delta": "14", - "immutable_staleness_delta": "2", - "immutable_stale_warning_delta": "120", - "immutable_culling_delta": "180", + "conventional_time_to_stale": "1", + "conventional_time_to_stale_warning": "7", + "conventional_time_to_delete": "14", + "immutable_time_to_stale": "2", + "immutable_time_to_stale_warning": "120", + "immutable_time_to_delete": "180", "created_at": "2023-07-28T14:32:16.353082", "updated_at": "2023-07-28T14:32:16.353082", } diff --git a/api/staleness_query.py b/api/staleness_query.py index 1eddfe754..19d11a815 100644 --- a/api/staleness_query.py +++ b/api/staleness_query.py @@ -38,12 +38,12 @@ def _build_staleness_sys_default(org_id, config=None): { "id": "system_default", "org_id": org_id, - "conventional_staleness_delta": config.conventional_staleness_seconds, - "conventional_stale_warning_delta": config.conventional_stale_warning_seconds, - "conventional_culling_delta": config.conventional_culling_seconds, - "immutable_staleness_delta": config.immutable_staleness_seconds, - "immutable_stale_warning_delta": config.immutable_stale_warning_seconds, - "immutable_culling_delta": config.immutable_culling_seconds, + "conventional_time_to_stale": config.conventional_time_to_stale_seconds, + "conventional_time_to_stale_warning": config.conventional_time_to_stale_warning_seconds, + "conventional_time_to_delete": config.conventional_time_to_delete_seconds, + "immutable_time_to_stale": config.immutable_time_to_stale_seconds, + "immutable_time_to_stale_warning": config.immutable_time_to_stale_warning_seconds, + "immutable_time_to_delete": config.immutable_time_to_delete_seconds, "created_on": "N/A", "modified_on": "N/A", } @@ -58,12 +58,12 @@ def _build_serialized_acc_staleness_obj(staleness): { "id": str(staleness.id), "org_id": staleness.org_id, - "conventional_staleness_delta": staleness.conventional_staleness_delta, - "conventional_stale_warning_delta": staleness.conventional_stale_warning_delta, - "conventional_culling_delta": staleness.conventional_culling_delta, - "immutable_staleness_delta": staleness.immutable_staleness_delta, - "immutable_stale_warning_delta": staleness.immutable_stale_warning_delta, - "immutable_culling_delta": staleness.immutable_culling_delta, + "conventional_time_to_stale": staleness.conventional_time_to_stale, + "conventional_time_to_stale_warning": staleness.conventional_time_to_stale_warning, + "conventional_time_to_delete": staleness.conventional_time_to_delete, + "immutable_time_to_stale": staleness.immutable_time_to_stale, + "immutable_time_to_stale_warning": staleness.immutable_time_to_stale_warning, + "immutable_time_to_delete": staleness.immutable_time_to_delete, "created_on": staleness.created_on, "modified_on": staleness.modified_on, } diff --git a/app/config.py b/app/config.py index aa620a8b4..549f3dee3 100644 --- a/app/config.py +++ b/app/config.py @@ -230,21 +230,29 @@ def __init__(self, runtime_environment): minutes=int(os.environ.get("CULLING_CULLED_OFFSET_MINUTES", "0")), ) - self.conventional_staleness_seconds = int(os.environ.get("CONVENTIONAL_STALENESS_SECONDS", 104400)) # 29 hours + self.conventional_time_to_stale_seconds = int( + os.environ.get("CONVENTIONAL_TIME_TO_STALE_SECONDS", 104400) + ) # 29 hours - self.conventional_stale_warning_seconds = os.environ.get( - "CONVENTIONAL_STALENESS_WARNING_SECONDS", self.days_to_seconds(7) + self.conventional_time_to_stale_warning_seconds = os.environ.get( + "CONVENTIONAL_TIME_TO_STALE_WARNING_SECONDS", self.days_to_seconds(7) ) - self.conventional_culling_seconds = os.environ.get("CONVENTIONAL_CULLING_SECONDS", self.days_to_seconds(14)) + self.conventional_time_to_delete_seconds = os.environ.get( + "CONVENTIONAL_TIME_TO_DELETE_SECONDS", self.days_to_seconds(14) + ) - self.immutable_staleness_seconds = os.environ.get("IMMUTABLE_STALENESS_SECONDS", self.days_to_seconds(2)) + self.immutable_time_to_stale_seconds = os.environ.get( + "IMMUTABLE_TIME_TO_STALE_SECONDS", self.days_to_seconds(2) + ) - self.immutable_stale_warning_seconds = os.environ.get( - "IMMUTABLE_STALENESS_WARNING_SECONDS", self.days_to_seconds(180) + self.immutable_time_to_stale_warning_seconds = os.environ.get( + "IMMUTABLE_TIME_TO_STALE_WARNING_SECONDS", self.days_to_seconds(180) ) - self.immutable_culling_seconds = os.environ.get("IMMUTABLE_CULLING_SECONDS", self.days_to_seconds(730)) + self.immutable_time_to_delete_seconds = os.environ.get( + "IMMUTABLE_TIME_TO_DELETE_SECONDS", self.days_to_seconds(730) + ) self.xjoin_graphql_url = os.environ.get("XJOIN_GRAPHQL_URL", "http://localhost:4000/graphql") diff --git a/app/culling.py b/app/culling.py index 67594d134..db5f1694e 100644 --- a/app/culling.py +++ b/app/culling.py @@ -44,14 +44,14 @@ def __init__(self, staleness, host_type): self.staleness_host_type = { None: { - "stale": staleness["conventional_staleness_delta"], - "warning": staleness["conventional_stale_warning_delta"], - "culled": staleness["conventional_culling_delta"], + "stale": staleness["conventional_time_to_stale"], + "warning": staleness["conventional_time_to_stale_warning"], + "culled": staleness["conventional_time_to_delete"], }, "edge": { - "stale": staleness["immutable_staleness_delta"], - "warning": staleness["immutable_stale_warning_delta"], - "culled": staleness["immutable_culling_delta"], + "stale": staleness["immutable_time_to_stale"], + "warning": staleness["immutable_time_to_stale_warning"], + "culled": staleness["immutable_time_to_delete"], }, } diff --git a/app/models.py b/app/models.py index 947b97e11..40701d454 100644 --- a/app/models.py +++ b/app/models.py @@ -549,50 +549,50 @@ class Staleness(db.Model): def __init__( self, org_id, - conventional_staleness_delta=None, - conventional_stale_warning_delta=None, - conventional_culling_delta=None, - immutable_staleness_delta=None, - immutable_stale_warning_delta=None, - immutable_culling_delta=None, + conventional_time_to_stale=None, + conventional_time_to_stale_warning=None, + conventional_time_to_delete=None, + immutable_time_to_stale=None, + immutable_time_to_stale_warning=None, + immutable_time_to_delete=None, ): if not org_id: raise ValidationException("Staleness org_id cannot be null.") self.org_id = org_id - self.conventional_staleness_delta = conventional_staleness_delta - self.conventional_stale_warning_delta = conventional_stale_warning_delta - self.conventional_culling_delta = conventional_culling_delta - self.immutable_staleness_delta = immutable_staleness_delta - self.immutable_stale_warning_delta = immutable_stale_warning_delta - self.immutable_culling_delta = immutable_culling_delta + self.conventional_time_to_stale = conventional_time_to_stale + self.conventional_time_to_stale_warning = conventional_time_to_stale_warning + self.conventional_time_to_delete = conventional_time_to_delete + self.immutable_time_to_stale = immutable_time_to_stale + self.immutable_time_to_stale_warning = immutable_time_to_stale_warning + self.immutable_time_to_delete = immutable_time_to_delete def days_to_seconds(n_days): factor = 86400 return n_days * factor def update(self, input_acc): - if input_acc.conventional_staleness_delta: - self.conventional_staleness_delta = input_acc.conventional_staleness_delta - if input_acc.conventional_stale_warning_delta: - self.conventional_stale_warning_delta = input_acc.conventional_stale_warning_delta - if input_acc.conventional_culling_delta: - self.conventional_culling_delta = input_acc.conventional_culling_delta - if input_acc.immutable_staleness_delta: - self.immutable_staleness_delta = input_acc.immutable_staleness_delta - if input_acc.immutable_stale_warning_delta: - self.immutable_stale_warning_delta = input_acc.immutable_stale_warning_delta - if input_acc.immutable_culling_delta: - self.immutable_culling_delta = input_acc.immutable_culling_delta + if input_acc.conventional_time_to_stale: + self.conventional_time_to_stale = input_acc.conventional_time_to_stale + if input_acc.conventional_time_to_stale_warning: + self.conventional_time_to_stale_warning = input_acc.conventional_time_to_stale_warning + if input_acc.conventional_time_to_delete: + self.conventional_time_to_delete = input_acc.conventional_time_to_delete + if input_acc.immutable_time_to_stale: + self.immutable_time_to_stale = input_acc.immutable_time_to_stale + if input_acc.immutable_time_to_stale_warning: + self.immutable_time_to_stale_warning = input_acc.immutable_time_to_stale_warning + if input_acc.immutable_time_to_delete: + self.immutable_time_to_delete = input_acc.immutable_time_to_delete id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) org_id = db.Column(db.String(36), nullable=False) - conventional_staleness_delta = db.Column(db.Integer, default=104400, nullable=False) - conventional_stale_warning_delta = db.Column(db.Integer, default=days_to_seconds(7), nullable=False) - conventional_culling_delta = db.Column(db.Integer, default=days_to_seconds(14), nullable=False) - immutable_staleness_delta = db.Column(db.Integer, default=days_to_seconds(2), nullable=False) - immutable_stale_warning_delta = db.Column(db.Integer, default=days_to_seconds(180), nullable=False) - immutable_culling_delta = db.Column(db.Integer, default=days_to_seconds(730), nullable=False) + conventional_time_to_stale = db.Column(db.Integer, default=104400, nullable=False) + conventional_time_to_stale_warning = db.Column(db.Integer, default=days_to_seconds(7), nullable=False) + conventional_time_to_delete = db.Column(db.Integer, default=days_to_seconds(14), nullable=False) + immutable_time_to_stale = db.Column(db.Integer, default=days_to_seconds(2), nullable=False) + immutable_time_to_stale_warning = db.Column(db.Integer, default=days_to_seconds(180), nullable=False) + immutable_time_to_delete = db.Column(db.Integer, default=days_to_seconds(730), nullable=False) created_on = db.Column(db.DateTime(timezone=True), default=_time_now) modified_on = db.Column(db.DateTime(timezone=True), default=_time_now, onupdate=_time_now) @@ -862,12 +862,12 @@ def __init__(self, *args, **kwargs): class StalenessSchema(MarshmallowSchema): - conventional_staleness_delta = fields.Integer(validate=marshmallow_validate.Range(min=1, max=2147483647)) - conventional_stale_warning_delta = fields.Integer(validate=marshmallow_validate.Range(min=1, max=2147483647)) - conventional_culling_delta = fields.Integer(validate=marshmallow_validate.Range(min=1, max=2147483647)) - immutable_staleness_delta = fields.Integer(validate=marshmallow_validate.Range(min=1, max=2147483647)) - immutable_stale_warning_delta = fields.Integer(validate=marshmallow_validate.Range(min=1, max=2147483647)) - immutable_culling_delta = fields.Integer(validate=marshmallow_validate.Range(min=1, max=2147483647)) + conventional_time_to_stale = fields.Integer(validate=marshmallow_validate.Range(min=1, max=2147483647)) + conventional_time_to_stale_warning = fields.Integer(validate=marshmallow_validate.Range(min=1, max=2147483647)) + conventional_time_to_delete = fields.Integer(validate=marshmallow_validate.Range(min=1, max=2147483647)) + immutable_time_to_stale = fields.Integer(validate=marshmallow_validate.Range(min=1, max=2147483647)) + immutable_time_to_stale_warning = fields.Integer(validate=marshmallow_validate.Range(min=1, max=2147483647)) + immutable_time_to_delete = fields.Integer(validate=marshmallow_validate.Range(min=1, max=2147483647)) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/app/serialization.py b/app/serialization.py index 4406db809..9eab5e6b3 100644 --- a/app/serialization.py +++ b/app/serialization.py @@ -122,24 +122,22 @@ def serialize_host( # TODO: In future, this must handle groups staleness if host.system_profile_facts.get("host_type") == "edge": - stale_timestamp = staleness_timestamps.stale_timestamp( - host.modified_on, staleness["immutable_staleness_delta"] - ) + stale_timestamp = staleness_timestamps.stale_timestamp(host.modified_on, staleness["immutable_time_to_stale"]) stale_warning_timestamp = staleness_timestamps.stale_warning_timestamp( - host.modified_on, staleness["immutable_stale_warning_delta"] + host.modified_on, staleness["immutable_time_to_stale_warning"] ) culled_timestamp = staleness_timestamps.culled_timestamp( - host.modified_on, staleness["immutable_culling_delta"] + host.modified_on, staleness["immutable_time_to_delete"] ) else: stale_timestamp = staleness_timestamps.stale_timestamp( - host.modified_on, staleness["conventional_staleness_delta"] + host.modified_on, staleness["conventional_time_to_stale"] ) stale_warning_timestamp = staleness_timestamps.stale_warning_timestamp( - host.modified_on, staleness["conventional_stale_warning_delta"] + host.modified_on, staleness["conventional_time_to_stale_warning"] ) culled_timestamp = staleness_timestamps.culled_timestamp( - host.modified_on, staleness["conventional_culling_delta"] + host.modified_on, staleness["conventional_time_to_delete"] ) serialized_host = {**serialize_canonical_facts(host.canonical_facts)} @@ -381,12 +379,12 @@ def serialize_staleness_response(staleness): return { "id": _serialize_uuid(staleness.id), "org_id": staleness.org_id, - "conventional_staleness_delta": staleness.conventional_staleness_delta, - "conventional_stale_warning_delta": staleness.conventional_stale_warning_delta, - "conventional_culling_delta": staleness.conventional_culling_delta, - "immutable_staleness_delta": staleness.immutable_staleness_delta, - "immutable_stale_warning_delta": staleness.immutable_stale_warning_delta, - "immutable_culling_delta": staleness.immutable_culling_delta, + "conventional_time_to_stale": staleness.conventional_time_to_stale, + "conventional_time_to_stale_warning": staleness.conventional_time_to_stale_warning, + "conventional_time_to_delete": staleness.conventional_time_to_delete, + "immutable_time_to_stale": staleness.immutable_time_to_stale, + "immutable_time_to_stale_warning": staleness.immutable_time_to_stale_warning, + "immutable_time_to_delete": staleness.immutable_time_to_delete, "created": "N/A" if staleness.created_on == "N/A" else _serialize_datetime(staleness.created_on), "updated": "N/A" if staleness.modified_on == "N/A" else _serialize_datetime(staleness.modified_on), } @@ -398,10 +396,10 @@ def serialize_staleness_to_dict(staleness_obj) -> dict: to a simple dictionary. This contains less information """ return { - "conventional_staleness_delta": staleness_obj.conventional_staleness_delta, - "conventional_stale_warning_delta": staleness_obj.conventional_stale_warning_delta, - "conventional_culling_delta": staleness_obj.conventional_culling_delta, - "immutable_staleness_delta": staleness_obj.immutable_staleness_delta, - "immutable_stale_warning_delta": staleness_obj.immutable_stale_warning_delta, - "immutable_culling_delta": staleness_obj.immutable_culling_delta, + "conventional_time_to_stale": staleness_obj.conventional_time_to_stale, + "conventional_time_to_stale_warning": staleness_obj.conventional_time_to_stale_warning, + "conventional_time_to_delete": staleness_obj.conventional_time_to_delete, + "immutable_time_to_stale": staleness_obj.immutable_time_to_stale, + "immutable_time_to_stale_warning": staleness_obj.immutable_time_to_stale_warning, + "immutable_time_to_delete": staleness_obj.immutable_time_to_delete, } diff --git a/lib/staleness.py b/lib/staleness.py index cddf6bdac..eb0990b10 100644 --- a/lib/staleness.py +++ b/lib/staleness.py @@ -9,23 +9,23 @@ def add_staleness(staleness_data) -> Staleness: logger.debug("Creating a new AccountStaleness: %s", staleness_data) - conventional_staleness_delta = staleness_data.get("conventional_staleness_delta") - conventional_stale_warning_delta = staleness_data.get("conventional_stale_warning_delta") - conventional_culling_delta = staleness_data.get("conventional_culling_delta") - immutable_staleness_delta = staleness_data.get("immutable_staleness_delta") - immutable_stale_warning_delta = staleness_data.get("immutable_stale_warning_delta") - immutable_culling_delta = staleness_data.get("immutable_culling_delta") + conventional_time_to_stale = staleness_data.get("conventional_time_to_stale") + conventional_time_to_stale_warning = staleness_data.get("conventional_time_to_stale_warning") + conventional_time_to_delete = staleness_data.get("conventional_time_to_delete") + immutable_time_to_stale = staleness_data.get("immutable_time_to_stale") + immutable_time_to_stale_warning = staleness_data.get("immutable_time_to_stale_warning") + immutable_time_to_delete = staleness_data.get("immutable_time_to_delete") org_id = get_current_identity().org_id with session_guard(db.session): new_staleness = Staleness( org_id=org_id, - conventional_staleness_delta=conventional_staleness_delta, - conventional_stale_warning_delta=conventional_stale_warning_delta, - conventional_culling_delta=conventional_culling_delta, - immutable_staleness_delta=immutable_staleness_delta, - immutable_stale_warning_delta=immutable_stale_warning_delta, - immutable_culling_delta=immutable_culling_delta, + conventional_time_to_stale=conventional_time_to_stale, + conventional_time_to_stale_warning=conventional_time_to_stale_warning, + conventional_time_to_delete=conventional_time_to_delete, + immutable_time_to_stale=immutable_time_to_stale, + immutable_time_to_stale_warning=immutable_time_to_stale_warning, + immutable_time_to_delete=immutable_time_to_delete, ) db.session.add(new_staleness) db.session.flush() diff --git a/migrations/versions/22367a1b23e9_rename_staleness_attribute.py b/migrations/versions/22367a1b23e9_rename_staleness_attribute.py new file mode 100644 index 000000000..095db02e6 --- /dev/null +++ b/migrations/versions/22367a1b23e9_rename_staleness_attribute.py @@ -0,0 +1,37 @@ +"""Rename staleness attribute + +Revision ID: 22367a1b23e9 +Revises: cc3494db47ea +Create Date: 2023-12-05 10:29:10.185627 + +""" +from alembic import op + + +# revision identifiers, used by Alembic. +revision = "22367a1b23e9" +down_revision = "cc3494db47ea" +branch_labels = None +depends_on = None + + +def upgrade(): + op.alter_column("staleness", "conventional_staleness_delta", new_column_name="conventional_time_to_stale") + op.alter_column( + "staleness", "conventional_stale_warning_delta", new_column_name="conventional_time_to_stale_warning" + ) + op.alter_column("staleness", "conventional_culling_delta", new_column_name="conventional_time_to_delete") + op.alter_column("staleness", "immutable_staleness_delta", new_column_name="immutable_time_to_stale") + op.alter_column("staleness", "immutable_stale_warning_delta", new_column_name="immutable_time_to_stale_warning") + op.alter_column("staleness", "immutable_culling_delta", new_column_name="immutable_time_to_delete") + + +def downgrade(): + op.alter_column("staleness", "conventional_time_to_stale", new_column_name="conventional_staleness_delta") + op.alter_column( + "staleness", "conventional_time_to_stale_warning", new_column_name="conventional_stale_warning_delta" + ) + op.alter_column("staleness", "conventional_time_to_delete", new_column_name="conventional_culling_delta") + op.alter_column("staleness", "immutable_time_to_stale", new_column_name="immutable_staleness_delta") + op.alter_column("staleness", "immutable_time_to_stale_warning", new_column_name="immutable_stale_warning_delta") + op.alter_column("staleness", "immutable_time_to_delete", new_column_name="immutable_culling_delta") diff --git a/swagger/api.spec.yaml b/swagger/api.spec.yaml index ddbc76724..d58d318f5 100644 --- a/swagger/api.spec.yaml +++ b/swagger/api.spec.yaml @@ -2058,22 +2058,22 @@ components: type: object anyOf: - properties: - conventional_staleness_delta: + conventional_time_to_stale: type: integer minimum: 1 - conventional_stale_warning_delta: + conventional_time_to_stale_warning: type: integer minimum: 1 - conventional_culling_delta: + conventional_time_to_delete: type: integer minimum: 1 - immutable_staleness_delta: + immutable_time_to_stale: type: integer minimum: 1 - immutable_stale_warning_delta: + immutable_time_to_stale_warning: type: integer minimum: 1 - immutable_culling_delta: + immutable_time_to_delete: type: integer minimum: 1 StalenessOutput: @@ -2086,17 +2086,17 @@ components: $ref: "#/components/schemas/StalenessId" org_id: $ref: "#/components/schemas/OrgId" - conventional_staleness_delta: + conventional_time_to_stale: type: integer - conventional_stale_warning_delta: + conventional_time_to_stale_warning: type: integer - conventional_culling_delta: + conventional_time_to_delete: type: integer - immutable_staleness_delta: + immutable_time_to_stale: type: integer - immutable_stale_warning_delta: + immutable_time_to_stale_warning: type: integer - immutable_culling_delta: + immutable_time_to_delete: type: integer created_at: description: A timestamp when the entry was created. diff --git a/swagger/openapi.json b/swagger/openapi.json index fe0a893a4..4a5611c58 100644 --- a/swagger/openapi.json +++ b/swagger/openapi.json @@ -3095,27 +3095,27 @@ "anyOf": [ { "properties": { - "conventional_staleness_delta": { + "conventional_time_to_stale": { "type": "integer", "minimum": 1 }, - "conventional_stale_warning_delta": { + "conventional_time_to_stale_warning": { "type": "integer", "minimum": 1 }, - "conventional_culling_delta": { + "conventional_time_to_delete": { "type": "integer", "minimum": 1 }, - "immutable_staleness_delta": { + "immutable_time_to_stale": { "type": "integer", "minimum": 1 }, - "immutable_stale_warning_delta": { + "immutable_time_to_stale_warning": { "type": "integer", "minimum": 1 }, - "immutable_culling_delta": { + "immutable_time_to_delete": { "type": "integer", "minimum": 1 } @@ -3134,22 +3134,22 @@ "org_id": { "$ref": "#/components/schemas/OrgId" }, - "conventional_staleness_delta": { + "conventional_time_to_stale": { "type": "integer" }, - "conventional_stale_warning_delta": { + "conventional_time_to_stale_warning": { "type": "integer" }, - "conventional_culling_delta": { + "conventional_time_to_delete": { "type": "integer" }, - "immutable_staleness_delta": { + "immutable_time_to_stale": { "type": "integer" }, - "immutable_stale_warning_delta": { + "immutable_time_to_stale_warning": { "type": "integer" }, - "immutable_culling_delta": { + "immutable_time_to_delete": { "type": "integer" }, "created_at": { diff --git a/tests/fixtures/db_fixtures.py b/tests/fixtures/db_fixtures.py index 266d9881a..ecedd8852 100644 --- a/tests/fixtures/db_fixtures.py +++ b/tests/fixtures/db_fixtures.py @@ -262,20 +262,20 @@ def _db_delete_assignment_rule(ar_id): @pytest.fixture(scope="function") def db_create_staleness_culling(flask_app): def _db_create_staleness_culling( - conventional_staleness_delta=None, - conventional_stale_warning_delta=None, - conventional_culling_delta=None, - immutable_staleness_delta=None, - immutable_stale_warning_delta=None, - immutable_culling_delta=None, + conventional_time_to_stale=None, + conventional_time_to_stale_warning=None, + conventional_time_to_delete=None, + immutable_time_to_stale=None, + immutable_time_to_stale_warning=None, + immutable_time_to_delete=None, ): staleness_culling = db_staleness_culling( - conventional_staleness_delta=conventional_staleness_delta, - conventional_stale_warning_delta=conventional_stale_warning_delta, - conventional_culling_delta=conventional_culling_delta, - immutable_staleness_delta=immutable_staleness_delta, - immutable_stale_warning_delta=immutable_stale_warning_delta, - immutable_culling_delta=immutable_culling_delta, + conventional_time_to_stale=conventional_time_to_stale, + conventional_time_to_stale_warning=conventional_time_to_stale_warning, + conventional_time_to_delete=conventional_time_to_delete, + immutable_time_to_stale=immutable_time_to_stale, + immutable_time_to_stale_warning=immutable_time_to_stale_warning, + immutable_time_to_delete=immutable_time_to_delete, ) db.session.add(staleness_culling) db.session.commit() diff --git a/tests/helpers/api_utils.py b/tests/helpers/api_utils.py index 5c2804554..a202beddd 100644 --- a/tests/helpers/api_utils.py +++ b/tests/helpers/api_utils.py @@ -158,12 +158,12 @@ ) _INPUT_DATA = { - "conventional_staleness_delta": 1, - "conventional_stale_warning_delta": 7, - "conventional_culling_delta": 14, - "immutable_staleness_delta": 7, - "immutable_stale_warning_delta": 120, - "immutable_culling_delta": 120, + "conventional_time_to_stale": 1, + "conventional_time_to_stale_warning": 7, + "conventional_time_to_delete": 14, + "immutable_time_to_stale": 7, + "immutable_time_to_stale_warning": 120, + "immutable_time_to_delete": 120, } diff --git a/tests/test_api_hosts_update.py b/tests/test_api_hosts_update.py index 56dd8b69e..5004bb662 100644 --- a/tests/test_api_hosts_update.py +++ b/tests/test_api_hosts_update.py @@ -436,12 +436,12 @@ def test_add_facts_to_multiple_culled_hosts( mock_datetime.side_effect = lambda *args, **kw: datetime(*args, **kw) db_create_staleness_culling( - conventional_staleness_delta=1, - conventional_stale_warning_delta=1, - conventional_culling_delta=1, - immutable_staleness_delta=1, - immutable_stale_warning_delta=1, - immutable_culling_delta=1, + conventional_time_to_stale=1, + conventional_time_to_stale_warning=1, + conventional_time_to_delete=1, + immutable_time_to_stale=1, + immutable_time_to_stale_warning=1, + immutable_time_to_delete=1, ) staleness_timestamps = get_staleness_timestamps() diff --git a/tests/test_api_staleness_create.py b/tests/test_api_staleness_create.py index 70bc318ca..ac6ebed87 100644 --- a/tests/test_api_staleness_create.py +++ b/tests/test_api_staleness_create.py @@ -4,12 +4,12 @@ from tests.helpers.api_utils import STALENESS_WRITE_PROHIBITED_RBAC_RESPONSE_FILES _INPUT_DATA = { - "conventional_staleness_delta": 1, - "conventional_stale_warning_delta": 7, - "conventional_culling_delta": 14, - "immutable_staleness_delta": 7, - "immutable_stale_warning_delta": 120, - "immutable_culling_delta": 120, + "conventional_time_to_stale": 1, + "conventional_time_to_stale_warning": 7, + "conventional_time_to_delete": 14, + "immutable_time_to_stale": 7, + "immutable_time_to_stale_warning": 120, + "immutable_time_to_delete": 120, } @@ -25,17 +25,17 @@ def test_create_staleness(api_create_staleness, db_get_staleness_culling): saved_org_id = response_data["org_id"] saved_data = db_get_staleness_culling(saved_org_id) - assert saved_data.conventional_staleness_delta == _INPUT_DATA["conventional_staleness_delta"] - assert saved_data.immutable_culling_delta == _INPUT_DATA["immutable_culling_delta"] - assert saved_data.conventional_culling_delta == _INPUT_DATA["conventional_culling_delta"] - assert saved_data.immutable_staleness_delta == _INPUT_DATA["immutable_staleness_delta"] - assert saved_data.immutable_stale_warning_delta == _INPUT_DATA["immutable_stale_warning_delta"] - assert saved_data.immutable_culling_delta == _INPUT_DATA["immutable_culling_delta"] + assert saved_data.conventional_time_to_stale == _INPUT_DATA["conventional_time_to_stale"] + assert saved_data.immutable_time_to_delete == _INPUT_DATA["immutable_time_to_delete"] + assert saved_data.conventional_time_to_delete == _INPUT_DATA["conventional_time_to_delete"] + assert saved_data.immutable_time_to_stale == _INPUT_DATA["immutable_time_to_stale"] + assert saved_data.immutable_time_to_stale_warning == _INPUT_DATA["immutable_time_to_stale_warning"] + assert saved_data.immutable_time_to_delete == _INPUT_DATA["immutable_time_to_delete"] def test_create_staleness_with_only_one_data(api_create_staleness, db_get_staleness_culling): input_data = { - "conventional_staleness_delta": 1, + "conventional_time_to_stale": 1, } response_status, response_data = api_create_staleness(input_data) assert_response_status(response_status, 201) @@ -43,12 +43,12 @@ def test_create_staleness_with_only_one_data(api_create_staleness, db_get_stalen saved_org_id = response_data["org_id"] saved_data = db_get_staleness_culling(saved_org_id) - assert saved_data.conventional_staleness_delta == input_data["conventional_staleness_delta"] - assert saved_data.conventional_stale_warning_delta == _days_to_seconds(7) - assert saved_data.conventional_culling_delta == _days_to_seconds(14) - assert saved_data.immutable_staleness_delta == _days_to_seconds(2) - assert saved_data.immutable_stale_warning_delta == _days_to_seconds(180) - assert saved_data.immutable_culling_delta == _days_to_seconds(730) + assert saved_data.conventional_time_to_stale == input_data["conventional_time_to_stale"] + assert saved_data.conventional_time_to_stale_warning == _days_to_seconds(7) + assert saved_data.conventional_time_to_delete == _days_to_seconds(14) + assert saved_data.immutable_time_to_stale == _days_to_seconds(2) + assert saved_data.immutable_time_to_stale_warning == _days_to_seconds(180) + assert saved_data.immutable_time_to_delete == _days_to_seconds(730) def test_create_same_staleness(api_create_staleness): diff --git a/tests/test_api_staleness_delete.py b/tests/test_api_staleness_delete.py index ee40a0b79..b94cec1d9 100644 --- a/tests/test_api_staleness_delete.py +++ b/tests/test_api_staleness_delete.py @@ -6,12 +6,12 @@ def test_delete_existing_staleness(db_create_staleness_culling, api_delete_staleness, db_get_staleness_culling): saved_staleness = db_create_staleness_culling( - conventional_staleness_delta=1, - conventional_stale_warning_delta=7, - conventional_culling_delta=14, - immutable_staleness_delta=7, - immutable_stale_warning_delta=120, - immutable_culling_delta=120, + conventional_time_to_stale=1, + conventional_time_to_stale_warning=7, + conventional_time_to_delete=14, + immutable_time_to_stale=7, + immutable_time_to_stale_warning=120, + immutable_time_to_delete=120, ) response_status, response_data = api_delete_staleness() @@ -39,12 +39,12 @@ def test_delete_staleness_rbac_allowed( get_rbac_permissions_mock.return_value = mock_rbac_response db_create_staleness_culling( - conventional_staleness_delta=1, - conventional_stale_warning_delta=7, - conventional_culling_delta=14, - immutable_staleness_delta=7, - immutable_stale_warning_delta=120, - immutable_culling_delta=120, + conventional_time_to_stale=1, + conventional_time_to_stale_warning=7, + conventional_time_to_delete=14, + immutable_time_to_stale=7, + immutable_time_to_stale_warning=120, + immutable_time_to_delete=120, ) response_status, _ = api_delete_staleness() diff --git a/tests/test_api_staleness_get.py b/tests/test_api_staleness_get.py index aa42d6e62..df2cf4483 100644 --- a/tests/test_api_staleness_get.py +++ b/tests/test_api_staleness_get.py @@ -9,31 +9,31 @@ def test_get_default_staleness(api_get): response_status, response_data = api_get(url) assert_response_status(response_status, 200) expected_result = { - "conventional_staleness_delta": 104400, - "conventional_stale_warning_delta": 604800, - "conventional_culling_delta": 1209600, - "immutable_staleness_delta": 172800, - "immutable_stale_warning_delta": 15552000, - "immutable_culling_delta": 63072000, + "conventional_time_to_stale": 104400, + "conventional_time_to_stale_warning": 604800, + "conventional_time_to_delete": 1209600, + "immutable_time_to_stale": 172800, + "immutable_time_to_stale_warning": 15552000, + "immutable_time_to_delete": 63072000, } - assert response_data["conventional_staleness_delta"] == expected_result["conventional_staleness_delta"] - assert response_data["conventional_stale_warning_delta"] == expected_result["conventional_stale_warning_delta"] - assert response_data["conventional_culling_delta"] == expected_result["conventional_culling_delta"] - assert response_data["immutable_staleness_delta"] == expected_result["immutable_staleness_delta"] - assert response_data["immutable_stale_warning_delta"] == expected_result["immutable_stale_warning_delta"] - assert response_data["immutable_culling_delta"] == expected_result["immutable_culling_delta"] + assert response_data["conventional_time_to_stale"] == expected_result["conventional_time_to_stale"] + assert response_data["conventional_time_to_stale_warning"] == expected_result["conventional_time_to_stale_warning"] + assert response_data["conventional_time_to_delete"] == expected_result["conventional_time_to_delete"] + assert response_data["immutable_time_to_stale"] == expected_result["immutable_time_to_stale"] + assert response_data["immutable_time_to_stale_warning"] == expected_result["immutable_time_to_stale_warning"] + assert response_data["immutable_time_to_delete"] == expected_result["immutable_time_to_delete"] def test_get_custom_staleness(api_create_staleness, api_get): created_response_status, _ = api_create_staleness(_INPUT_DATA) url = build_staleness_url() response_status, response_data = api_get(url) - assert response_data["conventional_staleness_delta"] == _INPUT_DATA["conventional_staleness_delta"] - assert response_data["conventional_stale_warning_delta"] == _INPUT_DATA["conventional_stale_warning_delta"] - assert response_data["conventional_culling_delta"] == _INPUT_DATA["conventional_culling_delta"] - assert response_data["immutable_staleness_delta"] == _INPUT_DATA["immutable_staleness_delta"] - assert response_data["immutable_stale_warning_delta"] == _INPUT_DATA["immutable_stale_warning_delta"] - assert response_data["immutable_culling_delta"] == _INPUT_DATA["immutable_culling_delta"] + assert response_data["conventional_time_to_stale"] == _INPUT_DATA["conventional_time_to_stale"] + assert response_data["conventional_time_to_stale_warning"] == _INPUT_DATA["conventional_time_to_stale_warning"] + assert response_data["conventional_time_to_delete"] == _INPUT_DATA["conventional_time_to_delete"] + assert response_data["immutable_time_to_stale"] == _INPUT_DATA["immutable_time_to_stale"] + assert response_data["immutable_time_to_stale_warning"] == _INPUT_DATA["immutable_time_to_stale_warning"] + assert response_data["immutable_time_to_delete"] == _INPUT_DATA["immutable_time_to_delete"] assert_response_status(response_status, 200) @@ -42,16 +42,16 @@ def test_get_sys_default_staleness(api_get): response_status, response_data = api_get(url) assert_response_status(response_status, 200) expected_result = { - "conventional_staleness_delta": 104400, - "conventional_stale_warning_delta": 604800, - "conventional_culling_delta": 1209600, - "immutable_staleness_delta": 172800, - "immutable_stale_warning_delta": 15552000, - "immutable_culling_delta": 63072000, + "conventional_time_to_stale": 104400, + "conventional_time_to_stale_warning": 604800, + "conventional_time_to_delete": 1209600, + "immutable_time_to_stale": 172800, + "immutable_time_to_stale_warning": 15552000, + "immutable_time_to_delete": 63072000, } - assert response_data["conventional_staleness_delta"] == expected_result["conventional_staleness_delta"] - assert response_data["conventional_stale_warning_delta"] == expected_result["conventional_stale_warning_delta"] - assert response_data["conventional_culling_delta"] == expected_result["conventional_culling_delta"] - assert response_data["immutable_staleness_delta"] == expected_result["immutable_staleness_delta"] - assert response_data["immutable_stale_warning_delta"] == expected_result["immutable_stale_warning_delta"] - assert response_data["immutable_culling_delta"] == expected_result["immutable_culling_delta"] + assert response_data["conventional_time_to_stale"] == expected_result["conventional_time_to_stale"] + assert response_data["conventional_time_to_stale_warning"] == expected_result["conventional_time_to_stale_warning"] + assert response_data["conventional_time_to_delete"] == expected_result["conventional_time_to_delete"] + assert response_data["immutable_time_to_stale"] == expected_result["immutable_time_to_stale"] + assert response_data["immutable_time_to_stale_warning"] == expected_result["immutable_time_to_stale_warning"] + assert response_data["immutable_time_to_delete"] == expected_result["immutable_time_to_delete"] diff --git a/tests/test_api_staleness_update.py b/tests/test_api_staleness_update.py index 317442576..69ca6ba0d 100644 --- a/tests/test_api_staleness_update.py +++ b/tests/test_api_staleness_update.py @@ -4,16 +4,16 @@ from tests.helpers.api_utils import STALENESS_WRITE_ALLOWED_RBAC_RESPONSE_FILES from tests.helpers.api_utils import STALENESS_WRITE_PROHIBITED_RBAC_RESPONSE_FILES -_INPUT_DATA = {"conventional_staleness_delta": 99} +_INPUT_DATA = {"conventional_time_to_stale": 99} def test_update_existing_record(api_patch, db_create_staleness_culling): - saved_staleness = db_create_staleness_culling(conventional_staleness_delta=1) + saved_staleness = db_create_staleness_culling(conventional_time_to_stale=1) url = build_staleness_url() response_status, response_data = api_patch(url, host_data=_INPUT_DATA) assert_response_status(response_status, 200) - assert saved_staleness.conventional_staleness_delta == 99 + assert saved_staleness.conventional_time_to_stale == 99 def test_update_non_existing_record(api_patch): @@ -24,13 +24,13 @@ def test_update_non_existing_record(api_patch): def test_update_with_wrong_data(api_patch): url = build_staleness_url() - response_status, response_data = api_patch(url, host_data={"conventional_staleness_delta": "9999"}) + response_status, response_data = api_patch(url, host_data={"conventional_time_to_stale": "9999"}) assert_response_status(response_status, 400) def test_update_staleness_rbac_allowed(subtests, mocker, api_patch, db_create_staleness_culling, enable_rbac): get_rbac_permissions_mock = mocker.patch("lib.middleware.get_rbac_permissions") - db_create_staleness_culling(conventional_staleness_delta=1) + db_create_staleness_culling(conventional_time_to_stale=1) for response_file in STALENESS_WRITE_ALLOWED_RBAC_RESPONSE_FILES: mock_rbac_response = create_mock_rbac_response(response_file) @@ -46,7 +46,7 @@ def test_update_staleness_rbac_allowed(subtests, mocker, api_patch, db_create_st def test_update_staleness_rbac_denied(subtests, mocker, api_patch, db_create_staleness_culling, enable_rbac): get_rbac_permissions_mock = mocker.patch("lib.middleware.get_rbac_permissions") - db_create_staleness_culling(conventional_staleness_delta=1) + db_create_staleness_culling(conventional_time_to_stale=1) for response_file in STALENESS_WRITE_PROHIBITED_RBAC_RESPONSE_FILES: mock_rbac_response = create_mock_rbac_response(response_file) diff --git a/tests/test_custom_staleness.py b/tests/test_custom_staleness.py index 0ea625425..ace90157c 100644 --- a/tests/test_custom_staleness.py +++ b/tests/test_custom_staleness.py @@ -7,39 +7,39 @@ CUSTOM_STALENESS_DELETE_ONLY_IMMUTABLE = { - "conventional_staleness_delta": 86400, - "conventional_stale_warning_delta": 604800, - "conventional_culling_delta": 1209600, - "immutable_staleness_delta": 172800, - "immutable_stale_warning_delta": 10368000, - "immutable_culling_delta": 1, + "conventional_time_to_stale": 86400, + "conventional_time_to_stale_warning": 604800, + "conventional_time_to_delete": 1209600, + "immutable_time_to_stale": 172800, + "immutable_time_to_stale_warning": 10368000, + "immutable_time_to_delete": 1, } CUSTOM_STALENESS_DELETE_ONLY_CONVENTIONAL = { - "conventional_staleness_delta": 86400, - "conventional_stale_warning_delta": 604800, - "conventional_culling_delta": 1, - "immutable_staleness_delta": 172800, - "immutable_stale_warning_delta": 10368000, - "immutable_culling_delta": 15552000, + "conventional_time_to_stale": 86400, + "conventional_time_to_stale_warning": 604800, + "conventional_time_to_delete": 1, + "immutable_time_to_stale": 172800, + "immutable_time_to_stale_warning": 10368000, + "immutable_time_to_delete": 15552000, } CUSTOM_STALENESS_DELETE_CONVENTIONAL_IMMUTABLE = { - "conventional_staleness_delta": 86400, - "conventional_stale_warning_delta": 604800, - "conventional_culling_delta": 1, - "immutable_staleness_delta": 172800, - "immutable_stale_warning_delta": 10368000, - "immutable_culling_delta": 1, + "conventional_time_to_stale": 86400, + "conventional_time_to_stale_warning": 604800, + "conventional_time_to_delete": 1, + "immutable_time_to_stale": 172800, + "immutable_time_to_stale_warning": 10368000, + "immutable_time_to_delete": 1, } CUSTOM_STALENESS_NO_HOSTS_TO_DELETE = { - "conventional_staleness_delta": 86400, - "conventional_stale_warning_delta": 604800, - "conventional_culling_delta": 1209600, - "immutable_staleness_delta": 172800, - "immutable_stale_warning_delta": 10368000, - "immutable_culling_delta": 15552000, + "conventional_time_to_stale": 86400, + "conventional_time_to_stale_warning": 604800, + "conventional_time_to_delete": 1209600, + "immutable_time_to_stale": 172800, + "immutable_time_to_stale_warning": 10368000, + "immutable_time_to_delete": 15552000, } diff --git a/tests/test_models.py b/tests/test_models.py index e017cf297..2f5132736 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -711,26 +711,26 @@ def test_create_default_staleness_culling(db_create_staleness_culling, db_get_st created_acc_st_cull = db_get_staleness_culling(acc_st_cull.org_id) assert created_acc_st_cull - assert created_acc_st_cull.conventional_staleness_delta == acc_st_cull.conventional_staleness_delta - assert created_acc_st_cull.conventional_stale_warning_delta == acc_st_cull.conventional_stale_warning_delta - assert created_acc_st_cull.conventional_culling_delta == acc_st_cull.conventional_culling_delta - assert created_acc_st_cull.immutable_staleness_delta == acc_st_cull.immutable_staleness_delta - assert created_acc_st_cull.immutable_stale_warning_delta == acc_st_cull.immutable_stale_warning_delta - assert created_acc_st_cull.immutable_culling_delta == acc_st_cull.immutable_culling_delta + assert created_acc_st_cull.conventional_time_to_stale == acc_st_cull.conventional_time_to_stale + assert created_acc_st_cull.conventional_time_to_stale_warning == acc_st_cull.conventional_time_to_stale_warning + assert created_acc_st_cull.conventional_time_to_delete == acc_st_cull.conventional_time_to_delete + assert created_acc_st_cull.immutable_time_to_stale == acc_st_cull.immutable_time_to_stale + assert created_acc_st_cull.immutable_time_to_stale_warning == acc_st_cull.immutable_time_to_stale_warning + assert created_acc_st_cull.immutable_time_to_delete == acc_st_cull.immutable_time_to_delete def test_create_staleness_culling(db_create_staleness_culling, db_get_staleness_culling): acc_st_cull = db_create_staleness_culling( - conventional_staleness_delta=2 * 86400, - conventional_stale_warning_delta=4 * 86400, - conventional_culling_delta=20 * 86400, + conventional_time_to_stale=2 * 86400, + conventional_time_to_stale_warning=4 * 86400, + conventional_time_to_delete=20 * 86400, ) created_acc_st_cull = db_get_staleness_culling(acc_st_cull.org_id) assert created_acc_st_cull - assert created_acc_st_cull.conventional_staleness_delta == acc_st_cull.conventional_staleness_delta - assert created_acc_st_cull.conventional_stale_warning_delta == acc_st_cull.conventional_stale_warning_delta - assert created_acc_st_cull.conventional_culling_delta == acc_st_cull.conventional_culling_delta + assert created_acc_st_cull.conventional_time_to_stale == acc_st_cull.conventional_time_to_stale + assert created_acc_st_cull.conventional_time_to_stale_warning == acc_st_cull.conventional_time_to_stale_warning + assert created_acc_st_cull.conventional_time_to_delete == acc_st_cull.conventional_time_to_delete def test_delete_staleness_culling(db_create_staleness_culling, db_delete_staleness_culling, db_get_staleness_culling):