Skip to content

Commit

Permalink
feat: validation for hosts added to already validated cloud
Browse files Browse the repository at this point in the history
added logic to reset cloud object validation status to false if new
hosts are added to ongoing assignment and to only validate over the
new hosts.

Change-Id: Idc6473147be3e362beee313d8f442a9f8a430224
  • Loading branch information
grafuls committed Dec 13, 2019
1 parent 425ae92 commit cc5737d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bin/quads-cli
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def main(_args):
if not _args.dryrun:
try:
if _args.movecommand == default_move_command:
fn = functools.partial(move_and_rebuild, host, current, new, semaphore, cloud.wipe)
fn = functools.partial(move_and_rebuild, host, new, semaphore, cloud.wipe)
tasks.append(fn)
switch_tasks.append(functools.partial(switch_config, host, current, new))
else:
Expand Down
8 changes: 8 additions & 0 deletions quads/api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,14 @@ def POST(self, **data):
result.append(
"Added schedule for %s on %s" % (data["host"], cloud_obj.name)
)
if self.model.current_schedule(cloud=cloud_obj) and cloud_obj.validated:
cloud_obj.update(validated=False)
notification_obj = model.Notification.objects(
cloud=cloud_obj,
ticket=cloud_obj.ticket
).first()
if notification_obj:
notification_obj.update(success=False)
else:
result.append("Host is not available during that time frame")

Expand Down
1 change: 1 addition & 0 deletions quads/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class Host(Document):
interfaces = ListField(EmbeddedDocumentField(Interface))
nullos = BooleanField(default=True)
build = BooleanField(default=False)
validated = BooleanField(default=False)
last_build = DateTimeField()
meta = {
'indexes': [
Expand Down
4 changes: 2 additions & 2 deletions quads/tools/move_and_rebuild_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async def ipmi_reset(host, semaphore):
await execute_ipmi(host, ipmi_on, semaphore)


async def move_and_rebuild(host, old_cloud, new_cloud, semaphore, rebuild=False, loop=None):
async def move_and_rebuild(host, new_cloud, semaphore, rebuild=False, loop=None):
build_start = datetime.now()
logger.debug("Moving and rebuilding host: %s" % host)

Expand Down Expand Up @@ -228,5 +228,5 @@ async def move_and_rebuild(host, old_cloud, new_cloud, semaphore, rebuild=False,
schedule.save()

logger.debug("Updating host: %s")
_host_obj.update(cloud=_new_cloud_obj, build=False, last_build=datetime.now())
_host_obj.update(cloud=_new_cloud_obj, build=False, last_build=datetime.now(), validated=False)
return True
4 changes: 3 additions & 1 deletion quads/tools/validate_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Validator(object):
def __init__(self, cloud):
self.cloud = cloud
self.report = ""
self.hosts = Host.objects(cloud=self.cloud)
self.hosts = Host.objects(cloud=self.cloud, validated=False)
self.hosts = [host for host in self.hosts if Schedule.current_schedule(host=host)]

def notify_failure(self):
Expand Down Expand Up @@ -186,6 +186,8 @@ def validate_env(self):
self.notify_success()
notification_obj.update(success=True, fail=False)

for host in self.hosts:
host.update(validated=True)
self.cloud.update(validated=True)

if failed and not notification_obj.fail:
Expand Down

0 comments on commit cc5737d

Please sign in to comment.