diff --git a/manila/share/drivers/service_instance.py b/manila/share/drivers/service_instance.py index b2d90c8850..a28a5121eb 100644 --- a/manila/share/drivers/service_instance.py +++ b/manila/share/drivers/service_instance.py @@ -78,6 +78,11 @@ share_servers_handling_mode_opts = [ default="manila_service_network", help="Name of manila service network. Used only with Neutron. " "Only used if driver_handles_share_servers=True."), + cfg.HostAddressOpt( + "service_network_host", + sample_default="", + help="Hostname to be used for service network binding. Used only with " + "Neutron and if driver_handles_share_servers=True."), cfg.StrOpt( "service_network_cidr", default="10.254.0.0/16", @@ -1020,7 +1025,7 @@ class NeutronNetworkHelper(BaseNetworkhelper): This port will be used for connectivity with service instances. """ - host = CONF.host + host = self.get_config_option("service_network_host") or CONF.host search_opts = {'device_id': device_id, 'binding:host_id': host} ports = [port for port in self.neutron_api. diff --git a/manila/tests/share/drivers/test_service_instance.py b/manila/tests/share/drivers/test_service_instance.py index f0a356eca0..2a94281fb1 100644 --- a/manila/tests/share/drivers/test_service_instance.py +++ b/manila/tests/share/drivers/test_service_instance.py @@ -45,8 +45,6 @@ def fake_get_config_option(key): return None elif key == 'service_instance_user': return 'fake_user' - elif key == 'service_network_name': - return 'fake_service_network_name' elif key == 'service_instance_flavor_id': return '100' elif key == 'service_instance_name_template': @@ -67,6 +65,8 @@ def fake_get_config_option(key): return '99.254.0.0/24' elif key == 'service_network_division_mask': return 27 + elif key == 'service_network_host': + return 'fake_service_network_host' elif key == 'service_network_name': return 'fake_service_network_name' elif key == 'interface_driver': @@ -2161,7 +2161,7 @@ class NeutronNetworkHelperTestCase(test.TestCase): instance = self._init_neutron_network_plugin() admin_project_id = 'fake_admin_project_id' fake_port_values = {'device_id': 'manila-share', - 'binding:host_id': 'fake-host'} + 'binding:host_id': 'fake_service_network_host'} self.mock_object( service_instance.neutron.API, 'admin_project_id', mock.Mock(return_value=admin_project_id)) @@ -2182,14 +2182,15 @@ class NeutronNetworkHelperTestCase(test.TestCase): instance.neutron_api.create_port.assert_called_once_with( instance.admin_project_id, instance.service_network_id, device_id='manila-share', device_owner='manila:share', - host_id='fake-host', subnet_id=None, port_security_enabled=False) + host_id='fake_service_network_host', + subnet_id=None, port_security_enabled=False) self.assertFalse(instance.neutron_api.update_port_fixed_ips.called) self.assertEqual(fake_service_port, result) def test__get_service_port_one_exist_on_same_host(self): instance = self._init_neutron_network_plugin() fake_port_values = {'device_id': 'manila-share', - 'binding:host_id': 'fake-host'} + 'binding:host_id': 'fake_service_network_host'} fake_service_port = fake_network.FakePort(**fake_port_values) self.flags(host='fake-host') self.mock_object(instance.neutron_api, 'list_ports', @@ -2208,7 +2209,9 @@ class NeutronNetworkHelperTestCase(test.TestCase): self.assertFalse(instance.neutron_api.update_port_fixed_ips.called) self.assertEqual(fake_service_port, result) - def test__get_service_port_one_exist_on_different_host(self): + def test__get_service_port_default_host(self): + self.mock_object(self.fake_manager, 'get_config_option', + mock.Mock(return_value=None)) instance = self._init_neutron_network_plugin() admin_project_id = 'fake_admin_project_id' fake_port = {'device_id': 'manila-share', @@ -2225,6 +2228,32 @@ class NeutronNetworkHelperTestCase(test.TestCase): self.mock_object(instance.neutron_api, 'update_port_fixed_ips', mock.Mock(return_value=fake_service_port)) + result = instance._get_service_port(instance.service_network_id, + None, 'manila-share') + instance.neutron_api.create_port.assert_called_once_with( + instance.admin_project_id, instance.service_network_id, + device_id='manila-share', device_owner='manila:share', + host_id='fake-host', subnet_id=None, + port_security_enabled=False) + self.assertEqual(fake_service_port, result) + + def test__get_service_port_one_exist_on_different_host(self): + instance = self._init_neutron_network_plugin() + admin_project_id = 'fake_admin_project_id' + fake_port = {'device_id': 'manila-share', + 'binding:host_id': 'fake_service_network_host'} + self.mock_object( + service_instance.neutron.API, 'admin_project_id', + mock.Mock(return_value=admin_project_id)) + fake_service_port = fake_network.FakePort(**fake_port) + self.mock_object(instance.neutron_api, 'list_ports', + mock.Mock(return_value=[])) + self.flags(host='fake-host') + self.mock_object(instance.neutron_api, 'create_port', + mock.Mock(return_value=fake_service_port)) + self.mock_object(instance.neutron_api, 'update_port_fixed_ips', + mock.Mock(return_value=fake_service_port)) + result = instance._get_service_port(instance.service_network_id, None, 'manila-share') @@ -2233,7 +2262,8 @@ class NeutronNetworkHelperTestCase(test.TestCase): instance.neutron_api.create_port.assert_called_once_with( instance.admin_project_id, instance.service_network_id, device_id='manila-share', device_owner='manila:share', - host_id='fake-host', subnet_id=None, port_security_enabled=False) + host_id='fake_service_network_host', subnet_id=None, + port_security_enabled=False) self.assertFalse(instance.neutron_api.update_port_fixed_ips.called) self.assertEqual(fake_service_port, result) diff --git a/releasenotes/notes/new-config-option-dhss-4931db193fd76656.yaml b/releasenotes/notes/new-config-option-dhss-4931db193fd76656.yaml new file mode 100644 index 0000000000..4145275272 --- /dev/null +++ b/releasenotes/notes/new-config-option-dhss-4931db193fd76656.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Add new config option 'service_network_host' for service instance with + 'dhss'=True. This helps us to define network host for ports and able to + seperate from manila host.