Rename bay's master_address to api_address
The idea of having a master is a Kubernetes concept and isn't necessarily a bay concept. In Magnum, we are actually using this value as the API endpoint. Thus, this patch renames the column in order to be more clear about what this value is used for, and also to be more agnostic across each Container Orchestration Environment. Partial-Implements: blueprint multiple-bay-templates Change-Id: Ifaaf626377b8b302e5b390deea53be7be85e88f7
This commit is contained in:
parent
95e14f6fb9
commit
11d28c0770
|
@ -244,13 +244,13 @@ class HeatPoller(object):
|
|||
self.attempts = 0
|
||||
|
||||
def poll_and_check(self):
|
||||
# TODO(yuanying): temporary implementation to update master_address,
|
||||
# TODO(yuanying): temporary implementation to update api_address,
|
||||
# minions_address and bay status
|
||||
stack = self.openstack_client.heat().stacks.get(self.bay.stack_id)
|
||||
self.attempts += 1
|
||||
if (stack.stack_status in ['CREATE_COMPLETE', 'UPDATE_COMPLETE']):
|
||||
parsed_outputs = _parse_stack_outputs(stack.outputs)
|
||||
self.bay.master_address = parsed_outputs["kube_master"]
|
||||
self.bay.api_address = parsed_outputs["kube_master"]
|
||||
self.bay.minions_address = parsed_outputs["kube_minions_external"]
|
||||
self.bay.status = stack.stack_status
|
||||
self.bay.save()
|
||||
|
|
|
@ -22,48 +22,48 @@ from magnum.openstack.common import utils
|
|||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _k8s_create(master_address, resource):
|
||||
def _k8s_create(api_address, resource):
|
||||
data = resource.manifest
|
||||
definition_url = resource.manifest_url
|
||||
if data is not None:
|
||||
return _k8s_create_with_data(master_address, data)
|
||||
return _k8s_create_with_data(api_address, data)
|
||||
else:
|
||||
return _k8s_create_with_path(master_address, definition_url)
|
||||
return _k8s_create_with_path(api_address, definition_url)
|
||||
|
||||
|
||||
def _k8s_create_with_path(master_address, resource_file):
|
||||
def _k8s_create_with_path(api_address, resource_file):
|
||||
return utils.trycmd('kubectl', 'create',
|
||||
'-s', master_address,
|
||||
'-s', api_address,
|
||||
'-f', resource_file)
|
||||
|
||||
|
||||
def _k8s_create_with_data(master_address, resource_data):
|
||||
def _k8s_create_with_data(api_address, resource_data):
|
||||
with tempfile.NamedTemporaryFile() as f:
|
||||
f.write(resource_data)
|
||||
f.flush()
|
||||
return _k8s_create_with_path(master_address, f.name)
|
||||
return _k8s_create_with_path(api_address, f.name)
|
||||
|
||||
|
||||
def _k8s_update(master_address, resource):
|
||||
def _k8s_update(api_address, resource):
|
||||
data = resource.manifest
|
||||
definition_url = resource.manifest_url
|
||||
if data is not None:
|
||||
return _k8s_update_with_data(master_address, data)
|
||||
return _k8s_update_with_data(api_address, data)
|
||||
else:
|
||||
return _k8s_update_with_path(master_address, definition_url)
|
||||
return _k8s_update_with_path(api_address, definition_url)
|
||||
|
||||
|
||||
def _k8s_update_with_path(master_address, resource_file):
|
||||
def _k8s_update_with_path(api_address, resource_file):
|
||||
return utils.trycmd('kubectl', 'update',
|
||||
'-s', master_address,
|
||||
'-s', api_address,
|
||||
'-f', resource_file)
|
||||
|
||||
|
||||
def _k8s_update_with_data(master_address, resource_data):
|
||||
def _k8s_update_with_data(api_address, resource_data):
|
||||
with tempfile.NamedTemporaryFile() as f:
|
||||
f.write(resource_data)
|
||||
f.flush()
|
||||
return _k8s_update_with_path(master_address, f.name)
|
||||
return _k8s_update_with_path(api_address, f.name)
|
||||
|
||||
|
||||
class KubeClient(object):
|
||||
|
@ -78,10 +78,10 @@ class KubeClient(object):
|
|||
def __init__(self):
|
||||
super(KubeClient, self).__init__()
|
||||
|
||||
def service_create(self, master_address, service):
|
||||
def service_create(self, api_address, service):
|
||||
LOG.debug("service_create with contents %s" % service)
|
||||
try:
|
||||
out, err = _k8s_create(master_address, service)
|
||||
out, err = _k8s_create(api_address, service)
|
||||
|
||||
if err:
|
||||
return False
|
||||
|
@ -92,10 +92,10 @@ class KubeClient(object):
|
|||
return False
|
||||
return True
|
||||
|
||||
def service_update(self, master_address, service):
|
||||
def service_update(self, api_address, service):
|
||||
LOG.debug("service_update with contents %s" % service)
|
||||
try:
|
||||
out, err = _k8s_update(master_address, service)
|
||||
out, err = _k8s_update(api_address, service)
|
||||
|
||||
if err:
|
||||
return False
|
||||
|
@ -106,11 +106,11 @@ class KubeClient(object):
|
|||
return False
|
||||
return True
|
||||
|
||||
def service_list(self, master_address):
|
||||
def service_list(self, api_address):
|
||||
LOG.debug("service_list")
|
||||
try:
|
||||
out = utils.execute('kubectl', 'get', 'services',
|
||||
'-s', master_address,)
|
||||
'-s', api_address,)
|
||||
manifest = [s.split() for s in out.split('\n')]
|
||||
return manifest
|
||||
except Exception as e:
|
||||
|
@ -118,11 +118,11 @@ class KubeClient(object):
|
|||
% e)
|
||||
return None
|
||||
|
||||
def service_delete(self, master_address, name):
|
||||
def service_delete(self, api_address, name):
|
||||
LOG.debug("service_delete %s" % name)
|
||||
try:
|
||||
out, err = utils.trycmd('kubectl', 'delete', 'service', name,
|
||||
'-s', master_address)
|
||||
'-s', api_address)
|
||||
if err:
|
||||
return False
|
||||
except Exception as e:
|
||||
|
@ -131,11 +131,11 @@ class KubeClient(object):
|
|||
return False
|
||||
return True
|
||||
|
||||
def service_get(self, master_address, uuid):
|
||||
def service_get(self, api_address, uuid):
|
||||
LOG.debug("service_get %s" % uuid)
|
||||
try:
|
||||
out = utils.execute('kubectl', 'get', 'service', uuid,
|
||||
'-s', master_address)
|
||||
'-s', api_address)
|
||||
# TODO(pkilambi): process the output as needed
|
||||
return out
|
||||
except Exception as e:
|
||||
|
@ -143,11 +143,11 @@ class KubeClient(object):
|
|||
"%(error)s") % {'service': uuid, 'error': e})
|
||||
return None
|
||||
|
||||
def service_show(self, master_address, uuid):
|
||||
def service_show(self, api_address, uuid):
|
||||
LOG.debug("service_show %s" % uuid)
|
||||
try:
|
||||
out = utils.execute('kubectl', 'describe', 'service', uuid,
|
||||
'-s', master_address)
|
||||
'-s', api_address)
|
||||
# TODO(pkilambi): process the output as needed
|
||||
return out
|
||||
except Exception as e:
|
||||
|
@ -156,10 +156,10 @@ class KubeClient(object):
|
|||
return None
|
||||
|
||||
# Pod Operations
|
||||
def pod_create(self, master_address, pod):
|
||||
def pod_create(self, api_address, pod):
|
||||
LOG.debug("pod_create contents %s" % pod)
|
||||
try:
|
||||
out, err = _k8s_create(master_address, pod)
|
||||
out, err = _k8s_create(api_address, pod)
|
||||
|
||||
if err:
|
||||
return False
|
||||
|
@ -170,10 +170,10 @@ class KubeClient(object):
|
|||
return False
|
||||
return True
|
||||
|
||||
def pod_update(self, master_address, pod):
|
||||
def pod_update(self, api_address, pod):
|
||||
LOG.debug("pod_update contents %s" % pod)
|
||||
try:
|
||||
out, err = _k8s_update(master_address, pod)
|
||||
out, err = _k8s_update(api_address, pod)
|
||||
|
||||
if err:
|
||||
return False
|
||||
|
@ -183,21 +183,21 @@ class KubeClient(object):
|
|||
return False
|
||||
return True
|
||||
|
||||
def pod_list(self, master_address):
|
||||
def pod_list(self, api_address):
|
||||
LOG.debug("pod_list")
|
||||
try:
|
||||
out = utils.execute('kubectl', 'get', 'pods', '-s', master_address)
|
||||
out = utils.execute('kubectl', 'get', 'pods', '-s', api_address)
|
||||
manifest = [s.split() for s in out.split('\n')]
|
||||
return manifest
|
||||
except Exception as e:
|
||||
LOG.error(_LE("Couldn't get list of pods due to error %s") % e)
|
||||
return None
|
||||
|
||||
def pod_delete(self, master_address, name):
|
||||
def pod_delete(self, api_address, name):
|
||||
LOG.debug("pod_delete %s" % name)
|
||||
try:
|
||||
out, err = utils.trycmd('kubectl', 'delete', 'pod', name,
|
||||
'-s', master_address,)
|
||||
'-s', api_address,)
|
||||
except Exception as e:
|
||||
LOG.error(_LE("Couldn't delete pod %(pod)s due to error "
|
||||
"%(error)s") % {'pod': name, 'error': e})
|
||||
|
@ -211,11 +211,11 @@ class KubeClient(object):
|
|||
|
||||
return True
|
||||
|
||||
def pod_get(self, master_address, uuid):
|
||||
def pod_get(self, api_address, uuid):
|
||||
LOG.debug("pod_get %s" % uuid)
|
||||
try:
|
||||
out = utils.execute('kubectl', 'get', 'pod', uuid,
|
||||
'-s', master_address)
|
||||
'-s', api_address)
|
||||
# TODO(pkilambi): process the output as needed
|
||||
return out
|
||||
except Exception as e:
|
||||
|
@ -223,11 +223,11 @@ class KubeClient(object):
|
|||
% {'pod': uuid, 'error': e})
|
||||
return None
|
||||
|
||||
def pod_show(self, master_address, uuid):
|
||||
def pod_show(self, api_address, uuid):
|
||||
LOG.debug("pod_show %s" % uuid)
|
||||
try:
|
||||
out = utils.execute('kubectl', 'describe', 'pod', uuid,
|
||||
'-s', master_address)
|
||||
'-s', api_address)
|
||||
# TODO(pkilambi): process the output as needed
|
||||
return out
|
||||
except Exception as e:
|
||||
|
@ -236,10 +236,10 @@ class KubeClient(object):
|
|||
return None
|
||||
|
||||
# Replication Controller Operations
|
||||
def rc_create(self, master_address, rc):
|
||||
def rc_create(self, api_address, rc):
|
||||
LOG.debug("rc_create contents %s" % rc)
|
||||
try:
|
||||
out, err = _k8s_create(master_address, rc)
|
||||
out, err = _k8s_create(api_address, rc)
|
||||
|
||||
if err:
|
||||
return False
|
||||
|
@ -249,10 +249,10 @@ class KubeClient(object):
|
|||
return False
|
||||
return True
|
||||
|
||||
def rc_update(self, master_address, rc):
|
||||
def rc_update(self, api_address, rc):
|
||||
LOG.debug("rc_update contents %s" % rc)
|
||||
try:
|
||||
out, err = _k8s_update(master_address, rc)
|
||||
out, err = _k8s_update(api_address, rc)
|
||||
|
||||
if err:
|
||||
return False
|
||||
|
@ -262,11 +262,11 @@ class KubeClient(object):
|
|||
return False
|
||||
return True
|
||||
|
||||
def rc_delete(self, master_address, name):
|
||||
def rc_delete(self, api_address, name):
|
||||
LOG.debug("rc_delete %s" % name)
|
||||
try:
|
||||
out, err = utils.trycmd('kubectl', 'delete', 'rc', name,
|
||||
'-s', master_address)
|
||||
'-s', api_address)
|
||||
if err:
|
||||
return False
|
||||
except Exception as e:
|
||||
|
|
|
@ -60,9 +60,9 @@ def _retrieve_k8s_master_url(context, obj):
|
|||
params = {
|
||||
'k8s_protocol': cfg.CONF.kubernetes.k8s_protocol,
|
||||
'k8s_port': apiserver_port,
|
||||
'master_address': obj.master_address
|
||||
'api_address': obj.api_address
|
||||
}
|
||||
return "%(k8s_protocol)s://%(master_address)s:%(k8s_port)s" % params
|
||||
return "%(k8s_protocol)s://%(api_address)s:%(k8s_port)s" % params
|
||||
|
||||
|
||||
def _object_has_stack(context, obj):
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
# 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.
|
||||
"""rename-bay-master-address
|
||||
|
||||
Revision ID: 29affeaa2bc2
|
||||
Revises: 2d1354bbf76e
|
||||
Create Date: 2015-03-25 16:06:08.148629
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '29affeaa2bc2'
|
||||
down_revision = '2d1354bbf76e'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.alter_column('bay', 'master_address',
|
||||
new_column_name='api_address',
|
||||
existing_type=sa.String(255))
|
|
@ -126,8 +126,8 @@ class Connection(api.Connection):
|
|||
query = query.filter_by(node_count=filters['node_count'])
|
||||
if 'stack_id' in filters:
|
||||
query = query.filter_by(stack_id=filters['stack_id'])
|
||||
if 'master_address' in filters:
|
||||
query = query.filter_by(master_address=filters['master_address'])
|
||||
if 'api_address' in filters:
|
||||
query = query.filter_by(api_address=filters['api_address'])
|
||||
if 'minions_address' in filters:
|
||||
query = query.filter_by(minions_address=filters['minions_address'])
|
||||
if 'project_id' in filters:
|
||||
|
|
|
@ -125,7 +125,7 @@ class Bay(Base):
|
|||
name = Column(String(255))
|
||||
baymodel_id = Column(String(255))
|
||||
stack_id = Column(String(255))
|
||||
master_address = Column(String(255))
|
||||
api_address = Column(String(255))
|
||||
minions_address = Column(JSONEncodedList)
|
||||
node_count = Column(Integer())
|
||||
status = Column(String(20), nullable=True)
|
||||
|
|
|
@ -50,7 +50,7 @@ class Bay(base.MagnumObject):
|
|||
# UPDATE_IN_PROGRESS|UPDATE_FAILED|UPDATED
|
||||
# DELETE_IN_PROGRESS|DELETE_FAILED|DELETED
|
||||
'status': obj_utils.str_or_none,
|
||||
'master_address': obj_utils.str_or_none,
|
||||
'api_address': obj_utils.str_or_none,
|
||||
'minions_address': obj_utils.list_or_none,
|
||||
'node_count': obj_utils.int_or_none
|
||||
}
|
||||
|
|
|
@ -28,39 +28,39 @@ class TestKubeUtils(base.BaseTestCase):
|
|||
def test_k8s_create_data(self,
|
||||
mock_create_with_data):
|
||||
expected_data = 'data'
|
||||
master_address = 'master_address'
|
||||
api_address = 'api_address'
|
||||
mock_resource = mock.MagicMock()
|
||||
mock_resource.manifest = expected_data
|
||||
mock_resource.manifest_url = None
|
||||
|
||||
kube_utils._k8s_create(master_address, mock_resource)
|
||||
mock_create_with_data.assert_called_once_with(master_address,
|
||||
kube_utils._k8s_create(api_address, mock_resource)
|
||||
mock_create_with_data.assert_called_once_with(api_address,
|
||||
expected_data)
|
||||
|
||||
@patch('magnum.conductor.handlers.common.kube_utils._k8s_create_with_path')
|
||||
def test_k8s_create_url(self,
|
||||
mock_create_with_path):
|
||||
expected_url = 'url'
|
||||
master_address = 'master_address'
|
||||
api_address = 'api_address'
|
||||
mock_resource = mock.MagicMock()
|
||||
mock_resource.manifest = None
|
||||
mock_resource.manifest_url = expected_url
|
||||
|
||||
kube_utils._k8s_create(master_address, mock_resource)
|
||||
mock_create_with_path.assert_called_once_with(master_address,
|
||||
kube_utils._k8s_create(api_address, mock_resource)
|
||||
mock_create_with_path.assert_called_once_with(api_address,
|
||||
expected_url)
|
||||
|
||||
@patch('magnum.openstack.common.utils.trycmd')
|
||||
def test_k8s_create_with_path(self, mock_trycmd):
|
||||
expected_master_address = 'master_address'
|
||||
expected_api_address = 'api_address'
|
||||
expected_pod_file = 'pod_file'
|
||||
expected_command = [
|
||||
'kubectl', 'create',
|
||||
'-s', expected_master_address,
|
||||
'-s', expected_api_address,
|
||||
'-f', expected_pod_file
|
||||
]
|
||||
|
||||
kube_utils._k8s_create_with_path(expected_master_address,
|
||||
kube_utils._k8s_create_with_path(expected_api_address,
|
||||
expected_pod_file)
|
||||
mock_trycmd.assert_called_once_with(*expected_command)
|
||||
|
||||
|
@ -69,7 +69,7 @@ class TestKubeUtils(base.BaseTestCase):
|
|||
def test_k8s_create_with_data(self,
|
||||
mock_named_tempfile,
|
||||
mock_k8s_create):
|
||||
expected_master_address = 'master_address'
|
||||
expected_api_address = 'api_address'
|
||||
expected_data = 'resource_data'
|
||||
expected_filename = 'resource_file'
|
||||
|
||||
|
@ -77,50 +77,50 @@ class TestKubeUtils(base.BaseTestCase):
|
|||
mock_file.name = expected_filename
|
||||
mock_named_tempfile.return_value.__enter__.return_value = mock_file
|
||||
|
||||
kube_utils._k8s_create_with_data(expected_master_address,
|
||||
kube_utils._k8s_create_with_data(expected_api_address,
|
||||
expected_data)
|
||||
|
||||
mock_file.write.assert_called_once_with(expected_data)
|
||||
mock_k8s_create.assert_called_once_with(expected_master_address,
|
||||
mock_k8s_create.assert_called_once_with(expected_api_address,
|
||||
expected_filename)
|
||||
|
||||
@patch('magnum.conductor.handlers.common.kube_utils._k8s_update_with_data')
|
||||
def test_k8s_update_data(self,
|
||||
mock_update_with_data):
|
||||
expected_data = 'data'
|
||||
master_address = 'master_address'
|
||||
api_address = 'api_address'
|
||||
mock_resource = mock.MagicMock()
|
||||
mock_resource.manifest = expected_data
|
||||
mock_resource.manifest_url = None
|
||||
|
||||
kube_utils._k8s_update(master_address, mock_resource)
|
||||
mock_update_with_data.assert_called_once_with(master_address,
|
||||
kube_utils._k8s_update(api_address, mock_resource)
|
||||
mock_update_with_data.assert_called_once_with(api_address,
|
||||
expected_data)
|
||||
|
||||
@patch('magnum.conductor.handlers.common.kube_utils._k8s_update_with_path')
|
||||
def test_k8s_update_url(self,
|
||||
mock_update_with_path):
|
||||
expected_url = 'url'
|
||||
master_address = 'master_address'
|
||||
api_address = 'api_address'
|
||||
mock_resource = mock.MagicMock()
|
||||
mock_resource.manifest = None
|
||||
mock_resource.manifest_url = expected_url
|
||||
|
||||
kube_utils._k8s_update(master_address, mock_resource)
|
||||
mock_update_with_path.assert_called_once_with(master_address,
|
||||
kube_utils._k8s_update(api_address, mock_resource)
|
||||
mock_update_with_path.assert_called_once_with(api_address,
|
||||
expected_url)
|
||||
|
||||
@patch('magnum.openstack.common.utils.trycmd')
|
||||
def test_k8s_update_with_path(self, mock_trycmd):
|
||||
expected_master_address = 'master_address'
|
||||
expected_api_address = 'api_address'
|
||||
expected_pod_file = 'pod_file'
|
||||
expected_command = [
|
||||
'kubectl', 'update',
|
||||
'-s', expected_master_address,
|
||||
'-s', expected_api_address,
|
||||
'-f', expected_pod_file
|
||||
]
|
||||
|
||||
kube_utils._k8s_update_with_path(expected_master_address,
|
||||
kube_utils._k8s_update_with_path(expected_api_address,
|
||||
expected_pod_file)
|
||||
mock_trycmd.assert_called_once_with(*expected_command)
|
||||
|
||||
|
@ -129,7 +129,7 @@ class TestKubeUtils(base.BaseTestCase):
|
|||
def test_k8s_update_with_data(self,
|
||||
mock_named_tempfile,
|
||||
mock_k8s_update):
|
||||
expected_master_address = 'master_address'
|
||||
expected_api_address = 'api_address'
|
||||
expected_data = 'resource_data'
|
||||
expected_filename = 'resource_file'
|
||||
|
||||
|
@ -137,11 +137,11 @@ class TestKubeUtils(base.BaseTestCase):
|
|||
mock_file.name = expected_filename
|
||||
mock_named_tempfile.return_value.__enter__.return_value = mock_file
|
||||
|
||||
kube_utils._k8s_update_with_data(expected_master_address,
|
||||
kube_utils._k8s_update_with_data(expected_api_address,
|
||||
expected_data)
|
||||
|
||||
mock_file.write.assert_called_once_with(expected_data)
|
||||
mock_k8s_update.assert_called_once_with(expected_master_address,
|
||||
mock_k8s_update.assert_called_once_with(expected_api_address,
|
||||
expected_filename)
|
||||
|
||||
|
||||
|
@ -152,75 +152,75 @@ class KubeClientTestCase(base.TestCase):
|
|||
|
||||
@patch('magnum.openstack.common.utils.trycmd')
|
||||
def test_pod_delete(self, mock_trycmd):
|
||||
expected_master_address = 'master-address'
|
||||
expected_api_address = 'master-address'
|
||||
expected_pod_name = 'test-pod'
|
||||
expected_command = [
|
||||
'kubectl', 'delete', 'pod', expected_pod_name,
|
||||
'-s', expected_master_address
|
||||
'-s', expected_api_address
|
||||
]
|
||||
mock_trycmd.return_value = ("", "")
|
||||
|
||||
result = self.kube_client.pod_delete(expected_master_address,
|
||||
result = self.kube_client.pod_delete(expected_api_address,
|
||||
expected_pod_name)
|
||||
self.assertTrue(result)
|
||||
mock_trycmd.assert_called_once_with(*expected_command)
|
||||
|
||||
@patch('magnum.openstack.common.utils.trycmd')
|
||||
def test_pod_delete_failure_err_not_empty(self, mock_trycmd):
|
||||
expected_master_address = 'master-address'
|
||||
expected_api_address = 'master-address'
|
||||
expected_pod_name = 'test-pod'
|
||||
expected_command = [
|
||||
'kubectl', 'delete', 'pod', expected_pod_name,
|
||||
'-s', expected_master_address
|
||||
'-s', expected_api_address
|
||||
]
|
||||
mock_trycmd.return_value = ("", "error")
|
||||
|
||||
result = self.kube_client.pod_delete(expected_master_address,
|
||||
result = self.kube_client.pod_delete(expected_api_address,
|
||||
expected_pod_name)
|
||||
self.assertFalse(result)
|
||||
mock_trycmd.assert_called_once_with(*expected_command)
|
||||
|
||||
@patch('magnum.openstack.common.utils.trycmd')
|
||||
def test_pod_delete_failure_exception(self, mock_trycmd):
|
||||
expected_master_address = 'master-address'
|
||||
expected_api_address = 'master-address'
|
||||
expected_pod_name = 'test-pod'
|
||||
expected_command = [
|
||||
'kubectl', 'delete', 'pod', expected_pod_name,
|
||||
'-s', expected_master_address
|
||||
'-s', expected_api_address
|
||||
]
|
||||
mock_trycmd.side_effect = Exception()
|
||||
|
||||
result = self.kube_client.pod_delete(expected_master_address,
|
||||
result = self.kube_client.pod_delete(expected_api_address,
|
||||
expected_pod_name)
|
||||
self.assertFalse(result)
|
||||
mock_trycmd.assert_called_once_with(*expected_command)
|
||||
|
||||
@patch('magnum.openstack.common.utils.trycmd')
|
||||
def test_pod_delete_not_found_old(self, mock_trycmd):
|
||||
expected_master_address = 'master-address'
|
||||
expected_api_address = 'master-address'
|
||||
expected_pod_name = 'test-pod'
|
||||
expected_command = [
|
||||
'kubectl', 'delete', 'pod', expected_pod_name,
|
||||
'-s', expected_master_address
|
||||
'-s', expected_api_address
|
||||
]
|
||||
mock_trycmd.return_value = ("", 'pod "test-pod" not found')
|
||||
|
||||
self.assertRaises(exception.PodNotFound, self.kube_client.pod_delete,
|
||||
expected_master_address, expected_pod_name)
|
||||
expected_api_address, expected_pod_name)
|
||||
|
||||
mock_trycmd.assert_called_once_with(*expected_command)
|
||||
|
||||
@patch('magnum.openstack.common.utils.trycmd')
|
||||
def test_pod_delete_not_found_new(self, mock_trycmd):
|
||||
expected_master_address = 'master-address'
|
||||
expected_api_address = 'master-address'
|
||||
expected_pod_name = 'test-pod'
|
||||
expected_command = [
|
||||
'kubectl', 'delete', 'pod', expected_pod_name,
|
||||
'-s', expected_master_address
|
||||
'-s', expected_api_address
|
||||
]
|
||||
mock_trycmd.return_value = ("", 'pods "test-pod" not found')
|
||||
|
||||
self.assertRaises(exception.PodNotFound, self.kube_client.pod_delete,
|
||||
expected_master_address, expected_pod_name)
|
||||
expected_api_address, expected_pod_name)
|
||||
|
||||
mock_trycmd.assert_called_once_with(*expected_command)
|
||||
|
|
|
@ -46,7 +46,7 @@ class TestBayK8sHeat(base.TestCase):
|
|||
'baymodel_id': 'xx-xx-xx-xx',
|
||||
'name': 'bay1',
|
||||
'stack_id': 'xx-xx-xx-xx',
|
||||
'master_address': '172.17.2.3',
|
||||
'api_address': '172.17.2.3',
|
||||
'minions_address': ['172.17.2.4'],
|
||||
'node_count': 1,
|
||||
}
|
||||
|
@ -372,11 +372,11 @@ class TestBayK8sHeat(base.TestCase):
|
|||
self.assertEqual(expected, bay_definition)
|
||||
|
||||
def test_parse_stack_outputs(self):
|
||||
expected_master_address = 'master_address'
|
||||
expected_api_address = 'api_address'
|
||||
expected_minion_address = ['minion', 'address']
|
||||
expected_minion_external_address = ['ex_minion', 'address']
|
||||
expected_return_value = {
|
||||
'kube_master': expected_master_address,
|
||||
'kube_master': expected_api_address,
|
||||
'kube_minions': expected_minion_address,
|
||||
'kube_minions_external': expected_minion_external_address
|
||||
}
|
||||
|
@ -393,7 +393,7 @@ class TestBayK8sHeat(base.TestCase):
|
|||
"output_key": "kube_minions"
|
||||
},
|
||||
{
|
||||
"output_value": expected_master_address,
|
||||
"output_value": expected_api_address,
|
||||
"description": "No description given",
|
||||
"output_key": "kube_master"
|
||||
}
|
||||
|
|
|
@ -69,14 +69,14 @@ class TestKube(base.TestCase):
|
|||
mock_baymodel_get_by_uuid,
|
||||
mock_bay_get_by_uuid):
|
||||
expected_context = 'context'
|
||||
expected_master_address = 'master_address'
|
||||
expected_api_address = 'api_address'
|
||||
expected_baymodel_id = 'e74c40e0-d825-11e2-a28f-0800200c9a61'
|
||||
expected_apiserver_port = 9999
|
||||
|
||||
pod = self.mock_pod()
|
||||
pod.bay_uuid = 'bay_uuid'
|
||||
bay = self.mock_bay()
|
||||
bay.master_address = expected_master_address
|
||||
bay.api_address = expected_api_address
|
||||
bay.baymodel_id = expected_baymodel_id
|
||||
baymodel = self.mock_baymodel()
|
||||
baymodel.apiserver_port = expected_apiserver_port
|
||||
|
@ -84,11 +84,11 @@ class TestKube(base.TestCase):
|
|||
mock_bay_get_by_uuid.return_value = bay
|
||||
mock_baymodel_get_by_uuid.return_value = baymodel
|
||||
|
||||
actual_master_address = kube._retrieve_k8s_master_url(expected_context,
|
||||
actual_api_address = kube._retrieve_k8s_master_url(expected_context,
|
||||
pod)
|
||||
self.assertEqual("http://%s:%d" % (expected_master_address,
|
||||
self.assertEqual("http://%s:%d" % (expected_api_address,
|
||||
expected_apiserver_port),
|
||||
actual_master_address)
|
||||
actual_api_address)
|
||||
|
||||
@patch('magnum.objects.Bay.get_by_uuid')
|
||||
@patch('magnum.objects.BayModel.get_by_uuid')
|
||||
|
@ -96,7 +96,7 @@ class TestKube(base.TestCase):
|
|||
mock_baymodel_get_by_uuid,
|
||||
mock_bay_get_by_uuid):
|
||||
expected_context = 'context'
|
||||
expected_master_address = 'master_address'
|
||||
expected_api_address = 'api_address'
|
||||
expected_baymodel_id = 'e74c40e0-d825-11e2-a28f-0800200c9a61'
|
||||
expected_protocol = cfg.CONF.kubernetes.k8s_protocol
|
||||
expected_apiserver_port = cfg.CONF.kubernetes.k8s_port
|
||||
|
@ -104,7 +104,7 @@ class TestKube(base.TestCase):
|
|||
resource = self.mock_pod()
|
||||
resource.bay_uuid = 'bay_uuid'
|
||||
bay = self.mock_bay()
|
||||
bay.master_address = expected_master_address
|
||||
bay.api_address = expected_api_address
|
||||
bay.baymodel_id = expected_baymodel_id
|
||||
baymodel = self.mock_baymodel()
|
||||
baymodel.apiserver_port = None
|
||||
|
@ -112,17 +112,17 @@ class TestKube(base.TestCase):
|
|||
mock_bay_get_by_uuid.return_value = bay
|
||||
mock_baymodel_get_by_uuid.return_value = baymodel
|
||||
|
||||
actual_master_address = kube._retrieve_k8s_master_url(expected_context,
|
||||
actual_api_address = kube._retrieve_k8s_master_url(expected_context,
|
||||
resource)
|
||||
self.assertEqual("%s://%s:%d" % (expected_protocol,
|
||||
expected_master_address,
|
||||
expected_api_address,
|
||||
expected_apiserver_port),
|
||||
actual_master_address)
|
||||
actual_api_address)
|
||||
|
||||
@patch('magnum.conductor.handlers.kube._retrieve_k8s_master_url')
|
||||
def test_pod_create_with_success(self,
|
||||
mock_retrieve_k8s_master_url):
|
||||
expected_master_url = 'master_address'
|
||||
expected_master_url = 'api_address'
|
||||
expected_pod = self.mock_pod()
|
||||
expected_pod.create = mock.MagicMock()
|
||||
|
||||
|
@ -136,7 +136,7 @@ class TestKube(base.TestCase):
|
|||
@patch('magnum.conductor.handlers.kube._retrieve_k8s_master_url')
|
||||
def test_pod_create_with_fail(self,
|
||||
mock_retrieve_k8s_master_url):
|
||||
expected_master_url = 'master_address'
|
||||
expected_master_url = 'api_address'
|
||||
expected_pod = self.mock_pod()
|
||||
expected_pod.create = mock.MagicMock()
|
||||
|
||||
|
@ -154,7 +154,7 @@ class TestKube(base.TestCase):
|
|||
mock_pod_get_by_uuid,
|
||||
mock_retrieve_k8s_master_url,
|
||||
mock_object_has_stack):
|
||||
expected_master_url = 'master_address'
|
||||
expected_master_url = 'api_address'
|
||||
mock_pod = mock.MagicMock()
|
||||
mock_pod.name = 'test-pod'
|
||||
mock_pod.uuid = 'test-uuid'
|
||||
|
@ -178,7 +178,7 @@ class TestKube(base.TestCase):
|
|||
mock_pod_get_by_uuid,
|
||||
mock_retrieve_k8s_master_url,
|
||||
mock_object_has_stack):
|
||||
expected_master_url = 'master_address'
|
||||
expected_master_url = 'api_address'
|
||||
mock_pod = mock.MagicMock()
|
||||
mock_pod.name = 'test-pod'
|
||||
mock_pod.uuid = 'test-uuid'
|
||||
|
@ -202,7 +202,7 @@ class TestKube(base.TestCase):
|
|||
mock_pod_get_by_uuid,
|
||||
mock_retrieve_k8s_master_url,
|
||||
mock_object_has_stack):
|
||||
expected_master_url = 'master_address'
|
||||
expected_master_url = 'api_address'
|
||||
mock_pod = mock.MagicMock()
|
||||
mock_pod.name = 'test-pod'
|
||||
mock_pod.uuid = 'test-uuid'
|
||||
|
@ -222,7 +222,7 @@ class TestKube(base.TestCase):
|
|||
@patch('magnum.conductor.handlers.kube._retrieve_k8s_master_url')
|
||||
def test_service_create_with_success(self,
|
||||
mock_retrieve_k8s_master_url):
|
||||
expected_master_url = 'master_address'
|
||||
expected_master_url = 'api_address'
|
||||
expected_service = self.mock_service()
|
||||
expected_service.create = mock.MagicMock()
|
||||
|
||||
|
@ -241,7 +241,7 @@ class TestKube(base.TestCase):
|
|||
mock_service_get_by_uuid,
|
||||
mock_retrieve_k8s_master_url,
|
||||
mock_object_has_stack):
|
||||
expected_master_url = 'master_address'
|
||||
expected_master_url = 'api_address'
|
||||
mock_service = mock.MagicMock()
|
||||
mock_service.name = 'test-service'
|
||||
mock_service.uuid = 'test-uuid'
|
||||
|
@ -265,7 +265,7 @@ class TestKube(base.TestCase):
|
|||
mock_service_get_by_uuid,
|
||||
mock_retrieve_k8s_master_url,
|
||||
mock_object_has_stack):
|
||||
expected_master_url = 'master_address'
|
||||
expected_master_url = 'api_address'
|
||||
mock_service = mock.MagicMock()
|
||||
mock_service.name = 'test-service'
|
||||
mock_service.uuid = 'test-uuid'
|
||||
|
@ -285,7 +285,7 @@ class TestKube(base.TestCase):
|
|||
@patch('magnum.conductor.handlers.kube._retrieve_k8s_master_url')
|
||||
def test_rc_create_with_success(self,
|
||||
mock_retrieve_k8s_master_url):
|
||||
expected_master_url = 'master_address'
|
||||
expected_master_url = 'api_address'
|
||||
expected_rc = self.mock_rc()
|
||||
expected_rc.create = mock.MagicMock()
|
||||
|
||||
|
@ -304,7 +304,7 @@ class TestKube(base.TestCase):
|
|||
mock_rc_get_by_uuid,
|
||||
mock_retrieve_k8s_master_url,
|
||||
mock_object_has_stack):
|
||||
expected_master_url = 'master_address'
|
||||
expected_master_url = 'api_address'
|
||||
mock_rc = mock.MagicMock()
|
||||
mock_rc.name = 'test-rc'
|
||||
mock_rc.uuid = 'test-uuid'
|
||||
|
|
|
@ -59,7 +59,7 @@ def get_test_bay(**kw):
|
|||
'e74c40e0-d825-11e2-a28f-0800200c9a66'),
|
||||
'stack_id': kw.get('stack_id', '047c6319-7abd-4bd9-a033-8c6af0173cd0'),
|
||||
'status': kw.get('status', 'CREATE_IN_PROGRESS'),
|
||||
'master_address': kw.get('master_address', '172.17.2.3'),
|
||||
'api_address': kw.get('api_address', '172.17.2.3'),
|
||||
'minions_address': kw.get('minions_address', ['172.17.2.4']),
|
||||
'node_count': kw.get('node_count', 3),
|
||||
'created_at': kw.get('created_at'),
|
||||
|
|
Loading…
Reference in New Issue