forked from openstack/kuryr-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch introduces an eventlet-based Kuryr-Kubernetes controller service base (based on oslo.service) and command-line launcher. Change-Id: Idfd5efd71d9dd7cb184905dd487eea4ba33b029e Partially-Implements: blueprint kuryr-k8s-integration
- Loading branch information
Showing
13 changed files
with
173 additions
and
3 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (c) 2016 Mirantis, Inc. | ||
# All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import eventlet | ||
|
||
eventlet.monkey_patch() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright (c) 2016 Mirantis, Inc. | ||
# All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from kuryr_kubernetes.controller import service | ||
|
||
|
||
start = service.start | ||
|
||
if __name__ == '__main__': | ||
start() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright (c) 2016 Mirantis, Inc. | ||
# All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import sys | ||
|
||
from kuryr.lib._i18n import _LI | ||
from oslo_log import log as logging | ||
from oslo_service import service | ||
|
||
from kuryr_kubernetes import clients | ||
from kuryr_kubernetes import config | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class KuryrK8sService(service.Service): | ||
"""Kuryr-Kubernetes controller Service.""" | ||
|
||
def __init__(self): | ||
super(KuryrK8sService, self).__init__() | ||
|
||
def start(self): | ||
LOG.info(_LI("Service '%s' starting"), self.__class__.__name__) | ||
super(KuryrK8sService, self).start() | ||
LOG.info(_LI("Service '%s' started"), self.__class__.__name__) | ||
|
||
def wait(self): | ||
super(KuryrK8sService, self).wait() | ||
LOG.info(_LI("Service '%s' stopped"), self.__class__.__name__) | ||
|
||
def stop(self, graceful=False): | ||
LOG.info(_LI("Service '%s' stopping"), self.__class__.__name__) | ||
super(KuryrK8sService, self).stop(graceful) | ||
|
||
|
||
def start(): | ||
config.init(sys.argv[1:]) | ||
config.setup_logging() | ||
clients.setup_clients() | ||
kuryrk8s_launcher = service.launch(config.CONF, KuryrK8sService()) | ||
kuryrk8s_launcher.wait() |
Empty file.
Empty file.
34 changes: 34 additions & 0 deletions
34
kuryr_kubernetes/tests/unit/cmd/eventlet/test_controller.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright (c) 2016 Mirantis, Inc. | ||
# All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import mock | ||
|
||
from kuryr_kubernetes.tests import base as test_base | ||
|
||
|
||
class TestControllerCmd(test_base.TestCase): | ||
|
||
@mock.patch('kuryr_kubernetes.controller.service.start') | ||
@mock.patch('eventlet.monkey_patch') | ||
def test_start(self, m_evmp, m_start): | ||
# NOTE(ivc): eventlet.monkey_patch is invoked during the module | ||
# import, so the controller cmd has to be imported locally to verify | ||
# that monkey_patch is called | ||
from kuryr_kubernetes.cmd.eventlet import controller | ||
|
||
controller.start() | ||
|
||
m_evmp.assert_called() | ||
m_start.assert_called() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (c) 2016 Mirantis, Inc. | ||
# All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import mock | ||
|
||
from kuryr_kubernetes.controller import service | ||
from kuryr_kubernetes.tests import base as test_base | ||
|
||
|
||
class TestControllerService(test_base.TestCase): | ||
|
||
@mock.patch('oslo_service.service.launch') | ||
@mock.patch('kuryr_kubernetes.config.init') | ||
@mock.patch('kuryr_kubernetes.config.setup_logging') | ||
@mock.patch('kuryr_kubernetes.clients.setup_clients') | ||
@mock.patch('kuryr_kubernetes.controller.service.KuryrK8sService') | ||
def test_start(self, m_svc, m_setup_clients, m_setup_logging, | ||
m_config_init, m_oslo_launch): | ||
m_launcher = mock.Mock() | ||
m_oslo_launch.return_value = m_launcher | ||
|
||
service.start() | ||
|
||
m_config_init.assert_called() | ||
m_setup_logging.assert_called() | ||
m_setup_clients.assert_called() | ||
m_svc.assert_called() | ||
m_oslo_launch.assert_called() | ||
m_launcher.wait.assert_called() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters