diff --git a/manila/share/drivers/netapp/dataontap/client/client_cmode.py b/manila/share/drivers/netapp/dataontap/client/client_cmode.py index 73a275ca..a070bd17 100644 --- a/manila/share/drivers/netapp/dataontap/client/client_cmode.py +++ b/manila/share/drivers/netapp/dataontap/client/client_cmode.py @@ -307,9 +307,11 @@ class NetAppCmodeClient(client_base.NetAppBaseClient): lif_name_template): """Creates LIF on VLAN port.""" - self._create_vlan(node, port, vlan) + home_port_name = port + if vlan: + self._create_vlan(node, port, vlan) + home_port_name = '%(port)s-%(tag)s' % {'port': port, 'tag': vlan} - vlan_interface_name = '%(port)s-%(tag)s' % {'port': port, 'tag': vlan} interface_name = (lif_name_template % {'node': node, 'net_allocation_id': allocation_id}) @@ -324,7 +326,7 @@ class NetAppCmodeClient(client_base.NetAppBaseClient): {'data-protocol': 'cifs'}, ], 'home-node': node, - 'home-port': vlan_interface_name, + 'home-port': home_port_name, 'netmask': netmask, 'interface-name': interface_name, 'role': 'data', @@ -357,14 +359,16 @@ class NetAppCmodeClient(client_base.NetAppBaseClient): def network_interface_exists(self, vserver_name, node, port, ip, netmask, vlan): """Checks if LIF exists.""" - vlan_interface_name = '%(port)s-%(tag)s' % {'port': port, 'tag': vlan} + + home_port_name = (port if not vlan else + '%(port)s-%(tag)s' % {'port': port, 'tag': vlan}) api_args = { 'query': { 'net-interface-info': { 'address': ip, 'home-node': node, - 'home-port': vlan_interface_name, + 'home-port': home_port_name, 'netmask': netmask, 'vserver': vserver_name, }, @@ -400,7 +404,7 @@ class NetAppCmodeClient(client_base.NetAppBaseClient): protocols = na_utils.convert_to_list(protocols) protocols = [protocol.lower() for protocol in protocols] - args = { + api_args = { 'query': { 'net-interface-info': { 'data-protocols': { @@ -410,7 +414,7 @@ class NetAppCmodeClient(client_base.NetAppBaseClient): } } if protocols else None - result = self.send_request('net-interface-get-iter', args) + result = self.send_request('net-interface-get-iter', api_args) lif_info_list = result.get_child_by_name( 'attributes-list') or netapp_api.NaElement('none') diff --git a/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py b/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py index 056ed4e9..ef9bd76c 100644 --- a/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py +++ b/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py @@ -549,6 +549,35 @@ class NetAppClientCmodeTestCase(test.TestCase): self.client.send_request.assert_has_calls([ mock.call('net-interface-create', lif_create_args)]) + def test_create_network_interface_no_vlan(self): + + self.mock_object(self.client, '_create_vlan') + self.mock_object(self.client, 'send_request') + + lif_create_args = { + 'address': fake.IP_ADDRESS, + 'administrative-status': 'up', + 'data-protocols': [ + {'data-protocol': 'nfs'}, + {'data-protocol': 'cifs'} + ], + 'home-node': fake.NODE_NAME, + 'home-port': fake.PORT, + 'netmask': fake.NETMASK, + 'interface-name': fake.LIF_NAME, + 'role': 'data', + 'vserver': fake.VSERVER_NAME, + } + self.client.create_network_interface(fake.IP_ADDRESS, fake.NETMASK, + None, fake.NODE_NAME, + fake.PORT, fake.VSERVER_NAME, + fake.NET_ALLOCATION_ID, + fake.LIF_NAME_TEMPLATE) + + self.assertFalse(self.client._create_vlan.called) + self.client.send_request.assert_has_calls([ + mock.call('net-interface-create', lif_create_args)]) + def test_create_vlan(self): self.mock_object(self.client, 'send_request') @@ -635,10 +664,26 @@ class NetAppClientCmodeTestCase(test.TestCase): 'send_request', mock.Mock(return_value=api_response)) + net_interface_get_args = { + 'query': { + 'net-interface-info': { + 'address': fake.IP_ADDRESS, + 'home-node': fake.NODE_NAME, + 'home-port': fake.PORT, + 'netmask': fake.NETMASK, + 'vserver': fake.VSERVER_NAME} + }, + 'desired-attributes': { + 'net-interface-info': { + 'interface-name': None, + } + } + } result = self.client.network_interface_exists( fake.VSERVER_NAME, fake.NODE_NAME, fake.PORT, fake.IP_ADDRESS, - fake.NETMASK, fake.VLAN) - + fake.NETMASK, None) + self.client.send_request.assert_has_calls([ + mock.call('net-interface-get-iter', net_interface_get_args)]) self.assertFalse(result) def test_list_network_interfaces(self):