From 8e55830a8280cbf4c86d5aa360a2d883ab58cf54 Mon Sep 17 00:00:00 2001 From: Zhijiang Hu Date: Thu, 10 Aug 2017 09:55:44 -0400 Subject: [PATCH] Rectify host_add request's body usage Please see https://jira.opnfv.org/browse/DAISY-57 Change-Id: I16d540710fc3638bedbb2bc9f719fe55fc2f07fc Signed-off-by: Zhijiang Hu --- code/daisy/daisy/api/v1/hosts.py | 39 +- code/daisy/daisy/db/sqlalchemy/api.py | 6 +- code/daisy/daisy/registry/api/v1/hosts.py | 2 +- code/daisy/daisy/tests/api/test_hosts.py | 338 ++++++++++-------- .../daisy/tests/db/sqlalchemy/test_db_api.py | 71 ++-- code/daisyclient/daisyclient/v1/hosts.py | 25 +- .../daisy_tempest/v1/test_discover_host.py | 16 +- test/tempest/daisy_tempest/v1/test_host.py | 57 +++ 8 files changed, 296 insertions(+), 258 deletions(-) create mode 100755 test/tempest/daisy_tempest/v1/test_host.py diff --git a/code/daisy/daisy/api/v1/hosts.py b/code/daisy/daisy/api/v1/hosts.py index d12b4c0b..1a5fff77 100755 --- a/code/daisy/daisy/api/v1/hosts.py +++ b/code/daisy/daisy/api/v1/hosts.py @@ -362,8 +362,8 @@ class Controller(controller.BaseController): def _check_add_host_interfaces(self, req, host_meta): host_meta_interfaces = [] - if host_meta.get('interfaces') and eval(host_meta['interfaces']): - host_meta_interfaces = list(eval(host_meta['interfaces'])) + if host_meta.get('interfaces') and host_meta['interfaces']: + host_meta_interfaces = list(host_meta['interfaces']) else: msg = "No Interface in host, host_meta is: %s" % host_meta LOG.error(msg) @@ -537,9 +537,6 @@ class Controller(controller.BaseController): host_interfaces = (host_meta.get('interfaces') or orig_host_meta.get('interfaces')) if host_interfaces: - if not isinstance(host_interfaces, list): - host_interfaces = eval(host_interfaces) - has_dvs = utils.get_dvs_interfaces(host_interfaces) if has_dvs: if (('hugepages' in host_meta and @@ -578,7 +575,7 @@ class Controller(controller.BaseController): role_list = registry.get_roles_detail(req.context, **params) for role_name in role_list: if role_name['cluster_id'] == host_meta['cluster']: - host_roles = list(eval(host_meta['role'])) + host_roles = list(host_meta['role']) for host_role in host_roles: if role_name['name'] == host_role: role_id_list.append(role_name['id']) @@ -639,11 +636,6 @@ class Controller(controller.BaseController): request=req, content_type="text/plain") - for discov_keyword in ['cpu', 'system', 'memory', - 'pci', 'disks', 'devices']: - if host_meta.get(discov_keyword): - host_meta[discov_keyword] = eval(host_meta.get(discov_keyword)) - host_meta = registry.add_host_metadata(req.context, host_meta) return {'host_meta': host_meta} @@ -825,7 +817,6 @@ class Controller(controller.BaseController): raise HTTPBadRequest(explanation=msg) def _count_host_pxe_info(self, interfaces): - interfaces = eval(interfaces) input_host_pxe_info = [ interface for interface in interfaces if interface.get( 'is_deployment', @@ -866,7 +857,6 @@ class Controller(controller.BaseController): :return: """ # verify interface among the input host - interfaces = eval(interfaces) same_mac_list = [interface1['name'] for interface1 in interfaces for interface2 in interfaces @@ -933,7 +923,7 @@ class Controller(controller.BaseController): for id in [host['id'] for host in all_hosts]: host_meta_list = registry.get_host_metadata(req.context, id) exist_nodes.append(host_meta_list) - interfaces = list(eval(host_meta['interfaces'])) + interfaces = list(host_meta['interfaces']) for host_interface in interfaces: host_mac = host_interface.get('mac', None) if not host_mac: @@ -1013,7 +1003,6 @@ class Controller(controller.BaseController): dhcp_ip_ranges = template_deploy_network[0]['ip_ranges'] deployment_interface_count = 0 - host_meta['interfaces'] = eval(host_meta['interfaces']) for interface in host_meta['interfaces']: if 'ip' in interface and interface['ip']: ip_in_cidr = utils.is_ip_in_cidr(interface['ip'], @@ -1034,7 +1023,6 @@ class Controller(controller.BaseController): msg = "error, find more than one dhcp ip" LOG.error(msg) raise HTTPBadRequest(explanation=msg) - host_meta['interfaces'] = unicode(host_meta['interfaces']) def _get_os_version(self, host_meta, orig_host_meta): # os_version_file and os_version_id only exist one at same time @@ -1184,9 +1172,6 @@ class Controller(controller.BaseController): if not interfaces: return None - if not isinstance(interfaces, list): - interfaces = eval(interfaces) - for interface in interfaces: if name == interface.get('name'): return interface @@ -1247,7 +1232,7 @@ class Controller(controller.BaseController): cluster_id = orig_cluster_id if 'interfaces' in host_meta: - host_meta_interfaces = list(eval(host_meta['interfaces'])) + host_meta_interfaces = list(host_meta['interfaces']) ether_nic_names_list = list() bond_nic_names_list = list() bond_slaves_lists = list() @@ -1381,7 +1366,7 @@ class Controller(controller.BaseController): orig_host_meta) new_mac_list = [] if "interfaces" in host_meta: - interfaces = eval(host_meta['interfaces']) + interfaces = host_meta['interfaces'] new_mac_list = [interface['mac'] for interface in interfaces if interface.get('mac')] if orig_mac_list: @@ -1471,7 +1456,7 @@ class Controller(controller.BaseController): boot_partition_m = 400 redundant_partiton_m = 600 if host_meta.get('role', None): - host_role_names = eval(host_meta['role']) + host_role_names = host_meta['role'] elif orig_host_meta.get('role', None): host_role_names = orig_host_meta['role'] else: @@ -1578,7 +1563,7 @@ class Controller(controller.BaseController): boot_partition_m = 400 redundant_partiton_m = 600 if host_meta.get('role', None): - host_role_names = eval(host_meta['role']) + host_role_names = host_meta['role'] elif orig_host_meta.get('role', None): host_role_names = orig_host_meta['role'] else: @@ -1720,7 +1705,7 @@ class Controller(controller.BaseController): host_roles = list() for role_name in role_list: if role_name['cluster_id'] == host_meta['cluster']: - host_roles = list(eval(host_meta['role'])) + host_roles = list(host_meta['role']) for host_role in host_roles: if role_name['name'] == host_role: role_id_list.append(role_name['id']) @@ -1897,12 +1882,6 @@ class Controller(controller.BaseController): daisy_cmn.add_ssh_host_to_cluster_and_assigned_network( req, host_meta['cluster'], id) - for discov_keyword in ['cpu', 'system', 'memory', - 'pci', 'disks', 'devices']: - if host_meta.get(discov_keyword): - host_meta[discov_keyword] = eval( - host_meta.get(discov_keyword)) - host_meta = registry.update_host_metadata(req.context, id, host_meta) diff --git a/code/daisy/daisy/db/sqlalchemy/api.py b/code/daisy/daisy/db/sqlalchemy/api.py index f6c359b4..3d16369e 100755 --- a/code/daisy/daisy/db/sqlalchemy/api.py +++ b/code/daisy/daisy/db/sqlalchemy/api.py @@ -710,10 +710,12 @@ def _host_update(context, values, host_id): delete_assigned_networks( context, host_interface_info.id, session) delete_host_interface(context, host_id, session) + if isinstance(values['interfaces'], list): orig_keys = values['interfaces'] else: - orig_keys = list(eval(values['interfaces'])) + orig_keys = list(values['interfaces']) + for host_interface_info in orig_keys: if (host_interface_info.has_key('assigned_networks') and host_interface_info['assigned_networks']): @@ -851,7 +853,7 @@ def _host_update(context, values, host_id): host_ref = _modify_os_version(values["os_version"], host_ref) if values.has_key('interfaces'): - orig_keys = list(eval(values['interfaces'])) + orig_keys = list(values['interfaces']) for network in orig_keys: host_interface_ref = models.HostInterface() host_interfaces_values = network.copy() diff --git a/code/daisy/daisy/registry/api/v1/hosts.py b/code/daisy/daisy/registry/api/v1/hosts.py index 67208b53..613b0617 100755 --- a/code/daisy/daisy/registry/api/v1/hosts.py +++ b/code/daisy/daisy/registry/api/v1/hosts.py @@ -479,7 +479,7 @@ class Controller(object): @utils.mutating def get_host_interface(self, req, body): - orig_interfaces = list(eval(body['interfaces'])) + orig_interfaces = list(body['interfaces']) for orig_interface in orig_interfaces: host_interface = self.db_api.get_host_interface_mac( req.context, orig_interface['mac']) diff --git a/code/daisy/daisy/tests/api/test_hosts.py b/code/daisy/daisy/tests/api/test_hosts.py index a53ea7b1..7620092e 100755 --- a/code/daisy/daisy/tests/api/test_hosts.py +++ b/code/daisy/daisy/tests/api/test_hosts.py @@ -1292,15 +1292,14 @@ class TestHostsApiConfig(test.TestCase): "deleted": None} host_meta = { "cluster": "111111111111-22222222222-3333333333333", - u'interfaces': u"""[ + "interfaces": [ {u'type': u'bond', u'name': u'bond0', u'slave2': u'enp_slave2', u'vswitch_type': u'dvs,sriov(direct)', u'slave1': u'enp_slave1', u'assigned_networks': [{u'ip': u'', u'name': u'physnet1'}], - u'slaves': { u'enp_slave1', - u'enp_slave2'} + u'slaves': {u'enp_slave1', u'enp_slave2'} }, {u'type': u'ether', u'name': u'enp_slave1', @@ -1311,7 +1310,7 @@ class TestHostsApiConfig(test.TestCase): u'name': u'enp_slave2', u'vswitch_type': u'', u'pci': u'0000:84:00.2', - u'is_support_vf': False}]"""} + u'is_support_vf': False}]} mock_get_host_meta_or_404.return_value = orig_host_meta self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update_host, @@ -1329,7 +1328,7 @@ class TestHostsApiConfig(test.TestCase): "deleted": None} host_meta = { "cluster": "111111111111-22222222222-3333333333333", - u'interfaces': u"""[ + "interfaces": [ {u'type': u'ether', u'name': u'enp_slave1', u'vswitch_type': u'dvs,sriov(direct)', @@ -1339,7 +1338,7 @@ class TestHostsApiConfig(test.TestCase): u'name': u'enp_slave2', u'vswitch_type': u'', u'pci': u'0000:84:00.2', - u'is_support_vf': False}]"""} + u'is_support_vf': False}]} mock_get_host_meta_or_404.return_value = orig_host_meta self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update_host, @@ -1357,7 +1356,7 @@ class TestHostsApiConfig(test.TestCase): "deleted": None} host_meta = { "cluster": "111111111111-22222222222-3333333333333", - u'interfaces': u"""[ + "interfaces": [ {u'type': u'ether', u'name': u'enp_slave1', u'vswitch_type': u'dvs,sriov(macvtap)', @@ -1367,7 +1366,7 @@ class TestHostsApiConfig(test.TestCase): u'name': u'enp_slave2', u'vswitch_type': u'', u'pci': u'0000:84:00.2', - u'is_support_vf': False}]"""} + u'is_support_vf': False}]} mock_get_host_meta_or_404.return_value = orig_host_meta self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update_host, @@ -1385,7 +1384,7 @@ class TestHostsApiConfig(test.TestCase): "deleted": None} host_meta = { "cluster": "111111111111-22222222222-3333333333333", - u'interfaces': u"""[ + "interfaces": [ {u'type': u'ether', u'name': u'enp_slave1', u'vswitch_type': u'dvs,sriov(direct)', @@ -1394,7 +1393,7 @@ class TestHostsApiConfig(test.TestCase): {u'type': u'ether', u'name': u'enp_slave2', u'vswitch_type': u'', - u'is_support_vf': False}]"""} + u'is_support_vf': False}]} mock_get_host_meta_or_404.return_value = orig_host_meta self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update_host, @@ -1410,7 +1409,7 @@ class TestHostsApiConfig(test.TestCase): "deleted": None} host_meta = { "cluster": "111111111111-22222222222-3333333333333", - u'interfaces': u"""[ + "interfaces": [ {u'type': u'bond', u'name': u'enp_slave1', u'vswitch_type': u'dvs,sriov(direct)', @@ -1419,8 +1418,8 @@ class TestHostsApiConfig(test.TestCase): {u'type': u'ether', u'name': u'enp_slave2', u'vswitch_type': u'', - u'pci': u'0000:84:00.2', - u'is_support_vf': False}]"""} + u'pci': u'0000:84:00.2', + u'is_support_vf': False}]} self.assertRaises(webob.exc.HTTPForbidden, self.controller._check_interface_on_update_host, req, host_meta, orig_host_meta) @@ -1653,58 +1652,11 @@ class TestHostsApiConfig(test.TestCase): def test_check_interface_on_update_host(self): host_id = "fe604c80-b5a0-4454-bbfd-2295ad8f1e5d" req = fakes.HTTPRequest.blank('/nodes/%s' % host_id) - host_meta = {"cluster": "111111-222222-333333", - "interfaces": """[ - { - "name": "enp3s0f0", - "is_deployment": False, - "deleted": False, - "ip": "192.168.1.8", - "is_vf": False, - "mac": "4c:09:b4:b0:ac:4b", - "netmask": "255.255.255.0", - "vswitch_type": "", - "state": "up", - "pci": "0000: 03: 00.0", - "current_speed": "100Mb/s", - "assigned_networks": [ - ], - "max_speed": "1000baseT/Full", - "host_id": "f2af88bf-a336-4e90-9c2b-cbb11638e580", - "type": "ether", - "is_support_vf": False - }, - { - "name": "enp3s0f1", - "is_deployment": False, - "deleted": False, - "ip": "10.43.203.224", - "is_vf": False, - "mac": "4c:09:b4:b0:ac:4c", - "netmask": "255.255.254.0", - "vswitch_type": "", - "state": "up", - "pci": "0000: 03: 00.1", - "current_speed": "100Mb/s", - "assigned_networks": [ - ], - "max_speed": "1000baseT/Full", - "host_id": "f2af88bf-a336-4e90-9c2b-cbb11638e580", - "type": "ether", - "is_support_vf": False - }, - { - "mode": "active-backup;off", - "type": "bond", - "name": "bond0", - "slave1":"enp3s0f0", - "slave2":"enp3s0f1", - "bond_type": "dvs/sr-iov/ovs" - } ]"""} - orig_host_meta = { - "cluster": "test_host", - "interfaces": - [{ + + host_meta = { + "cluster": "111111-222222-333333", + "interfaces": [ + { "name": "enp3s0f0", "is_deployment": False, "deleted": False, @@ -1716,13 +1668,13 @@ class TestHostsApiConfig(test.TestCase): "state": "up", "pci": "0000: 03: 00.0", "current_speed": "100Mb/s", - "assigned_networks": [ - ], + "assigned_networks": [], "max_speed": "1000baseT/Full", "host_id": "f2af88bf-a336-4e90-9c2b-cbb11638e580", "type": "ether", "is_support_vf": False - }, { + }, + { "name": "enp3s0f1", "is_deployment": False, "deleted": False, @@ -1734,13 +1686,63 @@ class TestHostsApiConfig(test.TestCase): "state": "up", "pci": "0000: 03: 00.1", "current_speed": "100Mb/s", - "assigned_networks": [ - ], + "assigned_networks": [], "max_speed": "1000baseT/Full", "host_id": "f2af88bf-a336-4e90-9c2b-cbb11638e580", "type": "ether", "is_support_vf": False - }]} + }, + { + "mode": "active-backup;off", + "type": "bond", + "name": "bond0", + "slave1": "enp3s0f0", + "slave2": "enp3s0f1", + "bond_type": "dvs/sr-iov/ovs" + } + ]} + + orig_host_meta = { + "cluster": "test_host", + "interfaces": [ + { + "name": "enp3s0f0", + "is_deployment": False, + "deleted": False, + "ip": "192.168.1.8", + "is_vf": False, + "mac": "4c:09:b4:b0:ac:4b", + "netmask": "255.255.255.0", + "vswitch_type": "", + "state": "up", + "pci": "0000: 03: 00.0", + "current_speed": "100Mb/s", + "assigned_networks": [], + "max_speed": "1000baseT/Full", + "host_id": "f2af88bf-a336-4e90-9c2b-cbb11638e580", + "type": "ether", + "is_support_vf": False + }, + { + "name": "enp3s0f1", + "is_deployment": False, + "deleted": False, + "ip": "10.43.203.224", + "is_vf": False, + "mac": "4c:09:b4:b0:ac:4c", + "netmask": "255.255.254.0", + "vswitch_type": "", + "state": "up", + "pci": "0000: 03: 00.1", + "current_speed": "100Mb/s", + "assigned_networks": [], + "max_speed": "1000baseT/Full", + "host_id": "f2af88bf-a336-4e90-9c2b-cbb11638e580", + "type": "ether", + "is_support_vf": False + } + ]} + mac_list = ["4c:09:b4:b0:ac:4c", "4c:09:b4:b0:ac:4b"] result = self.controller.\ _check_interface_on_update_host(req, host_meta, orig_host_meta) @@ -1765,21 +1767,28 @@ class TestHostsApiConfig(test.TestCase): host_meta = { 'cluster': '1', 'interfaces': - "[{'name': 'enp3s2','ip': '192.168.1.2'," - "'mac': '00:23:cd:96:53:96','pci': '0000:03:02.0'," - "'assigned_networks': []," - "'host_id': '1','type': 'ether'}," - "{'name': 'bond0','bond_type': ''," - "'mode': 'active-backup;off'," - "'slaves': ['enp2s0', 'enp3s2']," - "'assigned_networks':[{'ip': '192.168.1.5'," - "'name': 'PUBLICAPI'}],'host_id': '1','type': 'bond'}," - "{'name': 'enp2s0','ip': '10.43.178.21'," - "'mac': '00:24:21:74:8a:56','pci': '0000:02:00.0'," - "'assigned_networks': [],'host_id': '1'," - "'type': 'ether'}, {'name': 'enp3s1', " - "'mac': '00:23:cd:96:53:97', 'pci': '0000:03:02.1', " - "'type': 'ether'}]"} + [{'name': 'enp3s2', 'ip': '192.168.1.2', + 'mac': '00:23:cd:96:53:96', 'pci': '0000:03:02.0', + 'assigned_networks': [], + 'host_id': '1', 'type': 'ether'}, + {'name': 'bond0', 'bond_type': '', + 'mode': 'active-backup;off', + 'slaves': ['enp2s0', 'enp3s2'], + 'assigned_networks': + [{'ip': '192.168.1.5', + 'name': 'PUBLICAPI'}], + 'host_id': '1', 'type': 'bond'}, + {'name': 'enp2s0', + 'ip': '10.43.178.21', + 'mac': '00:24:21:74:8a:56', + 'pci': '0000:02:00.0', + 'assigned_networks': [], + 'host_id': '1', + 'type': 'ether'}, + {'name': 'enp3s1', + 'mac': '00:23:cd:96:53:97', 'pci': '0000:03:02.1', + 'type': 'ether'}]} + orig_host_meta = {'status': 'in-cluster', 'discover_mode': 'PXE', 'cluster_name': 'cluster_1', @@ -1804,6 +1813,7 @@ class TestHostsApiConfig(test.TestCase): {'mac': '00:24:21:74:8a:57', 'pci': '0000:02:00.1', 'is_deployment': True}]} + mock_get_clusters_detail.return_value = [{'id': '1', 'name': 'cluster_1'}] mock_get_cluster_network.return_value = [{'name': 'PUBLICAPI', @@ -1832,45 +1842,51 @@ class TestHostsApiConfig(test.TestCase): host_meta = { 'cluster': '1', 'interfaces': - "[{'name': 'enp3s2','ip': '192.168.1.2'," - "'mac': '00:23:cd:96:53:96','pci': '0000:03:02.0'," - "'assigned_networks': []," - "'host_id': '1','type': 'ether'}," - "{'name': 'bond0','bond_type': 'linux'," - "'mode': 'active-backup;off'," - "'slaves': ['enp2s0', 'enp3s2']," - "'assigned_networks':[{'name': 'physnet1'}]," - "'host_id': '1','type': 'bond'}," - "{'name': 'enp2s0','ip': '10.43.178.21'," - "'mac': '00:24:21:74:8a:56','pci': '0000:02:00.0'," - "'assigned_networks': [],'host_id': '1'," - "'type': 'ether'}, {'name': 'enp3s1', " - "'mac': '00:23:cd:96:53:97', 'pci': '0000:03:02.1', " - "'type': 'ether'}]"} - orig_host_meta = {'status': 'in-cluster', - 'discover_mode': 'PXE', - 'cluster_name': 'cluster_1', - 'os_status': 'active', - 'root_disk': 'sda', - 'root_lv_size': 102400, - 'swap_lv_size': 51200, - 'root_pwd': 'ossdbg1', - 'isolcpus': '', - 'deleted': 0, - 'interfaces': [{'name': 'enp3s2', - 'mac': '00:23:cd:96:53:96', - 'pci': '0000:03:02.0', - 'is_deployment': ''}, - {'name': 'bond0', - 'mac': '', - 'pci': '', - 'is_deployment': ''}, - {'mac': '00:24:21:74:8a:56', - 'pci': '0000:02:00.0', - 'is_deployment': ''}, - {'mac': '00:24:21:74:8a:57', - 'pci': '0000:02:00.1', - 'is_deployment': True}]} + [{'name': 'enp3s2', 'ip': '192.168.1.2', + 'mac': '00:23:cd:96:53:96', + 'pci': '0000:03:02.0', + 'assigned_networks': [], + 'host_id': '1', 'type': 'ether'}, + {'name': 'bond0', 'bond_type': 'linux', + 'mode': 'active-backup;off', + 'slaves': ['enp2s0', 'enp3s2'], + 'assigned_networks': [{'name': 'physnet1'}], + 'host_id': '1', 'type': 'bond'}, + {'name': 'enp2s0', 'ip': '10.43.178.21', + 'mac': '00:24:21:74:8a:56', + 'pci': '0000:02:00.0', + 'assigned_networks': [], 'host_id': '1', + 'type': 'ether'}, + {'name': 'enp3s1', + 'mac': '00:23:cd:96:53:97', + 'pci': '0000:03:02.1', + 'type': 'ether'}]} + orig_host_meta = { + 'status': 'in-cluster', + 'discover_mode': 'PXE', + 'cluster_name': 'cluster_1', + 'os_status': 'active', + 'root_disk': 'sda', + 'root_lv_size': 102400, + 'swap_lv_size': 51200, + 'root_pwd': 'ossdbg1', + 'isolcpus': '', + 'deleted': 0, + 'interfaces': + [{'name': 'enp3s2', + 'mac': '00:23:cd:96:53:96', + 'pci': '0000:03:02.0', + 'is_deployment': ''}, + {'name': 'bond0', + 'mac': '', + 'pci': '', + 'is_deployment': ''}, + {'mac': '00:24:21:74:8a:56', + 'pci': '0000:02:00.0', + 'is_deployment': ''}, + {'mac': '00:24:21:74:8a:57', + 'pci': '0000:02:00.1', + 'is_deployment': True}]} mock_get_clusters_detail.return_value = [{'id': '1', 'name': 'cluster_1'}] mock_get_cluster_network.return_value = [{'name': 'DATAPLANE', @@ -2044,21 +2060,25 @@ class TestHostsApiConfig(test.TestCase): 'cluster': '1', 'dmi_uuid': '03000200-0400-0500-0006-000700080009', 'interfaces': - "[{'name': 'enp132s0f2292','ip': '192.168.1.2'," - "'mac': '4c:09:b4:b2:80:8c','pci': '0000:03:02.0'," - "'assigned_networks': []," - "'host_id': '1','type': 'ether'}," - "{'name': 'bond0','bond_type': ''," - "'mode': 'active-backup;off'," - "'slaves': ['enp2s0', 'enp132s0f2292']," - "'assigned_networks':[{'ip': '192.168.1.5'," - "'name': 'PUBLICAPI'}],'host_id': '1','type': 'bond'}," - "{'name': 'enp2s0','ip': '10.43.178.21'," - "'mac': '00:24:21:74:8a:56','pci': '0000:02:00.0'," - "'assigned_networks': [],'host_id': '1'," - "'type': 'ether'}, {'name': 'enp3s1', " - "'mac': '00:23:cd:96:53:97', 'pci': '0000:03:02.1', " - "'type': 'ether'}]"} + [{'name': 'enp132s0f2292', 'ip': '192.168.1.2', + 'mac': '4c:09:b4:b2:80:8c', 'pci': '0000:03:02.0', + 'assigned_networks': [], + 'host_id': '1', 'type': 'ether'}, + {'name': 'bond0', 'bond_type': '', + 'mode': 'active-backup;off', + 'slaves': ['enp2s0', 'enp132s0f2292'], + 'assigned_networks': + [{'ip': '192.168.1.5', + 'name': 'PUBLICAPI'}], + 'host_id': '1', 'type': 'bond'}, + {'name': 'enp2s0', 'ip': '10.43.178.21', + 'mac': '00:24:21:74:8a:56', 'pci': '0000:02:00.0', + 'assigned_networks': [], 'host_id': '1', + 'type': 'ether'}, + {'name': 'enp3s1', + 'mac': '00:23:cd:96:53:97', + 'pci': '0000:03:02.1', + 'type': 'ether'}]} req = webob.Request.blank('/') req.context = RequestContext(is_admin=True, user='fake user', @@ -2113,22 +2133,24 @@ class TestHostsApiConfig(test.TestCase): 'root_disk': 'sda', 'os_status': 'init', 'interfaces': - "[{'name': 'enp132s0f2292','ip': '192.168.1.2'," - "'mac': '4c:09:b4:b2:80:8c','pci': '0000:03:02.0'," - "'assigned_networks': []," - "'host_id': '1','type': 'ether'}," - "{'name': 'bond0','bond_type': ''," - "'mode': 'active-backup;off'," - "'slaves': ['enp2s0', 'enp132s0f2292']," - "'assigned_networks':[{'ip': '192.168.1.5'," - "'name': 'PUBLICAPI'}],'host_id': '1'," - "'type': 'bond'}," - "{'name': 'enp2s0','ip': '10.43.178.21'," - "'mac': '00:24:21:74:8a:56','pci': '0000:02:00.0'," - "'assigned_networks': [],'host_id': '1'," - "'type': 'ether'}, {'name': 'enp3s1', " - "'mac': '00:23:cd:96:53:97', 'pci': '0000:03:02.1', " - "'type': 'ether'}]", + [{'name': 'enp132s0f2292', 'ip': '192.168.1.2', + 'mac': '4c:09:b4:b2:80:8c', 'pci': '0000:03:02.0', + 'assigned_networks': [], + 'host_id': '1', 'type': 'ether'}, + {'name': 'bond0', 'bond_type': '', + 'mode': 'active-backup;off', + 'slaves': ['enp2s0', 'enp132s0f2292'], + 'assigned_networks': [{'ip': '192.168.1.5', + 'name': 'PUBLICAPI'}], 'host_id': '1', + 'type': 'bond'}, + {'name': 'enp2s0', 'ip': '10.43.178.21', + 'mac': '00:24:21:74:8a:56', 'pci': '0000:02:00.0', + 'assigned_networks': [], + 'host_id': '1', + 'type': 'ether'}, {'name': 'enp3s1', + 'mac': '00:23:cd:96:53:97', + 'pci': '0000:03:02.1', + 'type': 'ether'}], 'disks': "{u'sda': {u'name': u'sda'," "u'extra': [u'scsi-3500003956831a6d8'," @@ -2508,6 +2530,6 @@ class TestGetClusterNetworkInfo(test.TestCase): ret = self.controller._get_interface_by_name(name, None) self.assertIsNone(ret) - intfaces = "[{'name': 'eth1'}]" - ret = self.controller._get_interface_by_name(name, intfaces) + interfaces = [{'name': 'eth1'}] + ret = self.controller._get_interface_by_name(name, interfaces) self.assertIsNone(ret) diff --git a/code/daisy/daisy/tests/db/sqlalchemy/test_db_api.py b/code/daisy/daisy/tests/db/sqlalchemy/test_db_api.py index eca56291..5813a8f1 100755 --- a/code/daisy/daisy/tests/db/sqlalchemy/test_db_api.py +++ b/code/daisy/daisy/tests/db/sqlalchemy/test_db_api.py @@ -559,20 +559,22 @@ class TestSqlalchemyApi(test.TestCase): def test_host_destroy(self): host_id = u'9692370d-7378-4ef8-9e21-1afe5cd1564a' discover_host_id = u'9692370d-7378-4ef8-9e21-1afe5cd15644' + host_meta = { u'name': u'host-192-168-1-102', u'description': u'default', u'discover_mode': u'SSH', u'dmi_uuid': u'574775DC-0000-1000-0000-744AA400B807', u'id': host_id, - u'interfaces': unicode([{u'bond_type': None, - u'ip': u'10.43.203.44', - u'is_deployment': False, - u'mac': u'a0:36:9f:91:85:a9', - u'max_speed': u'1000baseT/Full', - u'name': u'ens8f1.900', - u'netmask': u'255.255.254.0'}]), + u'interfaces': [{u'bond_type': None, + u'ip': u'10.43.203.44', + u'is_deployment': False, + u'mac': u'a0:36:9f:91:85:a9', + u'max_speed': u'1000baseT/Full', + u'name': u'ens8f1.900', + u'netmask': u'255.255.254.0'}], } + discover_host = {'status': u'DISCOVERY_SUCCESSFUL', 'ip': u'10.43.203.44', 'passwd': u'ossdbg1', @@ -917,17 +919,16 @@ class TestSqlalchemyApi(test.TestCase): u'discover_mode': u'SSH', u'dmi_uuid': u'574775DC-0000-1000-0000-744AA400B807', u'id': host_id, - u'interfaces': unicode([{u'bond_type': None, - u'ip': u'10.43.203.44', - u'is_deployment': False, - u'mac': u'a0:36:9f:91:85:a9', - u'max_speed': u'1000baseT/Full', - u'name': u'ens8f1.900', - u'netmask': u'255.255.254.0', - u'vf': [ - {'name': 'ens301', 'index': 0}]}]), + u'interfaces': [{u'bond_type': None, + u'ip': u'10.43.203.44', + u'is_deployment': False, + u'mac': u'a0:36:9f:91:85:a9', + u'max_speed': u'1000baseT/Full', + u'name': u'ens8f1.900', + u'netmask': u'255.255.254.0', + u'vf': [ + {'name': 'ens301', 'index': 0}]}], } - api.host_add(self.req.context, host_meta) ret = api.host_interfaces_get_all(self.req.context) self.assertEqual(ret[0]["host_id"], host_id) @@ -941,27 +942,27 @@ class TestSqlalchemyApi(test.TestCase): u'discover_mode': u'SSH', u'dmi_uuid': u'574775DC-0000-1000-0000-744AA400B807', u'id': host_id, - u'interfaces': unicode([{u'bond_type': None, - u'ip': u'10.43.203.44', - u'is_deployment': False, - u'mac': u'a0:36:9f:91:85:a9', - u'max_speed': u'1000baseT/Full', - u'name': u'ens8f1.900', - u'netmask': u'255.255.254.0', - u'vf': [ - {'name': 'ens301', 'index': 0}]}]), + u'interfaces': [{u'bond_type': None, + u'ip': u'10.43.203.44', + u'is_deployment': False, + u'mac': u'a0:36:9f:91:85:a9', + u'max_speed': u'1000baseT/Full', + u'name': u'ens8f1.900', + u'netmask': u'255.255.254.0', + u'vf': [ + {'name': 'ens301', 'index': 0}]}], } update_meta = { - u'interfaces': unicode([{u'bond_type': None, - u'ip': u'10.43.203.44', - u'is_deployment': False, - u'mac': u'a0:36:9f:91:85:a9', - u'max_speed': u'1000baseT/Full', - u'name': u'ens8f1.900', - u'netmask': u'255.255.254.0', - u'vf': [ - {'name': 'ens301', 'index': 1}]}]), + u'interfaces': [{u'bond_type': None, + u'ip': u'10.43.203.44', + u'is_deployment': False, + u'mac': u'a0:36:9f:91:85:a9', + u'max_speed': u'1000baseT/Full', + u'name': u'ens8f1.900', + u'netmask': u'255.255.254.0', + u'vf': [ + {'name': 'ens301', 'index': 1}]}], } api.host_add(self.req.context, host_meta) diff --git a/code/daisyclient/daisyclient/v1/hosts.py b/code/daisyclient/daisyclient/v1/hosts.py index a3c302a7..dc4b52de 100755 --- a/code/daisyclient/daisyclient/v1/hosts.py +++ b/code/daisyclient/daisyclient/v1/hosts.py @@ -265,11 +265,9 @@ class HostManager(base.ManagerWithFind): msg = 'create() got an unexpected keyword argument \'%s\'' raise TypeError(msg % field) - hdrs = self._host_meta_to_headers(fields) - resp, body = self.client.post('/v1/nodes', headers=None, - data=hdrs) + data=fields) return_request_id = kwargs.get('return_req_id', None) if return_request_id is not None: return_request_id.append(resp.headers.get(OS_REQ_ID_HDR, None)) @@ -289,7 +287,6 @@ class HostManager(base.ManagerWithFind): TODO(bcwaldon): document accepted params """ - hdrs = {} fields = {} for field in kwargs: if field in UPDATE_PARAMS: @@ -300,10 +297,8 @@ class HostManager(base.ManagerWithFind): # msg = 'update() got an unexpected keyword argument \'%s\'' # raise TypeError(msg % field) - hdrs.update(self._host_meta_to_headers(fields)) - url = '/v1/nodes/%s' % base.getid(host) - resp, body = self.client.put(url, headers=None, data=hdrs) + resp, body = self.client.put(url, headers=None, data=fields) return_request_id = kwargs.get('return_req_id', None) if return_request_id is not None: return_request_id.append(resp.headers.get(OS_REQ_ID_HDR, None)) @@ -314,16 +309,14 @@ class HostManager(base.ManagerWithFind): """discovery host TODO(bcwaldon): document accepted params """ - hdrs = {} fields = {} for field in kwargs: if field in UPDATE_PARAMS: fields[field] = kwargs[field] elif field == 'return_req_id': continue - hdrs.update(self._host_meta_to_headers(fields)) url = '/v1/discover_host/' - resp, body = self.client.post(url, headers=None, data=hdrs) + resp, body = self.client.post(url, headers=None, data=fields) return Host(self, self._format_host_meta_for_user(body)) @@ -346,11 +339,10 @@ class HostManager(base.ManagerWithFind): if fields.get('hwm_id'): params = self.get_min_mac(fields['hwm_id']) fields['mac'] = params.get('mac') - hdrs = self._host_meta_to_headers(fields) resp, body = self.client.post('/v1/discover/nodes', headers=None, - data=hdrs) + data=fields) return_request_id = kwargs.get('return_req_id', None) if return_request_id is not None: @@ -445,7 +437,6 @@ class HostManager(base.ManagerWithFind): TODO(bcwaldon): document accepted params """ - hdrs = {} fields = {} for field in kwargs: if field in UPDATE_PARAMS: @@ -456,10 +447,8 @@ class HostManager(base.ManagerWithFind): # msg = 'update() got an unexpected keyword argument \'%s\'' # raise TypeError(msg % field) - hdrs.update(self._host_meta_to_headers(fields)) - url = '/v1/discover/nodes/%s' % base.getid(host) - resp, body = self.client.put(url, headers=None, data=hdrs) + resp, body = self.client.put(url, headers=None, data=fields) return_request_id = kwargs.get('return_req_id', None) if return_request_id is not None: return_request_id.append(resp.headers.get(OS_REQ_ID_HDR, None)) @@ -478,13 +467,11 @@ class HostManager(base.ManagerWithFind): return Host(self, self._format_host_meta_for_user(body['host'])) def host_check(self, **kwargs): - hdrs = {} fields = {} for field in kwargs: if field in CHECK_PARAMS: fields[field] = kwargs[field] elif field == 'return_req_id': continue - hdrs.update(self._host_meta_to_headers(fields)) - resp, body = self.client.post('/v1/check', headers=None, data=hdrs) + resp, body = self.client.post('/v1/check', headers=None, data=fields) return Host(self, self._format_host_meta_for_user(body['host'])) diff --git a/test/tempest/daisy_tempest/v1/test_discover_host.py b/test/tempest/daisy_tempest/v1/test_discover_host.py index 6e59fb58..d2bfcf40 100755 --- a/test/tempest/daisy_tempest/v1/test_discover_host.py +++ b/test/tempest/daisy_tempest/v1/test_discover_host.py @@ -28,12 +28,12 @@ class DaisyDiscoverHostTest(base.BaseDaisyTest): cls.host_meta = {'ip': '127.0.0.1', 'passwd': 'ossdbg1'} - def test_add_dicover_host(self): + def test_add_discover_host(self): host = self.add_discover_host(**self.host_meta) self.assertEqual("init", host.status, "add discover host failed") self.delete_discover_host(host.id) - def test_delete_dicover_host(self): + def test_delete_discover_host(self): host = self.add_discover_host(**self.host_meta) self.delete_discover_host(host.id) @@ -88,17 +88,6 @@ class DaisyDiscoverHostTest(base.BaseDaisyTest): **add_host_meta) self.assertIn("PASSWD parameter can not be None.", str(ex)) - def test_add_discover_host_with_repeat_ip(self): - # add_host_meta = {'ip': '127.0.0.2', - # 'passwd': 'ossdbg2', - # 'user': 'root'} - # host_1 = self.add_discover_host(**add_host_meta) - # ex = self.assertRaises(client_exc.HTTPForbidden, - # self.add_discover_host, **add_host_meta) - # self.assertIn("403 Forbidden: ip %s already existed." - # % add_host_meta['ip'], str(ex)) - pass - def test_discover_host(self): daisy_endpoint = "http://127.0.0.1:19292" @@ -120,6 +109,7 @@ class DaisyDiscoverHostTest(base.BaseDaisyTest): time.sleep(8) discover_flag = 'false' while 1: + time.sleep(1) print("discovring!!!!!!!!") if discover_flag == 'true': break diff --git a/test/tempest/daisy_tempest/v1/test_host.py b/test/tempest/daisy_tempest/v1/test_host.py new file mode 100755 index 00000000..96e6b01d --- /dev/null +++ b/test/tempest/daisy_tempest/v1/test_host.py @@ -0,0 +1,57 @@ +# Copyright 2012 OpenStack Foundation +# 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 copy +from daisy_tempest import base +from fake.logical_network_fake import FakeLogicNetwork as logical_fake +from fake.logical_network_fake import FakeDiscoverHosts + + +class DaisyHostTest(base.BaseDaisyTest): + + @classmethod + def resource_setup(cls): + super(DaisyHostTest, cls).resource_setup() + cls.fake = logical_fake() + + cls.host_meta = copy.deepcopy(FakeDiscoverHosts().daisy_data[0]) + cls.host_meta_interfaces = { + 'type': 'ether', + 'name': 'enp129s0f0', + 'mac': '4c:09:b4:b2:78:8a', + 'ip': '99.99.1.121', + 'netmask': '255.255.255.0', + 'is_deployment': 'True', + 'slaves': 'eth1', + 'pci': '1', + 'gateway': '99.99.1.1'} + + def test_add_host(self): + host = self.add_fake_node(0) + self.assertEqual("init", host.status, "add-host failed") + + def tearDown(self): + if self.host_meta.get('cluster', None): + del self.host_meta['cluster'] + if self.host_meta.get('role', None): + del self.host_meta['role'] + if self.host_meta.get('os_version', None): + del self.host_meta['os_version'] + if self.host_meta.get('os_status', None): + del self.host_meta['os_status'] + self._clean_all_host() + self._clean_all_cluster() + # self._clean_all_physical_node() + super(DaisyHostTest, self).tearDown()