Esempio n. 1
0
def check_access_to_actions_launch(objects):
    """Check that superuser can run actions"""
    for obj in objects:
        with catch_failed(
            (AccessIsDenied, NoSuchEndpointOrAccessIsDenied),
                f'Superuser should has right to run action on {get_object_represent(obj)}',
        ):
            obj.action(name='no_config').run().wait()
Esempio n. 2
0
def test_accept_license_with_two_bundles_upload_at_once(
        create_bundle_archives: List[str], page: BundleListPage):
    """Upload two bundles and accept license"""
    with page.table.wait_rows_change():
        page.upload_bundles(create_bundle_archives)
    with catch_failed(ElementClickInterceptedException,
                      "License was not accepted by single button click"):
        page.accept_licence(row_num=1)
Esempio n. 3
0
def action_in_object_is_present(action: str, obj: AnyADCMObject):
    """Assert action in object is present"""
    with allure.step(
            f"Assert that action {action} is present in {get_object_represent(obj)}"
    ):
        with catch_failed(ObjectNotFound,
                          f"Action {action} not found in object {obj}"):
            obj.action(name=action)
Esempio n. 4
0
def test_load_should_fail_on_wrong_dsl(sdk_client_fs: ADCMClient, entity,
                                       case):
    """Test bundle load should fail on wrong states dsl"""
    with allure.step(f"Upload {entity} bundle with {case}"):
        bundle_path = utils.get_data_dir(__file__, "states", entity, case)
        with catch_failed(Failed, "Bundle was loaded but should fail to load"):
            with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
                sdk_client_fs.upload_from_fs(bundle_path)
    with allure.step("Assert that error message is correct"):
        err.INVALID_OBJECT_DEFINITION.equal(e)
Esempio n. 5
0
def action_in_object_is_absent(action: str, obj: AnyADCMObject):
    """Assert action in object is absent"""
    with allure.step(
            f"Assert that action {action} is absent in {get_object_represent(obj)}"
    ):
        with catch_failed(
                Failed,
                f"Action {action} is present in {get_object_represent(obj)}"):
            with pytest.raises(ObjectNotFound):
                obj.action(name=action)
Esempio n. 6
0
 def check_before_upgrade_state_equal_to(self,
                                         expected_state: Optional[str],
                                         inventory: dict):
     """Check that `state` key in inventory dictionary is equal to expected"""
     with utils.catch_failed(
             KeyError, "Structure of inventory.json file is unexpected"):
         actual_state = inventory["all"]["children"]["CLUSTER"]["vars"][
             "cluster"]["before_upgrade"]["state"]
     assert (
         actual_state == expected_state
     ), f'Before upgrade state should be "{expected_state}", but actual state is "{actual_state}"'
Esempio n. 7
0
def is_allowed(base_object: Union[BaseAPIObject, ADCMClient],
               business_role: Union[BusinessRole,
                                    BusinessRoles], *args, **kwargs):
    """
    Assert that role is allowed on object
    """
    role: BusinessRole = business_role.value if isinstance(
        business_role, BusinessRoles) else business_role
    with allure.step(
            f"Assert that {role.role_name} on {get_object_represent(base_object)} is allowed"
    ), catch_failed(
        (AccessIsDenied, NoSuchEndpointOrAccessIsDenied),
            f"{role.role_name} on {get_object_represent(base_object)} should be allowed",
    ):
        return role.method_call(base_object, *args, **kwargs)
Esempio n. 8
0
def check_business_roles_children(
    client: ADCMClient, prototype: Prototype, actions: List[dict],
    actions_role_names: List[str]
) -> Tuple[Set[RoleShortInfo], Set[RoleShortInfo]]:
    """
    Checks that "action" business roles have all newly created roles as its children.
    :returns: hidden and business roles as ShortRoleInfo set
    """
    hidden_roles = set()
    business_roles = set()
    for action_display_name, hidden_role_name in zip(
            key_values_from('display_name', actions), actions_role_names):
        business_role_name = f'{prototype.type.capitalize()} Action: {action_display_name}'
        with allure.step(
                f'Check role "{hidden_role_name}" is a child of "{business_role_name}"'
        ):
            with catch_failed(
                    ObjectNotFound,
                    f'There should be a hidden role with name "{hidden_role_name}"'
            ):
                hidden_role = client.role(name=hidden_role_name,
                                          type=RoleType.HIDDEN.value)
            with catch_failed(
                    ObjectNotFound,
                    f'There should be a business role with name "{business_role_name}"'
            ):
                business_role = client.role(name=business_role_name,
                                            type=RoleType.BUSINESS.value)
            is_in_collection(
                hidden_role.id,
                (child.id for child in business_role.child_list()),
                f"Role wasn't found in children of '{hidden_role.name}'",
            )
        hidden_roles.add(extract_role_short_info(hidden_role))
        business_roles.add(extract_role_short_info(business_role))
    return hidden_roles, business_roles
Esempio n. 9
0
def test_load_should_fail_on_wrong_states(sdk_client_fs: ADCMClient, entity,
                                          state, case):
    """Test bundle load should fail on wrong states syntax"""
    with allure.step(f"Upload {entity} bundle with {case}"):
        bundle_path = utils.get_data_dir(__file__, "states", entity, state,
                                         case)
        with catch_failed(Failed, "Bundle was loaded but should fail to load"):
            with pytest.raises(coreapi.exceptions.ErrorMessage) as e:
                sdk_client_fs.upload_from_fs(bundle_path)
    with allure.step("Assert that error message is correct"):
        # validation messages in new DSL are a bit messy so we check only error code and type
        if "new_dsl" in case:
            err.INVALID_OBJECT_DEFINITION.equal(e)
        else:
            err.INVALID_OBJECT_DEFINITION.equal(e, state)
Esempio n. 10
0
def policy_creation_should_succeeded(admin_client: ADCMClient, role: Role, adcm_object: AnyADCMObject, user: User):
    """Try to create policy based on give role and expect creation to succeed"""
    with allure.step(f'Create policy based on role "{role.display_name}" and expect it to succeeded'):
        policy_name = f'Test role {random_string(5)}'
        with catch_failed(ErrorMessage, 'Policy should be created'):
            admin_client.policy_create(name=policy_name, role=role, objects=[adcm_object], user=[user])
Esempio n. 11
0
def _check_that_host_exists(cluster: Cluster, host: Host) -> None:
    assert len(cluster.host_list()) == 1, "Only one host expected to be"
    with catch_failed(ObjectNotFound, "Previously created host not found"):
        cluster.host(fqdn=host.fqdn)
Esempio n. 12
0
def _check_that_cluster_exists(sdk_client_fs: ADCMClient, cluster: Cluster) -> None:
    assert len(sdk_client_fs.cluster_list()) == 1, "Only one cluster expected to be"
    with catch_failed(ObjectNotFound, "Previously created cluster not found"):
        sdk_client_fs.cluster(name=cluster.name)