From: Lynxzh Date: Mon, 19 May 2014 09:49:00 +0000 (+0800) Subject: BrcdFCSanLookupService should allow customize host key and policy X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=1eda138be81b2405969b80c00f30ba237e250fcd;p=openstack-build%2Fcinder-build.git BrcdFCSanLookupService should allow customize host key and policy In BrcdFCSanLookupService, the initialization should allow the customization of the known_hosts_file and missing_key_policy so that the hosts key and missing policy can be customized according to the different scenario and customer aspect. This will not change the default behavior when no argument is given, but more flexible to allow the caller to give more options according to different requirements. Closes-Bug: #1320050 Change-Id: If5767f63ccd2cde5fbea30a6154acf4d28f662b6 --- diff --git a/cinder/tests/zonemanager/test_brcd_fc_san_lookup_service.py b/cinder/tests/zonemanager/test_brcd_fc_san_lookup_service.py index 5be623320..f18b440e2 100644 --- a/cinder/tests/zonemanager/test_brcd_fc_san_lookup_service.py +++ b/cinder/tests/zonemanager/test_brcd_fc_san_lookup_service.py @@ -76,6 +76,19 @@ class TestBrcdFCSanLookupService(brcd_lookup.BrcdFCSanLookupService, config = conf.Configuration(fc_fabric_opts, 'BRCD_FAB_2') self.fabric_configs = {'BRCD_FAB_2': config} + @mock.patch.object(paramiko.hostkeys.HostKeys, 'load') + def test_create_ssh_client(self, load_mock): + mock_args = {} + mock_args['known_hosts_file'] = 'dummy_host_key_file' + mock_args['missing_key_policy'] = paramiko.RejectPolicy() + ssh_client = self.create_ssh_client(**mock_args) + self.assertEqual(ssh_client._host_keys_filename, 'dummy_host_key_file') + self.assertTrue(isinstance(ssh_client._policy, paramiko.RejectPolicy)) + mock_args = {} + ssh_client = self.create_ssh_client(**mock_args) + self.assertIsNone(ssh_client._host_keys_filename) + self.assertTrue(isinstance(ssh_client._policy, paramiko.WarningPolicy)) + @mock.patch.object(brcd_lookup.BrcdFCSanLookupService, 'get_nameserver_info') def test_get_device_mapping_from_network(self, get_nameserver_info_mock): diff --git a/cinder/zonemanager/drivers/brocade/brcd_fc_san_lookup_service.py b/cinder/zonemanager/drivers/brocade/brcd_fc_san_lookup_service.py index 5c05b52b2..d1f762e18 100644 --- a/cinder/zonemanager/drivers/brocade/brcd_fc_san_lookup_service.py +++ b/cinder/zonemanager/drivers/brocade/brcd_fc_san_lookup_service.py @@ -45,9 +45,7 @@ class BrcdFCSanLookupService(FCSanLookupService): super(BrcdFCSanLookupService, self).__init__(**kwargs) self.configuration = kwargs.get('configuration', None) self.create_configuration() - self.client = paramiko.SSHClient() - self.client.load_system_host_keys() - self.client.set_missing_host_key_policy(paramiko.WarningPolicy()) + self.client = self.create_ssh_client(**kwargs) def create_configuration(self): """Configuration specific to SAN context values.""" @@ -62,6 +60,19 @@ class BrcdFCSanLookupService(FCSanLookupService): self.fabric_configs = fabric_opts.load_fabric_configurations( fabric_names) + def create_ssh_client(self, **kwargs): + ssh_client = paramiko.SSHClient() + known_hosts_file = kwargs.get('known_hosts_file', None) + if known_hosts_file is None: + ssh_client.load_system_host_keys() + else: + ssh_client.load_host_keys(known_hosts_file) + missing_key_policy = kwargs.get('missing_key_policy', None) + if missing_key_policy is None: + missing_key_policy = paramiko.WarningPolicy() + ssh_client.set_missing_host_key_policy(missing_key_policy) + return ssh_client + def get_device_mapping_from_network(self, initiator_wwn_list, target_wwn_list):