Skip to content
This repository has been archived by the owner on Jan 19, 2018. It is now read-only.

Commit

Permalink
logging: add cockpit logging output
Browse files Browse the repository at this point in the history
Add in messages that the cockpit UI is concerned with.
Also remove old print* functions from utils as they are
no longer needed.

Fixes #432
  • Loading branch information
dustymabe committed Feb 19, 2016
1 parent 2412bc8 commit f909aab
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 20 deletions.
7 changes: 7 additions & 0 deletions atomicapp/nulecule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from atomicapp.constants import (APP_ENT_PATH,
EXTERNAL_APP_DIR,
GLOBAL_CONF,
LOGGER_COCKPIT,
LOGGER_DEFAULT,
MAIN_FILE,
RESOURCE_KEY,
Expand All @@ -28,6 +29,7 @@

from jsonpointer import resolve_pointer, set_pointer, JsonPointerException

cockpitlogger = logging.getLogger(LOGGER_COCKPIT)
logger = logging.getLogger(LOGGER_DEFAULT)


Expand Down Expand Up @@ -101,6 +103,7 @@ def unpack(cls, image, dest, config=None, namespace=GLOBAL_CONF,
docker_handler = DockerHandler(dryrun=dryrun)
docker_handler.pull(image)
docker_handler.extract(image, APP_ENT_PATH, dest, update)
cockpitlogger.info("All dependencies installed successfully.")
return cls.load_from_path(
dest, config=config, namespace=namespace, nodeps=nodeps,
dryrun=dryrun, update=update)
Expand Down Expand Up @@ -160,6 +163,7 @@ def run(self, provider_key=None, dryrun=False):
# Process components
for component in self.components:
component.run(provider_key, dryrun)
cockpitlogger.info("Component %s installed successfully" % provider_key)

def stop(self, provider_key=None, dryrun=False):
"""
Expand Down Expand Up @@ -272,6 +276,7 @@ def load(self, nodeps=False, dryrun=False):
"""
Load external application of the Nulecule component.
"""
cockpitlogger.info("Loading app %s ." % self.name)
if self.source:
if nodeps:
logger.info(
Expand All @@ -283,6 +288,7 @@ def run(self, provider_key, dryrun=False):
"""
Run the Nulecule component with the specified provider,
"""
cockpitlogger.info("Deploying component %s ..." % self.name)
if self._app:
self._app.run(provider_key, dryrun)
return
Expand Down Expand Up @@ -347,6 +353,7 @@ def load_external_application(self, dryrun=False, update=False):
update=update
)
self._app = nulecule
cockpitlogger.info("Copied app successfully.")

@property
def components(self):
Expand Down
6 changes: 6 additions & 0 deletions atomicapp/nulecule/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import logging

from atomicapp.constants import (APP_ENT_PATH,
LOGGER_COCKPIT,
LOGGER_DEFAULT,
MAIN_FILE)
from atomicapp.utils import Utils
from atomicapp.nulecule.exceptions import NuleculeException

cockpitlogger = logging.getLogger(LOGGER_COCKPIT)
logger = logging.getLogger(LOGGER_DEFAULT)


Expand Down Expand Up @@ -48,6 +50,7 @@ def pull(self, image, update=False):
"""
if not self.is_image_present(image) or update:
logger.info('Pulling Docker image: %s' % image)
cockpitlogger.info('Pulling Docker image: %s' % image)
pull_cmd = [self.docker_cli, 'pull', image]
logger.debug(' '.join(pull_cmd))
else:
Expand All @@ -59,6 +62,8 @@ def pull(self, image, update=False):
elif subprocess.call(pull_cmd) != 0:
raise Exception("Could not pull Docker image %s" % image)

cockpitlogger.info('Skipping pulling Docker image: %s' % image)

def extract(self, image, source, dest, update=False):
"""
Extracts content from a directory in a Docker image to specified
Expand Down Expand Up @@ -110,6 +115,7 @@ def extract(self, image, source, dest, update=False):
if os.path.exists(mainfile):
existing_id = Utils.getAppId(mainfile)
new_id = Utils.getAppId(tmpmainfile)
cockpitlogger.info("Loading app_id %s ." % new_id)
if existing_id != new_id:
raise NuleculeException(
"Existing app (%s) and requested app (%s) differ" %
Expand Down
6 changes: 6 additions & 0 deletions atomicapp/nulecule/lib.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# -*- coding: utf-8 -*-
import logging

from atomicapp.constants import (GLOBAL_CONF,
LOGGER_COCKPIT,
NAME_KEY,
DEFAULTNAME_KEY,
PROVIDER_KEY)
from atomicapp.utils import Utils
from atomicapp.plugin import Plugin

cockpitlogger = logging.getLogger(LOGGER_COCKPIT)


class NuleculeBase(object):

Expand Down Expand Up @@ -44,6 +49,7 @@ def load_config(self, config, ask=False, skip_asking=False):
config.get(GLOBAL_CONF, {}).get(param[NAME_KEY])
if value is None and (ask or (
not skip_asking and param.get(DEFAULTNAME_KEY) is None)):
cockpitlogger.info("%s is missing in answers.conf." % param[NAME_KEY])
value = Utils.askFor(param[NAME_KEY], param)
elif value is None:
value = param.get(DEFAULTNAME_KEY)
Expand Down
4 changes: 4 additions & 0 deletions atomicapp/nulecule/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
ANSWERS_FILE_SAMPLE,
ANSWERS_RUNTIME_FILE,
DEFAULT_ANSWERS,
LOGGER_COCKPIT,
LOGGER_DEFAULT,
MAIN_FILE,
PROVIDER_KEY)
from atomicapp.nulecule.base import Nulecule
from atomicapp.nulecule.exceptions import NuleculeException
from atomicapp.utils import Utils

cockpitlogger = logging.getLogger(LOGGER_COCKPIT)
logger = logging.getLogger(LOGGER_DEFAULT)


Expand Down Expand Up @@ -192,6 +194,8 @@ def fetch(self, nodeps=False, update=False, dryrun=False,
os.path.join(self.app_path, ANSWERS_FILE_SAMPLE),
runtime_answers, answers_format)

cockpitlogger.info("Install Successful.")

def run(self, cli_provider, answers_output, ask,
answers_format=ANSWERS_FILE_SAMPLE_FORMAT, **kwargs):
"""
Expand Down
8 changes: 5 additions & 3 deletions atomicapp/providers/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import os
from string import Template

from atomicapp.constants import LOGGER_DEFAULT
from atomicapp.constants import (LOGGER_COCKPIT,
LOGGER_DEFAULT)
from atomicapp.plugin import Provider, ProviderFailedException
from atomicapp.utils import printErrorStatus, Utils
from atomicapp.utils import Utils

cockpitlogger = logging.getLogger(LOGGER_COCKPIT)
logger = logging.getLogger(LOGGER_DEFAULT)


Expand Down Expand Up @@ -124,7 +126,7 @@ def process_k8s_artifacts(self):
except Exception:
msg = "Error processing %s artifcats, Error:" % os.path.join(
self.path, artifact)
printErrorStatus(msg)
cockpitlogger.error(msg)
raise
if "kind" in data:
self.k8s_manifests.append((data["kind"].lower(), artifact))
Expand Down
9 changes: 5 additions & 4 deletions atomicapp/providers/marathon.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
import urlparse
import logging
import os
from atomicapp.constants import LOGGER_DEFAULT
from atomicapp.constants import (LOGGER_COCKPIT,
LOGGER_DEFAULT)
from atomicapp.plugin import Provider, ProviderFailedException
from atomicapp.utils import printErrorStatus
from atomicapp.utils import Utils
from atomicapp.constants import PROVIDER_API_KEY

cockpitlogger = logging.getLogger(LOGGER_COCKPIT)
logger = logging.getLogger(LOGGER_DEFAULT)


Expand Down Expand Up @@ -116,10 +117,10 @@ def _process_artifacts(self):
# every marathon app has to have id. 'id' key is also used for showing messages
if "id" not in data.keys():
msg = "Error processing %s artifact. There is no id" % artifact
printErrorStatus(msg)
cockpitlogger.error(msg)
raise ProviderFailedException(msg)
except anymarkup.AnyMarkupError, e:
msg = "Error processing artifact - %s" % e
printErrorStatus(msg)
cockpitlogger.error(msg)
raise ProviderFailedException(msg)
self.marathon_artifacts.append(data)
16 changes: 3 additions & 13 deletions atomicapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,19 @@
CACHE_DIR,
EXTERNAL_APP_DIR,
HOST_DIR,
LOGGER_COCKPIT,
LOGGER_DEFAULT,
WORKDIR)

__all__ = ('Utils')

cockpitlogger = logging.getLogger(LOGGER_COCKPIT)
logger = logging.getLogger(LOGGER_DEFAULT)


class AtomicAppUtilsException(Exception):
pass

# Following Methods(printStatus, printErrorStatus)
# are required for Cockpit or thirdparty management tool integration
# DONOT change the atomicapp.status.* prefix in the logger method.


def printStatus(message):
logger.info("atomicapp.status.info.message=" + str(message))


def printErrorStatus(message):
logger.info("atomicapp.status.error.message=" + str(message))


def find_binary(executable, path=None):
"""Tries to find 'executable' in the directories listed in 'path'.
Expand Down Expand Up @@ -271,7 +261,7 @@ def run_cmd(cmd, checkexitcode=True, stdin=None):
# we were asked not to.
if checkexitcode:
if ec != 0:
printErrorStatus("cmd failed: %s" % str(cmd)) # For cockpit
cockpitlogger.error("cmd failed: %s" % str(cmd))
raise AtomicAppUtilsException(
"cmd: %s failed: \n%s" % (str(cmd), stderr))

Expand Down

0 comments on commit f909aab

Please sign in to comment.