def test_01_get_filesystem_listdir(): results = POST('/filesystem/listdir/', {'path': '/boot'}) assert results.status_code == 200, results.text assert isinstance(results.json(), list) is True, results.text assert len(results.json()) > 0, results.text global listdir listdir = results
def test_07_stop_vm(data): if nested_vm is False: pytest.skip(message) else: results = POST(f'/vm/id/{data["vmid"]}/stop/') assert results.status_code == 200, results.text assert isinstance(results.json(), bool) is True, results.text
def test_06_run_cloud_sync(env, task): result = POST(f"/cloudsync/id/{task['id']}/sync/") assert result.status_code == 200, result.text for i in range(120): result = GET(f"/cloudsync/id/{task['id']}/") assert result.status_code == 200, result.text state = result.json() if state["job"] is None: time.sleep(1) continue if state["job"]["state"] in ["PENDING", "RUNNING"]: time.sleep(1) continue assert state["job"]["state"] == "SUCCESS", state with open(os.path.join(DATASET_PATH, "freenas-test.txt")) as f: assert f.read() == "freenas-test\n" return assert False, state
def test_06_vm_status(data): if nested_vm is False: pytest.skip(message) else: results = POST(f'/vm/id/{data["vmid"]}/status/') assert results.status_code == 200, results.text status = results.json() assert isinstance(status, dict) is True, results.text
def test_01_creating_staticroute(sr_dict): results = POST('/staticroute/', { 'destination': DESTINATION, 'gateway': GATEWAY, 'description': 'test route', }) assert results.status_code == 200, results.text sr_dict['newroute'] = results.json()
def test_05_Associate_ISCSI_target(): payload = { 'target': 1, 'lunid': 1, 'extent': 1 } results = POST("/iscsi/targetextent/", payload) assert isinstance(results.json(), dict), results.text
def test_03_verify_list_resources_endpoint(): result = POST( '/jail/list_resource/', { 'resource': 'RELEASE', } ) assert isinstance(result.json(), list), result.text
def test_04_Add_ISCSI_extent(): payload = { 'type': 'FILE', 'name': 'extent', 'filesize': 536870912, 'path': f'/mnt/{pool_name}/dataset03/iscsi' } results = POST("/iscsi/extent/", payload) assert isinstance(results.json(), dict), results.text
def test_12_exec_call(): result = POST( '/jail/exec', { 'jail': JAIL_NAME, 'command': ['echo "exec successful"'] } ) assert 'exec successful' in result.json().lower(), result.text
def test_03_Add_ISCSI_target(): payload = { 'name': TARGET_NAME, 'groups': [ {'portal': 1} ] } results = POST("/iscsi/target/", payload) assert isinstance(results.json(), dict), results.text
def test_03_check_available_update(): global update_version results = POST('/update/check_available/') assert results.status_code == 200, results.text assert isinstance(results.json(), dict) is True, results.text if results.json()['status'] == 'AVAILABLE': update_version = results.json()['version'] else: update_version = None
def test_01_Create_initshutdownscript_command(initshutdowncmd_dict): results = POST('/initshutdownscript/', { 'type': 'COMMAND', 'command': TESTCMD, 'when': 'PREINIT' }) assert results.status_code == 200, results.text initshutdowncmd_dict.update(results.json()) assert isinstance(initshutdowncmd_dict['id'], int) is True
def test_03_Create_initshutdownscript_script(initshutdownsc_dict): results = POST('/initshutdownscript', { 'type': 'SCRIPT', 'script': TESTSCRIPT, 'when': 'POSTINIT' }) assert results.status_code == 200, results.text initshutdownsc_dict.update(results.json()) assert isinstance(initshutdownsc_dict['id'], int) is True
def test_01_Creating_new_cron_job_which_will_run_every_minute(cronjob_dict): results = POST('/cronjob', { 'user': '******', 'command': f'touch "{TESTFILE}"', 'schedule': {'minute': '*/1'} }) assert results.status_code == 200, results.text cronjob_dict.update(results.json()) assert isinstance(cronjob_dict['id'], int) is True
def test_19_perform_wipe_on_unused_disk(): unused_disks = POST('/disk/get_unused/', False) if len(unused_disks.json()) > 0: print('in if') results = POST('/disk/wipe/', { 'dev': unused_disks.json()[0]['name'], 'mode': 'QUICK' }) assert results.status_code == 200, results.text
def test_02_create_vmware(data): payload = { 'hostname': os.environ['VMWARE_HOST'], 'username': os.environ['VMWARE_USERNAME'], 'password': os.environ['VMWARE_PASSWORD'] } results = POST('/vmware/get_datastores/', payload) assert results.status_code == 200, results.text assert isinstance(results.json(), list) is True, results.text
def test_02_Creating_WebDAV_share_on_DATASET_PATH(webdav_dict): results = POST('/sharing/webdav/', { 'name': SHARE_NAME, 'comment': 'Auto-created by API tests', 'path': DATASET_PATH }) assert results.status_code == 200, results.text webdav_dict.update(results.json()) assert isinstance(webdav_dict['id'], int) is True
def test_10_start_jail(): global JOB_ID if freeze is True: pytest.skip(freeze_msg) results = POST('/jail/start/', JAIL_NAME) assert results.status_code == 200, results.text JOB_ID = results.json() time.sleep(1)
def test_10_verify_system_is_ready_to_reboot(): if update_version is None: pytest.skip('No update found') elif download_failed is True: pytest.skip(f'Downloading {selected_trains} failed') else: results = POST('/update/check_available/') assert results.status_code == 200, results.text assert isinstance(results.json(), dict) is True, results.text assert results.json()['status'] == 'REBOOT_REQUIRED', results.text
def test_07_get_pending_update(): if update_version is None: pytest.skip('No update found') elif download_failed is True: pytest.skip(f'Downloading {selected_trains} failed') else: results = POST('/update/get_pending/') assert results.status_code == 200, results.text assert isinstance(results.json(), list) is True, results.text assert results.json() != [], results.text
def test_11_import_nonascii_msdosfs(): payload = { "device": f"/dev/{IMAGES['msdosfs-nonascii']}s1", "fs_type": "msdosfs", "fs_options": {"locale": "ru_RU.UTF-8"}, "dst_path": dataset_path, } results = POST("/pool/import_disk/", payload) assert results.status_code == 200, results.text job_id = results.json() expect_state(job_id, "SUCCESS")
def test_02_Add_ISCSI_portal(): payload = { 'listen': [ { 'ip': '0.0.0.0', 'port': 3620 } ] } results = POST("/iscsi/portal/", payload) assert isinstance(results.json(), dict), results.text
def test_04_Creating_rsync_task(rsynctask_dict): payload = { 'user': '******', 'mode': 'SSH', 'remotehost': 'foobar', 'path': '/mnt/tank/share', "remotepath": "/share", "remoteport": 22 } results = POST('/rsynctask/', payload) assert results.status_code == 200, results.text rsynctask_dict.update(results.json()) assert isinstance(rsynctask_dict['id'], int) is True
def test_05_create_system_tunable_dummynet(): global payload, results, tunable_id payload = { "tun_var": "dummynet_load", "tun_comment": "tunable dummynet test", "tun_enabled": True, "tun_value": "YES", "tun_type": "loader" } results = POST("/system/tunable/", payload) assert results.status_code == 201, results.text assert isinstance(results.json(), dict) is True, results.text tunable_id = results.json()['id']
def test_15_stop_jail(): global JOB_ID if freeze is True: pytest.skip(freeze_msg) payload = { 'jail': JAIL_NAME, 'force': True } results = POST('/jail/stop/', payload) assert results.status_code == 200, results.text JOB_ID = results.json() time.sleep(1)
def test_02_create_cloud_credentials(env, credentials): result = POST("/cloudsync/credentials/", { "name": "Test", "provider": "S3", "attributes": { "access_key_id": env["CLOUDSYNC_AWS_ACCESS_KEY_ID"], "secret_access_key": "garbage", }, }) assert result.status_code == 200, result.text credentials.update(result.json())
def test_13_import_ntfs(): payload = { "device": f"/dev/{IMAGES['ntfs']}s1", "fs_type": "ntfs", "fs_options": {}, "dst_path": dataset_path, } results = POST("/pool/import_disk/", payload) assert results.status_code == 200, results.text job_id = results.json() expect_state(job_id, "SUCCESS")
def test_04_import_nonascii_msdosfs(): result = POST("/pool/import_disk", { "volume": f"/dev/{IMAGES['msdosfs-nonascii']}s1", "fs_type": "msdosfs", "fs_options": {"locale": "ru_RU.UTF-8"}, "dst_path": DATASET_PATH, }) assert result.status_code == 200, result.text job_id = result.json() expect_state(job_id, "SUCCESS") assert os.path.exists(os.path.join(DATASET_PATH, "Каталог/Файл"))
def test_02_import_msdosfs(): result = POST("/pool/import_disk", { "volume": f"/dev/{IMAGES['msdosfs']}s1", "fs_type": "msdosfs", "fs_options": {}, "dst_path": DATASET_PATH, }) assert result.status_code == 200, result.text job_id = result.json() expect_state(job_id, "SUCCESS") assert os.path.exists(os.path.join(DATASET_PATH, "Directory/File"))
def test_04_creating_storage_volume(): payload = { "volume_name": pool_name, "layout": [ { "vdevtype": "stripe", "disks": [disk1, disk2] } ] } global results results = POST("/storage/volume/", payload) assert results.status_code == 201, results.text assert isinstance(results.json(), dict), results.text
def test_17_filesystem_acl_is_removed(): results = POST('/filesystem/stat/', f'/mnt/{dataset}') assert results.status_code == 200, results.text assert results.json()['acl'] is False, results.text assert oct(results.json()['mode']) == '0o40777', results.text
def test_10_Stopping_WebDAV_service(): results = POST('/service/stop/', { 'service': 'webdav', }) assert results.status_code == 200, results.text sleep(1)
sys.path.append(apifolder) from auto_config import pool_name, ha, scale, ip, user, password from functions import GET, POST, PUT, DELETE, wait_on_job, SSH_TEST reason = 'Skipping test for HA' if ha else 'Skipping test for Scale' pytestmark = pytest.mark.skipif(ha or scale, reason=reason) JOB_ID = None job_results = None default_repos_url = 'https://github.com/freenas/iocage-ix-plugins.git' community_repos_url = 'https://github.com/ix-plugin-hub/iocage-plugin-index.git' custom_community_repos_url = 'https://github.com/ericbsd/iocage-plugin-index.git' if not scale and not ha: PUT("/ssh/", {"rootlogin": True}, controller_a=ha) POST("/service/start/", {"service": "ssh"}, controller_a=ha) ssh_cmd = "uname -r | cut -d '-' -f1" release_version = SSH_TEST(ssh_cmd, user, password, ip)['output'].strip() community_index_url = f'https://raw.githubusercontent.com/ix-plugin-hub/iocage-plugin-index/{release_version}-RELEASE/INDEX' community_plugin_index = GET(community_index_url).json() community_plugin_list = list(community_plugin_index.keys()) custom_community_index_url = f'https://raw.githubusercontent.com/ericbsd/iocage-plugin-index/{release_version}-RELEASE/INDEX' custom_community_plugin_index = GET(custom_community_index_url).json() custom_community_plugin_list = list(custom_community_plugin_index.keys()) PUT("/ssh/", {"rootlogin": False}, controller_a=ha) POST("/service/stop/", {"service": "ssh"}, controller_a=ha) else: community_plugin_list = [] custom_community_plugin_list = []
def test_03_activate_jail_pool(request): depends(request, ["pool_04"], scope="session") results = POST('/jail/activate/', pool_name) assert results.status_code == 200, results.text assert results.json() is True, results.text
def test_05_start_service(svc): results = POST('/service/start/', {'service': svc}) assert results.status_code == 200, results.text assert results.json() is True sleep(1)
def test_09_Stopping_WebDAV_service(): results = POST('/service/stop', { 'service': 'webdav', 'service-control': {'onetime': True} }) assert results.status_code == 200, results.text
def test_043_create_a_dataset_to_inherit_encryption_from_the_passphrase_encrypted_pool( ): payload = {'name': dataset, 'inherit_encryption': True} results = POST('/pool/dataset/', payload) assert results.status_code == 200, results.text assert results.json()['key_format']['value'] == 'PASSPHRASE', results.text
def test_17_leave_activedirectory(request): depends(request, ["JOINED_AD"]) global payload, results payload = {"username": ADUSERNAME, "password": ADPASSWORD} results = POST("/activedirectory/leave/", payload) assert results.status_code == 200, results.text
def test_15_creating_a_afp_share_on_afp_path(request): depends(request, ["pool_04"], scope="session") payload = {"name": AFP_NAME, "path": AFP_PATH} results = POST("/sharing/afp/", payload) assert results.status_code == 200, results.text
def test_34_stopping_afp_service(request): depends(request, ["pool_04"], scope="session") payload = {"service": "afp"} results = POST("/service/stop/", payload) assert results.status_code == 200, results.text sleep(1)
def test_03_Add_ISCSI_target(self): payload = {"iscsi_target_name": TARGET_NAME} assert POST("/services/iscsi/target/", payload) == 201
def test_01_creating_afp_dataset(request): depends(request, ["pool_04"], scope="session") results = POST("/pool/dataset/", {"name": dataset}) assert results.status_code == 200, results.text
def test_12_filesystem_acl_is_present(): results = POST('/filesystem/stat/', f'/mnt/{dataset}') assert results.status_code == 200, results.text assert results.json()['acl'] is True, results.text
def test_01_get_device_info(dtype): results = POST('/device/get_info/', dtype) assert results.status_code == 200, results.text assert isinstance(results.json(), (list, dict)) is True, results.text global all_results all_results[dtype] = results
def test_01_Creating_diagnostic_file(): payload = {"name": "newbe1", "source": "default"} results = POST("/system/debug/", payload) assert results.status_code == 200, results.text
# Author: Eric Turgeon # License: BSD import pytest import sys import os apifolder = os.getcwd() sys.path.append(apifolder) from functions import POST from auto_config import ha, dev_test # comment pytestmark for development testing with --dev-test pytestmark = pytest.mark.skipif(dev_test, reason='Skip for testing') global all_results all_results = {} disk_list = list( POST('/device/get_info/', 'DISK', controller_a=ha).json().keys()) @pytest.mark.parametrize('dtype', ['SERIAL', 'DISK']) def test_01_get_device_info(dtype): results = POST('/device/get_info/', dtype) assert results.status_code == 200, results.text assert isinstance(results.json(), (list, dict)) is True, results.text global all_results all_results[dtype] = results def test_02_look_at_device_serial(): results = all_results['SERIAL'] assert results.json()[0]['drivername'] == 'uart', results.text assert results.json()[1]['drivername'] == 'uart', results.text
def test_07_service_stop(svc): results = POST('/service/stop/', {'service': svc}) assert results.status_code == 200, results.text assert results.json() is False sleep(1)
def test_07_starting_smartd_service(): payload = {"service": "smartd", "service-control": {"onetime": True}} results = POST("/service/start/", payload) assert results.status_code == 200, results.text
def test_07_commite_interface(): payload = {"rollback": True, "checkin_timeout": 10} results = POST('/interface/commit/', payload) assert results.status_code == 200, results.text
def test_10_restore_the_alert(): results = POST("/alert/restore/", alert_id) assert results.status_code == 200, results.text assert isinstance(results.json(), type(None)), results.text
def test_42_verify_clean_call(request): depends(request, ["pool_04"], scope="session") results = POST('/jail/clean/', 'ALL') assert results.status_code == 200, results.text assert results.json() is True, results.text
def test_08_dimiss_the_alert(): results = POST("/alert/dismiss/", alert_id) assert results.status_code == 200, results.text assert isinstance(results.json(), type(None)), results.text
def test_06_Associate_ISCSI_target(self): payload = {"id": 1, "iscsi_extent": 1, "iscsi_lunid": None, "iscsi_target": 1} assert POST("/services/iscsi/targettoextent/", payload) == 201
def test_02_Creating_SMB_dataset(self): assert POST("/storage/volume/tank/datasets/", {"name": DATASET}) == 201
def test_094_run_inherit_parent_encryption_properties_on_the_passprase(): results = POST('/pool/dataset/inherit_parent_encryption_properties', child_dataset) assert results.status_code == 200, results.text
def test_01_Creating_dataset_for_WebDAV_use(pool_dict): results = POST("/pool/dataset/", {"name": dataset}) assert results.status_code == 200, results.text pool_dict.update(results.json()) assert isinstance(pool_dict['id'], str) is True
def test_010_create_a_dataset_with_inherit_encryption_true_on_a_normal_pool(): payload = {'name': dataset, 'inherit_encryption': True} results = POST('/pool/dataset/', payload) assert results.status_code == 200, results.text
def test_066_create_an_dataset_with_inherit_encryption_from_the_key_encrypted_pool( ): payload = {'name': dataset, 'inherit_encryption': True} results = POST('/pool/dataset/', payload) assert results.status_code == 200, results.text assert results.json()['key_format']['value'] == 'HEX', results.text
def test_07_creating_ad_dataset_for_smb(request): depends(request, ["pool_04", "AD_IS_HEALTHY"], scope="session") results = POST("/pool/dataset/", {"name": dataset}) assert results.status_code == 200, results.text
def test_02_Add_ISCSI_portal(self): payload = {"iscsi_target_portal_ips": ["0.0.0.0:3620"]} assert POST("/services/iscsi/portal/", payload) == 201