def create_project_endpoints(client, project_name=RBAC_PROJECT): linux_payload = read_test_config(file_name="linux_endpoint_payload.json") windows_payload = read_test_config( file_name="windows_endpoint_payload.json") http_payload = read_test_config(file_name="http_endpoint_payload.json") # Fix payload with correct data endpoint_resource = linux_payload["spec"]["resources"] endpoint_resource["attrs"]["values"] = [linux_ip] endpoint_resource["attrs"]["credential_definition_list"][0][ "username"] = CRED_USERNAME endpoint_resource["attrs"]["credential_definition_list"][0]["secret"][ "value"] = CRED_PASSWORD endpoint_resource = windows_payload["spec"]["resources"] endpoint_resource["attrs"]["values"] = [windows_ip] endpoint_resource["attrs"]["credential_definition_list"][0][ "username"] = CRED_WINDOWS_USERNAME endpoint_resource["attrs"]["credential_definition_list"][0]["secret"][ "value"] = CRED_PASSWORD project_uuid = get_project_id_from_name(client, project_name) project_endpoints = {} if project_uuid: for endpoint_payload in [linux_payload, windows_payload, http_payload]: endpoint = change_uuids(endpoint_payload, {}) endpoint["metadata"]["project_reference"] = { "kind": "project", "uuid": project_uuid, "name": project_name, } endpoint["spec"]["name"] = "Endpoint_{}_{}".format( project_name, str(uuid.uuid4())[-10:]) # Endpoint Create res, err = client.endpoint.create(endpoint) if err: print(err) pytest.fail(err) ep = res.json() ep_state = ep["status"]["state"] ep_uuid = ep["metadata"]["uuid"] ep_name = ep["spec"]["name"] ep_type = ep["spec"]["resources"]["type"] print(">> Endpoint created with name {} is in state: {}".format( ep_name, ep_state)) project_endpoints[ep_type] = (ep_name, ep_uuid) return project_name, project_endpoints
def get_http_task_runbook(): """returns the runbook for http task""" global endpoint_payload endpoint_payload = change_uuids( read_test_config(file_name="http_endpoint_payload.json"), {} ) @runbook def HTTPTask(endpoints=[endpoint]): # Creating an endpoint with POST call Task.HTTP.post( body=json.dumps(endpoint_payload), headers={"Content-Type": "application/json"}, content_type="application/json", response_paths={"ep_uuid": "$.metadata.uuid"}, status_mapping={200: True}, target=endpoints[0], ) # Check the type of the created endpoint Task.HTTP.get( relative_url="/" + endpoint_payload["metadata"]["uuid"], headers={"Content-Type": "application/json"}, content_type="application/json", response_paths={"ep_type": "$.spec.resources.type"}, status_mapping={200: True}, target=endpoints[0], ) # Delete the created endpoint Task.HTTP.delete( relative_url="/" + endpoint_payload["metadata"]["uuid"], headers={"Content-Type": "application/json"}, content_type="application/json", status_mapping={200: True}, target=endpoints[0], ) Task.Exec.escript(name="ExecTask", script='''print "@@{ep_type}@@"''') return HTTPTask
import pytest import copy import os import uuid from calm.dsl.cli.main import get_api_client from calm.dsl.cli.constants import ENDPOINT from calm.dsl.config import get_context from utils import change_uuids, read_test_config LinuxEndpointPayload = read_test_config(file_name="linux_endpoint_payload.json") WindowsEndpointPayload = read_test_config(file_name="windows_endpoint_payload.json") HTTPEndpointPayload = read_test_config(file_name="http_endpoint_payload.json") class TestEndpoints: @pytest.mark.runbook @pytest.mark.endpoint @pytest.mark.regression @pytest.mark.parametrize( "EndpointPayload", [LinuxEndpointPayload, WindowsEndpointPayload, HTTPEndpointPayload], ) def test_endpoint_crud(self, EndpointPayload): """ test_linux_endpoint_create_with_required_fields, test_linux_endpoint_update, test_linux_endpoint_delete test_windows_endpoint_create_with_required_fields, test_windows_endpoint_update, test_windows_endpoint_delete test_http_endpoint_create_with_auth, test_http_endpoint_update, test_http_endpoint_delete test_http_endpoint_download_upload, test_windows_endpoint_download_upload, test_linux_endpoint_download_upload """
def test_variables_in_runbook(self, Runbook): """ test_runbook_variables """ client = get_api_client() rb_name = "test_runbook_" + str(uuid.uuid4())[-10:] rb = upload_runbook(client, rb_name, Runbook) rb_state = rb["status"]["state"] rb_uuid = rb["metadata"]["uuid"] print(">> Runbook state: {}".format(rb_state)) assert rb_state == "ACTIVE" assert rb_name == rb["spec"]["name"] assert rb_name == rb["metadata"]["name"] # getting the run payload from the json data = read_test_config() run_payload = data[Runbook.action_name]["run_payload"] expected_output = data[Runbook.action_name]["expected_output"] # running the runbook print("\n>>Running the runbook") res, err = client.runbook.run(rb_uuid, run_payload) if err: pytest.fail("[{}] - {}".format(err["code"], err["error"])) response = res.json() runlog_uuid = response["status"]["runlog_uuid"] # polling till runbook run gets to terminal state state, reasons = poll_runlog_status(client, runlog_uuid, RUNLOG.TERMINAL_STATES) print(">> Runbook Run state: {}\n{}".format(state, reasons)) assert state == RUNLOG.STATUS.SUCCESS # Finding the task_uuid for the exec task res, err = client.runbook.list_runlogs(runlog_uuid) if err: pytest.fail("[{}] - {}".format(err["code"], err["error"])) response = res.json() entities = response["entities"] for entity in entities: if (entity["status"]["type"] == "task_runlog" and entity["status"]["task_reference"]["name"] == "Exec_Task"): exec_task = entity["metadata"]["uuid"] # Now checking the output of exec task print("runlog_id: {}".format(runlog_uuid)) res, err = client.runbook.runlog_output(runlog_uuid, exec_task) if err: pytest.fail("[{}] - {}".format(err["code"], err["error"])) runlog_output = res.json() output_list = runlog_output["status"]["output_list"] assert output_list[0]["output"] == expected_output # delete the runbook res, err = client.runbook.delete(rb_uuid) if err: pytest.fail("[{}] - {}".format(err["code"], err["error"])) else: print("runbook {} deleted".format(rb_name))
from calm.dsl.cli.main import get_api_client from calm.dsl.cli.constants import RUNLOG from calm.dsl.runbooks import create_endpoint_payload from tests.sample_runbooks import DslSimpleRunbook from utils import ( upload_runbook, update_runbook, poll_runlog_status, read_test_config, change_uuids, ) from test_files.exec_task import linux_endpoint from test_files.updated_runbook import DslUpdatedRunbook RunbookPayload = read_test_config(file_name="runbook_payload.json") RunbookUpdatePayload = read_test_config(file_name="runbook_payload2.json") class TestRunbooks: @pytest.mark.runbook @pytest.mark.regression def test_runbooks_list(self): """test_runbook_list""" client = get_api_client() params = {"length": 20, "offset": 0} res, err = client.runbook.list(params=params) if not err:
import pytest import os from distutils.version import LooseVersion as LV from calm.dsl.store import Version from calm.dsl.cli.main import get_api_client from calm.dsl.cli.constants import ENDPOINT from utils import read_test_config, change_uuids LinuxVMStaticAHVEpPayload = read_test_config( file_name="linux_vm_static_ahv_ep_payload.json") LinuxVMDynamicAHVEpPayload = read_test_config( file_name="linux_vm_dynamic_ahv_ep_payload.json") WindowsVMStaticAHVEpPayload = read_test_config( file_name="windows_vm_static_ahv_ep_payload.json") WindowsVMDynamicAHVEpPayload = read_test_config( file_name="windows_vm_dynamic_ahv_ep_payload.json") # calm_version CALM_VERSION = Version.get_version("Calm") @pytest.mark.skipif( LV(CALM_VERSION) < LV("3.2.0"), reason="Tests are for env changes introduced in 3.2.0", ) class TestVMEndpoints: @pytest.mark.runbook @pytest.mark.regression @pytest.mark.parametrize( "EndpointPayload",