Skip to content

Commit fe60e6b

Browse files
committed
fix: notify_failure triggered before foreman_heal runs
* Added foreman_heal run at the end of M&R * Better handling of boolean values on notifications blueprint fixes: #550 Change-Id: I281d54ac575cdc12529a05a819333745eeb0f7cc
1 parent ab573c5 commit fe60e6b

File tree

6 files changed

+15
-16
lines changed

6 files changed

+15
-16
lines changed

src/quads/cli/cli.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from quads.server.models import Assignment
2222
from quads.tools import reports
2323
from quads.tools.external.jira import Jira, JiraException
24-
from quads.tools.foreman_heal import main as foreman_heal
24+
from quads.tools.foreman_heal import rbac as foreman_heal
2525
from quads.tools.make_instackenv_json import main as regen_instack
2626
from quads.tools.move_and_rebuild import move_and_rebuild, switch_config
2727
from quads.tools.notify import main as notify
@@ -656,10 +656,10 @@ def action_extend(self):
656656

657657
if not check:
658658
data = {
659-
"one_day": "False",
660-
"three_days": "False",
661-
"five_days": "False",
662-
"seven_days": "False",
659+
"one_day": False,
660+
"three_days": False,
661+
"five_days": False,
662+
"seven_days": False,
663663
}
664664
try:
665665
self.quads.update_notification(schedules[0].assignment.notification.id, data)
@@ -1698,6 +1698,7 @@ def action_movehosts(self): # pragma: no cover
16981698
assignment.id,
16991699
{"provisioned": True, "validated": validate},
17001700
)
1701+
foreman_heal(self.logger)
17011702
except (
17021703
APIServerException,
17031704
APIBadRequest,
@@ -1818,7 +1819,6 @@ def action_cloudonly(self):
18181819
_hosts = self.quads.filter_hosts(host_kwargs)
18191820
if _hosts:
18201821
for schedule in sorted(schedules, key=lambda k: k.host.name):
1821-
# TODO: check data properties
18221822
if schedule.host.name in [host.name for host in _hosts]:
18231823
self.logger.info(schedule.host.name)
18241824
else:
@@ -1838,7 +1838,7 @@ def action_cloudonly(self):
18381838
if self.cli_args.get("filter"):
18391839
filter_args = self._filter_kwargs(self.cli_args.get("filter"))
18401840
host_kwargs.update(filter_args)
1841-
_host = self.quads.filter_hosts(host_kwargs)
1841+
_hosts = self.quads.filter_hosts(host_kwargs)
18421842
else:
18431843
_hosts = self.quads.get_hosts()
18441844
for host in sorted(_hosts, key=lambda k: k.name):

src/quads/server/blueprints/notifications.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def update_notification(notification_id: int) -> Response:
4646
update_fields = {}
4747
for attr in obj_attrs:
4848
value = data.get(attr.key)
49-
if value:
50-
if type(value) == str:
49+
if attr.key in data:
50+
if isinstance(value, str):
5151
if value.lower() in ["true", "false"]:
5252
value = eval(value.lower().capitalize())
5353
update_fields[attr.key] = value

src/quads/tools/foreman_heal.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
quads = QuadsApi(Config)
1717

1818

19-
def main(_logger=None):
19+
def rbac(_logger=None):
2020
global logger
2121
if _logger: # pragma: no cover
2222
logger = _logger
@@ -59,7 +59,7 @@ def main(_logger=None):
5959
if current_schedule:
6060

6161
logger.info(" Current Host Permissions:")
62-
for host, properties in cloud_hosts.items(): # pragma: no cover
62+
for host, _ in cloud_hosts.items(): # pragma: no cover
6363
logger.info(f" {host}")
6464

6565
match = [schedule.host.name for schedule in current_schedule if schedule.host.name == host]
@@ -78,7 +78,7 @@ def main(_logger=None):
7878
else:
7979
if cloud_hosts: # pragma: no cover
8080
logger.info(" No active schedule, removing pre-existing roles.")
81-
for host, properties in cloud_hosts.items():
81+
for host, _ in cloud_hosts.items():
8282
_host_id = loop.run_until_complete(foreman_admin.get_host_id(host))
8383
loop.run_until_complete(foreman_admin.put_element("hosts", _host_id, "owner_id", admin_id))
8484
logger.info(f"* Removed permission {host}")
@@ -87,4 +87,4 @@ def main(_logger=None):
8787

8888

8989
if __name__ == "__main__": # pragma: no cover
90-
main()
90+
rbac()

src/quads/tools/move_and_rebuild.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python3
22
import asyncio
33
import logging
4-
import os
54
from datetime import datetime
65
from time import sleep
76

src/quads/tools/validate_env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ async def post_network_test(self):
196196
}
197197
previous_schedule = quads.get_schedules(data=data)
198198
if previous_schedule:
199-
previous_cloud = previous_schedule[0].cloud.name
199+
previous_cloud = previous_schedule[0].assignment.cloud.name
200200
result = switch_config(host.name, previous_cloud, host.cloud.name)
201201
if result:
202202
try:

tests/tools/test_foreman_heal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22

33
from quads.config import Config
4-
from quads.tools.foreman_heal import main as foreman_heal_main
4+
from quads.tools.foreman_heal import rbac as foreman_heal_main
55
from tests.tools.test_base import TestBase
66

77

0 commit comments

Comments
 (0)