# Path: armada/exceptions/tiller_exceptions.py
# class TillerException(ex):
# class TillerServicesUnavailableException(TillerException):
# class ChartCleanupException(TillerException):
# class ListChartsException(TillerException):
# class PostUpdateJobDeleteException(TillerException):
# class PostUpdateJobCreateException(TillerException):
# class PreUpdateJobDeleteException(TillerException):
# class PreUpdateJobCreateException(TillerException):
# class ReleaseException(TillerException):
# class ChannelException(TillerException):
# class GetReleaseStatusException(TillerException):
# class GetReleaseContentException(TillerException):
# class TillerPodNotFoundException(TillerException):
# class TillerPodNotRunningException(TillerException):
# class TillerVersionException(TillerException):
#     def __init__(self, chart_name):
#     def __init__(self, name, namespace):
#     def __init__(self, name, namespace):
#     def __init__(self, name, namespace):
#     def __init__(self, name, namespace):
#     def __init__(self, name, status, action):
#     def __init__(self, release, version):
#     def __init__(self, release, version):
#     def __init__(self, labels):
# 
# Path: armada/handlers/tiller.py
# TILLER_VERSION = b'2.7.2'
# TILLER_TIMEOUT = 300
# GRPC_EPSILON = 60
# RELEASE_LIMIT = 128  # TODO(mark-burnett): There may be a better page size.
# RUNTEST_SUCCESS = 9
# MAX_MESSAGE_LENGTH = 429496729
# CONF = cfg.CONF
# LOG = logging.getLogger(__name__)
# class TillerResult(object):
# class Tiller(object):
#     def __init__(self, release, namespace, status, description, version):
#     def __init__(self, tiller_host=None, tiller_port=None,
#                  tiller_namespace=None):
#     def metadata(self):
#     def get_channel(self):
#     def _get_tiller_pod(self):
#     def _get_tiller_ip(self):
#     def _get_tiller_port(self):
#     def _get_tiller_namespace(self):
#     def tiller_status(self):
#     def list_releases(self):
#     def get_chart_templates(self, template_name, name, release_name, namespace,
#                             chart, disable_hooks, values):
#     def _pre_update_actions(self, actions, release_name, namespace, chart,
#                             disable_hooks, values, timeout):
#     def _post_update_actions(self, actions, namespace):
#     def list_charts(self):
#     def update_release(self, chart, release, namespace,
#                        dry_run=False,
#                        pre_actions=None,
#                        post_actions=None,
#                        disable_hooks=False,
#                        values=None,
#                        wait=False,
#                        timeout=None):
#     def install_release(self, chart, release, namespace,
#                         dry_run=False,
#                         values=None,
#                         wait=False,
#                         timeout=None):
#     def testing_release(self, release, timeout=300, cleanup=True):
#     def get_release_status(self, release, version=0):
#     def get_release_content(self, release, version=0):
#     def tiller_version(self):
#     def uninstall_release(self, release, disable_hooks=False, purge=True):
#     def chart_cleanup(self, prefix, charts):
#     def delete_resources(self, release_name, resource_name, resource_type,
#                          resource_labels, namespace, wait=False,
#                          timeout=TILLER_TIMEOUT):
#     def rolling_upgrade_pod_deployment(self, name, release_name, namespace,
#                                        resource_labels, action_type, chart,
#                                        disable_hooks, values,
#                                        timeout=TILLER_TIMEOUT):
# 
# Path: armada/tests/unit/base.py
# CONF = cfg.CONF
# class ArmadaTestCase(testtools.TestCase):
#     def setUp(self):
#     def override_config(self, name, override, group=None):
#     def assertEmpty(self, collection):
#     def patch(self, target, autospec=True, **kwargs):
#     def patchobject(self, target, attribute, new=mock.DEFAULT, autospec=True):


import mock
from armada.exceptions import tiller_exceptions as ex
from armada.handlers import tiller
from armada.tests.unit import base
                     ('grpc.max_receive_message_length',
                     tiller.MAX_MESSAGE_LENGTH)]
        )

    @mock.patch('armada.handlers.tiller.K8s', autospec=True)
    @mock.patch('armada.handlers.tiller.grpc', autospec=True)
    def test_get_tiller_ip_with_host_provided(self, mock_grpc, _):
        tiller_obj = tiller.Tiller('1.1.1.1')
        self.assertIsNotNone(tiller_obj._get_tiller_ip())
        self.assertEqual('1.1.1.1', tiller_obj._get_tiller_ip())

    @mock.patch.object(tiller.Tiller, '_get_tiller_pod', autospec=True)
    @mock.patch('armada.handlers.tiller.K8s', autospec=True)
    @mock.patch('armada.handlers.tiller.grpc', autospec=True)
    def test_get_tiller_ip_with_mocked_pod(self, mock_grpc, mock_k8s,
                                           mock_pod):
        status = mock.Mock(pod_ip='1.1.1.1')
        mock_pod.return_value.status = status
        tiller_obj = tiller.Tiller()
        self.assertEqual('1.1.1.1', tiller_obj._get_tiller_ip())

    @mock.patch.object(tiller.Tiller, '_get_tiller_ip', autospec=True)
    @mock.patch('armada.handlers.tiller.K8s', autospec=True)
    @mock.patch('armada.handlers.tiller.grpc', autospec=True)
    def test_get_tiller_pod_throws_exception(self, mock_grpc, mock_k8s,
                                             mock_ip):

        mock_k8s.get_namespace_pod.return_value.items = []
        tiller_obj = tiller.Tiller()
        mock_grpc.insecure_channel.side_effect = ex.ChannelException()

# Path: armada/exceptions/tiller_exceptions.py
# class TillerException(ex):
# class TillerServicesUnavailableException(TillerException):
# class ChartCleanupException(TillerException):
# class ListChartsException(TillerException):
# class PostUpdateJobDeleteException(TillerException):
# class PostUpdateJobCreateException(TillerException):
# class PreUpdateJobDeleteException(TillerException):
# class PreUpdateJobCreateException(TillerException):
# class ReleaseException(TillerException):
# class ChannelException(TillerException):
# class GetReleaseStatusException(TillerException):
# class GetReleaseContentException(TillerException):
# class TillerPodNotFoundException(TillerException):
# class TillerPodNotRunningException(TillerException):
# class TillerVersionException(TillerException):
#     def __init__(self, chart_name):
#     def __init__(self, name, namespace):
#     def __init__(self, name, namespace):
#     def __init__(self, name, namespace):
#     def __init__(self, name, namespace):
#     def __init__(self, name, status, action):
#     def __init__(self, release, version):
#     def __init__(self, release, version):
#     def __init__(self, labels):
# 
# Path: armada/handlers/tiller.py
# TILLER_VERSION = b'2.7.2'
# TILLER_TIMEOUT = 300
# GRPC_EPSILON = 60
# RELEASE_LIMIT = 128  # TODO(mark-burnett): There may be a better page size.
# RUNTEST_SUCCESS = 9
# MAX_MESSAGE_LENGTH = 429496729
# CONF = cfg.CONF
# LOG = logging.getLogger(__name__)
# class TillerResult(object):
# class Tiller(object):
#     def __init__(self, release, namespace, status, description, version):
#     def __init__(self, tiller_host=None, tiller_port=None,
#                  tiller_namespace=None):
#     def metadata(self):
#     def get_channel(self):
#     def _get_tiller_pod(self):
#     def _get_tiller_ip(self):
#     def _get_tiller_port(self):
#     def _get_tiller_namespace(self):
#     def tiller_status(self):
#     def list_releases(self):
#     def get_chart_templates(self, template_name, name, release_name, namespace,
#                             chart, disable_hooks, values):
#     def _pre_update_actions(self, actions, release_name, namespace, chart,
#                             disable_hooks, values, timeout):
#     def _post_update_actions(self, actions, namespace):
#     def list_charts(self):
#     def update_release(self, chart, release, namespace,
#                        dry_run=False,
#                        pre_actions=None,
#                        post_actions=None,
#                        disable_hooks=False,
#                        values=None,
#                        wait=False,
#                        timeout=None):
#     def install_release(self, chart, release, namespace,
#                         dry_run=False,
#                         values=None,
#                         wait=False,
#                         timeout=None):
#     def testing_release(self, release, timeout=300, cleanup=True):
#     def get_release_status(self, release, version=0):
#     def get_release_content(self, release, version=0):
#     def tiller_version(self):
#     def uninstall_release(self, release, disable_hooks=False, purge=True):
#     def chart_cleanup(self, prefix, charts):
#     def delete_resources(self, release_name, resource_name, resource_type,
#                          resource_labels, namespace, wait=False,
#                          timeout=TILLER_TIMEOUT):
#     def rolling_upgrade_pod_deployment(self, name, release_name, namespace,
#                                        resource_labels, action_type, chart,
#                                        disable_hooks, values,
#                                        timeout=TILLER_TIMEOUT):
# 
# Path: armada/tests/unit/base.py
# CONF = cfg.CONF
# class ArmadaTestCase(testtools.TestCase):
#     def setUp(self):
#     def override_config(self, name, override, group=None):
#     def assertEmpty(self, collection):
#     def patch(self, target, autospec=True, **kwargs):
#     def patchobject(self, target, attribute, new=mock.DEFAULT, autospec=True):


# Path: armada/tests/unit/handlers/test_tiller.py
import mock
from armada.exceptions import tiller_exceptions as ex
from armada.handlers import tiller
from armada.tests.unit import base

                     ('grpc.max_receive_message_length',
                     tiller.MAX_MESSAGE_LENGTH)]
        )

    @mock.patch('armada.handlers.tiller.K8s', autospec=True)
    @mock.patch('armada.handlers.tiller.grpc', autospec=True)
    def test_get_tiller_ip_with_host_provided(self, mock_grpc, _):
        tiller_obj = tiller.Tiller('1.1.1.1')
        self.assertIsNotNone(tiller_obj._get_tiller_ip())
        self.assertEqual('1.1.1.1', tiller_obj._get_tiller_ip())

    @mock.patch.object(tiller.Tiller, '_get_tiller_pod', autospec=True)
    @mock.patch('armada.handlers.tiller.K8s', autospec=True)
    @mock.patch('armada.handlers.tiller.grpc', autospec=True)
    def test_get_tiller_ip_with_mocked_pod(self, mock_grpc, mock_k8s,
                                           mock_pod):
        status = mock.Mock(pod_ip='1.1.1.1')
        mock_pod.return_value.status = status
        tiller_obj = tiller.Tiller()
        self.assertEqual('1.1.1.1', tiller_obj._get_tiller_ip())

    @mock.patch.object(tiller.Tiller, '_get_tiller_ip', autospec=True)
    @mock.patch('armada.handlers.tiller.K8s', autospec=True)
    @mock.patch('armada.handlers.tiller.grpc', autospec=True)
    def test_get_tiller_pod_throws_exception(self, mock_grpc, mock_k8s,
                                             mock_ip):

        mock_k8s.get_namespace_pod.return_value.items = []
        tiller_obj = tiller.Tiller()
        mock_grpc.insecure_channel.side_effect = ex.ChannelException()

        self.assertRaises(ex.TillerPodNotRunningException,