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):
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."""
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):