Merge "Add 'host' field to Pod object."

This commit is contained in:
Jenkins 2015-06-27 23:58:05 +00:00 committed by Gerrit Code Review
commit e942383e72
8 changed files with 46 additions and 2 deletions

View File

@ -55,6 +55,9 @@ class Pod(v1_base.K8sResourceBase):
links = wsme.wsattr([link.Link], readonly=True)
"""A list containing a self link and associated pod links"""
host = wtypes.text
"""The host of this pod"""
def __init__(self, **kwargs):
super(Pod, self).__init__()
@ -70,7 +73,7 @@ class Pod(v1_base.K8sResourceBase):
def _convert_with_links(pod, url, expand=True):
if not expand:
pod.unset_fields_except(['uuid', 'name', 'desc', 'bay_uuid',
'images', 'labels', 'status'])
'images', 'labels', 'status', 'host'])
pod.links = [link.Link.make_link('self', url,
'pods', pod.uuid),
@ -94,6 +97,7 @@ class Pod(v1_base.K8sResourceBase):
images=['MyImage'],
labels={'name': 'foo'},
status='Running',
host='10.0.0.3',
manifest_url='file:///tmp/rc.yaml',
manifest = '''{
"metadata": {

View File

@ -176,6 +176,7 @@ class Handler(object):
message = ast.literal_eval(err.read())['message']
raise exception.KubernetesAPIFailed(code=err.code, message=message)
pod.status = resp.status.phase
pod.host = resp.spec.host
# call the pod object to persist in db
# TODO(yuanying): parse pod file and,
# - extract pod name and set it

View File

@ -0,0 +1,32 @@
# Copyright 2015 Huawei Technologies Co.,LTD.
#
# 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.
"""add host column to pod
Revision ID: 53882537ac57
Revises: 1c1ff5e56048
Create Date: 2015-06-25 16:52:47.159887
"""
# revision identifiers, used by Alembic.
revision = '53882537ac57'
down_revision = '1c1ff5e56048'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('pod',
sa.Column('host', sa.Text, nullable=True))

View File

@ -229,6 +229,7 @@ class Pod(Base):
status = Column(String(255))
project_id = Column(String(255))
user_id = Column(String(255))
host = Column(String(255))
class Service(Base):

View File

@ -40,6 +40,7 @@ class Pod(base.MagnumPersistentObject, base.MagnumObject,
'status': fields.StringField(nullable=True),
'manifest_url': fields.StringField(nullable=True),
'manifest': fields.StringField(nullable=True),
'host': fields.StringField(nullable=True),
}
@staticmethod

View File

@ -48,7 +48,8 @@ class TestListPod(api_base.FunctionalTest):
self.assertEqual([], response['pods'])
def _assert_pod_fields(self, pod):
pod_fields = ['name', 'bay_uuid', 'desc', 'images', 'labels', 'status']
pod_fields = ['name', 'bay_uuid', 'desc', 'images', 'labels',
'status', 'host']
for field in pod_fields:
self.assertIn(field, pod)

View File

@ -136,10 +136,13 @@ class TestK8sConductor(base.TestCase):
return_value = mock.MagicMock()
return_value.status = mock.MagicMock()
return_value.status.phase = 'Pending'
return_value.spec = mock.MagicMock()
return_value.spec.host = '10.0.0.3'
mock_kube_api.return_value.createPod.return_value = return_value
self.kube_handler.pod_create(self.context, expected_pod)
self.assertEqual('Pending', expected_pod.status)
self.assertEqual('10.0.0.3', expected_pod.host)
expected_pod.create.assert_called_once_with(self.context)
@patch('magnum.conductor.handlers.k8s_conductor._retrieve_k8s_master_url')

View File

@ -97,6 +97,7 @@ def get_test_pod(**kw):
'images': kw.get('images', ['MyImage']),
'labels': kw.get('labels', {'name': 'foo'}),
'status': kw.get('status', 'Running'),
'host': kw.get('host', '10.0.0.3'),
'created_at': kw.get('created_at'),
'updated_at': kw.get('updated_at'),
}