From 0c33dae152f2a33e9eb22903ea622fc5a14c69ff Mon Sep 17 00:00:00 2001
From: Caleb <yocalebo@gmail.com>
Date: Thu, 15 Jun 2023 08:53:24 -0400
Subject: [PATCH] sigh add back sys.path to some modules

---
 tests/api2/test_011_user.py                  |  6 ++++++
 tests/api2/test_012_directory_service_ssh.py | 11 +++++++++--
 tests/api2/test_030_activedirectory.py       | 11 ++++++++---
 tests/api2/test_032_ad_kerberos.py           | 12 +++++++++---
 tests/api2/test_035_ad_idmap.py              |  8 +++++++-
 tests/api2/test_036_ad_ldap.py               | 14 +++++++++++---
 tests/api2/test_040_ad_user_group_cache.py   |  8 ++++++++
 tests/api2/test_200_ftp.py                   | 17 ++++++++++-------
 tests/api2/test_261_iscsi_cmd.py             |  9 +++++++--
 tests/api2/test_275_ldap.py                  | 11 +++++++++--
 tests/api2/test_278_freeipa.py               |  8 ++++++++
 tests/api2/test_340_pool_dataset.py          |  9 ++++++++-
 tests/api2/test_425_smb_protocol.py          | 10 +++++++---
 tests/api2/test_430_smb_sharesec.py          | 11 +++++++++--
 tests/api2/test_438_snapshots.py             |  8 ++++++++
 15 files changed, 124 insertions(+), 29 deletions(-)

diff --git a/tests/api2/test_011_user.py b/tests/api2/test_011_user.py
index 2ab0471e83..7e7cda5242 100644
--- a/tests/api2/test_011_user.py
+++ b/tests/api2/test_011_user.py
@@ -1,5 +1,6 @@
 import json
 import os
+import sys
 import time
 import stat
 from contextlib import contextmanager
@@ -7,6 +8,11 @@ from contextlib import contextmanager
 import pytest
 from pytest_dependency import depends
 
+# TODO: we alreay have an assets module in middlewared.test.integration
+# so move this there to prevent the sys.path alteration nonsense.
+# This has to be done because the local assets directory isn't in python
+# PATH since these tests aren't installed as a python "package"
+sys.path.append(os.getcwd())
 from assets.REST.pool import dataset as tmp_dataset
 from functions import POST, GET, DELETE, PUT, SSH_TEST, wait_on_job
 from auto_config import pool_name, ha, password, user, ip
diff --git a/tests/api2/test_012_directory_service_ssh.py b/tests/api2/test_012_directory_service_ssh.py
index f1f80b3303..327dce5017 100644
--- a/tests/api2/test_012_directory_service_ssh.py
+++ b/tests/api2/test_012_directory_service_ssh.py
@@ -1,10 +1,17 @@
+import os
+import sys
+
 import pytest
 
 from functions import SSH_TEST
 from auto_config import hostname, ip
-from assets.REST.directory_services import active_directory, ldap, override_nameservers
 from middlewared.test.integration.utils import call
-
+# TODO: we alreay have an assets module in middlewared.test.integration
+# so move this there to prevent the sys.path alteration nonsense.
+# This has to be done because the local assets directory isn't in python
+# PATH since these tests aren't installed as a python "package"
+sys.path.append(os.getcwd())
+from assets.REST.directory_services import active_directory, ldap, override_nameservers
 try:
     from config import AD_DOMAIN, ADPASSWORD, ADUSERNAME, ADNameServer
 except ImportError:
diff --git a/tests/api2/test_030_activedirectory.py b/tests/api2/test_030_activedirectory.py
index de22e4b76e..80076282b3 100644
--- a/tests/api2/test_030_activedirectory.py
+++ b/tests/api2/test_030_activedirectory.py
@@ -1,18 +1,23 @@
 import os
+import sys
 import ipaddress
 from time import sleep
 
 import pytest
 from pytest_dependency import depends
 
-from assets.REST.directory_services import active_directory, override_nameservers
-from assets.REST.pool import dataset
+# TODO: we alreay have an assets module in middlewared.test.integration
+# so move this there to prevent the sys.path alteration nonsense.
+# This has to be done because the local assets directory isn't in python
+# PATH since these tests aren't installed as a python "package"
+sys.path.append(os.getcwd())
 from auto_config import pool_name, ip, user, password, ha
 from functions import GET, POST, SSH_TEST, make_ws_request
 from protocols import smb_connection, smb_share
 from middlewared.test.integration.assets.privilege import privilege
 from middlewared.test.integration.utils import call, client
-
+from assets.REST.directory_services import active_directory, override_nameservers
+from assets.REST.pool import dataset
 if ha and "hostname_virtual" in os.environ:
     hostname = os.environ["hostname_virtual"]
 else:
diff --git a/tests/api2/test_032_ad_kerberos.py b/tests/api2/test_032_ad_kerberos.py
index 6cfd646809..7657aba6e3 100644
--- a/tests/api2/test_032_ad_kerberos.py
+++ b/tests/api2/test_032_ad_kerberos.py
@@ -1,3 +1,5 @@
+import os
+import sys
 import time
 from calendar import timegm
 from contextlib import contextmanager
@@ -6,12 +8,16 @@ from base64 import b64decode
 import pytest
 from pytest_dependency import depends
 
-from assets.REST.directory_services import active_directory
-from assets.REST.pool import dataset
+# TODO: we alreay have an assets module in middlewared.test.integration
+# so move this there to prevent the sys.path alteration nonsense.
+# This has to be done because the local assets directory isn't in python
+# PATH since these tests aren't installed as a python "package"
+sys.path.append(os.getcwd())
 from functions import make_ws_request, PUT, POST, GET, DELETE, SSH_TEST, wait_on_job
 from auto_config import pool_name, ip, hostname, password, user
 from protocols import nfs_share
-
+from assets.REST.directory_services import active_directory
+from assets.REST.pool import dataset
 try:
     from config import AD_DOMAIN, ADPASSWORD, ADUSERNAME, ADNameServer
 except ImportError:
diff --git a/tests/api2/test_035_ad_idmap.py b/tests/api2/test_035_ad_idmap.py
index cfe7eadbbf..56df48abae 100644
--- a/tests/api2/test_035_ad_idmap.py
+++ b/tests/api2/test_035_ad_idmap.py
@@ -1,10 +1,16 @@
+import os
+import sys
 from base64 import b64decode
 import json
 from time import sleep
 
 import pytest
 from pytest_dependency import depends
-
+# TODO: we alreay have an assets module in middlewared.test.integration
+# so move this there to prevent the sys.path alteration nonsense.
+# This has to be done because the local assets directory isn't in python
+# PATH since these tests aren't installed as a python "package"
+sys.path.append(os.getcwd())
 from functions import PUT, POST, GET, DELETE, SSH_TEST, wait_on_job
 from assets.REST.directory_services import active_directory, override_nameservers
 from auto_config import dev_test, ip, hostname, password, user
diff --git a/tests/api2/test_036_ad_ldap.py b/tests/api2/test_036_ad_ldap.py
index 485e5ee533..7ca8c9ccd3 100644
--- a/tests/api2/test_036_ad_ldap.py
+++ b/tests/api2/test_036_ad_ldap.py
@@ -1,15 +1,23 @@
 from contextlib import contextmanager
+import os
+import sys
 
 import pytest
 from pytest_dependency import depends
 
-from assets.REST.directory_services import active_directory, ldap, override_nameservers
-from assets.REST.pool import dataset
+# TODO: we alreay have an assets module in middlewared.test.integration
+# so move this there to prevent the sys.path alteration nonsense.
+# This has to be done because the local assets directory isn't in python
+# PATH since these tests aren't installed as a python "package"
+sys.path.append(os.getcwd())
 from auto_config import dev_test, ip, hostname, password, pool_name, user, ha
 from functions import GET, POST, PUT, SSH_TEST, make_ws_request, wait_on_job
 from protocols import nfs_share, SSH_NFS
 from middlewared.test.integration.utils import call
-
+from middlewared.test.integration.assets.REST.pool import dataset
+from middlewared.test.integration.assets.REST.directory_services import (
+    active_directory, ldap, override_nameservers
+)
 try:
     from config import AD_DOMAIN, ADPASSWORD, ADUSERNAME, ADNameServer
 except ImportError:
diff --git a/tests/api2/test_040_ad_user_group_cache.py b/tests/api2/test_040_ad_user_group_cache.py
index 51f7700c5b..fb94876ffd 100644
--- a/tests/api2/test_040_ad_user_group_cache.py
+++ b/tests/api2/test_040_ad_user_group_cache.py
@@ -1,6 +1,14 @@
+import os
+import sys
+
 import pytest
 from pytest_dependency import depends
 
+# TODO: we alreay have an assets module in middlewared.test.integration
+# so move this there to prevent the sys.path alteration nonsense.
+# This has to be done because the local assets directory isn't in python
+# PATH since these tests aren't installed as a python "package"
+sys.path.append(os.getcwd())
 from functions import GET, SSH_TEST, wait_on_job
 from assets.REST.directory_services import active_directory, override_nameservers
 from auto_config import dev_test, ip, hostname, password, user
diff --git a/tests/api2/test_200_ftp.py b/tests/api2/test_200_ftp.py
index da9bac7100..71176f91e2 100644
--- a/tests/api2/test_200_ftp.py
+++ b/tests/api2/test_200_ftp.py
@@ -1,4 +1,5 @@
 import os
+import sys
 import json
 import contextlib
 import copy
@@ -11,14 +12,16 @@ from types import SimpleNamespace
 import pytest
 from pytest_dependency import depends
 
-from assets.REST.pool import dataset as ftp_dataset
-from functions import SSH_TEST
-from functions import make_ws_request, send_file
-from auto_config import pool_name, ha
-from auto_config import dev_test, password, user
-from protocols import ftp_connect, ftp_connection
-from protocols import ftps_connection
+# TODO: we alreay have an assets module in middlewared.test.integration
+# so move this there to prevent the sys.path alteration nonsense.
+# This has to be done because the local assets directory isn't in python
+# PATH since these tests aren't installed as a python "package"
+sys.path.append(os.getcwd())
+from functions import SSH_TEST, make_ws_request, send_file
+from auto_config import pool_name, ha, dev_test, password, user
+from protocols import ftps_connection, ftp_connect, ftp_connection
 from middlewared.test.integration.assets.account import user as ftp_user
+from middlewared.test.integration.assets.REST.pool import dataset as ftp_dataset
 # comment pytestmark for development testing with --dev-test
 pytestmark = pytest.mark.skipif(dev_test, reason='Skipping for test development testing')
 
diff --git a/tests/api2/test_261_iscsi_cmd.py b/tests/api2/test_261_iscsi_cmd.py
index 737f55becb..b2e6565d14 100644
--- a/tests/api2/test_261_iscsi_cmd.py
+++ b/tests/api2/test_261_iscsi_cmd.py
@@ -1,6 +1,7 @@
 import contextlib
 import enum
 import os
+import sys
 import random
 import socket
 import string
@@ -12,12 +13,16 @@ import pytest
 from pyscsi.pyscsi.scsi_sense import sense_ascq_dict
 from pytest_dependency import depends
 
+# TODO: we alreay have an assets module in middlewared.test.integration
+# so move this there to prevent the sys.path alteration nonsense.
+# This has to be done because the local assets directory isn't in python
+# PATH since these tests aren't installed as a python "package"
+sys.path.append(os.getcwd())
 from auto_config import dev_test, ha, hostname, isns_ip, pool_name
 from functions import DELETE, GET, POST, PUT
 from protocols import initiator_name_supported, iscsi_scsi_connection, isns_connection
-from assets.REST.pool import dataset
 from assets.REST.snapshot import snapshot, snapshot_rollback
-
+from assets.REST.pool import dataset
 if ha and "virtual_ip" in os.environ:
     ip = os.environ["virtual_ip"]
     controller1_ip = os.environ['controller1_ip']
diff --git a/tests/api2/test_275_ldap.py b/tests/api2/test_275_ldap.py
index ded184e1c8..d46a9ad6aa 100644
--- a/tests/api2/test_275_ldap.py
+++ b/tests/api2/test_275_ldap.py
@@ -1,8 +1,15 @@
+import os
+import sys
 import time
 
 import pytest
 from pytest_dependency import depends
 
+# TODO: we alreay have an assets module in middlewared.test.integration
+# so move this there to prevent the sys.path alteration nonsense.
+# This has to be done because the local assets directory isn't in python
+# PATH since these tests aren't installed as a python "package"
+sys.path.append(os.getcwd())
 from functions import (
     GET,
     PUT,
@@ -12,9 +19,9 @@ from functions import (
     cmd_test,
     wait_on_job
 )
-from middlewared.test.integration.assets.privilege import privilege
-from middlewared.test.integration.utils import call, client
+from assets.privilege import privilege
 from assets.REST.directory_services import ldap
+from middlewared.test.integration.utils import call, client
 from auto_config import pool_name, ip, user, password, dev_test
 # comment pytestmark for development testing with --dev-test
 pytestmark = pytest.mark.skipif(dev_test, reason='Skipping for test development testing')
diff --git a/tests/api2/test_278_freeipa.py b/tests/api2/test_278_freeipa.py
index 37b80788dc..d6604a1f12 100644
--- a/tests/api2/test_278_freeipa.py
+++ b/tests/api2/test_278_freeipa.py
@@ -1,6 +1,14 @@
+import os
+import sys
+
 import pytest
 from pytest_dependency import depends
 
+# TODO: we alreay have an assets module in middlewared.test.integration
+# so move this there to prevent the sys.path alteration nonsense.
+# This has to be done because the local assets directory isn't in python
+# PATH since these tests aren't installed as a python "package"
+sys.path.append(os.getcwd())
 from functions import GET, POST
 from assets.REST.directory_services import ldap
 from auto_config import dev_test
diff --git a/tests/api2/test_340_pool_dataset.py b/tests/api2/test_340_pool_dataset.py
index 9deed37d19..82158a93d9 100644
--- a/tests/api2/test_340_pool_dataset.py
+++ b/tests/api2/test_340_pool_dataset.py
@@ -1,12 +1,19 @@
+import os
+import sys
+
 import pytest
 from pytest_dependency import depends
 
+# TODO: we alreay have an assets module in middlewared.test.integration
+# so move this there to prevent the sys.path alteration nonsense.
+# This has to be done because the local assets directory isn't in python
+# PATH since these tests aren't installed as a python "package"
+sys.path.append(os.getcwd())
 from assets.REST.pool import dataset as create_dataset
 from functions import DELETE, GET, POST, PUT, SSH_TEST, wait_on_job, make_ws_request
 from auto_config import dev_test, ip, pool_name, user, password
 # comment pytestmark for development testing with --dev-test
 pytestmark = pytest.mark.skipif(dev_test, reason='Skipping for test development testing')
-
 dataset = f'{pool_name}/dataset1'
 dataset_url = dataset.replace('/', '%2F')
 zvol = f'{pool_name}/zvol1'
diff --git a/tests/api2/test_425_smb_protocol.py b/tests/api2/test_425_smb_protocol.py
index 55151b2764..bc13bb4bac 100644
--- a/tests/api2/test_425_smb_protocol.py
+++ b/tests/api2/test_425_smb_protocol.py
@@ -1,4 +1,5 @@
 import os
+import sys
 import enum
 from time import sleep
 from base64 import b64decode, b64encode
@@ -6,16 +7,19 @@ from base64 import b64decode, b64encode
 import pytest
 from pytest_dependency import depends
 
+# TODO: we alreay have an assets module in middlewared.test.integration
+# so move this there to prevent the sys.path alteration nonsense.
+# This has to be done because the local assets directory isn't in python
+# PATH since these tests aren't installed as a python "package"
+sys.path.append(os.getcwd())
 from auto_config import ip, pool_name, dev_test, user, password
 from assets.REST.pool import dataset as create_dataset
 from functions import PUT, POST, GET, DELETE, SSH_TEST
 from protocols import SMB, smb_connection, smb_share
-from samba import ntstatus
-from samba import NTSTATUSError
+from samba import ntstatus, NTSTATUSError
 # comment pytestmark for development testing with --dev-test
 pytestmark = pytest.mark.skipif(dev_test, reason='Skipping for test development testing')
 
-
 dataset = f"{pool_name}/smb-proto"
 dataset_url = dataset.replace('/', '%2F')
 SMB_NAME = "SMBPROTO"
diff --git a/tests/api2/test_430_smb_sharesec.py b/tests/api2/test_430_smb_sharesec.py
index ac7efdf865..59ba99f695 100644
--- a/tests/api2/test_430_smb_sharesec.py
+++ b/tests/api2/test_430_smb_sharesec.py
@@ -1,10 +1,17 @@
+import os
+import sys
+
 import pytest
 from pytest_dependency import depends
 
+# TODO: we alreay have an assets module in middlewared.test.integration
+# so move this there to prevent the sys.path alteration nonsense.
+# This has to be done because the local assets directory isn't in python
+# PATH since these tests aren't installed as a python "package"
+sys.path.append(os.getcwd())
 from assets.REST.pool import dataset
 from middlewared.test.integration.assets.smb import smb_share
-from functions import PUT, POST, SSH_TEST
-from functions import make_ws_request, wait_on_job
+from functions import PUT, POST, SSH_TEST, make_ws_request, wait_on_job
 from auto_config import pool_name, user, password, ip, dev_test
 # comment pytestmark for development testing with --dev-test
 pytestmark = pytest.mark.skipif(dev_test, reason='Skipping for test development testing')
diff --git a/tests/api2/test_438_snapshots.py b/tests/api2/test_438_snapshots.py
index f885b67aa5..c5ed2ffa28 100644
--- a/tests/api2/test_438_snapshots.py
+++ b/tests/api2/test_438_snapshots.py
@@ -1,5 +1,13 @@
+import os
+import sys
+
 import pytest
 
+# TODO: we alreay have an assets module in middlewared.test.integration
+# so move this there to prevent the sys.path alteration nonsense.
+# This has to be done because the local assets directory isn't in python
+# PATH since these tests aren't installed as a python "package"
+sys.path.append(os.getcwd())
 from assets.REST.pool import dataset
 from assets.REST.snapshot import snapshot
 from auto_config import dev_test, pool_name
-- 
GitLab