Skip to content

Commit

Permalink
on expire, if mail could not be sent, delay vm deletion. Record first…
Browse files Browse the repository at this point in the history
… mail timestamp
  • Loading branch information
osallou committed May 11, 2022
1 parent 50f615e commit 09ca86b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
uses: osallou/rpmchecker-action@master
env:
EXTRA_1: epel-release
EXTRA_2: centos-release-openstack-stein
EXTRA_2: centos-release-openstack-ussuri
with:
path-to-rpm: 'packages/centos'
- name: show rpmversion
Expand Down
16 changes: 15 additions & 1 deletion os_vm_expire/cmd/cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def check(started_at):
res = send_email(entity, token, delete=False)
if res:
entity.notified = True
entity.notified_time = now
try:
entity.save()
repositories.commit()
Expand All @@ -264,7 +265,20 @@ def check(started_at):
except Exception as e:
LOG.exception("expiration save error: " + str(e))
repositories.rollback()
elif entity.expire < now:
elif entity.expire < now and entity.notified_last: # expired and last notification send at least notify_before_days days before
mintime = (conf_cleaner.notify_before_days * 3600 * 24)
if not entity.notified_time and entity.notified:
# backward compat, if notif time not set and notif already sent, set to now()
entity.notified_time = now
try:
entity.save()
repositories.commit()
except Exception as e:
LOG.exception("expiration save error: " + str(e))
repositories.rollback()
if (now - entity.notified_time) < mintime:
LOG.debug("Last expiration notification %s sent before %d days" % (entity.id, mintime))
continue
# delete
LOG.debug("Delete VM %s" % (entity.id))
res = delete_vm(entity.instance_id, entity.project_id, token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def upgrade():
sa.Column('expire', sa.Integer, index=False, nullable=False),
sa.Column('notified', sa.Boolean, index=False, nullable=False),
sa.Column('notified_last', sa.Boolean, index=False, nullable=False),
sa.Column('notified_time', sa.Integer, index=False, nullable=True),
sa.Column('instance_name', sa.String(255), index=False, nullable=True),
sa.PrimaryKeyConstraint('id')
)
5 changes: 5 additions & 0 deletions os_vm_expire/model/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ class VmExpire(BASE, ModelBase):
notified_last = sa.Column(
sa.Boolean, index=False,
nullable=False)
notified_time = sa.Column(
sa.Integer, index=False,
nullable=True
)
instance_name = sa.Column(
sa.String(255), index=False,
nullable=True)
Expand All @@ -222,6 +226,7 @@ def _do_extra_dict_fields(self):
'expire': self.expire,
'notified': self.notified,
'notified_last': self.notified_last,
'notified_time': self.notified_time,
'user_id': self.user_id,
'instance_name': self.instance_name
}
Expand Down
4 changes: 2 additions & 2 deletions packages/package.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e

git --help 1>/dev/null && pip -h 1>/dev/null && virtualenv -h 1>/dev/null
git --help 1>/dev/null && pip -h 1>/dev/null && python3 -V 1>/dev/null

# the temp directory used, within $DIR
# omit the -p parameter to create a temporal directory in the default location
Expand Down Expand Up @@ -39,7 +39,7 @@ else
fi
git checkout tags/${version}

virtualenv venv
python3 -mvenv venv
. venv/bin/activate
pip install reno
reno report > CHANGELOG
Expand Down

0 comments on commit 09ca86b

Please sign in to comment.