Ejemplo n.º 1
0
 def test_get_cluster_list(self, cluster_bundle: Bundle):
     """Test get cluster list"""
     actual, expected = [], []
     # Create list of clusters and fill expected list
     for name in utils.random_string_list():
         cluster_bundle.cluster_create(name)
         expected.append(name)
     for cluster in cluster_bundle.cluster_list():
         actual.append(cluster.name)
     with allure.step("Check cluster list"):
         assert actual == expected
Ejemplo n.º 2
0
 def test_creating_cluster_with_name_and_desc(self, cluster_bundle: Bundle):
     """Test create cluster with name and desc"""
     name, description = utils.random_string_list(2)
     cluster = cluster_bundle.cluster_create(name=name, description=description)
     with allure.step("Check created cluster"):
         assert cluster.name == name
         assert cluster.description == description
Ejemplo n.º 3
0
def check_role_with_parametrization(clients, user, cluster_bundle: Bundle, provider_bundle: Bundle):
    """Check that update of role with parametrization leads to correct permissions update"""
    cluster, provider = cluster_bundle.cluster_create('clusteraster'), provider_bundle.provider_create('provideraider')
    role_name = "Role with parametrization"

    role = clients.admin.role_create(
        name=role_name,
        display_name=role_name,
        child=_form_children(clients.admin, BusinessRoles.EditClusterConfigurations),
    )
    policy = clients.admin.policy_create(name="User policy", role=role, objects=[cluster], user=[user])
    with new_client_instance(*TEST_USER_CREDENTIALS, clients.user.url) as user_client:
        user_cluster, user_provider = as_user_objects(user_client, cluster, provider)
        is_allowed(user_cluster, BusinessRoles.EditClusterConfigurations)
        is_denied(user_provider, BusinessRoles.EditProviderConfigurations)
    role.update(child=_form_children(clients.admin, BusinessRoles.EditProviderConfigurations))
    with new_client_instance(*TEST_USER_CREDENTIALS, clients.user.url) as user_client:
        user_cluster, user_provider = as_user_objects(user_client, cluster, provider)
        is_denied(user_cluster, BusinessRoles.EditClusterConfigurations)
        is_denied(user_provider, BusinessRoles.EditProviderConfigurations)
    policy.update(object=[{'type': 'provider', 'id': provider.id}])
    with new_client_instance(*TEST_USER_CREDENTIALS, clients.user.url) as user_client:
        user_cluster, user_provider = as_user_objects(user_client, cluster, provider)
        is_denied(user_cluster, BusinessRoles.EditClusterConfigurations)
        is_allowed(user_provider, BusinessRoles.EditProviderConfigurations)
    policy.delete()
    role.delete()
Ejemplo n.º 4
0
 def _create_cluster_with_all_services(self, cluster_bundle: Bundle, hosts: Tuple[Host, Host, Host]) -> Cluster:
     """
     Create cluster with three services
     Add three hosts on it
     Set components on hosts
     Run some actions
     """
     with allure.step('Create cluster and add services'):
         cluster = cluster_bundle.cluster_create(name='With all services')
         cluster.config_set_diff({'very_important_flag': 1.6})
         cheese_service = cluster.service_add(name=self.CHEESE_SERVICE)
         sauce_service = cluster.service_add(name=self.SAUCE_SERVICE)
         bread_service = cluster.service_add(name=self.BREAD_SERVICE)
         components = {
             self.MILK_COMPONENT: cheese_service.component(name=self.MILK_COMPONENT),
             self.TOMATO_COMPONENT: sauce_service.component(name=self.TOMATO_COMPONENT),
             self.LEMON_COMPONENT: sauce_service.component(name=self.LEMON_COMPONENT),
             self.SPICE_COMPONENT: sauce_service.component(name=self.SPICE_COMPONENT),
         }
     with allure.step('Add hosts'):
         for host in hosts:
             cluster.host_add(host)
     with allure.step('Run actions on the cluster, all components and services'):
         self._run_actions_on_components(cluster, sauce_service, components, hosts)
         _wait_for_tasks(service.action().run() for service in (cheese_service, sauce_service, bread_service))
         cluster.action(name='make_sandwich').run().wait()
     return cluster
Ejemplo n.º 5
0
 def _create_cluster_with_hosts(
     self, cluster_bundle: Bundle, hosts: Tuple[Host, ...], service_name: str = SAUCE_SERVICE
 ) -> Cluster:
     """
     Create cluster with given amount of hosts.
     Cluster is not configured (can't run actions on it).
     Cluster has 1 service added.
     """
     cluster = cluster_bundle.cluster_create(name='Cluster with hosts')
     cluster.service_add(name=service_name)
     for host in hosts:
         cluster.host_add(host)
     return cluster
Ejemplo n.º 6
0
    def _create_cluster_with_config_history(self, bundle: Bundle) -> Cluster:
        """Create cluster with one service and config history"""

        def get_random_config_map() -> dict:
            return {
                'a_lot_of_text': {'simple_string': random_string(25), 'file_pass': random_string(16)},
                'from_doc': {
                    'memory_size': random.randint(2, 64),
                    'person': {
                        'name': random_string(13),
                        'age': str(random.randint(14, 80)),
                        'custom_field': random_string(12),
                    },
                },
                'country_codes': [
                    {'country': random_string(12), 'code': int(random.randint(1, 200))} for _ in range(4)
                ],
            }

        def get_component_random_config_map() -> dict:
            return {'illicium': random.random()}

        config_change_iterations = 100
        cluster = bundle.cluster_create(name='Config history')
        cluster.config_set_diff({'very_important_flag': 1.6})
        with allure.step(f"Change cluster's config {config_change_iterations} times"):
            for _ in range(config_change_iterations):
                cluster.config_set_diff(get_random_config_map())
        with allure.step(f"Add service and change its config {config_change_iterations} times"):
            service = cluster.service_add(name=self.SAUCE_SERVICE)
            for _ in range(config_change_iterations):
                service.config_set_diff(get_random_config_map())
        with allure.step(f"Change component's config {config_change_iterations} times"):
            component = service.component()
            for _ in range(config_change_iterations):
                component.config_set_diff(get_component_random_config_map())
        return cluster
Ejemplo n.º 7
0
def cluster(cluster_bundle: Bundle) -> Cluster:
    """Create cluster"""
    return cluster_bundle.cluster_create(name=utils.random_string())
Ejemplo n.º 8
0
def cluster(cluster_bundle: Bundle) -> Cluster:
    """Creates cluster and adds service"""
    cluster = cluster_bundle.cluster_create(CLUSTER_NAME)
    cluster.service_add(name=SERVICE_NAME)
    return cluster