Skip to content

Commit

Permalink
feat(LOGS): standardize all log/console messages
Browse files Browse the repository at this point in the history
  • Loading branch information
niall-byrne committed Feb 16, 2022
1 parent 48749f3 commit 655b2a3
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion mac_maker/ansible_controller/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setup(self) -> None:
"""Configure the environment for the current Ansible job."""

self.log.debug(
"Environment: configuring Ansible runtime environment variables..."
"Environment: Configuring Ansible runtime environment variables."
)

self._combine_env_with_state(config.ENV_ANSIBLE_ROLES_PATH, 'roles_path')
Expand Down
2 changes: 1 addition & 1 deletion mac_maker/ansible_controller/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ def write_inventory_file(self) -> None:
config.ANSIBLE_INVENTORY_CONTENT, self.state['inventory']
)
self.log.debug(
"InventoryFile: inventory has been written to %s",
"InventoryFile: Inventory has been written to %s.",
self.state['inventory'],
)
5 changes: 2 additions & 3 deletions mac_maker/ansible_controller/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def spawn(self, command: str) -> None:
:param command: The Ansible CLI Command to spawn.
"""

self.log.debug("AnsibleProcess: Preparing to Fork for Ansible Process")
self.log.debug("AnsibleProcess: Preparing to Fork for Ansible Process.")
pid = os.fork()
if pid == 0:
self._forked_process(command)
Expand All @@ -47,7 +47,7 @@ def spawn(self, command: str) -> None:
def _forked_process(self, command: str) -> None:
try:
self.log.debug(
"AnsibleProcess: Forked process is now executing: %s",
"AnsibleProcess: Forked process is now executing: %s.",
command,
)

Expand All @@ -66,7 +66,6 @@ def _forked_process(self, command: str) -> None:
raise ClickShellUncleanExit() # pylint: disable=raise-missing-from
self._perform_clean_exit()
except KeyboardInterrupt:
self.log.error("AnsibleProcess: Keyboard Interrupt Intercepted.")
raise ClickShellUncleanExit() from KeyboardInterrupt

def _environment(self) -> None:
Expand Down
12 changes: 7 additions & 5 deletions mac_maker/ansible_controller/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _construct_galaxy_roles_command(self) -> str:
requirements_file = self.state['galaxy_requirements_file']
role_path = self.state['roles_path'][0]
self.log.debug(
"AnsibleRunner: Reading Profile Requirements from: %s",
"AnsibleRunner: Reading Profile requirements from: %s.",
requirements_file,
)
command = (
Expand All @@ -50,7 +50,7 @@ def _construct_galaxy_col_command(self) -> str:
requirements_file = self.state['galaxy_requirements_file']
col_path = self.state['collections_path'][0]
self.log.debug(
"AnsibleRunner: Reading Profile Requirements from: %s",
"AnsibleRunner: Reading Profile requirements from: %s.",
requirements_file,
)
command = (
Expand All @@ -61,7 +61,7 @@ def _construct_galaxy_col_command(self) -> str:

def _construct_ansible_playbook_command(self) -> str:

self.log.debug("AnsibleRunner: Invoking Ansible")
self.log.debug("AnsibleRunner: Invoking Ansible.")
command = (
f"ansible-playbook {self.state['playbook']}"
f" -i {self.state['inventory']}"
Expand All @@ -83,7 +83,8 @@ def _do_install_galaxy_roles(self, galaxy_command: str) -> None:
click.echo(config.ANSIBLE_ROLES_MESSAGE)
controller.spawn(galaxy_command)
self.log.debug(
"AnsibleRunner: Profile Galaxy Roles have been installed to: %s",
"AnsibleRunner: Profile Ansible Galaxy roles have been "
"installed to: %s.",
self.state['roles_path'][0],
)

Expand All @@ -97,7 +98,8 @@ def _do_install_galaxy_col(self, galaxy_command: str) -> None:
click.echo(config.ANSIBLE_COLLECTIONS_MESSAGE)
controller.spawn(galaxy_command)
self.log.debug(
"AnsibleRunner: Profile Galaxy Collections have been installed to: %s",
"AnsibleRunner: Profile Ansible Galaxy collections have been "
"installed to: %s.",
self.state['collections_path'][0],
)

Expand Down
2 changes: 1 addition & 1 deletion mac_maker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
ANSIBLE_JOB_SPEC_READ_MESSAGE = "--- Job Spec Loaded ---"
ANSIBLE_RETRIEVE_MESSAGE = "--- Retrieving Remote Profile ---"
ANSIBLE_ROLES_MESSAGE = "--- Installing Profile Roles ---"
ANSIBLE_COLLECTIONS_MESSAGE = "--- Installing Collection Roles ---"
ANSIBLE_COLLECTIONS_MESSAGE = "--- Installing Profile Collections ---"

GITHUB_HTTP_REGEX = r'http[s]?://github.com/(?P<org>.+)/(?P<repo>[^.]+)(\.git)?'
GITHUB_SSH_REGEX = r'git@github.com:(?P<org>.+)/(?P<repo>[^.]+)(\.git)?'
Expand Down
6 changes: 4 additions & 2 deletions mac_maker/utilities/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ def get_job_spec_data(
:param spec_file_location: The path to the Job Spec file that will be read.
:returns: The Job Spec file contents, and it's location on the filesystem.
"""
self.log.debug('JobSpecExtractor: Reading state from from file system.')
self.log.debug(
'JobSpecExtractor: Reading runtime state from a Job Spec file.'
)
spec_file_content = self.state_manager.state_rehydrate(spec_file_location)
validator = SpecFileValidator(spec_file_content)
validator.validate_spec_file()
self.log.debug('JobSpecExtractor: State has been built.')
self.log.debug('JobSpecExtractor: Runtime state has been built.')
return TypeSpecFileData(
spec_file_content=spec_file_content,
spec_file_location=spec_file_location
Expand Down
6 changes: 3 additions & 3 deletions mac_maker/utilities/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def state_generate(self, filesystem: FileSystem) -> TypeState:
:param filesystem: The FileSystem object you are using.
:returns: The generated runtime state object.
"""
self.log.debug("State: Generating New Ansible State Content")
self.log.debug("State: Generating new Ansible runtime state.")
return TypeState(
workspace_root_path=str(filesystem.get_work_space_root().resolve()),
profile_data_path=str(filesystem.get_profile_data_path().resolve()),
Expand All @@ -54,7 +54,7 @@ def state_dehydrate(
:param state_data: The Python object that represents the runtime state.
:param spec_file_path: The path to the Job Spec file that will be written.
"""
self.log.debug("State: saving State as Spec File")
self.log.debug("State: saving runtime state as a Job Spec file.")
self.write_json_file(state_data, spec_file_path)

def state_rehydrate(self, spec_file_path: Union[Path, str]) -> TypeState:
Expand All @@ -64,6 +64,6 @@ def state_rehydrate(self, spec_file_path: Union[Path, str]) -> TypeState:
:returns: The runtime state object.
"""

self.log.debug("State: loading State from Spec File")
self.log.debug("State: loading runtime state from Job Spec file.")
state_data = self.load_json_file(spec_file_path)
return cast(TypeState, state_data)
2 changes: 1 addition & 1 deletion mac_maker/utilities/validation/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ def validate_spec_file(self) -> None:

errors = self._validate_with_schema(self.schema)
if errors:
self.log.error('JobSpecValidator: The loaded job spec file is invalid!')
self.log.error('JobSpecValidator: The loaded Job Spec file is invalid!')
formatted_errors = pprint.pformat(errors)
raise SpecFileValidationException(formatted_errors)

0 comments on commit 655b2a3

Please sign in to comment.