DebugMixin added
Change-Id: Ic970a5375fb7462afd5b88d9e369ecf1626df125
This commit is contained in:
parent
9320c3a8f3
commit
080e782b3d
|
@ -0,0 +1,7 @@
|
|||
from cliff import command
|
||||
|
||||
from fuel_dev_tools import debug
|
||||
|
||||
|
||||
class BaseCommand(debug.DebugMixin, command.Command):
|
||||
pass
|
|
@ -0,0 +1,12 @@
|
|||
import six
|
||||
|
||||
|
||||
class DebugMixin(object):
|
||||
def __init__(self, app, parsed_args):
|
||||
super(DebugMixin, self).__init__(app, parsed_args)
|
||||
|
||||
self._debug = getattr(parsed_args, 'debug', False)
|
||||
|
||||
def print_debug(self, msg):
|
||||
if self._debug:
|
||||
six.print_(msg)
|
|
@ -17,8 +17,8 @@ import logging
|
|||
import os
|
||||
import six
|
||||
|
||||
from cliff import command
|
||||
|
||||
from fuel_dev_tools import command
|
||||
from fuel_dev_tools import exc
|
||||
from fuel_dev_tools import rsync
|
||||
from fuel_dev_tools import ssh
|
||||
|
@ -27,9 +27,6 @@ from fuel_dev_tools import ssh
|
|||
DOCKER_CONTAINER_PATH = '/var/lib/docker/containers/'
|
||||
DOCKER_DEVICEMAPPER_PATH = '/var/lib/docker/devicemapper/mnt/'
|
||||
|
||||
# TODO(pkaminski)
|
||||
print_verbose = six.print_
|
||||
|
||||
|
||||
class DockerMixin(object):
|
||||
container = None
|
||||
|
@ -73,17 +70,17 @@ class DockerMixin(object):
|
|||
self.container
|
||||
).decode('utf-8')
|
||||
|
||||
print_verbose('FOUND CONTAINERS: %r' % up)
|
||||
self.print_debug('FOUND CONTAINERS: %r' % up)
|
||||
|
||||
if not up and get_exited:
|
||||
print_verbose('Container not Up, trying Exited')
|
||||
self.print_debug('Container not Up, trying Exited')
|
||||
|
||||
up = self.ssh_command(
|
||||
'docker ps -a | grep -i %s | grep Exited | cut -f 1 -d " "' %
|
||||
self.container
|
||||
).decode('utf-8')
|
||||
|
||||
print_verbose('FOUND CONTAINERS: %r' % up)
|
||||
self.print_debug('FOUND CONTAINERS: %r' % up)
|
||||
|
||||
if not up:
|
||||
raise exc.DockerError(
|
||||
|
@ -124,39 +121,39 @@ class DockerMixin(object):
|
|||
'docker restart %s' % self.get_docker_id()
|
||||
)
|
||||
|
||||
print_verbose(result)
|
||||
self.print_debug(result)
|
||||
|
||||
def start_container(self):
|
||||
result = self.ssh_command(
|
||||
'docker start %s' % self.get_docker_id(get_exited=True)
|
||||
)
|
||||
|
||||
print_verbose(result)
|
||||
self.print_debug(result)
|
||||
|
||||
def stop_container(self):
|
||||
result = self.ssh_command(
|
||||
'docker stop %s' % self.get_docker_id()
|
||||
)
|
||||
|
||||
print_verbose(result)
|
||||
self.print_debug(result)
|
||||
|
||||
|
||||
class IdCommand(DockerMixin, ssh.SSHMixin, command.Command):
|
||||
class IdCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
def take_action(self, parsed_args):
|
||||
six.print_(self.get_docker_id(get_exited=True))
|
||||
|
||||
|
||||
class ConfigCommand(DockerMixin, ssh.SSHMixin, command.Command):
|
||||
class ConfigCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
def take_action(self, parsed_args):
|
||||
six.print_(json.dumps(self.get_container_config(), indent=2))
|
||||
|
||||
|
||||
class DirCommand(DockerMixin, ssh.SSHMixin, command.Command):
|
||||
class DirCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
def take_action(self, parsed_args):
|
||||
six.print_(self.get_container_directory())
|
||||
|
||||
|
||||
class LogCommand(DockerMixin, ssh.SSHMixin, command.Command):
|
||||
class LogCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
def get_log_directory(self):
|
||||
raise NotImplementedError('No log directory for this command')
|
||||
|
||||
|
@ -180,15 +177,15 @@ class LogCommand(DockerMixin, ssh.SSHMixin, command.Command):
|
|||
)
|
||||
|
||||
|
||||
class RestartCommand(DockerMixin, ssh.SSHMixin, command.Command):
|
||||
class RestartCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
def take_action(self, parsed_args):
|
||||
self.restart_container()
|
||||
|
||||
|
||||
class RsyncCommand(rsync.RsyncMixin,
|
||||
DockerMixin,
|
||||
class RsyncCommand(DockerMixin,
|
||||
rsync.RsyncMixin,
|
||||
ssh.SSHMixin,
|
||||
command.Command):
|
||||
command.BaseCommand):
|
||||
def pre_sync(self, parsed_args):
|
||||
pass
|
||||
|
||||
|
@ -234,7 +231,7 @@ class RsyncCommand(rsync.RsyncMixin,
|
|||
self.post_sync(parsed_args)
|
||||
|
||||
|
||||
class ShellCommand(DockerMixin, ssh.SSHMixin, command.Command):
|
||||
class ShellCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
default_command = None
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -272,17 +269,17 @@ class ShellCommand(DockerMixin, ssh.SSHMixin, command.Command):
|
|||
return self.ssh_command_interactive(self.container_command(command))
|
||||
|
||||
|
||||
class StartCommand(DockerMixin, ssh.SSHMixin, command.Command):
|
||||
class StartCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
def take_action(self, parsed_args):
|
||||
self.start_container()
|
||||
|
||||
|
||||
class StopCommand(DockerMixin, ssh.SSHMixin, command.Command):
|
||||
class StopCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
def take_action(self, parsed_args):
|
||||
self.stop_container()
|
||||
|
||||
|
||||
class TailCommand(DockerMixin, ssh.SSHMixin, command.Command):
|
||||
class TailCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
def get_log_directory(self):
|
||||
raise NotImplementedError('No log directory for this command')
|
||||
|
||||
|
@ -304,7 +301,7 @@ class TailCommand(DockerMixin, ssh.SSHMixin, command.Command):
|
|||
)
|
||||
|
||||
|
||||
class VolumesCommand(DockerMixin, ssh.SSHMixin, command.Command):
|
||||
class VolumesCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
def take_action(self, parsed_args):
|
||||
six.print_(
|
||||
json.dumps(
|
||||
|
|
|
@ -91,7 +91,7 @@ class Rsync(DockerAstuteMixin, docker.RsyncCommand, docker.ShellCommand):
|
|||
cmd
|
||||
], shell=True)
|
||||
|
||||
six.print_(result)
|
||||
self.print_debug(result)
|
||||
except subprocess.CalledProcessError as e:
|
||||
six.print_('GEM BUILD ERROR')
|
||||
six.print_(e.output)
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
# under the License.
|
||||
|
||||
import os
|
||||
import six
|
||||
|
||||
from fabric import api as fabric_api
|
||||
|
||||
|
@ -63,7 +62,7 @@ class Rsync(DockerNginxMixin, docker.RsyncCommand):
|
|||
def build_gulp_static(self, source_dir):
|
||||
cwd = os.path.join(source_dir, 'nailgun')
|
||||
|
||||
six.print_(
|
||||
self.print_debug(
|
||||
'Building gulp static in %s, temporary static dir is: %s...' % (
|
||||
cwd,
|
||||
self.temporary_build_dir
|
||||
|
@ -77,4 +76,4 @@ class Rsync(DockerNginxMixin, docker.RsyncCommand):
|
|||
)
|
||||
)
|
||||
|
||||
six.print_(result)
|
||||
self.print_debug(result)
|
||||
|
|
|
@ -15,14 +15,14 @@
|
|||
import logging
|
||||
import six
|
||||
|
||||
from cliff import command
|
||||
from fuel_dev_tools import command
|
||||
|
||||
|
||||
class BasicInfo(object):
|
||||
pass
|
||||
|
||||
|
||||
class Info(command.Command):
|
||||
class Info(command.BaseCommand):
|
||||
"""Various useful information about the Fuel master node."""
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
|
|
@ -19,11 +19,11 @@ from fabric.contrib import project
|
|||
|
||||
class RsyncMixin(object):
|
||||
def rsync(self, source, target):
|
||||
six.print_('RSYNC: %s --> %s' % (source, target))
|
||||
self.print_debug('RSYNC: %s --> %s' % (source, target))
|
||||
|
||||
result = project.rsync_project(
|
||||
local_dir=source,
|
||||
remote_dir=target
|
||||
)
|
||||
|
||||
six.print_(result.decode('utf-8'))
|
||||
self.print_debug(result.decode('utf-8'))
|
||||
|
|
|
@ -27,11 +27,11 @@ import traceback
|
|||
from cliff import app
|
||||
from cliff import commandmanager
|
||||
|
||||
from docker import astute
|
||||
from docker import nailgun
|
||||
from docker import nginx
|
||||
import exc
|
||||
import info
|
||||
from fuel_dev_tools.docker import astute
|
||||
from fuel_dev_tools.docker import nailgun
|
||||
from fuel_dev_tools.docker import nginx
|
||||
from fuel_dev_tools import exc
|
||||
from fuel_dev_tools import info
|
||||
|
||||
|
||||
COMMANDS = {
|
||||
|
|
|
@ -24,9 +24,6 @@ import exc
|
|||
SSH_PASSWORD_CHECKED = False
|
||||
|
||||
|
||||
print_verbose = six.print_
|
||||
|
||||
|
||||
# TODO(pkaminski): ssh_command should be in some utils, not necessarily
|
||||
# in this class?
|
||||
class SSHMixin(object):
|
||||
|
@ -42,8 +39,8 @@ class SSHMixin(object):
|
|||
fabric.state.output[key] = False
|
||||
|
||||
def send_identity(self):
|
||||
print_verbose('Sending identity %s for passwordless authentication' %
|
||||
self.app_args.identity_file)
|
||||
self.print_debug('Sending identity %s for passwordless authentication' %
|
||||
self.app_args.identity_file)
|
||||
|
||||
with open('%s.pub' % self.app_args.identity_file) as f:
|
||||
contents = f.read()
|
||||
|
@ -51,7 +48,7 @@ class SSHMixin(object):
|
|||
result = fabric_api.run(
|
||||
"echo '%s' >> ~/.ssh/authorized_keys" % contents
|
||||
)
|
||||
print_verbose(result)
|
||||
self.print_debug(result)
|
||||
|
||||
# And while we're here, let's fix /etc/hosts for which 10.20.0.2
|
||||
# points to some non-existing domain (with misconfigured reverse-DNS
|
||||
|
@ -61,11 +58,11 @@ class SSHMixin(object):
|
|||
'IP': self.app_args.IP
|
||||
}
|
||||
)
|
||||
print_verbose(result)
|
||||
self.print_debug(result)
|
||||
|
||||
# Need to restart after /etc/hosts change
|
||||
result = fabric_api.run('service sshd restart')
|
||||
print_verbose(result)
|
||||
self.print_debug(result)
|
||||
|
||||
return result
|
||||
|
||||
|
@ -97,13 +94,13 @@ class SSHMixin(object):
|
|||
return fabric_api.run(' '.join(args))
|
||||
|
||||
def ssh_command_interactive(self, *args):
|
||||
print_verbose("COMMAND: %r" % list(args))
|
||||
self.print_debug("COMMAND: %r" % list(args))
|
||||
|
||||
command = None
|
||||
|
||||
if args:
|
||||
command = ' '.join(args)
|
||||
|
||||
print_verbose('interactive', command)
|
||||
self.print_debug('interactive', command)
|
||||
|
||||
fabric_api.open_shell(command=command)
|
||||
|
|
Loading…
Reference in New Issue