@mock.patch.object(rest_client.KioxiaProvisioner, 'get_backend_by_id')
@mock.patch.object(rest_client.KioxiaProvisioner, 'get_targets')
@mock.patch.object(rest_client.KioxiaProvisioner, 'get_volumes_by_uuid')
@mock.patch.object(rest_client.KioxiaProvisioner, 'publish')
@mock.patch.object(rest_client.KioxiaProvisioner, 'host_probe')
def test_initialize_connection(self, mock_host_probe, mock_publish, mock_get_volumes_by_uuid, mock_get_targets, mock_get_backend_by_id):
    testvol = _stub_volume()
    testconn = _stub_connector()
    prov_target1 = TargetEntity('target.nqn', prov_backend1)
    prov_portal = PortalEntity('1.2.3.4', 4420, 'TCP')
    backend = BackendEntity([prov_portal])
    prov_targets_response = entities.ProvisionerResponse([prov_target1])
    mock_publish.return_value = success_prov_response
    mock_host_probe.return_value = success_prov_response
    mock_get_volumes_by_uuid.return_value = prov_volumes_response
    mock_get_targets.return_value = prov_targets_response
    mock_get_backend_by_id.return_value = entities.ProvisionerResponse([backend])
    result = self.driver.initialize_connection(testvol, testconn)
    mock_host_probe.assert_any_call(testconn['nqn'], testconn['uuid'], testconn['host'], 'Agent', 'cinder-driver-0.1', 30)
    mock_publish.assert_any_call(testconn['uuid'], testvol['id'])
    mock_get_volumes_by_uuid.assert_any_call(testvol['id'])
    mock_get_targets.assert_any_call(testconn['uuid'], testvol['id'])
    mock_get_backend_by_id.assert_any_call('dummy-pid-1')
    expected_replica = {'portals': [('1.2.3.4', '4420', 'TCP')], 'target_nqn': 'target.nqn', 'vol_uuid': testvol['id']}
    expected_data = {'vol_uuid': testvol['id'], 'alias': testvol['name'], 'writable': True, 'volume_replicas': [expected_replica]}
    expected_result = {'driver_volume_type': 'nvmeof', 'data': expected_data}
    self.assertDictEqual(result, expected_result)
@mock.patch.object(rest_client.KioxiaProvisioner, 'get_backend_by_id')
@mock.patch.object(rest_client.KioxiaProvisioner, 'get_targets')
@mock.patch.object(rest_client.KioxiaProvisioner, 'get_volumes_by_uuid')
@mock.patch.object(rest_client.KioxiaProvisioner, 'publish')
@mock.patch.object(rest_client.KioxiaProvisioner, 'host_probe')
def test_initialize_connection(self, mock_host_probe, mock_publish, mock_get_volumes_by_uuid, mock_get_targets, mock_get_backend_by_id):
    testvol = _stub_volume()
    testconn = _stub_connector()
    prov_target1 = TargetEntity('target.nqn', prov_backend1)
    prov_portal = PortalEntity('1.2.3.4', 4420, 'TCP')
    backend = BackendEntity([prov_portal])
    prov_targets_response = entities.ProvisionerResponse([prov_target1])
    mock_publish.return_value = success_prov_response
    mock_host_probe.return_value = success_prov_response
    mock_get_volumes_by_uuid.return_value = prov_volumes_response
    mock_get_targets.return_value = prov_targets_response
    mock_get_backend_by_id.return_value = entities.ProvisionerResponse([backend])
    result = self.driver.initialize_connection(testvol, testconn)
    mock_host_probe.assert_any_call(testconn['nqn'], testconn['uuid'], testconn['host'], 'Agent', 'cinder-driver-0.1', 30)
    mock_publish.assert_any_call(testconn['uuid'], testvol['id'])
    mock_get_volumes_by_uuid.assert_any_call(testvol['id'])
    mock_get_targets.assert_any_call(testconn['uuid'], testvol['id'])
    mock_get_backend_by_id.assert_any_call('dummy-pid-1')
    expected_replica = {'portals': [('1.2.3.4', '4420', 'TCP')], 'target_nqn': 'target.nqn', 'vol_uuid': testvol['id']}
    expected_data = {'vol_uuid': testvol['id'], 'alias': testvol['name'], 'writable': True, 'volume_replicas': [expected_replica]}
    expected_result = {'driver_volume_type': 'nvmeof', 'data': expected_data}
    self.assertDictEqual(result, expected_result)