Skip to content

Commit

Permalink
qa fix
Browse files Browse the repository at this point in the history
  • Loading branch information
a1fred committed Dec 2, 2021
1 parent a759e54 commit 65a1e1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
17 changes: 10 additions & 7 deletions carnival/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import typing
import sys

from colorama import Fore, Style, Back # type: ignore
from colorama import Fore as F, Style as S, Back as B # type: ignore

from carnival import Step
from carnival.role import Role
Expand Down Expand Up @@ -134,7 +134,7 @@ def validate(self) -> bool:
from carnival.cli import carnival_tasks_module
from carnival.tasks_loader import get_task_full_name
task_name = get_task_full_name(carnival_tasks_module, self.__class__)
print(f"Validating task {Style.BRIGHT}{Fore.BLUE}{task_name}{Fore.RESET}{Style.RESET_ALL}", end="", flush=True)
print(f"Validating task {S.BRIGHT}{F.BLUE}{task_name}{F.RESET}{S.RESET_ALL}", end="", flush=True)
errors: typing.List[str] = []

for hostrole in self.hostroles:
Expand All @@ -143,20 +143,20 @@ def validate(self) -> bool:
for step in self.get_steps():
try:
step.validate(c=c)
print(f"{Fore.GREEN}.{Fore.RESET}", end="", flush=True)
print(f"{F.GREEN}.{F.RESET}", end="", flush=True)
except StepValidationError as ex:
step_name = step.get_name()
errors.append(f"{task_name} -> {step_name} on {hostrole.host}: {Fore.RED}{ex}{Fore.RESET}")
errors.append(f"{task_name} -> {step_name} on {hostrole.host}: {F.RED}{ex}{F.RESET}")
print("{Fore.RED}e{Fore.RESET}", end="", flush=True)
del self.role

if errors:
print(f" {Fore.RED}{len(errors)} errors{Fore.RESET}")
print(f" {F.RED}{len(errors)} errors{F.RESET}")
for e in errors:
print(f" * {e}")
return False

print(f" {Style.BRIGHT}{Fore.GREEN}OK{Fore.RESET}{Style.RESET_ALL}")
print(f" {S.BRIGHT}{F.GREEN}OK{F.RESET}{S.RESET_ALL}")
return True

def run(self) -> None:
Expand All @@ -169,5 +169,8 @@ def run(self) -> None:
for step in self.get_steps():
task_name = get_task_full_name(carnival_tasks_module, self.__class__)
step_name = step.get_name()
print(f"{Back.YELLOW}💃💃💃{Back.BLUE} {hostrole.host}{Back.RESET}{Fore.RESET}> Running {Style.BRIGHT}{task_name}:{step_name}{Style.RESET_ALL}")
print(
f"{B.YELLOW}💃💃💃{B.BLUE} {hostrole.host}{B.RESET}{F.RESET}> "
f"Running {S.BRIGHT}{task_name}:{step_name}{S.RESET_ALL}"
)
step.run(c=c)
6 changes: 4 additions & 2 deletions carnival_tasks_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ class PackagesRole(Role):
packages = ['htop', "mc"]


my_server_ip = os.getenv("TESTSERVER_ADDR", "1.2.3.4")
my_server = SshHost(my_server_ip, ssh_user="root", roles=[PackagesRole, ])
my_server_ip = os.getenv("TESTSERVER_ADDR", "1.2.3.4") # Dynamic ip for testing
my_server = SshHost(my_server_ip, ssh_user="root")

PackagesRole(my_server) # Bind server to role


class CheckDiskSpace(TaskBase):
Expand Down

0 comments on commit 65a1e1b

Please sign in to comment.