ssh host which use host template do not need to assign IP.

Change-Id: Iab1117743da12f01aac01cab5cca1e655dfd448a
This commit is contained in:
meizhifang
2017-02-24 11:45:02 +08:00
committed by Zhijiang Hu
parent 57a43ba80f
commit 90b6a3964d
2 changed files with 60 additions and 3 deletions

View File

@@ -422,12 +422,11 @@ class Controller(controller.BaseController):
msg = "cluster name is null"
raise HTTPNotFound(explanation=msg)
if host_template.get('host_id', None):
self.get_host_meta_or_404(req, host_template['host_id'])
host_id = host_template['host_id']
orig_host_meta = self.get_host_meta_or_404(req, host_id)
else:
msg = "host id which need to template instantiate can't be null"
raise HTTPBadRequest(explanation=msg)
host_id = host_template['host_id']
orig_host_meta = registry.get_host_metadata(req.context, host_id)
path = os.path.join(os.path.abspath(os.path.dirname(
os.path.realpath(__file__))), 'ext')
for root, dirs, names in os.walk(path):
@@ -492,6 +491,9 @@ class Controller(controller.BaseController):
req,
host_template_used['cluster'],
host_id)
# ssh host add cluster and assigned network,must get new host data.
orig_host_meta = registry.get_host_metadata(req.context, host_id)
else:
if not host_template_used.get("root_disk", None):
raise HTTPBadRequest(

View File

@@ -5,6 +5,7 @@ from daisy.context import RequestContext
# import daisy.registry.client.v1.api as registry
from daisy import test
from daisy.api.v1 import host_template
import daisy.api.backends.common as daisy_cmn
# from webob.exc import HTTPNotFound
# from webob.exc import HTTPForbidden
@@ -169,3 +170,57 @@ class TestHostTemplate(test.TestCase):
actual = {
'host_template': host_detail}
self.assertEqual(actual, ret)
@mock.patch("daisy.api.v1.controller.BaseController."
"get_host_meta_or_404")
@mock.patch("daisy.registry.client.v1.api.get_host_metadata")
@mock.patch("daisy.registry.client.v1.api.host_template_lists_metadata")
@mock.patch("daisy.registry.client.v1.api.get_clusters_detail")
@mock.patch("daisy.api.v1.host_template.Controller._judge_ssh_host")
@mock.patch("daisy.registry.client.v1.api.update_host_metadata")
def test_template_to_host_with_ssh(self, mock_do_update_host_metadata,
mock_do_judge_ssh_host,
mock_do_get_clusters_detail,
mock_do_host_template_list,
mock_do_get_host_meta,
mock_do_get_host_meta_or_404):
def mock_get_host_meta_or_404(*args, **kwargs):
return host_detail
def mock_get_host_meta(*args, **kwargs):
return host_detail
def mock_host_template_lists(*args, **kwargs):
return [{'hosts': json.dumps([host_detail])}]
def mock_get_clusters_detail(*args, **kwargs):
return [{
"id": "93ca3165-1a82-4c4a-914f-65279827e46e",
"name": "test"}]
def mock_judge_ssh_host(*args, **kwargs):
return True
def mock_update_host_metadata(*args, **kwargs):
return host_detail
mock_do_update_host_metadata.side_effect = mock_update_host_metadata
mock_do_judge_ssh_host.side_effect = mock_judge_ssh_host
mock_do_get_clusters_detail.side_effect = mock_get_clusters_detail
mock_do_host_template_list.side_effect = mock_host_template_lists
mock_do_get_host_meta.side_effect = mock_get_host_meta
mock_do_get_host_meta_or_404.side_effect = mock_get_host_meta_or_404
daisy_cmn.add_ssh_host_to_cluster_and_assigned_network = \
mock.Mock(return_value={})
req = webob.Request.blank('/')
req.context = RequestContext(is_admin=True,
user='fake user',
tenant='fake tenant')
host_template = {'host_template_name': 'test',
'cluster_name': "11",
'host_id': "123"}
ret = self.controller.template_to_host(req, host_template)
actual = {
'host_template': host_detail}
self.assertEqual(actual, ret)