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

Commit

Permalink
Merge pull request #26 from ashcrow/slow-docker-startup-fix
Browse files Browse the repository at this point in the history
LGTM
  • Loading branch information
cooktheryan committed Feb 11, 2016
2 parents 950921a + 2b49291 commit b5d161b
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 140 deletions.
53 changes: 9 additions & 44 deletions src/commissaire/oscmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ class OSCmdBase:
#: Full path to kubelet configuration file
kubelet_config = '/etc/kubernetes/kubelet'

#: Docker service name
docker_service = 'docker'
#: Flannel service name
flannel_service = 'flanneld'
#: Kubernetes kubelet service name
kubelet_service = 'kubelet'
#: Kubernetes kube-proxy service name
kubelet_proxy_service = 'kube-proxy'

def restart(self):
"""
Restart command. Must be overriden.
Expand Down Expand Up @@ -66,17 +75,6 @@ def install_docker(self):
'{0}.install_docker() must be overriden.'.format(
self.__class__.__name__))

def start_docker(self):
"""
Start Docker command. Must be overriden.
:return: The command to execute as a list
:rtype: list
"""
raise NotImplementedError(
'{0}.start_docker() must be overriden.'.format(
self.__class__.__name__))

def install_flannel(self):
"""
Install Flannel command. Must be overriden.
Expand All @@ -88,17 +86,6 @@ def install_flannel(self):
'{0}.install_flannel() must be overriden.'.format(
self.__class__.__name__))

def start_flannel(self):
"""
Start Flannel command. Must be overriden.
:return: The command to execute as a list
:rtype: list
"""
raise NotImplementedError(
'{0}.start_flannel() must be overriden.'.format(
self.__class__.__name__))

def install_kube(self):
"""
Install Kube command. Must be overriden.
Expand All @@ -110,28 +97,6 @@ def install_kube(self):
'{0}.install_kube() must be overriden.'.format(
self.__class__.__name__))

def start_kube(self):
"""
Start Kube command. Must be overriden.
:return: The command to execute as a list
:rtype: list
"""
raise NotImplementedError(
'{0}.start_kube() must be overriden.'.format(
self.__class__.__name__))

def start_kube_proxy(self):
"""
Start Kube Proxy command. Must be overriden.
:return: The command to execute as a list
:rtype: list
"""
raise NotImplementedError(
'{0}.start_kube_proxy() must be overriden.'.format(
self.__class__.__name__))


def get_oscmd(os_type):
"""
Expand Down
36 changes: 0 additions & 36 deletions src/commissaire/oscmd/fedora.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@ def install_docker(self):
"""
return ['dnf', 'install', '-y', 'docker']

def start_docker(self):
"""
Fedora start docker command..
:return: The command to execute as a list
:rtype: list
"""
return ['systemctl', 'start', 'docker']

def install_flannel(self):
"""
Fedora install flannel command.
Expand All @@ -72,15 +63,6 @@ def install_flannel(self):
"""
return ['dnf', 'install', '-y', 'flannel']

def start_flannel(self):
"""
Fedora start flannel command..
:return: The command to execute as a list
:rtype: list
"""
return ['systemctl', 'start', 'flanneld']

def install_kube(self):
"""
Fedora install Kube command.
Expand All @@ -89,21 +71,3 @@ def install_kube(self):
:rtype: list
"""
return ['dnf', 'install', '-y', 'kubernetes-node']

def start_kube(self):
"""
Fedora start kube command.
:return: The command to execute as a list
:rtype: list
"""
return ['systemctl', 'start', 'kubelet']

def start_kube_proxy(self):
"""
Fedora start Kube Proxy command.
:return: The command to execute as a list
:rtype: list
"""
return ['systemctl', 'start', 'kube-proxy']
77 changes: 55 additions & 22 deletions src/commissaire/transport/ansibleapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ def v2_runner_on_failed(self, result, *args, **kwargs):
"""
if 'exception' in result._result.keys():
self.log.warn(
'An exception occurred: {0}'.format(
result._result['exception']))
'An exception occurred for {0}: {1}'.format(
result._host.get_name(), result._result['exception']))
self.log.debug('{0}'.format(result.__dict__))

def v2_runner_on_ok(self, result):
"""
Expand All @@ -76,7 +77,9 @@ def v2_runner_on_ok(self, result):
:type result: ansible.executor.task_result.TaskResult
"""
self._clean_results(result._result, result._task.action)
self.log.info('SUCCESS {0}'.format(result._host.get_name()))
self.log.info('SUCCESS {0}: {1}'.format(
result._host.get_name(), result._task.get_name().strip()))
self.log.debug('{0}'.format(result.__dict__))

def v2_runner_on_skipped(self, result):
"""
Expand All @@ -85,7 +88,9 @@ def v2_runner_on_skipped(self, result):
:param result: Ansible's result.
:type result: ansible.executor.task_result.TaskResult
"""
self.log.warn('SKIPPED {0}'.format(result._host.get_name()))
self.log.warn('SKIPPED {0}: {1}'.format(
result._host.get_name(), result._task.get_name().strip()))
self.log.debug('{0}'.format(result.__dict__))

def v2_runner_on_unreachable(self, result):
"""
Expand All @@ -94,9 +99,8 @@ def v2_runner_on_unreachable(self, result):
:param result: Ansible's result.
:type result: ansible.executor.task_result.TaskResult
"""
self.log.warn('UNREACHABLE {0}'.format(
result._host.get_name(),
result._result))
self.log.warn('UNREACHABLE {0}: {1}'.format(
result._host.get_name(), result._task.get_name().strip()))
self.log.debug('{0}'.format(result.__dict__))

def v2_playbook_on_task_start(self, task, *args, **kwargs):
Expand All @@ -110,7 +114,8 @@ def v2_playbook_on_task_start(self, task, *args, **kwargs):
:param kwargs: All other ignored keyword arguments.
:type kwargs: dict
"""
self.log.info("TASK started: %s" % task.get_name().strip())
self.log.info("START TASK: {0}".format(task.get_name().strip()))
self.log.debug('{0}'.format(task.__dict__))


class Transport:
Expand Down Expand Up @@ -346,90 +351,118 @@ def bootstrap(self, ip, key_file, connection_config, oscmd):
'gather_facts': 'no',
'tasks': [
{
'name': 'Install Flannel',
'action': {
'module': 'command',
'args': " ".join(oscmd.install_flannel()),
}
},
{
'name': 'Configure Flannel',
'action': {
'module': 'synchronize',
'args': {
'dest': oscmd.flanneld_config,
'src': configs['flanneld']
'src': configs['flanneld'],
}
}
},
{
'name': 'Enable and Start Flannel',
'action': {
'module': 'command',
'args': " ".join(oscmd.start_flannel())
'module': 'service',
'args': {
'name': oscmd.flannel_service,
'enabled': 'yes',
'state': 'started',
}
}
},
{
'name': 'Install Docker',
'action': {
'module': 'command',
'args': " ".join(oscmd.install_docker()),
}
},
{
'name': 'Configure Docker',
'action': {
'module': 'synchronize',
'args': {
'dest': oscmd.docker_config,
'src': configs['docker']
'src': configs['docker'],
}
}
},
{
'name': 'Enable and Start Docker',
'action': {
'module': 'command',
'args': " ".join(oscmd.start_docker())
'module': 'service',
'args': {
'name': oscmd.docker_service,
'enabled': 'yes',
'state': 'started',
}
}
},
{
'name': 'Install Kubernetes Node',
'action': {
'module': 'command',
'args': " ".join(oscmd.install_kube())
'args': " ".join(oscmd.install_kube()),
}
},
{
'name': 'Configure Kubernetes Node',
'action': {
'module': 'synchronize',
'args': {
'dest': oscmd.kubernetes_config,
'src': configs['kube_config']
'src': configs['kube_config'],
}
}
},
{
'name': 'Add Kubernetes kubeconfig',
'action': {
'module': 'synchronize',
'args': {
'dest': oscmd.kubernetes_kubeconfig,
'src': configs['kubeconfig']
'src': configs['kubeconfig'],
}
}
},
{
'name': 'Configure Kubernetes kubelet',
'action': {
'module': 'synchronize',
'args': {
'dest': oscmd.kubelet_config,
'src': configs['kubelet']
'src': configs['kubelet'],
}
}
},
{
'name': 'Enable and Start Kubelet',
'action': {
'module': 'command',
'args': " ".join(oscmd.start_kube())
'module': 'service',
'args': {
'name': oscmd.kubelet_service,
'enabled': 'yes',
'state': 'started',
}
}
},
{
'name': 'Enable and Start Kube Proxy',
'action': {
'module': 'command',
'args': " ".join(oscmd.start_kube_proxy())
'module': 'service',
'args': {
'name': oscmd.kubelet_proxy_service,
'enabled': 'yes',
'state': 'started',
}
}
},
]
Expand Down
23 changes: 17 additions & 6 deletions test/test_oscmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,35 @@
from commissaire import oscmd


class Test_OSCmdBase(TestCase):
class _Test_OSCmd(TestCase):
"""
Tests for the OSCmdBase class.
"""

oscmdcls = None
expected_methods = (
'restart', 'upgrade', 'install_docker',
'install_flannel', 'install_kube')

def before(self):
"""
Sets up a fresh instance of the class before each run.
"""
self.instance = oscmd.OSCmdBase()
self.instance = self.oscmdcls()


class Test_OSCmdBase(_Test_OSCmd):
"""
Tests for the OSCmdBase class.
"""

oscmdcls = oscmd.OSCmdBase

def test_oscmd_base_methods(self):
def test_oscmd_methods(self):
"""
Verify OSCmdBase base methods all raises.
"""
for meth in ('restart', 'upgrade', 'install_docker',
'start_docker', 'install_flannel', 'start_flannel',
'install_kube', 'start_kube', 'start_kube_proxy'):
for meth in self.expected_methods:
self.assertRaises(
NotImplementedError,
getattr(self.instance, meth))
Expand Down
14 changes: 4 additions & 10 deletions test/test_oscmd_fedora.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,21 @@
Test cases for the commissaire.oscmd.fedora module.
"""

from . import TestCase
from . test_oscmd import _Test_OSCmd
from commissaire.oscmd import fedora


class Test_Fedora_OSCmd(TestCase):
class Test_Fedora_OSCmd(_Test_OSCmd):
"""
Tests for the OSCmd class for Fedora.
"""

def before(self):
"""
Sets up a fresh instance of the class before each run.
"""
self.instance = fedora.OSCmd()
oscmdcls = fedora.OSCmd

def test_fedora_oscmd_commands(self):
"""
Verify Fedora's OSCmd returns proper data on restart.
"""
for meth in ('restart', 'upgrade', 'install_docker',
'start_docker', 'install_flannel', 'start_flannel',
'install_kube', 'start_kube', 'start_kube_proxy'):
for meth in self.expected_methods:
cmd = getattr(self.instance, meth)()
self.assertEquals(list, type(cmd))

0 comments on commit b5d161b

Please sign in to comment.